Implemented ?O to display +/- downloaded flag.
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for 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 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 (require 'nnoo)
40
41 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
42 (autoload 'gnus-cache-write-active "gnus-cache")
43 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
44 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
45 (autoload 'mm-uu-dissect "mm-uu")
46 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
47   "Deuglify broken Outlook (Express) articles and redisplay."
48   t)
49
50 (defcustom gnus-kill-summary-on-exit t
51   "*If non-nil, kill the summary buffer when you exit from it.
52 If nil, the summary will become a \"*Dead Summary*\" buffer, and
53 it will be killed sometime later."
54   :group 'gnus-summary-exit
55   :type 'boolean)
56
57 (defcustom gnus-fetch-old-headers nil
58   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
59 If an unread article in the group refers to an older, already read (or
60 just marked as read) article, the old article will not normally be
61 displayed in the Summary buffer.  If this variable is non-nil, Gnus
62 will attempt to grab the headers to the old articles, and thereby
63 build complete threads.  If it has the value `some', only enough
64 headers to connect otherwise loose threads will be displayed.  This
65 variable can also be a number.  In that case, no more than that number
66 of old headers will be fetched.  If it has the value `invisible', all
67 old headers will be fetched, but none will be displayed.
68
69 The server has to support NOV for any of this to work."
70   :group 'gnus-thread
71   :type '(choice (const :tag "off" nil)
72                  (const some)
73                  number
74                  (sexp :menu-tag "other" t)))
75
76 (defcustom gnus-refer-thread-limit 200
77   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
78 If t, fetch all the available old headers."
79   :group 'gnus-thread
80   :type '(choice number
81                  (sexp :menu-tag "other" t)))
82
83 (defcustom gnus-summary-make-false-root 'adopt
84   "*nil means that Gnus won't gather loose threads.
85 If the root of a thread has expired or been read in a previous
86 session, the information necessary to build a complete thread has been
87 lost.  Instead of having many small sub-threads from this original thread
88 scattered all over the summary buffer, Gnus can gather them.
89
90 If non-nil, Gnus will try to gather all loose sub-threads from an
91 original thread into one large thread.
92
93 If this variable is non-nil, it should be one of `none', `adopt',
94 `dummy' or `empty'.
95
96 If this variable is `none', Gnus will not make a false root, but just
97 present the sub-threads after another.
98 If this variable is `dummy', Gnus will create a dummy root that will
99 have all the sub-threads as children.
100 If this variable is `adopt', Gnus will make one of the \"children\"
101 the parent and mark all the step-children as such.
102 If this variable is `empty', the \"children\" are printed with empty
103 subject fields.  (Or rather, they will be printed with a string
104 given by the `gnus-summary-same-subject' variable.)"
105   :group 'gnus-thread
106   :type '(choice (const :tag "off" nil)
107                  (const none)
108                  (const dummy)
109                  (const adopt)
110                  (const empty)))
111
112 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
113   "*A regexp to match subjects to be excluded from loose thread gathering.
114 As loose thread gathering is done on subjects only, that means that
115 there can be many false gatherings performed.  By rooting out certain
116 common subjects, gathering might become saner."
117   :group 'gnus-thread
118   :type 'regexp)
119
120 (defcustom gnus-summary-gather-subject-limit nil
121   "*Maximum length of subject comparisons when gathering loose threads.
122 Use nil to compare full subjects.  Setting this variable to a low
123 number will help gather threads that have been corrupted by
124 newsreaders chopping off subject lines, but it might also mean that
125 unrelated articles that have subject that happen to begin with the
126 same few characters will be incorrectly gathered.
127
128 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
129 comparing subjects."
130   :group 'gnus-thread
131   :type '(choice (const :tag "off" nil)
132                  (const fuzzy)
133                  (sexp :menu-tag "on" t)))
134
135 (defcustom gnus-simplify-subject-functions nil
136   "List of functions taking a string argument that simplify subjects.
137 The functions are applied recursively.
138
139 Useful functions to put in this list include:
140 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
141 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
142   :group 'gnus-thread
143   :type '(repeat function))
144
145 (defcustom gnus-simplify-ignored-prefixes nil
146   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
147   :group 'gnus-thread
148   :type '(choice (const :tag "off" nil)
149                  regexp))
150
151 (defcustom gnus-build-sparse-threads nil
152   "*If non-nil, fill in the gaps in threads.
153 If `some', only fill in the gaps that are needed to tie loose threads
154 together.  If `more', fill in all leaf nodes that Gnus can find.  If
155 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
156   :group 'gnus-thread
157   :type '(choice (const :tag "off" nil)
158                  (const some)
159                  (const more)
160                  (sexp :menu-tag "all" t)))
161
162 (defcustom gnus-summary-thread-gathering-function
163   'gnus-gather-threads-by-subject
164   "*Function used for gathering loose threads.
165 There are two pre-defined functions: `gnus-gather-threads-by-subject',
166 which only takes Subjects into consideration; and
167 `gnus-gather-threads-by-references', which compared the References
168 headers of the articles to find matches."
169   :group 'gnus-thread
170   :type '(radio (function-item gnus-gather-threads-by-subject)
171                 (function-item gnus-gather-threads-by-references)
172                 (function :tag "other")))
173
174 (defcustom gnus-summary-same-subject ""
175   "*String indicating that the current article has the same subject as the previous.
176 This variable will only be used if the value of
177 `gnus-summary-make-false-root' is `empty'."
178   :group 'gnus-summary-format
179   :type 'string)
180
181 (defcustom gnus-summary-goto-unread t
182   "*If t, many commands will go to the next unread article.
183 This applies to marking commands as well as other commands that
184 \"naturally\" select the next article, like, for instance, `SPC' at
185 the end of an article.
186
187 If nil, the marking commands do NOT go to the next unread article
188 \(they go to the next article instead).  If `never', commands that
189 usually go to the next unread article, will go to the next article,
190 whether it is read or not."
191   :group 'gnus-summary-marks
192   :link '(custom-manual "(gnus)Setting Marks")
193   :type '(choice (const :tag "off" nil)
194                  (const never)
195                  (sexp :menu-tag "on" t)))
196
197 (defcustom gnus-summary-default-score 0
198   "*Default article score level.
199 All scores generated by the score files will be added to this score.
200 If this variable is nil, scoring will be disabled."
201   :group 'gnus-score-default
202   :type '(choice (const :tag "disable")
203                  integer))
204
205 (defcustom gnus-summary-default-high-score 0
206   "*Default threshold for a high scored article.
207 An article will be highlighted as high scored if its score is greater
208 than this score."
209   :group 'gnus-score-default
210   :type 'integer)
211
212 (defcustom gnus-summary-default-low-score 0
213   "*Default threshold for a low scored article.
214 An article will be highlighted as low scored if its score is smaller
215 than this score."
216   :group 'gnus-score-default
217   :type 'integer)
218
219 (defcustom gnus-summary-zcore-fuzz 0
220   "*Fuzziness factor for the zcore in the summary buffer.
221 Articles with scores closer than this to `gnus-summary-default-score'
222 will not be marked."
223   :group 'gnus-summary-format
224   :type 'integer)
225
226 (defcustom gnus-simplify-subject-fuzzy-regexp nil
227   "*Strings to be removed when doing fuzzy matches.
228 This can either be a regular expression or list of regular expressions
229 that will be removed from subject strings if fuzzy subject
230 simplification is selected."
231   :group 'gnus-thread
232   :type '(repeat regexp))
233
234 (defcustom gnus-show-threads t
235   "*If non-nil, display threads in summary mode."
236   :group 'gnus-thread
237   :type 'boolean)
238
239 (defcustom gnus-thread-hide-subtree nil
240   "*If non-nil, hide all threads initially.
241 This can be a predicate specifier which says which threads to hide.
242 If threads are hidden, you have to run the command
243 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
244 to expose hidden threads."
245   :group 'gnus-thread
246   :type 'boolean)
247
248 (defcustom gnus-thread-hide-killed t
249   "*If non-nil, hide killed threads automatically."
250   :group 'gnus-thread
251   :type 'boolean)
252
253 (defcustom gnus-thread-ignore-subject t
254   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
255 If nil, articles that have different subjects from their parents will
256 start separate threads."
257   :group 'gnus-thread
258   :type 'boolean)
259
260 (defcustom gnus-thread-operation-ignore-subject t
261   "*If non-nil, subjects will be ignored when doing thread commands.
262 This affects commands like `gnus-summary-kill-thread' and
263 `gnus-summary-lower-thread'.
264
265 If this variable is nil, articles in the same thread with different
266 subjects will not be included in the operation in question.  If this
267 variable is `fuzzy', only articles that have subjects that are fuzzily
268 equal will be included."
269   :group 'gnus-thread
270   :type '(choice (const :tag "off" nil)
271                  (const fuzzy)
272                  (sexp :tag "on" t)))
273
274 (defcustom gnus-thread-indent-level 4
275   "*Number that says how much each sub-thread should be indented."
276   :group 'gnus-thread
277   :type 'integer)
278
279 (defcustom gnus-auto-extend-newsgroup t
280   "*If non-nil, extend newsgroup forward and backward when requested."
281   :group 'gnus-summary-choose
282   :type 'boolean)
283
284 (defcustom gnus-auto-select-first t
285   "*If non-nil, select the article under point.
286 Which article this is is controlled by the `gnus-auto-select-subject'
287 variable.
288
289 If you want to prevent automatic selection of articles in some
290 newsgroups, set the variable to nil in `gnus-select-group-hook'."
291   :group 'gnus-group-select
292   :type '(choice (const :tag "none" nil)
293                  (sexp :menu-tag "first" t)))
294
295 (defcustom gnus-auto-select-subject 'unread
296   "*Says what subject to place under point when entering a group.
297
298 This variable can either be the symbols `first' (place point on the
299 first subject), `unread' (place point on the subject line of the first
300 unread article), `best' (place point on the subject line of the
301 higest-scored article), `unseen' (place point on the subject line of
302 the first unseen article), 'unseen-or-unread' (place point on the subject
303 line of the first unseen article or, if all article have been seen, on the
304 subject line of the first unread article), or a function to be called to
305 place point on some subject line."
306   :group 'gnus-group-select
307   :type '(choice (const best)
308                  (const unread)
309                  (const first)
310                  (const unseen)
311                  (const unseen-or-unread)))
312
313 (defcustom gnus-auto-select-next t
314   "*If non-nil, offer to go to the next group from the end of the previous.
315 If the value is t and the next newsgroup is empty, Gnus will exit
316 summary mode and go back to group mode.  If the value is neither nil
317 nor t, Gnus will select the following unread newsgroup.  In
318 particular, if the value is the symbol `quietly', the next unread
319 newsgroup will be selected without any confirmation, and if it is
320 `almost-quietly', the next group will be selected without any
321 confirmation if you are located on the last article in the group.
322 Finally, if this variable is `slightly-quietly', the `Z n' command
323 will go to the next group without confirmation."
324   :group 'gnus-summary-maneuvering
325   :type '(choice (const :tag "off" nil)
326                  (const quietly)
327                  (const almost-quietly)
328                  (const slightly-quietly)
329                  (sexp :menu-tag "on" t)))
330
331 (defcustom gnus-auto-select-same nil
332   "*If non-nil, select the next article with the same subject.
333 If there are no more articles with the same subject, go to
334 the first unread article."
335   :group 'gnus-summary-maneuvering
336   :type 'boolean)
337
338 (defcustom gnus-summary-check-current nil
339   "*If non-nil, consider the current article when moving.
340 The \"unread\" movement commands will stay on the same line if the
341 current article is unread."
342   :group 'gnus-summary-maneuvering
343   :type 'boolean)
344
345 (defcustom gnus-auto-center-summary t
346   "*If non-nil, always center the current summary buffer.
347 In particular, if `vertical' do only vertical recentering.  If non-nil
348 and non-`vertical', do both horizontal and vertical recentering."
349   :group 'gnus-summary-maneuvering
350   :type '(choice (const :tag "none" nil)
351                  (const vertical)
352                  (integer :tag "height")
353                  (sexp :menu-tag "both" t)))
354
355 (defcustom gnus-show-all-headers nil
356   "*If non-nil, don't hide any headers."
357   :group 'gnus-article-hiding
358   :group 'gnus-article-headers
359   :type 'boolean)
360
361 (defcustom gnus-summary-ignore-duplicates nil
362   "*If non-nil, ignore articles with identical Message-ID headers."
363   :group 'gnus-summary
364   :type 'boolean)
365
366 (defcustom gnus-single-article-buffer t
367   "*If non-nil, display all articles in the same buffer.
368 If nil, each group will get its own article buffer."
369   :group 'gnus-article-various
370   :type 'boolean)
371
372 (defcustom gnus-break-pages t
373   "*If non-nil, do page breaking on articles.
374 The page delimiter is specified by the `gnus-page-delimiter'
375 variable."
376   :group 'gnus-article-various
377   :type 'boolean)
378
379 (defcustom gnus-move-split-methods nil
380   "*Variable used to suggest where articles are to be moved to.
381 It uses the same syntax as the `gnus-split-methods' variable.
382 However, whereas `gnus-split-methods' specifies file names as targets,
383 this variable specifies group names."
384   :group 'gnus-summary-mail
385   :type '(repeat (choice (list :value (fun) function)
386                          (cons :value ("" "") regexp (repeat string))
387                          (sexp :value nil))))
388
389 (defcustom gnus-unread-mark ?           ;Whitespace
390   "*Mark used for unread articles."
391   :group 'gnus-summary-marks
392   :type 'character)
393
394 (defcustom gnus-ticked-mark ?!
395   "*Mark used for ticked articles."
396   :group 'gnus-summary-marks
397   :type 'character)
398
399 (defcustom gnus-dormant-mark ??
400   "*Mark used for dormant articles."
401   :group 'gnus-summary-marks
402   :type 'character)
403
404 (defcustom gnus-del-mark ?r
405   "*Mark used for del'd articles."
406   :group 'gnus-summary-marks
407   :type 'character)
408
409 (defcustom gnus-read-mark ?R
410   "*Mark used for read articles."
411   :group 'gnus-summary-marks
412   :type 'character)
413
414 (defcustom gnus-expirable-mark ?E
415   "*Mark used for expirable articles."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-killed-mark ?K
420   "*Mark used for killed articles."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-spam-mark ?H
425   "*Mark used for spam articles."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-souped-mark ?F
430   "*Mark used for souped articles."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-kill-file-mark ?X
435   "*Mark used for articles killed by kill files."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-low-score-mark ?Y
440   "*Mark used for articles with a low score."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-catchup-mark ?C
445   "*Mark used for articles that are caught up."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-replied-mark ?A
450   "*Mark used for articles that have been replied to."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-forwarded-mark ?F
455   "*Mark used for articles that have been forwarded."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-recent-mark ?N
460   "*Mark used for articles that are recent."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-cached-mark ?*
465   "*Mark used for articles that are in the cache."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-saved-mark ?S
470   "*Mark used for articles that have been saved."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-unseen-mark ?.
475   "*Mark used for articles that haven't been seen."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-no-mark ?               ;Whitespace
480   "*Mark used for articles that have no other secondary mark."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-ancient-mark ?O
485   "*Mark used for ancient articles."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-sparse-mark ?Q
490   "*Mark used for sparsely reffed articles."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-canceled-mark ?G
495   "*Mark used for canceled articles."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-duplicate-mark ?M
500   "*Mark used for duplicate articles."
501   :group 'gnus-summary-marks
502   :type 'character)
503
504 (defcustom gnus-undownloaded-mark ?-
505   "*Mark used for articles that weren't downloaded."
506   :group 'gnus-summary-marks
507   :type 'character)
508
509 (defcustom gnus-downloaded-mark ?+
510   "*Mark used for articles that were downloaded."
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-downloadable-mark ?%
515   "*Mark used for articles that are to be downloaded."
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-unsendable-mark ?=
520   "*Mark used for articles that won't be sent."
521   :group 'gnus-summary-marks
522   :type 'character)
523
524 (defcustom gnus-score-over-mark ?+
525   "*Score mark used for articles with high scores."
526   :group 'gnus-summary-marks
527   :type 'character)
528
529 (defcustom gnus-score-below-mark ?-
530   "*Score mark used for articles with low scores."
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-empty-thread-mark ?     ;Whitespace
535   "*There is no thread under the article."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-not-empty-thread-mark ?=
540   "*There is a thread under the article."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-view-pseudo-asynchronously nil
545   "*If non-nil, Gnus will view pseudo-articles asynchronously."
546   :group 'gnus-extract-view
547   :type 'boolean)
548
549 (defcustom gnus-auto-expirable-marks
550   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
551         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
552         gnus-souped-mark gnus-duplicate-mark)
553   "*The list of marks converted into expiration if a group is auto-expirable."
554   :version "21.1"
555   :group 'gnus-summary
556   :type '(repeat character))
557
558 (defcustom gnus-inhibit-user-auto-expire t
559   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
560   :version "21.1"
561   :group 'gnus-summary
562   :type 'boolean)
563
564 (defcustom gnus-view-pseudos nil
565   "*If `automatic', pseudo-articles will be viewed automatically.
566 If `not-confirm', pseudos will be viewed automatically, and the user
567 will not be asked to confirm the command."
568   :group 'gnus-extract-view
569   :type '(choice (const :tag "off" nil)
570                  (const automatic)
571                  (const not-confirm)))
572
573 (defcustom gnus-view-pseudos-separately t
574   "*If non-nil, one pseudo-article will be created for each file to be viewed.
575 If nil, all files that use the same viewing command will be given as a
576 list of parameters to that command."
577   :group 'gnus-extract-view
578   :type 'boolean)
579
580 (defcustom gnus-insert-pseudo-articles t
581   "*If non-nil, insert pseudo-articles when decoding articles."
582   :group 'gnus-extract-view
583   :type 'boolean)
584
585 (defcustom gnus-summary-dummy-line-format
586   "  %(:                          :%) %S\n"
587   "*The format specification for the dummy roots in the summary buffer.
588 It works along the same lines as a normal formatting string,
589 with some simple extensions.
590
591 %S  The subject
592
593 General format specifiers can also be used.
594 See `(gnus)Formatting Variables'."
595   :link '(custom-manual "(gnus)Formatting Variables")
596   :group 'gnus-threading
597   :type 'string)
598
599 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
600   "*The format specification for the summary mode line.
601 It works along the same lines as a normal formatting string,
602 with some simple extensions:
603
604 %G  Group name
605 %p  Unprefixed group name
606 %A  Current article number
607 %z  Current article score
608 %V  Gnus version
609 %U  Number of unread articles in the group
610 %e  Number of unselected articles in the group
611 %Z  A string with unread/unselected article counts
612 %g  Shortish group name
613 %S  Subject of the current article
614 %u  User-defined spec
615 %s  Current score file name
616 %d  Number of dormant articles
617 %r  Number of articles that have been marked as read in this session
618 %E  Number of articles expunged by the score files"
619   :group 'gnus-summary-format
620   :type 'string)
621
622 (defcustom gnus-list-identifiers nil
623   "Regexp that matches list identifiers to be removed from subject.
624 This can also be a list of regexps."
625   :version "21.1"
626   :group 'gnus-summary-format
627   :group 'gnus-article-hiding
628   :type '(choice (const :tag "none" nil)
629                  (regexp :value ".*")
630                  (repeat :value (".*") regexp)))
631
632 (defcustom gnus-summary-mark-below 0
633   "*Mark all articles with a score below this variable as read.
634 This variable is local to each summary buffer and usually set by the
635 score file."
636   :group 'gnus-score-default
637   :type 'integer)
638
639 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
640   "*List of functions used for sorting articles in the summary buffer.
641
642 Each function takes two articles and returns non-nil if the first
643 article should be sorted before the other.  If you use more than one
644 function, the primary sort function should be the last.  You should
645 probably always include `gnus-article-sort-by-number' in the list of
646 sorting functions -- preferably first.  Also note that sorting by date
647 is often much slower than sorting by number, and the sorting order is
648 very similar.  (Sorting by date means sorting by the time the message
649 was sent, sorting by number means sorting by arrival time.)
650
651 Ready-made functions include `gnus-article-sort-by-number',
652 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
653 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
654 and `gnus-article-sort-by-score'.
655
656 When threading is turned on, the variable `gnus-thread-sort-functions'
657 controls how articles are sorted."
658   :group 'gnus-summary-sort
659   :type '(repeat (choice (function-item gnus-article-sort-by-number)
660                          (function-item gnus-article-sort-by-author)
661                          (function-item gnus-article-sort-by-subject)
662                          (function-item gnus-article-sort-by-date)
663                          (function-item gnus-article-sort-by-score)
664                          (function-item gnus-article-sort-by-random)
665                          (function :tag "other"))))
666
667 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
668   "*List of functions used for sorting threads in the summary buffer.
669 By default, threads are sorted by article number.
670
671 Each function takes two threads and returns non-nil if the first
672 thread should be sorted before the other.  If you use more than one
673 function, the primary sort function should be the last.  You should
674 probably always include `gnus-thread-sort-by-number' in the list of
675 sorting functions -- preferably first.  Also note that sorting by date
676 is often much slower than sorting by number, and the sorting order is
677 very similar.  (Sorting by date means sorting by the time the message
678 was sent, sorting by number means sorting by arrival time.)
679
680 Ready-made functions include `gnus-thread-sort-by-number',
681 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
682 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
683 `gnus-thread-sort-by-most-recent-number',
684 `gnus-thread-sort-by-most-recent-date',
685 `gnus-thread-sort-by-random', and
686 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
687
688 When threading is turned off, the variable
689 `gnus-article-sort-functions' controls how articles are sorted."
690   :group 'gnus-summary-sort
691   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
692                          (function-item gnus-thread-sort-by-author)
693                          (function-item gnus-thread-sort-by-subject)
694                          (function-item gnus-thread-sort-by-date)
695                          (function-item gnus-thread-sort-by-score)
696                          (function-item gnus-thread-sort-by-total-score)
697                          (function-item gnus-thread-sort-by-random)
698                          (function :tag "other"))))
699
700 (defcustom gnus-thread-score-function '+
701   "*Function used for calculating the total score of a thread.
702
703 The function is called with the scores of the article and each
704 subthread and should then return the score of the thread.
705
706 Some functions you can use are `+', `max', or `min'."
707   :group 'gnus-summary-sort
708   :type 'function)
709
710 (defcustom gnus-summary-expunge-below nil
711   "All articles that have a score less than this variable will be expunged.
712 This variable is local to the summary buffers."
713   :group 'gnus-score-default
714   :type '(choice (const :tag "off" nil)
715                  integer))
716
717 (defcustom gnus-thread-expunge-below nil
718   "All threads that have a total score less than this variable will be expunged.
719 See `gnus-thread-score-function' for en explanation of what a
720 \"thread score\" is.
721
722 This variable is local to the summary buffers."
723   :group 'gnus-threading
724   :group 'gnus-score-default
725   :type '(choice (const :tag "off" nil)
726                  integer))
727
728 (defcustom gnus-summary-mode-hook nil
729   "*A hook for Gnus summary mode.
730 This hook is run before any variables are set in the summary buffer."
731   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
732   :group 'gnus-summary-various
733   :type 'hook)
734
735 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
736 (when (featurep 'xemacs)
737   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
738   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
739   (add-hook 'gnus-summary-mode-hook
740             'gnus-xmas-switch-horizontal-scrollbar-off))
741
742 (defcustom gnus-summary-menu-hook nil
743   "*Hook run after the creation of the summary mode menu."
744   :group 'gnus-summary-visual
745   :type 'hook)
746
747 (defcustom gnus-summary-exit-hook nil
748   "*A hook called on exit from the summary buffer.
749 It will be called with point in the group buffer."
750   :group 'gnus-summary-exit
751   :type 'hook)
752
753 (defcustom gnus-summary-prepare-hook nil
754   "*A hook called after the summary buffer has been generated.
755 If you want to modify the summary buffer, you can use this hook."
756   :group 'gnus-summary-various
757   :type 'hook)
758
759 (defcustom gnus-summary-prepared-hook nil
760   "*A hook called as the last thing after the summary buffer has been generated."
761   :group 'gnus-summary-various
762   :type 'hook)
763
764 (defcustom gnus-summary-generate-hook nil
765   "*A hook run just before generating the summary buffer.
766 This hook is commonly used to customize threading variables and the
767 like."
768   :group 'gnus-summary-various
769   :type 'hook)
770
771 (defcustom gnus-select-group-hook nil
772   "*A hook called when a newsgroup is selected.
773
774 If you'd like to simplify subjects like the
775 `gnus-summary-next-same-subject' command does, you can use the
776 following hook:
777
778  (add-hook gnus-select-group-hook
779            (lambda ()
780              (mapcar (lambda (header)
781                        (mail-header-set-subject
782                         header
783                         (gnus-simplify-subject
784                          (mail-header-subject header) 're-only)))
785                      gnus-newsgroup-headers)))"
786   :group 'gnus-group-select
787   :type 'hook)
788
789 (defcustom gnus-select-article-hook nil
790   "*A hook called when an article is selected."
791   :group 'gnus-summary-choose
792   :type 'hook)
793
794 (defcustom gnus-visual-mark-article-hook
795   (list 'gnus-highlight-selected-summary)
796   "*Hook run after selecting an article in the summary buffer.
797 It is meant to be used for highlighting the article in some way.  It
798 is not run if `gnus-visual' is nil."
799   :group 'gnus-summary-visual
800   :type 'hook)
801
802 (defcustom gnus-parse-headers-hook nil
803   "*A hook called before parsing the headers."
804   :group 'gnus-various
805   :type 'hook)
806
807 (defcustom gnus-exit-group-hook nil
808   "*A hook called when exiting summary mode.
809 This hook is not called from the non-updating exit commands like `Q'."
810   :group 'gnus-various
811   :type 'hook)
812
813 (defcustom gnus-summary-update-hook
814   (list 'gnus-summary-highlight-line)
815   "*A hook called when a summary line is changed.
816 The hook will not be called if `gnus-visual' is nil.
817
818 The default function `gnus-summary-highlight-line' will
819 highlight the line according to the `gnus-summary-highlight'
820 variable."
821   :group 'gnus-summary-visual
822   :type 'hook)
823
824 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
825   "*A hook called when an article is selected for the first time.
826 The hook is intended to mark an article as read (or unread)
827 automatically when it is selected."
828   :group 'gnus-summary-choose
829   :type 'hook)
830
831 (defcustom gnus-group-no-more-groups-hook nil
832   "*A hook run when returning to group mode having no more (unread) groups."
833   :group 'gnus-group-select
834   :type 'hook)
835
836 (defcustom gnus-ps-print-hook nil
837   "*A hook run before ps-printing something from Gnus."
838   :group 'gnus-summary
839   :type 'hook)
840
841 (defcustom gnus-summary-display-arrow
842   (and (fboundp 'display-graphic-p)
843        (display-graphic-p))
844   "*If non-nil, display an arrow highlighting the current article."
845   :version "21.1"
846   :group 'gnus-summary
847   :type 'boolean)
848
849 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
850   "Face used for highlighting the current article in the summary buffer."
851   :group 'gnus-summary-visual
852   :type 'face)
853
854 (defvar gnus-tmp-downloaded nil)
855
856 (defcustom gnus-summary-highlight
857   '(((eq mark gnus-canceled-mark)
858      . gnus-summary-cancelled-face)
859     ((and uncached (> score default-high))
860      . gnus-summary-high-uncached-face)
861     ((and uncached (< score default-low))
862      . gnus-summary-low-uncached-face)
863     (uncached
864      . gnus-summary-normal-uncached-face)
865     ((and (> score default-high)
866           (or (eq mark gnus-dormant-mark)
867               (eq mark gnus-ticked-mark)))
868      . gnus-summary-high-ticked-face)
869     ((and (< score default-low)
870           (or (eq mark gnus-dormant-mark)
871               (eq mark gnus-ticked-mark)))
872      . gnus-summary-low-ticked-face)
873     ((or (eq mark gnus-dormant-mark)
874          (eq mark gnus-ticked-mark))
875      . gnus-summary-normal-ticked-face)
876     ((and (> score default-high) (eq mark gnus-ancient-mark))
877      . gnus-summary-high-ancient-face)
878     ((and (< score default-low) (eq mark gnus-ancient-mark))
879      . gnus-summary-low-ancient-face)
880     ((eq mark gnus-ancient-mark)
881      . gnus-summary-normal-ancient-face)
882     ((and (> score default-high) (eq mark gnus-unread-mark))
883      . gnus-summary-high-unread-face)
884     ((and (< score default-low) (eq mark gnus-unread-mark))
885      . gnus-summary-low-unread-face)
886     ((eq mark gnus-unread-mark)
887      . gnus-summary-normal-unread-face)
888     ((> score default-high)
889      . gnus-summary-high-read-face)
890     ((< score default-low)
891      . gnus-summary-low-read-face)
892     (t
893      . gnus-summary-normal-read-face))
894   "*Controls the highlighting of summary buffer lines.
895
896 A list of (FORM . FACE) pairs.  When deciding how a a particular
897 summary line should be displayed, each form is evaluated.  The content
898 of the face field after the first true form is used.  You can change
899 how those summary lines are displayed, by editing the face field.
900
901 You can use the following variables in the FORM field.
902
903 score:        The article's score
904 default:      The default article score.
905 default-high: The default score for high scored articles.
906 default-low:  The default score for low scored articles.
907 below:        The score below which articles are automatically marked as read.
908 mark:         The articles mark."
909   :group 'gnus-summary-visual
910   :type '(repeat (cons (sexp :tag "Form" nil)
911                        face)))
912
913 (defcustom gnus-alter-header-function nil
914   "Function called to allow alteration of article header structures.
915 The function is called with one parameter, the article header vector,
916 which it may alter in any way.")
917
918 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
919   "Variable that says which function should be used to decode a string with encoded words.")
920
921 (defcustom gnus-extra-headers '(To Newsgroups)
922   "*Extra headers to parse."
923   :version "21.1"
924   :group 'gnus-summary
925   :type '(repeat symbol))
926
927 (defcustom gnus-ignored-from-addresses
928   (and user-mail-address (regexp-quote user-mail-address))
929   "*Regexp of From headers that may be suppressed in favor of To headers."
930   :version "21.1"
931   :group 'gnus-summary
932   :type 'regexp)
933
934 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
935   "List of charsets that should be ignored.
936 When these charsets are used in the \"charset\" parameter, the
937 default charset will be used instead."
938   :version "21.1"
939   :type '(repeat symbol)
940   :group 'gnus-charset)
941
942 (gnus-define-group-parameter
943  ignored-charsets
944  :type list
945  :function-document
946  "Return the ignored charsets of GROUP."
947  :variable gnus-group-ignored-charsets-alist
948  :variable-default
949  '(("alt\\.chinese\\.text" iso-8859-1))
950  :variable-document
951  "Alist of regexps (to match group names) and charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954  :variable-group gnus-charset
955  :variable-type '(repeat (cons (regexp :tag "Group")
956                                (repeat symbol)))
957  :parameter-type '(choice :tag "Ignored charsets"
958                           :value nil
959                           (repeat (symbol)))
960  :parameter-document       "\
961 List of charsets that should be ignored.
962
963 When these charsets are used in the \"charset\" parameter, the
964 default charset will be used instead.")
965
966 (defcustom gnus-group-highlight-words-alist nil
967   "Alist of group regexps and highlight regexps.
968 This variable uses the same syntax as `gnus-emphasis-alist'."
969   :version "21.1"
970   :type '(repeat (cons (regexp :tag "Group")
971                        (repeat (list (regexp :tag "Highlight regexp")
972                                      (number :tag "Group for entire word" 0)
973                                      (number :tag "Group for displayed part" 0)
974                                      (symbol :tag "Face"
975                                              gnus-emphasis-highlight-words)))))
976   :group 'gnus-summary-visual)
977
978 (defcustom gnus-summary-show-article-charset-alist
979   nil
980   "Alist of number and charset.
981 The article will be shown with the charset corresponding to the
982 numbered argument.
983 For example: ((1 . cn-gb-2312) (2 . big5))."
984   :version "21.1"
985   :type '(repeat (cons (number :tag "Argument" 1)
986                        (symbol :tag "Charset")))
987   :group 'gnus-charset)
988
989 (defcustom gnus-preserve-marks t
990   "Whether marks are preserved when moving, copying and respooling messages."
991   :version "21.1"
992   :type 'boolean
993   :group 'gnus-summary-marks)
994
995 (defcustom gnus-alter-articles-to-read-function nil
996   "Function to be called to alter the list of articles to be selected."
997   :type '(choice (const nil) function)
998   :group 'gnus-summary)
999
1000 (defcustom gnus-orphan-score nil
1001   "*All orphans get this score added.  Set in the score file."
1002   :group 'gnus-score-default
1003   :type '(choice (const nil)
1004                  integer))
1005
1006 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1007   "*A regexp to match MIME parts when saving multiple parts of a message
1008 with gnus-summary-save-parts (X m). This regexp will be used by default
1009 when prompting the user for which type of files to save."
1010   :group 'gnus-summary
1011   :type 'regexp)
1012
1013 (defcustom gnus-read-all-available-headers nil
1014   "Whether Gnus should parse all headers made available to it.
1015 This is mostly relevant for slow backends where the user may
1016 wish to widen the summary buffer to include all headers
1017 that were fetched.  Say, for nnultimate groups."
1018   :group 'gnus-summary
1019   :type '(choice boolean regexp))
1020
1021 (defcustom gnus-summary-muttprint-program "muttprint"
1022   "Command (and optional arguments) used to run Muttprint."
1023   :version "21.3"
1024   :group 'gnus-summary
1025   :type 'string)
1026
1027 (defcustom gnus-article-loose-mime nil
1028   "If non-nil, don't require MIME-Version header.
1029 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1030 supply the MIME-Version header or deliberately strip it From the mail.
1031 Set it to non-nil, Gnus will treat some articles as MIME even if
1032 the MIME-Version header is missed."
1033   :version "21.3"
1034   :type 'boolean
1035   :group 'gnus-article)
1036
1037 ;;; Internal variables
1038
1039 (defvar gnus-summary-display-cache nil)
1040 (defvar gnus-article-mime-handles nil)
1041 (defvar gnus-article-decoded-p nil)
1042 (defvar gnus-article-charset nil)
1043 (defvar gnus-article-ignored-charsets nil)
1044 (defvar gnus-scores-exclude-files nil)
1045 (defvar gnus-page-broken nil)
1046
1047 (defvar gnus-original-article nil)
1048 (defvar gnus-article-internal-prepare-hook nil)
1049 (defvar gnus-newsgroup-process-stack nil)
1050
1051 (defvar gnus-thread-indent-array nil)
1052 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1053 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1054   "Function called to sort the articles within a thread after it has been gathered together.")
1055
1056 (defvar gnus-summary-save-parts-type-history nil)
1057 (defvar gnus-summary-save-parts-last-directory nil)
1058
1059 ;; Avoid highlighting in kill files.
1060 (defvar gnus-summary-inhibit-highlight nil)
1061 (defvar gnus-newsgroup-selected-overlay nil)
1062 (defvar gnus-inhibit-limiting nil)
1063 (defvar gnus-newsgroup-adaptive-score-file nil)
1064 (defvar gnus-current-score-file nil)
1065 (defvar gnus-current-move-group nil)
1066 (defvar gnus-current-copy-group nil)
1067 (defvar gnus-current-crosspost-group nil)
1068 (defvar gnus-newsgroup-display nil)
1069
1070 (defvar gnus-newsgroup-dependencies nil)
1071 (defvar gnus-newsgroup-adaptive nil)
1072 (defvar gnus-summary-display-article-function nil)
1073 (defvar gnus-summary-highlight-line-function nil
1074   "Function called after highlighting a summary line.")
1075
1076 (defvar gnus-summary-line-format-alist
1077   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1078     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1079     (?s gnus-tmp-subject-or-nil ?s)
1080     (?n gnus-tmp-name ?s)
1081     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1082         ?s)
1083     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1084             gnus-tmp-from) ?s)
1085     (?F gnus-tmp-from ?s)
1086     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1087     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1088     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1089     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1090     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1091     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1092     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1093     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1094     (?L gnus-tmp-lines ?s)
1095     (?O gnus-tmp-downloaded ?c)
1096     (?I gnus-tmp-indentation ?s)
1097     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1098     (?R gnus-tmp-replied ?c)
1099     (?\[ gnus-tmp-opening-bracket ?c)
1100     (?\] gnus-tmp-closing-bracket ?c)
1101     (?\> (make-string gnus-tmp-level ? ) ?s)
1102     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1103     (?i gnus-tmp-score ?d)
1104     (?z gnus-tmp-score-char ?c)
1105     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1106     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1107     (?U gnus-tmp-unread ?c)
1108     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1109         ?s)
1110     (?t (gnus-summary-number-of-articles-in-thread
1111          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1112         ?d)
1113     (?e (gnus-summary-number-of-articles-in-thread
1114          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1115         ?c)
1116     (?u gnus-tmp-user-defined ?s)
1117     (?P (gnus-pick-line-number) ?d)
1118     (?B gnus-tmp-thread-tree-header-string ?s)
1119     (user-date (gnus-user-date
1120                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1121   "An alist of format specifications that can appear in summary lines.
1122 These are paired with what variables they correspond with, along with
1123 the type of the variable (string, integer, character, etc).")
1124
1125 (defvar gnus-summary-dummy-line-format-alist
1126   `((?S gnus-tmp-subject ?s)
1127     (?N gnus-tmp-number ?d)
1128     (?u gnus-tmp-user-defined ?s)))
1129
1130 (defvar gnus-summary-mode-line-format-alist
1131   `((?G gnus-tmp-group-name ?s)
1132     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1133     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1134     (?A gnus-tmp-article-number ?d)
1135     (?Z gnus-tmp-unread-and-unselected ?s)
1136     (?V gnus-version ?s)
1137     (?U gnus-tmp-unread-and-unticked ?d)
1138     (?S gnus-tmp-subject ?s)
1139     (?e gnus-tmp-unselected ?d)
1140     (?u gnus-tmp-user-defined ?s)
1141     (?d (length gnus-newsgroup-dormant) ?d)
1142     (?t (length gnus-newsgroup-marked) ?d)
1143     (?h (length gnus-newsgroup-spam-marked) ?d)
1144     (?r (length gnus-newsgroup-reads) ?d)
1145     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1146     (?E gnus-newsgroup-expunged-tally ?d)
1147     (?s (gnus-current-score-file-nondirectory) ?s)))
1148
1149 (defvar gnus-last-search-regexp nil
1150   "Default regexp for article search command.")
1151
1152 (defvar gnus-last-shell-command nil
1153   "Default shell command on article.")
1154
1155 (defvar gnus-newsgroup-agentized nil
1156   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1157 (defvar gnus-newsgroup-begin nil)
1158 (defvar gnus-newsgroup-end nil)
1159 (defvar gnus-newsgroup-last-rmail nil)
1160 (defvar gnus-newsgroup-last-mail nil)
1161 (defvar gnus-newsgroup-last-folder nil)
1162 (defvar gnus-newsgroup-last-file nil)
1163 (defvar gnus-newsgroup-auto-expire nil)
1164 (defvar gnus-newsgroup-active nil)
1165
1166 (defvar gnus-newsgroup-data nil)
1167 (defvar gnus-newsgroup-data-reverse nil)
1168 (defvar gnus-newsgroup-limit nil)
1169 (defvar gnus-newsgroup-limits nil)
1170
1171 (defvar gnus-newsgroup-unreads nil
1172   "Sorted list of unread articles in the current newsgroup.")
1173
1174 (defvar gnus-newsgroup-unselected nil
1175   "Sorted list of unselected unread articles in the current newsgroup.")
1176
1177 (defvar gnus-newsgroup-reads nil
1178   "Alist of read articles and article marks in the current newsgroup.")
1179
1180 (defvar gnus-newsgroup-expunged-tally nil)
1181
1182 (defvar gnus-newsgroup-marked nil
1183   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1184
1185 (defvar gnus-newsgroup-spam-marked nil
1186   "List of ranges of articles that have been marked as spam.")
1187
1188 (defvar gnus-newsgroup-killed nil
1189   "List of ranges of articles that have been through the scoring process.")
1190
1191 (defvar gnus-newsgroup-cached nil
1192   "Sorted list of articles that come from the article cache.")
1193
1194 (defvar gnus-newsgroup-saved nil
1195   "List of articles that have been saved.")
1196
1197 (defvar gnus-newsgroup-kill-headers nil)
1198
1199 (defvar gnus-newsgroup-replied nil
1200   "List of articles that have been replied to in the current newsgroup.")
1201
1202 (defvar gnus-newsgroup-forwarded nil
1203   "List of articles that have been forwarded in the current newsgroup.")
1204
1205 (defvar gnus-newsgroup-recent nil
1206   "List of articles that have are recent in the current newsgroup.")
1207
1208 (defvar gnus-newsgroup-expirable nil
1209   "Sorted list of articles in the current newsgroup that can be expired.")
1210
1211 (defvar gnus-newsgroup-processable nil
1212   "List of articles in the current newsgroup that can be processed.")
1213
1214 (defvar gnus-newsgroup-downloadable nil
1215   "Sorted list of articles in the current newsgroup that can be processed.")
1216
1217 (defvar gnus-newsgroup-undownloaded nil
1218   "List of articles in the current newsgroup that haven't been downloaded..")
1219
1220 (defvar gnus-newsgroup-unsendable nil
1221   "List of articles in the current newsgroup that won't be sent.")
1222
1223 (defvar gnus-newsgroup-bookmarks nil
1224   "List of articles in the current newsgroup that have bookmarks.")
1225
1226 (defvar gnus-newsgroup-dormant nil
1227   "Sorted list of dormant articles in the current newsgroup.")
1228
1229 (defvar gnus-newsgroup-unseen nil
1230   "List of unseen articles in the current newsgroup.")
1231
1232 (defvar gnus-newsgroup-seen nil
1233   "Range of seen articles in the current newsgroup.")
1234
1235 (defvar gnus-newsgroup-articles nil
1236   "List of articles in the current newsgroup.")
1237
1238 (defvar gnus-newsgroup-scored nil
1239   "List of scored articles in the current newsgroup.")
1240
1241 (defvar gnus-newsgroup-headers nil
1242   "List of article headers in the current newsgroup.")
1243
1244 (defvar gnus-newsgroup-threads nil)
1245
1246 (defvar gnus-newsgroup-prepared nil
1247   "Whether the current group has been prepared properly.")
1248
1249 (defvar gnus-newsgroup-ancient nil
1250   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1251
1252 (defvar gnus-newsgroup-sparse nil)
1253
1254 (defvar gnus-current-article nil)
1255 (defvar gnus-article-current nil)
1256 (defvar gnus-current-headers nil)
1257 (defvar gnus-have-all-headers nil)
1258 (defvar gnus-last-article nil)
1259 (defvar gnus-newsgroup-history nil)
1260 (defvar gnus-newsgroup-charset nil)
1261 (defvar gnus-newsgroup-ephemeral-charset nil)
1262 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1263
1264 (defvar gnus-article-before-search nil)
1265
1266 (defconst gnus-summary-local-variables
1267   '(gnus-newsgroup-name
1268     gnus-newsgroup-begin gnus-newsgroup-end
1269     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1270     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1271     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1272     gnus-newsgroup-unselected gnus-newsgroup-marked
1273     gnus-newsgroup-spam-marked
1274     gnus-newsgroup-reads gnus-newsgroup-saved
1275     gnus-newsgroup-replied gnus-newsgroup-forwarded
1276     gnus-newsgroup-recent
1277     gnus-newsgroup-expirable
1278     gnus-newsgroup-processable gnus-newsgroup-killed
1279     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1280     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1281     gnus-newsgroup-seen gnus-newsgroup-articles
1282     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1283     gnus-newsgroup-headers gnus-newsgroup-threads
1284     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1285     gnus-current-article gnus-current-headers gnus-have-all-headers
1286     gnus-last-article gnus-article-internal-prepare-hook
1287     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1288     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1289     gnus-thread-expunge-below
1290     gnus-score-alist gnus-current-score-file
1291     (gnus-summary-expunge-below . global)
1292     (gnus-summary-mark-below . global)
1293     (gnus-orphan-score . global)
1294     gnus-newsgroup-active gnus-scores-exclude-files
1295     gnus-newsgroup-history gnus-newsgroup-ancient
1296     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1297     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1298     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1299     (gnus-newsgroup-expunged-tally . 0)
1300     gnus-cache-removable-articles gnus-newsgroup-cached
1301     gnus-newsgroup-data gnus-newsgroup-data-reverse
1302     gnus-newsgroup-limit gnus-newsgroup-limits
1303     gnus-newsgroup-charset gnus-newsgroup-display)
1304   "Variables that are buffer-local to the summary buffers.")
1305
1306 (defvar gnus-newsgroup-variables nil
1307   "A list of variables that have separate values in different newsgroups.
1308 A list of newsgroup (summary buffer) local variables, or cons of
1309 variables and their default values (when the default values are not
1310 nil), that should be made global while the summary buffer is active.
1311 These variables can be used to set variables in the group parameters
1312 while still allowing them to affect operations done in other
1313 buffers. For example:
1314
1315 \(setq gnus-newsgroup-variables
1316      '(message-use-followup-to
1317        (gnus-visible-headers .
1318          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1319 ")
1320
1321 ;; Byte-compiler warning.
1322 (eval-when-compile (defvar gnus-article-mode-map))
1323
1324 ;; MIME stuff.
1325
1326 (defvar gnus-decode-encoded-word-methods
1327   '(mail-decode-encoded-word-string)
1328   "List of methods used to decode encoded words.
1329
1330 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1331 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1332 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1333 whose names match REGEXP.
1334
1335 For example:
1336 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1337  mail-decode-encoded-word-string
1338  (\"chinese\" . rfc1843-decode-string))")
1339
1340 (defvar gnus-decode-encoded-word-methods-cache nil)
1341
1342 (defun gnus-multi-decode-encoded-word-string (string)
1343   "Apply the functions from `gnus-encoded-word-methods' that match."
1344   (unless (and gnus-decode-encoded-word-methods-cache
1345                (eq gnus-newsgroup-name
1346                    (car gnus-decode-encoded-word-methods-cache)))
1347     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1348     (mapcar (lambda (x)
1349               (if (symbolp x)
1350                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1351                 (if (and gnus-newsgroup-name
1352                          (string-match (car x) gnus-newsgroup-name))
1353                     (nconc gnus-decode-encoded-word-methods-cache
1354                            (list (cdr x))))))
1355             gnus-decode-encoded-word-methods))
1356   (let ((xlist gnus-decode-encoded-word-methods-cache))
1357     (pop xlist)
1358     (while xlist
1359       (setq string (funcall (pop xlist) string))))
1360   string)
1361
1362 ;; Subject simplification.
1363
1364 (defun gnus-simplify-whitespace (str)
1365   "Remove excessive whitespace from STR."
1366   (let ((mystr str))
1367     ;; Multiple spaces.
1368     (while (string-match "[ \t][ \t]+" mystr)
1369       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1370                           " "
1371                           (substring mystr (match-end 0)))))
1372     ;; Leading spaces.
1373     (when (string-match "^[ \t]+" mystr)
1374       (setq mystr (substring mystr (match-end 0))))
1375     ;; Trailing spaces.
1376     (when (string-match "[ \t]+$" mystr)
1377       (setq mystr (substring mystr 0 (match-beginning 0))))
1378     mystr))
1379
1380 (defun gnus-simplify-all-whitespace (str)
1381   "Remove all whitespace from STR."
1382   (let ((mystr str))
1383     (while (string-match "[ \t\n]+" mystr)
1384       (setq mystr (replace-match "" nil nil mystr)))
1385     mystr))
1386
1387 (defsubst gnus-simplify-subject-re (subject)
1388   "Remove \"Re:\" from subject lines."
1389   (if (string-match message-subject-re-regexp subject)
1390       (substring subject (match-end 0))
1391     subject))
1392
1393 (defun gnus-simplify-subject (subject &optional re-only)
1394   "Remove `Re:' and words in parentheses.
1395 If RE-ONLY is non-nil, strip leading `Re:'s only."
1396   (let ((case-fold-search t))           ;Ignore case.
1397     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1398     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1399       (setq subject (substring subject (match-end 0))))
1400     ;; Remove uninteresting prefixes.
1401     (when (and (not re-only)
1402                gnus-simplify-ignored-prefixes
1403                (string-match gnus-simplify-ignored-prefixes subject))
1404       (setq subject (substring subject (match-end 0))))
1405     ;; Remove words in parentheses from end.
1406     (unless re-only
1407       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1408         (setq subject (substring subject 0 (match-beginning 0)))))
1409     ;; Return subject string.
1410     subject))
1411
1412 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1413 ;; all whitespace.
1414 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1415   (goto-char (point-min))
1416   (while (re-search-forward regexp nil t)
1417     (replace-match (or newtext ""))))
1418
1419 (defun gnus-simplify-buffer-fuzzy ()
1420   "Simplify string in the buffer fuzzily.
1421 The string in the accessible portion of the current buffer is simplified.
1422 It is assumed to be a single-line subject.
1423 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1424 matter is removed.  Additional things can be deleted by setting
1425 `gnus-simplify-subject-fuzzy-regexp'."
1426   (let ((case-fold-search t)
1427         (modified-tick))
1428     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1429
1430     (while (not (eq modified-tick (buffer-modified-tick)))
1431       (setq modified-tick (buffer-modified-tick))
1432       (cond
1433        ((listp gnus-simplify-subject-fuzzy-regexp)
1434         (mapcar 'gnus-simplify-buffer-fuzzy-step
1435                 gnus-simplify-subject-fuzzy-regexp))
1436        (gnus-simplify-subject-fuzzy-regexp
1437         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1438       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1439       (gnus-simplify-buffer-fuzzy-step
1440        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1441       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1442
1443     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1444     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1445     (gnus-simplify-buffer-fuzzy-step " $")
1446     (gnus-simplify-buffer-fuzzy-step "^ +")))
1447
1448 (defun gnus-simplify-subject-fuzzy (subject)
1449   "Simplify a subject string fuzzily.
1450 See `gnus-simplify-buffer-fuzzy' for details."
1451   (save-excursion
1452     (gnus-set-work-buffer)
1453     (let ((case-fold-search t))
1454       ;; Remove uninteresting prefixes.
1455       (when (and gnus-simplify-ignored-prefixes
1456                  (string-match gnus-simplify-ignored-prefixes subject))
1457         (setq subject (substring subject (match-end 0))))
1458       (insert subject)
1459       (inline (gnus-simplify-buffer-fuzzy))
1460       (buffer-string))))
1461
1462 (defsubst gnus-simplify-subject-fully (subject)
1463   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1464   (cond
1465    (gnus-simplify-subject-functions
1466     (gnus-map-function gnus-simplify-subject-functions subject))
1467    ((null gnus-summary-gather-subject-limit)
1468     (gnus-simplify-subject-re subject))
1469    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1470     (gnus-simplify-subject-fuzzy subject))
1471    ((numberp gnus-summary-gather-subject-limit)
1472     (gnus-limit-string (gnus-simplify-subject-re subject)
1473                        gnus-summary-gather-subject-limit))
1474    (t
1475     subject)))
1476
1477 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1478   "Check whether two subjects are equal.
1479 If optional argument simple-first is t, first argument is already
1480 simplified."
1481   (cond
1482    ((null simple-first)
1483     (equal (gnus-simplify-subject-fully s1)
1484            (gnus-simplify-subject-fully s2)))
1485    (t
1486     (equal s1
1487            (gnus-simplify-subject-fully s2)))))
1488
1489 (defun gnus-summary-bubble-group ()
1490   "Increase the score of the current group.
1491 This is a handy function to add to `gnus-summary-exit-hook' to
1492 increase the score of each group you read."
1493   (gnus-group-add-score gnus-newsgroup-name))
1494
1495 \f
1496 ;;;
1497 ;;; Gnus summary mode
1498 ;;;
1499
1500 (put 'gnus-summary-mode 'mode-class 'special)
1501
1502 (defvar gnus-article-commands-menu)
1503
1504 (when t
1505   ;; Non-orthogonal keys
1506
1507   (gnus-define-keys gnus-summary-mode-map
1508     " " gnus-summary-next-page
1509     "\177" gnus-summary-prev-page
1510     [delete] gnus-summary-prev-page
1511     [backspace] gnus-summary-prev-page
1512     "\r" gnus-summary-scroll-up
1513     "\M-\r" gnus-summary-scroll-down
1514     "n" gnus-summary-next-unread-article
1515     "p" gnus-summary-prev-unread-article
1516     "N" gnus-summary-next-article
1517     "P" gnus-summary-prev-article
1518     "\M-\C-n" gnus-summary-next-same-subject
1519     "\M-\C-p" gnus-summary-prev-same-subject
1520     "\M-n" gnus-summary-next-unread-subject
1521     "\M-p" gnus-summary-prev-unread-subject
1522     "." gnus-summary-first-unread-article
1523     "," gnus-summary-best-unread-article
1524     "\M-s" gnus-summary-search-article-forward
1525     "\M-r" gnus-summary-search-article-backward
1526     "<" gnus-summary-beginning-of-article
1527     ">" gnus-summary-end-of-article
1528     "j" gnus-summary-goto-article
1529     "^" gnus-summary-refer-parent-article
1530     "\M-^" gnus-summary-refer-article
1531     "u" gnus-summary-tick-article-forward
1532     "!" gnus-summary-tick-article-forward
1533     "U" gnus-summary-tick-article-backward
1534     "d" gnus-summary-mark-as-read-forward
1535     "D" gnus-summary-mark-as-read-backward
1536     "E" gnus-summary-mark-as-expirable
1537     "\M-u" gnus-summary-clear-mark-forward
1538     "\M-U" gnus-summary-clear-mark-backward
1539     "k" gnus-summary-kill-same-subject-and-select
1540     "\C-k" gnus-summary-kill-same-subject
1541     "\M-\C-k" gnus-summary-kill-thread
1542     "\M-\C-l" gnus-summary-lower-thread
1543     "e" gnus-summary-edit-article
1544     "#" gnus-summary-mark-as-processable
1545     "\M-#" gnus-summary-unmark-as-processable
1546     "\M-\C-t" gnus-summary-toggle-threads
1547     "\M-\C-s" gnus-summary-show-thread
1548     "\M-\C-h" gnus-summary-hide-thread
1549     "\M-\C-f" gnus-summary-next-thread
1550     "\M-\C-b" gnus-summary-prev-thread
1551     [(meta down)] gnus-summary-next-thread
1552     [(meta up)] gnus-summary-prev-thread
1553     "\M-\C-u" gnus-summary-up-thread
1554     "\M-\C-d" gnus-summary-down-thread
1555     "&" gnus-summary-execute-command
1556     "c" gnus-summary-catchup-and-exit
1557     "\C-w" gnus-summary-mark-region-as-read
1558     "\C-t" gnus-summary-toggle-truncation
1559     "?" gnus-summary-mark-as-dormant
1560     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1561     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1562     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1563     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1564     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1565     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1566     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1567     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1568     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1569     "\C-c\C-s\C-r" gnus-summary-sort-by-random
1570     "=" gnus-summary-expand-window
1571     "\C-x\C-s" gnus-summary-reselect-current-group
1572     "\M-g" gnus-summary-rescan-group
1573     "w" gnus-summary-stop-page-breaking
1574     "\C-c\C-r" gnus-summary-caesar-message
1575     "f" gnus-summary-followup
1576     "F" gnus-summary-followup-with-original
1577     "C" gnus-summary-cancel-article
1578     "r" gnus-summary-reply
1579     "R" gnus-summary-reply-with-original
1580     "\C-c\C-f" gnus-summary-mail-forward
1581     "o" gnus-summary-save-article
1582     "\C-o" gnus-summary-save-article-mail
1583     "|" gnus-summary-pipe-output
1584     "\M-k" gnus-summary-edit-local-kill
1585     "\M-K" gnus-summary-edit-global-kill
1586     ;; "V" gnus-version
1587     "\C-c\C-d" gnus-summary-describe-group
1588     "q" gnus-summary-exit
1589     "Q" gnus-summary-exit-no-update
1590     "\C-c\C-i" gnus-info-find-node
1591     gnus-mouse-2 gnus-mouse-pick-article
1592     "m" gnus-summary-mail-other-window
1593     "a" gnus-summary-post-news
1594     "i" gnus-summary-news-other-window
1595     "x" gnus-summary-limit-to-unread
1596     "s" gnus-summary-isearch-article
1597     "t" gnus-summary-toggle-header
1598     "g" gnus-summary-show-article
1599     "l" gnus-summary-goto-last-article
1600     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1601     "\C-d" gnus-summary-enter-digest-group
1602     "\M-\C-d" gnus-summary-read-document
1603     "\M-\C-e" gnus-summary-edit-parameters
1604     "\M-\C-a" gnus-summary-customize-parameters
1605     "\C-c\C-b" gnus-bug
1606     "*" gnus-cache-enter-article
1607     "\M-*" gnus-cache-remove-article
1608     "\M-&" gnus-summary-universal-argument
1609     "\C-l" gnus-recenter
1610     "I" gnus-summary-increase-score
1611     "L" gnus-summary-lower-score
1612     "\M-i" gnus-symbolic-argument
1613     "h" gnus-summary-select-article-buffer
1614
1615     "b" gnus-article-view-part
1616     "\M-t" gnus-summary-toggle-display-buttonized
1617
1618     "V" gnus-summary-score-map
1619     "X" gnus-uu-extract-map
1620     "S" gnus-summary-send-map)
1621
1622   ;; Sort of orthogonal keymap
1623   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1624     "t" gnus-summary-tick-article-forward
1625     "!" gnus-summary-tick-article-forward
1626     "d" gnus-summary-mark-as-read-forward
1627     "r" gnus-summary-mark-as-read-forward
1628     "c" gnus-summary-clear-mark-forward
1629     " " gnus-summary-clear-mark-forward
1630     "e" gnus-summary-mark-as-expirable
1631     "x" gnus-summary-mark-as-expirable
1632     "?" gnus-summary-mark-as-dormant
1633     "b" gnus-summary-set-bookmark
1634     "B" gnus-summary-remove-bookmark
1635     "#" gnus-summary-mark-as-processable
1636     "\M-#" gnus-summary-unmark-as-processable
1637     "S" gnus-summary-limit-include-expunged
1638     "C" gnus-summary-catchup
1639     "H" gnus-summary-catchup-to-here
1640     "h" gnus-summary-catchup-from-here
1641     "\C-c" gnus-summary-catchup-all
1642     "k" gnus-summary-kill-same-subject-and-select
1643     "K" gnus-summary-kill-same-subject
1644     "P" gnus-uu-mark-map)
1645
1646   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1647     "c" gnus-summary-clear-above
1648     "u" gnus-summary-tick-above
1649     "m" gnus-summary-mark-above
1650     "k" gnus-summary-kill-below)
1651
1652   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1653     "/" gnus-summary-limit-to-subject
1654     "n" gnus-summary-limit-to-articles
1655     "w" gnus-summary-pop-limit
1656     "s" gnus-summary-limit-to-subject
1657     "a" gnus-summary-limit-to-author
1658     "u" gnus-summary-limit-to-unread
1659     "m" gnus-summary-limit-to-marks
1660     "M" gnus-summary-limit-exclude-marks
1661     "v" gnus-summary-limit-to-score
1662     "*" gnus-summary-limit-include-cached
1663     "D" gnus-summary-limit-include-dormant
1664     "T" gnus-summary-limit-include-thread
1665     "d" gnus-summary-limit-exclude-dormant
1666     "t" gnus-summary-limit-to-age
1667     "." gnus-summary-limit-to-unseen
1668     "x" gnus-summary-limit-to-extra
1669     "p" gnus-summary-limit-to-display-predicate
1670     "E" gnus-summary-limit-include-expunged
1671     "c" gnus-summary-limit-exclude-childless-dormant
1672     "C" gnus-summary-limit-mark-excluded-as-read
1673     "o" gnus-summary-insert-old-articles
1674     "N" gnus-summary-insert-new-articles)
1675
1676   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1677     "n" gnus-summary-next-unread-article
1678     "p" gnus-summary-prev-unread-article
1679     "N" gnus-summary-next-article
1680     "P" gnus-summary-prev-article
1681     "\C-n" gnus-summary-next-same-subject
1682     "\C-p" gnus-summary-prev-same-subject
1683     "\M-n" gnus-summary-next-unread-subject
1684     "\M-p" gnus-summary-prev-unread-subject
1685     "f" gnus-summary-first-unread-article
1686     "b" gnus-summary-best-unread-article
1687     "j" gnus-summary-goto-article
1688     "g" gnus-summary-goto-subject
1689     "l" gnus-summary-goto-last-article
1690     "o" gnus-summary-pop-article)
1691
1692   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1693     "k" gnus-summary-kill-thread
1694     "l" gnus-summary-lower-thread
1695     "i" gnus-summary-raise-thread
1696     "T" gnus-summary-toggle-threads
1697     "t" gnus-summary-rethread-current
1698     "^" gnus-summary-reparent-thread
1699     "s" gnus-summary-show-thread
1700     "S" gnus-summary-show-all-threads
1701     "h" gnus-summary-hide-thread
1702     "H" gnus-summary-hide-all-threads
1703     "n" gnus-summary-next-thread
1704     "p" gnus-summary-prev-thread
1705     "u" gnus-summary-up-thread
1706     "o" gnus-summary-top-thread
1707     "d" gnus-summary-down-thread
1708     "#" gnus-uu-mark-thread
1709     "\M-#" gnus-uu-unmark-thread)
1710
1711   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1712     "g" gnus-summary-prepare
1713     "c" gnus-summary-insert-cached-articles)
1714
1715   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1716     "c" gnus-summary-catchup-and-exit
1717     "C" gnus-summary-catchup-all-and-exit
1718     "E" gnus-summary-exit-no-update
1719     "Q" gnus-summary-exit
1720     "Z" gnus-summary-exit
1721     "n" gnus-summary-catchup-and-goto-next-group
1722     "R" gnus-summary-reselect-current-group
1723     "G" gnus-summary-rescan-group
1724     "N" gnus-summary-next-group
1725     "s" gnus-summary-save-newsrc
1726     "P" gnus-summary-prev-group)
1727
1728   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1729     " " gnus-summary-next-page
1730     "n" gnus-summary-next-page
1731     "\177" gnus-summary-prev-page
1732     [delete] gnus-summary-prev-page
1733     "p" gnus-summary-prev-page
1734     "\r" gnus-summary-scroll-up
1735     "\M-\r" gnus-summary-scroll-down
1736     "<" gnus-summary-beginning-of-article
1737     ">" gnus-summary-end-of-article
1738     "b" gnus-summary-beginning-of-article
1739     "e" gnus-summary-end-of-article
1740     "^" gnus-summary-refer-parent-article
1741     "r" gnus-summary-refer-parent-article
1742     "D" gnus-summary-enter-digest-group
1743     "R" gnus-summary-refer-references
1744     "T" gnus-summary-refer-thread
1745     "g" gnus-summary-show-article
1746     "s" gnus-summary-isearch-article
1747     "P" gnus-summary-print-article
1748     "M" gnus-mailing-list-insinuate
1749     "t" gnus-article-babel)
1750
1751   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1752     "b" gnus-article-add-buttons
1753     "B" gnus-article-add-buttons-to-head
1754     "o" gnus-article-treat-overstrike
1755     "e" gnus-article-emphasize
1756     "w" gnus-article-fill-cited-article
1757     "Q" gnus-article-fill-long-lines
1758     "C" gnus-article-capitalize-sentences
1759     "c" gnus-article-remove-cr
1760     "q" gnus-article-de-quoted-unreadable
1761     "6" gnus-article-de-base64-unreadable
1762     "Z" gnus-article-decode-HZ
1763     "h" gnus-article-wash-html
1764     "u" gnus-article-unsplit-urls
1765     "s" gnus-summary-force-verify-and-decrypt
1766     "f" gnus-article-display-x-face
1767     "l" gnus-summary-stop-page-breaking
1768     "r" gnus-summary-caesar-message
1769     "m" gnus-summary-morse-message
1770     "t" gnus-summary-toggle-header
1771     "g" gnus-treat-smiley
1772     "v" gnus-summary-verbose-headers
1773     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1774     "p" gnus-article-verify-x-pgp-sig
1775     "d" gnus-article-treat-dumbquotes
1776     "k" gnus-article-outlook-deuglify-article)
1777
1778   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1779     "a" gnus-article-hide
1780     "h" gnus-article-hide-headers
1781     "b" gnus-article-hide-boring-headers
1782     "s" gnus-article-hide-signature
1783     "c" gnus-article-hide-citation
1784     "C" gnus-article-hide-citation-in-followups
1785     "l" gnus-article-hide-list-identifiers
1786     "p" gnus-article-hide-pgp
1787     "B" gnus-article-strip-banner
1788     "P" gnus-article-hide-pem
1789     "\C-c" gnus-article-hide-citation-maybe)
1790
1791   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1792     "a" gnus-article-highlight
1793     "h" gnus-article-highlight-headers
1794     "c" gnus-article-highlight-citation
1795     "s" gnus-article-highlight-signature)
1796
1797   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1798     "f" gnus-article-treat-fold-headers
1799     "u" gnus-article-treat-unfold-headers
1800     "n" gnus-article-treat-fold-newsgroups)
1801
1802   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1803     "x" gnus-article-display-x-face
1804     "s" gnus-treat-smiley
1805     "D" gnus-article-remove-images
1806     "f" gnus-treat-from-picon
1807     "m" gnus-treat-mail-picon
1808     "n" gnus-treat-newsgroups-picon)
1809
1810   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1811     "w" gnus-article-decode-mime-words
1812     "c" gnus-article-decode-charset
1813     "v" gnus-mime-view-all-parts
1814     "b" gnus-article-view-part)
1815
1816   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1817     "z" gnus-article-date-ut
1818     "u" gnus-article-date-ut
1819     "l" gnus-article-date-local
1820     "p" gnus-article-date-english
1821     "e" gnus-article-date-lapsed
1822     "o" gnus-article-date-original
1823     "i" gnus-article-date-iso8601
1824     "s" gnus-article-date-user)
1825
1826   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1827     "t" gnus-article-remove-trailing-blank-lines
1828     "l" gnus-article-strip-leading-blank-lines
1829     "m" gnus-article-strip-multiple-blank-lines
1830     "a" gnus-article-strip-blank-lines
1831     "A" gnus-article-strip-all-blank-lines
1832     "s" gnus-article-strip-leading-space
1833     "e" gnus-article-strip-trailing-space
1834     "w" gnus-article-remove-leading-whitespace)
1835
1836   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1837     "v" gnus-version
1838     "f" gnus-summary-fetch-faq
1839     "d" gnus-summary-describe-group
1840     "h" gnus-summary-describe-briefly
1841     "i" gnus-info-find-node
1842     "c" gnus-group-fetch-charter
1843     "C" gnus-group-fetch-control)
1844
1845   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1846     "e" gnus-summary-expire-articles
1847     "\M-\C-e" gnus-summary-expire-articles-now
1848     "\177" gnus-summary-delete-article
1849     [delete] gnus-summary-delete-article
1850     [backspace] gnus-summary-delete-article
1851     "m" gnus-summary-move-article
1852     "r" gnus-summary-respool-article
1853     "w" gnus-summary-edit-article
1854     "c" gnus-summary-copy-article
1855     "B" gnus-summary-crosspost-article
1856     "q" gnus-summary-respool-query
1857     "t" gnus-summary-respool-trace
1858     "i" gnus-summary-import-article
1859     "I" gnus-summary-create-article
1860     "p" gnus-summary-article-posted-p)
1861
1862   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1863     "o" gnus-summary-save-article
1864     "m" gnus-summary-save-article-mail
1865     "F" gnus-summary-write-article-file
1866     "r" gnus-summary-save-article-rmail
1867     "f" gnus-summary-save-article-file
1868     "b" gnus-summary-save-article-body-file
1869     "h" gnus-summary-save-article-folder
1870     "v" gnus-summary-save-article-vm
1871     "p" gnus-summary-pipe-output
1872     "P" gnus-summary-muttprint
1873     "s" gnus-soup-add-article)
1874
1875   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1876     "b" gnus-summary-display-buttonized
1877     "m" gnus-summary-repair-multipart
1878     "v" gnus-article-view-part
1879     "o" gnus-article-save-part
1880     "c" gnus-article-copy-part
1881     "C" gnus-article-view-part-as-charset
1882     "e" gnus-article-view-part-externally
1883     "E" gnus-article-encrypt-body
1884     "i" gnus-article-inline-part
1885     "|" gnus-article-pipe-part)
1886
1887   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1888     "p" gnus-summary-mark-as-processable
1889     "u" gnus-summary-unmark-as-processable
1890     "U" gnus-summary-unmark-all-processable
1891     "v" gnus-uu-mark-over
1892     "s" gnus-uu-mark-series
1893     "r" gnus-uu-mark-region
1894     "g" gnus-uu-unmark-region
1895     "R" gnus-uu-mark-by-regexp
1896     "G" gnus-uu-unmark-by-regexp
1897     "t" gnus-uu-mark-thread
1898     "T" gnus-uu-unmark-thread
1899     "a" gnus-uu-mark-all
1900     "b" gnus-uu-mark-buffer
1901     "S" gnus-uu-mark-sparse
1902     "k" gnus-summary-kill-process-mark
1903     "y" gnus-summary-yank-process-mark
1904     "w" gnus-summary-save-process-mark
1905     "i" gnus-uu-invert-processable)
1906
1907   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1908     ;;"x" gnus-uu-extract-any
1909     "m" gnus-summary-save-parts
1910     "u" gnus-uu-decode-uu
1911     "U" gnus-uu-decode-uu-and-save
1912     "s" gnus-uu-decode-unshar
1913     "S" gnus-uu-decode-unshar-and-save
1914     "o" gnus-uu-decode-save
1915     "O" gnus-uu-decode-save
1916     "b" gnus-uu-decode-binhex
1917     "B" gnus-uu-decode-binhex
1918     "p" gnus-uu-decode-postscript
1919     "P" gnus-uu-decode-postscript-and-save)
1920
1921   (gnus-define-keys
1922       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1923     "u" gnus-uu-decode-uu-view
1924     "U" gnus-uu-decode-uu-and-save-view
1925     "s" gnus-uu-decode-unshar-view
1926     "S" gnus-uu-decode-unshar-and-save-view
1927     "o" gnus-uu-decode-save-view
1928     "O" gnus-uu-decode-save-view
1929     "b" gnus-uu-decode-binhex-view
1930     "B" gnus-uu-decode-binhex-view
1931     "p" gnus-uu-decode-postscript-view
1932     "P" gnus-uu-decode-postscript-and-save-view))
1933
1934 (defvar gnus-article-post-menu nil)
1935
1936 (defconst gnus-summary-menu-maxlen 20)
1937
1938 (defun gnus-summary-menu-split (menu)
1939   ;; If we have lots of elements, divide them into groups of 20
1940   ;; and make a pane (or submenu) for each one.
1941   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1942       (let ((menu menu) sublists next
1943             (i 1))
1944         (while menu
1945           ;; Pull off the next gnus-summary-menu-maxlen elements
1946           ;; and make them the next element of sublist.
1947           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1948           (if next
1949               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1950                       nil))
1951           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1952                                              (aref (car (last menu)) 0)) menu)
1953                                sublists))
1954           (setq i (1+ i))
1955           (setq menu next))
1956         (nreverse sublists))
1957     ;; Few elements--put them all in one pane.
1958     menu))
1959
1960 (defun gnus-summary-make-menu-bar ()
1961   (gnus-turn-off-edit-menu 'summary)
1962
1963   (unless (boundp 'gnus-summary-misc-menu)
1964
1965     (easy-menu-define
1966       gnus-summary-kill-menu gnus-summary-mode-map ""
1967       (cons
1968        "Score"
1969        (nconc
1970         (list
1971          ["Customize" gnus-score-customize t])
1972         (gnus-make-score-map 'increase)
1973         (gnus-make-score-map 'lower)
1974         '(("Mark"
1975            ["Kill below" gnus-summary-kill-below t]
1976            ["Mark above" gnus-summary-mark-above t]
1977            ["Tick above" gnus-summary-tick-above t]
1978            ["Clear above" gnus-summary-clear-above t])
1979           ["Current score" gnus-summary-current-score t]
1980           ["Set score" gnus-summary-set-score t]
1981           ["Switch current score file..." gnus-score-change-score-file t]
1982           ["Set mark below..." gnus-score-set-mark-below t]
1983           ["Set expunge below..." gnus-score-set-expunge-below t]
1984           ["Edit current score file" gnus-score-edit-current-scores t]
1985           ["Edit score file" gnus-score-edit-file t]
1986           ["Trace score" gnus-score-find-trace t]
1987           ["Find words" gnus-score-find-favourite-words t]
1988           ["Rescore buffer" gnus-summary-rescore t]
1989           ["Increase score..." gnus-summary-increase-score t]
1990           ["Lower score..." gnus-summary-lower-score t]))))
1991
1992     ;; Define both the Article menu in the summary buffer and the
1993     ;; equivalent Commands menu in the article buffer here for
1994     ;; consistency.
1995     (let ((innards
1996            `(("Hide"
1997               ["All" gnus-article-hide t]
1998               ["Headers" gnus-article-hide-headers t]
1999               ["Signature" gnus-article-hide-signature t]
2000               ["Citation" gnus-article-hide-citation t]
2001               ["List identifiers" gnus-article-hide-list-identifiers t]
2002               ["PGP" gnus-article-hide-pgp t]
2003               ["Banner" gnus-article-strip-banner t]
2004               ["Boring headers" gnus-article-hide-boring-headers t])
2005              ("Highlight"
2006               ["All" gnus-article-highlight t]
2007               ["Headers" gnus-article-highlight-headers t]
2008               ["Signature" gnus-article-highlight-signature t]
2009               ["Citation" gnus-article-highlight-citation t])
2010              ("MIME"
2011               ["Words" gnus-article-decode-mime-words t]
2012               ["Charset" gnus-article-decode-charset t]
2013               ["QP" gnus-article-de-quoted-unreadable t]
2014               ["Base64" gnus-article-de-base64-unreadable t]
2015               ["View MIME buttons" gnus-summary-display-buttonized t]
2016               ["View all" gnus-mime-view-all-parts t]
2017               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2018               ["Encrypt body" gnus-article-encrypt-body t]
2019               ["Extract all parts" gnus-summary-save-parts t])
2020              ("Date"
2021               ["Local" gnus-article-date-local t]
2022               ["ISO8601" gnus-article-date-iso8601 t]
2023               ["UT" gnus-article-date-ut t]
2024               ["Original" gnus-article-date-original t]
2025               ["Lapsed" gnus-article-date-lapsed t]
2026               ["User-defined" gnus-article-date-user t])
2027              ("Display"
2028               ["Remove images" gnus-article-remove-images t]
2029               ["Toggle smiley" gnus-treat-smiley t]
2030               ["Show X-Face" gnus-article-display-x-face t]
2031               ["Show picons in From" gnus-treat-from-picon t]
2032               ["Show picons in mail headers" gnus-treat-mail-picon t]
2033               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2034               ("View as different encoding"
2035                ,@(gnus-summary-menu-split
2036                   (mapcar
2037                    (lambda (cs)
2038                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2039                      ;; forms for menu commands, we should provide intern'ed
2040                      ;; function symbols.
2041                      (let ((command (intern (format "\
2042 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2043                        (fset command
2044                              `(lambda ()
2045                                 (interactive)
2046                                 (let ((gnus-summary-show-article-charset-alist
2047                                        '((1 . ,cs))))
2048                                   (gnus-summary-show-article 1))))
2049                        `[,(symbol-name cs) ,command t]))
2050                    (sort (if (fboundp 'coding-system-list)
2051                              (coding-system-list)
2052                            (mapcar 'car mm-mime-mule-charset-alist))
2053                          'string<)))))
2054              ("Washing"
2055               ("Remove Blanks"
2056                ["Leading" gnus-article-strip-leading-blank-lines t]
2057                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2058                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2059                ["All of the above" gnus-article-strip-blank-lines t]
2060                ["All" gnus-article-strip-all-blank-lines t]
2061                ["Leading space" gnus-article-strip-leading-space t]
2062                ["Trailing space" gnus-article-strip-trailing-space t]
2063                ["Leading space in headers"
2064                 gnus-article-remove-leading-whitespace t])
2065               ["Overstrike" gnus-article-treat-overstrike t]
2066               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2067               ["Emphasis" gnus-article-emphasize t]
2068               ["Word wrap" gnus-article-fill-cited-article t]
2069               ["Fill long lines" gnus-article-fill-long-lines t]
2070               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2071               ["CR" gnus-article-remove-cr t]
2072               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2073               ["Base64" gnus-article-de-base64-unreadable t]
2074               ["Rot 13" gnus-summary-caesar-message
2075                ,@(if (featurep 'xemacs) '(t)
2076                    '(:help "\"Caesar rotate\" article by 13"))]
2077               ["Morse decode" gnus-summary-morse-message t]
2078               ["Unix pipe..." gnus-summary-pipe-message t]
2079               ["Add buttons" gnus-article-add-buttons t]
2080               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2081               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2082               ["Verbose header" gnus-summary-verbose-headers t]
2083               ["Toggle header" gnus-summary-toggle-header t]
2084               ["Unfold headers" gnus-article-treat-unfold-headers t]
2085               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2086               ["Html" gnus-article-wash-html t]
2087               ["URLs" gnus-article-unsplit-urls t]
2088               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2089               ["HZ" gnus-article-decode-HZ t]
2090               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2091               )
2092              ("Output"
2093               ["Save in default format" gnus-summary-save-article
2094                ,@(if (featurep 'xemacs) '(t)
2095                    '(:help "Save article using default method"))]
2096               ["Save in file" gnus-summary-save-article-file
2097                ,@(if (featurep 'xemacs) '(t)
2098                    '(:help "Save article in file"))]
2099               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2100               ["Save in MH folder" gnus-summary-save-article-folder t]
2101               ["Save in VM folder" gnus-summary-save-article-vm t]
2102               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2103               ["Save body in file" gnus-summary-save-article-body-file t]
2104               ["Pipe through a filter" gnus-summary-pipe-output t]
2105               ["Add to SOUP packet" gnus-soup-add-article t]
2106               ["Print with Muttprint" gnus-summary-muttprint t]
2107               ["Print" gnus-summary-print-article t])
2108              ("Backend"
2109               ["Respool article..." gnus-summary-respool-article t]
2110               ["Move article..." gnus-summary-move-article
2111                (gnus-check-backend-function
2112                 'request-move-article gnus-newsgroup-name)]
2113               ["Copy article..." gnus-summary-copy-article t]
2114               ["Crosspost article..." gnus-summary-crosspost-article
2115                (gnus-check-backend-function
2116                 'request-replace-article gnus-newsgroup-name)]
2117               ["Import file..." gnus-summary-import-article t]
2118               ["Create article..." gnus-summary-create-article t]
2119               ["Check if posted" gnus-summary-article-posted-p t]
2120               ["Edit article" gnus-summary-edit-article
2121                (not (gnus-group-read-only-p))]
2122               ["Delete article" gnus-summary-delete-article
2123                (gnus-check-backend-function
2124                 'request-expire-articles gnus-newsgroup-name)]
2125               ["Query respool" gnus-summary-respool-query t]
2126               ["Trace respool" gnus-summary-respool-trace t]
2127               ["Delete expirable articles" gnus-summary-expire-articles-now
2128                (gnus-check-backend-function
2129                 'request-expire-articles gnus-newsgroup-name)])
2130              ("Extract"
2131               ["Uudecode" gnus-uu-decode-uu
2132                ,@(if (featurep 'xemacs) '(t)
2133                    '(:help "Decode uuencoded article(s)"))]
2134               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2135               ["Unshar" gnus-uu-decode-unshar t]
2136               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2137               ["Save" gnus-uu-decode-save t]
2138               ["Binhex" gnus-uu-decode-binhex t]
2139               ["Postscript" gnus-uu-decode-postscript t]
2140               ["All MIME parts" gnus-summary-save-parts t])
2141              ("Cache"
2142               ["Enter article" gnus-cache-enter-article t]
2143               ["Remove article" gnus-cache-remove-article t])
2144              ["Translate" gnus-article-babel t]
2145              ["Select article buffer" gnus-summary-select-article-buffer t]
2146              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2147              ["Isearch article..." gnus-summary-isearch-article t]
2148              ["Beginning of the article" gnus-summary-beginning-of-article t]
2149              ["End of the article" gnus-summary-end-of-article t]
2150              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2151              ["Fetch referenced articles" gnus-summary-refer-references t]
2152              ["Fetch current thread" gnus-summary-refer-thread t]
2153              ["Fetch article with id..." gnus-summary-refer-article t]
2154              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2155              ["Redisplay" gnus-summary-show-article t]
2156              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2157       (easy-menu-define
2158         gnus-summary-article-menu gnus-summary-mode-map ""
2159         (cons "Article" innards))
2160
2161       (if (not (keymapp gnus-summary-article-menu))
2162           (easy-menu-define
2163             gnus-article-commands-menu gnus-article-mode-map ""
2164             (cons "Commands" innards))
2165         ;; in Emacs, don't share menu.
2166         (setq gnus-article-commands-menu
2167               (copy-keymap gnus-summary-article-menu))
2168         (define-key gnus-article-mode-map [menu-bar commands]
2169           (cons "Commands" gnus-article-commands-menu))))
2170
2171     (easy-menu-define
2172       gnus-summary-thread-menu gnus-summary-mode-map ""
2173       '("Threads"
2174         ["Toggle threading" gnus-summary-toggle-threads t]
2175         ["Hide threads" gnus-summary-hide-all-threads t]
2176         ["Show threads" gnus-summary-show-all-threads t]
2177         ["Hide thread" gnus-summary-hide-thread t]
2178         ["Show thread" gnus-summary-show-thread t]
2179         ["Go to next thread" gnus-summary-next-thread t]
2180         ["Go to previous thread" gnus-summary-prev-thread t]
2181         ["Go down thread" gnus-summary-down-thread t]
2182         ["Go up thread" gnus-summary-up-thread t]
2183         ["Top of thread" gnus-summary-top-thread t]
2184         ["Mark thread as read" gnus-summary-kill-thread t]
2185         ["Lower thread score" gnus-summary-lower-thread t]
2186         ["Raise thread score" gnus-summary-raise-thread t]
2187         ["Rethread current" gnus-summary-rethread-current t]))
2188
2189     (easy-menu-define
2190       gnus-summary-post-menu gnus-summary-mode-map ""
2191       `("Post"
2192         ["Send a message (mail or news)" gnus-summary-post-news
2193          ,@(if (featurep 'xemacs) '(t)
2194              '(:help "Post an article"))]
2195         ["Followup" gnus-summary-followup
2196          ,@(if (featurep 'xemacs) '(t)
2197              '(:help "Post followup to this article"))]
2198         ["Followup and yank" gnus-summary-followup-with-original
2199          ,@(if (featurep 'xemacs) '(t)
2200              '(:help "Post followup to this article, quoting its contents"))]
2201         ["Supersede article" gnus-summary-supersede-article t]
2202         ["Cancel article" gnus-summary-cancel-article
2203          ,@(if (featurep 'xemacs) '(t)
2204              '(:help "Cancel an article you posted"))]
2205         ["Reply" gnus-summary-reply t]
2206         ["Reply and yank" gnus-summary-reply-with-original t]
2207         ["Wide reply" gnus-summary-wide-reply t]
2208         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2209          ,@(if (featurep 'xemacs) '(t)
2210              '(:help "Mail a reply, quoting this article"))]
2211         ["Very wide reply" gnus-summary-very-wide-reply t]
2212         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2213          ,@(if (featurep 'xemacs) '(t)
2214              '(:help "Mail a very wide reply, quoting this article"))]
2215         ["Mail forward" gnus-summary-mail-forward t]
2216         ["Post forward" gnus-summary-post-forward t]
2217         ["Digest and mail" gnus-uu-digest-mail-forward t]
2218         ["Digest and post" gnus-uu-digest-post-forward t]
2219         ["Resend message" gnus-summary-resend-message t]
2220         ["Resend message edit" gnus-summary-resend-message-edit t]
2221         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2222         ["Send a mail" gnus-summary-mail-other-window t]
2223         ["Create a local message" gnus-summary-news-other-window t]
2224         ["Uuencode and post" gnus-uu-post-news
2225          ,@(if (featurep 'xemacs) '(t)
2226              '(:help "Post a uuencoded article"))]
2227         ["Followup via news" gnus-summary-followup-to-mail t]
2228         ["Followup via news and yank"
2229          gnus-summary-followup-to-mail-with-original t]
2230         ;;("Draft"
2231         ;;["Send" gnus-summary-send-draft t]
2232         ;;["Send bounced" gnus-resend-bounced-mail t])
2233         ))
2234
2235     (cond
2236      ((not (keymapp gnus-summary-post-menu))
2237       (setq gnus-article-post-menu gnus-summary-post-menu))
2238      ((not gnus-article-post-menu)
2239       ;; Don't share post menu.
2240       (setq gnus-article-post-menu
2241             (copy-keymap gnus-summary-post-menu))))
2242     (define-key gnus-article-mode-map [menu-bar post]
2243       (cons "Post" gnus-article-post-menu))
2244
2245     (easy-menu-define
2246       gnus-summary-misc-menu gnus-summary-mode-map ""
2247       `("Gnus"
2248         ("Mark Read"
2249          ["Mark as read" gnus-summary-mark-as-read-forward t]
2250          ["Mark same subject and select"
2251           gnus-summary-kill-same-subject-and-select t]
2252          ["Mark same subject" gnus-summary-kill-same-subject t]
2253          ["Catchup" gnus-summary-catchup
2254           ,@(if (featurep 'xemacs) '(t)
2255               '(:help "Mark unread articles in this group as read"))]
2256          ["Catchup all" gnus-summary-catchup-all t]
2257          ["Catchup to here" gnus-summary-catchup-to-here t]
2258          ["Catchup from here" gnus-summary-catchup-from-here t]
2259          ["Catchup region" gnus-summary-mark-region-as-read t]
2260          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2261         ("Mark Various"
2262          ["Tick" gnus-summary-tick-article-forward t]
2263          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2264          ["Remove marks" gnus-summary-clear-mark-forward t]
2265          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2266          ["Set bookmark" gnus-summary-set-bookmark t]
2267          ["Remove bookmark" gnus-summary-remove-bookmark t])
2268         ("Limit to"
2269          ["Marks..." gnus-summary-limit-to-marks t]
2270          ["Subject..." gnus-summary-limit-to-subject t]
2271          ["Author..." gnus-summary-limit-to-author t]
2272          ["Age..." gnus-summary-limit-to-age t]
2273          ["Extra..." gnus-summary-limit-to-extra t]
2274          ["Score..." gnus-summary-limit-to-score t]
2275          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2276          ["Unread" gnus-summary-limit-to-unread t]
2277          ["Unseen" gnus-summary-limit-to-unseen t]
2278          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2279          ["Articles" gnus-summary-limit-to-articles t]
2280          ["Pop limit" gnus-summary-pop-limit t]
2281          ["Show dormant" gnus-summary-limit-include-dormant t]
2282          ["Hide childless dormant"
2283           gnus-summary-limit-exclude-childless-dormant t]
2284          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2285          ["Hide marked" gnus-summary-limit-exclude-marks t]
2286          ["Show expunged" gnus-summary-limit-include-expunged t])
2287         ("Process Mark"
2288          ["Set mark" gnus-summary-mark-as-processable t]
2289          ["Remove mark" gnus-summary-unmark-as-processable t]
2290          ["Remove all marks" gnus-summary-unmark-all-processable t]
2291          ["Mark above" gnus-uu-mark-over t]
2292          ["Mark series" gnus-uu-mark-series t]
2293          ["Mark region" gnus-uu-mark-region t]
2294          ["Unmark region" gnus-uu-unmark-region t]
2295          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2296          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2297          ["Mark all" gnus-uu-mark-all t]
2298          ["Mark buffer" gnus-uu-mark-buffer t]
2299          ["Mark sparse" gnus-uu-mark-sparse t]
2300          ["Mark thread" gnus-uu-mark-thread t]
2301          ["Unmark thread" gnus-uu-unmark-thread t]
2302          ("Process Mark Sets"
2303           ["Kill" gnus-summary-kill-process-mark t]
2304           ["Yank" gnus-summary-yank-process-mark
2305            gnus-newsgroup-process-stack]
2306           ["Save" gnus-summary-save-process-mark t]))
2307         ("Scroll article"
2308          ["Page forward" gnus-summary-next-page
2309           ,@(if (featurep 'xemacs) '(t)
2310               '(:help "Show next page of article"))]
2311          ["Page backward" gnus-summary-prev-page
2312           ,@(if (featurep 'xemacs) '(t)
2313               '(:help "Show previous page of article"))]
2314          ["Line forward" gnus-summary-scroll-up t])
2315         ("Move"
2316          ["Next unread article" gnus-summary-next-unread-article t]
2317          ["Previous unread article" gnus-summary-prev-unread-article t]
2318          ["Next article" gnus-summary-next-article t]
2319          ["Previous article" gnus-summary-prev-article t]
2320          ["Next unread subject" gnus-summary-next-unread-subject t]
2321          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2322          ["Next article same subject" gnus-summary-next-same-subject t]
2323          ["Previous article same subject" gnus-summary-prev-same-subject t]
2324          ["First unread article" gnus-summary-first-unread-article t]
2325          ["Best unread article" gnus-summary-best-unread-article t]
2326          ["Go to subject number..." gnus-summary-goto-subject t]
2327          ["Go to article number..." gnus-summary-goto-article t]
2328          ["Go to the last article" gnus-summary-goto-last-article t]
2329          ["Pop article off history" gnus-summary-pop-article t])
2330         ("Sort"
2331          ["Sort by number" gnus-summary-sort-by-number t]
2332          ["Sort by author" gnus-summary-sort-by-author t]
2333          ["Sort by subject" gnus-summary-sort-by-subject t]
2334          ["Sort by date" gnus-summary-sort-by-date t]
2335          ["Sort by score" gnus-summary-sort-by-score t]
2336          ["Sort by lines" gnus-summary-sort-by-lines t]
2337          ["Sort by characters" gnus-summary-sort-by-chars t]
2338          ["Randomize" gnus-summary-sort-by-random t]
2339          ["Original sort" gnus-summary-sort-by-original t])
2340         ("Help"
2341          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2342          ["Describe group" gnus-summary-describe-group t]
2343          ["Fetch charter" gnus-group-fetch-charter
2344           ,@(if (featurep 'xemacs) nil
2345               '(:help "Display the charter of the current group"))]
2346          ["Fetch control message" gnus-group-fetch-control
2347           ,@(if (featurep 'xemacs) nil
2348               '(:help "Display the archived control message for the current group"))]
2349          ["Read manual" gnus-info-find-node t])
2350         ("Modes"
2351          ["Pick and read" gnus-pick-mode t]
2352          ["Binary" gnus-binary-mode t])
2353         ("Regeneration"
2354          ["Regenerate" gnus-summary-prepare t]
2355          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2356          ["Toggle threading" gnus-summary-toggle-threads t])
2357         ["See old articles" gnus-summary-insert-old-articles t]
2358         ["See new articles" gnus-summary-insert-new-articles t]
2359         ["Filter articles..." gnus-summary-execute-command t]
2360         ["Run command on subjects..." gnus-summary-universal-argument t]
2361         ["Search articles forward..." gnus-summary-search-article-forward t]
2362         ["Search articles backward..." gnus-summary-search-article-backward t]
2363         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2364         ["Expand window" gnus-summary-expand-window t]
2365         ["Expire expirable articles" gnus-summary-expire-articles
2366          (gnus-check-backend-function
2367           'request-expire-articles gnus-newsgroup-name)]
2368         ["Edit local kill file" gnus-summary-edit-local-kill t]
2369         ["Edit main kill file" gnus-summary-edit-global-kill t]
2370         ["Edit group parameters" gnus-summary-edit-parameters t]
2371         ["Customize group parameters" gnus-summary-customize-parameters t]
2372         ["Send a bug report" gnus-bug t]
2373         ("Exit"
2374          ["Catchup and exit" gnus-summary-catchup-and-exit
2375           ,@(if (featurep 'xemacs) '(t)
2376               '(:help "Mark unread articles in this group as read, then exit"))]
2377          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2378          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2379          ["Exit group" gnus-summary-exit
2380           ,@(if (featurep 'xemacs) '(t)
2381               '(:help "Exit current group, return to group selection mode"))]
2382          ["Exit group without updating" gnus-summary-exit-no-update t]
2383          ["Exit and goto next group" gnus-summary-next-group t]
2384          ["Exit and goto prev group" gnus-summary-prev-group t]
2385          ["Reselect group" gnus-summary-reselect-current-group t]
2386          ["Rescan group" gnus-summary-rescan-group t]
2387          ["Update dribble" gnus-summary-save-newsrc t])))
2388
2389     (gnus-run-hooks 'gnus-summary-menu-hook)))
2390
2391 (defvar gnus-summary-tool-bar-map nil)
2392
2393 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2394 (defun gnus-summary-make-tool-bar ()
2395   (if (and (fboundp 'tool-bar-add-item-from-menu)
2396            (default-value 'tool-bar-mode)
2397            (not gnus-summary-tool-bar-map))
2398       (setq gnus-summary-tool-bar-map
2399             (let ((tool-bar-map (make-sparse-keymap))
2400                   (load-path (mm-image-load-path)))
2401               (tool-bar-add-item-from-menu
2402                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2403               (tool-bar-add-item-from-menu
2404                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2405               (tool-bar-add-item-from-menu
2406                'gnus-summary-post-news "post" gnus-summary-mode-map)
2407               (tool-bar-add-item-from-menu
2408                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2409               (tool-bar-add-item-from-menu
2410                'gnus-summary-followup "followup" gnus-summary-mode-map)
2411               (tool-bar-add-item-from-menu
2412                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2413               (tool-bar-add-item-from-menu
2414                'gnus-summary-reply "reply" gnus-summary-mode-map)
2415               (tool-bar-add-item-from-menu
2416                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2417               (tool-bar-add-item-from-menu
2418                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2419               (tool-bar-add-item-from-menu
2420                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2421               (tool-bar-add-item-from-menu
2422                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2423               (tool-bar-add-item-from-menu
2424                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2425               (tool-bar-add-item-from-menu
2426                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2427               (tool-bar-add-item-from-menu
2428                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2429               (tool-bar-add-item-from-menu
2430                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2431               tool-bar-map)))
2432   (if gnus-summary-tool-bar-map
2433       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2434
2435 (defun gnus-score-set-default (var value)
2436   "A version of set that updates the GNU Emacs menu-bar."
2437   (set var value)
2438   ;; It is the message that forces the active status to be updated.
2439   (message ""))
2440
2441 (defun gnus-make-score-map (type)
2442   "Make a summary score map of type TYPE."
2443   (if t
2444       nil
2445     (let ((headers '(("author" "from" string)
2446                      ("subject" "subject" string)
2447                      ("article body" "body" string)
2448                      ("article head" "head" string)
2449                      ("xref" "xref" string)
2450                      ("extra header" "extra" string)
2451                      ("lines" "lines" number)
2452                      ("followups to author" "followup" string)))
2453           (types '((number ("less than" <)
2454                            ("greater than" >)
2455                            ("equal" =))
2456                    (string ("substring" s)
2457                            ("exact string" e)
2458                            ("fuzzy string" f)
2459                            ("regexp" r))))
2460           (perms '(("temporary" (current-time-string))
2461                    ("permanent" nil)
2462                    ("immediate" now)))
2463           header)
2464       (list
2465        (apply
2466         'nconc
2467         (list
2468          (if (eq type 'lower)
2469              "Lower score"
2470            "Increase score"))
2471         (let (outh)
2472           (while headers
2473             (setq header (car headers))
2474             (setq outh
2475                   (cons
2476                    (apply
2477                     'nconc
2478                     (list (car header))
2479                     (let ((ts (cdr (assoc (nth 2 header) types)))
2480                           outt)
2481                       (while ts
2482                         (setq outt
2483                               (cons
2484                                (apply
2485                                 'nconc
2486                                 (list (caar ts))
2487                                 (let ((ps perms)
2488                                       outp)
2489                                   (while ps
2490                                     (setq outp
2491                                           (cons
2492                                            (vector
2493                                             (caar ps)
2494                                             (list
2495                                              'gnus-summary-score-entry
2496                                              (nth 1 header)
2497                                              (if (or (string= (nth 1 header)
2498                                                               "head")
2499                                                      (string= (nth 1 header)
2500                                                               "body"))
2501                                                  ""
2502                                                (list 'gnus-summary-header
2503                                                      (nth 1 header)))
2504                                              (list 'quote (nth 1 (car ts)))
2505                                              (list 'gnus-score-delta-default
2506                                                    nil)
2507                                              (nth 1 (car ps))
2508                                              t)
2509                                             t)
2510                                            outp))
2511                                     (setq ps (cdr ps)))
2512                                   (list (nreverse outp))))
2513                                outt))
2514                         (setq ts (cdr ts)))
2515                       (list (nreverse outt))))
2516                    outh))
2517             (setq headers (cdr headers)))
2518           (list (nreverse outh))))))))
2519
2520 \f
2521
2522 (defun gnus-summary-mode (&optional group)
2523   "Major mode for reading articles.
2524
2525 All normal editing commands are switched off.
2526 \\<gnus-summary-mode-map>
2527 Each line in this buffer represents one article.  To read an
2528 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2529 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2530 respectively.
2531
2532 You can also post articles and send mail from this buffer.  To
2533 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2534 of an article, type `\\[gnus-summary-reply]'.
2535
2536 There are approx. one gazillion commands you can execute in this
2537 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2538
2539 The following commands are available:
2540
2541 \\{gnus-summary-mode-map}"
2542   (interactive)
2543   (kill-all-local-variables)
2544   (when (gnus-visual-p 'summary-menu 'menu)
2545     (gnus-summary-make-menu-bar)
2546     (gnus-summary-make-tool-bar))
2547   (gnus-summary-make-local-variables)
2548   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2549     (gnus-summary-make-local-variables))
2550   (gnus-make-thread-indent-array)
2551   (gnus-simplify-mode-line)
2552   (setq major-mode 'gnus-summary-mode)
2553   (setq mode-name "Summary")
2554   (make-local-variable 'minor-mode-alist)
2555   (use-local-map gnus-summary-mode-map)
2556   (buffer-disable-undo)
2557   (setq buffer-read-only t)             ;Disable modification
2558   (setq truncate-lines t)
2559   (setq selective-display t)
2560   (setq selective-display-ellipses t)   ;Display `...'
2561   (gnus-summary-set-display-table)
2562   (gnus-set-default-directory)
2563   (setq gnus-newsgroup-name group)
2564   (make-local-variable 'gnus-summary-line-format)
2565   (make-local-variable 'gnus-summary-line-format-spec)
2566   (make-local-variable 'gnus-summary-dummy-line-format)
2567   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2568   (make-local-variable 'gnus-summary-mark-positions)
2569   (make-local-hook 'pre-command-hook)
2570   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2571   (gnus-run-hooks 'gnus-summary-mode-hook)
2572   (turn-on-gnus-mailing-list-mode)
2573   (mm-enable-multibyte)
2574   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2575   (gnus-update-summary-mark-positions))
2576
2577 (defun gnus-summary-make-local-variables ()
2578   "Make all the local summary buffer variables."
2579   (let (global)
2580     (dolist (local gnus-summary-local-variables)
2581       (if (consp local)
2582           (progn
2583             (if (eq (cdr local) 'global)
2584                 ;; Copy the global value of the variable.
2585                 (setq global (symbol-value (car local)))
2586               ;; Use the value from the list.
2587               (setq global (eval (cdr local))))
2588             (set (make-local-variable (car local)) global))
2589         ;; Simple nil-valued local variable.
2590         (set (make-local-variable local) nil)))))
2591
2592 (defun gnus-summary-clear-local-variables ()
2593   (let ((locals gnus-summary-local-variables))
2594     (while locals
2595       (if (consp (car locals))
2596           (and (vectorp (caar locals))
2597                (set (caar locals) nil))
2598         (and (vectorp (car locals))
2599              (set (car locals) nil)))
2600       (setq locals (cdr locals)))))
2601
2602 ;; Summary data functions.
2603
2604 (defmacro gnus-data-number (data)
2605   `(car ,data))
2606
2607 (defmacro gnus-data-set-number (data number)
2608   `(setcar ,data ,number))
2609
2610 (defmacro gnus-data-mark (data)
2611   `(nth 1 ,data))
2612
2613 (defmacro gnus-data-set-mark (data mark)
2614   `(setcar (nthcdr 1 ,data) ,mark))
2615
2616 (defmacro gnus-data-pos (data)
2617   `(nth 2 ,data))
2618
2619 (defmacro gnus-data-set-pos (data pos)
2620   `(setcar (nthcdr 2 ,data) ,pos))
2621
2622 (defmacro gnus-data-header (data)
2623   `(nth 3 ,data))
2624
2625 (defmacro gnus-data-set-header (data header)
2626   `(setf (nth 3 ,data) ,header))
2627
2628 (defmacro gnus-data-level (data)
2629   `(nth 4 ,data))
2630
2631 (defmacro gnus-data-unread-p (data)
2632   `(= (nth 1 ,data) gnus-unread-mark))
2633
2634 (defmacro gnus-data-read-p (data)
2635   `(/= (nth 1 ,data) gnus-unread-mark))
2636
2637 (defmacro gnus-data-pseudo-p (data)
2638   `(consp (nth 3 ,data)))
2639
2640 (defmacro gnus-data-find (number)
2641   `(assq ,number gnus-newsgroup-data))
2642
2643 (defmacro gnus-data-find-list (number &optional data)
2644   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2645      (memq (assq ,number bdata)
2646            bdata)))
2647
2648 (defmacro gnus-data-make (number mark pos header level)
2649   `(list ,number ,mark ,pos ,header ,level))
2650
2651 (defun gnus-data-enter (after-article number mark pos header level offset)
2652   (let ((data (gnus-data-find-list after-article)))
2653     (unless data
2654       (error "No such article: %d" after-article))
2655     (setcdr data (cons (gnus-data-make number mark pos header level)
2656                        (cdr data)))
2657     (setq gnus-newsgroup-data-reverse nil)
2658     (gnus-data-update-list (cddr data) offset)))
2659
2660 (defun gnus-data-enter-list (after-article list &optional offset)
2661   (when list
2662     (let ((data (and after-article (gnus-data-find-list after-article)))
2663           (ilist list))
2664       (if (not (or data
2665                    after-article))
2666           (let ((odata gnus-newsgroup-data))
2667             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2668             (when offset
2669               (gnus-data-update-list odata offset)))
2670       ;; Find the last element in the list to be spliced into the main
2671         ;; list.
2672         (while (cdr list)
2673           (setq list (cdr list)))
2674         (if (not data)
2675             (progn
2676               (setcdr list gnus-newsgroup-data)
2677               (setq gnus-newsgroup-data ilist)
2678               (when offset
2679                 (gnus-data-update-list (cdr list) offset)))
2680           (setcdr list (cdr data))
2681           (setcdr data ilist)
2682           (when offset
2683             (gnus-data-update-list (cdr list) offset))))
2684       (setq gnus-newsgroup-data-reverse nil))))
2685
2686 (defun gnus-data-remove (article &optional offset)
2687   (let ((data gnus-newsgroup-data))
2688     (if (= (gnus-data-number (car data)) article)
2689         (progn
2690           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2691                 gnus-newsgroup-data-reverse nil)
2692           (when offset
2693             (gnus-data-update-list gnus-newsgroup-data offset)))
2694       (while (cdr data)
2695         (when (= (gnus-data-number (cadr data)) article)
2696           (setcdr data (cddr data))
2697           (when offset
2698             (gnus-data-update-list (cdr data) offset))
2699           (setq data nil
2700                 gnus-newsgroup-data-reverse nil))
2701         (setq data (cdr data))))))
2702
2703 (defmacro gnus-data-list (backward)
2704   `(if ,backward
2705        (or gnus-newsgroup-data-reverse
2706            (setq gnus-newsgroup-data-reverse
2707                  (reverse gnus-newsgroup-data)))
2708      gnus-newsgroup-data))
2709
2710 (defun gnus-data-update-list (data offset)
2711   "Add OFFSET to the POS of all data entries in DATA."
2712   (setq gnus-newsgroup-data-reverse nil)
2713   (while data
2714     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2715     (setq data (cdr data))))
2716
2717 (defun gnus-summary-article-pseudo-p (article)
2718   "Say whether this article is a pseudo article or not."
2719   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2720
2721 (defmacro gnus-summary-article-sparse-p (article)
2722   "Say whether this article is a sparse article or not."
2723   `(memq ,article gnus-newsgroup-sparse))
2724
2725 (defmacro gnus-summary-article-ancient-p (article)
2726   "Say whether this article is a sparse article or not."
2727   `(memq ,article gnus-newsgroup-ancient))
2728
2729 (defun gnus-article-parent-p (number)
2730   "Say whether this article is a parent or not."
2731   (let ((data (gnus-data-find-list number)))
2732     (and (cdr data)              ; There has to be an article after...
2733          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2734             (gnus-data-level (nth 1 data))))))
2735
2736 (defun gnus-article-children (number)
2737   "Return a list of all children to NUMBER."
2738   (let* ((data (gnus-data-find-list number))
2739          (level (gnus-data-level (car data)))
2740          children)
2741     (setq data (cdr data))
2742     (while (and data
2743                 (= (gnus-data-level (car data)) (1+ level)))
2744       (push (gnus-data-number (car data)) children)
2745       (setq data (cdr data)))
2746     children))
2747
2748 (defmacro gnus-summary-skip-intangible ()
2749   "If the current article is intangible, then jump to a different article."
2750   '(let ((to (get-text-property (point) 'gnus-intangible)))
2751      (and to (gnus-summary-goto-subject to))))
2752
2753 (defmacro gnus-summary-article-intangible-p ()
2754   "Say whether this article is intangible or not."
2755   '(get-text-property (point) 'gnus-intangible))
2756
2757 (defun gnus-article-read-p (article)
2758   "Say whether ARTICLE is read or not."
2759   (not (or (memq article gnus-newsgroup-marked)
2760            (memq article gnus-newsgroup-spam-marked)
2761            (memq article gnus-newsgroup-unreads)
2762            (memq article gnus-newsgroup-unselected)
2763            (memq article gnus-newsgroup-dormant))))
2764
2765 ;; Some summary mode macros.
2766
2767 (defmacro gnus-summary-article-number ()
2768   "The article number of the article on the current line.
2769 If there isn't an article number here, then we return the current
2770 article number."
2771   '(progn
2772      (gnus-summary-skip-intangible)
2773      (or (get-text-property (point) 'gnus-number)
2774          (gnus-summary-last-subject))))
2775
2776 (defmacro gnus-summary-article-header (&optional number)
2777   "Return the header of article NUMBER."
2778   `(gnus-data-header (gnus-data-find
2779                       ,(or number '(gnus-summary-article-number)))))
2780
2781 (defmacro gnus-summary-thread-level (&optional number)
2782   "Return the level of thread that starts with article NUMBER."
2783   `(if (and (eq gnus-summary-make-false-root 'dummy)
2784             (get-text-property (point) 'gnus-intangible))
2785        0
2786      (gnus-data-level (gnus-data-find
2787                        ,(or number '(gnus-summary-article-number))))))
2788
2789 (defmacro gnus-summary-article-mark (&optional number)
2790   "Return the mark of article NUMBER."
2791   `(gnus-data-mark (gnus-data-find
2792                     ,(or number '(gnus-summary-article-number)))))
2793
2794 (defmacro gnus-summary-article-pos (&optional number)
2795   "Return the position of the line of article NUMBER."
2796   `(gnus-data-pos (gnus-data-find
2797                    ,(or number '(gnus-summary-article-number)))))
2798
2799 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2800 (defmacro gnus-summary-article-subject (&optional number)
2801   "Return current subject string or nil if nothing."
2802   `(let ((headers
2803           ,(if number
2804                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2805              '(gnus-data-header (assq (gnus-summary-article-number)
2806                                       gnus-newsgroup-data)))))
2807      (and headers
2808           (vectorp headers)
2809           (mail-header-subject headers))))
2810
2811 (defmacro gnus-summary-article-score (&optional number)
2812   "Return current article score."
2813   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2814                   gnus-newsgroup-scored))
2815        gnus-summary-default-score 0))
2816
2817 (defun gnus-summary-article-children (&optional number)
2818   "Return a list of article numbers that are children of article NUMBER."
2819   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2820          (level (gnus-data-level (car data)))
2821          l children)
2822     (while (and (setq data (cdr data))
2823                 (> (setq l (gnus-data-level (car data))) level))
2824       (and (= (1+ level) l)
2825            (push (gnus-data-number (car data))
2826                  children)))
2827     (nreverse children)))
2828
2829 (defun gnus-summary-article-parent (&optional number)
2830   "Return the article number of the parent of article NUMBER."
2831   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2832                                     (gnus-data-list t)))
2833          (level (gnus-data-level (car data))))
2834     (if (zerop level)
2835         ()                              ; This is a root.
2836       ;; We search until we find an article with a level less than
2837       ;; this one.  That function has to be the parent.
2838       (while (and (setq data (cdr data))
2839                   (not (< (gnus-data-level (car data)) level))))
2840       (and data (gnus-data-number (car data))))))
2841
2842 (defun gnus-unread-mark-p (mark)
2843   "Say whether MARK is the unread mark."
2844   (= mark gnus-unread-mark))
2845
2846 (defun gnus-read-mark-p (mark)
2847   "Say whether MARK is one of the marks that mark as read.
2848 This is all marks except unread, ticked, dormant, and expirable."
2849   (not (or (= mark gnus-unread-mark)
2850            (= mark gnus-ticked-mark)
2851            (= mark gnus-dormant-mark)
2852            (= mark gnus-expirable-mark))))
2853
2854 (defmacro gnus-article-mark (number)
2855   "Return the MARK of article NUMBER.
2856 This macro should only be used when computing the mark the \"first\"
2857 time; i.e., when generating the summary lines.  After that,
2858 `gnus-summary-article-mark' should be used to examine the
2859 marks of articles."
2860   `(cond
2861     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2862     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2863     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2864     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2865     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2866     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2867     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2868     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2869            gnus-ancient-mark))))
2870
2871 ;; Saving hidden threads.
2872
2873 (defmacro gnus-save-hidden-threads (&rest forms)
2874   "Save hidden threads, eval FORMS, and restore the hidden threads."
2875   (let ((config (make-symbol "config")))
2876     `(let ((,config (gnus-hidden-threads-configuration)))
2877        (unwind-protect
2878            (save-excursion
2879              ,@forms)
2880          (gnus-restore-hidden-threads-configuration ,config)))))
2881 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2882 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2883
2884 (defun gnus-data-compute-positions ()
2885   "Compute the positions of all articles."
2886   (setq gnus-newsgroup-data-reverse nil)
2887   (let ((data gnus-newsgroup-data))
2888     (save-excursion
2889       (gnus-save-hidden-threads
2890         (gnus-summary-show-all-threads)
2891         (goto-char (point-min))
2892         (while data
2893           (while (get-text-property (point) 'gnus-intangible)
2894             (forward-line 1))
2895           (gnus-data-set-pos (car data) (+ (point) 3))
2896           (setq data (cdr data))
2897           (forward-line 1))))))
2898
2899 (defun gnus-hidden-threads-configuration ()
2900   "Return the current hidden threads configuration."
2901   (save-excursion
2902     (let (config)
2903       (goto-char (point-min))
2904       (while (search-forward "\r" nil t)
2905         (push (1- (point)) config))
2906       config)))
2907
2908 (defun gnus-restore-hidden-threads-configuration (config)
2909   "Restore hidden threads configuration from CONFIG."
2910   (save-excursion
2911     (let (point buffer-read-only)
2912       (while (setq point (pop config))
2913         (when (and (< point (point-max))
2914                    (goto-char point)
2915                    (eq (char-after) ?\n))
2916           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2917
2918 ;; Various summary mode internalish functions.
2919
2920 (defun gnus-mouse-pick-article (e)
2921   (interactive "e")
2922   (mouse-set-point e)
2923   (gnus-summary-next-page nil t))
2924
2925 (defun gnus-summary-set-display-table ()
2926   "Change the display table.
2927 Odd characters have a tendency to mess
2928 up nicely formatted displays - we make all possible glyphs
2929 display only a single character."
2930
2931   ;; We start from the standard display table, if any.
2932   (let ((table (or (copy-sequence standard-display-table)
2933                    (make-display-table)))
2934         (i 32))
2935     ;; Nix out all the control chars...
2936     (while (>= (setq i (1- i)) 0)
2937       (aset table i [??]))
2938    ;; ... but not newline and cr, of course.  (cr is necessary for the
2939     ;; selective display).
2940     (aset table ?\n nil)
2941     (aset table ?\r nil)
2942     ;; We keep TAB as well.
2943     (aset table ?\t nil)
2944     ;; We nix out any glyphs over 126 that are not set already.
2945     (let ((i 256))
2946       (while (>= (setq i (1- i)) 127)
2947         ;; Only modify if the entry is nil.
2948         (unless (aref table i)
2949           (aset table i [??]))))
2950     (setq buffer-display-table table)))
2951
2952 (defun gnus-summary-set-article-display-arrow (pos)
2953   "Update the overlay arrow to point to line at position POS."
2954   (when (and gnus-summary-display-arrow
2955              (boundp 'overlay-arrow-position)
2956              (boundp 'overlay-arrow-string))
2957     (save-excursion
2958       (goto-char pos)
2959       (beginning-of-line)
2960       (unless overlay-arrow-position
2961         (setq overlay-arrow-position (make-marker)))
2962       (setq overlay-arrow-string "=>"
2963             overlay-arrow-position (set-marker overlay-arrow-position
2964                                                (point)
2965                                                (current-buffer))))))
2966
2967 (defun gnus-summary-buffer-name (group)
2968   "Return the summary buffer name of GROUP."
2969   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2970
2971 (defun gnus-summary-setup-buffer (group)
2972   "Initialize summary buffer."
2973   (let ((buffer (gnus-summary-buffer-name group))
2974         (dead-name (concat "*Dead Summary "
2975                            (gnus-group-decoded-name group) "*")))
2976     ;; If a dead summary buffer exists, we kill it.
2977     (when (gnus-buffer-live-p dead-name)
2978       (gnus-kill-buffer dead-name))
2979     (if (get-buffer buffer)
2980         (progn
2981           (set-buffer buffer)
2982           (setq gnus-summary-buffer (current-buffer))
2983           (not gnus-newsgroup-prepared))
2984       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2985       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2986       (gnus-summary-mode group)
2987       (when gnus-carpal
2988         (gnus-carpal-setup-buffer 'summary))
2989       (unless gnus-single-article-buffer
2990         (make-local-variable 'gnus-article-buffer)
2991         (make-local-variable 'gnus-article-current)
2992         (make-local-variable 'gnus-original-article-buffer))
2993       (setq gnus-newsgroup-name group)
2994       ;; Set any local variables in the group parameters.
2995       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2996       t)))
2997
2998 (defun gnus-set-global-variables ()
2999   "Set the global equivalents of the buffer-local variables.
3000 They are set to the latest values they had.  These reflect the summary
3001 buffer that was in action when the last article was fetched."
3002   (when (eq major-mode 'gnus-summary-mode)
3003     (setq gnus-summary-buffer (current-buffer))
3004     (let ((name gnus-newsgroup-name)
3005           (marked gnus-newsgroup-marked)
3006           (spam gnus-newsgroup-spam-marked)
3007           (unread gnus-newsgroup-unreads)
3008           (headers gnus-current-headers)
3009           (data gnus-newsgroup-data)
3010           (summary gnus-summary-buffer)
3011           (article-buffer gnus-article-buffer)
3012           (original gnus-original-article-buffer)
3013           (gac gnus-article-current)
3014           (reffed gnus-reffed-article-number)
3015           (score-file gnus-current-score-file)
3016           (default-charset gnus-newsgroup-charset)
3017           vlist)
3018       (let ((locals gnus-newsgroup-variables))
3019         (while locals
3020           (if (consp (car locals))
3021               (push (eval (caar locals)) vlist)
3022             (push (eval (car locals)) vlist))
3023           (setq locals (cdr locals)))
3024         (setq vlist (nreverse vlist)))
3025       (save-excursion
3026         (set-buffer gnus-group-buffer)
3027         (setq gnus-newsgroup-name name
3028               gnus-newsgroup-marked marked
3029               gnus-newsgroup-spam-marked spam
3030               gnus-newsgroup-unreads unread
3031               gnus-current-headers headers
3032               gnus-newsgroup-data data
3033               gnus-article-current gac
3034               gnus-summary-buffer summary
3035               gnus-article-buffer article-buffer
3036               gnus-original-article-buffer original
3037               gnus-reffed-article-number reffed
3038               gnus-current-score-file score-file
3039               gnus-newsgroup-charset default-charset)
3040         (let ((locals gnus-newsgroup-variables))
3041           (while locals
3042             (if (consp (car locals))
3043                 (set (caar locals) (pop vlist))
3044               (set (car locals) (pop vlist)))
3045             (setq locals (cdr locals))))
3046         ;; The article buffer also has local variables.
3047         (when (gnus-buffer-live-p gnus-article-buffer)
3048           (set-buffer gnus-article-buffer)
3049           (setq gnus-summary-buffer summary))))))
3050
3051 (defun gnus-summary-article-unread-p (article)
3052   "Say whether ARTICLE is unread or not."
3053   (memq article gnus-newsgroup-unreads))
3054
3055 (defun gnus-summary-first-article-p (&optional article)
3056   "Return whether ARTICLE is the first article in the buffer."
3057   (if (not (setq article (or article (gnus-summary-article-number))))
3058       nil
3059     (eq article (caar gnus-newsgroup-data))))
3060
3061 (defun gnus-summary-last-article-p (&optional article)
3062   "Return whether ARTICLE is the last article in the buffer."
3063   (if (not (setq article (or article (gnus-summary-article-number))))
3064       ;; All non-existent numbers are the last article.  :-)
3065       t
3066     (not (cdr (gnus-data-find-list article)))))
3067
3068 (defun gnus-make-thread-indent-array ()
3069   (let ((n 200))
3070     (unless (and gnus-thread-indent-array
3071                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3072       (setq gnus-thread-indent-array (make-vector 201 "")
3073             gnus-thread-indent-array-level gnus-thread-indent-level)
3074       (while (>= n 0)
3075         (aset gnus-thread-indent-array n
3076               (make-string (* n gnus-thread-indent-level) ? ))
3077         (setq n (1- n))))))
3078
3079 (defun gnus-update-summary-mark-positions ()
3080   "Compute where the summary marks are to go."
3081   (save-excursion
3082     (when (gnus-buffer-exists-p gnus-summary-buffer)
3083       (set-buffer gnus-summary-buffer))
3084     (let ((gnus-replied-mark 129)
3085           (gnus-score-below-mark 130)
3086           (gnus-score-over-mark 130)
3087           (gnus-downloaded-mark 131)
3088           (spec gnus-summary-line-format-spec)
3089           gnus-visual pos)
3090       (save-excursion
3091         (gnus-set-work-buffer)
3092         (let ((gnus-summary-line-format-spec spec)
3093               (gnus-newsgroup-downloadable '(0)))
3094           (gnus-summary-insert-line
3095            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
3096            0 nil nil 128 t nil "" nil 1)
3097           (goto-char (point-min))
3098           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3099                                              (- (point) (point-min) 1)))))
3100           (goto-char (point-min))
3101           (push (cons 'replied (and (search-forward "\201" nil t)
3102                                     (- (point) (point-min) 1)))
3103                 pos)
3104           (goto-char (point-min))
3105           (push (cons 'score (and (search-forward "\202" nil t)
3106                                   (- (point) (point-min) 1)))
3107                 pos)
3108           (goto-char (point-min))
3109           (push (cons 'download
3110                       (and (search-forward "\203" nil t)
3111                            (- (point) (point-min) 1)))
3112                 pos)))
3113       (setq gnus-summary-mark-positions pos))))
3114
3115 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3116   "Insert a dummy root in the summary buffer."
3117   (beginning-of-line)
3118   (gnus-add-text-properties
3119    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3120    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3121
3122 (defun gnus-summary-extract-address-component (from)
3123   (or (car (funcall gnus-extract-address-components from))
3124       from))
3125
3126 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3127   (let ((mail-parse-charset gnus-newsgroup-charset)
3128         ; Is it really necessary to do this next part for each summary line?
3129         ; Luckily, doesn't seem to slow things down much.
3130         (mail-parse-ignored-charsets
3131          (save-excursion (set-buffer gnus-summary-buffer)
3132                          gnus-newsgroup-ignored-charsets)))
3133     (or
3134      (and gnus-ignored-from-addresses
3135           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3136           (let ((extra-headers (mail-header-extra header))
3137                 to
3138                 newsgroups)
3139             (cond
3140              ((setq to (cdr (assq 'To extra-headers)))
3141               (concat "-> "
3142                       (inline
3143                         (gnus-summary-extract-address-component
3144                          (funcall gnus-decode-encoded-word-function to)))))
3145              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3146               (concat "=> " newsgroups)))))
3147      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3148
3149 (defun gnus-summary-insert-line (gnus-tmp-header
3150                                  gnus-tmp-level gnus-tmp-current
3151                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3152                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3153                                  &optional gnus-tmp-dummy gnus-tmp-score
3154                                  gnus-tmp-process)
3155   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3156          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3157          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3158          (gnus-tmp-score-char
3159           (if (or (null gnus-summary-default-score)
3160                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3161                       gnus-summary-zcore-fuzz))
3162               ?                         ;Whitespace
3163             (if (< gnus-tmp-score gnus-summary-default-score)
3164                 gnus-score-below-mark gnus-score-over-mark)))
3165          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3166          (gnus-tmp-replied
3167           (cond (gnus-tmp-process gnus-process-mark)
3168                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3169                  gnus-cached-mark)
3170                 (gnus-tmp-replied gnus-replied-mark)
3171                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3172                  gnus-forwarded-mark)
3173                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3174                  gnus-saved-mark)
3175                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3176                  gnus-recent-mark)
3177                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3178                  gnus-unseen-mark)
3179                 (t gnus-no-mark)))
3180          (gnus-tmp-downloaded
3181           (cond (undownloaded 
3182                  gnus-undownloaded-mark)
3183                 (gnus-newsgroup-agentized
3184                  gnus-downloaded-mark)
3185                 (t
3186                  gnus-no-mark)))
3187          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3188          (gnus-tmp-name
3189           (cond
3190            ((string-match "<[^>]+> *$" gnus-tmp-from)
3191             (let ((beg (match-beginning 0)))
3192               (or (and (string-match "^\".+\"" gnus-tmp-from)
3193                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3194                   (substring gnus-tmp-from 0 beg))))
3195            ((string-match "(.+)" gnus-tmp-from)
3196             (substring gnus-tmp-from
3197                        (1+ (match-beginning 0)) (1- (match-end 0))))
3198            (t gnus-tmp-from)))
3199          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3200          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3201          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3202          (buffer-read-only nil))
3203     (when (string= gnus-tmp-name "")
3204       (setq gnus-tmp-name gnus-tmp-from))
3205     (unless (numberp gnus-tmp-lines)
3206       (setq gnus-tmp-lines -1))
3207     (if (= gnus-tmp-lines -1)
3208         (setq gnus-tmp-lines "?")
3209       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3210     (gnus-put-text-property
3211      (point)
3212      (progn (eval gnus-summary-line-format-spec) (point))
3213      'gnus-number gnus-tmp-number)
3214     (when (gnus-visual-p 'summary-highlight 'highlight)
3215       (forward-line -1)
3216       (gnus-run-hooks 'gnus-summary-update-hook)
3217       (forward-line 1))))
3218
3219 (defun gnus-summary-update-line (&optional dont-update)
3220   "Update summary line after change."
3221   (when (and gnus-summary-default-score
3222              (not gnus-summary-inhibit-highlight))
3223     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3224            (article (gnus-summary-article-number))
3225            (score (gnus-summary-article-score article)))
3226       (unless dont-update
3227         (if (and gnus-summary-mark-below
3228                  (< (gnus-summary-article-score)
3229                     gnus-summary-mark-below))
3230             ;; This article has a low score, so we mark it as read.
3231             (when (memq article gnus-newsgroup-unreads)
3232               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3233           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3234             ;; This article was previously marked as read on account
3235             ;; of a low score, but now it has risen, so we mark it as
3236             ;; unread.
3237             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3238         (gnus-summary-update-mark
3239          (if (or (null gnus-summary-default-score)
3240                  (<= (abs (- score gnus-summary-default-score))
3241                      gnus-summary-zcore-fuzz))
3242              ?                          ;Whitespace
3243            (if (< score gnus-summary-default-score)
3244                gnus-score-below-mark gnus-score-over-mark))
3245          'score))
3246       ;; Do visual highlighting.
3247       (when (gnus-visual-p 'summary-highlight 'highlight)
3248         (gnus-run-hooks 'gnus-summary-update-hook)))))
3249
3250 (defvar gnus-tmp-new-adopts nil)
3251
3252 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3253   "Return the number of articles in THREAD.
3254 This may be 0 in some cases -- if none of the articles in
3255 the thread are to be displayed."
3256   (let* ((number
3257          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3258           (cond
3259            ((not (listp thread))
3260             1)
3261            ((and (consp thread) (cdr thread))
3262             (apply
3263              '+ 1 (mapcar
3264                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3265            ((null thread)
3266             1)
3267            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3268             1)
3269            (t 0))))
3270     (when (and level (zerop level) gnus-tmp-new-adopts)
3271       (incf number
3272             (apply '+ (mapcar
3273                        'gnus-summary-number-of-articles-in-thread
3274                        gnus-tmp-new-adopts))))
3275     (if char
3276         (if (> number 1) gnus-not-empty-thread-mark
3277           gnus-empty-thread-mark)
3278       number)))
3279
3280 (defsubst gnus-summary-line-message-size (head)
3281   "Return pretty-printed version of message size.
3282 This function is intended to be used in
3283 `gnus-summary-line-format-alist', which see."
3284   (let ((c (or (mail-header-chars head) -1)))
3285     (cond ((< c 0) "n/a")               ; chars not available
3286           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3287           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3288           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3289           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3290
3291
3292 (defun gnus-summary-set-local-parameters (group)
3293   "Go through the local params of GROUP and set all variable specs in that list."
3294   (let ((params (gnus-group-find-parameter group))
3295         (vars '(quit-config))           ; Ignore quit-config.
3296         elem)
3297     (while params
3298       (setq elem (car params)
3299             params (cdr params))
3300       (and (consp elem)                 ; Has to be a cons.
3301            (consp (cdr elem))           ; The cdr has to be a list.
3302            (symbolp (car elem))         ; Has to be a symbol in there.
3303            (not (memq (car elem) vars))
3304            (ignore-errors               ; So we set it.
3305              (push (car elem) vars)
3306              (make-local-variable (car elem))
3307              (set (car elem) (eval (nth 1 elem))))))))
3308
3309 (defun gnus-summary-read-group (group &optional show-all no-article
3310                                       kill-buffer no-display backward
3311                                       select-articles)
3312   "Start reading news in newsgroup GROUP.
3313 If SHOW-ALL is non-nil, already read articles are also listed.
3314 If NO-ARTICLE is non-nil, no article is selected initially.
3315 If NO-DISPLAY, don't generate a summary buffer."
3316   (let (result)
3317     (while (and group
3318                 (null (setq result
3319                             (let ((gnus-auto-select-next nil))
3320                               (or (gnus-summary-read-group-1
3321                                    group show-all no-article
3322                                    kill-buffer no-display
3323                                    select-articles)
3324                                   (setq show-all nil
3325                                         select-articles nil)))))
3326                 (eq gnus-auto-select-next 'quietly))
3327       (set-buffer gnus-group-buffer)
3328       ;; The entry function called above goes to the next
3329       ;; group automatically, so we go two groups back
3330       ;; if we are searching for the previous group.
3331       (when backward
3332         (gnus-group-prev-unread-group 2))
3333       (if (not (equal group (gnus-group-group-name)))
3334           (setq group (gnus-group-group-name))
3335         (setq group nil)))
3336     result))
3337
3338 (defun gnus-summary-read-group-1 (group show-all no-article
3339                                         kill-buffer no-display
3340                                         &optional select-articles)
3341   ;; Killed foreign groups can't be entered.
3342   ;;  (when (and (not (gnus-group-native-p group))
3343   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3344   ;;    (error "Dead non-native groups can't be entered"))
3345   (gnus-message 5 "Retrieving newsgroup: %s..."
3346                 (gnus-group-decoded-name group))
3347   (let* ((new-group (gnus-summary-setup-buffer group))
3348          (quit-config (gnus-group-quit-config group))
3349          (did-select (and new-group (gnus-select-newsgroup
3350                                      group show-all select-articles))))
3351     (cond
3352      ;; This summary buffer exists already, so we just select it.
3353      ((not new-group)
3354       (gnus-set-global-variables)
3355       (when kill-buffer
3356         (gnus-kill-or-deaden-summary kill-buffer))
3357       (gnus-configure-windows 'summary 'force)
3358       (gnus-set-mode-line 'summary)
3359       (gnus-summary-position-point)
3360       (message "")
3361       t)
3362      ;; We couldn't select this group.
3363      ((null did-select)
3364       (when (and (eq major-mode 'gnus-summary-mode)
3365                  (not (equal (current-buffer) kill-buffer)))
3366         (kill-buffer (current-buffer))
3367         (if (not quit-config)
3368             (progn
3369               ;; Update the info -- marks might need to be removed,
3370               ;; for instance.
3371               (gnus-summary-update-info)
3372               (set-buffer gnus-group-buffer)
3373               (gnus-group-jump-to-group group)
3374               (gnus-group-next-unread-group 1))
3375           (gnus-handle-ephemeral-exit quit-config)))
3376       (let ((grpinfo (gnus-get-info group)))
3377         (if (null (gnus-info-read grpinfo))
3378             (gnus-message 3 "Group %s contains no messages"
3379                           (gnus-group-decoded-name group))
3380           (gnus-message 3 "Can't select group")))
3381       nil)
3382      ;; The user did a `C-g' while prompting for number of articles,
3383      ;; so we exit this group.
3384      ((eq did-select 'quit)
3385       (and (eq major-mode 'gnus-summary-mode)
3386            (not (equal (current-buffer) kill-buffer))
3387            (kill-buffer (current-buffer)))
3388       (when kill-buffer
3389         (gnus-kill-or-deaden-summary kill-buffer))
3390       (if (not quit-config)
3391           (progn
3392             (set-buffer gnus-group-buffer)
3393             (gnus-group-jump-to-group group)
3394             (gnus-group-next-unread-group 1)
3395             (gnus-configure-windows 'group 'force))
3396         (gnus-handle-ephemeral-exit quit-config))
3397       ;; Finally signal the quit.
3398       (signal 'quit nil))
3399      ;; The group was successfully selected.
3400      (t
3401       (gnus-set-global-variables)
3402       ;; Save the active value in effect when the group was entered.
3403       (setq gnus-newsgroup-active
3404             (gnus-copy-sequence
3405              (gnus-active gnus-newsgroup-name)))
3406       ;; You can change the summary buffer in some way with this hook.
3407       (gnus-run-hooks 'gnus-select-group-hook)
3408       (gnus-update-format-specifications
3409        nil 'summary 'summary-mode 'summary-dummy)
3410       (gnus-update-summary-mark-positions)
3411       ;; Do score processing.
3412       (when gnus-use-scoring
3413         (gnus-possibly-score-headers))
3414       ;; Check whether to fill in the gaps in the threads.
3415       (when gnus-build-sparse-threads
3416         (gnus-build-sparse-threads))
3417       ;; Find the initial limit.
3418       (if gnus-show-threads
3419           (if show-all
3420               (let ((gnus-newsgroup-dormant nil))
3421                 (gnus-summary-initial-limit show-all))
3422             (gnus-summary-initial-limit show-all))
3423         ;; When unthreaded, all articles are always shown.
3424         (setq gnus-newsgroup-limit
3425               (mapcar
3426                (lambda (header) (mail-header-number header))
3427                gnus-newsgroup-headers)))
3428       ;; Generate the summary buffer.
3429       (unless no-display
3430         (gnus-summary-prepare))
3431       (when gnus-use-trees
3432         (gnus-tree-open group)
3433         (setq gnus-summary-highlight-line-function
3434               'gnus-tree-highlight-article))
3435       ;; If the summary buffer is empty, but there are some low-scored
3436       ;; articles or some excluded dormants, we include these in the
3437       ;; buffer.
3438       (when (and (zerop (buffer-size))
3439                  (not no-display))
3440         (cond (gnus-newsgroup-dormant
3441                (gnus-summary-limit-include-dormant))
3442               ((and gnus-newsgroup-scored show-all)
3443                (gnus-summary-limit-include-expunged t))))
3444       ;; Function `gnus-apply-kill-file' must be called in this hook.
3445       (gnus-run-hooks 'gnus-apply-kill-hook)
3446       (if (and (zerop (buffer-size))
3447                (not no-display))
3448           (progn
3449             ;; This newsgroup is empty.
3450             (gnus-summary-catchup-and-exit nil t)
3451             (gnus-message 6 "No unread news")
3452             (when kill-buffer
3453               (gnus-kill-or-deaden-summary kill-buffer))
3454             ;; Return nil from this function.
3455             nil)
3456         ;; Hide conversation thread subtrees.  We cannot do this in
3457         ;; gnus-summary-prepare-hook since kill processing may not
3458         ;; work with hidden articles.
3459         (gnus-summary-maybe-hide-threads)
3460         (when kill-buffer
3461           (gnus-kill-or-deaden-summary kill-buffer))
3462         (gnus-summary-auto-select-subject)
3463         ;; Show first unread article if requested.
3464         (if (and (not no-article)
3465                  (not no-display)
3466                  gnus-newsgroup-unreads
3467                  gnus-auto-select-first)
3468             (progn
3469               (gnus-configure-windows 'summary)
3470               (let ((art (gnus-summary-article-number)))
3471                 (unless (or (memq art gnus-newsgroup-undownloaded)
3472                             (memq art gnus-newsgroup-downloadable))
3473                   (gnus-summary-goto-article art))))
3474           ;; Don't select any articles.
3475           (gnus-summary-position-point)
3476           (gnus-configure-windows 'summary 'force)
3477           (gnus-set-mode-line 'summary))
3478         (when (get-buffer-window gnus-group-buffer t)
3479           ;; Gotta use windows, because recenter does weird stuff if
3480           ;; the current buffer ain't the displayed window.
3481           (let ((owin (selected-window)))
3482             (select-window (get-buffer-window gnus-group-buffer t))
3483             (when (gnus-group-goto-group group)
3484               (recenter))
3485             (select-window owin)))
3486         ;; Mark this buffer as "prepared".
3487         (setq gnus-newsgroup-prepared t)
3488         (gnus-run-hooks 'gnus-summary-prepared-hook)
3489         t)))))
3490
3491 (defun gnus-summary-auto-select-subject ()
3492   "Select the subject line on initial group entry."
3493   (goto-char (point-min))
3494   (cond
3495    ((eq gnus-auto-select-subject 'best)
3496     (gnus-summary-best-unread-subject))
3497    ((eq gnus-auto-select-subject 'unread)
3498     (gnus-summary-first-unread-subject))
3499    ((eq gnus-auto-select-subject 'unseen)
3500     (gnus-summary-first-unseen-subject))
3501    ((eq gnus-auto-select-subject 'unseen-or-unread)
3502     (gnus-summary-first-unseen-or-unread-subject))
3503    ((eq gnus-auto-select-subject 'first)
3504     ;; Do nothing.
3505     )
3506    ((gnus-functionp gnus-auto-select-subject)
3507     (funcall gnus-auto-select-subject))))
3508
3509 (defun gnus-summary-prepare ()
3510   "Generate the summary buffer."
3511   (interactive)
3512   (let ((buffer-read-only nil))
3513     (erase-buffer)
3514     (setq gnus-newsgroup-data nil
3515           gnus-newsgroup-data-reverse nil)
3516     (gnus-run-hooks 'gnus-summary-generate-hook)
3517     ;; Generate the buffer, either with threads or without.
3518     (when gnus-newsgroup-headers
3519       (gnus-summary-prepare-threads
3520        (if gnus-show-threads
3521            (gnus-sort-gathered-threads
3522             (funcall gnus-summary-thread-gathering-function
3523                      (gnus-sort-threads
3524                       (gnus-cut-threads (gnus-make-threads)))))
3525          ;; Unthreaded display.
3526          (gnus-sort-articles gnus-newsgroup-headers))))
3527     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3528     ;; Call hooks for modifying summary buffer.
3529     (goto-char (point-min))
3530     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3531
3532 (defsubst gnus-general-simplify-subject (subject)
3533   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3534   (setq subject
3535         (cond
3536          ;; Truncate the subject.
3537          (gnus-simplify-subject-functions
3538           (gnus-map-function gnus-simplify-subject-functions subject))
3539          ((numberp gnus-summary-gather-subject-limit)
3540           (setq subject (gnus-simplify-subject-re subject))
3541           (if (> (length subject) gnus-summary-gather-subject-limit)
3542               (substring subject 0 gnus-summary-gather-subject-limit)
3543             subject))
3544          ;; Fuzzily simplify it.
3545          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3546           (gnus-simplify-subject-fuzzy subject))
3547          ;; Just remove the leading "Re:".
3548          (t
3549           (gnus-simplify-subject-re subject))))
3550
3551   (if (and gnus-summary-gather-exclude-subject
3552            (string-match gnus-summary-gather-exclude-subject subject))
3553       nil                         ; This article shouldn't be gathered
3554     subject))
3555
3556 (defun gnus-summary-simplify-subject-query ()
3557   "Query where the respool algorithm would put this article."
3558   (interactive)
3559   (gnus-summary-select-article)
3560   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3561
3562 (defun gnus-gather-threads-by-subject (threads)
3563   "Gather threads by looking at Subject headers."
3564   (if (not gnus-summary-make-false-root)
3565       threads
3566     (let ((hashtb (gnus-make-hashtable 1024))
3567           (prev threads)
3568           (result threads)
3569           subject hthread whole-subject)
3570       (while threads
3571         (setq subject (gnus-general-simplify-subject
3572                        (setq whole-subject (mail-header-subject
3573                                             (caar threads)))))
3574         (when subject
3575           (if (setq hthread (gnus-gethash subject hashtb))
3576               (progn
3577                 ;; We enter a dummy root into the thread, if we
3578                 ;; haven't done that already.
3579                 (unless (stringp (caar hthread))
3580                   (setcar hthread (list whole-subject (car hthread))))
3581                 ;; We add this new gathered thread to this gathered
3582                 ;; thread.
3583                 (setcdr (car hthread)
3584                         (nconc (cdar hthread) (list (car threads))))
3585                 ;; Remove it from the list of threads.
3586                 (setcdr prev (cdr threads))
3587                 (setq threads prev))
3588             ;; Enter this thread into the hash table.
3589             (gnus-sethash subject threads hashtb)))
3590         (setq prev threads)
3591         (setq threads (cdr threads)))
3592       result)))
3593
3594 (defun gnus-gather-threads-by-references (threads)
3595   "Gather threads by looking at References headers."
3596   (let ((idhashtb (gnus-make-hashtable 1024))
3597         (thhashtb (gnus-make-hashtable 1024))
3598         (prev threads)
3599         (result threads)
3600         ids references id gthread gid entered ref)
3601     (while threads
3602       (when (setq references (mail-header-references (caar threads)))
3603         (setq id (mail-header-id (caar threads))
3604               ids (inline (gnus-split-references references))
3605               entered nil)
3606         (while (setq ref (pop ids))
3607           (setq ids (delete ref ids))
3608           (if (not (setq gid (gnus-gethash ref idhashtb)))
3609               (progn
3610                 (gnus-sethash ref id idhashtb)
3611                 (gnus-sethash id threads thhashtb))
3612             (setq gthread (gnus-gethash gid thhashtb))
3613             (unless entered
3614               ;; We enter a dummy root into the thread, if we
3615               ;; haven't done that already.
3616               (unless (stringp (caar gthread))
3617                 (setcar gthread (list (mail-header-subject (caar gthread))
3618                                       (car gthread))))
3619               ;; We add this new gathered thread to this gathered
3620               ;; thread.
3621               (setcdr (car gthread)
3622                       (nconc (cdar gthread) (list (car threads)))))
3623             ;; Add it into the thread hash table.
3624             (gnus-sethash id gthread thhashtb)
3625             (setq entered t)
3626             ;; Remove it from the list of threads.
3627             (setcdr prev (cdr threads))
3628             (setq threads prev))))
3629       (setq prev threads)
3630       (setq threads (cdr threads)))
3631     result))
3632
3633 (defun gnus-sort-gathered-threads (threads)
3634   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3635   (let ((result threads))
3636     (while threads
3637       (when (stringp (caar threads))
3638         (setcdr (car threads)
3639                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3640       (setq threads (cdr threads)))
3641     result))
3642
3643 (defun gnus-thread-loop-p (root thread)
3644   "Say whether ROOT is in THREAD."
3645   (let ((stack (list thread))
3646         (infloop 0)
3647         th)
3648     (while (setq thread (pop stack))
3649       (setq th (cdr thread))
3650       (while (and th
3651                   (not (eq (caar th) root)))
3652         (pop th))
3653       (if th
3654           ;; We have found a loop.
3655           (let (ref-dep)
3656             (setcdr thread (delq (car th) (cdr thread)))
3657             (if (boundp (setq ref-dep (intern "none"
3658                                               gnus-newsgroup-dependencies)))
3659                 (setcdr (symbol-value ref-dep)
3660                         (nconc (cdr (symbol-value ref-dep))
3661                                (list (car th))))
3662               (set ref-dep (list nil (car th))))
3663             (setq infloop 1
3664                   stack nil))
3665         ;; Push all the subthreads onto the stack.
3666         (push (cdr thread) stack)))
3667     infloop))
3668
3669 (defun gnus-make-threads ()
3670   "Go through the dependency hashtb and find the roots.  Return all threads."
3671   (let (threads)
3672     (while (catch 'infloop
3673              (mapatoms
3674               (lambda (refs)
3675                 ;; Deal with self-referencing References loops.
3676                 (when (and (car (symbol-value refs))
3677                            (not (zerop
3678                                  (apply
3679                                   '+
3680                                   (mapcar
3681                                    (lambda (thread)
3682                                      (gnus-thread-loop-p
3683                                       (car (symbol-value refs)) thread))
3684                                    (cdr (symbol-value refs)))))))
3685                   (setq threads nil)
3686                   (throw 'infloop t))
3687                 (unless (car (symbol-value refs))
3688                   ;; These threads do not refer back to any other
3689                   ;; articles, so they're roots.
3690                   (setq threads (append (cdr (symbol-value refs)) threads))))
3691               gnus-newsgroup-dependencies)))
3692     threads))
3693
3694 ;; Build the thread tree.
3695 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3696   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3697
3698 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3699 if it was already present.
3700
3701 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3702 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3703 Message-IDs will be renamed to a unique Message-ID before being
3704 entered.
3705
3706 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3707   (let* ((id (mail-header-id header))
3708          (id-dep (and id (intern id dependencies)))
3709          parent-id ref ref-dep ref-header replaced)
3710     ;; Enter this `header' in the `dependencies' table.
3711     (cond
3712      ((not id-dep)
3713       (setq header nil))
3714      ;; The first two cases do the normal part: enter a new `header'
3715      ;; in the `dependencies' table.
3716      ((not (boundp id-dep))
3717       (set id-dep (list header)))
3718      ((null (car (symbol-value id-dep)))
3719       (setcar (symbol-value id-dep) header))
3720
3721      ;; From here the `header' was already present in the
3722      ;; `dependencies' table.
3723      (force-new
3724       ;; Overrides an existing entry;
3725       ;; just set the header part of the entry.
3726       (setcar (symbol-value id-dep) header)
3727       (setq replaced t))
3728
3729      ;; Renames the existing `header' to a unique Message-ID.
3730      ((not gnus-summary-ignore-duplicates)
3731       ;; An article with this Message-ID has already been seen.
3732       ;; We rename the Message-ID.
3733       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3734            (list header))
3735       (mail-header-set-id header id))
3736
3737      ;; The last case ignores an existing entry, except it adds any
3738      ;; additional Xrefs (in case the two articles came from different
3739      ;; servers.
3740      ;; Also sets `header' to `nil' meaning that the `dependencies'
3741      ;; table was *not* modified.
3742      (t
3743       (mail-header-set-xref
3744        (car (symbol-value id-dep))
3745        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3746                    "")
3747                (or (mail-header-xref header) "")))
3748       (setq header nil)))
3749
3750     (when (and header (not replaced))
3751       ;; First check that we are not creating a References loop.
3752       (setq parent-id (gnus-parent-id (mail-header-references header)))
3753       (setq ref parent-id)
3754       (while (and ref
3755                   (setq ref-dep (intern-soft ref dependencies))
3756                   (boundp ref-dep)
3757                   (setq ref-header (car (symbol-value ref-dep))))
3758         (if (string= id ref)
3759             ;; Yuk!  This is a reference loop.  Make the article be a
3760             ;; root article.
3761             (progn
3762               (mail-header-set-references (car (symbol-value id-dep)) "none")
3763               (setq ref nil)
3764               (setq parent-id nil))
3765           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3766       (setq ref-dep (intern (or parent-id "none") dependencies))
3767       (if (boundp ref-dep)
3768           (setcdr (symbol-value ref-dep)
3769                   (nconc (cdr (symbol-value ref-dep))
3770                          (list (symbol-value id-dep))))
3771         (set ref-dep (list nil (symbol-value id-dep)))))
3772     header))
3773
3774 (defun gnus-extract-message-id-from-in-reply-to (string)
3775   (if (string-match "<[^>]+>" string)
3776       (substring string (match-beginning 0) (match-end 0))
3777     nil))
3778
3779 (defun gnus-build-sparse-threads ()
3780   (let ((headers gnus-newsgroup-headers)
3781         (mail-parse-charset gnus-newsgroup-charset)
3782         (gnus-summary-ignore-duplicates t)
3783         header references generation relations
3784         subject child end new-child date)
3785     ;; First we create an alist of generations/relations, where
3786     ;; generations is how much we trust the relation, and the relation
3787     ;; is parent/child.
3788     (gnus-message 7 "Making sparse threads...")
3789     (save-excursion
3790       (nnheader-set-temp-buffer " *gnus sparse threads*")
3791       (while (setq header (pop headers))
3792         (when (and (setq references (mail-header-references header))
3793                    (not (string= references "")))
3794           (insert references)
3795           (setq child (mail-header-id header)
3796                 subject (mail-header-subject header)
3797                 date (mail-header-date header)
3798                 generation 0)
3799           (while (search-backward ">" nil t)
3800             (setq end (1+ (point)))
3801             (when (search-backward "<" nil t)
3802               (setq new-child (buffer-substring (point) end))
3803               (push (list (incf generation)
3804                           child (setq child new-child)
3805                           subject date)
3806                     relations)))
3807           (when child
3808             (push (list (1+ generation) child nil subject) relations))
3809           (erase-buffer)))
3810       (kill-buffer (current-buffer)))
3811     ;; Sort over trustworthiness.
3812     (mapcar
3813      (lambda (relation)
3814        (when (gnus-dependencies-add-header
3815               (make-full-mail-header
3816                gnus-reffed-article-number
3817                (nth 3 relation) "" (or (nth 4 relation) "")
3818                (nth 1 relation)
3819                (or (nth 2 relation) "") 0 0 "")
3820               gnus-newsgroup-dependencies nil)
3821          (push gnus-reffed-article-number gnus-newsgroup-limit)
3822          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3823          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3824                gnus-newsgroup-reads)
3825          (decf gnus-reffed-article-number)))
3826      (sort relations 'car-less-than-car))
3827     (gnus-message 7 "Making sparse threads...done")))
3828
3829 (defun gnus-build-old-threads ()
3830   ;; Look at all the articles that refer back to old articles, and
3831   ;; fetch the headers for the articles that aren't there.  This will
3832   ;; build complete threads - if the roots haven't been expired by the
3833   ;; server, that is.
3834   (let ((mail-parse-charset gnus-newsgroup-charset)
3835         id heads)
3836     (mapatoms
3837      (lambda (refs)
3838        (when (not (car (symbol-value refs)))
3839          (setq heads (cdr (symbol-value refs)))
3840          (while heads
3841            (if (memq (mail-header-number (caar heads))
3842                      gnus-newsgroup-dormant)
3843                (setq heads (cdr heads))
3844              (setq id (symbol-name refs))
3845              (while (and (setq id (gnus-build-get-header id))
3846                          (not (car (gnus-id-to-thread id)))))
3847              (setq heads nil)))))
3848      gnus-newsgroup-dependencies)))
3849
3850 ;; This function has to be called with point after the article number
3851 ;; on the beginning of the line.
3852 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3853   (let ((eol (gnus-point-at-eol))
3854         (buffer (current-buffer))
3855         header references in-reply-to)
3856
3857     ;; overview: [num subject from date id refs chars lines misc]
3858     (unwind-protect
3859         (let (x)
3860           (narrow-to-region (point) eol)
3861           (unless (eobp)
3862             (forward-char))
3863
3864           (setq header
3865                 (make-full-mail-header
3866                  number                 ; number
3867                  (condition-case ()     ; subject
3868                      (funcall gnus-decode-encoded-word-function
3869                               (setq x (nnheader-nov-field)))
3870                    (error x))
3871                  (condition-case ()     ; from
3872                      (funcall gnus-decode-encoded-word-function
3873                               (setq x (nnheader-nov-field)))
3874                    (error x))
3875                  (nnheader-nov-field)   ; date
3876                  (nnheader-nov-read-message-id) ; id
3877                  (setq references (nnheader-nov-field)) ; refs
3878                  (nnheader-nov-read-integer) ; chars
3879                  (nnheader-nov-read-integer) ; lines
3880                  (unless (eobp)
3881                    (if (looking-at "Xref: ")
3882                        (goto-char (match-end 0)))
3883                    (nnheader-nov-field)) ; Xref
3884                  (nnheader-nov-parse-extra)))) ; extra
3885
3886       (widen))
3887
3888     (when (and (string= references "")
3889                (setq in-reply-to (mail-header-extra header))
3890                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3891       (mail-header-set-references
3892        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3893
3894     (when gnus-alter-header-function
3895       (funcall gnus-alter-header-function header))
3896     (gnus-dependencies-add-header header dependencies force-new)))
3897
3898 (defun gnus-build-get-header (id)
3899   "Look through the buffer of NOV lines and find the header to ID.
3900 Enter this line into the dependencies hash table, and return
3901 the id of the parent article (if any)."
3902   (let ((deps gnus-newsgroup-dependencies)
3903         found header)
3904     (prog1
3905         (save-excursion
3906           (set-buffer nntp-server-buffer)
3907           (let ((case-fold-search nil))
3908             (goto-char (point-min))
3909             (while (and (not found)
3910                         (search-forward id nil t))
3911               (beginning-of-line)
3912               (setq found (looking-at
3913                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3914                                    (regexp-quote id))))
3915               (or found (beginning-of-line 2)))
3916             (when found
3917               (beginning-of-line)
3918               (and
3919                (setq header (gnus-nov-parse-line
3920                              (read (current-buffer)) deps))
3921                (gnus-parent-id (mail-header-references header))))))
3922       (when header
3923         (let ((number (mail-header-number header)))
3924           (push number gnus-newsgroup-limit)
3925           (push header gnus-newsgroup-headers)
3926           (if (memq number gnus-newsgroup-unselected)
3927               (progn
3928                 (setq gnus-newsgroup-unreads
3929                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3930                                                number))
3931                 (setq gnus-newsgroup-unselected
3932                       (delq number gnus-newsgroup-unselected)))
3933             (push number gnus-newsgroup-ancient)))))))
3934
3935 (defun gnus-build-all-threads ()
3936   "Read all the headers."
3937   (let ((gnus-summary-ignore-duplicates t)
3938         (mail-parse-charset gnus-newsgroup-charset)
3939         (dependencies gnus-newsgroup-dependencies)
3940         header article)
3941     (save-excursion
3942       (set-buffer nntp-server-buffer)
3943       (let ((case-fold-search nil))
3944         (goto-char (point-min))
3945         (while (not (eobp))
3946           (ignore-errors
3947             (setq article (read (current-buffer))
3948                   header (gnus-nov-parse-line article dependencies)))
3949           (when header
3950             (save-excursion
3951               (set-buffer gnus-summary-buffer)
3952               (push header gnus-newsgroup-headers)
3953               (if (memq (setq article (mail-header-number header))
3954                         gnus-newsgroup-unselected)
3955                   (progn
3956                     (setq gnus-newsgroup-unreads
3957                           (gnus-add-to-sorted-list
3958                            gnus-newsgroup-unreads article))
3959                     (setq gnus-newsgroup-unselected
3960                           (delq article gnus-newsgroup-unselected)))
3961                 (push article gnus-newsgroup-ancient)))
3962             (forward-line 1)))))))
3963
3964 (defun gnus-summary-update-article-line (article header)
3965   "Update the line for ARTICLE using HEADERS."
3966   (let* ((id (mail-header-id header))
3967          (thread (gnus-id-to-thread id)))
3968     (unless thread
3969       (error "Article in no thread"))
3970     ;; Update the thread.
3971     (setcar thread header)
3972     (gnus-summary-goto-subject article)
3973     (let* ((datal (gnus-data-find-list article))
3974            (data (car datal))
3975            (length (when (cdr datal)
3976                      (- (gnus-data-pos data)
3977                         (gnus-data-pos (cadr datal)))))
3978            (buffer-read-only nil)
3979            (level (gnus-summary-thread-level)))
3980       (gnus-delete-line)
3981       (gnus-summary-insert-line
3982        header level nil 
3983        (memq article gnus-newsgroup-undownloaded)
3984        (gnus-article-mark article)
3985        (memq article gnus-newsgroup-replied)
3986        (memq article gnus-newsgroup-expirable)
3987        ;; Only insert the Subject string when it's different
3988        ;; from the previous Subject string.
3989        (if (and
3990             gnus-show-threads
3991             (gnus-subject-equal
3992              (condition-case ()
3993                  (mail-header-subject
3994                   (gnus-data-header
3995                    (cadr
3996                     (gnus-data-find-list
3997                      article
3998                      (gnus-data-list t)))))
3999                ;; Error on the side of excessive subjects.
4000                (error ""))
4001              (mail-header-subject header)))
4002            ""
4003          (mail-header-subject header))
4004        nil (cdr (assq article gnus-newsgroup-scored))
4005        (memq article gnus-newsgroup-processable))
4006       (when length
4007         (gnus-data-update-list
4008          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
4009
4010 (defun gnus-summary-update-article (article &optional iheader)
4011   "Update ARTICLE in the summary buffer."
4012   (set-buffer gnus-summary-buffer)
4013   (let* ((header (gnus-summary-article-header article))
4014          (id (mail-header-id header))
4015          (data (gnus-data-find article))
4016          (thread (gnus-id-to-thread id))
4017          (references (mail-header-references header))
4018          (parent
4019           (gnus-id-to-thread
4020            (or (gnus-parent-id
4021                 (when (and references
4022                            (not (equal "" references)))
4023                   references))
4024                "none")))
4025          (buffer-read-only nil)
4026          (old (car thread)))
4027     (when thread
4028       (unless iheader
4029         (setcar thread nil)
4030         (when parent
4031           (delq thread parent)))
4032       (if (gnus-summary-insert-subject id header)
4033        ;; Set the (possibly) new article number in the data structure.
4034           (gnus-data-set-number data (gnus-id-to-article id))
4035         (setcar thread old)
4036         nil))))
4037
4038 (defun gnus-rebuild-thread (id &optional line)
4039   "Rebuild the thread containing ID.
4040 If LINE, insert the rebuilt thread starting on line LINE."
4041   (let ((buffer-read-only nil)
4042         old-pos current thread data)
4043     (if (not gnus-show-threads)
4044         (setq thread (list (car (gnus-id-to-thread id))))
4045       ;; Get the thread this article is part of.
4046       (setq thread (gnus-remove-thread id)))
4047     (setq old-pos (gnus-point-at-bol))
4048     (setq current (save-excursion
4049                     (and (re-search-backward "[\r\n]" nil t)
4050                          (gnus-summary-article-number))))
4051     ;; If this is a gathered thread, we have to go some re-gathering.
4052     (when (stringp (car thread))
4053       (let ((subject (car thread))
4054             roots thr)
4055         (setq thread (cdr thread))
4056         (while thread
4057           (unless (memq (setq thr (gnus-id-to-thread
4058                                    (gnus-root-id
4059                                     (mail-header-id (caar thread)))))
4060                         roots)
4061             (push thr roots))
4062           (setq thread (cdr thread)))
4063         ;; We now have all (unique) roots.
4064         (if (= (length roots) 1)
4065             ;; All the loose roots are now one solid root.
4066             (setq thread (car roots))
4067           (setq thread (cons subject (gnus-sort-threads roots))))))
4068     (let (threads)
4069       ;; We then insert this thread into the summary buffer.
4070       (when line
4071         (goto-char (point-min))
4072         (forward-line (1- line)))
4073       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4074         (if gnus-show-threads
4075             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4076           (gnus-summary-prepare-unthreaded thread))
4077         (setq data (nreverse gnus-newsgroup-data))
4078         (setq threads gnus-newsgroup-threads))
4079       ;; We splice the new data into the data structure.
4080       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4081       ;;!!! then we want to insert at the beginning of the buffer.
4082       ;;!!! That happens to be true with Gnus now, but that may
4083       ;;!!! change in the future.  Perhaps.
4084       (gnus-data-enter-list
4085        (if line nil current) data (- (point) old-pos))
4086       (setq gnus-newsgroup-threads
4087             (nconc threads gnus-newsgroup-threads))
4088       (gnus-data-compute-positions))))
4089
4090 (defun gnus-number-to-header (number)
4091   "Return the header for article NUMBER."
4092   (let ((headers gnus-newsgroup-headers))
4093     (while (and headers
4094                 (not (= number (mail-header-number (car headers)))))
4095       (pop headers))
4096     (when headers
4097       (car headers))))
4098
4099 (defun gnus-parent-headers (in-headers &optional generation)
4100   "Return the headers of the GENERATIONeth parent of HEADERS."
4101   (unless generation
4102     (setq generation 1))
4103   (let ((parent t)
4104         (headers in-headers)
4105         references)
4106     (while (and parent
4107                 (not (zerop generation))
4108                 (setq references (mail-header-references headers)))
4109       (setq headers (if (and references
4110                              (setq parent (gnus-parent-id references)))
4111                         (car (gnus-id-to-thread parent))
4112                       nil))
4113       (decf generation))
4114     (and (not (eq headers in-headers))
4115          headers)))
4116
4117 (defun gnus-id-to-thread (id)
4118   "Return the (sub-)thread where ID appears."
4119   (gnus-gethash id gnus-newsgroup-dependencies))
4120
4121 (defun gnus-id-to-article (id)
4122   "Return the article number of ID."
4123   (let ((thread (gnus-id-to-thread id)))
4124     (when (and thread
4125                (car thread))
4126       (mail-header-number (car thread)))))
4127
4128 (defun gnus-id-to-header (id)
4129   "Return the article headers of ID."
4130   (car (gnus-id-to-thread id)))
4131
4132 (defun gnus-article-displayed-root-p (article)
4133   "Say whether ARTICLE is a root(ish) article."
4134   (let ((level (gnus-summary-thread-level article))
4135         (refs (mail-header-references  (gnus-summary-article-header article)))
4136         particle)
4137     (cond
4138      ((null level) nil)
4139      ((zerop level) t)
4140      ((null refs) t)
4141      ((null (gnus-parent-id refs)) t)
4142      ((and (= 1 level)
4143            (null (setq particle (gnus-id-to-article
4144                                  (gnus-parent-id refs))))
4145            (null (gnus-summary-thread-level particle)))))))
4146
4147 (defun gnus-root-id (id)
4148   "Return the id of the root of the thread where ID appears."
4149   (let (last-id prev)
4150     (while (and id (setq prev (car (gnus-id-to-thread id))))
4151       (setq last-id id
4152             id (gnus-parent-id (mail-header-references prev))))
4153     last-id))
4154
4155 (defun gnus-articles-in-thread (thread)
4156   "Return the list of articles in THREAD."
4157   (cons (mail-header-number (car thread))
4158         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4159
4160 (defun gnus-remove-thread (id &optional dont-remove)
4161   "Remove the thread that has ID in it."
4162   (let (headers thread last-id)
4163     ;; First go up in this thread until we find the root.
4164     (setq last-id (gnus-root-id id)
4165           headers (message-flatten-list (gnus-id-to-thread last-id)))
4166     ;; We have now found the real root of this thread.  It might have
4167     ;; been gathered into some loose thread, so we have to search
4168     ;; through the threads to find the thread we wanted.
4169     (let ((threads gnus-newsgroup-threads)
4170           sub)
4171       (while threads
4172         (setq sub (car threads))
4173         (if (stringp (car sub))
4174             ;; This is a gathered thread, so we look at the roots
4175             ;; below it to find whether this article is in this
4176             ;; gathered root.
4177             (progn
4178               (setq sub (cdr sub))
4179               (while sub
4180                 (when (member (caar sub) headers)
4181                   (setq thread (car threads)
4182                         threads nil
4183                         sub nil))
4184                 (setq sub (cdr sub))))
4185           ;; It's an ordinary thread, so we check it.
4186           (when (eq (car sub) (car headers))
4187             (setq thread sub
4188                   threads nil)))
4189         (setq threads (cdr threads)))
4190       ;; If this article is in no thread, then it's a root.
4191       (if thread
4192           (unless dont-remove
4193             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4194         (setq thread (gnus-id-to-thread last-id)))
4195       (when thread
4196         (prog1
4197             thread                      ; We return this thread.
4198           (unless dont-remove
4199             (if (stringp (car thread))
4200                 (progn
4201                   ;; If we use dummy roots, then we have to remove the
4202                   ;; dummy root as well.
4203                   (when (eq gnus-summary-make-false-root 'dummy)
4204                     ;; We go to the dummy root by going to
4205                     ;; the first sub-"thread", and then one line up.
4206                     (gnus-summary-goto-article
4207                      (mail-header-number (caadr thread)))
4208                     (forward-line -1)
4209                     (gnus-delete-line)
4210                     (gnus-data-compute-positions))
4211                   (setq thread (cdr thread))
4212                   (while thread
4213                     (gnus-remove-thread-1 (car thread))
4214                     (setq thread (cdr thread))))
4215               (gnus-remove-thread-1 thread))))))))
4216
4217 (defun gnus-remove-thread-1 (thread)
4218   "Remove the thread THREAD recursively."
4219   (let ((number (mail-header-number (pop thread)))
4220         d)
4221     (setq thread (reverse thread))
4222     (while thread
4223       (gnus-remove-thread-1 (pop thread)))
4224     (when (setq d (gnus-data-find number))
4225       (goto-char (gnus-data-pos d))
4226       (gnus-summary-show-thread)
4227       (gnus-data-remove
4228        number
4229        (- (gnus-point-at-bol)
4230           (prog1
4231               (1+ (gnus-point-at-eol))
4232             (gnus-delete-line)))))))
4233
4234 (defun gnus-sort-threads-1 (threads func)
4235   (sort (mapcar (lambda (thread)
4236                   (cons (car thread)
4237                         (and (cdr thread)
4238                              (gnus-sort-threads-1 (cdr thread) func))))
4239                 threads) func))
4240
4241 (defun gnus-sort-threads (threads)
4242   "Sort THREADS."
4243   (if (not gnus-thread-sort-functions)
4244       threads
4245     (gnus-message 8 "Sorting threads...")
4246     (let ((max-lisp-eval-depth 5000))
4247       (prog1 (gnus-sort-threads-1
4248          threads
4249          (gnus-make-sort-function gnus-thread-sort-functions))
4250         (gnus-message 8 "Sorting threads...done")))))
4251
4252 (defun gnus-sort-articles (articles)
4253   "Sort ARTICLES."
4254   (when gnus-article-sort-functions
4255     (gnus-message 7 "Sorting articles...")
4256     (prog1
4257         (setq gnus-newsgroup-headers
4258               (sort articles (gnus-make-sort-function
4259                               gnus-article-sort-functions)))
4260       (gnus-message 7 "Sorting articles...done"))))
4261
4262 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4263 (defmacro gnus-thread-header (thread)
4264   "Return header of first article in THREAD.
4265 Note that THREAD must never, ever be anything else than a variable -
4266 using some other form will lead to serious barfage."
4267   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4268   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4269   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4270         (vector thread) 2))
4271
4272 (defsubst gnus-article-sort-by-number (h1 h2)
4273   "Sort articles by article number."
4274   (< (mail-header-number h1)
4275      (mail-header-number h2)))
4276
4277 (defun gnus-thread-sort-by-number (h1 h2)
4278   "Sort threads by root article number."
4279   (gnus-article-sort-by-number
4280    (gnus-thread-header h1) (gnus-thread-header h2)))
4281
4282 (defsubst gnus-article-sort-by-random (h1 h2)
4283   "Sort articles by article number."
4284   (zerop (random 2)))
4285
4286 (defun gnus-thread-sort-by-random (h1 h2)
4287   "Sort threads by root article number."
4288   (gnus-article-sort-by-random
4289    (gnus-thread-header h1) (gnus-thread-header h2)))
4290
4291 (defsubst gnus-article-sort-by-lines (h1 h2)
4292   "Sort articles by article Lines header."
4293   (< (mail-header-lines h1)
4294      (mail-header-lines h2)))
4295
4296 (defun gnus-thread-sort-by-lines (h1 h2)
4297   "Sort threads by root article Lines header."
4298   (gnus-article-sort-by-lines
4299    (gnus-thread-header h1) (gnus-thread-header h2)))
4300
4301 (defsubst gnus-article-sort-by-chars (h1 h2)
4302   "Sort articles by octet length."
4303   (< (mail-header-chars h1)
4304      (mail-header-chars h2)))
4305
4306 (defun gnus-thread-sort-by-chars (h1 h2)
4307   "Sort threads by root article octet length."
4308   (gnus-article-sort-by-chars
4309    (gnus-thread-header h1) (gnus-thread-header h2)))
4310
4311 (defsubst gnus-article-sort-by-author (h1 h2)
4312   "Sort articles by root author."
4313   (string-lessp
4314    (let ((extract (funcall
4315                    gnus-extract-address-components
4316                    (mail-header-from h1))))
4317      (or (car extract) (cadr extract) ""))
4318    (let ((extract (funcall
4319                    gnus-extract-address-components
4320                    (mail-header-from h2))))
4321      (or (car extract) (cadr extract) ""))))
4322
4323 (defun gnus-thread-sort-by-author (h1 h2)
4324   "Sort threads by root author."
4325   (gnus-article-sort-by-author
4326    (gnus-thread-header h1)  (gnus-thread-header h2)))
4327
4328 (defsubst gnus-article-sort-by-subject (h1 h2)
4329   "Sort articles by root subject."
4330   (string-lessp
4331    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4332    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4333
4334 (defun gnus-thread-sort-by-subject (h1 h2)
4335   "Sort threads by root subject."
4336   (gnus-article-sort-by-subject
4337    (gnus-thread-header h1) (gnus-thread-header h2)))
4338
4339 (defsubst gnus-article-sort-by-date (h1 h2)
4340   "Sort articles by root article date."
4341   (time-less-p
4342    (gnus-date-get-time (mail-header-date h1))
4343    (gnus-date-get-time (mail-header-date h2))))
4344
4345 (defun gnus-thread-sort-by-date (h1 h2)
4346   "Sort threads by root article date."
4347   (gnus-article-sort-by-date
4348    (gnus-thread-header h1) (gnus-thread-header h2)))
4349
4350 (defsubst gnus-article-sort-by-score (h1 h2)
4351   "Sort articles by root article score.
4352 Unscored articles will be counted as having a score of zero."
4353   (> (or (cdr (assq (mail-header-number h1)
4354                     gnus-newsgroup-scored))
4355          gnus-summary-default-score 0)
4356      (or (cdr (assq (mail-header-number h2)
4357                     gnus-newsgroup-scored))
4358          gnus-summary-default-score 0)))
4359
4360 (defun gnus-thread-sort-by-score (h1 h2)
4361   "Sort threads by root article score."
4362   (gnus-article-sort-by-score
4363    (gnus-thread-header h1) (gnus-thread-header h2)))
4364
4365 (defun gnus-thread-sort-by-total-score (h1 h2)
4366   "Sort threads by the sum of all scores in the thread.
4367 Unscored articles will be counted as having a score of zero."
4368   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4369
4370 (defun gnus-thread-total-score (thread)
4371   ;; This function find the total score of THREAD.
4372   (cond
4373    ((null thread)
4374     0)
4375    ((consp thread)
4376     (if (stringp (car thread))
4377         (apply gnus-thread-score-function 0
4378                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4379       (gnus-thread-total-score-1 thread)))
4380    (t
4381     (gnus-thread-total-score-1 (list thread)))))
4382
4383 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4384   "Sort threads such that the thread with the most recently arrived article comes first."
4385   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4386
4387 (defun gnus-thread-highest-number (thread)
4388   "Return the highest article number in THREAD."
4389   (apply 'max (mapcar (lambda (header)
4390                         (mail-header-number header))
4391                       (message-flatten-list thread))))
4392
4393 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4394   "Sort threads such that the thread with the most recently dated article comes first."
4395   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4396
4397 (defun gnus-thread-latest-date (thread)
4398   "Return the highest article date in THREAD."
4399   (let ((previous-time 0))
4400     (apply 'max (mapcar
4401                  (lambda (header)
4402                    (setq previous-time
4403                          (time-to-seconds
4404                           (mail-header-parse-date
4405                            (condition-case ()
4406                                (mail-header-date header)
4407                              (error previous-time))))))
4408                  (sort
4409                   (message-flatten-list thread)
4410                   (lambda (h1 h2)
4411                     (< (mail-header-number h1)
4412                        (mail-header-number h2))))))))
4413
4414 (defun gnus-thread-total-score-1 (root)
4415   ;; This function find the total score of the thread below ROOT.
4416   (setq root (car root))
4417   (apply gnus-thread-score-function
4418          (or (append
4419               (mapcar 'gnus-thread-total-score
4420                       (cdr (gnus-id-to-thread (mail-header-id root))))
4421               (when (> (mail-header-number root) 0)
4422                 (list (or (cdr (assq (mail-header-number root)
4423                                      gnus-newsgroup-scored))
4424                           gnus-summary-default-score 0))))
4425              (list gnus-summary-default-score)
4426              '(0))))
4427
4428 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4429 (defvar gnus-tmp-prev-subject nil)
4430 (defvar gnus-tmp-false-parent nil)
4431 (defvar gnus-tmp-root-expunged nil)
4432 (defvar gnus-tmp-dummy-line nil)
4433
4434 (eval-when-compile (defvar gnus-tmp-header))
4435 (defun gnus-extra-header (type &optional header)
4436   "Return the extra header of TYPE."
4437   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4438       ""))
4439
4440 (defvar gnus-tmp-thread-tree-header-string "")
4441
4442 (defcustom gnus-sum-thread-tree-root "> "
4443   "With %B spec, used for the root of a thread.
4444 If nil, use subject instead."
4445   :type 'string
4446   :group 'gnus-thread)
4447 (defcustom gnus-sum-thread-tree-single-indent ""
4448   "With %B spec, used for a thread with just one message.
4449 If nil, use subject instead."
4450   :type 'string
4451   :group 'gnus-thread)
4452 (defcustom gnus-sum-thread-tree-vertical "| "
4453   "With %B spec, used for drawing a vertical line."
4454   :type 'string
4455   :group 'gnus-thread)
4456 (defcustom gnus-sum-thread-tree-indent "  "
4457   "With %B spec, used for indenting."
4458   :type 'string
4459   :group 'gnus-thread)
4460 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4461   "With %B spec, used for a leaf with brothers."
4462   :type 'string
4463   :group 'gnus-thread)
4464 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4465   "With %B spec, used for a leaf without brothers."
4466   :type 'string
4467   :group 'gnus-thread)
4468
4469 (defun gnus-summary-prepare-threads (threads)
4470   "Prepare summary buffer from THREADS and indentation LEVEL.
4471 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4472 or a straight list of headers."
4473   (gnus-message 7 "Generating summary...")
4474
4475   (setq gnus-newsgroup-threads threads)
4476   (beginning-of-line)
4477
4478   (let ((gnus-tmp-level 0)
4479         (default-score (or gnus-summary-default-score 0))
4480         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4481         thread number subject stack state gnus-tmp-gathered beg-match
4482         new-roots gnus-tmp-new-adopts thread-end simp-subject
4483         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4484         gnus-tmp-replied gnus-tmp-subject-or-nil
4485         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4486         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4487         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4488         tree-stack)
4489
4490     (setq gnus-tmp-prev-subject nil)
4491
4492     (if (vectorp (car threads))
4493         ;; If this is a straight (sic) list of headers, then a
4494         ;; threaded summary display isn't required, so we just create
4495         ;; an unthreaded one.
4496         (gnus-summary-prepare-unthreaded threads)
4497
4498       ;; Do the threaded display.
4499
4500       (while (or threads stack gnus-tmp-new-adopts new-roots)
4501
4502         (if (and (= gnus-tmp-level 0)
4503                  (or (not stack)
4504                      (= (caar stack) 0))
4505                  (not gnus-tmp-false-parent)
4506                  (or gnus-tmp-new-adopts new-roots))
4507             (if gnus-tmp-new-adopts
4508                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4509                       thread (list (car gnus-tmp-new-adopts))
4510                       gnus-tmp-header (caar thread)
4511                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4512               (when new-roots
4513                 (setq thread (list (car new-roots))
4514                       gnus-tmp-header (caar thread)
4515                       new-roots (cdr new-roots))))
4516
4517           (if threads
4518               ;; If there are some threads, we do them before the
4519               ;; threads on the stack.
4520               (setq thread threads
4521                     gnus-tmp-header (caar thread))
4522             ;; There were no current threads, so we pop something off
4523             ;; the stack.
4524             (setq state (car stack)
4525                   gnus-tmp-level (car state)
4526                   tree-stack (cadr state)
4527                   thread (caddr state)
4528                   stack (cdr stack)
4529                   gnus-tmp-header (caar thread))))
4530
4531         (setq gnus-tmp-false-parent nil)
4532         (setq gnus-tmp-root-expunged nil)
4533         (setq thread-end nil)
4534
4535         (if (stringp gnus-tmp-header)
4536             ;; The header is a dummy root.
4537             (cond
4538              ((eq gnus-summary-make-false-root 'adopt)
4539               ;; We let the first article adopt the rest.
4540               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4541                                                (cddar thread)))
4542               (setq gnus-tmp-gathered
4543                     (nconc (mapcar
4544                             (lambda (h) (mail-header-number (car h)))
4545                             (cddar thread))
4546                            gnus-tmp-gathered))
4547               (setq thread (cons (list (caar thread)
4548                                        (cadar thread))
4549                                  (cdr thread)))
4550               (setq gnus-tmp-level -1
4551                     gnus-tmp-false-parent t))
4552              ((eq gnus-summary-make-false-root 'empty)
4553               ;; We print adopted articles with empty subject fields.
4554               (setq gnus-tmp-gathered
4555                     (nconc (mapcar
4556                             (lambda (h) (mail-header-number (car h)))
4557                             (cddar thread))
4558                            gnus-tmp-gathered))
4559               (setq gnus-tmp-level -1))
4560              ((eq gnus-summary-make-false-root 'dummy)
4561               ;; We remember that we probably want to output a dummy
4562               ;; root.
4563               (setq gnus-tmp-dummy-line gnus-tmp-header)
4564               (setq gnus-tmp-prev-subject gnus-tmp-header))
4565              (t
4566               ;; We do not make a root for the gathered
4567               ;; sub-threads at all.
4568               (setq gnus-tmp-level -1)))
4569
4570           (setq number (mail-header-number gnus-tmp-header)
4571                 subject (mail-header-subject gnus-tmp-header)
4572                 simp-subject (gnus-simplify-subject-fully subject))
4573
4574           (cond
4575            ;; If the thread has changed subject, we might want to make
4576            ;; this subthread into a root.
4577            ((and (null gnus-thread-ignore-subject)
4578                  (not (zerop gnus-tmp-level))
4579                  gnus-tmp-prev-subject
4580                  (not (string= gnus-tmp-prev-subject simp-subject)))
4581             (setq new-roots (nconc new-roots (list (car thread)))
4582                   thread-end t
4583                   gnus-tmp-header nil))
4584            ;; If the article lies outside the current limit,
4585            ;; then we do not display it.
4586            ((not (memq number gnus-newsgroup-limit))
4587             (setq gnus-tmp-gathered
4588                   (nconc (mapcar
4589                           (lambda (h) (mail-header-number (car h)))
4590                           (cdar thread))
4591                          gnus-tmp-gathered))
4592             (setq gnus-tmp-new-adopts (if (cdar thread)
4593                                           (append gnus-tmp-new-adopts
4594                                                   (cdar thread))
4595                                         gnus-tmp-new-adopts)
4596                   thread-end t
4597                   gnus-tmp-header nil)
4598             (when (zerop gnus-tmp-level)
4599               (setq gnus-tmp-root-expunged t)))
4600            ;; Perhaps this article is to be marked as read?
4601            ((and gnus-summary-mark-below
4602                  (< (or (cdr (assq number gnus-newsgroup-scored))
4603                         default-score)
4604                     gnus-summary-mark-below)
4605                  ;; Don't touch sparse articles.
4606                  (not (gnus-summary-article-sparse-p number))
4607                  (not (gnus-summary-article-ancient-p number)))
4608             (setq gnus-newsgroup-unreads
4609                   (delq number gnus-newsgroup-unreads))
4610             (if gnus-newsgroup-auto-expire
4611                 (setq gnus-newsgroup-expirable
4612                       (gnus-add-to-sorted-list
4613                        gnus-newsgroup-expirable number))
4614               (push (cons number gnus-low-score-mark)
4615                     gnus-newsgroup-reads))))
4616
4617           (when gnus-tmp-header
4618             ;; We may have an old dummy line to output before this
4619             ;; article.
4620             (when (and gnus-tmp-dummy-line
4621                        (gnus-subject-equal
4622                         gnus-tmp-dummy-line
4623                         (mail-header-subject gnus-tmp-header)))
4624               (gnus-summary-insert-dummy-line
4625                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4626               (setq gnus-tmp-dummy-line nil))
4627
4628             ;; Compute the mark.
4629             (setq gnus-tmp-unread (gnus-article-mark number))
4630
4631             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4632                                   gnus-tmp-header gnus-tmp-level)
4633                   gnus-newsgroup-data)
4634
4635             ;; Actually insert the line.
4636             (setq
4637              gnus-tmp-subject-or-nil
4638              (cond
4639               ((and gnus-thread-ignore-subject
4640                     gnus-tmp-prev-subject
4641                     (not (string= gnus-tmp-prev-subject simp-subject)))
4642                subject)
4643               ((zerop gnus-tmp-level)
4644                (if (and (eq gnus-summary-make-false-root 'empty)
4645                         (memq number gnus-tmp-gathered)
4646                         gnus-tmp-prev-subject
4647                         (string= gnus-tmp-prev-subject simp-subject))
4648                    gnus-summary-same-subject
4649                  subject))
4650               (t gnus-summary-same-subject)))
4651             (if (and (eq gnus-summary-make-false-root 'adopt)
4652                      (= gnus-tmp-level 1)
4653                      (memq number gnus-tmp-gathered))
4654                 (setq gnus-tmp-opening-bracket ?\<
4655                       gnus-tmp-closing-bracket ?\>)
4656               (setq gnus-tmp-opening-bracket ?\[
4657                     gnus-tmp-closing-bracket ?\]))
4658             (setq
4659              gnus-tmp-indentation
4660              (aref gnus-thread-indent-array gnus-tmp-level)
4661              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4662              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4663                                 gnus-summary-default-score 0)
4664              gnus-tmp-score-char
4665              (if (or (null gnus-summary-default-score)
4666                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4667                          gnus-summary-zcore-fuzz))
4668                  ?                      ;Whitespace
4669                (if (< gnus-tmp-score gnus-summary-default-score)
4670                    gnus-score-below-mark gnus-score-over-mark))
4671              gnus-tmp-replied
4672              (cond ((memq number gnus-newsgroup-processable)
4673                     gnus-process-mark)
4674                    ((memq number gnus-newsgroup-cached)
4675                     gnus-cached-mark)
4676                    ((memq number gnus-newsgroup-replied)
4677                     gnus-replied-mark)
4678                    ((memq number gnus-newsgroup-forwarded)
4679                     gnus-forwarded-mark)
4680                    ((memq number gnus-newsgroup-saved)
4681                     gnus-saved-mark)
4682                    ((memq number gnus-newsgroup-recent)
4683                     gnus-recent-mark)
4684                    ((memq number gnus-newsgroup-unseen)
4685                     gnus-unseen-mark)
4686                    (t gnus-no-mark))
4687              gnus-tmp-downloaded
4688              (cond ((memq number gnus-newsgroup-undownloaded) 
4689                     gnus-undownloaded-mark)
4690                    (gnus-newsgroup-agentized
4691                     gnus-downloaded-mark)
4692                    (t
4693                     gnus-no-mark))
4694              gnus-tmp-from (mail-header-from gnus-tmp-header)
4695              gnus-tmp-name
4696              (cond
4697               ((string-match "<[^>]+> *$" gnus-tmp-from)
4698                (setq beg-match (match-beginning 0))
4699                (or (and (string-match "^\".+\"" gnus-tmp-from)
4700                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4701                    (substring gnus-tmp-from 0 beg-match)))
4702               ((string-match "(.+)" gnus-tmp-from)
4703                (substring gnus-tmp-from
4704                           (1+ (match-beginning 0)) (1- (match-end 0))))
4705               (t gnus-tmp-from))
4706              gnus-tmp-thread-tree-header-string
4707              (cond
4708               ((not gnus-show-threads) "")
4709               ((zerop gnus-tmp-level)
4710                (if (cdar thread)
4711                    (or gnus-sum-thread-tree-root subject)
4712                  (or gnus-sum-thread-tree-single-indent subject)))
4713               (t
4714                (concat (apply 'concat
4715                               (mapcar (lambda (item)
4716                                         (if (= item 1)
4717                                             gnus-sum-thread-tree-vertical
4718                                           gnus-sum-thread-tree-indent))
4719                                       (cdr (reverse tree-stack))))
4720                        (if (nth 1 thread)
4721                            gnus-sum-thread-tree-leaf-with-other
4722                          gnus-sum-thread-tree-single-leaf)))))
4723             (when (string= gnus-tmp-name "")
4724               (setq gnus-tmp-name gnus-tmp-from))
4725             (unless (numberp gnus-tmp-lines)
4726               (setq gnus-tmp-lines -1))
4727             (if (= gnus-tmp-lines -1)
4728                 (setq gnus-tmp-lines "?")
4729               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4730             (gnus-put-text-property
4731              (point)
4732              (progn (eval gnus-summary-line-format-spec) (point))
4733              'gnus-number number)
4734             (when gnus-visual-p
4735               (forward-line -1)
4736               (gnus-run-hooks 'gnus-summary-update-hook)
4737               (forward-line 1))
4738
4739             (setq gnus-tmp-prev-subject simp-subject)))
4740
4741         (when (nth 1 thread)
4742           (push (list (max 0 gnus-tmp-level)
4743                       (copy-list tree-stack)
4744                       (nthcdr 1 thread))
4745                 stack))
4746         (push (if (nth 1 thread) 1 0) tree-stack)
4747         (incf gnus-tmp-level)
4748         (setq threads (if thread-end nil (cdar thread)))
4749         (unless threads
4750           (setq gnus-tmp-level 0)))))
4751   (gnus-message 7 "Generating summary...done"))
4752
4753 (defun gnus-summary-prepare-unthreaded (headers)
4754   "Generate an unthreaded summary buffer based on HEADERS."
4755   (let (header number mark)
4756
4757     (beginning-of-line)
4758
4759     (while headers
4760       ;; We may have to root out some bad articles...
4761       (when (memq (setq number (mail-header-number
4762                                 (setq header (pop headers))))
4763                   gnus-newsgroup-limit)
4764         ;; Mark article as read when it has a low score.
4765         (when (and gnus-summary-mark-below
4766                    (< (or (cdr (assq number gnus-newsgroup-scored))
4767                           gnus-summary-default-score 0)
4768                       gnus-summary-mark-below)
4769                    (not (gnus-summary-article-ancient-p number)))
4770           (setq gnus-newsgroup-unreads
4771                 (delq number gnus-newsgroup-unreads))
4772           (if gnus-newsgroup-auto-expire
4773               (push number gnus-newsgroup-expirable)
4774             (push (cons number gnus-low-score-mark)
4775                   gnus-newsgroup-reads)))
4776
4777         (setq mark (gnus-article-mark number))
4778         (push (gnus-data-make number mark (1+ (point)) header 0)
4779               gnus-newsgroup-data)
4780         (gnus-summary-insert-line
4781          header 0 number
4782          (memq article gnus-newsgroup-undownloaded)
4783          mark (memq number gnus-newsgroup-replied)
4784          (memq number gnus-newsgroup-expirable)
4785          (mail-header-subject header) nil
4786          (cdr (assq number gnus-newsgroup-scored))
4787          (memq number gnus-newsgroup-processable))))))
4788
4789 (defun gnus-summary-remove-list-identifiers ()
4790   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4791   (let ((regexp (if (consp gnus-list-identifiers)
4792                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4793                   gnus-list-identifiers))
4794         changed subject)
4795     (when regexp
4796       (dolist (header gnus-newsgroup-headers)
4797         (setq subject (mail-header-subject header)
4798               changed nil)
4799         (while (string-match
4800                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4801                 subject)
4802           (setq subject
4803                 (concat (substring subject 0 (match-beginning 2))
4804                         (substring subject (match-end 0)))
4805                 changed t))
4806         (when (and changed
4807                    (string-match
4808                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4809           (setq subject
4810                 (concat (substring subject 0 (match-beginning 1))
4811                         (substring subject (match-end 1)))))
4812         (when changed
4813           (mail-header-set-subject header subject))))))
4814
4815 (defun gnus-fetch-headers (articles)
4816   "Fetch headers of ARTICLES."
4817   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4818     (gnus-message 5 "Fetching headers for %s..." name)
4819     (prog1
4820         (if (eq 'nov
4821                 (setq gnus-headers-retrieved-by
4822                       (gnus-retrieve-headers
4823                        articles gnus-newsgroup-name
4824                        ;; We might want to fetch old headers, but
4825                        ;; not if there is only 1 article.
4826                        (and (or (and
4827                                  (not (eq gnus-fetch-old-headers 'some))
4828                                  (not (numberp gnus-fetch-old-headers)))
4829                                 (> (length articles) 1))
4830                             gnus-fetch-old-headers))))
4831             (gnus-get-newsgroup-headers-xover
4832              articles nil nil gnus-newsgroup-name t)
4833           (gnus-get-newsgroup-headers))
4834       (gnus-message 5 "Fetching headers for %s...done" name))))
4835
4836 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4837   "Select newsgroup GROUP.
4838 If READ-ALL is non-nil, all articles in the group are selected.
4839 If SELECT-ARTICLES, only select those articles from GROUP."
4840   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4841          ;;!!! Dirty hack; should be removed.
4842          (gnus-summary-ignore-duplicates
4843           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4844               t
4845             gnus-summary-ignore-duplicates))
4846          (info (nth 2 entry))
4847          articles fetched-articles cached)
4848
4849     (unless (gnus-check-server
4850              (set (make-local-variable 'gnus-current-select-method)
4851                   (gnus-find-method-for-group group)))
4852       (error "Couldn't open server"))
4853
4854     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4855         (gnus-activate-group group)     ; Or we can activate it...
4856         (progn                          ; Or we bug out.
4857           (when (equal major-mode 'gnus-summary-mode)
4858             (kill-buffer (current-buffer)))
4859           (error "Couldn't activate group %s: %s"
4860                  group (gnus-status-message group))))
4861
4862     (unless (gnus-request-group group t)
4863       (when (equal major-mode 'gnus-summary-mode)
4864         (kill-buffer (current-buffer)))
4865       (error "Couldn't request group %s: %s"
4866              group (gnus-status-message group)))
4867
4868     (setq gnus-newsgroup-name group
4869           gnus-newsgroup-unselected nil
4870           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4871
4872     (let ((display (gnus-group-find-parameter group 'display)))
4873       (setq gnus-newsgroup-display
4874             (cond
4875              ((not (zerop (or (car-safe read-all) 0)))
4876               ;; The user entered the group with C-u SPC/RET, let's show
4877               ;; all articles.
4878               'gnus-not-ignore)
4879              ((eq display 'all)
4880               'gnus-not-ignore)
4881              ((arrayp display)
4882               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4883              ((numberp display)
4884               ;; The following is probably the "correct" solution, but
4885               ;; it makes Gnus fetch all headers and then limit the
4886               ;; articles (which is slow), so instead we hack the
4887               ;; select-articles parameter instead. -- Simon Josefsson
4888               ;; <jas@kth.se>
4889               ;;
4890               ;; (gnus-byte-compile
4891               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4892               ;;                         display)))))
4893               (setq select-articles
4894                     (gnus-uncompress-range
4895                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4896                              (if (> tmp 0)
4897                                  tmp
4898                                1))
4899                            (cdr (gnus-active group)))))
4900               nil)
4901              (t
4902               nil))))
4903
4904     (gnus-summary-setup-default-charset)
4905
4906     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4907     (when (gnus-virtual-group-p group)
4908       (setq cached gnus-newsgroup-cached))
4909
4910     (setq gnus-newsgroup-unreads
4911           (gnus-sorted-ndifference
4912            (gnus-sorted-ndifference gnus-newsgroup-unreads
4913                                     gnus-newsgroup-marked)
4914            gnus-newsgroup-dormant))
4915
4916     (setq gnus-newsgroup-processable nil)
4917
4918     (gnus-update-read-articles group gnus-newsgroup-unreads)
4919
4920     ;; Adjust and set lists of article marks.
4921     (when info
4922       (gnus-adjust-marked-articles info))
4923     (if (setq articles select-articles)
4924         (setq gnus-newsgroup-unselected
4925               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4926       (setq articles (gnus-articles-to-read group read-all)))
4927
4928     (cond
4929      ((null articles)
4930       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4931       'quit)
4932      ((eq articles 0) nil)
4933      (t
4934       ;; Init the dependencies hash table.
4935       (setq gnus-newsgroup-dependencies
4936             (gnus-make-hashtable (length articles)))
4937       (gnus-set-global-variables)
4938       ;; Retrieve the headers and read them in.
4939
4940       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4941
4942       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4943       (when cached
4944         (setq gnus-newsgroup-cached cached))
4945
4946       ;; Suppress duplicates?
4947       (when gnus-suppress-duplicates
4948         (gnus-dup-suppress-articles))
4949
4950       ;; Set the initial limit.
4951       (setq gnus-newsgroup-limit (copy-sequence articles))
4952       ;; Remove canceled articles from the list of unread articles.
4953       (setq fetched-articles
4954             (mapcar (lambda (headers) (mail-header-number headers))
4955                     gnus-newsgroup-headers))
4956       (setq gnus-newsgroup-articles fetched-articles)
4957       (setq gnus-newsgroup-unreads
4958             (gnus-sorted-nintersection
4959              gnus-newsgroup-unreads fetched-articles))
4960       (gnus-compute-unseen-list)
4961
4962       ;; Removed marked articles that do not exist.
4963       (gnus-update-missing-marks
4964        (gnus-sorted-difference articles fetched-articles))
4965       ;; We might want to build some more threads first.
4966       (when (and gnus-fetch-old-headers
4967                  (eq gnus-headers-retrieved-by 'nov))
4968         (if (eq gnus-fetch-old-headers 'invisible)
4969             (gnus-build-all-threads)
4970           (gnus-build-old-threads)))
4971       ;; Let the Gnus agent mark articles as read.
4972       (when gnus-agent
4973         (gnus-agent-get-undownloaded-list))
4974       ;; Remove list identifiers from subject
4975       (when gnus-list-identifiers
4976         (gnus-summary-remove-list-identifiers))
4977       ;; Check whether auto-expire is to be done in this group.
4978       (setq gnus-newsgroup-auto-expire
4979             (gnus-group-auto-expirable-p group))
4980       ;; Set up the article buffer now, if necessary.
4981       (unless gnus-single-article-buffer
4982         (gnus-article-setup-buffer))
4983       ;; First and last article in this newsgroup.
4984       (when gnus-newsgroup-headers
4985         (setq gnus-newsgroup-begin
4986               (mail-header-number (car gnus-newsgroup-headers))
4987               gnus-newsgroup-end
4988               (mail-header-number
4989                (gnus-last-element gnus-newsgroup-headers))))
4990       ;; GROUP is successfully selected.
4991       (or gnus-newsgroup-headers t)))))
4992
4993 (defun gnus-compute-unseen-list ()
4994   ;; The `seen' marks are treated specially.
4995   (if (not gnus-newsgroup-seen)
4996       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4997     (setq gnus-newsgroup-unseen
4998           (gnus-inverse-list-range-intersection
4999            gnus-newsgroup-articles gnus-newsgroup-seen))))
5000
5001 (defun gnus-summary-display-make-predicate (display)
5002   (require 'gnus-agent)
5003   (when (= (length display) 1)
5004     (setq display (car display)))
5005   (unless gnus-summary-display-cache
5006     (dolist (elem (append '((unread . unread)
5007                             (read . read)
5008                             (unseen . unseen))
5009                           gnus-article-mark-lists))
5010       (push (cons (cdr elem)
5011                   (gnus-byte-compile
5012                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5013             gnus-summary-display-cache)))
5014   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5015         (gnus-category-predicate-cache gnus-summary-display-cache))
5016     (gnus-get-predicate display)))
5017
5018 ;; Uses the dynamically bound `number' variable.
5019 (eval-when-compile
5020   (defvar number))
5021 (defun gnus-article-marked-p (type &optional article)
5022   (let ((article (or article number)))
5023     (cond
5024      ((eq type 'tick)
5025       (memq article gnus-newsgroup-marked))
5026      ((eq type 'spam)
5027       (memq article gnus-newsgroup-spam-marked))
5028      ((eq type 'unsend)
5029       (memq article gnus-newsgroup-unsendable))
5030      ((eq type 'undownload)
5031       (memq article gnus-newsgroup-undownloaded))
5032      ((eq type 'download)
5033       (memq article gnus-newsgroup-downloadable))
5034      ((eq type 'unread)
5035       (memq article gnus-newsgroup-unreads))
5036      ((eq type 'read)
5037       (memq article gnus-newsgroup-reads))
5038      ((eq type 'dormant)
5039       (memq article gnus-newsgroup-dormant) )
5040      ((eq type 'expire)
5041       (memq article gnus-newsgroup-expirable))
5042      ((eq type 'reply)
5043       (memq article gnus-newsgroup-replied))
5044      ((eq type 'killed)
5045       (memq article gnus-newsgroup-killed))
5046      ((eq type 'bookmark)
5047       (assq article gnus-newsgroup-bookmarks))
5048      ((eq type 'score)
5049       (assq article gnus-newsgroup-scored))
5050      ((eq type 'save)
5051       (memq article gnus-newsgroup-saved))
5052      ((eq type 'cache)
5053       (memq article gnus-newsgroup-cached))
5054      ((eq type 'forward)
5055       (memq article gnus-newsgroup-forwarded))
5056      ((eq type 'seen)
5057       (not (memq article gnus-newsgroup-unseen)))
5058      ((eq type 'recent)
5059       (memq article gnus-newsgroup-recent))
5060      (t t))))
5061
5062 (defun gnus-articles-to-read (group &optional read-all)
5063   "Find out what articles the user wants to read."
5064   (let* ((articles
5065           ;; Select all articles if `read-all' is non-nil, or if there
5066           ;; are no unread articles.
5067           (if (or read-all
5068                   (and (zerop (length gnus-newsgroup-marked))
5069                        (zerop (length gnus-newsgroup-unreads)))
5070                   ;; Fetch all if the predicate is non-nil.
5071                   gnus-newsgroup-display)
5072               ;; We want to select the headers for all the articles in
5073               ;; the group, so we select either all the active
5074               ;; articles in the group, or (if that's nil), the
5075               ;; articles in the cache.
5076               (or
5077                (gnus-uncompress-range (gnus-active group))
5078                (gnus-cache-articles-in-group group))
5079             ;; Select only the "normal" subset of articles.
5080             (gnus-sorted-nunion
5081              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5082              gnus-newsgroup-unreads)))
5083          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5084          (scored (length scored-list))
5085          (number (length articles))
5086          (marked (+ (length gnus-newsgroup-marked)
5087                     (length gnus-newsgroup-dormant)))
5088          (select
5089           (cond
5090            ((numberp read-all)
5091             read-all)
5092            ((numberp gnus-newsgroup-display)
5093             gnus-newsgroup-display)
5094            (t
5095             (condition-case ()
5096                 (cond
5097                  ((and (or (<= scored marked) (= scored number))
5098                        (numberp gnus-large-newsgroup)
5099                        (> number gnus-large-newsgroup))
5100                   (let* ((cursor-in-echo-area nil)
5101                          (initial (gnus-parameter-large-newsgroup-initial
5102                                    gnus-newsgroup-name))
5103                          (input
5104                           (read-string
5105                            (format
5106                             "How many articles from %s (%s %d): "
5107                             (gnus-limit-string
5108                              (gnus-group-decoded-name gnus-newsgroup-name)
5109                              35)
5110                             (if initial "max" "default")
5111                             number)
5112                            (if initial
5113                                (cons (number-to-string initial)
5114                                      0)))))
5115                     (if (string-match "^[ \t]*$" input) number input)))
5116                  ((and (> scored marked) (< scored number)
5117                        (> (- scored number) 20))
5118                   (let ((input
5119                          (read-string
5120                           (format "%s %s (%d scored, %d total): "
5121                                   "How many articles from"
5122                                   (gnus-group-decoded-name group)
5123                                   scored number))))
5124                     (if (string-match "^[ \t]*$" input)
5125                         number input)))
5126                  (t number))
5127               (quit
5128                (message "Quit getting the articles to read")
5129                nil))))))
5130     (setq select (if (stringp select) (string-to-number select) select))
5131     (if (or (null select) (zerop select))
5132         select
5133       (if (and (not (zerop scored)) (<= (abs select) scored))
5134           (progn
5135             (setq articles (sort scored-list '<))
5136             (setq number (length articles)))
5137         (setq articles (copy-sequence articles)))
5138
5139       (when (< (abs select) number)
5140         (if (< select 0)
5141             ;; Select the N oldest articles.
5142             (setcdr (nthcdr (1- (abs select)) articles) nil)
5143           ;; Select the N most recent articles.
5144           (setq articles (nthcdr (- number select) articles))))
5145       (setq gnus-newsgroup-unselected
5146             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5147       (when gnus-alter-articles-to-read-function
5148         (setq gnus-newsgroup-unreads
5149               (sort
5150                (funcall gnus-alter-articles-to-read-function
5151                         gnus-newsgroup-name gnus-newsgroup-unreads)
5152                '<)))
5153       articles)))
5154
5155 (defun gnus-killed-articles (killed articles)
5156   (let (out)
5157     (while articles
5158       (when (inline (gnus-member-of-range (car articles) killed))
5159         (push (car articles) out))
5160       (setq articles (cdr articles)))
5161     out))
5162
5163 (defun gnus-uncompress-marks (marks)
5164   "Uncompress the mark ranges in MARKS."
5165   (let ((uncompressed '(score bookmark))
5166         out)
5167     (while marks
5168       (if (memq (caar marks) uncompressed)
5169           (push (car marks) out)
5170         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5171       (setq marks (cdr marks)))
5172     out))
5173
5174 (defun gnus-article-mark-to-type (mark)
5175   "Return the type of MARK."
5176   (or (cadr (assq mark gnus-article-special-mark-lists))
5177       'list))
5178
5179 (defun gnus-article-unpropagatable-p (mark)
5180   "Return whether MARK should be propagated to backend."
5181   (memq mark gnus-article-unpropagated-mark-lists))
5182
5183 (defun gnus-adjust-marked-articles (info)
5184   "Set all article lists and remove all marks that are no longer valid."
5185   (let* ((marked-lists (gnus-info-marks info))
5186          (active (gnus-active (gnus-info-group info)))
5187          (min (car active))
5188          (max (cdr active))
5189          (types gnus-article-mark-lists)
5190          marks var articles article mark mark-type)
5191
5192     (dolist (marks marked-lists)
5193       (setq mark (car marks)
5194             mark-type (gnus-article-mark-to-type mark)
5195             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5196
5197       ;; We set the variable according to the type of the marks list,
5198       ;; and then adjust the marks to a subset of the active articles.
5199       (cond
5200        ;; Adjust "simple" lists.
5201        ((eq mark-type 'list)
5202         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5203         (when (memq mark '(tick dormant expire reply save))
5204           (while articles
5205             (when (or (< (setq article (pop articles)) min) (> article max))
5206               (set var (delq article (symbol-value var)))))))
5207        ;; Adjust assocs.
5208        ((eq mark-type 'tuple)
5209         (set var (setq articles (cdr marks)))
5210         (when (not (listp (cdr (symbol-value var))))
5211           (set var (list (symbol-value var))))
5212         (when (not (listp (cdr articles)))
5213           (setq articles (list articles)))
5214         (while articles
5215           (when (or (not (consp (setq article (pop articles))))
5216                     (< (car article) min)
5217                     (> (car article) max))
5218             (set var (delq article (symbol-value var))))))
5219        ;; Adjust ranges (sloppily).
5220        ((eq mark-type 'range)
5221         (cond
5222          ((eq mark 'seen)
5223           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5224           ;; It should be (seen (NUM1 . NUM2)).
5225           (when (numberp (cddr marks))
5226             (setcdr marks (list (cdr marks))))
5227           (setq articles (cdr marks))
5228           (while (and articles
5229                       (or (and (consp (car articles))
5230                                (> min (cdar articles)))
5231                           (and (numberp (car articles))
5232                                (> min (car articles)))))
5233             (pop articles))
5234           (set var articles))))))))
5235
5236 (defun gnus-update-missing-marks (missing)
5237   "Go through the list of MISSING articles and remove them from the mark lists."
5238   (when missing
5239     (let (var m)
5240       ;; Go through all types.
5241       (dolist (elem gnus-article-mark-lists)
5242         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5243           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5244           (when (symbol-value var)
5245             ;; This list has articles.  So we delete all missing
5246             ;; articles from it.
5247             (setq m missing)
5248             (while m
5249               (set var (delq (pop m) (symbol-value var))))))))))
5250
5251 (defun gnus-update-marks ()
5252   "Enter the various lists of marked articles into the newsgroup info list."
5253   (let ((types gnus-article-mark-lists)
5254         (info (gnus-get-info gnus-newsgroup-name))
5255         type list newmarked symbol delta-marks)
5256     (when info
5257       ;; Add all marks lists to the list of marks lists.
5258       (while (setq type (pop types))
5259         (setq list (symbol-value
5260                     (setq symbol
5261                           (intern (format "gnus-newsgroup-%s" (car type))))))
5262
5263         (when list
5264           ;; Get rid of the entries of the articles that have the
5265           ;; default score.
5266           (when (and (eq (cdr type) 'score)
5267                      gnus-save-score
5268                      list)
5269             (let* ((arts list)
5270                    (prev (cons nil list))
5271                    (all prev))
5272               (while arts
5273                 (if (or (not (consp (car arts)))
5274                         (= (cdar arts) gnus-summary-default-score))
5275                     (setcdr prev (cdr arts))
5276                   (setq prev arts))
5277                 (setq arts (cdr arts)))
5278               (setq list (cdr all)))))
5279
5280         (when (eq (cdr type) 'seen)
5281           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5282
5283         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5284           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5285
5286         (when (and (gnus-check-backend-function
5287                     'request-set-mark gnus-newsgroup-name)
5288                    (not (gnus-article-unpropagatable-p (cdr type))))
5289           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5290                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5291                  (add (gnus-remove-from-range
5292                        (gnus-copy-sequence list) old)))
5293             (when add
5294               (push (list add 'add (list (cdr type))) delta-marks))
5295             (when del
5296               (push (list del 'del (list (cdr type))) delta-marks))))
5297
5298         (when list
5299           (push (cons (cdr type) list) newmarked)))
5300
5301       (when delta-marks
5302         (unless (gnus-check-group gnus-newsgroup-name)
5303           (error "Can't open server for %s" gnus-newsgroup-name))
5304         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5305
5306       ;; Enter these new marks into the info of the group.
5307       (if (nthcdr 3 info)
5308           (setcar (nthcdr 3 info) newmarked)
5309         ;; Add the marks lists to the end of the info.
5310         (when newmarked
5311           (setcdr (nthcdr 2 info) (list newmarked))))
5312
5313       ;; Cut off the end of the info if there's nothing else there.
5314       (let ((i 5))
5315         (while (and (> i 2)
5316                     (not (nth i info)))
5317           (when (nthcdr (decf i) info)
5318             (setcdr (nthcdr i info) nil)))))))
5319
5320 (defun gnus-set-mode-line (where)
5321   "Set the mode line of the article or summary buffers.
5322 If WHERE is `summary', the summary mode line format will be used."
5323   ;; Is this mode line one we keep updated?
5324   (when (and (memq where gnus-updated-mode-lines)
5325              (symbol-value
5326               (intern (format "gnus-%s-mode-line-format-spec" where))))
5327     (let (mode-string)
5328       (save-excursion
5329         ;; We evaluate this in the summary buffer since these
5330         ;; variables are buffer-local to that buffer.
5331         (set-buffer gnus-summary-buffer)
5332        ;; We bind all these variables that are used in the `eval' form
5333         ;; below.
5334         (let* ((mformat (symbol-value
5335                          (intern
5336                           (format "gnus-%s-mode-line-format-spec" where))))
5337                (gnus-tmp-group-name (gnus-group-decoded-name
5338                                      gnus-newsgroup-name))
5339                (gnus-tmp-article-number (or gnus-current-article 0))
5340                (gnus-tmp-unread gnus-newsgroup-unreads)
5341                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5342                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5343                (gnus-tmp-unread-and-unselected
5344                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5345                             (zerop gnus-tmp-unselected))
5346                        "")
5347                       ((zerop gnus-tmp-unselected)
5348                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5349                       (t (format "{%d(+%d) more}"
5350                                  gnus-tmp-unread-and-unticked
5351                                  gnus-tmp-unselected))))
5352                (gnus-tmp-subject
5353                 (if (and gnus-current-headers
5354                          (vectorp gnus-current-headers))
5355                     (gnus-mode-string-quote
5356                      (mail-header-subject gnus-current-headers))
5357                   ""))
5358                bufname-length max-len
5359                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5360           (setq mode-string (eval mformat))
5361           (setq bufname-length (if (string-match "%b" mode-string)
5362                                    (- (length
5363                                        (buffer-name
5364                                         (if (eq where 'summary)
5365                                             nil
5366                                           (get-buffer gnus-article-buffer))))
5367                                       2)
5368                                  0))
5369           (setq max-len (max 4 (if gnus-mode-non-string-length
5370                                    (- (window-width)
5371                                       gnus-mode-non-string-length
5372                                       bufname-length)
5373                                  (length mode-string))))
5374           ;; We might have to chop a bit of the string off...
5375           (when (> (length mode-string) max-len)
5376             (setq mode-string
5377                   (concat (truncate-string-to-width mode-string (- max-len 3))
5378                           "...")))
5379           ;; Pad the mode string a bit.
5380           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5381       ;; Update the mode line.
5382       (setq mode-line-buffer-identification
5383             (gnus-mode-line-buffer-identification (list mode-string)))
5384       (set-buffer-modified-p t))))
5385
5386 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5387   "Go through the HEADERS list and add all Xrefs to a hash table.
5388 The resulting hash table is returned, or nil if no Xrefs were found."
5389   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5390          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5391          (xref-hashtb (gnus-make-hashtable))
5392          start group entry number xrefs header)
5393     (while headers
5394       (setq header (pop headers))
5395       (when (and (setq xrefs (mail-header-xref header))
5396                  (not (memq (setq number (mail-header-number header))
5397                             unreads)))
5398         (setq start 0)
5399         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5400           (setq start (match-end 0))
5401           (setq group (if prefix
5402                           (concat prefix (substring xrefs (match-beginning 1)
5403                                                     (match-end 1)))
5404                         (substring xrefs (match-beginning 1) (match-end 1))))
5405           (setq number
5406                 (string-to-int (substring xrefs (match-beginning 2)
5407                                           (match-end 2))))
5408           (if (setq entry (gnus-gethash group xref-hashtb))
5409               (setcdr entry (cons number (cdr entry)))
5410             (gnus-sethash group (cons number nil) xref-hashtb)))))
5411     (and start xref-hashtb)))
5412
5413 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5414   "Look through all the headers and mark the Xrefs as read."
5415   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5416         name entry info xref-hashtb idlist method nth4)
5417     (save-excursion
5418       (set-buffer gnus-group-buffer)
5419       (when (setq xref-hashtb
5420                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5421         (mapatoms
5422          (lambda (group)
5423            (unless (string= from-newsgroup (setq name (symbol-name group)))
5424              (setq idlist (symbol-value group))
5425              ;; Dead groups are not updated.
5426              (and (prog1
5427                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5428                             info (nth 2 entry))
5429                     (when (stringp (setq nth4 (gnus-info-method info)))
5430                       (setq nth4 (gnus-server-to-method nth4))))
5431                   ;; Only do the xrefs if the group has the same
5432                   ;; select method as the group we have just read.
5433                   (or (gnus-methods-equal-p
5434                        nth4 (gnus-find-method-for-group from-newsgroup))
5435                       virtual
5436                       (equal nth4 (setq method (gnus-find-method-for-group
5437                                                 from-newsgroup)))
5438                       (and (equal (car nth4) (car method))
5439                            (equal (nth 1 nth4) (nth 1 method))))
5440                   gnus-use-cross-reference
5441                   (or (not (eq gnus-use-cross-reference t))
5442                       virtual
5443                       ;; Only do cross-references on subscribed
5444                       ;; groups, if that is what is wanted.
5445                       (<= (gnus-info-level info) gnus-level-subscribed))
5446                   (gnus-group-make-articles-read name idlist))))
5447          xref-hashtb)))))
5448
5449 (defun gnus-compute-read-articles (group articles)
5450   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5451          (info (nth 2 entry))
5452          (active (gnus-active group))
5453          ninfo)
5454     (when entry
5455       ;; First peel off all invalid article numbers.
5456       (when active
5457         (let ((ids articles)
5458               id first)
5459           (while (setq id (pop ids))
5460             (when (and first (> id (cdr active)))
5461               ;; We'll end up in this situation in one particular
5462               ;; obscure situation.  If you re-scan a group and get
5463               ;; a new article that is cross-posted to a different
5464               ;; group that has not been re-scanned, you might get
5465               ;; crossposted article that has a higher number than
5466               ;; Gnus believes possible.  So we re-activate this
5467               ;; group as well.  This might mean doing the
5468               ;; crossposting thingy will *increase* the number
5469               ;; of articles in some groups.  Tsk, tsk.
5470               (setq active (or (gnus-activate-group group) active)))
5471             (when (or (> id (cdr active))
5472                       (< id (car active)))
5473               (setq articles (delq id articles))))))
5474       ;; If the read list is nil, we init it.
5475       (if (and active
5476                (null (gnus-info-read info))
5477                (> (car active) 1))
5478           (setq ninfo (cons 1 (1- (car active))))
5479         (setq ninfo (gnus-info-read info)))
5480       ;; Then we add the read articles to the range.
5481       (gnus-add-to-range
5482        ninfo (setq articles (sort articles '<))))))
5483
5484 (defun gnus-group-make-articles-read (group articles)
5485   "Update the info of GROUP to say that ARTICLES are read."
5486   (let* ((num 0)
5487          (entry (gnus-gethash group gnus-newsrc-hashtb))
5488          (info (nth 2 entry))
5489          (active (gnus-active group))
5490          range)
5491     (when entry
5492       (setq range (gnus-compute-read-articles group articles))
5493       (save-excursion
5494         (set-buffer gnus-group-buffer)
5495         (gnus-undo-register
5496           `(progn
5497              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5498              (gnus-info-set-read ',info ',(gnus-info-read info))
5499              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5500              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5501              (gnus-group-update-group ,group t))))
5502       ;; Add the read articles to the range.
5503       (gnus-info-set-read info range)
5504       (gnus-request-set-mark group (list (list range 'add '(read))))
5505       ;; Then we have to re-compute how many unread
5506       ;; articles there are in this group.
5507       (when active
5508         (cond
5509          ((not range)
5510           (setq num (- (1+ (cdr active)) (car active))))
5511          ((not (listp (cdr range)))
5512           (setq num (- (cdr active) (- (1+ (cdr range))
5513                                        (car range)))))
5514          (t
5515           (while range
5516             (if (numberp (car range))
5517                 (setq num (1+ num))
5518               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5519             (setq range (cdr range)))
5520           (setq num (- (cdr active) num))))
5521         ;; Update the number of unread articles.
5522         (setcar entry num)
5523         ;; Update the group buffer.
5524         (gnus-group-update-group group t)))))
5525
5526 (defvar gnus-newsgroup-none-id 0)
5527
5528 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5529   (let ((cur nntp-server-buffer)
5530         (dependencies
5531          (or dependencies
5532              (save-excursion (set-buffer gnus-summary-buffer)
5533                              gnus-newsgroup-dependencies)))
5534         headers id end ref
5535         (mail-parse-charset gnus-newsgroup-charset)
5536         (mail-parse-ignored-charsets
5537          (save-excursion (condition-case nil
5538                              (set-buffer gnus-summary-buffer)
5539                            (error))
5540                          gnus-newsgroup-ignored-charsets)))
5541     (save-excursion
5542       (set-buffer nntp-server-buffer)
5543       ;; Translate all TAB characters into SPACE characters.
5544       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5545       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5546       (gnus-run-hooks 'gnus-parse-headers-hook)
5547       (let ((case-fold-search t)
5548             in-reply-to header p lines chars)
5549         (goto-char (point-min))
5550         ;; Search to the beginning of the next header.  Error messages
5551         ;; do not begin with 2 or 3.
5552         (while (re-search-forward "^[23][0-9]+ " nil t)
5553           (setq id nil
5554                 ref nil)
5555           ;; This implementation of this function, with nine
5556           ;; search-forwards instead of the one re-search-forward and
5557           ;; a case (which basically was the old function) is actually
5558           ;; about twice as fast, even though it looks messier.  You
5559           ;; can't have everything, I guess.  Speed and elegance
5560           ;; doesn't always go hand in hand.
5561           (setq
5562            header
5563            (vector
5564             ;; Number.
5565             (prog1
5566                 (read cur)
5567               (end-of-line)
5568               (setq p (point))
5569               (narrow-to-region (point)
5570                                 (or (and (search-forward "\n.\n" nil t)
5571                                          (- (point) 2))
5572                                     (point))))
5573             ;; Subject.
5574             (progn
5575               (goto-char p)
5576               (if (search-forward "\nsubject:" nil t)
5577                   (funcall gnus-decode-encoded-word-function
5578                            (nnheader-header-value))
5579                 "(none)"))
5580             ;; From.
5581             (progn
5582               (goto-char p)
5583               (if (search-forward "\nfrom:" nil t)
5584                   (funcall gnus-decode-encoded-word-function
5585                            (nnheader-header-value))
5586                 "(nobody)"))
5587             ;; Date.
5588             (progn
5589               (goto-char p)
5590               (if (search-forward "\ndate:" nil t)
5591                   (nnheader-header-value) ""))
5592             ;; Message-ID.
5593             (progn
5594               (goto-char p)
5595               (setq id (if (re-search-forward
5596                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5597                            ;; We do it this way to make sure the Message-ID
5598                            ;; is (somewhat) syntactically valid.
5599                            (buffer-substring (match-beginning 1)
5600                                              (match-end 1))
5601                          ;; If there was no message-id, we just fake one
5602                          ;; to make subsequent routines simpler.
5603                          (nnheader-generate-fake-message-id))))
5604             ;; References.
5605             (progn
5606               (goto-char p)
5607               (if (search-forward "\nreferences:" nil t)
5608                   (progn
5609                     (setq end (point))
5610                     (prog1
5611                         (nnheader-header-value)
5612                       (setq ref
5613                             (buffer-substring
5614                              (progn
5615                                (end-of-line)
5616                                (search-backward ">" end t)
5617                                (1+ (point)))
5618                              (progn
5619                                (search-backward "<" end t)
5620                                (point))))))
5621                 ;; Get the references from the in-reply-to header if there
5622                 ;; were no references and the in-reply-to header looks
5623                 ;; promising.
5624                 (if (and (search-forward "\nin-reply-to:" nil t)
5625                          (setq in-reply-to (nnheader-header-value))
5626                          (string-match "<[^>]+>" in-reply-to))
5627                     (let (ref2)
5628                       (setq ref (substring in-reply-to (match-beginning 0)
5629                                            (match-end 0)))
5630                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5631                         (setq ref2 (substring in-reply-to (match-beginning 0)
5632                                               (match-end 0)))
5633                         (when (> (length ref2) (length ref))
5634                           (setq ref ref2)))
5635                       ref)
5636                   (setq ref nil))))
5637             ;; Chars.
5638             (progn
5639               (goto-char p)
5640               (if (search-forward "\nchars: " nil t)
5641                   (if (numberp (setq chars (ignore-errors (read cur))))
5642                       chars -1)
5643                 -1))
5644             ;; Lines.
5645             (progn
5646               (goto-char p)
5647               (if (search-forward "\nlines: " nil t)
5648                   (if (numberp (setq lines (ignore-errors (read cur))))
5649                       lines -1)
5650                 -1))
5651             ;; Xref.
5652             (progn
5653               (goto-char p)
5654               (and (search-forward "\nxref:" nil t)
5655                    (nnheader-header-value)))
5656             ;; Extra.
5657             (when gnus-extra-headers
5658               (let ((extra gnus-extra-headers)
5659                     out)
5660                 (while extra
5661                   (goto-char p)
5662                   (when (search-forward
5663                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5664                     (push (cons (car extra) (nnheader-header-value))
5665                           out))
5666                   (pop extra))
5667                 out))))
5668           (when (equal id ref)
5669             (setq ref nil))
5670
5671           (when gnus-alter-header-function
5672             (funcall gnus-alter-header-function header)
5673             (setq id (mail-header-id header)
5674                   ref (gnus-parent-id (mail-header-references header))))
5675
5676           (when (setq header
5677                       (gnus-dependencies-add-header
5678                        header dependencies force-new))
5679             (push header headers))
5680           (goto-char (point-max))
5681           (widen))
5682         (nreverse headers)))))
5683
5684 ;; Goes through the xover lines and returns a list of vectors
5685 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5686                                                   force-new dependencies
5687                                                   group also-fetch-heads)
5688   "Parse the news overview data in the server buffer.
5689 Return a list of headers that match SEQUENCE (see
5690 `nntp-retrieve-headers')."
5691   ;; Get the Xref when the users reads the articles since most/some
5692   ;; NNTP servers do not include Xrefs when using XOVER.
5693   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5694   (let ((mail-parse-charset gnus-newsgroup-charset)
5695         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5696         (cur nntp-server-buffer)
5697         (dependencies (or dependencies gnus-newsgroup-dependencies))
5698         (allp (cond
5699                ((eq gnus-read-all-available-headers t)
5700                 t)
5701                ((stringp gnus-read-all-available-headers)
5702                 (string-match gnus-read-all-available-headers group))
5703                (t
5704                 nil)))
5705         number headers header)
5706     (save-excursion
5707       (set-buffer nntp-server-buffer)
5708       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5709       ;; Allow the user to mangle the headers before parsing them.
5710       (gnus-run-hooks 'gnus-parse-headers-hook)
5711       (goto-char (point-min))
5712       (gnus-parse-without-error
5713         (while (and (or sequence allp)
5714                     (not (eobp)))
5715           (setq number (read cur))
5716           (when (not allp)
5717             (while (and sequence
5718                         (< (car sequence) number))
5719               (setq sequence (cdr sequence))))
5720           (when (and (or allp
5721                          (and sequence
5722                               (eq number (car sequence))))
5723                      (progn
5724                        (setq sequence (cdr sequence))
5725                        (setq header (inline
5726                                       (gnus-nov-parse-line
5727                                        number dependencies force-new)))))
5728             (push header headers))
5729           (forward-line 1)))
5730       ;; A common bug in inn is that if you have posted an article and
5731       ;; then retrieves the active file, it will answer correctly --
5732       ;; the new article is included.  However, a NOV entry for the
5733       ;; article may not have been generated yet, so this may fail.
5734       ;; We work around this problem by retrieving the last few
5735       ;; headers using HEAD.
5736       (if (or (not also-fetch-heads)
5737               (not sequence))
5738           ;; We (probably) got all the headers.
5739           (nreverse headers)
5740         (let ((gnus-nov-is-evil t))
5741           (nconc
5742            (nreverse headers)
5743            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5744              (gnus-get-newsgroup-headers))))))))
5745
5746 (defun gnus-article-get-xrefs ()
5747   "Fill in the Xref value in `gnus-current-headers', if necessary.
5748 This is meant to be called in `gnus-article-internal-prepare-hook'."
5749   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5750                                  gnus-current-headers)))
5751     (or (not gnus-use-cross-reference)
5752         (not headers)
5753         (and (mail-header-xref headers)
5754              (not (string= (mail-header-xref headers) "")))
5755         (let ((case-fold-search t)
5756               xref)
5757           (save-restriction
5758             (nnheader-narrow-to-headers)
5759             (goto-char (point-min))
5760             (when (or (and (not (eobp))
5761                            (eq (downcase (char-after)) ?x)
5762                            (looking-at "Xref:"))
5763                       (search-forward "\nXref:" nil t))
5764               (goto-char (1+ (match-end 0)))
5765               (setq xref (buffer-substring (point)
5766                                            (progn (end-of-line) (point))))
5767               (mail-header-set-xref headers xref)))))))
5768
5769 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5770   "Find article ID and insert the summary line for that article.
5771 OLD-HEADER can either be a header or a line number to insert
5772 the subject line on."
5773   (let* ((line (and (numberp old-header) old-header))
5774          (old-header (and (vectorp old-header) old-header))
5775          (header (cond ((and old-header use-old-header)
5776                         old-header)
5777                        ((and (numberp id)
5778                              (gnus-number-to-header id))
5779                         (gnus-number-to-header id))
5780                        (t
5781                         (gnus-read-header id))))
5782          (number (and (numberp id) id))
5783          d)
5784     (when header
5785       ;; Rebuild the thread that this article is part of and go to the
5786       ;; article we have fetched.
5787       (when (and (not gnus-show-threads)
5788                  old-header)
5789         (when (and number
5790                    (setq d (gnus-data-find (mail-header-number old-header))))
5791           (goto-char (gnus-data-pos d))
5792           (gnus-data-remove
5793            number
5794            (- (gnus-point-at-bol)
5795               (prog1
5796                   (1+ (gnus-point-at-eol))
5797                 (gnus-delete-line))))))
5798       (when old-header
5799         (mail-header-set-number header (mail-header-number old-header)))
5800       (setq gnus-newsgroup-sparse
5801             (delq (setq number (mail-header-number header))
5802                   gnus-newsgroup-sparse))
5803       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5804       (push number gnus-newsgroup-limit)
5805       (gnus-rebuild-thread (mail-header-id header) line)
5806       (gnus-summary-goto-subject number nil t))
5807     (when (and (numberp number)
5808                (> number 0))
5809       ;; We have to update the boundaries even if we can't fetch the
5810       ;; article if ID is a number -- so that the next `P' or `N'
5811       ;; command will fetch the previous (or next) article even
5812       ;; if the one we tried to fetch this time has been canceled.
5813       (when (> number gnus-newsgroup-end)
5814         (setq gnus-newsgroup-end number))
5815       (when (< number gnus-newsgroup-begin)
5816         (setq gnus-newsgroup-begin number))
5817       (setq gnus-newsgroup-unselected
5818             (delq number gnus-newsgroup-unselected)))
5819     ;; Report back a success?
5820     (and header (mail-header-number header))))
5821
5822 ;;; Process/prefix in the summary buffer
5823
5824 (defun gnus-summary-work-articles (n)
5825   "Return a list of articles to be worked upon.
5826 The prefix argument, the list of process marked articles, and the
5827 current article will be taken into consideration."
5828   (save-excursion
5829     (set-buffer gnus-summary-buffer)
5830     (cond
5831      (n
5832       ;; A numerical prefix has been given.
5833       (setq n (prefix-numeric-value n))
5834       (let ((backward (< n 0))
5835             (n (abs (prefix-numeric-value n)))
5836             articles article)
5837         (save-excursion
5838           (while
5839               (and (> n 0)
5840                    (push (setq article (gnus-summary-article-number))
5841                          articles)
5842                    (if backward
5843                        (gnus-summary-find-prev nil article)
5844                      (gnus-summary-find-next nil article)))
5845             (decf n)))
5846         (nreverse articles)))
5847      ((and (gnus-region-active-p) (mark))
5848       (message "region active")
5849       ;; Work on the region between point and mark.
5850       (let ((max (max (point) (mark)))
5851             articles article)
5852         (save-excursion
5853           (goto-char (min (min (point) (mark))))
5854           (while
5855               (and
5856                (push (setq article (gnus-summary-article-number)) articles)
5857                (gnus-summary-find-next nil article)
5858                (< (point) max)))
5859           (nreverse articles))))
5860      (gnus-newsgroup-processable
5861       ;; There are process-marked articles present.
5862       ;; Save current state.
5863       (gnus-summary-save-process-mark)
5864       ;; Return the list.
5865       (reverse gnus-newsgroup-processable))
5866      (t
5867       ;; Just return the current article.
5868       (list (gnus-summary-article-number))))))
5869
5870 (defmacro gnus-summary-iterate (arg &rest forms)
5871   "Iterate over the process/prefixed articles and do FORMS.
5872 ARG is the interactive prefix given to the command.  FORMS will be
5873 executed with point over the summary line of the articles."
5874   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5875     `(let ((,articles (gnus-summary-work-articles ,arg)))
5876        (while ,articles
5877          (gnus-summary-goto-subject (car ,articles))
5878          ,@forms
5879          (pop ,articles)))))
5880
5881 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5882 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5883
5884 (defun gnus-summary-save-process-mark ()
5885   "Push the current set of process marked articles on the stack."
5886   (interactive)
5887   (push (copy-sequence gnus-newsgroup-processable)
5888         gnus-newsgroup-process-stack))
5889
5890 (defun gnus-summary-kill-process-mark ()
5891   "Push the current set of process marked articles on the stack and unmark."
5892   (interactive)
5893   (gnus-summary-save-process-mark)
5894   (gnus-summary-unmark-all-processable))
5895
5896 (defun gnus-summary-yank-process-mark ()
5897   "Pop the last process mark state off the stack and restore it."
5898   (interactive)
5899   (unless gnus-newsgroup-process-stack
5900     (error "Empty mark stack"))
5901   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5902
5903 (defun gnus-summary-process-mark-set (set)
5904   "Make SET into the current process marked articles."
5905   (gnus-summary-unmark-all-processable)
5906   (while set
5907     (gnus-summary-set-process-mark (pop set))))
5908
5909 ;;; Searching and stuff
5910
5911 (defun gnus-summary-search-group (&optional backward use-level)
5912   "Search for next unread newsgroup.
5913 If optional argument BACKWARD is non-nil, search backward instead."
5914   (save-excursion
5915     (set-buffer gnus-group-buffer)
5916     (when (gnus-group-search-forward
5917            backward nil (if use-level (gnus-group-group-level) nil))
5918       (gnus-group-group-name))))
5919
5920 (defun gnus-summary-best-group (&optional exclude-group)
5921   "Find the name of the best unread group.
5922 If EXCLUDE-GROUP, do not go to this group."
5923   (save-excursion
5924     (set-buffer gnus-group-buffer)
5925     (save-excursion
5926       (gnus-group-best-unread-group exclude-group))))
5927
5928 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5929   (if backward (gnus-summary-find-prev)
5930     (let* ((dummy (gnus-summary-article-intangible-p))
5931            (article (or article (gnus-summary-article-number)))
5932            (arts (gnus-data-find-list article))
5933            result)
5934       (when (and (not dummy)
5935                  (or (not gnus-summary-check-current)
5936                      (not unread)
5937                      (not (gnus-data-unread-p (car arts)))))
5938         (setq arts (cdr arts)))
5939       (when (setq result
5940                   (if unread
5941                       (progn
5942                         (while arts
5943                           (when (or (and undownloaded
5944                                          (memq (car arts) gnus-newsgroup-undownloaded))
5945                                     (gnus-data-unread-p (car arts)))
5946                             (setq result (car arts)
5947                                   arts nil))
5948                           (setq arts (cdr arts)))
5949                         result)
5950                     (car arts)))
5951         (goto-char (gnus-data-pos result))
5952         (gnus-data-number result)))))
5953
5954 (defun gnus-summary-find-prev (&optional unread article)
5955   (let* ((eobp (eobp))
5956          (article (or article (gnus-summary-article-number)))
5957          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5958          result)
5959     (when (and (not eobp)
5960                (or (not gnus-summary-check-current)
5961                    (not unread)
5962                    (not (gnus-data-unread-p (car arts)))))
5963       (setq arts (cdr arts)))
5964     (when (setq result
5965                 (if unread
5966                     (progn
5967                       (while arts
5968                         (when (gnus-data-unread-p (car arts))
5969                           (setq result (car arts)
5970                                 arts nil))
5971                         (setq arts (cdr arts)))
5972                       result)
5973                   (car arts)))
5974       (goto-char (gnus-data-pos result))
5975       (gnus-data-number result))))
5976
5977 (defun gnus-summary-find-subject (subject &optional unread backward article)
5978   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5979          (article (or article (gnus-summary-article-number)))
5980          (articles (gnus-data-list backward))
5981          (arts (gnus-data-find-list article articles))
5982          result)
5983     (when (or (not gnus-summary-check-current)
5984               (not unread)
5985               (not (gnus-data-unread-p (car arts))))
5986       (setq arts (cdr arts)))
5987     (while arts
5988       (and (or (not unread)
5989                (gnus-data-unread-p (car arts)))
5990            (vectorp (gnus-data-header (car arts)))
5991            (gnus-subject-equal
5992             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5993            (setq result (car arts)
5994                  arts nil))
5995       (setq arts (cdr arts)))
5996     (and result
5997          (goto-char (gnus-data-pos result))
5998          (gnus-data-number result))))
5999
6000 (defun gnus-summary-search-forward (&optional unread subject backward)
6001   "Search forward for an article.
6002 If UNREAD, look for unread articles.  If SUBJECT, look for
6003 articles with that subject.  If BACKWARD, search backward instead."
6004   (cond (subject (gnus-summary-find-subject subject unread backward))
6005         (backward (gnus-summary-find-prev unread))
6006         (t (gnus-summary-find-next unread))))
6007
6008 (defun gnus-recenter (&optional n)
6009   "Center point in window and redisplay frame.
6010 Also do horizontal recentering."
6011   (interactive "P")
6012   (when (and gnus-auto-center-summary
6013              (not (eq gnus-auto-center-summary 'vertical)))
6014     (gnus-horizontal-recenter))
6015   (recenter n))
6016
6017 (defun gnus-summary-recenter ()
6018   "Center point in the summary window.
6019 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6020 displayed, no centering will be performed."
6021   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6022 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6023   (interactive)
6024   (let* ((top (cond ((< (window-height) 4) 0)
6025                     ((< (window-height) 7) 1)
6026                     (t (if (numberp gnus-auto-center-summary)
6027                            gnus-auto-center-summary
6028                          2))))
6029          (height (1- (window-height)))
6030          (bottom (save-excursion (goto-char (point-max))
6031                                  (forward-line (- height))
6032                                  (point)))
6033          (window (get-buffer-window (current-buffer))))
6034     ;; The user has to want it.
6035     (when gnus-auto-center-summary
6036       (when (get-buffer-window gnus-article-buffer)
6037         ;; Only do recentering when the article buffer is displayed,
6038       ;; Set the window start to either `bottom', which is the biggest
6039         ;; possible valid number, or the second line from the top,
6040         ;; whichever is the least.
6041         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6042           (if (> bottom top-pos)
6043               ;; Keep the second line from the top visible
6044               (set-window-start window top-pos t)
6045             ;; Try to keep the bottom line visible; if it's partially
6046             ;; obscured, either scroll one more line to make it fully
6047             ;; visible, or revert to using TOP-POS.
6048             (save-excursion
6049               (goto-char (point-max))
6050               (forward-line -1)
6051               (let ((last-line-start (point)))
6052                 (goto-char bottom)
6053                 (set-window-start window (point) t)
6054                 (when (not (pos-visible-in-window-p last-line-start window))
6055                   (forward-line 1)
6056                   (set-window-start window (min (point) top-pos) t)))))))
6057       ;; Do horizontal recentering while we're at it.
6058       (when (and (get-buffer-window (current-buffer) t)
6059                  (not (eq gnus-auto-center-summary 'vertical)))
6060         (let ((selected (selected-window)))
6061           (select-window (get-buffer-window (current-buffer) t))
6062           (gnus-summary-position-point)
6063           (gnus-horizontal-recenter)
6064           (select-window selected))))))
6065
6066 (defun gnus-summary-jump-to-group (newsgroup)
6067   "Move point to NEWSGROUP in group mode buffer."
6068   ;; Keep update point of group mode buffer if visible.
6069   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6070       (save-window-excursion
6071         ;; Take care of tree window mode.
6072         (when (get-buffer-window gnus-group-buffer)
6073           (pop-to-buffer gnus-group-buffer))
6074         (gnus-group-jump-to-group newsgroup))
6075     (save-excursion
6076       ;; Take care of tree window mode.
6077       (if (get-buffer-window gnus-group-buffer)
6078           (pop-to-buffer gnus-group-buffer)
6079         (set-buffer gnus-group-buffer))
6080       (gnus-group-jump-to-group newsgroup))))
6081
6082 ;; This function returns a list of article numbers based on the
6083 ;; difference between the ranges of read articles in this group and
6084 ;; the range of active articles.
6085 (defun gnus-list-of-unread-articles (group)
6086   (let* ((read (gnus-info-read (gnus-get-info group)))
6087          (active (or (gnus-active group) (gnus-activate-group group)))
6088          (last (cdr active))
6089          first nlast unread)
6090     ;; If none are read, then all are unread.
6091     (if (not read)
6092         (setq first (car active))
6093       ;; If the range of read articles is a single range, then the
6094       ;; first unread article is the article after the last read
6095       ;; article.  Sounds logical, doesn't it?
6096       (if (and (not (listp (cdr read)))
6097                (or (< (car read) (car active))
6098                    (progn (setq read (list read))
6099                           nil)))
6100           (setq first (max (car active) (1+ (cdr read))))
6101         ;; `read' is a list of ranges.
6102         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6103                                   (caar read)))
6104                   1)
6105           (setq first (car active)))
6106         (while read
6107           (when first
6108             (while (< first nlast)
6109               (push first unread)
6110               (setq first (1+ first))))
6111           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6112           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6113           (setq read (cdr read)))))
6114     ;; And add the last unread articles.
6115     (while (<= first last)
6116       (push first unread)
6117       (setq first (1+ first)))
6118     ;; Return the list of unread articles.
6119     (delq 0 (nreverse unread))))
6120
6121 (defun gnus-list-of-read-articles (group)
6122   "Return a list of unread, unticked and non-dormant articles."
6123   (let* ((info (gnus-get-info group))
6124          (marked (gnus-info-marks info))
6125          (active (gnus-active group)))
6126     (and info active
6127          (gnus-list-range-difference
6128           (gnus-list-range-difference
6129            (gnus-sorted-complement
6130             (gnus-uncompress-range active)
6131             (gnus-list-of-unread-articles group))
6132            (cdr (assq 'dormant marked)))
6133           (cdr (assq 'tick marked))))))
6134
6135 ;; Various summary commands
6136
6137 (defun gnus-summary-select-article-buffer ()
6138   "Reconfigure windows to show article buffer."
6139   (interactive)
6140   (if (not (gnus-buffer-live-p gnus-article-buffer))
6141       (error "There is no article buffer for this summary buffer")
6142     (gnus-configure-windows 'article)
6143     (select-window (get-buffer-window gnus-article-buffer))))
6144
6145 (defun gnus-summary-universal-argument (arg)
6146   "Perform any operation on all articles that are process/prefixed."
6147   (interactive "P")
6148   (let ((articles (gnus-summary-work-articles arg))
6149         func article)
6150     (if (eq
6151          (setq
6152           func
6153           (key-binding
6154            (read-key-sequence
6155             (substitute-command-keys
6156              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6157          'undefined)
6158         (gnus-error 1 "Undefined key")
6159       (save-excursion
6160         (while articles
6161           (gnus-summary-goto-subject (setq article (pop articles)))
6162           (let (gnus-newsgroup-processable)
6163             (command-execute func))
6164           (gnus-summary-remove-process-mark article)))))
6165   (gnus-summary-position-point))
6166
6167 (defun gnus-summary-toggle-truncation (&optional arg)
6168   "Toggle truncation of summary lines.
6169 With arg, turn line truncation on if arg is positive."
6170   (interactive "P")
6171   (setq truncate-lines
6172         (if (null arg) (not truncate-lines)
6173           (> (prefix-numeric-value arg) 0)))
6174   (redraw-display))
6175
6176 (defun gnus-summary-find-uncancelled ()
6177   "Return the number of an uncancelled article.
6178 The current article is considered, then following articles, then previous
6179 articles.  If all articles are cancelled then return a dummy 0."
6180   (let (found)
6181     (dolist (rev '(nil t))
6182       (unless found      ; don't demand the reverse list if we don't need it
6183         (let ((data (gnus-data-find-list
6184                      (gnus-summary-article-number) (gnus-data-list rev))))
6185           (while (and data (not found))
6186             (if (not (eq gnus-canceled-mark (gnus-data-mark (car data))))
6187                 (setq found (gnus-data-number (car data))))
6188             (setq data (cdr data))))))
6189     (or found 0)))
6190
6191 (defun gnus-summary-reselect-current-group (&optional all rescan)
6192   "Exit and then reselect the current newsgroup.
6193 The prefix argument ALL means to select all articles."
6194   (interactive "P")
6195   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6196     (error "Ephemeral groups can't be reselected"))
6197   (let ((current-subject (gnus-summary-find-uncancelled))
6198         (group gnus-newsgroup-name))
6199     (setq gnus-newsgroup-begin nil)
6200     (gnus-summary-exit)
6201     ;; We have to adjust the point of group mode buffer because
6202     ;; point was moved to the next unread newsgroup by exiting.
6203     (gnus-summary-jump-to-group group)
6204     (when rescan
6205       (save-excursion
6206         (gnus-group-get-new-news-this-group 1)))
6207     (gnus-group-read-group all t)
6208     (gnus-summary-goto-subject current-subject nil t)))
6209
6210 (defun gnus-summary-rescan-group (&optional all)
6211   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6212   (interactive "P")
6213   (gnus-summary-reselect-current-group all t))
6214
6215 (defun gnus-summary-update-info (&optional non-destructive)
6216   (save-excursion
6217     (let ((group gnus-newsgroup-name))
6218       (when group
6219         (when gnus-newsgroup-kill-headers
6220           (setq gnus-newsgroup-killed
6221                 (gnus-compress-sequence
6222                  (gnus-sorted-union
6223                   (gnus-list-range-intersection
6224                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6225                   gnus-newsgroup-unreads)
6226                  t)))
6227         (unless (listp (cdr gnus-newsgroup-killed))
6228           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6229         (let ((headers gnus-newsgroup-headers))
6230           ;; Set the new ranges of read articles.
6231           (save-excursion
6232             (set-buffer gnus-group-buffer)
6233             (gnus-undo-force-boundary))
6234           (gnus-update-read-articles
6235            group (gnus-sorted-union
6236                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6237           ;; Set the current article marks.
6238           (let ((gnus-newsgroup-scored
6239                  (if (and (not gnus-save-score)
6240                           (not non-destructive))
6241                      nil
6242                    gnus-newsgroup-scored)))
6243             (save-excursion
6244               (gnus-update-marks)))
6245           ;; Do the cross-ref thing.
6246           (when gnus-use-cross-reference
6247             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6248           ;; Do not switch windows but change the buffer to work.
6249           (set-buffer gnus-group-buffer)
6250           (unless (gnus-ephemeral-group-p group)
6251             (gnus-group-update-group group)))))))
6252
6253 (defun gnus-summary-save-newsrc (&optional force)
6254   "Save the current number of read/marked articles in the dribble buffer.
6255 The dribble buffer will then be saved.
6256 If FORCE (the prefix), also save the .newsrc file(s)."
6257   (interactive "P")
6258   (gnus-summary-update-info t)
6259   (if force
6260       (gnus-save-newsrc-file)
6261     (gnus-dribble-save)))
6262
6263 (defun gnus-summary-exit (&optional temporary)
6264   "Exit reading current newsgroup, and then return to group selection mode.
6265 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6266   (interactive)
6267   (gnus-set-global-variables)
6268   (when (gnus-buffer-live-p gnus-article-buffer)
6269     (save-excursion
6270       (set-buffer gnus-article-buffer)
6271       (mm-destroy-parts gnus-article-mime-handles)
6272       ;; Set it to nil for safety reason.
6273       (setq gnus-article-mime-handle-alist nil)
6274       (setq gnus-article-mime-handles nil)))
6275   (gnus-kill-save-kill-buffer)
6276   (gnus-async-halt-prefetch)
6277   (let* ((group gnus-newsgroup-name)
6278          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6279          (mode major-mode)
6280          (group-point nil)
6281          (buf (current-buffer)))
6282     (unless quit-config
6283       ;; Do adaptive scoring, and possibly save score files.
6284       (when gnus-newsgroup-adaptive
6285         (gnus-score-adaptive))
6286       (when gnus-use-scoring
6287         (gnus-score-save)))
6288     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6289     ;; If we have several article buffers, we kill them at exit.
6290     (unless gnus-single-article-buffer
6291       (gnus-kill-buffer gnus-original-article-buffer)
6292       (setq gnus-article-current nil))
6293     (when gnus-use-cache
6294       (gnus-cache-possibly-remove-articles)
6295       (gnus-cache-save-buffers))
6296     (gnus-async-prefetch-remove-group group)
6297     (when gnus-suppress-duplicates
6298       (gnus-dup-enter-articles))
6299     (when gnus-use-trees
6300       (gnus-tree-close group))
6301     (when gnus-use-cache
6302       (gnus-cache-write-active))
6303     ;; Remove entries for this group.
6304     (nnmail-purge-split-history (gnus-group-real-name group))
6305     ;; Make all changes in this group permanent.
6306     (unless quit-config
6307       (gnus-run-hooks 'gnus-exit-group-hook)
6308       (gnus-summary-update-info))
6309     (gnus-close-group group)
6310     ;; Make sure where we were, and go to next newsgroup.
6311     (set-buffer gnus-group-buffer)
6312     (unless quit-config
6313       (gnus-group-jump-to-group group))
6314     (gnus-run-hooks 'gnus-summary-exit-hook)
6315     (unless (or quit-config
6316                 ;; If this group has disappeared from the summary
6317                 ;; buffer, don't skip forwards.
6318                 (not (string= group (gnus-group-group-name))))
6319       (gnus-group-next-unread-group 1))
6320     (setq group-point (point))
6321     (if temporary
6322         nil                             ;Nothing to do.
6323       ;; If we have several article buffers, we kill them at exit.
6324       (unless gnus-single-article-buffer
6325         (gnus-kill-buffer gnus-article-buffer)
6326         (gnus-kill-buffer gnus-original-article-buffer)
6327         (setq gnus-article-current nil))
6328       (set-buffer buf)
6329       (if (not gnus-kill-summary-on-exit)
6330           (progn
6331             (gnus-deaden-summary)
6332             (setq mode nil))
6333        ;; We set all buffer-local variables to nil.  It is unclear why
6334         ;; this is needed, but if we don't, buffer-local variables are
6335         ;; not garbage-collected, it seems.  This would the lead to en
6336         ;; ever-growing Emacs.
6337         (gnus-summary-clear-local-variables)
6338         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6339           (gnus-summary-clear-local-variables))
6340         (when (get-buffer gnus-article-buffer)
6341           (bury-buffer gnus-article-buffer))
6342         ;; We clear the global counterparts of the buffer-local
6343         ;; variables as well, just to be on the safe side.
6344         (set-buffer gnus-group-buffer)
6345         (gnus-summary-clear-local-variables)
6346         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6347           (gnus-summary-clear-local-variables)))
6348       (setq gnus-current-select-method gnus-select-method)
6349       (pop-to-buffer gnus-group-buffer)
6350       (if (not quit-config)
6351           (progn
6352             (goto-char group-point)
6353             (gnus-configure-windows 'group 'force))
6354         (gnus-handle-ephemeral-exit quit-config))
6355       ;; Return to group mode buffer.
6356       (when (eq mode 'gnus-summary-mode)
6357         (gnus-kill-buffer buf))
6358       ;; Clear the current group name.
6359       (unless quit-config
6360         (setq gnus-newsgroup-name nil)))))
6361
6362 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6363 (defun gnus-summary-exit-no-update (&optional no-questions)
6364   "Quit reading current newsgroup without updating read article info."
6365   (interactive)
6366   (let* ((group gnus-newsgroup-name)
6367          (quit-config (gnus-group-quit-config group)))
6368     (when (or no-questions
6369               gnus-expert-user
6370               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6371       (gnus-async-halt-prefetch)
6372       (mapcar 'funcall
6373               (delq 'gnus-summary-expire-articles
6374                     (copy-sequence gnus-summary-prepare-exit-hook)))
6375       (when (gnus-buffer-live-p gnus-article-buffer)
6376         (save-excursion
6377           (set-buffer gnus-article-buffer)
6378           (mm-destroy-parts gnus-article-mime-handles)
6379           ;; Set it to nil for safety reason.
6380           (setq gnus-article-mime-handle-alist nil)
6381           (setq gnus-article-mime-handles nil)))
6382       ;; If we have several article buffers, we kill them at exit.
6383       (unless gnus-single-article-buffer
6384         (gnus-kill-buffer gnus-article-buffer)
6385         (gnus-kill-buffer gnus-original-article-buffer)
6386         (setq gnus-article-current nil))
6387       (if (not gnus-kill-summary-on-exit)
6388           (gnus-deaden-summary)
6389         (gnus-close-group group)
6390         (gnus-summary-clear-local-variables)
6391         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6392           (gnus-summary-clear-local-variables))
6393         (set-buffer gnus-group-buffer)
6394         (gnus-summary-clear-local-variables)
6395         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6396           (gnus-summary-clear-local-variables))
6397         (when (get-buffer gnus-summary-buffer)
6398           (kill-buffer gnus-summary-buffer)))
6399       (unless gnus-single-article-buffer
6400         (setq gnus-article-current nil))
6401       (when gnus-use-trees
6402         (gnus-tree-close group))
6403       (gnus-async-prefetch-remove-group group)
6404       (when (get-buffer gnus-article-buffer)
6405         (bury-buffer gnus-article-buffer))
6406       ;; Return to the group buffer.
6407       (gnus-configure-windows 'group 'force)
6408       ;; Clear the current group name.
6409       (setq gnus-newsgroup-name nil)
6410       (when (equal (gnus-group-group-name) group)
6411         (gnus-group-next-unread-group 1))
6412       (when quit-config
6413         (gnus-handle-ephemeral-exit quit-config)))))
6414
6415 (defun gnus-handle-ephemeral-exit (quit-config)
6416   "Handle movement when leaving an ephemeral group.
6417 The state which existed when entering the ephemeral is reset."
6418   (if (not (buffer-name (car quit-config)))
6419       (gnus-configure-windows 'group 'force)
6420     (set-buffer (car quit-config))
6421     (cond ((eq major-mode 'gnus-summary-mode)
6422            (gnus-set-global-variables))
6423           ((eq major-mode 'gnus-article-mode)
6424            (save-excursion
6425              ;; The `gnus-summary-buffer' variable may point
6426              ;; to the old summary buffer when using a single
6427              ;; article buffer.
6428              (unless (gnus-buffer-live-p gnus-summary-buffer)
6429                (set-buffer gnus-group-buffer))
6430              (set-buffer gnus-summary-buffer)
6431              (gnus-set-global-variables))))
6432     (if (or (eq (cdr quit-config) 'article)
6433             (eq (cdr quit-config) 'pick))
6434         (progn
6435           ;; The current article may be from the ephemeral group
6436           ;; thus it is best that we reload this article
6437           (gnus-summary-show-article)
6438           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6439               (gnus-configure-windows 'pick 'force)
6440             (gnus-configure-windows (cdr quit-config) 'force)))
6441       (gnus-configure-windows (cdr quit-config) 'force))
6442     (when (eq major-mode 'gnus-summary-mode)
6443       (gnus-summary-next-subject 1 nil t)
6444       (gnus-summary-recenter)
6445       (gnus-summary-position-point))))
6446
6447 ;;; Dead summaries.
6448
6449 (defvar gnus-dead-summary-mode-map nil)
6450
6451 (unless gnus-dead-summary-mode-map
6452   (setq gnus-dead-summary-mode-map (make-keymap))
6453   (suppress-keymap gnus-dead-summary-mode-map)
6454   (substitute-key-definition
6455    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6456   (dolist (key '("\C-d" "\r" "\177" [delete]))
6457     (define-key gnus-dead-summary-mode-map
6458       key 'gnus-summary-wake-up-the-dead))
6459   (dolist (key '("q" "Q"))
6460     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6461
6462 (defvar gnus-dead-summary-mode nil
6463   "Minor mode for Gnus summary buffers.")
6464
6465 (defun gnus-dead-summary-mode (&optional arg)
6466   "Minor mode for Gnus summary buffers."
6467   (interactive "P")
6468   (when (eq major-mode 'gnus-summary-mode)
6469     (make-local-variable 'gnus-dead-summary-mode)
6470     (setq gnus-dead-summary-mode
6471           (if (null arg) (not gnus-dead-summary-mode)
6472             (> (prefix-numeric-value arg) 0)))
6473     (when gnus-dead-summary-mode
6474       (gnus-add-minor-mode
6475        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6476
6477 (defun gnus-deaden-summary ()
6478   "Make the current summary buffer into a dead summary buffer."
6479   ;; Kill any previous dead summary buffer.
6480   (when (and gnus-dead-summary
6481              (buffer-name gnus-dead-summary))
6482     (save-excursion
6483       (set-buffer gnus-dead-summary)
6484       (when gnus-dead-summary-mode
6485         (kill-buffer (current-buffer)))))
6486   ;; Make this the current dead summary.
6487   (setq gnus-dead-summary (current-buffer))
6488   (gnus-dead-summary-mode 1)
6489   (let ((name (buffer-name)))
6490     (when (string-match "Summary" name)
6491       (rename-buffer
6492        (concat (substring name 0 (match-beginning 0)) "Dead "
6493                (substring name (match-beginning 0)))
6494        t)
6495       (bury-buffer))))
6496
6497 (defun gnus-kill-or-deaden-summary (buffer)
6498   "Kill or deaden the summary BUFFER."
6499   (save-excursion
6500     (when (and (buffer-name buffer)
6501                (not gnus-single-article-buffer))
6502       (save-excursion
6503         (set-buffer buffer)
6504         (gnus-kill-buffer gnus-article-buffer)
6505         (gnus-kill-buffer gnus-original-article-buffer)))
6506     (cond
6507      ;; Kill the buffer.
6508      (gnus-kill-summary-on-exit
6509       (when (and gnus-use-trees
6510                  (gnus-buffer-exists-p buffer))
6511         (save-excursion
6512           (set-buffer buffer)
6513           (gnus-tree-close gnus-newsgroup-name)))
6514       (gnus-kill-buffer buffer))
6515      ;; Deaden the buffer.
6516      ((gnus-buffer-exists-p buffer)
6517       (save-excursion
6518         (set-buffer buffer)
6519         (gnus-deaden-summary))))))
6520
6521 (defun gnus-summary-wake-up-the-dead (&rest args)
6522   "Wake up the dead summary buffer."
6523   (interactive)
6524   (gnus-dead-summary-mode -1)
6525   (let ((name (buffer-name)))
6526     (when (string-match "Dead " name)
6527       (rename-buffer
6528        (concat (substring name 0 (match-beginning 0))
6529                (substring name (match-end 0)))
6530        t)))
6531   (gnus-message 3 "This dead summary is now alive again"))
6532
6533 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6534 (defun gnus-summary-fetch-faq (&optional faq-dir)
6535   "Fetch the FAQ for the current group.
6536 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6537 in."
6538   (interactive
6539    (list
6540     (when current-prefix-arg
6541       (completing-read
6542        "FAQ dir: " (and (listp gnus-group-faq-directory)
6543                         (mapcar (lambda (file) (list file))
6544                                 gnus-group-faq-directory))))))
6545   (let (gnus-faq-buffer)
6546     (when (setq gnus-faq-buffer
6547                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6548       (gnus-configure-windows 'summary-faq))))
6549
6550 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6551 (defun gnus-summary-describe-group (&optional force)
6552   "Describe the current newsgroup."
6553   (interactive "P")
6554   (gnus-group-describe-group force gnus-newsgroup-name))
6555
6556 (defun gnus-summary-describe-briefly ()
6557   "Describe summary mode commands briefly."
6558   (interactive)
6559   (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")))
6560
6561 ;; Walking around group mode buffer from summary mode.
6562
6563 (defun gnus-summary-next-group (&optional no-article target-group backward)
6564   "Exit current newsgroup and then select next unread newsgroup.
6565 If prefix argument NO-ARTICLE is non-nil, no article is selected
6566 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6567 previous group instead."
6568   (interactive "P")
6569   ;; Stop pre-fetching.
6570   (gnus-async-halt-prefetch)
6571   (let ((current-group gnus-newsgroup-name)
6572         (current-buffer (current-buffer))
6573         entered)
6574     (while (not entered)
6575       ;; Then we find what group we are supposed to enter.
6576       (set-buffer gnus-group-buffer)
6577       (gnus-group-jump-to-group current-group)
6578       (setq target-group
6579             (or target-group
6580                 (if (eq gnus-keep-same-level 'best)
6581                     (gnus-summary-best-group gnus-newsgroup-name)
6582                   (gnus-summary-search-group backward gnus-keep-same-level))))
6583       (if (not target-group)
6584           ;; There are no further groups, so we return to the group
6585           ;; buffer.
6586           (progn
6587             (gnus-message 5 "Returning to the group buffer")
6588             (setq entered t)
6589             (when (gnus-buffer-live-p current-buffer)
6590               (set-buffer current-buffer)
6591               (gnus-summary-exit))
6592             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6593         ;; We try to enter the target group.
6594         (gnus-group-jump-to-group target-group)
6595         (let ((unreads (gnus-group-group-unread)))
6596           (if (and (or (eq t unreads)
6597                        (and unreads (not (zerop unreads))))
6598                    (progn
6599                      ;; Now we semi-exit this group to update Xrefs
6600                      ;; and all variables.  We can't do a real exit,
6601                      ;; because the window conf must remain the same
6602                      ;; in case the user is prompted for info, and we
6603                      ;; don't want the window conf to change before
6604                      ;; that...
6605                      (when (gnus-buffer-live-p current-buffer)
6606                        (set-buffer current-buffer)
6607                        (gnus-summary-exit t))
6608                      (gnus-summary-read-group
6609                       target-group nil no-article
6610                       (and (buffer-name current-buffer) current-buffer)
6611                       nil backward)))
6612               (setq entered t)
6613             (setq current-group target-group
6614                   target-group nil)))))))
6615
6616 (defun gnus-summary-prev-group (&optional no-article)
6617   "Exit current newsgroup and then select previous unread newsgroup.
6618 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6619   (interactive "P")
6620   (gnus-summary-next-group no-article nil t))
6621
6622 ;; Walking around summary lines.
6623
6624 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6625   "Go to the first unread subject.
6626 If UNREAD is non-nil, go to the first unread article.
6627 Returns the article selected or nil if there are no unread articles."
6628   (interactive "P")
6629   (prog1
6630       (cond
6631        ;; Empty summary.
6632        ((null gnus-newsgroup-data)
6633         (gnus-message 3 "No articles in the group")
6634         nil)
6635        ;; Pick the first article.
6636        ((not unread)
6637         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6638         (gnus-data-number (car gnus-newsgroup-data)))
6639        ;; No unread articles.
6640        ((null gnus-newsgroup-unreads)
6641         (gnus-message 3 "No more unread articles")
6642         nil)
6643        ;; Find the first unread article.
6644        (t
6645         (let ((data gnus-newsgroup-data))
6646           (while (and data
6647                       (and (not (and undownloaded
6648                                      (memq (car data) gnus-newsgroup-undownloaded)))
6649                            (if unseen
6650                                (or (not (memq
6651                                          (gnus-data-number (car data))
6652                                          gnus-newsgroup-unseen))
6653                                    (not (gnus-data-unread-p (car data))))
6654                              (not (gnus-data-unread-p (car data))))))
6655             (setq data (cdr data)))
6656           (when data
6657             (goto-char (gnus-data-pos (car data)))
6658             (gnus-data-number (car data))))))
6659     (gnus-summary-position-point)))
6660
6661 (defun gnus-summary-next-subject (n &optional unread dont-display)
6662   "Go to next N'th summary line.
6663 If N is negative, go to the previous N'th subject line.
6664 If UNREAD is non-nil, only unread articles are selected.
6665 The difference between N and the actual number of steps taken is
6666 returned."
6667   (interactive "p")
6668   (let ((backward (< n 0))
6669         (n (abs n)))
6670     (while (and (> n 0)
6671                 (if backward
6672                     (gnus-summary-find-prev unread)
6673                   (gnus-summary-find-next unread)))
6674       (unless (zerop (setq n (1- n)))
6675         (gnus-summary-show-thread)))
6676     (when (/= 0 n)
6677       (gnus-message 7 "No more%s articles"
6678                     (if unread " unread" "")))
6679     (unless dont-display
6680       (gnus-summary-recenter)
6681       (gnus-summary-position-point))
6682     n))
6683
6684 (defun gnus-summary-next-unread-subject (n)
6685   "Go to next N'th unread summary line."
6686   (interactive "p")
6687   (gnus-summary-next-subject n t))
6688
6689 (defun gnus-summary-prev-subject (n &optional unread)
6690   "Go to previous N'th summary line.
6691 If optional argument UNREAD is non-nil, only unread article is selected."
6692   (interactive "p")
6693   (gnus-summary-next-subject (- n) unread))
6694
6695 (defun gnus-summary-prev-unread-subject (n)
6696   "Go to previous N'th unread summary line."
6697   (interactive "p")
6698   (gnus-summary-next-subject (- n) t))
6699
6700 (defun gnus-summary-goto-subject (article &optional force silent)
6701   "Go the subject line of ARTICLE.
6702 If FORCE, also allow jumping to articles not currently shown."
6703   (interactive "nArticle number: ")
6704   (unless (numberp article)
6705     (error "Article %s is not a number" article))
6706   (let ((b (point))
6707         (data (gnus-data-find article)))
6708     ;; We read in the article if we have to.
6709     (and (not data)
6710          force
6711          (gnus-summary-insert-subject
6712           article
6713           (if (or (numberp force) (vectorp force)) force)
6714           t)
6715          (setq data (gnus-data-find article)))
6716     (goto-char b)
6717     (if (not data)
6718         (progn
6719           (unless silent
6720             (gnus-message 3 "Can't find article %d" article))
6721           nil)
6722       (let ((pt (gnus-data-pos data)))
6723         (goto-char pt)
6724         (gnus-summary-set-article-display-arrow pt))
6725       (gnus-summary-position-point)
6726       article)))
6727
6728 ;; Walking around summary lines with displaying articles.
6729
6730 (defun gnus-summary-expand-window (&optional arg)
6731   "Make the summary buffer take up the entire Emacs frame.
6732 Given a prefix, will force an `article' buffer configuration."
6733   (interactive "P")
6734   (if arg
6735       (gnus-configure-windows 'article 'force)
6736     (gnus-configure-windows 'summary 'force)))
6737
6738 (defun gnus-summary-display-article (article &optional all-header)
6739   "Display ARTICLE in article buffer."
6740   (when (gnus-buffer-live-p gnus-article-buffer)
6741     (with-current-buffer gnus-article-buffer
6742       (mm-enable-multibyte)))
6743   (gnus-set-global-variables)
6744   (when (gnus-buffer-live-p gnus-article-buffer)
6745     (with-current-buffer gnus-article-buffer
6746       (setq gnus-article-charset gnus-newsgroup-charset)
6747       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6748       (mm-enable-multibyte)))
6749   (if (null article)
6750       nil
6751     (prog1
6752         (if gnus-summary-display-article-function
6753             (funcall gnus-summary-display-article-function article all-header)
6754           (gnus-article-prepare article all-header))
6755       (gnus-run-hooks 'gnus-select-article-hook)
6756       (when (and gnus-current-article
6757                  (not (zerop gnus-current-article)))
6758         (gnus-summary-goto-subject gnus-current-article))
6759       (gnus-summary-recenter)
6760       (when (and gnus-use-trees gnus-show-threads)
6761         (gnus-possibly-generate-tree article)
6762         (gnus-highlight-selected-tree article))
6763       ;; Successfully display article.
6764       (gnus-article-set-window-start
6765        (cdr (assq article gnus-newsgroup-bookmarks))))))
6766
6767 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6768   "Select the current article.
6769 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6770 non-nil, the article will be re-fetched even if it already present in
6771 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6772 be displayed."
6773   ;; Make sure we are in the summary buffer to work around bbdb bug.
6774   (unless (eq major-mode 'gnus-summary-mode)
6775     (set-buffer gnus-summary-buffer))
6776   (let ((article (or article (gnus-summary-article-number)))
6777         (all-headers (not (not all-headers))) ;Must be t or nil.
6778         gnus-summary-display-article-function)
6779     (and (not pseudo)
6780          (gnus-summary-article-pseudo-p article)
6781          (error "This is a pseudo-article"))
6782     (save-excursion
6783       (set-buffer gnus-summary-buffer)
6784       (if (or (and gnus-single-article-buffer
6785                    (or (null gnus-current-article)
6786                        (null gnus-article-current)
6787                        (null (get-buffer gnus-article-buffer))
6788                        (not (eq article (cdr gnus-article-current)))
6789                        (not (equal (car gnus-article-current)
6790                                    gnus-newsgroup-name))))
6791               (and (not gnus-single-article-buffer)
6792                    (or (null gnus-current-article)
6793                        (not (eq gnus-current-article article))))
6794               force)
6795           ;; The requested article is different from the current article.
6796           (progn
6797             (gnus-summary-display-article article all-headers)
6798             (when (gnus-buffer-live-p gnus-article-buffer)
6799               (with-current-buffer gnus-article-buffer
6800                 (if (not gnus-article-decoded-p) ;; a local variable
6801                     (mm-disable-multibyte))))
6802             (gnus-article-set-window-start
6803              (cdr (assq article gnus-newsgroup-bookmarks)))
6804             article)
6805         'old))))
6806
6807 (defun gnus-summary-force-verify-and-decrypt ()
6808   (interactive)
6809   (let ((mm-verify-option 'known)
6810         (mm-decrypt-option 'known)
6811         (gnus-buttonized-mime-types (append (list "multipart/signed"
6812                                                   "multipart/encrypted")
6813                                             gnus-buttonized-mime-types)))
6814     (gnus-summary-select-article nil 'force)))
6815
6816 (defun gnus-summary-set-current-mark (&optional current-mark)
6817   "Obsolete function."
6818   nil)
6819
6820 (defun gnus-summary-next-article (&optional unread subject backward push)
6821   "Select the next article.
6822 If UNREAD, only unread articles are selected.
6823 If SUBJECT, only articles with SUBJECT are selected.
6824 If BACKWARD, the previous article is selected instead of the next."
6825   (interactive "P")
6826   (cond
6827    ;; Is there such an article?
6828    ((and (gnus-summary-search-forward unread subject backward)
6829          (or (gnus-summary-display-article (gnus-summary-article-number))
6830              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6831     (gnus-summary-position-point))
6832    ;; If not, we try the first unread, if that is wanted.
6833    ((and subject
6834          gnus-auto-select-same
6835          (gnus-summary-first-unread-article))
6836     (gnus-summary-position-point)
6837     (gnus-message 6 "Wrapped"))
6838    ;; Try to get next/previous article not displayed in this group.
6839    ((and gnus-auto-extend-newsgroup
6840          (not unread) (not subject))
6841     (gnus-summary-goto-article
6842      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6843      nil (count-lines (point-min) (point))))
6844    ;; Go to next/previous group.
6845    (t
6846     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6847       (gnus-summary-jump-to-group gnus-newsgroup-name))
6848     (let ((cmd last-command-char)
6849           (point
6850            (save-excursion
6851              (set-buffer gnus-group-buffer)
6852              (point)))
6853           (group
6854            (if (eq gnus-keep-same-level 'best)
6855                (gnus-summary-best-group gnus-newsgroup-name)
6856              (gnus-summary-search-group backward gnus-keep-same-level))))
6857       ;; For some reason, the group window gets selected.  We change
6858       ;; it back.
6859       (select-window (get-buffer-window (current-buffer)))
6860       ;; Select next unread newsgroup automagically.
6861       (cond
6862        ((or (not gnus-auto-select-next)
6863             (not cmd))
6864         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6865        ((or (eq gnus-auto-select-next 'quietly)
6866             (and (eq gnus-auto-select-next 'slightly-quietly)
6867                  push)
6868             (and (eq gnus-auto-select-next 'almost-quietly)
6869                  (gnus-summary-last-article-p)))
6870         ;; Select quietly.
6871         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6872             (gnus-summary-exit)
6873           (gnus-message 7 "No more%s articles (%s)..."
6874                         (if unread " unread" "")
6875                         (if group (concat "selecting " group)
6876                           "exiting"))
6877           (gnus-summary-next-group nil group backward)))
6878        (t
6879         (when (gnus-key-press-event-p last-input-event)
6880           (gnus-summary-walk-group-buffer
6881            gnus-newsgroup-name cmd unread backward point))))))))
6882
6883 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6884   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6885                       (?\C-p (gnus-group-prev-unread-group 1))))
6886         (cursor-in-echo-area t)
6887         keve key group ended)
6888     (save-excursion
6889       (set-buffer gnus-group-buffer)
6890       (goto-char start)
6891       (setq group
6892             (if (eq gnus-keep-same-level 'best)
6893                 (gnus-summary-best-group gnus-newsgroup-name)
6894               (gnus-summary-search-group backward gnus-keep-same-level))))
6895     (while (not ended)
6896       (gnus-message
6897        5 "No more%s articles%s" (if unread " unread" "")
6898        (if (and group
6899                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6900            (format " (Type %s for %s [%s])"
6901                    (single-key-description cmd) group
6902                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6903          (format " (Type %s to exit %s)"
6904                  (single-key-description cmd)
6905                  gnus-newsgroup-name)))
6906       ;; Confirm auto selection.
6907       (setq key (car (setq keve (gnus-read-event-char))))
6908       (setq ended t)
6909       (cond
6910        ((assq key keystrokes)
6911         (let ((obuf (current-buffer)))
6912           (switch-to-buffer gnus-group-buffer)
6913           (when group
6914             (gnus-group-jump-to-group group))
6915           (eval (cadr (assq key keystrokes)))
6916           (setq group (gnus-group-group-name))
6917           (switch-to-buffer obuf))
6918         (setq ended nil))
6919        ((equal key cmd)
6920         (if (or (not group)
6921                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6922             (gnus-summary-exit)
6923           (gnus-summary-next-group nil group backward)))
6924        (t
6925         (push (cdr keve) unread-command-events))))))
6926
6927 (defun gnus-summary-next-unread-article ()
6928   "Select unread article after current one."
6929   (interactive)
6930   (gnus-summary-next-article
6931    (or (not (eq gnus-summary-goto-unread 'never))
6932        (gnus-summary-last-article-p (gnus-summary-article-number)))
6933    (and gnus-auto-select-same
6934         (gnus-summary-article-subject))))
6935
6936 (defun gnus-summary-prev-article (&optional unread subject)
6937   "Select the article after the current one.
6938 If UNREAD is non-nil, only unread articles are selected."
6939   (interactive "P")
6940   (gnus-summary-next-article unread subject t))
6941
6942 (defun gnus-summary-prev-unread-article ()
6943   "Select unread article before current one."
6944   (interactive)
6945   (gnus-summary-prev-article
6946    (or (not (eq gnus-summary-goto-unread 'never))
6947        (gnus-summary-first-article-p (gnus-summary-article-number)))
6948    (and gnus-auto-select-same
6949         (gnus-summary-article-subject))))
6950
6951 (defun gnus-summary-next-page (&optional lines circular)
6952   "Show next page of the selected article.
6953 If at the end of the current article, select the next article.
6954 LINES says how many lines should be scrolled up.
6955
6956 If CIRCULAR is non-nil, go to the start of the article instead of
6957 selecting the next article when reaching the end of the current
6958 article."
6959   (interactive "P")
6960   (setq gnus-summary-buffer (current-buffer))
6961   (gnus-set-global-variables)
6962   (let ((article (gnus-summary-article-number))
6963         (article-window (get-buffer-window gnus-article-buffer t))
6964         endp)
6965     ;; If the buffer is empty, we have no article.
6966     (unless article
6967       (error "No article to select"))
6968     (gnus-configure-windows 'article)
6969     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6970         (if (and (eq gnus-summary-goto-unread 'never)
6971                  (not (gnus-summary-last-article-p article)))
6972             (gnus-summary-next-article)
6973           (gnus-summary-next-unread-article))
6974       (if (or (null gnus-current-article)
6975               (null gnus-article-current)
6976               (/= article (cdr gnus-article-current))
6977               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6978           ;; Selected subject is different from current article's.
6979           (gnus-summary-display-article article)
6980         (when article-window
6981           (gnus-eval-in-buffer-window gnus-article-buffer
6982             (setq endp (gnus-article-next-page lines)))
6983           (when endp
6984             (cond (circular
6985                    (gnus-summary-beginning-of-article))
6986                   (lines
6987                    (gnus-message 3 "End of message"))
6988                   ((null lines)
6989                    (if (and (eq gnus-summary-goto-unread 'never)
6990                             (not (gnus-summary-last-article-p article)))
6991                        (gnus-summary-next-article)
6992                      (gnus-summary-next-unread-article))))))))
6993     (gnus-summary-recenter)
6994     (gnus-summary-position-point)))
6995
6996 (defun gnus-summary-prev-page (&optional lines move)
6997   "Show previous page of selected article.
6998 Argument LINES specifies lines to be scrolled down.
6999 If MOVE, move to the previous unread article if point is at
7000 the beginning of the buffer."
7001   (interactive "P")
7002   (let ((article (gnus-summary-article-number))
7003         (article-window (get-buffer-window gnus-article-buffer t))
7004         endp)
7005     (gnus-configure-windows 'article)
7006     (if (or (null gnus-current-article)
7007             (null gnus-article-current)
7008             (/= article (cdr gnus-article-current))
7009             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7010         ;; Selected subject is different from current article's.
7011         (gnus-summary-display-article article)
7012       (gnus-summary-recenter)
7013       (when article-window
7014         (gnus-eval-in-buffer-window gnus-article-buffer
7015           (setq endp (gnus-article-prev-page lines)))
7016         (when (and move endp)
7017           (cond (lines
7018                  (gnus-message 3 "Beginning of message"))
7019                 ((null lines)
7020                  (if (and (eq gnus-summary-goto-unread 'never)
7021                           (not (gnus-summary-first-article-p article)))
7022                      (gnus-summary-prev-article)
7023                    (gnus-summary-prev-unread-article))))))))
7024   (gnus-summary-position-point))
7025
7026 (defun gnus-summary-prev-page-or-article (&optional lines)
7027   "Show previous page of selected article.
7028 Argument LINES specifies lines to be scrolled down.
7029 If at the beginning of the article, go to the next article."
7030   (interactive "P")
7031   (gnus-summary-prev-page lines t))
7032
7033 (defun gnus-summary-scroll-up (lines)
7034   "Scroll up (or down) one line current article.
7035 Argument LINES specifies lines to be scrolled up (or down if negative)."
7036   (interactive "p")
7037   (gnus-configure-windows 'article)
7038   (gnus-summary-show-thread)
7039   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7040     (gnus-eval-in-buffer-window gnus-article-buffer
7041       (cond ((> lines 0)
7042              (when (gnus-article-next-page lines)
7043                (gnus-message 3 "End of message")))
7044             ((< lines 0)
7045              (gnus-article-prev-page (- lines))))))
7046   (gnus-summary-recenter)
7047   (gnus-summary-position-point))
7048
7049 (defun gnus-summary-scroll-down (lines)
7050   "Scroll down (or up) one line current article.
7051 Argument LINES specifies lines to be scrolled down (or up if negative)."
7052   (interactive "p")
7053   (gnus-summary-scroll-up (- lines)))
7054
7055 (defun gnus-summary-next-same-subject ()
7056   "Select next article which has the same subject as current one."
7057   (interactive)
7058   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7059
7060 (defun gnus-summary-prev-same-subject ()
7061   "Select previous article which has the same subject as current one."
7062   (interactive)
7063   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7064
7065 (defun gnus-summary-next-unread-same-subject ()
7066   "Select next unread article which has the same subject as current one."
7067   (interactive)
7068   (gnus-summary-next-article t (gnus-summary-article-subject)))
7069
7070 (defun gnus-summary-prev-unread-same-subject ()
7071   "Select previous unread article which has the same subject as current one."
7072   (interactive)
7073   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7074
7075 (defun gnus-summary-first-unread-article ()
7076   "Select the first unread article.
7077 Return nil if there are no unread articles."
7078   (interactive)
7079   (prog1
7080       (when (gnus-summary-first-subject t)
7081         (gnus-summary-show-thread)
7082         (gnus-summary-first-subject t)
7083         (gnus-summary-display-article (gnus-summary-article-number)))
7084     (gnus-summary-position-point)))
7085
7086 (defun gnus-summary-first-unread-subject ()
7087   "Place the point on the subject line of the first unread article.
7088 Return nil if there are no unread articles."
7089   (interactive)
7090   (prog1
7091       (when (gnus-summary-first-subject t)
7092         (gnus-summary-show-thread)
7093         (gnus-summary-first-subject t))
7094     (gnus-summary-position-point)))
7095
7096 (defun gnus-summary-first-unseen-subject ()
7097   "Place the point on the subject line of the first unseen article.
7098 Return nil if there are no unseen articles."
7099   (interactive)
7100   (prog1
7101       (when (gnus-summary-first-subject t t t)
7102         (gnus-summary-show-thread)
7103         (gnus-summary-first-subject t t t))
7104     (gnus-summary-position-point)))
7105
7106 (defun gnus-summary-first-unseen-or-unread-subject ()
7107   "Place the point on the subject line of the first unseen article.
7108 Return nil if there are no unseen articles."
7109   (interactive)
7110   (prog1
7111       (unless (when (gnus-summary-first-subject t t t)
7112                 (gnus-summary-show-thread)
7113                 (gnus-summary-first-subject t t t))
7114         (when (gnus-summary-first-subject t)
7115           (gnus-summary-show-thread)
7116           (gnus-summary-first-subject t)))
7117     (gnus-summary-position-point)))
7118
7119 (defun gnus-summary-first-article ()
7120   "Select the first article.
7121 Return nil if there are no articles."
7122   (interactive)
7123   (prog1
7124       (when (gnus-summary-first-subject)
7125         (gnus-summary-show-thread)
7126         (gnus-summary-first-subject)
7127         (gnus-summary-display-article (gnus-summary-article-number)))
7128     (gnus-summary-position-point)))
7129
7130 (defun gnus-summary-best-unread-article (&optional arg)
7131   "Select the unread article with the highest score.
7132 If given a prefix argument, select the next unread article that has a
7133 score higher than the default score."
7134   (interactive "P")
7135   (let ((article (if arg
7136                      (gnus-summary-better-unread-subject)
7137                    (gnus-summary-best-unread-subject))))
7138     (if article
7139         (gnus-summary-goto-article article)
7140       (error "No unread articles"))))
7141
7142 (defun gnus-summary-best-unread-subject ()
7143   "Select the unread subject with the highest score."
7144   (interactive)
7145   (let ((best -1000000)
7146         (data gnus-newsgroup-data)
7147         article score)
7148     (while data
7149       (and (gnus-data-unread-p (car data))
7150            (> (setq score
7151                     (gnus-summary-article-score (gnus-data-number (car data))))
7152               best)
7153            (setq best score
7154                  article (gnus-data-number (car data))))
7155       (setq data (cdr data)))
7156     (when article
7157       (gnus-summary-goto-subject article))
7158     (gnus-summary-position-point)
7159     article))
7160
7161 (defun gnus-summary-better-unread-subject ()
7162   "Select the first unread subject that has a score over the default score."
7163   (interactive)
7164   (let ((data gnus-newsgroup-data)
7165         article score)
7166     (while (and (setq article (gnus-data-number (car data)))
7167                 (or (gnus-data-read-p (car data))
7168                     (not (> (gnus-summary-article-score article)
7169                             gnus-summary-default-score))))
7170       (setq data (cdr data)))
7171     (when article
7172       (gnus-summary-goto-subject article))
7173     (gnus-summary-position-point)
7174     article))
7175
7176 (defun gnus-summary-last-subject ()
7177   "Go to the last displayed subject line in the group."
7178   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7179     (when article
7180       (gnus-summary-goto-subject article))))
7181
7182 (defun gnus-summary-goto-article (article &optional all-headers force)
7183   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7184 If ALL-HEADERS is non-nil, no header lines are hidden.
7185 If FORCE, go to the article even if it isn't displayed.  If FORCE
7186 is a number, it is the line the article is to be displayed on."
7187   (interactive
7188    (list
7189     (completing-read
7190      "Article number or Message-ID: "
7191      (mapcar (lambda (number) (list (int-to-string number)))
7192              gnus-newsgroup-limit))
7193     current-prefix-arg
7194     t))
7195   (prog1
7196       (if (and (stringp article)
7197                (string-match "@" article))
7198           (gnus-summary-refer-article article)
7199         (when (stringp article)
7200           (setq article (string-to-number article)))
7201         (if (gnus-summary-goto-subject article force)
7202             (gnus-summary-display-article article all-headers)
7203           (gnus-message 4 "Couldn't go to article %s" article) nil))
7204     (gnus-summary-position-point)))
7205
7206 (defun gnus-summary-goto-last-article ()
7207   "Go to the previously read article."
7208   (interactive)
7209   (prog1
7210       (when gnus-last-article
7211         (gnus-summary-goto-article gnus-last-article nil t))
7212     (gnus-summary-position-point)))
7213
7214 (defun gnus-summary-pop-article (number)
7215   "Pop one article off the history and go to the previous.
7216 NUMBER articles will be popped off."
7217   (interactive "p")
7218   (let (to)
7219     (setq gnus-newsgroup-history
7220           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7221     (if to
7222         (gnus-summary-goto-article (car to) nil t)
7223       (error "Article history empty")))
7224   (gnus-summary-position-point))
7225
7226 ;; Summary commands and functions for limiting the summary buffer.
7227
7228 (defun gnus-summary-limit-to-articles (n)
7229   "Limit the summary buffer to the next N articles.
7230 If not given a prefix, use the process marked articles instead."
7231   (interactive "P")
7232   (prog1
7233       (let ((articles (gnus-summary-work-articles n)))
7234         (setq gnus-newsgroup-processable nil)
7235         (gnus-summary-limit articles))
7236     (gnus-summary-position-point)))
7237
7238 (defun gnus-summary-pop-limit (&optional total)
7239   "Restore the previous limit.
7240 If given a prefix, remove all limits."
7241   (interactive "P")
7242   (when total
7243     (setq gnus-newsgroup-limits
7244           (list (mapcar (lambda (h) (mail-header-number h))
7245                         gnus-newsgroup-headers))))
7246   (unless gnus-newsgroup-limits
7247     (error "No limit to pop"))
7248   (prog1
7249       (gnus-summary-limit nil 'pop)
7250     (gnus-summary-position-point)))
7251
7252 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7253   "Limit the summary buffer to articles that have subjects that match a regexp.
7254 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7255   (interactive
7256    (list (read-string (if current-prefix-arg
7257                           "Exclude subject (regexp): "
7258                         "Limit to subject (regexp): "))
7259          nil current-prefix-arg))
7260   (unless header
7261     (setq header "subject"))
7262   (when (not (equal "" subject))
7263     (prog1
7264         (let ((articles (gnus-summary-find-matching
7265                          (or header "subject") subject 'all nil nil
7266                          not-matching)))
7267           (unless articles
7268             (error "Found no matches for \"%s\"" subject))
7269           (gnus-summary-limit articles))
7270       (gnus-summary-position-point))))
7271
7272 (defun gnus-summary-limit-to-author (from &optional not-matching)
7273   "Limit the summary buffer to articles that have authors that match a regexp.
7274 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7275   (interactive
7276    (list (read-string (if current-prefix-arg
7277                           "Exclude author (regexp): "
7278                         "Limit to author (regexp): "))
7279          current-prefix-arg))
7280   (gnus-summary-limit-to-subject from "from" not-matching))
7281
7282 (defun gnus-summary-limit-to-age (age &optional younger-p)
7283   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7284 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7285 articles that are younger than AGE days."
7286   (interactive
7287    (let ((younger current-prefix-arg)
7288          (days-got nil)
7289          days)
7290      (while (not days-got)
7291        (setq days (if younger
7292                       (read-string "Limit to articles within (in days): ")
7293                     (read-string "Limit to articles older than (in days): ")))
7294        (when (> (length days) 0)
7295          (setq days (read days)))
7296        (if (numberp days)
7297            (progn
7298              (setq days-got t)
7299              (if (< days 0)
7300                  (progn
7301                    (setq younger (not younger))
7302                    (setq days (* days -1)))))
7303          (message "Please enter a number.")
7304          (sleep-for 1)))
7305      (list days younger)))
7306   (prog1
7307       (let ((data gnus-newsgroup-data)
7308             (cutoff (days-to-time age))
7309             articles d date is-younger)
7310         (while (setq d (pop data))
7311           (when (and (vectorp (gnus-data-header d))
7312                      (setq date (mail-header-date (gnus-data-header d))))
7313             (setq is-younger (time-less-p
7314                               (time-since (condition-case ()
7315                                               (date-to-time date)
7316                                             (error '(0 0))))
7317                               cutoff))
7318             (when (if younger-p
7319                       is-younger
7320                     (not is-younger))
7321               (push (gnus-data-number d) articles))))
7322         (gnus-summary-limit (nreverse articles)))
7323     (gnus-summary-position-point)))
7324
7325 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7326   "Limit the summary buffer to articles that match an 'extra' header."
7327   (interactive
7328    (let ((header
7329           (intern
7330            (gnus-completing-read-with-default
7331             (symbol-name (car gnus-extra-headers))
7332             (if current-prefix-arg
7333                 "Exclude extra header:"
7334               "Limit extra header:")
7335             (mapcar (lambda (x)
7336                       (cons (symbol-name x) x))
7337                     gnus-extra-headers)
7338             nil
7339             t))))
7340      (list header
7341            (read-string (format "%s header %s (regexp): "
7342                                 (if current-prefix-arg "Exclude" "Limit to")
7343                                 header))
7344            current-prefix-arg)))
7345   (when (not (equal "" regexp))
7346     (prog1
7347         (let ((articles (gnus-summary-find-matching
7348                          (cons 'extra header) regexp 'all nil nil
7349                          not-matching)))
7350           (unless articles
7351             (error "Found no matches for \"%s\"" regexp))
7352           (gnus-summary-limit articles))
7353       (gnus-summary-position-point))))
7354
7355 (defun gnus-summary-limit-to-display-predicate ()
7356   "Limit the summary buffer to the predicated in the `display' group parameter."
7357   (interactive)
7358   (unless gnus-newsgroup-display
7359     (error "There is no `display' group parameter"))
7360   (let (articles)
7361     (dolist (number gnus-newsgroup-articles)
7362       (when (funcall gnus-newsgroup-display)
7363         (push number articles)))
7364     (gnus-summary-limit articles))
7365   (gnus-summary-position-point))
7366
7367 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7368 (make-obsolete
7369  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7370
7371 (defun gnus-summary-limit-to-unread (&optional all)
7372   "Limit the summary buffer to articles that are not marked as read.
7373 If ALL is non-nil, limit strictly to unread articles."
7374   (interactive "P")
7375   (if all
7376       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7377     (gnus-summary-limit-to-marks
7378      ;; Concat all the marks that say that an article is read and have
7379      ;; those removed.
7380      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7381            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7382            gnus-low-score-mark gnus-expirable-mark
7383            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7384            gnus-duplicate-mark gnus-souped-mark)
7385      'reverse)))
7386
7387 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7388 (make-obsolete 'gnus-summary-delete-marked-with
7389                'gnus-summary-limit-exclude-marks)
7390
7391 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7392   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7393 If REVERSE, limit the summary buffer to articles that are marked
7394 with MARKS.  MARKS can either be a string of marks or a list of marks.
7395 Returns how many articles were removed."
7396   (interactive "sMarks: ")
7397   (gnus-summary-limit-to-marks marks t))
7398
7399 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7400   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7401 If REVERSE (the prefix), limit the summary buffer to articles that are
7402 not marked with MARKS.  MARKS can either be a string of marks or a
7403 list of marks.
7404 Returns how many articles were removed."
7405   (interactive "sMarks: \nP")
7406   (prog1
7407       (let ((data gnus-newsgroup-data)
7408             (marks (if (listp marks) marks
7409                      (append marks nil))) ; Transform to list.
7410             articles)
7411         (while data
7412           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7413                   (memq (gnus-data-mark (car data)) marks))
7414             (push (gnus-data-number (car data)) articles))
7415           (setq data (cdr data)))
7416         (gnus-summary-limit articles))
7417     (gnus-summary-position-point)))
7418
7419 (defun gnus-summary-limit-to-score (score)
7420   "Limit to articles with score at or above SCORE."
7421   (interactive "NLimit to articles with score of at least: ")
7422   (let ((data gnus-newsgroup-data)
7423         articles)
7424     (while data
7425       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7426                 score)
7427         (push (gnus-data-number (car data)) articles))
7428       (setq data (cdr data)))
7429     (prog1
7430         (gnus-summary-limit articles)
7431       (gnus-summary-position-point))))
7432
7433 (defun gnus-summary-limit-to-unseen ()
7434   "Limit to unseen articles."
7435   (interactive)
7436   (prog1
7437       (gnus-summary-limit gnus-newsgroup-unseen)
7438     (gnus-summary-position-point)))
7439
7440 (defun gnus-summary-limit-include-thread (id)
7441   "Display all the hidden articles that is in the thread with ID in it.
7442 When called interactively, ID is the Message-ID of the current
7443 article."
7444   (interactive (list (mail-header-id (gnus-summary-article-header))))
7445   (let ((articles (gnus-articles-in-thread
7446                    (gnus-id-to-thread (gnus-root-id id)))))
7447     (prog1
7448         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7449       (gnus-summary-limit-include-matching-articles
7450        "subject"
7451        (regexp-quote (gnus-simplify-subject-re
7452                       (mail-header-subject (gnus-id-to-header id)))))
7453       (gnus-summary-position-point))))
7454
7455 (defun gnus-summary-limit-include-matching-articles (header regexp)
7456   "Display all the hidden articles that have HEADERs that match REGEXP."
7457   (interactive (list (read-string "Match on header: ")
7458                      (read-string "Regexp: ")))
7459   (let ((articles (gnus-find-matching-articles header regexp)))
7460     (prog1
7461         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7462       (gnus-summary-position-point))))
7463
7464 (defun gnus-summary-limit-include-dormant ()
7465   "Display all the hidden articles that are marked as dormant.
7466 Note that this command only works on a subset of the articles currently
7467 fetched for this group."
7468   (interactive)
7469   (unless gnus-newsgroup-dormant
7470     (error "There are no dormant articles in this group"))
7471   (prog1
7472       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7473     (gnus-summary-position-point)))
7474
7475 (defun gnus-summary-limit-exclude-dormant ()
7476   "Hide all dormant articles."
7477   (interactive)
7478   (prog1
7479       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7480     (gnus-summary-position-point)))
7481
7482 (defun gnus-summary-limit-exclude-childless-dormant ()
7483   "Hide all dormant articles that have no children."
7484   (interactive)
7485   (let ((data (gnus-data-list t))
7486         articles d children)
7487     ;; Find all articles that are either not dormant or have
7488     ;; children.
7489     (while (setq d (pop data))
7490       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7491                 (and (setq children
7492                            (gnus-article-children (gnus-data-number d)))
7493                      (let (found)
7494                        (while children
7495                          (when (memq (car children) articles)
7496                            (setq children nil
7497                                  found t))
7498                          (pop children))
7499                        found)))
7500         (push (gnus-data-number d) articles)))
7501     ;; Do the limiting.
7502     (prog1
7503         (gnus-summary-limit articles)
7504       (gnus-summary-position-point))))
7505
7506 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7507   "Mark all unread excluded articles as read.
7508 If ALL, mark even excluded ticked and dormants as read."
7509   (interactive "P")
7510   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7511   (let ((articles (gnus-sorted-ndifference
7512                    (sort
7513                     (mapcar (lambda (h) (mail-header-number h))
7514                             gnus-newsgroup-headers)
7515                     '<)
7516                    gnus-newsgroup-limit))
7517         article)
7518     (setq gnus-newsgroup-unreads
7519           (gnus-sorted-intersection gnus-newsgroup-unreads
7520                                     gnus-newsgroup-limit))
7521     (if all
7522         (setq gnus-newsgroup-dormant nil
7523               gnus-newsgroup-marked nil
7524               gnus-newsgroup-reads
7525               (nconc
7526                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7527                gnus-newsgroup-reads))
7528       (while (setq article (pop articles))
7529         (unless (or (memq article gnus-newsgroup-dormant)
7530                     (memq article gnus-newsgroup-marked))
7531           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7532
7533 (defun gnus-summary-limit (articles &optional pop)
7534   (if pop
7535       ;; We pop the previous limit off the stack and use that.
7536       (setq articles (car gnus-newsgroup-limits)
7537             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7538     ;; We use the new limit, so we push the old limit on the stack.
7539     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7540   ;; Set the limit.
7541   (setq gnus-newsgroup-limit articles)
7542   (let ((total (length gnus-newsgroup-data))
7543         (data (gnus-data-find-list (gnus-summary-article-number)))
7544         (gnus-summary-mark-below nil)   ; Inhibit this.
7545         found)
7546     ;; This will do all the work of generating the new summary buffer
7547     ;; according to the new limit.
7548     (gnus-summary-prepare)
7549     ;; Hide any threads, possibly.
7550     (gnus-summary-maybe-hide-threads)
7551     ;; Try to return to the article you were at, or one in the
7552     ;; neighborhood.
7553     (when data
7554       ;; We try to find some article after the current one.
7555       (while data
7556         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7557           (setq data nil
7558                 found t))
7559         (setq data (cdr data))))
7560     (unless found
7561       ;; If there is no data, that means that we were after the last
7562       ;; article.  The same goes when we can't find any articles
7563       ;; after the current one.
7564       (goto-char (point-max))
7565       (gnus-summary-find-prev))
7566     (gnus-set-mode-line 'summary)
7567     ;; We return how many articles were removed from the summary
7568     ;; buffer as a result of the new limit.
7569     (- total (length gnus-newsgroup-data))))
7570
7571 (defsubst gnus-invisible-cut-children (threads)
7572   (let ((num 0))
7573     (while threads
7574       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7575         (incf num))
7576       (pop threads))
7577     (< num 2)))
7578
7579 (defsubst gnus-cut-thread (thread)
7580   "Go forwards in the thread until we find an article that we want to display."
7581   (when (or (eq gnus-fetch-old-headers 'some)
7582             (eq gnus-fetch-old-headers 'invisible)
7583             (numberp gnus-fetch-old-headers)
7584             (eq gnus-build-sparse-threads 'some)
7585             (eq gnus-build-sparse-threads 'more))
7586     ;; Deal with old-fetched headers and sparse threads.
7587     (while (and
7588             thread
7589             (or
7590              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7591              (gnus-summary-article-ancient-p
7592               (mail-header-number (car thread))))
7593             (if (or (<= (length (cdr thread)) 1)
7594                     (eq gnus-fetch-old-headers 'invisible))
7595                 (setq gnus-newsgroup-limit
7596                       (delq (mail-header-number (car thread))
7597                             gnus-newsgroup-limit)
7598                       thread (cadr thread))
7599               (when (gnus-invisible-cut-children (cdr thread))
7600                 (let ((th (cdr thread)))
7601                   (while th
7602                     (if (memq (mail-header-number (caar th))
7603                               gnus-newsgroup-limit)
7604                         (setq thread (car th)
7605                               th nil)
7606                       (setq th (cdr th))))))))))
7607   thread)
7608
7609 (defun gnus-cut-threads (threads)
7610   "Cut off all uninteresting articles from the beginning of threads."
7611   (when (or (eq gnus-fetch-old-headers 'some)
7612             (eq gnus-fetch-old-headers 'invisible)
7613             (numberp gnus-fetch-old-headers)
7614             (eq gnus-build-sparse-threads 'some)
7615             (eq gnus-build-sparse-threads 'more))
7616     (let ((th threads))
7617       (while th
7618         (setcar th (gnus-cut-thread (car th)))
7619         (setq th (cdr th)))))
7620   ;; Remove nixed out threads.
7621   (delq nil threads))
7622
7623 (defun gnus-summary-initial-limit (&optional show-if-empty)
7624   "Figure out what the initial limit is supposed to be on group entry.
7625 This entails weeding out unwanted dormants, low-scored articles,
7626 fetch-old-headers verbiage, and so on."
7627   ;; Most groups have nothing to remove.
7628   (if (or gnus-inhibit-limiting
7629           (and (null gnus-newsgroup-dormant)
7630                (eq gnus-newsgroup-display 'gnus-not-ignore)
7631                (not (eq gnus-fetch-old-headers 'some))
7632                (not (numberp gnus-fetch-old-headers))
7633                (not (eq gnus-fetch-old-headers 'invisible))
7634                (null gnus-summary-expunge-below)
7635                (not (eq gnus-build-sparse-threads 'some))
7636                (not (eq gnus-build-sparse-threads 'more))
7637                (null gnus-thread-expunge-below)
7638                (not gnus-use-nocem)))
7639       ()                                ; Do nothing.
7640     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7641     (setq gnus-newsgroup-limit nil)
7642     (mapatoms
7643      (lambda (node)
7644        (unless (car (symbol-value node))
7645          ;; These threads have no parents -- they are roots.
7646          (let ((nodes (cdr (symbol-value node)))
7647                thread)
7648            (while nodes
7649              (if (and gnus-thread-expunge-below
7650                       (< (gnus-thread-total-score (car nodes))
7651                          gnus-thread-expunge-below))
7652                  (gnus-expunge-thread (pop nodes))
7653                (setq thread (pop nodes))
7654                (gnus-summary-limit-children thread))))))
7655      gnus-newsgroup-dependencies)
7656     ;; If this limitation resulted in an empty group, we might
7657     ;; pop the previous limit and use it instead.
7658     (when (and (not gnus-newsgroup-limit)
7659                show-if-empty)
7660       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7661     gnus-newsgroup-limit))
7662
7663 (defun gnus-summary-limit-children (thread)
7664   "Return 1 if this subthread is visible and 0 if it is not."
7665   ;; First we get the number of visible children to this thread.  This
7666   ;; is done by recursing down the thread using this function, so this
7667   ;; will really go down to a leaf article first, before slowly
7668   ;; working its way up towards the root.
7669   (when thread
7670     (let* ((max-lisp-eval-depth 5000)
7671            (children
7672            (if (cdr thread)
7673                (apply '+ (mapcar 'gnus-summary-limit-children
7674                                  (cdr thread)))
7675              0))
7676           (number (mail-header-number (car thread)))
7677           score)
7678       (if (and
7679            (not (memq number gnus-newsgroup-marked))
7680            (or
7681             ;; If this article is dormant and has absolutely no visible
7682             ;; children, then this article isn't visible.
7683             (and (memq number gnus-newsgroup-dormant)
7684                  (zerop children))
7685             ;; If this is "fetch-old-headered" and there is no
7686             ;; visible children, then we don't want this article.
7687             (and (or (eq gnus-fetch-old-headers 'some)
7688                      (numberp gnus-fetch-old-headers))
7689                  (gnus-summary-article-ancient-p number)
7690                  (zerop children))
7691             ;; If this is "fetch-old-headered" and `invisible', then
7692             ;; we don't want this article.
7693             (and (eq gnus-fetch-old-headers 'invisible)
7694                  (gnus-summary-article-ancient-p number))
7695             ;; If this is a sparsely inserted article with no children,
7696             ;; we don't want it.
7697             (and (eq gnus-build-sparse-threads 'some)
7698                  (gnus-summary-article-sparse-p number)
7699                  (zerop children))
7700             ;; If we use expunging, and this article is really
7701             ;; low-scored, then we don't want this article.
7702             (when (and gnus-summary-expunge-below
7703                        (< (setq score
7704                                 (or (cdr (assq number gnus-newsgroup-scored))
7705                                     gnus-summary-default-score))
7706                           gnus-summary-expunge-below))
7707               ;; We increase the expunge-tally here, but that has
7708               ;; nothing to do with the limits, really.
7709               (incf gnus-newsgroup-expunged-tally)
7710               ;; We also mark as read here, if that's wanted.
7711               (when (and gnus-summary-mark-below
7712                          (< score gnus-summary-mark-below))
7713                 (setq gnus-newsgroup-unreads
7714                       (delq number gnus-newsgroup-unreads))
7715                 (if gnus-newsgroup-auto-expire
7716                     (push number gnus-newsgroup-expirable)
7717                   (push (cons number gnus-low-score-mark)
7718                         gnus-newsgroup-reads)))
7719               t)
7720             ;; Do the `display' group parameter.
7721             (and gnus-newsgroup-display
7722                  (not (funcall gnus-newsgroup-display)))
7723             ;; Check NoCeM things.
7724             (if (and gnus-use-nocem
7725                      (gnus-nocem-unwanted-article-p
7726                       (mail-header-id (car thread))))
7727                 (progn
7728                   (setq gnus-newsgroup-unreads
7729                         (delq number gnus-newsgroup-unreads))
7730                   t))))
7731           ;; Nope, invisible article.
7732           0
7733         ;; Ok, this article is to be visible, so we add it to the limit
7734         ;; and return 1.
7735         (push number gnus-newsgroup-limit)
7736         1))))
7737
7738 (defun gnus-expunge-thread (thread)
7739   "Mark all articles in THREAD as read."
7740   (let* ((number (mail-header-number (car thread))))
7741     (incf gnus-newsgroup-expunged-tally)
7742     ;; We also mark as read here, if that's wanted.
7743     (setq gnus-newsgroup-unreads
7744           (delq number gnus-newsgroup-unreads))
7745     (if gnus-newsgroup-auto-expire
7746         (push number gnus-newsgroup-expirable)
7747       (push (cons number gnus-low-score-mark)
7748             gnus-newsgroup-reads)))
7749   ;; Go recursively through all subthreads.
7750   (mapcar 'gnus-expunge-thread (cdr thread)))
7751
7752 ;; Summary article oriented commands
7753
7754 (defun gnus-summary-refer-parent-article (n)
7755   "Refer parent article N times.
7756 If N is negative, go to ancestor -N instead.
7757 The difference between N and the number of articles fetched is returned."
7758   (interactive "p")
7759   (let ((skip 1)
7760         error header ref)
7761     (when (not (natnump n))
7762       (setq skip (abs n)
7763             n 1))
7764     (while (and (> n 0)
7765                 (not error))
7766       (setq header (gnus-summary-article-header))
7767       (if (and (eq (mail-header-number header)
7768                    (cdr gnus-article-current))
7769                (equal gnus-newsgroup-name
7770                       (car gnus-article-current)))
7771           ;; If we try to find the parent of the currently
7772           ;; displayed article, then we take a look at the actual
7773           ;; References header, since this is slightly more
7774           ;; reliable than the References field we got from the
7775           ;; server.
7776           (save-excursion
7777             (set-buffer gnus-original-article-buffer)
7778             (nnheader-narrow-to-headers)
7779             (unless (setq ref (message-fetch-field "references"))
7780               (setq ref (message-fetch-field "in-reply-to")))
7781             (widen))
7782         (setq ref
7783               ;; It's not the current article, so we take a bet on
7784               ;; the value we got from the server.
7785               (mail-header-references header)))
7786       (if (and ref
7787                (not (equal ref "")))
7788           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7789             (gnus-message 1 "Couldn't find parent"))
7790         (gnus-message 1 "No references in article %d"
7791                       (gnus-summary-article-number))
7792         (setq error t))
7793       (decf n))
7794     (gnus-summary-position-point)
7795     n))
7796
7797 (defun gnus-summary-refer-references ()
7798   "Fetch all articles mentioned in the References header.
7799 Return the number of articles fetched."
7800   (interactive)
7801   (let ((ref (mail-header-references (gnus-summary-article-header)))
7802         (current (gnus-summary-article-number))
7803         (n 0))
7804     (if (or (not ref)
7805             (equal ref ""))
7806         (error "No References in the current article")
7807       ;; For each Message-ID in the References header...
7808       (while (string-match "<[^>]*>" ref)
7809         (incf n)
7810         ;; ... fetch that article.
7811         (gnus-summary-refer-article
7812          (prog1 (match-string 0 ref)
7813            (setq ref (substring ref (match-end 0))))))
7814       (gnus-summary-goto-subject current)
7815       (gnus-summary-position-point)
7816       n)))
7817
7818 (defun gnus-summary-refer-thread (&optional limit)
7819   "Fetch all articles in the current thread.
7820 If LIMIT (the numerical prefix), fetch that many old headers instead
7821 of what's specified by the `gnus-refer-thread-limit' variable."
7822   (interactive "P")
7823   (let ((id (mail-header-id (gnus-summary-article-header)))
7824         (limit (if limit (prefix-numeric-value limit)
7825                  gnus-refer-thread-limit)))
7826     ;; We want to fetch LIMIT *old* headers, but we also have to
7827     ;; re-fetch all the headers in the current buffer, because many of
7828     ;; them may be undisplayed.  So we adjust LIMIT.
7829     (when (numberp limit)
7830       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7831     (unless (eq gnus-fetch-old-headers 'invisible)
7832       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7833       ;; Retrieve the headers and read them in.
7834       (if (eq (gnus-retrieve-headers
7835                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7836               'nov)
7837           (gnus-build-all-threads)
7838         (error "Can't fetch thread from backends that don't support NOV"))
7839       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7840     (gnus-summary-limit-include-thread id)))
7841
7842 (defun gnus-summary-refer-article (message-id)
7843   "Fetch an article specified by MESSAGE-ID."
7844   (interactive "sMessage-ID: ")
7845   (when (and (stringp message-id)
7846              (not (zerop (length message-id))))
7847     ;; Construct the correct Message-ID if necessary.
7848     ;; Suggested by tale@pawl.rpi.edu.
7849     (unless (string-match "^<" message-id)
7850       (setq message-id (concat "<" message-id)))
7851     (unless (string-match ">$" message-id)
7852       (setq message-id (concat message-id ">")))
7853     (let* ((header (gnus-id-to-header message-id))
7854            (sparse (and header
7855                         (gnus-summary-article-sparse-p
7856                          (mail-header-number header))
7857                         (memq (mail-header-number header)
7858                               gnus-newsgroup-limit)))
7859            number)
7860       (cond
7861        ;; If the article is present in the buffer we just go to it.
7862        ((and header
7863              (or (not (gnus-summary-article-sparse-p
7864                        (mail-header-number header)))
7865                  sparse))
7866         (prog1
7867             (gnus-summary-goto-article
7868              (mail-header-number header) nil t)
7869           (when sparse
7870             (gnus-summary-update-article (mail-header-number header)))))
7871        (t
7872         ;; We fetch the article.
7873         (catch 'found
7874           (dolist (gnus-override-method (gnus-refer-article-methods))
7875             (gnus-check-server gnus-override-method)
7876             ;; Fetch the header, and display the article.
7877             (when (setq number (gnus-summary-insert-subject message-id))
7878               (gnus-summary-select-article nil nil nil number)
7879               (throw 'found t)))
7880           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7881
7882 (defun gnus-refer-article-methods ()
7883   "Return a list of referable methods."
7884   (cond
7885    ;; No method, so we default to current and native.
7886    ((null gnus-refer-article-method)
7887     (list gnus-current-select-method gnus-select-method))
7888    ;; Current.
7889    ((eq 'current gnus-refer-article-method)
7890     (list gnus-current-select-method))
7891    ;; List of select methods.
7892    ((not (and (symbolp (car gnus-refer-article-method))
7893               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7894     (let (out)
7895       (dolist (method gnus-refer-article-method)
7896         (push (if (eq 'current method)
7897                   gnus-current-select-method
7898                 method)
7899               out))
7900       (nreverse out)))
7901    ;; One single select method.
7902    (t
7903     (list gnus-refer-article-method))))
7904
7905 (defun gnus-summary-edit-parameters ()
7906   "Edit the group parameters of the current group."
7907   (interactive)
7908   (gnus-group-edit-group gnus-newsgroup-name 'params))
7909
7910 (defun gnus-summary-customize-parameters ()
7911   "Customize the group parameters of the current group."
7912   (interactive)
7913   (gnus-group-customize gnus-newsgroup-name))
7914
7915 (defun gnus-summary-enter-digest-group (&optional force)
7916   "Enter an nndoc group based on the current article.
7917 If FORCE, force a digest interpretation.  If not, try
7918 to guess what the document format is."
7919   (interactive "P")
7920   (let ((conf gnus-current-window-configuration))
7921     (save-excursion
7922       (gnus-summary-select-article))
7923     (setq gnus-current-window-configuration conf)
7924     (let* ((name (format "%s-%d"
7925                          (gnus-group-prefixed-name
7926                           gnus-newsgroup-name (list 'nndoc ""))
7927                          (save-excursion
7928                            (set-buffer gnus-summary-buffer)
7929                            gnus-current-article)))
7930            (ogroup gnus-newsgroup-name)
7931            (params (append (gnus-info-params (gnus-get-info ogroup))
7932                            (list (cons 'to-group ogroup))
7933                            (list (cons 'save-article-group ogroup))))
7934            (case-fold-search t)
7935            (buf (current-buffer))
7936            dig to-address)
7937       (save-excursion
7938         (set-buffer gnus-original-article-buffer)
7939         ;; Have the digest group inherit the main mail address of
7940         ;; the parent article.
7941         (when (setq to-address (or (gnus-fetch-field "reply-to")
7942                                    (gnus-fetch-field "from")))
7943           (setq params (append
7944                         (list (cons 'to-address
7945                                     (funcall gnus-decode-encoded-word-function
7946                                              to-address))))))
7947         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7948         (insert-buffer-substring gnus-original-article-buffer)
7949         ;; Remove lines that may lead nndoc to misinterpret the
7950         ;; document type.
7951         (narrow-to-region
7952          (goto-char (point-min))
7953          (or (search-forward "\n\n" nil t) (point)))
7954         (goto-char (point-min))
7955         (delete-matching-lines "^Path:\\|^From ")
7956         (widen))
7957       (unwind-protect
7958           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7959                     (gnus-newsgroup-ephemeral-ignored-charsets
7960                      gnus-newsgroup-ignored-charsets))
7961                 (gnus-group-read-ephemeral-group
7962                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7963                               (nndoc-article-type
7964                                ,(if force 'mbox 'guess)))
7965                  t nil nil nil
7966                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7967                                                         "ADAPT")))))
7968               ;; Make all postings to this group go to the parent group.
7969               (nconc (gnus-info-params (gnus-get-info name))
7970                      params)
7971             ;; Couldn't select this doc group.
7972             (switch-to-buffer buf)
7973             (gnus-set-global-variables)
7974             (gnus-configure-windows 'summary)
7975             (gnus-message 3 "Article couldn't be entered?"))
7976         (kill-buffer dig)))))
7977
7978 (defun gnus-summary-read-document (n)
7979   "Open a new group based on the current article(s).
7980 This will allow you to read digests and other similar
7981 documents as newsgroups.
7982 Obeys the standard process/prefix convention."
7983   (interactive "P")
7984   (let* ((articles (gnus-summary-work-articles n))
7985          (ogroup gnus-newsgroup-name)
7986          (params (append (gnus-info-params (gnus-get-info ogroup))
7987                          (list (cons 'to-group ogroup))))
7988          article group egroup groups vgroup)
7989     (while (setq article (pop articles))
7990       (setq group (format "%s-%d" gnus-newsgroup-name article))
7991       (gnus-summary-remove-process-mark article)
7992       (when (gnus-summary-display-article article)
7993         (save-excursion
7994           (with-temp-buffer
7995             (insert-buffer-substring gnus-original-article-buffer)
7996             ;; Remove some headers that may lead nndoc to make
7997             ;; the wrong guess.
7998             (message-narrow-to-head)
7999             (goto-char (point-min))
8000             (delete-matching-lines "^\\(Path\\):\\|^From ")
8001             (widen)
8002             (if (setq egroup
8003                       (gnus-group-read-ephemeral-group
8004                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8005                                      (nndoc-article-type guess))
8006                        t nil t))
8007                 (progn
8008             ;; Make all postings to this group go to the parent group.
8009                   (nconc (gnus-info-params (gnus-get-info egroup))
8010                          params)
8011                   (push egroup groups))
8012               ;; Couldn't select this doc group.
8013               (gnus-error 3 "Article couldn't be entered"))))))
8014     ;; Now we have selected all the documents.
8015     (cond
8016      ((not groups)
8017       (error "None of the articles could be interpreted as documents"))
8018      ((gnus-group-read-ephemeral-group
8019        (setq vgroup (format
8020                      "nnvirtual:%s-%s" gnus-newsgroup-name
8021                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8022        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8023        t
8024        (cons (current-buffer) 'summary)))
8025      (t
8026       (error "Couldn't select virtual nndoc group")))))
8027
8028 (defun gnus-summary-isearch-article (&optional regexp-p)
8029   "Do incremental search forward on the current article.
8030 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8031   (interactive "P")
8032   (gnus-summary-select-article)
8033   (gnus-configure-windows 'article)
8034   (gnus-eval-in-buffer-window gnus-article-buffer
8035     (save-restriction
8036       (widen)
8037       (isearch-forward regexp-p))))
8038
8039 (defun gnus-summary-search-article-forward (regexp &optional backward)
8040   "Search for an article containing REGEXP forward.
8041 If BACKWARD, search backward instead."
8042   (interactive
8043    (list (read-string
8044           (format "Search article %s (regexp%s): "
8045                   (if current-prefix-arg "backward" "forward")
8046                   (if gnus-last-search-regexp
8047                       (concat ", default " gnus-last-search-regexp)
8048                     "")))
8049          current-prefix-arg))
8050   (if (string-equal regexp "")
8051       (setq regexp (or gnus-last-search-regexp ""))
8052     (setq gnus-last-search-regexp regexp)
8053     (setq gnus-article-before-search gnus-current-article))
8054   ;; Intentionally set gnus-last-article.
8055   (setq gnus-last-article gnus-article-before-search)
8056   (let ((gnus-last-article gnus-last-article))
8057     (if (gnus-summary-search-article regexp backward)
8058         (gnus-summary-show-thread)
8059       (error "Search failed: \"%s\"" regexp))))
8060
8061 (defun gnus-summary-search-article-backward (regexp)
8062   "Search for an article containing REGEXP backward."
8063   (interactive
8064    (list (read-string
8065           (format "Search article backward (regexp%s): "
8066                   (if gnus-last-search-regexp
8067                       (concat ", default " gnus-last-search-regexp)
8068                     "")))))
8069   (gnus-summary-search-article-forward regexp 'backward))
8070
8071 (defun gnus-summary-search-article (regexp &optional backward)
8072   "Search for an article containing REGEXP.
8073 Optional argument BACKWARD means do search for backward.
8074 `gnus-select-article-hook' is not called during the search."
8075   ;; We have to require this here to make sure that the following
8076   ;; dynamic binding isn't shadowed by autoloading.
8077   (require 'gnus-async)
8078   (require 'gnus-art)
8079   (let ((gnus-select-article-hook nil)  ;Disable hook.
8080         (gnus-article-prepare-hook nil)
8081         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8082         (gnus-use-article-prefetch nil)
8083         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8084         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8085         (sum (current-buffer))
8086         (gnus-display-mime-function nil)
8087         (found nil)
8088         point)
8089     (gnus-save-hidden-threads
8090       (gnus-summary-select-article)
8091       (set-buffer gnus-article-buffer)
8092       (goto-char (window-point (get-buffer-window (current-buffer))))
8093       (when backward
8094         (forward-line -1))
8095       (while (not found)
8096         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8097         (if (if backward
8098                 (re-search-backward regexp nil t)
8099               (re-search-forward regexp nil t))
8100             ;; We found the regexp.
8101             (progn
8102               (setq found 'found)
8103               (beginning-of-line)
8104               (set-window-start
8105                (get-buffer-window (current-buffer))
8106                (point))
8107               (forward-line 1)
8108               (set-window-point
8109                (get-buffer-window (current-buffer))
8110                (point))
8111               (set-buffer sum)
8112               (setq point (point)))
8113           ;; We didn't find it, so we go to the next article.
8114           (set-buffer sum)
8115           (setq found 'not)
8116           (while (eq found 'not)
8117             (if (not (if backward (gnus-summary-find-prev)
8118                        (gnus-summary-find-next)))
8119                 ;; No more articles.
8120                 (setq found t)
8121               ;; Select the next article and adjust point.
8122               (unless (gnus-summary-article-sparse-p
8123                        (gnus-summary-article-number))
8124                 (setq found nil)
8125                 (gnus-summary-select-article)
8126                 (set-buffer gnus-article-buffer)
8127                 (widen)
8128                 (goto-char (if backward (point-max) (point-min))))))))
8129       (gnus-message 7 ""))
8130     ;; Return whether we found the regexp.
8131     (when (eq found 'found)
8132       (goto-char point)
8133       (gnus-summary-show-thread)
8134       (gnus-summary-goto-subject gnus-current-article)
8135       (gnus-summary-position-point)
8136       t)))
8137
8138 (defun gnus-find-matching-articles (header regexp)
8139   "Return a list of all articles that match REGEXP on HEADER.
8140 This search includes all articles in the current group that Gnus has
8141 fetched headers for, whether they are displayed or not."
8142   (let ((articles nil)
8143         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8144         (case-fold-search t))
8145     (dolist (header gnus-newsgroup-headers)
8146       (when (string-match regexp (funcall func header))
8147         (push (mail-header-number header) articles)))
8148     (nreverse articles)))
8149
8150 (defun gnus-summary-find-matching (header regexp &optional backward unread
8151                                           not-case-fold not-matching)
8152   "Return a list of all articles that match REGEXP on HEADER.
8153 The search stars on the current article and goes forwards unless
8154 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8155 If UNREAD is non-nil, only unread articles will
8156 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8157 in the comparisons. If NOT-MATCHING, return a list of all articles that
8158 not match REGEXP on HEADER."
8159   (let ((case-fold-search (not not-case-fold))
8160         articles d func)
8161     (if (consp header)
8162         (if (eq (car header) 'extra)
8163             (setq func
8164                   `(lambda (h)
8165                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8166                          "")))
8167           (error "%s is an invalid header" header))
8168       (unless (fboundp (intern (concat "mail-header-" header)))
8169         (error "%s is not a valid header" header))
8170       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8171     (dolist (d (if (eq backward 'all)
8172                    gnus-newsgroup-data
8173                  (gnus-data-find-list
8174                   (gnus-summary-article-number)
8175                   (gnus-data-list backward))))
8176       (when (and (or (not unread)       ; We want all articles...
8177                      (gnus-data-unread-p d)) ; Or just unreads.
8178                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8179                  (if not-matching
8180                      (not (string-match
8181                            regexp
8182                            (funcall func (gnus-data-header d))))
8183                    (string-match regexp
8184                                  (funcall func (gnus-data-header d)))))
8185         (push (gnus-data-number d) articles))) ; Success!
8186     (nreverse articles)))
8187
8188 (defun gnus-summary-execute-command (header regexp command &optional backward)
8189   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8190 If HEADER is an empty string (or nil), the match is done on the entire
8191 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8192   (interactive
8193    (list (let ((completion-ignore-case t))
8194            (completing-read
8195             "Header name: "
8196             (mapcar (lambda (header) (list (format "%s" header)))
8197                     (append
8198                      '("Number" "Subject" "From" "Lines" "Date"
8199                        "Message-ID" "Xref" "References" "Body")
8200                      gnus-extra-headers))
8201             nil 'require-match))
8202          (read-string "Regexp: ")
8203          (read-key-sequence "Command: ")
8204          current-prefix-arg))
8205   (when (equal header "Body")
8206     (setq header ""))
8207   ;; Hidden thread subtrees must be searched as well.
8208   (gnus-summary-show-all-threads)
8209   ;; We don't want to change current point nor window configuration.
8210   (save-excursion
8211     (save-window-excursion
8212       (let (gnus-visual
8213             gnus-treat-strip-trailing-blank-lines
8214             gnus-treat-strip-leading-blank-lines
8215             gnus-treat-strip-multiple-blank-lines
8216             gnus-treat-hide-boring-headers
8217             gnus-treat-fold-newsgroups
8218             gnus-article-prepare-hook)
8219         (gnus-message 6 "Executing %s..." (key-description command))
8220         ;; We'd like to execute COMMAND interactively so as to give arguments.
8221         (gnus-execute header regexp
8222                       `(call-interactively ',(key-binding command))
8223                       backward)
8224         (gnus-message 6 "Executing %s...done" (key-description command))))))
8225
8226 (defun gnus-summary-beginning-of-article ()
8227   "Scroll the article back to the beginning."
8228   (interactive)
8229   (gnus-summary-select-article)
8230   (gnus-configure-windows 'article)
8231   (gnus-eval-in-buffer-window gnus-article-buffer
8232     (widen)
8233     (goto-char (point-min))
8234     (when gnus-page-broken
8235       (gnus-narrow-to-page))))
8236
8237 (defun gnus-summary-end-of-article ()
8238   "Scroll to the end of the article."
8239   (interactive)
8240   (gnus-summary-select-article)
8241   (gnus-configure-windows 'article)
8242   (gnus-eval-in-buffer-window gnus-article-buffer
8243     (widen)
8244     (goto-char (point-max))
8245     (recenter -3)
8246     (when gnus-page-broken
8247       (gnus-narrow-to-page))))
8248
8249 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8250   "Truncate to LEN and quote all \"(\"'s in STRING."
8251   (gnus-replace-in-string (if (and len (> (length string) len))
8252                               (substring string 0 len)
8253                             string)
8254                           "[()]" "\\\\\\&"))
8255
8256 (defun gnus-summary-print-article (&optional filename n)
8257   "Generate and print a PostScript image of the N next (mail) articles.
8258
8259 If N is negative, print the N previous articles.  If N is nil and articles
8260 have been marked with the process mark, print these instead.
8261
8262 If the optional first argument FILENAME is nil, send the image to the
8263 printer.  If FILENAME is a string, save the PostScript image in a file with
8264 that name.  If FILENAME is a number, prompt the user for the name of the file
8265 to save in."
8266   (interactive (list (ps-print-preprint current-prefix-arg)))
8267   (dolist (article (gnus-summary-work-articles n))
8268     (gnus-summary-select-article nil nil 'pseudo article)
8269     (gnus-eval-in-buffer-window gnus-article-buffer
8270       (gnus-print-buffer))
8271     (gnus-summary-remove-process-mark article))
8272   (ps-despool filename))
8273
8274 (defun gnus-print-buffer ()
8275   (let ((buffer (generate-new-buffer " *print*")))
8276     (unwind-protect
8277         (progn
8278           (copy-to-buffer buffer (point-min) (point-max))
8279           (set-buffer buffer)
8280           (gnus-article-delete-invisible-text)
8281           (gnus-remove-text-with-property 'gnus-decoration)
8282           (when (gnus-visual-p 'article-highlight 'highlight)
8283             ;; Copy-to-buffer doesn't copy overlay.  So redo
8284             ;; highlight.
8285             (let ((gnus-article-buffer buffer))
8286               (gnus-article-highlight-citation t)
8287               (gnus-article-highlight-signature)))
8288           (let ((ps-left-header
8289                  (list
8290                   (concat "("
8291                           (gnus-summary-print-truncate-and-quote
8292                            (mail-header-subject gnus-current-headers)
8293                            66) ")")
8294                   (concat "("
8295                           (gnus-summary-print-truncate-and-quote
8296                            (mail-header-from gnus-current-headers)
8297                            45) ")")))
8298                 (ps-right-header
8299                  (list
8300                   "/pagenumberstring load"
8301                   (concat "("
8302                           (mail-header-date gnus-current-headers) ")"))))
8303             (gnus-run-hooks 'gnus-ps-print-hook)
8304             (save-excursion
8305               (if window-system
8306                   (ps-spool-buffer-with-faces)
8307                 (ps-spool-buffer)))))
8308       (kill-buffer buffer))))
8309
8310 (defun gnus-summary-show-article (&optional arg)
8311   "Force redisplaying of the current article.
8312 If ARG (the prefix) is a number, show the article with the charset
8313 defined in `gnus-summary-show-article-charset-alist', or the charset
8314 input.
8315 If ARG (the prefix) is non-nil and not a number, show the raw article
8316 without any article massaging functions being run.  Normally, the key strokes
8317 are `C-u g'."
8318   (interactive "P")
8319   (cond
8320    ((numberp arg)
8321     (gnus-summary-show-article t)
8322     (let ((gnus-newsgroup-charset
8323            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8324                (mm-read-coding-system
8325                 "View as charset: " ;; actually it is coding system.
8326                 (save-excursion
8327                   (set-buffer gnus-article-buffer)
8328                   (mm-detect-coding-region (point) (point-max))))))
8329           (gnus-newsgroup-ignored-charsets 'gnus-all))
8330       (gnus-summary-select-article nil 'force)
8331       (let ((deps gnus-newsgroup-dependencies)
8332             head header lines)
8333         (save-excursion
8334           (set-buffer gnus-original-article-buffer)
8335           (save-restriction
8336             (message-narrow-to-head)
8337             (setq head (buffer-string))
8338             (goto-char (point-min))
8339             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8340               (goto-char (point-max))
8341               (widen)
8342               (setq lines (1- (count-lines (point) (point-max))))))
8343           (with-temp-buffer
8344             (insert (format "211 %d Article retrieved.\n"
8345                             (cdr gnus-article-current)))
8346             (insert head)
8347             (if lines (insert (format "Lines: %d\n" lines)))
8348             (insert ".\n")
8349             (let ((nntp-server-buffer (current-buffer)))
8350               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8351         (gnus-data-set-header
8352          (gnus-data-find (cdr gnus-article-current))
8353          header)
8354         (gnus-summary-update-article-line
8355          (cdr gnus-article-current) header)
8356         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8357           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8358    ((not arg)
8359     ;; Select the article the normal way.
8360     (gnus-summary-select-article nil 'force))
8361    (t
8362     ;; We have to require this here to make sure that the following
8363     ;; dynamic binding isn't shadowed by autoloading.
8364     (require 'gnus-async)
8365     (require 'gnus-art)
8366     ;; Bind the article treatment functions to nil.
8367     (let ((gnus-have-all-headers t)
8368           gnus-article-prepare-hook
8369           gnus-article-decode-hook
8370           gnus-display-mime-function
8371           gnus-break-pages)
8372       ;; Destroy any MIME parts.
8373       (when (gnus-buffer-live-p gnus-article-buffer)
8374         (save-excursion
8375           (set-buffer gnus-article-buffer)
8376           (mm-destroy-parts gnus-article-mime-handles)
8377           ;; Set it to nil for safety reason.
8378           (setq gnus-article-mime-handle-alist nil)
8379           (setq gnus-article-mime-handles nil)))
8380       (gnus-summary-select-article nil 'force))))
8381   (gnus-summary-goto-subject gnus-current-article)
8382   (gnus-summary-position-point))
8383
8384 (defun gnus-summary-show-raw-article ()
8385   "Show the raw article without any article massaging functions being run."
8386   (interactive)
8387   (gnus-summary-show-article t))
8388
8389 (defun gnus-summary-verbose-headers (&optional arg)
8390   "Toggle permanent full header display.
8391 If ARG is a positive number, turn header display on.
8392 If ARG is a negative number, turn header display off."
8393   (interactive "P")
8394   (setq gnus-show-all-headers
8395         (cond ((or (not (numberp arg))
8396                    (zerop arg))
8397                (not gnus-show-all-headers))
8398               ((natnump arg)
8399                t)))
8400   (gnus-summary-show-article))
8401
8402 (defun gnus-summary-toggle-header (&optional arg)
8403   "Show the headers if they are hidden, or hide them if they are shown.
8404 If ARG is a positive number, show the entire header.
8405 If ARG is a negative number, hide the unwanted header lines."
8406   (interactive "P")
8407   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8408                      (get-buffer-window gnus-article-buffer t))))
8409     (with-current-buffer gnus-article-buffer
8410       (widen)
8411       (article-narrow-to-head)
8412       (let* ((buffer-read-only nil)
8413              (inhibit-point-motion-hooks t)
8414              (hidden (if (numberp arg)
8415                          (>= arg 0)
8416                        (gnus-article-hidden-text-p 'headers)))
8417              s e)
8418         (delete-region (point-min) (point-max))
8419         (with-current-buffer gnus-original-article-buffer
8420           (goto-char (setq s (point-min)))
8421           (setq e (if (search-forward "\n\n" nil t)
8422                       (1- (point))
8423                     (point-max))))
8424         (insert-buffer-substring gnus-original-article-buffer s e)
8425         (article-decode-encoded-words)
8426         (if hidden
8427             (let ((gnus-treat-hide-headers nil)
8428                   (gnus-treat-hide-boring-headers nil))
8429               (gnus-delete-wash-type 'headers)
8430               (gnus-treat-article 'head))
8431           (gnus-treat-article 'head))
8432         (widen)
8433         (if window
8434             (set-window-start window (goto-char (point-min))))
8435         (setq gnus-page-broken
8436               (when gnus-break-pages
8437                 (gnus-narrow-to-page)
8438                 t))
8439         (gnus-set-mode-line 'article)))))
8440
8441 (defun gnus-summary-show-all-headers ()
8442   "Make all header lines visible."
8443   (interactive)
8444   (gnus-summary-toggle-header 1))
8445
8446 (defun gnus-summary-caesar-message (&optional arg)
8447   "Caesar rotate the current article by 13.
8448 The numerical prefix specifies how many places to rotate each letter
8449 forward."
8450   (interactive "P")
8451   (gnus-summary-select-article)
8452   (let ((mail-header-separator ""))
8453     (gnus-eval-in-buffer-window gnus-article-buffer
8454       (save-restriction
8455         (widen)
8456         (let ((start (window-start))
8457               buffer-read-only)
8458           (message-caesar-buffer-body arg)
8459           (set-window-start (get-buffer-window (current-buffer)) start))))))
8460
8461 (autoload 'unmorse-region "morse"
8462   "Convert morse coded text in region to ordinary ASCII text."
8463   t)
8464
8465 (defun gnus-summary-morse-message (&optional arg)
8466   "Morse decode the current article."
8467   (interactive "P")
8468   (gnus-summary-select-article)
8469   (let ((mail-header-separator ""))
8470     (gnus-eval-in-buffer-window gnus-article-buffer
8471       (save-excursion
8472         (save-restriction
8473           (widen)
8474           (let ((pos (window-start))
8475                 buffer-read-only)
8476             (goto-char (point-min))
8477             (when (message-goto-body)
8478               (gnus-narrow-to-body))
8479             (goto-char (point-min))
8480             (while (re-search-forward "·" (point-max) t)
8481               (replace-match "."))
8482             (unmorse-region (point-min) (point-max))
8483             (widen)
8484             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8485
8486 (defun gnus-summary-stop-page-breaking ()
8487   "Stop page breaking in the current article."
8488   (interactive)
8489   (gnus-summary-select-article)
8490   (gnus-eval-in-buffer-window gnus-article-buffer
8491     (widen)
8492     (when (gnus-visual-p 'page-marker)
8493       (let ((buffer-read-only nil))
8494         (gnus-remove-text-with-property 'gnus-prev)
8495         (gnus-remove-text-with-property 'gnus-next))
8496       (setq gnus-page-broken nil))))
8497
8498 (defun gnus-summary-move-article (&optional n to-newsgroup
8499                                             select-method action)
8500   "Move the current article to a different newsgroup.
8501 If N is a positive number, move the N next articles.
8502 If N is a negative number, move the N previous articles.
8503 If N is nil and any articles have been marked with the process mark,
8504 move those articles instead.
8505 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8506 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8507 re-spool using this method.
8508
8509 When called interactively with TO-NEWSGROUP being nil, the value of
8510 the variable `gnus-move-split-methods' is used for finding a default
8511 for the target newsgroup.
8512
8513 For this function to work, both the current newsgroup and the
8514 newsgroup that you want to move to have to support the `request-move'
8515 and `request-accept' functions.
8516
8517 ACTION can be either `move' (the default), `crosspost' or `copy'."
8518   (interactive "P")
8519   (unless action
8520     (setq action 'move))
8521   ;; Check whether the source group supports the required functions.
8522   (cond ((and (eq action 'move)
8523               (not (gnus-check-backend-function
8524                     'request-move-article gnus-newsgroup-name)))
8525          (error "The current group does not support article moving"))
8526         ((and (eq action 'crosspost)
8527               (not (gnus-check-backend-function
8528                     'request-replace-article gnus-newsgroup-name)))
8529          (error "The current group does not support article editing")))
8530   (let ((articles (gnus-summary-work-articles n))
8531         (prefix (if (gnus-check-backend-function
8532                      'request-move-article gnus-newsgroup-name)
8533                     (gnus-group-real-prefix gnus-newsgroup-name)
8534                   ""))
8535         (names '((move "Move" "Moving")
8536                  (copy "Copy" "Copying")
8537                  (crosspost "Crosspost" "Crossposting")))
8538         (copy-buf (save-excursion
8539                     (nnheader-set-temp-buffer " *copy article*")))
8540         art-group to-method new-xref article to-groups)
8541     (unless (assq action names)
8542       (error "Unknown action %s" action))
8543     ;; Read the newsgroup name.
8544     (when (and (not to-newsgroup)
8545                (not select-method))
8546       (if (and gnus-move-split-methods
8547                (not
8548                 (and (memq gnus-current-article articles)
8549                      (gnus-buffer-live-p gnus-original-article-buffer))))
8550           ;; When `gnus-move-split-methods' is non-nil, we have to
8551           ;; select an article to give `gnus-read-move-group-name' an
8552           ;; opportunity to suggest an appropriate default.  However,
8553           ;; we needn't render or mark the article.
8554           (let ((gnus-display-mime-function nil)
8555                 (gnus-article-prepare-hook nil)
8556                 (gnus-mark-article-hook nil))
8557             (gnus-summary-select-article nil nil nil (car articles))))
8558       (setq to-newsgroup
8559             (gnus-read-move-group-name
8560              (cadr (assq action names))
8561              (symbol-value (intern (format "gnus-current-%s-group" action)))
8562              articles prefix))
8563       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8564     (setq to-method (or select-method
8565                         (gnus-server-to-method
8566                          (gnus-group-method to-newsgroup))))
8567     ;; Check the method we are to move this article to...
8568     (unless (gnus-check-backend-function
8569              'request-accept-article (car to-method))
8570       (error "%s does not support article copying" (car to-method)))
8571     (unless (gnus-check-server to-method)
8572       (error "Can't open server %s" (car to-method)))
8573     (gnus-message 6 "%s to %s: %s..."
8574                   (caddr (assq action names))
8575                   (or (car select-method) to-newsgroup) articles)
8576     (while articles
8577       (setq article (pop articles))
8578       (setq
8579        art-group
8580        (cond
8581         ;; Move the article.
8582         ((eq action 'move)
8583          ;; Remove this article from future suppression.
8584          (gnus-dup-unsuppress-article article)
8585          (gnus-request-move-article
8586           article                       ; Article to move
8587           gnus-newsgroup-name           ; From newsgroup
8588           (nth 1 (gnus-find-method-for-group
8589                   gnus-newsgroup-name)) ; Server
8590           (list 'gnus-request-accept-article
8591                 to-newsgroup (list 'quote select-method)
8592                 (not articles) t)       ; Accept form
8593           (not articles)))              ; Only save nov last time
8594         ;; Copy the article.
8595         ((eq action 'copy)
8596          (save-excursion
8597            (set-buffer copy-buf)
8598            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8599              (gnus-request-accept-article
8600               to-newsgroup select-method (not articles) t))))
8601         ;; Crosspost the article.
8602         ((eq action 'crosspost)
8603          (let ((xref (message-tokenize-header
8604                       (mail-header-xref (gnus-summary-article-header article))
8605                       " ")))
8606            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8607                                   ":" (number-to-string article)))
8608            (unless xref
8609              (setq xref (list (system-name))))
8610            (setq new-xref
8611                  (concat
8612                   (mapconcat 'identity
8613                              (delete "Xref:" (delete new-xref xref))
8614                              " ")
8615                   " " new-xref))
8616            (save-excursion
8617              (set-buffer copy-buf)
8618              ;; First put the article in the destination group.
8619              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8620              (when (consp (setq art-group
8621                                 (gnus-request-accept-article
8622                                  to-newsgroup select-method (not articles))))
8623                (setq new-xref (concat new-xref " " (car art-group)
8624                                       ":"
8625                                       (number-to-string (cdr art-group))))
8626                ;; Now we have the new Xrefs header, so we insert
8627                ;; it and replace the new article.
8628                (nnheader-replace-header "Xref" new-xref)
8629                (gnus-request-replace-article
8630                 (cdr art-group) to-newsgroup (current-buffer))
8631                art-group))))))
8632       (cond
8633        ((not art-group)
8634         (gnus-message 1 "Couldn't %s article %s: %s"
8635                       (cadr (assq action names)) article
8636                       (nnheader-get-report (car to-method))))
8637        ((eq art-group 'junk)
8638         (when (eq action 'move)
8639           (gnus-summary-mark-article article gnus-canceled-mark)
8640           (gnus-message 4 "Deleted article %s" article)))
8641        (t
8642         (let* ((pto-group (gnus-group-prefixed-name
8643                            (car art-group) to-method))
8644                (entry
8645                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8646                (info (nth 2 entry))
8647                (to-group (gnus-info-group info))
8648                to-marks)
8649           ;; Update the group that has been moved to.
8650           (when (and info
8651                      (memq action '(move copy)))
8652             (unless (member to-group to-groups)
8653               (push to-group to-groups))
8654
8655             (unless (memq article gnus-newsgroup-unreads)
8656               (push 'read to-marks)
8657               (gnus-info-set-read
8658                info (gnus-add-to-range (gnus-info-read info)
8659                                        (list (cdr art-group)))))
8660
8661             ;; See whether the article is to be put in the cache.
8662             (let ((marks gnus-article-mark-lists)
8663                   (to-article (cdr art-group)))
8664
8665               ;; Enter the article into the cache in the new group,
8666               ;; if that is required.
8667               (when gnus-use-cache
8668                 (gnus-cache-possibly-enter-article
8669                  to-group to-article
8670                  (memq article gnus-newsgroup-marked)
8671                  (memq article gnus-newsgroup-dormant)
8672                  (memq article gnus-newsgroup-unreads)))
8673
8674               (when gnus-preserve-marks
8675                 ;; Copy any marks over to the new group.
8676                 (when (and (equal to-group gnus-newsgroup-name)
8677                            (not (memq article gnus-newsgroup-unreads)))
8678                   ;; Mark this article as read in this group.
8679                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8680                   (setcdr (gnus-active to-group) to-article)
8681                   (setcdr gnus-newsgroup-active to-article))
8682
8683                 (while marks
8684                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8685                     (when (memq article (symbol-value
8686                                          (intern (format "gnus-newsgroup-%s"
8687                                                          (caar marks)))))
8688                       (push (cdar marks) to-marks)
8689                       ;; If the other group is the same as this group,
8690                       ;; then we have to add the mark to the list.
8691                       (when (equal to-group gnus-newsgroup-name)
8692                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8693                              (cons to-article
8694                                    (symbol-value
8695                                     (intern (format "gnus-newsgroup-%s"
8696                                                     (caar marks)))))))
8697                       ;; Copy the marks to other group.
8698                       (gnus-add-marked-articles
8699                        to-group (cdar marks) (list to-article) info)))
8700                   (setq marks (cdr marks)))
8701
8702                 (gnus-request-set-mark to-group (list (list (list to-article)
8703                                                             'add
8704                                                             to-marks))))
8705
8706               (gnus-dribble-enter
8707                (concat "(gnus-group-set-info '"
8708                        (gnus-prin1-to-string (gnus-get-info to-group))
8709                        ")"))))
8710
8711           ;; Update the Xref header in this article to point to
8712           ;; the new crossposted article we have just created.
8713           (when (eq action 'crosspost)
8714             (save-excursion
8715               (set-buffer copy-buf)
8716               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8717               (nnheader-replace-header "Xref" new-xref)
8718               (gnus-request-replace-article
8719                article gnus-newsgroup-name (current-buffer)))))
8720
8721         ;;;!!!Why is this necessary?
8722         (set-buffer gnus-summary-buffer)
8723
8724         (gnus-summary-goto-subject article)
8725         (when (eq action 'move)
8726           (gnus-summary-mark-article article gnus-canceled-mark))))
8727       (gnus-summary-remove-process-mark article))
8728     ;; Re-activate all groups that have been moved to.
8729     (save-excursion
8730       (set-buffer gnus-group-buffer)
8731       (let ((gnus-group-marked to-groups))
8732         (gnus-group-get-new-news-this-group nil t)))
8733
8734     (gnus-kill-buffer copy-buf)
8735     (gnus-summary-position-point)
8736     (gnus-set-mode-line 'summary)))
8737
8738 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8739   "Move the current article to a different newsgroup.
8740 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8741 When called interactively, if TO-NEWSGROUP is nil, use the value of
8742 the variable `gnus-move-split-methods' for finding a default target
8743 newsgroup.
8744 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8745 re-spool using this method."
8746   (interactive "P")
8747   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8748
8749 (defun gnus-summary-crosspost-article (&optional n)
8750   "Crosspost the current article to some other group."
8751   (interactive "P")
8752   (gnus-summary-move-article n nil nil 'crosspost))
8753
8754 (defcustom gnus-summary-respool-default-method nil
8755   "Default method type for respooling an article.
8756 If nil, use to the current newsgroup method."
8757   :type 'symbol
8758   :group 'gnus-summary-mail)
8759
8760 (defun gnus-summary-respool-article (&optional n method)
8761   "Respool the current article.
8762 The article will be squeezed through the mail spooling process again,
8763 which means that it will be put in some mail newsgroup or other
8764 depending on `nnmail-split-methods'.
8765 If N is a positive number, respool the N next articles.
8766 If N is a negative number, respool the N previous articles.
8767 If N is nil and any articles have been marked with the process mark,
8768 respool those articles instead.
8769
8770 Respooling can be done both from mail groups and \"real\" newsgroups.
8771 In the former case, the articles in question will be moved from the
8772 current group into whatever groups they are destined to.  In the
8773 latter case, they will be copied into the relevant groups."
8774   (interactive
8775    (list current-prefix-arg
8776          (let* ((methods (gnus-methods-using 'respool))
8777                 (methname
8778                  (symbol-name (or gnus-summary-respool-default-method
8779                                   (car (gnus-find-method-for-group
8780                                         gnus-newsgroup-name)))))
8781                 (method
8782                  (gnus-completing-read-with-default
8783                   methname "What backend do you want to use when respooling?"
8784                   methods nil t nil 'gnus-mail-method-history))
8785                 ms)
8786            (cond
8787             ((zerop (length (setq ms (gnus-servers-using-backend
8788                                       (intern method)))))
8789              (list (intern method) ""))
8790             ((= 1 (length ms))
8791              (car ms))
8792             (t
8793              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8794                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8795                            ms-alist))))))))
8796   (unless method
8797     (error "No method given for respooling"))
8798   (if (assoc (symbol-name
8799               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8800              (gnus-methods-using 'respool))
8801       (gnus-summary-move-article n nil method)
8802     (gnus-summary-copy-article n nil method)))
8803
8804 (defun gnus-summary-import-article (file &optional edit)
8805   "Import an arbitrary file into a mail newsgroup."
8806   (interactive "fImport file: \nP")
8807   (let ((group gnus-newsgroup-name)
8808         (now (current-time))
8809         atts lines group-art)
8810     (unless (gnus-check-backend-function 'request-accept-article group)
8811       (error "%s does not support article importing" group))
8812     (or (file-readable-p file)
8813         (not (file-regular-p file))
8814         (error "Can't read %s" file))
8815     (save-excursion
8816       (set-buffer (gnus-get-buffer-create " *import file*"))
8817       (erase-buffer)
8818       (nnheader-insert-file-contents file)
8819       (goto-char (point-min))
8820       (if (nnheader-article-p)
8821           (save-restriction
8822             (goto-char (point-min))
8823             (search-forward "\n\n" nil t)
8824             (narrow-to-region (point-min) (1- (point)))
8825             (goto-char (point-min))
8826             (unless (re-search-forward "^date:" nil t)
8827               (goto-char (point-max))
8828               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8829        ;; This doesn't look like an article, so we fudge some headers.
8830         (setq atts (file-attributes file)
8831               lines (count-lines (point-min) (point-max)))
8832         (insert "From: " (read-string "From: ") "\n"
8833                 "Subject: " (read-string "Subject: ") "\n"
8834                 "Date: " (message-make-date (nth 5 atts)) "\n"
8835                 "Message-ID: " (message-make-message-id) "\n"
8836                 "Lines: " (int-to-string lines) "\n"
8837                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8838       (setq group-art (gnus-request-accept-article group nil t))
8839       (kill-buffer (current-buffer)))
8840     (setq gnus-newsgroup-active (gnus-activate-group group))
8841     (forward-line 1)
8842     (gnus-summary-goto-article (cdr group-art) nil t)
8843     (when edit
8844       (gnus-summary-edit-article))))
8845
8846 (defun gnus-summary-create-article ()
8847   "Create an article in a mail newsgroup."
8848   (interactive)
8849   (let ((group gnus-newsgroup-name)
8850         (now (current-time))
8851         group-art)
8852     (unless (gnus-check-backend-function 'request-accept-article group)
8853       (error "%s does not support article importing" group))
8854     (save-excursion
8855       (set-buffer (gnus-get-buffer-create " *import file*"))
8856       (erase-buffer)
8857       (goto-char (point-min))
8858       ;; This doesn't look like an article, so we fudge some headers.
8859       (insert "From: " (read-string "From: ") "\n"
8860               "Subject: " (read-string "Subject: ") "\n"
8861               "Date: " (message-make-date now) "\n"
8862               "Message-ID: " (message-make-message-id) "\n")
8863       (setq group-art (gnus-request-accept-article group nil t))
8864       (kill-buffer (current-buffer)))
8865     (setq gnus-newsgroup-active (gnus-activate-group group))
8866     (forward-line 1)
8867     (gnus-summary-goto-article (cdr group-art) nil t)
8868     (gnus-summary-edit-article)))
8869
8870 (defun gnus-summary-article-posted-p ()
8871   "Say whether the current (mail) article is available from news as well.
8872 This will be the case if the article has both been mailed and posted."
8873   (interactive)
8874   (let ((id (mail-header-references (gnus-summary-article-header)))
8875         (gnus-override-method (car (gnus-refer-article-methods))))
8876     (if (gnus-request-head id "")
8877         (gnus-message 2 "The current message was found on %s"
8878                       gnus-override-method)
8879       (gnus-message 2 "The current message couldn't be found on %s"
8880                     gnus-override-method)
8881       nil)))
8882
8883 (defun gnus-summary-expire-articles (&optional now)
8884   "Expire all articles that are marked as expirable in the current group."
8885   (interactive)
8886   (when (gnus-check-backend-function
8887          'request-expire-articles gnus-newsgroup-name)
8888     ;; This backend supports expiry.
8889     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8890            (expirable (if total
8891                           (progn
8892                             ;; We need to update the info for
8893                             ;; this group for `gnus-list-of-read-articles'
8894                             ;; to give us the right answer.
8895                             (gnus-run-hooks 'gnus-exit-group-hook)
8896                             (gnus-summary-update-info)
8897                             (gnus-list-of-read-articles gnus-newsgroup-name))
8898                         (setq gnus-newsgroup-expirable
8899                               (sort gnus-newsgroup-expirable '<))))
8900            (expiry-wait (if now 'immediate
8901                           (gnus-group-find-parameter
8902                            gnus-newsgroup-name 'expiry-wait)))
8903            (nnmail-expiry-target
8904             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8905                 nnmail-expiry-target))
8906            es)
8907       (when expirable
8908         ;; There are expirable articles in this group, so we run them
8909         ;; through the expiry process.
8910         (gnus-message 6 "Expiring articles...")
8911         (unless (gnus-check-group gnus-newsgroup-name)
8912           (error "Can't open server for %s" gnus-newsgroup-name))
8913         ;; The list of articles that weren't expired is returned.
8914         (save-excursion
8915           (if expiry-wait
8916               (let ((nnmail-expiry-wait-function nil)
8917                     (nnmail-expiry-wait expiry-wait))
8918                 (setq es (gnus-request-expire-articles
8919                           expirable gnus-newsgroup-name)))
8920             (setq es (gnus-request-expire-articles
8921                       expirable gnus-newsgroup-name)))
8922           (unless total
8923             (setq gnus-newsgroup-expirable es))
8924           ;; We go through the old list of expirable, and mark all
8925           ;; really expired articles as nonexistent.
8926           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8927             (let ((gnus-use-cache nil))
8928               (dolist (article expirable)
8929                 (when (and (not (memq article es))
8930                            (gnus-data-find article))
8931                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8932         (gnus-message 6 "Expiring articles...done")))))
8933
8934 (defun gnus-summary-expire-articles-now ()
8935   "Expunge all expirable articles in the current group.
8936 This means that *all* articles that are marked as expirable will be
8937 deleted forever, right now."
8938   (interactive)
8939   (or gnus-expert-user
8940       (gnus-yes-or-no-p
8941        "Are you really, really, really sure you want to delete all these messages? ")
8942       (error "Phew!"))
8943   (gnus-summary-expire-articles t))
8944
8945 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8946 (defun gnus-summary-delete-article (&optional n)
8947   "Delete the N next (mail) articles.
8948 This command actually deletes articles.  This is not a marking
8949 command.  The article will disappear forever from your life, never to
8950 return.
8951 If N is negative, delete backwards.
8952 If N is nil and articles have been marked with the process mark,
8953 delete these instead."
8954   (interactive "P")
8955   (unless (gnus-check-backend-function 'request-expire-articles
8956                                        gnus-newsgroup-name)
8957     (error "The current newsgroup does not support article deletion"))
8958   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8959     (error "Couldn't open server"))
8960   ;; Compute the list of articles to delete.
8961   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8962         (nnmail-expiry-target 'delete)
8963         not-deleted)
8964     (if (and gnus-novice-user
8965              (not (gnus-yes-or-no-p
8966                    (format "Do you really want to delete %s forever? "
8967                            (if (> (length articles) 1)
8968                                (format "these %s articles" (length articles))
8969                              "this article")))))
8970         ()
8971       ;; Delete the articles.
8972       (setq not-deleted (gnus-request-expire-articles
8973                          articles gnus-newsgroup-name 'force))
8974       (while articles
8975         (gnus-summary-remove-process-mark (car articles))
8976         ;; The backend might not have been able to delete the article
8977         ;; after all.
8978         (unless (memq (car articles) not-deleted)
8979           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8980         (setq articles (cdr articles)))
8981       (when not-deleted
8982         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8983     (gnus-summary-position-point)
8984     (gnus-set-mode-line 'summary)
8985     not-deleted))
8986
8987 (defun gnus-summary-edit-article (&optional arg)
8988   "Edit the current article.
8989 This will have permanent effect only in mail groups.
8990 If ARG is nil, edit the decoded articles.
8991 If ARG is 1, edit the raw articles.
8992 If ARG is 2, edit the raw articles even in read-only groups.
8993 If ARG is 3, edit the articles with the current handles.
8994 Otherwise, allow editing of articles even in read-only
8995 groups."
8996   (interactive "P")
8997   (let (force raw current-handles)
8998     (cond
8999      ((null arg))
9000      ((eq arg 1)
9001       (setq raw t))
9002      ((eq arg 2)
9003       (setq raw t
9004             force t))
9005      ((eq arg 3)
9006       (setq current-handles
9007             (and (gnus-buffer-live-p gnus-article-buffer)
9008                  (with-current-buffer gnus-article-buffer
9009                    (prog1
9010                        gnus-article-mime-handles
9011                      (setq gnus-article-mime-handles nil))))))
9012      (t
9013       (setq force t)))
9014     (when (and raw (not force)
9015                (member gnus-newsgroup-name '("nndraft:delayed"
9016                                              "nndraft:drafts"
9017                                              "nndraft:queue")))
9018       (error "Can't edit the raw article in group %s"
9019              gnus-newsgroup-name))
9020     (save-excursion
9021       (set-buffer gnus-summary-buffer)
9022       (let ((mail-parse-charset gnus-newsgroup-charset)
9023             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9024         (gnus-set-global-variables)
9025         (when (and (not force)
9026                    (gnus-group-read-only-p))
9027           (error "The current newsgroup does not support article editing"))
9028         (gnus-summary-show-article t)
9029         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9030           (with-current-buffer gnus-article-buffer
9031             (mm-enable-multibyte)))
9032         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9033             (setq raw t))
9034         (gnus-article-edit-article
9035          (if raw 'ignore
9036            `(lambda ()
9037               (let ((mbl mml-buffer-list))
9038                 (setq mml-buffer-list nil)
9039                 (mime-to-mml ,'current-handles)
9040                 (let ((mbl1 mml-buffer-list))
9041                   (setq mml-buffer-list mbl)
9042                   (set (make-local-variable 'mml-buffer-list) mbl1))
9043                 (make-local-hook 'kill-buffer-hook)
9044                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9045          `(lambda (no-highlight)
9046             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9047                   (message-options message-options)
9048                   (message-options-set-recipient)
9049                   (mail-parse-ignored-charsets
9050                    ',gnus-newsgroup-ignored-charsets))
9051               ,(if (not raw) '(progn
9052                                 (mml-to-mime)
9053                                 (mml-destroy-buffers)
9054                                 (remove-hook 'kill-buffer-hook
9055                                              'mml-destroy-buffers t)
9056                                 (kill-local-variable 'mml-buffer-list)))
9057               (gnus-summary-edit-article-done
9058                ,(or (mail-header-references gnus-current-headers) "")
9059                ,(gnus-group-read-only-p)
9060                ,gnus-summary-buffer no-highlight))))))))
9061
9062 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9063
9064 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9065                                                  no-highlight)
9066   "Make edits to the current article permanent."
9067   (interactive)
9068   (save-excursion
9069    ;; The buffer restriction contains the entire article if it exists.
9070     (when (article-goto-body)
9071       (let ((lines (count-lines (point) (point-max)))
9072             (length (- (point-max) (point)))
9073             (case-fold-search t)
9074             (body (copy-marker (point))))
9075         (goto-char (point-min))
9076         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9077           (delete-region (match-beginning 1) (match-end 1))
9078           (insert (number-to-string length)))
9079         (goto-char (point-min))
9080         (when (re-search-forward
9081                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9082           (delete-region (match-beginning 1) (match-end 1))
9083           (insert (number-to-string length)))
9084         (goto-char (point-min))
9085         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9086           (delete-region (match-beginning 1) (match-end 1))
9087           (insert (number-to-string lines))))))
9088   ;; Replace the article.
9089   (let ((buf (current-buffer)))
9090     (with-temp-buffer
9091       (insert-buffer-substring buf)
9092
9093       (if (and (not read-only)
9094                (not (gnus-request-replace-article
9095                      (cdr gnus-article-current) (car gnus-article-current)
9096                      (current-buffer) t)))
9097           (error "Couldn't replace article")
9098         ;; Update the summary buffer.
9099         (if (and references
9100                  (equal (message-tokenize-header references " ")
9101                         (message-tokenize-header
9102                          (or (message-fetch-field "references") "") " ")))
9103             ;; We only have to update this line.
9104             (save-excursion
9105               (save-restriction
9106                 (message-narrow-to-head)
9107                 (let ((head (buffer-string))
9108                       header)
9109                   (with-temp-buffer
9110                     (insert (format "211 %d Article retrieved.\n"
9111                                     (cdr gnus-article-current)))
9112                     (insert head)
9113                     (insert ".\n")
9114                     (let ((nntp-server-buffer (current-buffer)))
9115                       (setq header (car (gnus-get-newsgroup-headers
9116                                          nil t))))
9117                     (save-excursion
9118                       (set-buffer gnus-summary-buffer)
9119                       (gnus-data-set-header
9120                        (gnus-data-find (cdr gnus-article-current))
9121                        header)
9122                       (gnus-summary-update-article-line
9123                        (cdr gnus-article-current) header)
9124                       (if (gnus-summary-goto-subject
9125                            (cdr gnus-article-current) nil t)
9126                           (gnus-summary-update-secondary-mark
9127                            (cdr gnus-article-current))))))))
9128           ;; Update threads.
9129           (set-buffer (or buffer gnus-summary-buffer))
9130           (gnus-summary-update-article (cdr gnus-article-current))
9131           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9132               (gnus-summary-update-secondary-mark
9133                (cdr gnus-article-current))))
9134         ;; Prettify the article buffer again.
9135         (unless no-highlight
9136           (save-excursion
9137             (set-buffer gnus-article-buffer)
9138             ;;;!!! Fix this -- article should be rehighlighted.
9139             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9140             (set-buffer gnus-original-article-buffer)
9141             (gnus-request-article
9142              (cdr gnus-article-current)
9143              (car gnus-article-current) (current-buffer))))
9144         ;; Prettify the summary buffer line.
9145         (when (gnus-visual-p 'summary-highlight 'highlight)
9146           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9147
9148 (defun gnus-summary-edit-wash (key)
9149   "Perform editing command KEY in the article buffer."
9150   (interactive
9151    (list
9152     (progn
9153       (message "%s" (concat (this-command-keys) "- "))
9154       (read-char))))
9155   (message "")
9156   (gnus-summary-edit-article)
9157   (execute-kbd-macro (concat (this-command-keys) key))
9158   (gnus-article-edit-done))
9159
9160 ;;; Respooling
9161
9162 (defun gnus-summary-respool-query (&optional silent trace)
9163   "Query where the respool algorithm would put this article."
9164   (interactive)
9165   (let (gnus-mark-article-hook)
9166     (gnus-summary-select-article)
9167     (save-excursion
9168       (set-buffer gnus-original-article-buffer)
9169       (save-restriction
9170         (message-narrow-to-head)
9171         (let ((groups (nnmail-article-group 'identity trace)))
9172           (unless silent
9173             (if groups
9174                 (message "This message would go to %s"
9175                          (mapconcat 'car groups ", "))
9176               (message "This message would go to no groups"))
9177             groups))))))
9178
9179 (defun gnus-summary-respool-trace ()
9180   "Trace where the respool algorithm would put this article.
9181 Display a buffer showing all fancy splitting patterns which matched."
9182   (interactive)
9183   (gnus-summary-respool-query nil t))
9184
9185 ;; Summary marking commands.
9186
9187 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9188   "Mark articles which has the same subject as read, and then select the next.
9189 If UNMARK is positive, remove any kind of mark.
9190 If UNMARK is negative, tick articles."
9191   (interactive "P")
9192   (when unmark
9193     (setq unmark (prefix-numeric-value unmark)))
9194   (let ((count
9195          (gnus-summary-mark-same-subject
9196           (gnus-summary-article-subject) unmark)))
9197     ;; Select next unread article.  If auto-select-same mode, should
9198     ;; select the first unread article.
9199     (gnus-summary-next-article t (and gnus-auto-select-same
9200                                       (gnus-summary-article-subject)))
9201     (gnus-message 7 "%d article%s marked as %s"
9202                   count (if (= count 1) " is" "s are")
9203                   (if unmark "unread" "read"))))
9204
9205 (defun gnus-summary-kill-same-subject (&optional unmark)
9206   "Mark articles which has the same subject as read.
9207 If UNMARK is positive, remove any kind of mark.
9208 If UNMARK is negative, tick articles."
9209   (interactive "P")
9210   (when unmark
9211     (setq unmark (prefix-numeric-value unmark)))
9212   (let ((count
9213          (gnus-summary-mark-same-subject
9214           (gnus-summary-article-subject) unmark)))
9215     ;; If marked as read, go to next unread subject.
9216     (when (null unmark)
9217       ;; Go to next unread subject.
9218       (gnus-summary-next-subject 1 t))
9219     (gnus-message 7 "%d articles are marked as %s"
9220                   count (if unmark "unread" "read"))))
9221
9222 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9223   "Mark articles with same SUBJECT as read, and return marked number.
9224 If optional argument UNMARK is positive, remove any kinds of marks.
9225 If optional argument UNMARK is negative, mark articles as unread instead."
9226   (let ((count 1))
9227     (save-excursion
9228       (cond
9229        ((null unmark)                   ; Mark as read.
9230         (while (and
9231                 (progn
9232                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9233                   (gnus-summary-show-thread) t)
9234                 (gnus-summary-find-subject subject))
9235           (setq count (1+ count))))
9236        ((> unmark 0)                    ; Tick.
9237         (while (and
9238                 (progn
9239                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9240                   (gnus-summary-show-thread) t)
9241                 (gnus-summary-find-subject subject))
9242           (setq count (1+ count))))
9243        (t                               ; Mark as unread.
9244         (while (and
9245                 (progn
9246                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9247                   (gnus-summary-show-thread) t)
9248                 (gnus-summary-find-subject subject))
9249           (setq count (1+ count)))))
9250       (gnus-set-mode-line 'summary)
9251       ;; Return the number of marked articles.
9252       count)))
9253
9254 (defun gnus-summary-mark-as-processable (n &optional unmark)
9255   "Set the process mark on the next N articles.
9256 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9257 the process mark instead.  The difference between N and the actual
9258 number of articles marked is returned."
9259   (interactive "P")
9260   (if (and (null n) (gnus-region-active-p))
9261       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9262     (setq n (prefix-numeric-value n))
9263     (let ((backward (< n 0))
9264           (n (abs n)))
9265       (while (and
9266               (> n 0)
9267               (if unmark
9268                   (gnus-summary-remove-process-mark
9269                    (gnus-summary-article-number))
9270                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9271               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9272         (setq n (1- n)))
9273       (when (/= 0 n)
9274         (gnus-message 7 "No more articles"))
9275       (gnus-summary-recenter)
9276       (gnus-summary-position-point)
9277       n)))
9278
9279 (defun gnus-summary-unmark-as-processable (n)
9280   "Remove the process mark from the next N articles.
9281 If N is negative, unmark backward instead.  The difference between N and
9282 the actual number of articles unmarked is returned."
9283   (interactive "P")
9284   (gnus-summary-mark-as-processable n t))
9285
9286 (defun gnus-summary-unmark-all-processable ()
9287   "Remove the process mark from all articles."
9288   (interactive)
9289   (save-excursion
9290     (while gnus-newsgroup-processable
9291       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9292   (gnus-summary-position-point))
9293
9294 (defun gnus-summary-add-mark (article type)
9295   "Mark ARTICLE with a mark of TYPE."
9296   (let ((vtype (car (assq type gnus-article-mark-lists)))
9297         var)
9298     (if (not vtype)
9299         (error "No such mark type: %s" type)
9300       (setq var (intern (format "gnus-newsgroup-%s" type)))
9301       (set var (cons article (symbol-value var)))
9302       (if (memq type '(processable cached replied forwarded recent saved))
9303           (gnus-summary-update-secondary-mark article)
9304         ;;; !!! This is bogus.  We should find out what primary
9305         ;;; !!! mark we want to set.
9306         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9307
9308 (defun gnus-summary-mark-as-expirable (n)
9309   "Mark N articles forward as expirable.
9310 If N is negative, mark backward instead.  The difference between N and
9311 the actual number of articles marked is returned."
9312   (interactive "p")
9313   (gnus-summary-mark-forward n gnus-expirable-mark))
9314
9315 (defun gnus-summary-mark-as-spam (n)
9316   "Mark N articles forward as spam.
9317 If N is negative, mark backward instead.  The difference between N and
9318 the actual number of articles marked is returned."
9319   (interactive "p")
9320   (gnus-summary-mark-forward n gnus-spam-mark))
9321
9322 (defun gnus-summary-mark-article-as-replied (article)
9323   "Mark ARTICLE as replied to and update the summary line.
9324 ARTICLE can also be a list of articles."
9325   (interactive (list (gnus-summary-article-number)))
9326   (let ((articles (if (listp article) article (list article))))
9327     (dolist (article articles)
9328       (push article gnus-newsgroup-replied)
9329       (let ((buffer-read-only nil))
9330         (when (gnus-summary-goto-subject article nil t)
9331           (gnus-summary-update-secondary-mark article))))))
9332
9333 (defun gnus-summary-mark-article-as-forwarded (article)
9334   "Mark ARTICLE as forwarded and update the summary line.
9335 ARTICLE can also be a list of articles."
9336   (let ((articles (if (listp article) article (list article))))
9337     (dolist (article articles)
9338       (push article gnus-newsgroup-forwarded)
9339       (let ((buffer-read-only nil))
9340         (when (gnus-summary-goto-subject article nil t)
9341           (gnus-summary-update-secondary-mark article))))))
9342
9343 (defun gnus-summary-set-bookmark (article)
9344   "Set a bookmark in current article."
9345   (interactive (list (gnus-summary-article-number)))
9346   (when (or (not (get-buffer gnus-article-buffer))
9347             (not gnus-current-article)
9348             (not gnus-article-current)
9349             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9350     (error "No current article selected"))
9351   ;; Remove old bookmark, if one exists.
9352   (let ((old (assq article gnus-newsgroup-bookmarks)))
9353     (when old
9354       (setq gnus-newsgroup-bookmarks
9355             (delq old gnus-newsgroup-bookmarks))))
9356   ;; Set the new bookmark, which is on the form
9357   ;; (article-number . line-number-in-body).
9358   (push
9359    (cons article
9360          (save-excursion
9361            (set-buffer gnus-article-buffer)
9362            (count-lines
9363             (min (point)
9364                  (save-excursion
9365                    (goto-char (point-min))
9366                    (search-forward "\n\n" nil t)
9367                    (point)))
9368             (point))))
9369    gnus-newsgroup-bookmarks)
9370   (gnus-message 6 "A bookmark has been added to the current article."))
9371
9372 (defun gnus-summary-remove-bookmark (article)
9373   "Remove the bookmark from the current article."
9374   (interactive (list (gnus-summary-article-number)))
9375   ;; Remove old bookmark, if one exists.
9376   (let ((old (assq article gnus-newsgroup-bookmarks)))
9377     (if old
9378         (progn
9379           (setq gnus-newsgroup-bookmarks
9380                 (delq old gnus-newsgroup-bookmarks))
9381           (gnus-message 6 "Removed bookmark."))
9382       (gnus-message 6 "No bookmark in current article."))))
9383
9384 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9385 (defun gnus-summary-mark-as-dormant (n)
9386   "Mark N articles forward as dormant.
9387 If N is negative, mark backward instead.  The difference between N and
9388 the actual number of articles marked is returned."
9389   (interactive "p")
9390   (gnus-summary-mark-forward n gnus-dormant-mark))
9391
9392 (defun gnus-summary-set-process-mark (article)
9393   "Set the process mark on ARTICLE and update the summary line."
9394   (setq gnus-newsgroup-processable
9395         (cons article
9396               (delq article gnus-newsgroup-processable)))
9397   (when (gnus-summary-goto-subject article)
9398     (gnus-summary-show-thread)
9399     (gnus-summary-goto-subject article)
9400     (gnus-summary-update-secondary-mark article)))
9401
9402 (defun gnus-summary-remove-process-mark (article)
9403   "Remove the process mark from ARTICLE and update the summary line."
9404   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9405   (when (gnus-summary-goto-subject article)
9406     (gnus-summary-show-thread)
9407     (gnus-summary-goto-subject article)
9408     (gnus-summary-update-secondary-mark article)))
9409
9410 (defun gnus-summary-set-saved-mark (article)
9411   "Set the process mark on ARTICLE and update the summary line."
9412   (push article gnus-newsgroup-saved)
9413   (when (gnus-summary-goto-subject article)
9414     (gnus-summary-update-secondary-mark article)))
9415
9416 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9417   "Mark N articles as read forwards.
9418 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9419 The difference between N and the actual number of articles marked is
9420 returned.
9421 If NO-EXPIRE, auto-expiry will be inhibited."
9422   (interactive "p")
9423   (gnus-summary-show-thread)
9424   (let ((backward (< n 0))
9425         (gnus-summary-goto-unread
9426          (and gnus-summary-goto-unread
9427               (not (eq gnus-summary-goto-unread 'never))
9428               (not (memq mark (list gnus-unread-mark
9429                                     gnus-ticked-mark gnus-dormant-mark)))))
9430         (n (abs n))
9431         (mark (or mark gnus-del-mark)))
9432     (while (and (> n 0)
9433                 (gnus-summary-mark-article nil mark no-expire)
9434                 (zerop (gnus-summary-next-subject
9435                         (if backward -1 1)
9436                         (and gnus-summary-goto-unread
9437                              (not (eq gnus-summary-goto-unread 'never)))
9438                         t)))
9439       (setq n (1- n)))
9440     (when (/= 0 n)
9441       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9442     (gnus-summary-recenter)
9443     (gnus-summary-position-point)
9444     (gnus-set-mode-line 'summary)
9445     n))
9446
9447 (defun gnus-summary-mark-article-as-read (mark)
9448   "Mark the current article quickly as read with MARK."
9449   (let ((article (gnus-summary-article-number)))
9450     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9451     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9452     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9453     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9454     (push (cons article mark) gnus-newsgroup-reads)
9455     ;; Possibly remove from cache, if that is used.
9456     (when gnus-use-cache
9457       (gnus-cache-enter-remove-article article))
9458     ;; Allow the backend to change the mark.
9459     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9460     ;; Check for auto-expiry.
9461     (when (and gnus-newsgroup-auto-expire
9462                (memq mark gnus-auto-expirable-marks))
9463       (setq mark gnus-expirable-mark)
9464       ;; Let the backend know about the mark change.
9465       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9466       (push article gnus-newsgroup-expirable))
9467     ;; Set the mark in the buffer.
9468     (gnus-summary-update-mark mark 'unread)
9469     t))
9470
9471 (defun gnus-summary-mark-article-as-unread (mark)
9472   "Mark the current article quickly as unread with MARK."
9473   (let* ((article (gnus-summary-article-number))
9474          (old-mark (gnus-summary-article-mark article)))
9475     ;; Allow the backend to change the mark.
9476     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9477     (if (eq mark old-mark)
9478         t
9479       (if (<= article 0)
9480           (progn
9481             (gnus-error 1 "Can't mark negative article numbers")
9482             nil)
9483         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9484         (setq gnus-newsgroup-spam-marked
9485               (delq article gnus-newsgroup-spam-marked))
9486         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9487         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9488         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9489         (cond ((= mark gnus-ticked-mark)
9490                (setq gnus-newsgroup-marked
9491                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9492                                               article)))
9493               ((= mark gnus-spam-mark)
9494                (setq gnus-newsgroup-spam-marked
9495                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9496                                               article)))
9497               ((= mark gnus-dormant-mark)
9498                (setq gnus-newsgroup-dormant
9499                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9500                                               article)))
9501               (t
9502                (setq gnus-newsgroup-unreads
9503                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9504                                               article))))
9505         (gnus-pull article gnus-newsgroup-reads)
9506
9507         ;; See whether the article is to be put in the cache.
9508         (and gnus-use-cache
9509              (vectorp (gnus-summary-article-header article))
9510              (save-excursion
9511                (gnus-cache-possibly-enter-article
9512                 gnus-newsgroup-name article
9513                 (= mark gnus-ticked-mark)
9514                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9515
9516         ;; Fix the mark.
9517         (gnus-summary-update-mark mark 'unread)
9518         t))))
9519
9520 (defun gnus-summary-mark-article (&optional article mark no-expire)
9521   "Mark ARTICLE with MARK.  MARK can be any character.
9522 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9523 `??' (dormant) and `?E' (expirable).
9524 If MARK is nil, then the default character `?r' is used.
9525 If ARTICLE is nil, then the article on the current line will be
9526 marked.
9527 If NO-EXPIRE, auto-expiry will be inhibited."
9528   ;; The mark might be a string.
9529   (when (stringp mark)
9530     (setq mark (aref mark 0)))
9531   ;; If no mark is given, then we check auto-expiring.
9532   (when (null mark)
9533     (setq mark gnus-del-mark))
9534   (when (and (not no-expire)
9535              gnus-newsgroup-auto-expire
9536              (memq mark gnus-auto-expirable-marks))
9537     (setq mark gnus-expirable-mark))
9538   (let ((article (or article (gnus-summary-article-number)))
9539         (old-mark (gnus-summary-article-mark article)))
9540     ;; Allow the backend to change the mark.
9541     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9542     (if (eq mark old-mark)
9543         t
9544       (unless article
9545         (error "No article on current line"))
9546       (if (not (if (or (= mark gnus-unread-mark)
9547                        (= mark gnus-ticked-mark)
9548                        (= mark gnus-spam-mark)
9549                        (= mark gnus-dormant-mark))
9550                    (gnus-mark-article-as-unread article mark)
9551                  (gnus-mark-article-as-read article mark)))
9552           t
9553         ;; See whether the article is to be put in the cache.
9554         (and gnus-use-cache
9555              (not (= mark gnus-canceled-mark))
9556              (vectorp (gnus-summary-article-header article))
9557              (save-excursion
9558                (gnus-cache-possibly-enter-article
9559                 gnus-newsgroup-name article
9560                 (= mark gnus-ticked-mark)
9561                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9562
9563         (when (gnus-summary-goto-subject article nil t)
9564           (let ((buffer-read-only nil))
9565             (gnus-summary-show-thread)
9566             ;; Fix the mark.
9567             (gnus-summary-update-mark mark 'unread)
9568             t))))))
9569
9570 (defun gnus-summary-update-secondary-mark (article)
9571   "Update the secondary (read, process, cache) mark."
9572   (gnus-summary-update-mark
9573    (cond ((memq article gnus-newsgroup-processable)
9574           gnus-process-mark)
9575          ((memq article gnus-newsgroup-cached)
9576           gnus-cached-mark)
9577          ((memq article gnus-newsgroup-replied)
9578           gnus-replied-mark)
9579          ((memq article gnus-newsgroup-forwarded)
9580           gnus-forwarded-mark)
9581          ((memq article gnus-newsgroup-saved)
9582           gnus-saved-mark)
9583          ((memq article gnus-newsgroup-recent)
9584           gnus-recent-mark)
9585          ((memq article gnus-newsgroup-unseen)
9586           gnus-unseen-mark)
9587          (t gnus-no-mark))
9588    'replied)
9589   (when (gnus-visual-p 'summary-highlight 'highlight)
9590     (gnus-run-hooks 'gnus-summary-update-hook))
9591   t)
9592
9593 (defun gnus-summary-update-download-mark (article)
9594   "Update the secondary (read, process, cache) mark."
9595   (gnus-summary-update-mark
9596    (cond ((memq article gnus-newsgroup-undownloaded) 
9597           gnus-undownloaded-mark)
9598          (gnus-newsgroup-agentized
9599           gnus-downloaded-mark)
9600          (t
9601           gnus-no-mark))
9602    'download)
9603   (gnus-summary-update-line t)
9604   t)
9605
9606 (defun gnus-summary-update-mark (mark type)
9607   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9608         (buffer-read-only nil))
9609     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9610     (when forward
9611       (when (looking-at "\r")
9612         (incf forward))
9613       (when (<= (+ forward (point)) (point-max))
9614         ;; Go to the right position on the line.
9615         (goto-char (+ forward (point)))
9616         ;; Replace the old mark with the new mark.
9617         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9618         ;; Optionally update the marks by some user rule.
9619         (when (eq type 'unread)
9620           (gnus-data-set-mark
9621            (gnus-data-find (gnus-summary-article-number)) mark)
9622           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9623
9624 (defun gnus-mark-article-as-read (article &optional mark)
9625   "Enter ARTICLE in the pertinent lists and remove it from others."
9626   ;; Make the article expirable.
9627   (let ((mark (or mark gnus-del-mark)))
9628     (setq gnus-newsgroup-expirable
9629           (if (= mark gnus-expirable-mark)
9630               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9631             (delq article gnus-newsgroup-expirable)))
9632     ;; Remove from unread and marked lists.
9633     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9634     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9635     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9636     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9637     (push (cons article mark) gnus-newsgroup-reads)
9638     ;; Possibly remove from cache, if that is used.
9639     (when gnus-use-cache
9640       (gnus-cache-enter-remove-article article))
9641     t))
9642
9643 (defun gnus-mark-article-as-unread (article &optional mark)
9644   "Enter ARTICLE in the pertinent lists and remove it from others."
9645   (let ((mark (or mark gnus-ticked-mark)))
9646     (if (<= article 0)
9647         (progn
9648           (gnus-error 1 "Can't mark negative article numbers")
9649           nil)
9650       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9651             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9652             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9653             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9654             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9655
9656       ;; Unsuppress duplicates?
9657       (when gnus-suppress-duplicates
9658         (gnus-dup-unsuppress-article article))
9659
9660       (cond ((= mark gnus-ticked-mark)
9661              (setq gnus-newsgroup-marked
9662                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9663             ((= mark gnus-spam-mark)
9664              (setq gnus-newsgroup-spam-marked
9665                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9666                                             article)))
9667             ((= mark gnus-dormant-mark)
9668              (setq gnus-newsgroup-dormant
9669                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9670             (t
9671              (setq gnus-newsgroup-unreads
9672                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9673       (gnus-pull article gnus-newsgroup-reads)
9674       t)))
9675
9676 (defalias 'gnus-summary-mark-as-unread-forward
9677   'gnus-summary-tick-article-forward)
9678 (make-obsolete 'gnus-summary-mark-as-unread-forward
9679                'gnus-summary-tick-article-forward)
9680 (defun gnus-summary-tick-article-forward (n)
9681   "Tick N articles forwards.
9682 If N is negative, tick backwards instead.
9683 The difference between N and the number of articles ticked is returned."
9684   (interactive "p")
9685   (gnus-summary-mark-forward n gnus-ticked-mark))
9686
9687 (defalias 'gnus-summary-mark-as-unread-backward
9688   'gnus-summary-tick-article-backward)
9689 (make-obsolete 'gnus-summary-mark-as-unread-backward
9690                'gnus-summary-tick-article-backward)
9691 (defun gnus-summary-tick-article-backward (n)
9692   "Tick N articles backwards.
9693 The difference between N and the number of articles ticked is returned."
9694   (interactive "p")
9695   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9696
9697 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9698 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9699 (defun gnus-summary-tick-article (&optional article clear-mark)
9700   "Mark current article as unread.
9701 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9702 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9703   (interactive)
9704   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9705                                        gnus-ticked-mark)))
9706
9707 (defun gnus-summary-mark-as-read-forward (n)
9708   "Mark N articles as read forwards.
9709 If N is negative, mark backwards instead.
9710 The difference between N and the actual number of articles marked is
9711 returned."
9712   (interactive "p")
9713   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9714
9715 (defun gnus-summary-mark-as-read-backward (n)
9716   "Mark the N articles as read backwards.
9717 The difference between N and the actual number of articles marked is
9718 returned."
9719   (interactive "p")
9720   (gnus-summary-mark-forward
9721    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9722
9723 (defun gnus-summary-mark-as-read (&optional article mark)
9724   "Mark current article as read.
9725 ARTICLE specifies the article to be marked as read.
9726 MARK specifies a string to be inserted at the beginning of the line."
9727   (gnus-summary-mark-article article mark))
9728
9729 (defun gnus-summary-clear-mark-forward (n)
9730   "Clear marks from N articles forward.
9731 If N is negative, clear backward instead.
9732 The difference between N and the number of marks cleared is returned."
9733   (interactive "p")
9734   (gnus-summary-mark-forward n gnus-unread-mark))
9735
9736 (defun gnus-summary-clear-mark-backward (n)
9737   "Clear marks from N articles backward.
9738 The difference between N and the number of marks cleared is returned."
9739   (interactive "p")
9740   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9741
9742 (defun gnus-summary-mark-unread-as-read ()
9743   "Intended to be used by `gnus-summary-mark-article-hook'."
9744   (when (memq gnus-current-article gnus-newsgroup-unreads)
9745     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9746
9747 (defun gnus-summary-mark-read-and-unread-as-read ()
9748   "Intended to be used by `gnus-summary-mark-article-hook'."
9749   (let ((mark (gnus-summary-article-mark)))
9750     (when (or (gnus-unread-mark-p mark)
9751               (gnus-read-mark-p mark))
9752       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9753
9754 (defun gnus-summary-mark-unread-as-ticked ()
9755   "Intended to be used by `gnus-summary-mark-article-hook'."
9756   (when (memq gnus-current-article gnus-newsgroup-unreads)
9757     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9758
9759 (defun gnus-summary-mark-region-as-read (point mark all)
9760   "Mark all unread articles between point and mark as read.
9761 If given a prefix, mark all articles between point and mark as read,
9762 even ticked and dormant ones."
9763   (interactive "r\nP")
9764   (save-excursion
9765     (let (article)
9766       (goto-char point)
9767       (beginning-of-line)
9768       (while (and
9769               (< (point) mark)
9770               (progn
9771                 (when (or all
9772                           (memq (setq article (gnus-summary-article-number))
9773                                 gnus-newsgroup-unreads))
9774                   (gnus-summary-mark-article article gnus-del-mark))
9775                 t)
9776               (gnus-summary-find-next))))))
9777
9778 (defun gnus-summary-mark-below (score mark)
9779   "Mark articles with score less than SCORE with MARK."
9780   (interactive "P\ncMark: ")
9781   (setq score (if score
9782                   (prefix-numeric-value score)
9783                 (or gnus-summary-default-score 0)))
9784   (save-excursion
9785     (set-buffer gnus-summary-buffer)
9786     (goto-char (point-min))
9787     (while
9788         (progn
9789           (and (< (gnus-summary-article-score) score)
9790                (gnus-summary-mark-article nil mark))
9791           (gnus-summary-find-next)))))
9792
9793 (defun gnus-summary-kill-below (&optional score)
9794   "Mark articles with score below SCORE as read."
9795   (interactive "P")
9796   (gnus-summary-mark-below score gnus-killed-mark))
9797
9798 (defun gnus-summary-clear-above (&optional score)
9799   "Clear all marks from articles with score above SCORE."
9800   (interactive "P")
9801   (gnus-summary-mark-above score gnus-unread-mark))
9802
9803 (defun gnus-summary-tick-above (&optional score)
9804   "Tick all articles with score above SCORE."
9805   (interactive "P")
9806   (gnus-summary-mark-above score gnus-ticked-mark))
9807
9808 (defun gnus-summary-mark-above (score mark)
9809   "Mark articles with score over SCORE with MARK."
9810   (interactive "P\ncMark: ")
9811   (setq score (if score
9812                   (prefix-numeric-value score)
9813                 (or gnus-summary-default-score 0)))
9814   (save-excursion
9815     (set-buffer gnus-summary-buffer)
9816     (goto-char (point-min))
9817     (while (and (progn
9818                   (when (> (gnus-summary-article-score) score)
9819                     (gnus-summary-mark-article nil mark))
9820                   t)
9821                 (gnus-summary-find-next)))))
9822
9823 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9824 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9825 (defun gnus-summary-limit-include-expunged (&optional no-error)
9826   "Display all the hidden articles that were expunged for low scores."
9827   (interactive)
9828   (let ((buffer-read-only nil))
9829     (let ((scored gnus-newsgroup-scored)
9830           headers h)
9831       (while scored
9832         (unless (gnus-summary-article-header (caar scored))
9833           (and (setq h (gnus-number-to-header (caar scored)))
9834                (< (cdar scored) gnus-summary-expunge-below)
9835                (push h headers)))
9836         (setq scored (cdr scored)))
9837       (if (not headers)
9838           (when (not no-error)
9839             (error "No expunged articles hidden"))
9840         (goto-char (point-min))
9841         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9842         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9843         (mapcar (lambda (x) (push (mail-header-number x)
9844                                   gnus-newsgroup-limit))
9845                 headers)
9846         (gnus-summary-prepare-unthreaded (nreverse headers))
9847         (goto-char (point-min))
9848         (gnus-summary-position-point)
9849         t))))
9850
9851 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9852   "Mark all unread articles in this newsgroup as read.
9853 If prefix argument ALL is non-nil, ticked and dormant articles will
9854 also be marked as read.
9855 If QUIETLY is non-nil, no questions will be asked.
9856 If TO-HERE is non-nil, it should be a point in the buffer.  All
9857 articles before (after, if REVERSE is set) this point will be marked as read.
9858 Note that this function will only catch up the unread article
9859 in the current summary buffer limitation.
9860 The number of articles marked as read is returned."
9861   (interactive "P")
9862   (prog1
9863       (save-excursion
9864         (when (or quietly
9865                   (not gnus-interactive-catchup) ;Without confirmation?
9866                   gnus-expert-user
9867                   (gnus-y-or-n-p
9868                    (if all
9869                        "Mark absolutely all articles as read? "
9870                      "Mark all unread articles as read? ")))
9871           (if (and not-mark
9872                    (not gnus-newsgroup-adaptive)
9873                    (not gnus-newsgroup-auto-expire)
9874                    (not gnus-suppress-duplicates)
9875                    (or (not gnus-use-cache)
9876                        (eq gnus-use-cache 'passive)))
9877               (progn
9878                 (when all
9879                   (setq gnus-newsgroup-marked nil
9880                         gnus-newsgroup-spam-marked nil
9881                         gnus-newsgroup-dormant nil))
9882                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9883             ;; We actually mark all articles as canceled, which we
9884             ;; have to do when using auto-expiry or adaptive scoring.
9885             (gnus-summary-show-all-threads)
9886             (if (and to-here reverse)
9887                 (progn
9888                   (goto-char to-here)
9889                   (while (and
9890                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9891                           (gnus-summary-find-next (not all) nil nil t))))
9892               (when (gnus-summary-first-subject (not all) t)
9893                 (while (and
9894                         (if to-here (< (point) to-here) t)
9895                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9896                         (gnus-summary-find-next (not all) nil nil t)))))
9897             (gnus-set-mode-line 'summary))
9898           t))
9899     (gnus-summary-position-point)))
9900
9901 (defun gnus-summary-catchup-to-here (&optional all)
9902   "Mark all unticked articles before the current one as read.
9903 If ALL is non-nil, also mark ticked and dormant articles as read."
9904   (interactive "P")
9905   (save-excursion
9906     (gnus-save-hidden-threads
9907       (let ((beg (point)))
9908         ;; We check that there are unread articles.
9909         (when (or all (gnus-summary-find-prev))
9910           (gnus-summary-catchup all t beg)))))
9911   (gnus-summary-position-point))
9912
9913 (defun gnus-summary-catchup-from-here (&optional all)
9914   "Mark all unticked articles after the current one as read.
9915 If ALL is non-nil, also mark ticked and dormant articles as read."
9916   (interactive "P")
9917   (save-excursion
9918     (gnus-save-hidden-threads
9919       (let ((beg (point)))
9920         ;; We check that there are unread articles.
9921         (when (or all (gnus-summary-find-next))
9922           (gnus-summary-catchup all t beg nil t)))))
9923
9924   (gnus-summary-position-point))
9925 (defun gnus-summary-catchup-all (&optional quietly)
9926   "Mark all articles in this newsgroup as read.
9927 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
9928 instead, which marks only unread articles as read."
9929   (interactive "P")
9930   (gnus-summary-catchup t quietly))
9931
9932 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9933   "Mark all unread articles in this group as read, then exit.
9934 If prefix argument ALL is non-nil, all articles are marked as read.
9935 If QUIETLY is non-nil, no questions will be asked."
9936   (interactive "P")
9937   (when (gnus-summary-catchup all quietly nil 'fast)
9938     ;; Select next newsgroup or exit.
9939     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9940              (eq gnus-auto-select-next 'quietly))
9941         (gnus-summary-next-group nil)
9942       (gnus-summary-exit))))
9943
9944 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9945   "Mark all articles in this newsgroup as read, and then exit.
9946 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
9947 instead, which marks only unread articles as read."
9948   (interactive "P")
9949   (gnus-summary-catchup-and-exit t quietly))
9950
9951 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9952   "Mark all articles in this group as read and select the next group.
9953 If given a prefix, mark all articles, unread as well as ticked, as
9954 read."
9955   (interactive "P")
9956   (save-excursion
9957     (gnus-summary-catchup all))
9958   (gnus-summary-next-group))
9959
9960 ;;;
9961 ;;; with article
9962 ;;;
9963
9964 (defmacro gnus-with-article (article &rest forms)
9965   "Select ARTICLE and perform FORMS in the original article buffer.
9966 Then replace the article with the result."
9967   `(progn
9968      ;; We don't want the article to be marked as read.
9969      (let (gnus-mark-article-hook)
9970        (gnus-summary-select-article t t nil ,article))
9971      (set-buffer gnus-original-article-buffer)
9972      ,@forms
9973      (if (not (gnus-check-backend-function
9974                'request-replace-article (car gnus-article-current)))
9975          (gnus-message 5 "Read-only group; not replacing")
9976        (unless (gnus-request-replace-article
9977                 ,article (car gnus-article-current)
9978                 (current-buffer) t)
9979          (error "Couldn't replace article")))
9980      ;; The cache and backlog have to be flushed somewhat.
9981      (when gnus-keep-backlog
9982        (gnus-backlog-remove-article
9983         (car gnus-article-current) (cdr gnus-article-current)))
9984      (when gnus-use-cache
9985        (gnus-cache-update-article
9986         (car gnus-article-current) (cdr gnus-article-current)))))
9987
9988 (put 'gnus-with-article 'lisp-indent-function 1)
9989 (put 'gnus-with-article 'edebug-form-spec '(form body))
9990
9991 ;; Thread-based commands.
9992
9993 (defun gnus-summary-articles-in-thread (&optional article)
9994   "Return a list of all articles in the current thread.
9995 If ARTICLE is non-nil, return all articles in the thread that starts
9996 with that article."
9997   (let* ((article (or article (gnus-summary-article-number)))
9998          (data (gnus-data-find-list article))
9999          (top-level (gnus-data-level (car data)))
10000          (top-subject
10001           (cond ((null gnus-thread-operation-ignore-subject)
10002                  (gnus-simplify-subject-re
10003                   (mail-header-subject (gnus-data-header (car data)))))
10004                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10005                  (gnus-simplify-subject-fuzzy
10006                   (mail-header-subject (gnus-data-header (car data)))))
10007                 (t nil)))
10008          (end-point (save-excursion
10009                       (if (gnus-summary-go-to-next-thread)
10010                           (point) (point-max))))
10011          articles)
10012     (while (and data
10013                 (< (gnus-data-pos (car data)) end-point))
10014       (when (or (not top-subject)
10015                 (string= top-subject
10016                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10017                              (gnus-simplify-subject-fuzzy
10018                               (mail-header-subject
10019                                (gnus-data-header (car data))))
10020                            (gnus-simplify-subject-re
10021                             (mail-header-subject
10022                              (gnus-data-header (car data)))))))
10023         (push (gnus-data-number (car data)) articles))
10024       (unless (and (setq data (cdr data))
10025                    (> (gnus-data-level (car data)) top-level))
10026         (setq data nil)))
10027     ;; Return the list of articles.
10028     (nreverse articles)))
10029
10030 (defun gnus-summary-rethread-current ()
10031   "Rethread the thread the current article is part of."
10032   (interactive)
10033   (let* ((gnus-show-threads t)
10034          (article (gnus-summary-article-number))
10035          (id (mail-header-id (gnus-summary-article-header)))
10036          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10037     (unless id
10038       (error "No article on the current line"))
10039     (gnus-rebuild-thread id)
10040     (gnus-summary-goto-subject article)))
10041
10042 (defun gnus-summary-reparent-thread ()
10043   "Make the current article child of the marked (or previous) article.
10044
10045 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10046 is non-nil or the Subject: of both articles are the same."
10047   (interactive)
10048   (unless (not (gnus-group-read-only-p))
10049     (error "The current newsgroup does not support article editing"))
10050   (unless (<= (length gnus-newsgroup-processable) 1)
10051     (error "No more than one article may be marked"))
10052   (save-window-excursion
10053     (let ((gnus-article-buffer " *reparent*")
10054           (current-article (gnus-summary-article-number))
10055           ;; First grab the marked article, otherwise one line up.
10056           (parent-article (if (not (null gnus-newsgroup-processable))
10057                               (car gnus-newsgroup-processable)
10058                             (save-excursion
10059                               (if (eq (forward-line -1) 0)
10060                                   (gnus-summary-article-number)
10061                                 (error "Beginning of summary buffer"))))))
10062       (unless (not (eq current-article parent-article))
10063         (error "An article may not be self-referential"))
10064       (let ((message-id (mail-header-id
10065                          (gnus-summary-article-header parent-article))))
10066         (unless (and message-id (not (equal message-id "")))
10067           (error "No message-id in desired parent"))
10068         (gnus-with-article current-article
10069           (save-restriction
10070             (goto-char (point-min))
10071             (message-narrow-to-head)
10072             (if (re-search-forward "^References: " nil t)
10073                 (progn
10074                   (re-search-forward "^[^ \t]" nil t)
10075                   (forward-line -1)
10076                   (end-of-line)
10077                   (insert " " message-id))
10078               (insert "References: " message-id "\n"))))
10079         (set-buffer gnus-summary-buffer)
10080         (gnus-summary-unmark-all-processable)
10081         (gnus-summary-update-article current-article)
10082         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10083             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10084         (gnus-summary-rethread-current)
10085         (gnus-message 3 "Article %d is now the child of article %d"
10086                       current-article parent-article)))))
10087
10088 (defun gnus-summary-toggle-threads (&optional arg)
10089   "Toggle showing conversation threads.
10090 If ARG is positive number, turn showing conversation threads on."
10091   (interactive "P")
10092   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10093     (setq gnus-show-threads
10094           (if (null arg) (not gnus-show-threads)
10095             (> (prefix-numeric-value arg) 0)))
10096     (gnus-summary-prepare)
10097     (gnus-summary-goto-subject current)
10098     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10099     (gnus-summary-position-point)))
10100
10101 (defun gnus-summary-show-all-threads ()
10102   "Show all threads."
10103   (interactive)
10104   (save-excursion
10105     (let ((buffer-read-only nil))
10106       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10107   (gnus-summary-position-point))
10108
10109 (defun gnus-summary-show-thread ()
10110   "Show thread subtrees.
10111 Returns nil if no thread was there to be shown."
10112   (interactive)
10113   (let ((buffer-read-only nil)
10114         (orig (point))
10115         ;; first goto end then to beg, to have point at beg after let
10116         (end (progn (end-of-line) (point)))
10117         (beg (progn (beginning-of-line) (point))))
10118     (prog1
10119         ;; Any hidden lines here?
10120         (search-forward "\r" end t)
10121       (subst-char-in-region beg end ?\^M ?\n t)
10122       (goto-char orig)
10123       (gnus-summary-position-point))))
10124
10125 (defun gnus-summary-maybe-hide-threads ()
10126   "If requested, hide the threads that should be hidden."
10127   (when (and gnus-show-threads
10128              gnus-thread-hide-subtree)
10129     (gnus-summary-hide-all-threads
10130      (if (or (consp gnus-thread-hide-subtree)
10131              (gnus-functionp gnus-thread-hide-subtree))
10132          (gnus-make-predicate gnus-thread-hide-subtree)
10133        nil))))
10134
10135 ;;; Hiding predicates.
10136
10137 (defun gnus-article-unread-p (header)
10138   (memq (mail-header-number header) gnus-newsgroup-unreads))
10139
10140 (defun gnus-article-unseen-p (header)
10141   (memq (mail-header-number header) gnus-newsgroup-unseen))
10142
10143 (defun gnus-map-articles (predicate articles)
10144   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10145   (apply 'gnus-or (mapcar predicate
10146                           (mapcar 'gnus-summary-article-header articles))))
10147
10148 (defun gnus-summary-hide-all-threads (&optional predicate)
10149   "Hide all thread subtrees.
10150 If PREDICATE is supplied, threads that satisfy this predicate
10151 will not be hidden."
10152   (interactive)
10153   (save-excursion
10154     (goto-char (point-min))
10155     (let ((end nil))
10156       (while (not end)
10157         (when (or (not predicate)
10158                   (gnus-map-articles
10159                    predicate (gnus-summary-article-children)))
10160             (gnus-summary-hide-thread))
10161         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10162   (gnus-summary-position-point))
10163
10164 (defun gnus-summary-hide-thread ()
10165   "Hide thread subtrees.
10166 If PREDICATE is supplied, threads that satisfy this predicate
10167 will not be hidden.
10168 Returns nil if no threads were there to be hidden."
10169   (interactive)
10170   (let ((buffer-read-only nil)
10171         (start (point))
10172         (article (gnus-summary-article-number)))
10173     (goto-char start)
10174     ;; Go forward until either the buffer ends or the subthread
10175     ;; ends.
10176     (when (and (not (eobp))
10177                (or (zerop (gnus-summary-next-thread 1 t))
10178                    (goto-char (point-max))))
10179       (prog1
10180           (if (and (> (point) start)
10181                    (search-backward "\n" start t))
10182               (progn
10183                 (subst-char-in-region start (point) ?\n ?\^M)
10184                 (gnus-summary-goto-subject article))
10185             (goto-char start)
10186             nil)))))
10187
10188 (defun gnus-summary-go-to-next-thread (&optional previous)
10189   "Go to the same level (or less) next thread.
10190 If PREVIOUS is non-nil, go to previous thread instead.
10191 Return the article number moved to, or nil if moving was impossible."
10192   (let ((level (gnus-summary-thread-level))
10193         (way (if previous -1 1))
10194         (beg (point)))
10195     (forward-line way)
10196     (while (and (not (eobp))
10197                 (< level (gnus-summary-thread-level)))
10198       (forward-line way))
10199     (if (eobp)
10200         (progn
10201           (goto-char beg)
10202           nil)
10203       (setq beg (point))
10204       (prog1
10205           (gnus-summary-article-number)
10206         (goto-char beg)))))
10207
10208 (defun gnus-summary-next-thread (n &optional silent)
10209   "Go to the same level next N'th thread.
10210 If N is negative, search backward instead.
10211 Returns the difference between N and the number of skips actually
10212 done.
10213
10214 If SILENT, don't output messages."
10215   (interactive "p")
10216   (let ((backward (< n 0))
10217         (n (abs n)))
10218     (while (and (> n 0)
10219                 (gnus-summary-go-to-next-thread backward))
10220       (decf n))
10221     (unless silent
10222       (gnus-summary-position-point))
10223     (when (and (not silent) (/= 0 n))
10224       (gnus-message 7 "No more threads"))
10225     n))
10226
10227 (defun gnus-summary-prev-thread (n)
10228   "Go to the same level previous N'th thread.
10229 Returns the difference between N and the number of skips actually
10230 done."
10231   (interactive "p")
10232   (gnus-summary-next-thread (- n)))
10233
10234 (defun gnus-summary-go-down-thread ()
10235   "Go down one level in the current thread."
10236   (let ((children (gnus-summary-article-children)))
10237     (when children
10238       (gnus-summary-goto-subject (car children)))))
10239
10240 (defun gnus-summary-go-up-thread ()
10241   "Go up one level in the current thread."
10242   (let ((parent (gnus-summary-article-parent)))
10243     (when parent
10244       (gnus-summary-goto-subject parent))))
10245
10246 (defun gnus-summary-down-thread (n)
10247   "Go down thread N steps.
10248 If N is negative, go up instead.
10249 Returns the difference between N and how many steps down that were
10250 taken."
10251   (interactive "p")
10252   (let ((up (< n 0))
10253         (n (abs n)))
10254     (while (and (> n 0)
10255                 (if up (gnus-summary-go-up-thread)
10256                   (gnus-summary-go-down-thread)))
10257       (setq n (1- n)))
10258     (gnus-summary-position-point)
10259     (when (/= 0 n)
10260       (gnus-message 7 "Can't go further"))
10261     n))
10262
10263 (defun gnus-summary-up-thread (n)
10264   "Go up thread N steps.
10265 If N is negative, go down instead.
10266 Returns the difference between N and how many steps down that were
10267 taken."
10268   (interactive "p")
10269   (gnus-summary-down-thread (- n)))
10270
10271 (defun gnus-summary-top-thread ()
10272   "Go to the top of the thread."
10273   (interactive)
10274   (while (gnus-summary-go-up-thread))
10275   (gnus-summary-article-number))
10276
10277 (defun gnus-summary-kill-thread (&optional unmark)
10278   "Mark articles under current thread as read.
10279 If the prefix argument is positive, remove any kinds of marks.
10280 If the prefix argument is negative, tick articles instead."
10281   (interactive "P")
10282   (when unmark
10283     (setq unmark (prefix-numeric-value unmark)))
10284   (let ((articles (gnus-summary-articles-in-thread)))
10285     (save-excursion
10286       ;; Expand the thread.
10287       (gnus-summary-show-thread)
10288       ;; Mark all the articles.
10289       (while articles
10290         (gnus-summary-goto-subject (car articles))
10291         (cond ((null unmark)
10292                (gnus-summary-mark-article-as-read gnus-killed-mark))
10293               ((> unmark 0)
10294                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10295               (t
10296                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10297         (setq articles (cdr articles))))
10298     ;; Hide killed subtrees.
10299     (and (null unmark)
10300          gnus-thread-hide-killed
10301          (gnus-summary-hide-thread))
10302     ;; If marked as read, go to next unread subject.
10303     (when (null unmark)
10304       ;; Go to next unread subject.
10305       (gnus-summary-next-subject 1 t)))
10306   (gnus-set-mode-line 'summary))
10307
10308 ;; Summary sorting commands
10309
10310 (defun gnus-summary-sort-by-number (&optional reverse)
10311   "Sort the summary buffer by article number.
10312 Argument REVERSE means reverse order."
10313   (interactive "P")
10314   (gnus-summary-sort 'number reverse))
10315
10316 (defun gnus-summary-sort-by-random (&optional reverse)
10317   "Randomize the order in the summary buffer.
10318 Argument REVERSE means to randomize in reverse order."
10319   (interactive "P")
10320   (gnus-summary-sort 'random reverse))
10321
10322 (defun gnus-summary-sort-by-author (&optional reverse)
10323   "Sort the summary buffer by author name alphabetically.
10324 If `case-fold-search' is non-nil, case of letters is ignored.
10325 Argument REVERSE means reverse order."
10326   (interactive "P")
10327   (gnus-summary-sort 'author reverse))
10328
10329 (defun gnus-summary-sort-by-subject (&optional reverse)
10330   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10331 If `case-fold-search' is non-nil, case of letters is ignored.
10332 Argument REVERSE means reverse order."
10333   (interactive "P")
10334   (gnus-summary-sort 'subject reverse))
10335
10336 (defun gnus-summary-sort-by-date (&optional reverse)
10337   "Sort the summary buffer by date.
10338 Argument REVERSE means reverse order."
10339   (interactive "P")
10340   (gnus-summary-sort 'date reverse))
10341
10342 (defun gnus-summary-sort-by-score (&optional reverse)
10343   "Sort the summary buffer by score.
10344 Argument REVERSE means reverse order."
10345   (interactive "P")
10346   (gnus-summary-sort 'score reverse))
10347
10348 (defun gnus-summary-sort-by-lines (&optional reverse)
10349   "Sort the summary buffer by the number of lines.
10350 Argument REVERSE means reverse order."
10351   (interactive "P")
10352   (gnus-summary-sort 'lines reverse))
10353
10354 (defun gnus-summary-sort-by-chars (&optional reverse)
10355   "Sort the summary buffer by article length.
10356 Argument REVERSE means reverse order."
10357   (interactive "P")
10358   (gnus-summary-sort 'chars reverse))
10359
10360 (defun gnus-summary-sort-by-original (&optional reverse)
10361   "Sort the summary buffer using the default sorting method.
10362 Argument REVERSE means reverse order."
10363   (interactive "P")
10364   (let* ((buffer-read-only)
10365          (gnus-summary-prepare-hook nil))
10366     ;; We do the sorting by regenerating the threads.
10367     (gnus-summary-prepare)
10368     ;; Hide subthreads if needed.
10369     (gnus-summary-maybe-hide-threads)))
10370
10371 (defun gnus-summary-sort (predicate reverse)
10372   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10373   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10374          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10375          (gnus-thread-sort-functions
10376           (if (not reverse)
10377               thread
10378             `(lambda (t1 t2)
10379                (,thread t2 t1))))
10380          (gnus-sort-gathered-threads-function
10381           gnus-thread-sort-functions)
10382          (gnus-article-sort-functions
10383           (if (not reverse)
10384               article
10385             `(lambda (t1 t2)
10386                (,article t2 t1))))
10387          (buffer-read-only)
10388          (gnus-summary-prepare-hook nil))
10389     ;; We do the sorting by regenerating the threads.
10390     (gnus-summary-prepare)
10391     ;; Hide subthreads if needed.
10392     (gnus-summary-maybe-hide-threads)))
10393
10394 ;; Summary saving commands.
10395
10396 (defun gnus-summary-save-article (&optional n not-saved)
10397   "Save the current article using the default saver function.
10398 If N is a positive number, save the N next articles.
10399 If N is a negative number, save the N previous articles.
10400 If N is nil and any articles have been marked with the process mark,
10401 save those articles instead.
10402 The variable `gnus-default-article-saver' specifies the saver function."
10403   (interactive "P")
10404   (let* ((articles (gnus-summary-work-articles n))
10405          (save-buffer (save-excursion
10406                         (nnheader-set-temp-buffer " *Gnus Save*")))
10407          (num (length articles))
10408          header file)
10409     (dolist (article articles)
10410       (setq header (gnus-summary-article-header article))
10411       (if (not (vectorp header))
10412           ;; This is a pseudo-article.
10413           (if (assq 'name header)
10414               (gnus-copy-file (cdr (assq 'name header)))
10415             (gnus-message 1 "Article %d is unsaveable" article))
10416         ;; This is a real article.
10417         (save-window-excursion
10418           (let ((gnus-display-mime-function nil)
10419                 (gnus-article-prepare-hook nil))
10420             (gnus-summary-select-article t nil nil article)))
10421         (save-excursion
10422           (set-buffer save-buffer)
10423           (erase-buffer)
10424           (insert-buffer-substring gnus-original-article-buffer))
10425         (setq file (gnus-article-save save-buffer file num))
10426         (gnus-summary-remove-process-mark article)
10427         (unless not-saved
10428           (gnus-summary-set-saved-mark article))))
10429     (gnus-kill-buffer save-buffer)
10430     (gnus-summary-position-point)
10431     (gnus-set-mode-line 'summary)
10432     n))
10433
10434 (defun gnus-summary-pipe-output (&optional arg)
10435   "Pipe the current article to a subprocess.
10436 If N is a positive number, pipe the N next articles.
10437 If N is a negative number, pipe the N previous articles.
10438 If N is nil and any articles have been marked with the process mark,
10439 pipe those articles instead."
10440   (interactive "P")
10441   (require 'gnus-art)
10442   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10443     (gnus-summary-save-article arg t))
10444   (let ((buffer (get-buffer "*Shell Command Output*")))
10445     (if (and buffer
10446              (with-current-buffer buffer (> (point-max) (point-min))))
10447         (gnus-configure-windows 'pipe))))
10448
10449 (defun gnus-summary-save-article-mail (&optional arg)
10450   "Append the current article to an mail file.
10451 If N is a positive number, save the N next articles.
10452 If N is a negative number, save the N previous articles.
10453 If N is nil and any articles have been marked with the process mark,
10454 save those articles instead."
10455   (interactive "P")
10456   (require 'gnus-art)
10457   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10458     (gnus-summary-save-article arg)))
10459
10460 (defun gnus-summary-save-article-rmail (&optional arg)
10461   "Append the current article to an rmail file.
10462 If N is a positive number, save the N next articles.
10463 If N is a negative number, save the N previous articles.
10464 If N is nil and any articles have been marked with the process mark,
10465 save those articles instead."
10466   (interactive "P")
10467   (require 'gnus-art)
10468   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10469     (gnus-summary-save-article arg)))
10470
10471 (defun gnus-summary-save-article-file (&optional arg)
10472   "Append the current article to a file.
10473 If N is a positive number, save the N next articles.
10474 If N is a negative number, save the N previous articles.
10475 If N is nil and any articles have been marked with the process mark,
10476 save those articles instead."
10477   (interactive "P")
10478   (require 'gnus-art)
10479   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10480     (gnus-summary-save-article arg)))
10481
10482 (defun gnus-summary-write-article-file (&optional arg)
10483   "Write the current article to a file, deleting the previous file.
10484 If N is a positive number, save the N next articles.
10485 If N is a negative number, save the N previous articles.
10486 If N is nil and any articles have been marked with the process mark,
10487 save those articles instead."
10488   (interactive "P")
10489   (require 'gnus-art)
10490   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10491     (gnus-summary-save-article arg)))
10492
10493 (defun gnus-summary-save-article-body-file (&optional arg)
10494   "Append the current article body to a file.
10495 If N is a positive number, save the N next articles.
10496 If N is a negative number, save the N previous articles.
10497 If N is nil and any articles have been marked with the process mark,
10498 save those articles instead."
10499   (interactive "P")
10500   (require 'gnus-art)
10501   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10502     (gnus-summary-save-article arg)))
10503
10504 (defun gnus-summary-muttprint (&optional arg)
10505   "Print the current article using Muttprint.
10506 If N is a positive number, save the N next articles.
10507 If N is a negative number, save the N previous articles.
10508 If N is nil and any articles have been marked with the process mark,
10509 save those articles instead."
10510   (interactive "P")
10511   (require 'gnus-art)
10512   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10513     (gnus-summary-save-article arg t)))
10514
10515 (defun gnus-summary-pipe-message (program)
10516   "Pipe the current article through PROGRAM."
10517   (interactive "sProgram: ")
10518   (gnus-summary-select-article)
10519   (let ((mail-header-separator ""))
10520     (gnus-eval-in-buffer-window gnus-article-buffer
10521       (save-restriction
10522         (widen)
10523         (let ((start (window-start))
10524               buffer-read-only)
10525           (message-pipe-buffer-body program)
10526           (set-window-start (get-buffer-window (current-buffer)) start))))))
10527
10528 (defun gnus-get-split-value (methods)
10529   "Return a value based on the split METHODS."
10530   (let (split-name method result match)
10531     (when methods
10532       (save-excursion
10533         (set-buffer gnus-original-article-buffer)
10534         (save-restriction
10535           (nnheader-narrow-to-headers)
10536           (while (and methods (not split-name))
10537             (goto-char (point-min))
10538             (setq method (pop methods))
10539             (setq match (car method))
10540             (when (cond
10541                    ((stringp match)
10542                     ;; Regular expression.
10543                     (ignore-errors
10544                       (re-search-forward match nil t)))
10545                    ((gnus-functionp match)
10546                     ;; Function.
10547                     (save-restriction
10548                       (widen)
10549                       (setq result (funcall match gnus-newsgroup-name))))
10550                    ((consp match)
10551                     ;; Form.
10552                     (save-restriction
10553                       (widen)
10554                       (setq result (eval match)))))
10555               (setq split-name (cdr method))
10556               (cond ((stringp result)
10557                      (push (expand-file-name
10558                             result gnus-article-save-directory)
10559                            split-name))
10560                     ((consp result)
10561                      (setq split-name (append result split-name)))))))))
10562     (nreverse split-name)))
10563
10564 (defun gnus-valid-move-group-p (group)
10565   (and (boundp group)
10566        (symbol-name group)
10567        (symbol-value group)
10568        (gnus-get-function (gnus-find-method-for-group
10569                            (symbol-name group)) 'request-accept-article t)))
10570
10571 (defun gnus-read-move-group-name (prompt default articles prefix)
10572   "Read a group name."
10573   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10574          (minibuffer-confirm-incomplete nil) ; XEmacs
10575          (prom
10576           (format "%s %s to:"
10577                   prompt
10578                   (if (> (length articles) 1)
10579                       (format "these %d articles" (length articles))
10580                     "this article")))
10581          (to-newsgroup
10582           (cond
10583            ((null split-name)
10584             (gnus-completing-read-with-default
10585              default prom
10586              gnus-active-hashtb
10587              'gnus-valid-move-group-p
10588              nil prefix
10589              'gnus-group-history))
10590            ((= 1 (length split-name))
10591             (gnus-completing-read-with-default
10592              (car split-name) prom
10593              gnus-active-hashtb
10594              'gnus-valid-move-group-p
10595              nil nil
10596              'gnus-group-history))
10597            (t
10598             (gnus-completing-read-with-default
10599              nil prom
10600              (mapcar (lambda (el) (list el))
10601                      (nreverse split-name))
10602              nil nil nil
10603              'gnus-group-history))))
10604          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10605     (when to-newsgroup
10606       (if (or (string= to-newsgroup "")
10607               (string= to-newsgroup prefix))
10608           (setq to-newsgroup default))
10609       (unless to-newsgroup
10610         (error "No group name entered"))
10611       (or (gnus-active to-newsgroup)
10612           (gnus-activate-group to-newsgroup nil nil to-method)
10613           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10614                                      to-newsgroup))
10615               (or (and (gnus-request-create-group to-newsgroup to-method)
10616                        (gnus-activate-group
10617                         to-newsgroup nil nil to-method)
10618                        (gnus-subscribe-group to-newsgroup))
10619                   (error "Couldn't create group %s" to-newsgroup)))
10620           (error "No such group: %s" to-newsgroup)))
10621     to-newsgroup))
10622
10623 (defun gnus-summary-save-parts (type dir n &optional reverse)
10624   "Save parts matching TYPE to DIR.
10625 If REVERSE, save parts that do not match TYPE."
10626   (interactive
10627    (list (read-string "Save parts of type: "
10628                       (or (car gnus-summary-save-parts-type-history)
10629                           gnus-summary-save-parts-default-mime)
10630                       'gnus-summary-save-parts-type-history)
10631          (setq gnus-summary-save-parts-last-directory
10632                (read-file-name "Save to directory: "
10633                                gnus-summary-save-parts-last-directory
10634                                nil t))
10635          current-prefix-arg))
10636   (gnus-summary-iterate n
10637     (let ((gnus-display-mime-function nil)
10638           (gnus-inhibit-treatment t))
10639       (gnus-summary-select-article))
10640     (save-excursion
10641       (set-buffer gnus-article-buffer)
10642       (let ((handles (or gnus-article-mime-handles
10643                          (mm-dissect-buffer nil gnus-article-loose-mime)
10644                          (mm-uu-dissect))))
10645         (when handles
10646           (gnus-summary-save-parts-1 type dir handles reverse)
10647           (unless gnus-article-mime-handles ;; Don't destroy this case.
10648             (mm-destroy-parts handles)))))))
10649
10650 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10651   (if (stringp (car handle))
10652       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10653               (cdr handle))
10654     (when (if reverse
10655               (not (string-match type (mm-handle-media-type handle)))
10656             (string-match type (mm-handle-media-type handle)))
10657       (let ((file (expand-file-name
10658                    (file-name-nondirectory
10659                     (or
10660                      (mail-content-type-get
10661                       (mm-handle-disposition handle) 'filename)
10662                      (concat gnus-newsgroup-name
10663                              "." (number-to-string
10664                                   (cdr gnus-article-current)))))
10665                    dir)))
10666         (unless (file-exists-p file)
10667           (mm-save-part-to-file handle file))))))
10668
10669 ;; Summary extract commands
10670
10671 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10672   (let ((buffer-read-only nil)
10673         (article (gnus-summary-article-number))
10674         after-article b e)
10675     (unless (gnus-summary-goto-subject article)
10676       (error "No such article: %d" article))
10677     (gnus-summary-position-point)
10678     ;; If all commands are to be bunched up on one line, we collect
10679     ;; them here.
10680     (unless gnus-view-pseudos-separately
10681       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10682             files action)
10683         (while ps
10684           (setq action (cdr (assq 'action (car ps))))
10685           (setq files (list (cdr (assq 'name (car ps)))))
10686           (while (and ps (cdr ps)
10687                       (string= (or action "1")
10688                                (or (cdr (assq 'action (cadr ps))) "2")))
10689             (push (cdr (assq 'name (cadr ps))) files)
10690             (setcdr ps (cddr ps)))
10691           (when files
10692             (when (not (string-match "%s" action))
10693               (push " " files))
10694             (push " " files)
10695             (when (assq 'execute (car ps))
10696               (setcdr (assq 'execute (car ps))
10697                       (funcall (if (string-match "%s" action)
10698                                    'format 'concat)
10699                                action
10700                                (mapconcat
10701                                 (lambda (f)
10702                                   (if (equal f " ")
10703                                       f
10704                                     (mm-quote-arg f)))
10705                                 files " ")))))
10706           (setq ps (cdr ps)))))
10707     (if (and gnus-view-pseudos (not not-view))
10708         (while pslist
10709           (when (assq 'execute (car pslist))
10710             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10711                                   (eq gnus-view-pseudos 'not-confirm)))
10712           (setq pslist (cdr pslist)))
10713       (save-excursion
10714         (while pslist
10715           (setq after-article (or (cdr (assq 'article (car pslist)))
10716                                   (gnus-summary-article-number)))
10717           (gnus-summary-goto-subject after-article)
10718           (forward-line 1)
10719           (setq b (point))
10720           (insert "    " (file-name-nondirectory
10721                           (cdr (assq 'name (car pslist))))
10722                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10723           (setq e (point))
10724           (forward-line -1)             ; back to `b'
10725           (gnus-add-text-properties
10726            b (1- e) (list 'gnus-number gnus-reffed-article-number
10727                           gnus-mouse-face-prop gnus-mouse-face))
10728           (gnus-data-enter
10729            after-article gnus-reffed-article-number
10730            gnus-unread-mark b (car pslist) 0 (- e b))
10731           (setq gnus-newsgroup-unreads
10732                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10733                                          gnus-reffed-article-number))
10734           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10735           (setq pslist (cdr pslist)))))))
10736
10737 (defun gnus-pseudos< (p1 p2)
10738   (let ((c1 (cdr (assq 'action p1)))
10739         (c2 (cdr (assq 'action p2))))
10740     (and c1 c2 (string< c1 c2))))
10741
10742 (defun gnus-request-pseudo-article (props)
10743   (cond ((assq 'execute props)
10744          (gnus-execute-command (cdr (assq 'execute props)))))
10745   (let ((gnus-current-article (gnus-summary-article-number)))
10746     (gnus-run-hooks 'gnus-mark-article-hook)))
10747
10748 (defun gnus-execute-command (command &optional automatic)
10749   (save-excursion
10750     (gnus-article-setup-buffer)
10751     (set-buffer gnus-article-buffer)
10752     (setq buffer-read-only nil)
10753     (let ((command (if automatic command
10754                      (read-string "Command: " (cons command 0)))))
10755       (erase-buffer)
10756       (insert "$ " command "\n\n")
10757       (if gnus-view-pseudo-asynchronously
10758           (start-process "gnus-execute" (current-buffer) shell-file-name
10759                          shell-command-switch command)
10760         (call-process shell-file-name nil t nil
10761                       shell-command-switch command)))))
10762
10763 ;; Summary kill commands.
10764
10765 (defun gnus-summary-edit-global-kill (article)
10766   "Edit the \"global\" kill file."
10767   (interactive (list (gnus-summary-article-number)))
10768   (gnus-group-edit-global-kill article))
10769
10770 (defun gnus-summary-edit-local-kill ()
10771   "Edit a local kill file applied to the current newsgroup."
10772   (interactive)
10773   (setq gnus-current-headers (gnus-summary-article-header))
10774   (gnus-group-edit-local-kill
10775    (gnus-summary-article-number) gnus-newsgroup-name))
10776
10777 ;;; Header reading.
10778
10779 (defun gnus-read-header (id &optional header)
10780   "Read the headers of article ID and enter them into the Gnus system."
10781   (let ((group gnus-newsgroup-name)
10782         (gnus-override-method
10783          (or
10784           gnus-override-method
10785           (and (gnus-news-group-p gnus-newsgroup-name)
10786                (car (gnus-refer-article-methods)))))
10787         where)
10788     ;; First we check to see whether the header in question is already
10789     ;; fetched.
10790     (if (stringp id)
10791         ;; This is a Message-ID.
10792         (setq header (or header (gnus-id-to-header id)))
10793       ;; This is an article number.
10794       (setq header (or header (gnus-summary-article-header id))))
10795     (if (and header
10796              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10797         ;; We have found the header.
10798         header
10799       ;; If this is a sparse article, we have to nix out its
10800       ;; previous entry in the thread hashtb.
10801       (when (and header
10802                  (gnus-summary-article-sparse-p (mail-header-number header)))
10803         (let* ((parent (gnus-parent-id (mail-header-references header)))
10804                (thread (and parent (gnus-id-to-thread parent))))
10805           (when thread
10806             (delq (assq header thread) thread))))
10807       ;; We have to really fetch the header to this article.
10808       (save-excursion
10809         (set-buffer nntp-server-buffer)
10810         (when (setq where (gnus-request-head id group))
10811           (nnheader-fold-continuation-lines)
10812           (goto-char (point-max))
10813           (insert ".\n")
10814           (goto-char (point-min))
10815           (insert "211 ")
10816           (princ (cond
10817                   ((numberp id) id)
10818                   ((cdr where) (cdr where))
10819                   (header (mail-header-number header))
10820                   (t gnus-reffed-article-number))
10821                  (current-buffer))
10822           (insert " Article retrieved.\n"))
10823         (if (or (not where)
10824                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10825             ()                          ; Malformed head.
10826           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10827             (when (and (stringp id)
10828                        (not (string= (gnus-group-real-name group)
10829                                      (car where))))
10830               ;; If we fetched by Message-ID and the article came
10831               ;; from a different group, we fudge some bogus article
10832               ;; numbers for this article.
10833               (mail-header-set-number header gnus-reffed-article-number))
10834             (save-excursion
10835               (set-buffer gnus-summary-buffer)
10836               (decf gnus-reffed-article-number)
10837               (gnus-remove-header (mail-header-number header))
10838               (push header gnus-newsgroup-headers)
10839               (setq gnus-current-headers header)
10840               (push (mail-header-number header) gnus-newsgroup-limit)))
10841           header)))))
10842
10843 (defun gnus-remove-header (number)
10844   "Remove header NUMBER from `gnus-newsgroup-headers'."
10845   (if (and gnus-newsgroup-headers
10846            (= number (mail-header-number (car gnus-newsgroup-headers))))
10847       (pop gnus-newsgroup-headers)
10848     (let ((headers gnus-newsgroup-headers))
10849       (while (and (cdr headers)
10850                   (not (= number (mail-header-number (cadr headers)))))
10851         (pop headers))
10852       (when (cdr headers)
10853         (setcdr headers (cddr headers))))))
10854
10855 ;;;
10856 ;;; summary highlights
10857 ;;;
10858
10859 (defun gnus-highlight-selected-summary ()
10860   "Highlight selected article in summary buffer."
10861   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10862   (when gnus-summary-selected-face
10863     (save-excursion
10864       (let* ((beg (progn (beginning-of-line) (point)))
10865              (end (progn (end-of-line) (point)))
10866              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10867              (from (if (get-text-property beg gnus-mouse-face-prop)
10868                        beg
10869                      (or (next-single-property-change
10870                           beg gnus-mouse-face-prop nil end)
10871                          beg)))
10872              (to
10873               (if (= from end)
10874                   (- from 2)
10875                 (or (next-single-property-change
10876                      from gnus-mouse-face-prop nil end)
10877                     end))))
10878         ;; If no mouse-face prop on line we will have to = from = end,
10879         ;; so we highlight the entire line instead.
10880         (when (= (+ to 2) from)
10881           (setq from beg)
10882           (setq to end))
10883         (if gnus-newsgroup-selected-overlay
10884             ;; Move old overlay.
10885             (gnus-move-overlay
10886              gnus-newsgroup-selected-overlay from to (current-buffer))
10887           ;; Create new overlay.
10888           (gnus-overlay-put
10889            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10890            'face gnus-summary-selected-face))))))
10891
10892 (eval-when-compile
10893 (defvar gnus-summary-highlight-line-cached nil)
10894   (defvar gnus-summary-highlight-line-trigger nil))
10895
10896 (defun gnus-summary-highlight-line-0 ()
10897   (if (and (eq gnus-summary-highlight-line-trigger 
10898                gnus-summary-highlight)
10899            gnus-summary-highlight-line-cached)
10900       gnus-summary-highlight-line-cached
10901     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
10902           gnus-summary-highlight-line-cached
10903           (let* ((cond (list 'cond))
10904                  (c cond)
10905                  (list gnus-summary-highlight))
10906             (while list
10907               (setcdr c (cons (list (caar list) (list 'quote (cdar list))) nil))
10908               (setq c (cdr c)
10909                     list (cdr list)))
10910             (gnus-byte-compile (list 'lambda nil cond))))))
10911
10912 (eval-when-compile
10913 (defvar gnus-summary-highlight-line-downloaded-alist nil)
10914   (defvar gnus-summary-highlight-line-downloaded-cached nil))
10915
10916 (defun gnus-summary-highlight-line ()
10917   "Highlight current line according to `gnus-summary-highlight'."
10918   (let*
10919       ((list gnus-summary-highlight)
10920        (beg (gnus-point-at-bol))
10921          (article (or (gnus-summary-article-number) gnus-current-article))
10922          (score (or (cdr (assq article
10923                              gnus-newsgroup-scored))
10924                   gnus-summary-default-score 0))
10925        (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10926        (inhibit-read-only t)
10927        (default gnus-summary-default-score)
10928        (default-high gnus-summary-default-high-score)
10929        (default-low gnus-summary-default-low-score)
10930          (uncached (memq article gnus-newsgroup-undownloaded))
10931          (downloaded (not uncached))
10932          )
10933     (let ((face (funcall (gnus-summary-highlight-line-0))))
10934       (unless (eq face (get-text-property beg 'face))
10935         (gnus-put-text-property-excluding-characters-with-faces
10936          beg (gnus-point-at-eol) 'face
10937          (setq face (if (boundp face) (symbol-value face) face)))
10938         (when gnus-summary-highlight-line-function
10939           (funcall gnus-summary-highlight-line-function article face))))))
10940
10941 (defun gnus-update-read-articles (group unread &optional compute)
10942   "Update the list of read articles in GROUP.
10943 UNREAD is a sorted list."
10944   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10945          (entry (gnus-gethash group gnus-newsrc-hashtb))
10946          (info (nth 2 entry))
10947          (prev 1)
10948          read)
10949     (if (or (not info) (not active))
10950         ;; There is no info on this group if it was, in fact,
10951         ;; killed.  Gnus stores no information on killed groups, so
10952         ;; there's nothing to be done.
10953         ;; One could store the information somewhere temporarily,
10954         ;; perhaps...  Hmmm...
10955         ()
10956       ;; Remove any negative articles numbers.
10957       (while (and unread (< (car unread) 0))
10958         (setq unread (cdr unread)))
10959       ;; Remove any expired article numbers
10960       (while (and unread (< (car unread) (car active)))
10961         (setq unread (cdr unread)))
10962       ;; Compute the ranges of read articles by looking at the list of
10963       ;; unread articles.
10964       (while unread
10965         (when (/= (car unread) prev)
10966           (push (if (= prev (1- (car unread))) prev
10967                   (cons prev (1- (car unread))))
10968                 read))
10969         (setq prev (1+ (car unread)))
10970         (setq unread (cdr unread)))
10971       (when (<= prev (cdr active))
10972         (push (cons prev (cdr active)) read))
10973       (setq read (if (> (length read) 1) (nreverse read) read))
10974       (if compute
10975           read
10976         (save-excursion
10977           (let (setmarkundo)
10978             ;; Propagate the read marks to the backend.
10979             (when (gnus-check-backend-function 'request-set-mark group)
10980               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10981                     (add (gnus-remove-from-range read (gnus-info-read info))))
10982                 (when (or add del)
10983                   (unless (gnus-check-group group)
10984                     (error "Can't open server for %s" group))
10985                   (gnus-request-set-mark
10986                    group (delq nil (list (if add (list add 'add '(read)))
10987                                          (if del (list del 'del '(read))))))
10988                   (setq setmarkundo
10989                         `(gnus-request-set-mark
10990                           ,group
10991                           ',(delq nil (list
10992                                        (if del (list del 'add '(read)))
10993                                        (if add (list add 'del '(read))))))))))
10994             (set-buffer gnus-group-buffer)
10995             (gnus-undo-register
10996               `(progn
10997                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10998                  (gnus-info-set-read ',info ',(gnus-info-read info))
10999                  (gnus-get-unread-articles-in-group ',info
11000                                                     (gnus-active ,group))
11001                  (gnus-group-update-group ,group t)
11002                  ,setmarkundo))))
11003         ;; Enter this list into the group info.
11004         (gnus-info-set-read info read)
11005         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11006         (gnus-get-unread-articles-in-group info (gnus-active group))
11007         t))))
11008
11009 (defun gnus-offer-save-summaries ()
11010   "Offer to save all active summary buffers."
11011   (let (buffers)
11012     ;; Go through all buffers and find all summaries.
11013     (dolist (buffer (buffer-list))
11014       (when (and (setq buffer (buffer-name buffer))
11015                  (string-match "Summary" buffer)
11016                  (save-excursion
11017                    (set-buffer buffer)
11018                    ;; We check that this is, indeed, a summary buffer.
11019                    (and (eq major-mode 'gnus-summary-mode)
11020                         ;; Also make sure this isn't bogus.
11021                         gnus-newsgroup-prepared
11022                         ;; Also make sure that this isn't a
11023                         ;; dead summary buffer.
11024                         (not gnus-dead-summary-mode))))
11025         (push buffer buffers)))
11026     ;; Go through all these summary buffers and offer to save them.
11027     (when buffers
11028       (save-excursion
11029         (map-y-or-n-p
11030          "Update summary buffer %s? "
11031          (lambda (buf)
11032            (switch-to-buffer buf)
11033            (gnus-summary-exit))
11034          buffers)))))
11035
11036 (defun gnus-summary-setup-default-charset ()
11037   "Setup newsgroup default charset."
11038   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11039       (setq gnus-newsgroup-charset nil)
11040     (let* ((ignored-charsets
11041             (or gnus-newsgroup-ephemeral-ignored-charsets
11042                 (append
11043                  (and gnus-newsgroup-name
11044                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11045                  gnus-newsgroup-ignored-charsets))))
11046       (setq gnus-newsgroup-charset
11047             (or gnus-newsgroup-ephemeral-charset
11048                 (and gnus-newsgroup-name
11049                      (gnus-parameter-charset gnus-newsgroup-name))
11050                 gnus-default-charset))
11051       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11052            ignored-charsets))))
11053
11054 ;;;
11055 ;;; Mime Commands
11056 ;;;
11057
11058 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11059   "Display the current article buffer fully MIME-buttonized.
11060 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11061 treated as multipart/mixed."
11062   (interactive "P")
11063   (require 'gnus-art)
11064   (let ((gnus-unbuttonized-mime-types nil)
11065         (gnus-mime-display-multipart-as-mixed show-all-parts))
11066     (gnus-summary-show-article)))
11067
11068 (defun gnus-summary-repair-multipart (article)
11069   "Add a Content-Type header to a multipart article without one."
11070   (interactive (list (gnus-summary-article-number)))
11071   (gnus-with-article article
11072     (message-narrow-to-head)
11073     (message-remove-header "Mime-Version")
11074     (goto-char (point-max))
11075     (insert "Mime-Version: 1.0\n")
11076     (widen)
11077     (when (search-forward "\n--" nil t)
11078       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11079         (message-narrow-to-head)
11080         (message-remove-header "Content-Type")
11081         (goto-char (point-max))
11082         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11083                         separator))
11084         (widen))))
11085   (let (gnus-mark-article-hook)
11086     (gnus-summary-select-article t t nil article)))
11087
11088 (defun gnus-summary-toggle-display-buttonized ()
11089   "Toggle the buttonizing of the article buffer."
11090   (interactive)
11091   (require 'gnus-art)
11092   (if (setq gnus-inhibit-mime-unbuttonizing
11093             (not gnus-inhibit-mime-unbuttonizing))
11094       (let ((gnus-unbuttonized-mime-types nil))
11095         (gnus-summary-show-article))
11096     (gnus-summary-show-article)))
11097
11098 ;;;
11099 ;;; Generic summary marking commands
11100 ;;;
11101
11102 (defvar gnus-summary-marking-alist
11103   '((read gnus-del-mark "d")
11104     (unread gnus-unread-mark "u")
11105     (ticked gnus-ticked-mark "!")
11106     (dormant gnus-dormant-mark "?")
11107     (expirable gnus-expirable-mark "e"))
11108   "An alist of names/marks/keystrokes.")
11109
11110 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11111 (defvar gnus-summary-mark-map)
11112
11113 (defun gnus-summary-make-all-marking-commands ()
11114   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11115   (dolist (elem gnus-summary-marking-alist)
11116     (apply 'gnus-summary-make-marking-command elem)))
11117
11118 (defun gnus-summary-make-marking-command (name mark keystroke)
11119   (let ((map (make-sparse-keymap)))
11120     (define-key gnus-summary-generic-mark-map keystroke map)
11121     (dolist (lway `((next "next" next nil "n")
11122                     (next-unread "next unread" next t "N")
11123                     (prev "previous" prev nil "p")
11124                     (prev-unread "previous unread" prev t "P")
11125                     (nomove "" nil nil ,keystroke)))
11126       (let ((func (gnus-summary-make-marking-command-1
11127                    mark (car lway) lway name)))
11128         (setq func (eval func))
11129         (define-key map (nth 4 lway) func)))))
11130
11131 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11132   `(defun ,(intern
11133             (format "gnus-summary-put-mark-as-%s%s"
11134                     name (if (eq way 'nomove)
11135                              ""
11136                            (concat "-" (symbol-name way)))))
11137      (n)
11138      ,(format
11139        "Mark the current article as %s%s.
11140 If N, the prefix, then repeat N times.
11141 If N is negative, move in reverse order.
11142 The difference between N and the actual number of articles marked is
11143 returned."
11144        name (cadr lway))
11145      (interactive "p")
11146      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11147
11148 (defun gnus-summary-generic-mark (n mark move unread)
11149   "Mark N articles with MARK."
11150   (unless (eq major-mode 'gnus-summary-mode)
11151     (error "This command can only be used in the summary buffer"))
11152   (gnus-summary-show-thread)
11153   (let ((nummove
11154          (cond
11155           ((eq move 'next) 1)
11156           ((eq move 'prev) -1)
11157           (t 0))))
11158     (if (zerop nummove)
11159         (setq n 1)
11160       (when (< n 0)
11161         (setq n (abs n)
11162               nummove (* -1 nummove))))
11163     (while (and (> n 0)
11164                 (gnus-summary-mark-article nil mark)
11165                 (zerop (gnus-summary-next-subject nummove unread t)))
11166       (setq n (1- n)))
11167     (when (/= 0 n)
11168       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11169     (gnus-summary-recenter)
11170     (gnus-summary-position-point)
11171     (gnus-set-mode-line 'summary)
11172     n))
11173
11174 (defun gnus-summary-insert-articles (articles)
11175   (when (setq articles
11176               (gnus-sorted-difference articles
11177                                       (mapcar (lambda (h)
11178                                                 (mail-header-number h))
11179                                               gnus-newsgroup-headers)))
11180     (setq gnus-newsgroup-headers
11181           (merge 'list
11182                  gnus-newsgroup-headers
11183                  (gnus-fetch-headers articles)
11184                  'gnus-article-sort-by-number))
11185     ;; Suppress duplicates?
11186     (when gnus-suppress-duplicates
11187       (gnus-dup-suppress-articles))
11188
11189     ;; We might want to build some more threads first.
11190     (when (and gnus-fetch-old-headers
11191                (eq gnus-headers-retrieved-by 'nov))
11192       (if (eq gnus-fetch-old-headers 'invisible)
11193           (gnus-build-all-threads)
11194         (gnus-build-old-threads)))
11195     ;; Let the Gnus agent mark articles as read.
11196     (when gnus-agent
11197       (gnus-agent-get-undownloaded-list))
11198     ;; Remove list identifiers from subject
11199     (when gnus-list-identifiers
11200       (gnus-summary-remove-list-identifiers))
11201     ;; First and last article in this newsgroup.
11202     (when gnus-newsgroup-headers
11203       (setq gnus-newsgroup-begin
11204             (mail-header-number (car gnus-newsgroup-headers))
11205             gnus-newsgroup-end
11206             (mail-header-number
11207              (gnus-last-element gnus-newsgroup-headers))))
11208     (when gnus-use-scoring
11209       (gnus-possibly-score-headers))))
11210
11211 (defun gnus-summary-insert-old-articles (&optional all)
11212   "Insert all old articles in this group.
11213 If ALL is non-nil, already read articles become readable.
11214 If ALL is a number, fetch this number of articles."
11215   (interactive "P")
11216   (prog1
11217       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11218             older len)
11219         (setq older
11220               ;; Some nntp servers lie about their active range.  When
11221               ;; this happens, the active range can be in the millions.
11222               ;; Use a compressed range to avoid creating a huge list.
11223               (gnus-range-difference (list gnus-newsgroup-active) old))
11224         (setq len (gnus-range-length older))
11225         (cond
11226          ((null older) nil)
11227          ((numberp all)
11228           (if (< all len)
11229               (let ((older-range (nreverse older)))
11230                 (setq older nil)
11231
11232                 (while (> all 0)
11233                   (let* ((r (pop older-range))
11234                          (min (if (numberp r) r (car r)))
11235                          (max (if (numberp r) r (cdr r))))
11236                     (while (and (<= min max)
11237                                 (> all 0))
11238                       (push max older)
11239                       (setq all (1- all)
11240                             max (1- max))))))
11241             (setq older (gnus-uncompress-range older))))
11242          (all
11243           (setq older (gnus-uncompress-range older)))
11244          (t
11245           (when (and (numberp gnus-large-newsgroup)
11246                    (> len gnus-large-newsgroup))
11247               (let* ((cursor-in-echo-area nil)
11248                      (initial (gnus-parameter-large-newsgroup-initial
11249                                gnus-newsgroup-name))
11250                      (input
11251                       (read-string
11252                        (format
11253                         "How many articles from %s (%s %d): "
11254                         (gnus-limit-string
11255                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11256                         (if initial "max" "default")
11257                         len)
11258                        (if initial
11259                            (cons (number-to-string initial)
11260                                  0)))))
11261                 (unless (string-match "^[ \t]*$" input)
11262                   (setq all (string-to-number input))
11263                   (if (< all len)
11264                       (let ((older-range (nreverse older)))
11265                         (setq older nil)
11266
11267                         (while (> all 0)
11268                           (let* ((r (pop older-range))
11269                                  (min (if (numberp r) r (car r)))
11270                                  (max (if (numberp r) r (cdr r))))
11271                             (while (and (<= min max)
11272                                         (> all 0))
11273                               (push max older)
11274                               (setq all (1- all)
11275                                     max (1- max))))))))))
11276           (setq older (gnus-uncompress-range older))))
11277         (if (not older)
11278             (message "No old news.")
11279           (gnus-summary-insert-articles older)
11280           (gnus-summary-limit (gnus-sorted-nunion old older))))
11281     (gnus-summary-position-point)))
11282
11283 (defun gnus-summary-insert-new-articles ()
11284   "Insert all new articles in this group."
11285   (interactive)
11286   (prog1
11287       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11288             (old-active gnus-newsgroup-active)
11289             (nnmail-fetched-sources (list t))
11290             i new)
11291         (setq gnus-newsgroup-active
11292               (gnus-activate-group gnus-newsgroup-name 'scan))
11293         (setq i (cdr gnus-newsgroup-active))
11294         (while (> i (cdr old-active))
11295           (push i new)
11296           (decf i))
11297         (if (not new)
11298             (message "No gnus is bad news.")
11299           (gnus-summary-insert-articles new)
11300           (setq gnus-newsgroup-unreads
11301                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11302           (gnus-summary-limit (gnus-sorted-nunion old new))))
11303     (gnus-summary-position-point)))
11304
11305 (gnus-summary-make-all-marking-commands)
11306
11307 (gnus-ems-redefine)
11308
11309 (provide 'gnus-sum)
11310
11311 (run-hooks 'gnus-sum-load-hook)
11312
11313 ;;; gnus-sum.el ends here