9db6095669928eea6ec6d980378485c5ef75d6ee
[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-downloadable-mark ?%
510   "*Mark used for articles that are to be downloaded."
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-unsendable-mark ?=
515   "*Mark used for articles that won't be sent."
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-score-over-mark ?+
520   "*Score mark used for articles with high scores."
521   :group 'gnus-summary-marks
522   :type 'character)
523
524 (defcustom gnus-score-below-mark ?-
525   "*Score mark used for articles with low scores."
526   :group 'gnus-summary-marks
527   :type 'character)
528
529 (defcustom gnus-empty-thread-mark ?     ;Whitespace
530   "*There is no thread under the article."
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-not-empty-thread-mark ?=
535   "*There is a thread under the article."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-view-pseudo-asynchronously nil
540   "*If non-nil, Gnus will view pseudo-articles asynchronously."
541   :group 'gnus-extract-view
542   :type 'boolean)
543
544 (defcustom gnus-auto-expirable-marks
545   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
546         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
547         gnus-souped-mark gnus-duplicate-mark)
548   "*The list of marks converted into expiration if a group is auto-expirable."
549   :version "21.1"
550   :group 'gnus-summary
551   :type '(repeat character))
552
553 (defcustom gnus-inhibit-user-auto-expire t
554   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
555   :version "21.1"
556   :group 'gnus-summary
557   :type 'boolean)
558
559 (defcustom gnus-view-pseudos nil
560   "*If `automatic', pseudo-articles will be viewed automatically.
561 If `not-confirm', pseudos will be viewed automatically, and the user
562 will not be asked to confirm the command."
563   :group 'gnus-extract-view
564   :type '(choice (const :tag "off" nil)
565                  (const automatic)
566                  (const not-confirm)))
567
568 (defcustom gnus-view-pseudos-separately t
569   "*If non-nil, one pseudo-article will be created for each file to be viewed.
570 If nil, all files that use the same viewing command will be given as a
571 list of parameters to that command."
572   :group 'gnus-extract-view
573   :type 'boolean)
574
575 (defcustom gnus-insert-pseudo-articles t
576   "*If non-nil, insert pseudo-articles when decoding articles."
577   :group 'gnus-extract-view
578   :type 'boolean)
579
580 (defcustom gnus-summary-dummy-line-format
581   "  %(:                          :%) %S\n"
582   "*The format specification for the dummy roots in the summary buffer.
583 It works along the same lines as a normal formatting string,
584 with some simple extensions.
585
586 %S  The subject
587
588 General format specifiers can also be used.
589 See `(gnus)Formatting Variables'."
590   :link '(custom-manual "(gnus)Formatting Variables")
591   :group 'gnus-threading
592   :type 'string)
593
594 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
595   "*The format specification for the summary mode line.
596 It works along the same lines as a normal formatting string,
597 with some simple extensions:
598
599 %G  Group name
600 %p  Unprefixed group name
601 %A  Current article number
602 %z  Current article score
603 %V  Gnus version
604 %U  Number of unread articles in the group
605 %e  Number of unselected articles in the group
606 %Z  A string with unread/unselected article counts
607 %g  Shortish group name
608 %S  Subject of the current article
609 %u  User-defined spec
610 %s  Current score file name
611 %d  Number of dormant articles
612 %r  Number of articles that have been marked as read in this session
613 %E  Number of articles expunged by the score files"
614   :group 'gnus-summary-format
615   :type 'string)
616
617 (defcustom gnus-list-identifiers nil
618   "Regexp that matches list identifiers to be removed from subject.
619 This can also be a list of regexps."
620   :version "21.1"
621   :group 'gnus-summary-format
622   :group 'gnus-article-hiding
623   :type '(choice (const :tag "none" nil)
624                  (regexp :value ".*")
625                  (repeat :value (".*") regexp)))
626
627 (defcustom gnus-summary-mark-below 0
628   "*Mark all articles with a score below this variable as read.
629 This variable is local to each summary buffer and usually set by the
630 score file."
631   :group 'gnus-score-default
632   :type 'integer)
633
634 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
635   "*List of functions used for sorting articles in the summary buffer.
636
637 Each function takes two articles and returns non-nil if the first
638 article should be sorted before the other.  If you use more than one
639 function, the primary sort function should be the last.  You should
640 probably always include `gnus-article-sort-by-number' in the list of
641 sorting functions -- preferably first.  Also note that sorting by date
642 is often much slower than sorting by number, and the sorting order is
643 very similar.  (Sorting by date means sorting by the time the message
644 was sent, sorting by number means sorting by arrival time.)
645
646 Ready-made functions include `gnus-article-sort-by-number',
647 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
648 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
649 and `gnus-article-sort-by-score'.
650
651 When threading is turned on, the variable `gnus-thread-sort-functions'
652 controls how articles are sorted."
653   :group 'gnus-summary-sort
654   :type '(repeat (choice (function-item gnus-article-sort-by-number)
655                          (function-item gnus-article-sort-by-author)
656                          (function-item gnus-article-sort-by-subject)
657                          (function-item gnus-article-sort-by-date)
658                          (function-item gnus-article-sort-by-score)
659                          (function-item gnus-article-sort-by-random)
660                          (function :tag "other"))))
661
662 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
663   "*List of functions used for sorting threads in the summary buffer.
664 By default, threads are sorted by article number.
665
666 Each function takes two threads and returns non-nil if the first
667 thread should be sorted before the other.  If you use more than one
668 function, the primary sort function should be the last.  You should
669 probably always include `gnus-thread-sort-by-number' in the list of
670 sorting functions -- preferably first.  Also note that sorting by date
671 is often much slower than sorting by number, and the sorting order is
672 very similar.  (Sorting by date means sorting by the time the message
673 was sent, sorting by number means sorting by arrival time.)
674
675 Ready-made functions include `gnus-thread-sort-by-number',
676 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
677 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
678 `gnus-thread-sort-by-most-recent-number',
679 `gnus-thread-sort-by-most-recent-date',
680 `gnus-thread-sort-by-random', and
681 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
682
683 When threading is turned off, the variable
684 `gnus-article-sort-functions' controls how articles are sorted."
685   :group 'gnus-summary-sort
686   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
687                          (function-item gnus-thread-sort-by-author)
688                          (function-item gnus-thread-sort-by-subject)
689                          (function-item gnus-thread-sort-by-date)
690                          (function-item gnus-thread-sort-by-score)
691                          (function-item gnus-thread-sort-by-total-score)
692                          (function-item gnus-thread-sort-by-random)
693                          (function :tag "other"))))
694
695 (defcustom gnus-thread-score-function '+
696   "*Function used for calculating the total score of a thread.
697
698 The function is called with the scores of the article and each
699 subthread and should then return the score of the thread.
700
701 Some functions you can use are `+', `max', or `min'."
702   :group 'gnus-summary-sort
703   :type 'function)
704
705 (defcustom gnus-summary-expunge-below nil
706   "All articles that have a score less than this variable will be expunged.
707 This variable is local to the summary buffers."
708   :group 'gnus-score-default
709   :type '(choice (const :tag "off" nil)
710                  integer))
711
712 (defcustom gnus-thread-expunge-below nil
713   "All threads that have a total score less than this variable will be expunged.
714 See `gnus-thread-score-function' for en explanation of what a
715 \"thread score\" is.
716
717 This variable is local to the summary buffers."
718   :group 'gnus-threading
719   :group 'gnus-score-default
720   :type '(choice (const :tag "off" nil)
721                  integer))
722
723 (defcustom gnus-summary-mode-hook nil
724   "*A hook for Gnus summary mode.
725 This hook is run before any variables are set in the summary buffer."
726   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
727   :group 'gnus-summary-various
728   :type 'hook)
729
730 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
731 (when (featurep 'xemacs)
732   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
733   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
734   (add-hook 'gnus-summary-mode-hook
735             'gnus-xmas-switch-horizontal-scrollbar-off))
736
737 (defcustom gnus-summary-menu-hook nil
738   "*Hook run after the creation of the summary mode menu."
739   :group 'gnus-summary-visual
740   :type 'hook)
741
742 (defcustom gnus-summary-exit-hook nil
743   "*A hook called on exit from the summary buffer.
744 It will be called with point in the group buffer."
745   :group 'gnus-summary-exit
746   :type 'hook)
747
748 (defcustom gnus-summary-prepare-hook nil
749   "*A hook called after the summary buffer has been generated.
750 If you want to modify the summary buffer, you can use this hook."
751   :group 'gnus-summary-various
752   :type 'hook)
753
754 (defcustom gnus-summary-prepared-hook nil
755   "*A hook called as the last thing after the summary buffer has been generated."
756   :group 'gnus-summary-various
757   :type 'hook)
758
759 (defcustom gnus-summary-generate-hook nil
760   "*A hook run just before generating the summary buffer.
761 This hook is commonly used to customize threading variables and the
762 like."
763   :group 'gnus-summary-various
764   :type 'hook)
765
766 (defcustom gnus-select-group-hook nil
767   "*A hook called when a newsgroup is selected.
768
769 If you'd like to simplify subjects like the
770 `gnus-summary-next-same-subject' command does, you can use the
771 following hook:
772
773  (add-hook gnus-select-group-hook
774            (lambda ()
775              (mapcar (lambda (header)
776                        (mail-header-set-subject
777                         header
778                         (gnus-simplify-subject
779                          (mail-header-subject header) 're-only)))
780                      gnus-newsgroup-headers)))"
781   :group 'gnus-group-select
782   :type 'hook)
783
784 (defcustom gnus-select-article-hook nil
785   "*A hook called when an article is selected."
786   :group 'gnus-summary-choose
787   :type 'hook)
788
789 (defcustom gnus-visual-mark-article-hook
790   (list 'gnus-highlight-selected-summary)
791   "*Hook run after selecting an article in the summary buffer.
792 It is meant to be used for highlighting the article in some way.  It
793 is not run if `gnus-visual' is nil."
794   :group 'gnus-summary-visual
795   :type 'hook)
796
797 (defcustom gnus-parse-headers-hook nil
798   "*A hook called before parsing the headers."
799   :group 'gnus-various
800   :type 'hook)
801
802 (defcustom gnus-exit-group-hook nil
803   "*A hook called when exiting summary mode.
804 This hook is not called from the non-updating exit commands like `Q'."
805   :group 'gnus-various
806   :type 'hook)
807
808 (defcustom gnus-summary-update-hook
809   (list 'gnus-summary-highlight-line)
810   "*A hook called when a summary line is changed.
811 The hook will not be called if `gnus-visual' is nil.
812
813 The default function `gnus-summary-highlight-line' will
814 highlight the line according to the `gnus-summary-highlight'
815 variable."
816   :group 'gnus-summary-visual
817   :type 'hook)
818
819 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
820   "*A hook called when an article is selected for the first time.
821 The hook is intended to mark an article as read (or unread)
822 automatically when it is selected."
823   :group 'gnus-summary-choose
824   :type 'hook)
825
826 (defcustom gnus-group-no-more-groups-hook nil
827   "*A hook run when returning to group mode having no more (unread) groups."
828   :group 'gnus-group-select
829   :type 'hook)
830
831 (defcustom gnus-ps-print-hook nil
832   "*A hook run before ps-printing something from Gnus."
833   :group 'gnus-summary
834   :type 'hook)
835
836 (defcustom gnus-summary-display-arrow
837   (and (fboundp 'display-graphic-p)
838        (display-graphic-p))
839   "*If non-nil, display an arrow highlighting the current article."
840   :version "21.1"
841   :group 'gnus-summary
842   :type 'boolean)
843
844 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
845   "Face used for highlighting the current article in the summary buffer."
846   :group 'gnus-summary-visual
847   :type 'face)
848
849 (defcustom gnus-summary-highlight
850   '(((eq mark gnus-canceled-mark)
851      . gnus-summary-cancelled-face)
852     ((and (> score default-high)
853           (or (eq mark gnus-dormant-mark)
854               (eq mark gnus-ticked-mark)))
855      . gnus-summary-high-ticked-face)
856     ((and (< score default-low)
857           (or (eq mark gnus-dormant-mark)
858               (eq mark gnus-ticked-mark)))
859      . gnus-summary-low-ticked-face)
860     ((or (eq mark gnus-dormant-mark)
861          (eq mark gnus-ticked-mark))
862      . gnus-summary-normal-ticked-face)
863     ((and (> score default-high) (eq mark gnus-ancient-mark))
864      . gnus-summary-high-ancient-face)
865     ((and (< score default-low) (eq mark gnus-ancient-mark))
866      . gnus-summary-low-ancient-face)
867     ((eq mark gnus-ancient-mark)
868      . gnus-summary-normal-ancient-face)
869     (downloaded
870      . gnus-agent-downloaded-article-face)
871     ((and (> score default-high) (eq mark gnus-unread-mark))
872      . gnus-summary-high-unread-face)
873     ((and (< score default-low) (eq mark gnus-unread-mark))
874      . gnus-summary-low-unread-face)
875     ((eq mark gnus-unread-mark)
876      . gnus-summary-normal-unread-face)
877     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
878                                                   gnus-undownloaded-mark)))
879      . gnus-summary-high-unread-face)
880     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
881                                                  gnus-undownloaded-mark)))
882      . gnus-summary-low-unread-face)
883     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
884           (memq article gnus-newsgroup-unreads))
885      . gnus-summary-normal-unread-face)
886     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
887      . gnus-summary-normal-read-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 (defvar gnus-inhibit-mime-unbuttonizing nil)
1047
1048 (defvar gnus-original-article nil)
1049 (defvar gnus-article-internal-prepare-hook nil)
1050 (defvar gnus-newsgroup-process-stack nil)
1051
1052 (defvar gnus-thread-indent-array nil)
1053 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1054 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1055   "Function called to sort the articles within a thread after it has been gathered together.")
1056
1057 (defvar gnus-summary-save-parts-type-history nil)
1058 (defvar gnus-summary-save-parts-last-directory nil)
1059
1060 ;; Avoid highlighting in kill files.
1061 (defvar gnus-summary-inhibit-highlight nil)
1062 (defvar gnus-newsgroup-selected-overlay nil)
1063 (defvar gnus-inhibit-limiting nil)
1064 (defvar gnus-newsgroup-adaptive-score-file nil)
1065 (defvar gnus-current-score-file nil)
1066 (defvar gnus-current-move-group nil)
1067 (defvar gnus-current-copy-group nil)
1068 (defvar gnus-current-crosspost-group nil)
1069 (defvar gnus-newsgroup-display nil)
1070
1071 (defvar gnus-newsgroup-dependencies nil)
1072 (defvar gnus-newsgroup-adaptive nil)
1073 (defvar gnus-summary-display-article-function nil)
1074 (defvar gnus-summary-highlight-line-function nil
1075   "Function called after highlighting a summary line.")
1076
1077 (defvar gnus-summary-line-format-alist
1078   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1079     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1080     (?s gnus-tmp-subject-or-nil ?s)
1081     (?n gnus-tmp-name ?s)
1082     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1083         ?s)
1084     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1085             gnus-tmp-from) ?s)
1086     (?F gnus-tmp-from ?s)
1087     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1088     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1089     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1090     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1091     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1092     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1093     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1094     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1095     (?L gnus-tmp-lines ?s)
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-begin nil)
1156 (defvar gnus-newsgroup-end nil)
1157 (defvar gnus-newsgroup-last-rmail nil)
1158 (defvar gnus-newsgroup-last-mail nil)
1159 (defvar gnus-newsgroup-last-folder nil)
1160 (defvar gnus-newsgroup-last-file nil)
1161 (defvar gnus-newsgroup-auto-expire nil)
1162 (defvar gnus-newsgroup-active nil)
1163
1164 (defvar gnus-newsgroup-data nil)
1165 (defvar gnus-newsgroup-data-reverse nil)
1166 (defvar gnus-newsgroup-limit nil)
1167 (defvar gnus-newsgroup-limits nil)
1168
1169 (defvar gnus-newsgroup-unreads nil
1170   "Sorted list of unread articles in the current newsgroup.")
1171
1172 (defvar gnus-newsgroup-unselected nil
1173   "Sorted list of unselected unread articles in the current newsgroup.")
1174
1175 (defvar gnus-newsgroup-reads nil
1176   "Alist of read articles and article marks in the current newsgroup.")
1177
1178 (defvar gnus-newsgroup-expunged-tally nil)
1179
1180 (defvar gnus-newsgroup-marked nil
1181   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1182
1183 (defvar gnus-newsgroup-spam-marked nil
1184   "List of ranges of articles that have been marked as spam.")
1185
1186 (defvar gnus-newsgroup-killed nil
1187   "List of ranges of articles that have been through the scoring process.")
1188
1189 (defvar gnus-newsgroup-cached nil
1190   "Sorted list of articles that come from the article cache.")
1191
1192 (defvar gnus-newsgroup-saved nil
1193   "List of articles that have been saved.")
1194
1195 (defvar gnus-newsgroup-kill-headers nil)
1196
1197 (defvar gnus-newsgroup-replied nil
1198   "List of articles that have been replied to in the current newsgroup.")
1199
1200 (defvar gnus-newsgroup-forwarded nil
1201   "List of articles that have been forwarded in the current newsgroup.")
1202
1203 (defvar gnus-newsgroup-recent nil
1204   "List of articles that have are recent in the current newsgroup.")
1205
1206 (defvar gnus-newsgroup-expirable nil
1207   "Sorted list of articles in the current newsgroup that can be expired.")
1208
1209 (defvar gnus-newsgroup-processable nil
1210   "List of articles in the current newsgroup that can be processed.")
1211
1212 (defvar gnus-newsgroup-downloadable nil
1213   "Sorted list of articles in the current newsgroup that can be processed.")
1214
1215 (defvar gnus-newsgroup-undownloaded nil
1216   "List of articles in the current newsgroup that haven't been downloaded..")
1217
1218 (defvar gnus-newsgroup-unsendable nil
1219   "List of articles in the current newsgroup that won't be sent.")
1220
1221 (defvar gnus-newsgroup-bookmarks nil
1222   "List of articles in the current newsgroup that have bookmarks.")
1223
1224 (defvar gnus-newsgroup-dormant nil
1225   "Sorted list of dormant articles in the current newsgroup.")
1226
1227 (defvar gnus-newsgroup-unseen nil
1228   "List of unseen articles in the current newsgroup.")
1229
1230 (defvar gnus-newsgroup-seen nil
1231   "Range of seen articles in the current newsgroup.")
1232
1233 (defvar gnus-newsgroup-articles nil
1234   "List of articles in the current newsgroup.")
1235
1236 (defvar gnus-newsgroup-scored nil
1237   "List of scored articles in the current newsgroup.")
1238
1239 (defvar gnus-newsgroup-headers nil
1240   "List of article headers in the current newsgroup.")
1241
1242 (defvar gnus-newsgroup-threads nil)
1243
1244 (defvar gnus-newsgroup-prepared nil
1245   "Whether the current group has been prepared properly.")
1246
1247 (defvar gnus-newsgroup-ancient nil
1248   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-sparse nil)
1251
1252 (defvar gnus-current-article nil)
1253 (defvar gnus-article-current nil)
1254 (defvar gnus-current-headers nil)
1255 (defvar gnus-have-all-headers nil)
1256 (defvar gnus-last-article nil)
1257 (defvar gnus-newsgroup-history nil)
1258 (defvar gnus-newsgroup-charset nil)
1259 (defvar gnus-newsgroup-ephemeral-charset nil)
1260 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1261
1262 (defvar gnus-article-before-search nil)
1263
1264 (defconst gnus-summary-local-variables
1265   '(gnus-newsgroup-name
1266     gnus-newsgroup-begin gnus-newsgroup-end
1267     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1268     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1269     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1270     gnus-newsgroup-unselected gnus-newsgroup-marked
1271     gnus-newsgroup-spam-marked
1272     gnus-newsgroup-reads gnus-newsgroup-saved
1273     gnus-newsgroup-replied gnus-newsgroup-forwarded
1274     gnus-newsgroup-recent
1275     gnus-newsgroup-expirable
1276     gnus-newsgroup-processable gnus-newsgroup-killed
1277     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1278     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1279     gnus-newsgroup-seen gnus-newsgroup-articles
1280     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1281     gnus-newsgroup-headers gnus-newsgroup-threads
1282     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1283     gnus-current-article gnus-current-headers gnus-have-all-headers
1284     gnus-last-article gnus-article-internal-prepare-hook
1285     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1286     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1287     gnus-thread-expunge-below
1288     gnus-score-alist gnus-current-score-file
1289     (gnus-summary-expunge-below . global)
1290     (gnus-summary-mark-below . global)
1291     (gnus-orphan-score . global)
1292     gnus-newsgroup-active gnus-scores-exclude-files
1293     gnus-newsgroup-history gnus-newsgroup-ancient
1294     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1295     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1296     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1297     (gnus-newsgroup-expunged-tally . 0)
1298     gnus-cache-removable-articles gnus-newsgroup-cached
1299     gnus-newsgroup-data gnus-newsgroup-data-reverse
1300     gnus-newsgroup-limit gnus-newsgroup-limits
1301     gnus-newsgroup-charset gnus-newsgroup-display)
1302   "Variables that are buffer-local to the summary buffers.")
1303
1304 (defvar gnus-newsgroup-variables nil
1305   "A list of variables that have separate values in different newsgroups.
1306 A list of newsgroup (summary buffer) local variables, or cons of
1307 variables and their default values (when the default values are not
1308 nil), that should be made global while the summary buffer is active.
1309 These variables can be used to set variables in the group parameters
1310 while still allowing them to affect operations done in other
1311 buffers. For example:
1312
1313 \(setq gnus-newsgroup-variables
1314      '(message-use-followup-to
1315        (gnus-visible-headers .
1316          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1317 ")
1318
1319 ;; Byte-compiler warning.
1320 (eval-when-compile (defvar gnus-article-mode-map))
1321
1322 ;; MIME stuff.
1323
1324 (defvar gnus-decode-encoded-word-methods
1325   '(mail-decode-encoded-word-string)
1326   "List of methods used to decode encoded words.
1327
1328 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1329 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1330 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1331 whose names match REGEXP.
1332
1333 For example:
1334 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1335  mail-decode-encoded-word-string
1336  (\"chinese\" . rfc1843-decode-string))")
1337
1338 (defvar gnus-decode-encoded-word-methods-cache nil)
1339
1340 (defun gnus-multi-decode-encoded-word-string (string)
1341   "Apply the functions from `gnus-encoded-word-methods' that match."
1342   (unless (and gnus-decode-encoded-word-methods-cache
1343                (eq gnus-newsgroup-name
1344                    (car gnus-decode-encoded-word-methods-cache)))
1345     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1346     (mapcar (lambda (x)
1347               (if (symbolp x)
1348                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1349                 (if (and gnus-newsgroup-name
1350                          (string-match (car x) gnus-newsgroup-name))
1351                     (nconc gnus-decode-encoded-word-methods-cache
1352                            (list (cdr x))))))
1353             gnus-decode-encoded-word-methods))
1354   (let ((xlist gnus-decode-encoded-word-methods-cache))
1355     (pop xlist)
1356     (while xlist
1357       (setq string (funcall (pop xlist) string))))
1358   string)
1359
1360 ;; Subject simplification.
1361
1362 (defun gnus-simplify-whitespace (str)
1363   "Remove excessive whitespace from STR."
1364   (let ((mystr str))
1365     ;; Multiple spaces.
1366     (while (string-match "[ \t][ \t]+" mystr)
1367       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1368                           " "
1369                           (substring mystr (match-end 0)))))
1370     ;; Leading spaces.
1371     (when (string-match "^[ \t]+" mystr)
1372       (setq mystr (substring mystr (match-end 0))))
1373     ;; Trailing spaces.
1374     (when (string-match "[ \t]+$" mystr)
1375       (setq mystr (substring mystr 0 (match-beginning 0))))
1376     mystr))
1377
1378 (defun gnus-simplify-all-whitespace (str)
1379   "Remove all whitespace from STR."
1380   (let ((mystr str))
1381     (while (string-match "[ \t\n]+" mystr)
1382       (setq mystr (replace-match "" nil nil mystr)))
1383     mystr))
1384
1385 (defsubst gnus-simplify-subject-re (subject)
1386   "Remove \"Re:\" from subject lines."
1387   (if (string-match message-subject-re-regexp subject)
1388       (substring subject (match-end 0))
1389     subject))
1390
1391 (defun gnus-simplify-subject (subject &optional re-only)
1392   "Remove `Re:' and words in parentheses.
1393 If RE-ONLY is non-nil, strip leading `Re:'s only."
1394   (let ((case-fold-search t))           ;Ignore case.
1395     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1396     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1397       (setq subject (substring subject (match-end 0))))
1398     ;; Remove uninteresting prefixes.
1399     (when (and (not re-only)
1400                gnus-simplify-ignored-prefixes
1401                (string-match gnus-simplify-ignored-prefixes subject))
1402       (setq subject (substring subject (match-end 0))))
1403     ;; Remove words in parentheses from end.
1404     (unless re-only
1405       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1406         (setq subject (substring subject 0 (match-beginning 0)))))
1407     ;; Return subject string.
1408     subject))
1409
1410 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1411 ;; all whitespace.
1412 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1413   (goto-char (point-min))
1414   (while (re-search-forward regexp nil t)
1415     (replace-match (or newtext ""))))
1416
1417 (defun gnus-simplify-buffer-fuzzy ()
1418   "Simplify string in the buffer fuzzily.
1419 The string in the accessible portion of the current buffer is simplified.
1420 It is assumed to be a single-line subject.
1421 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1422 matter is removed.  Additional things can be deleted by setting
1423 `gnus-simplify-subject-fuzzy-regexp'."
1424   (let ((case-fold-search t)
1425         (modified-tick))
1426     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1427
1428     (while (not (eq modified-tick (buffer-modified-tick)))
1429       (setq modified-tick (buffer-modified-tick))
1430       (cond
1431        ((listp gnus-simplify-subject-fuzzy-regexp)
1432         (mapcar 'gnus-simplify-buffer-fuzzy-step
1433                 gnus-simplify-subject-fuzzy-regexp))
1434        (gnus-simplify-subject-fuzzy-regexp
1435         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1436       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1437       (gnus-simplify-buffer-fuzzy-step
1438        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1439       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1440
1441     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1442     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1443     (gnus-simplify-buffer-fuzzy-step " $")
1444     (gnus-simplify-buffer-fuzzy-step "^ +")))
1445
1446 (defun gnus-simplify-subject-fuzzy (subject)
1447   "Simplify a subject string fuzzily.
1448 See `gnus-simplify-buffer-fuzzy' for details."
1449   (save-excursion
1450     (gnus-set-work-buffer)
1451     (let ((case-fold-search t))
1452       ;; Remove uninteresting prefixes.
1453       (when (and gnus-simplify-ignored-prefixes
1454                  (string-match gnus-simplify-ignored-prefixes subject))
1455         (setq subject (substring subject (match-end 0))))
1456       (insert subject)
1457       (inline (gnus-simplify-buffer-fuzzy))
1458       (buffer-string))))
1459
1460 (defsubst gnus-simplify-subject-fully (subject)
1461   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1462   (cond
1463    (gnus-simplify-subject-functions
1464     (gnus-map-function gnus-simplify-subject-functions subject))
1465    ((null gnus-summary-gather-subject-limit)
1466     (gnus-simplify-subject-re subject))
1467    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1468     (gnus-simplify-subject-fuzzy subject))
1469    ((numberp gnus-summary-gather-subject-limit)
1470     (gnus-limit-string (gnus-simplify-subject-re subject)
1471                        gnus-summary-gather-subject-limit))
1472    (t
1473     subject)))
1474
1475 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1476   "Check whether two subjects are equal.
1477 If optional argument simple-first is t, first argument is already
1478 simplified."
1479   (cond
1480    ((null simple-first)
1481     (equal (gnus-simplify-subject-fully s1)
1482            (gnus-simplify-subject-fully s2)))
1483    (t
1484     (equal s1
1485            (gnus-simplify-subject-fully s2)))))
1486
1487 (defun gnus-summary-bubble-group ()
1488   "Increase the score of the current group.
1489 This is a handy function to add to `gnus-summary-exit-hook' to
1490 increase the score of each group you read."
1491   (gnus-group-add-score gnus-newsgroup-name))
1492
1493 \f
1494 ;;;
1495 ;;; Gnus summary mode
1496 ;;;
1497
1498 (put 'gnus-summary-mode 'mode-class 'special)
1499
1500 (defvar gnus-article-commands-menu)
1501
1502 (when t
1503   ;; Non-orthogonal keys
1504
1505   (gnus-define-keys gnus-summary-mode-map
1506     " " gnus-summary-next-page
1507     "\177" gnus-summary-prev-page
1508     [delete] gnus-summary-prev-page
1509     [backspace] gnus-summary-prev-page
1510     "\r" gnus-summary-scroll-up
1511     "\M-\r" gnus-summary-scroll-down
1512     "n" gnus-summary-next-unread-article
1513     "p" gnus-summary-prev-unread-article
1514     "N" gnus-summary-next-article
1515     "P" gnus-summary-prev-article
1516     "\M-\C-n" gnus-summary-next-same-subject
1517     "\M-\C-p" gnus-summary-prev-same-subject
1518     "\M-n" gnus-summary-next-unread-subject
1519     "\M-p" gnus-summary-prev-unread-subject
1520     "." gnus-summary-first-unread-article
1521     "," gnus-summary-best-unread-article
1522     "\M-s" gnus-summary-search-article-forward
1523     "\M-r" gnus-summary-search-article-backward
1524     "<" gnus-summary-beginning-of-article
1525     ">" gnus-summary-end-of-article
1526     "j" gnus-summary-goto-article
1527     "^" gnus-summary-refer-parent-article
1528     "\M-^" gnus-summary-refer-article
1529     "u" gnus-summary-tick-article-forward
1530     "!" gnus-summary-tick-article-forward
1531     "U" gnus-summary-tick-article-backward
1532     "d" gnus-summary-mark-as-read-forward
1533     "D" gnus-summary-mark-as-read-backward
1534     "E" gnus-summary-mark-as-expirable
1535     "\M-u" gnus-summary-clear-mark-forward
1536     "\M-U" gnus-summary-clear-mark-backward
1537     "k" gnus-summary-kill-same-subject-and-select
1538     "\C-k" gnus-summary-kill-same-subject
1539     "\M-\C-k" gnus-summary-kill-thread
1540     "\M-\C-l" gnus-summary-lower-thread
1541     "e" gnus-summary-edit-article
1542     "#" gnus-summary-mark-as-processable
1543     "\M-#" gnus-summary-unmark-as-processable
1544     "\M-\C-t" gnus-summary-toggle-threads
1545     "\M-\C-s" gnus-summary-show-thread
1546     "\M-\C-h" gnus-summary-hide-thread
1547     "\M-\C-f" gnus-summary-next-thread
1548     "\M-\C-b" gnus-summary-prev-thread
1549     [(meta down)] gnus-summary-next-thread
1550     [(meta up)] gnus-summary-prev-thread
1551     "\M-\C-u" gnus-summary-up-thread
1552     "\M-\C-d" gnus-summary-down-thread
1553     "&" gnus-summary-execute-command
1554     "c" gnus-summary-catchup-and-exit
1555     "\C-w" gnus-summary-mark-region-as-read
1556     "\C-t" gnus-summary-toggle-truncation
1557     "?" gnus-summary-mark-as-dormant
1558     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1559     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1560     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1561     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1562     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1563     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1564     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1565     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1566     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1567     "\C-c\C-s\C-r" gnus-summary-sort-by-random
1568     "=" gnus-summary-expand-window
1569     "\C-x\C-s" gnus-summary-reselect-current-group
1570     "\M-g" gnus-summary-rescan-group
1571     "w" gnus-summary-stop-page-breaking
1572     "\C-c\C-r" gnus-summary-caesar-message
1573     "f" gnus-summary-followup
1574     "F" gnus-summary-followup-with-original
1575     "C" gnus-summary-cancel-article
1576     "r" gnus-summary-reply
1577     "R" gnus-summary-reply-with-original
1578     "\C-c\C-f" gnus-summary-mail-forward
1579     "o" gnus-summary-save-article
1580     "\C-o" gnus-summary-save-article-mail
1581     "|" gnus-summary-pipe-output
1582     "\M-k" gnus-summary-edit-local-kill
1583     "\M-K" gnus-summary-edit-global-kill
1584     ;; "V" gnus-version
1585     "\C-c\C-d" gnus-summary-describe-group
1586     "q" gnus-summary-exit
1587     "Q" gnus-summary-exit-no-update
1588     "\C-c\C-i" gnus-info-find-node
1589     gnus-mouse-2 gnus-mouse-pick-article
1590     "m" gnus-summary-mail-other-window
1591     "a" gnus-summary-post-news
1592     "i" gnus-summary-news-other-window
1593     "x" gnus-summary-limit-to-unread
1594     "s" gnus-summary-isearch-article
1595     "t" gnus-summary-toggle-header
1596     "g" gnus-summary-show-article
1597     "l" gnus-summary-goto-last-article
1598     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1599     "\C-d" gnus-summary-enter-digest-group
1600     "\M-\C-d" gnus-summary-read-document
1601     "\M-\C-e" gnus-summary-edit-parameters
1602     "\M-\C-a" gnus-summary-customize-parameters
1603     "\C-c\C-b" gnus-bug
1604     "*" gnus-cache-enter-article
1605     "\M-*" gnus-cache-remove-article
1606     "\M-&" gnus-summary-universal-argument
1607     "\C-l" gnus-recenter
1608     "I" gnus-summary-increase-score
1609     "L" gnus-summary-lower-score
1610     "\M-i" gnus-symbolic-argument
1611     "h" gnus-summary-select-article-buffer
1612
1613     "b" gnus-article-view-part
1614     "\M-t" gnus-summary-toggle-display-buttonized
1615
1616     "V" gnus-summary-score-map
1617     "X" gnus-uu-extract-map
1618     "S" gnus-summary-send-map)
1619
1620   ;; Sort of orthogonal keymap
1621   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1622     "t" gnus-summary-tick-article-forward
1623     "!" gnus-summary-tick-article-forward
1624     "d" gnus-summary-mark-as-read-forward
1625     "r" gnus-summary-mark-as-read-forward
1626     "c" gnus-summary-clear-mark-forward
1627     " " gnus-summary-clear-mark-forward
1628     "e" gnus-summary-mark-as-expirable
1629     "x" gnus-summary-mark-as-expirable
1630     "?" gnus-summary-mark-as-dormant
1631     "b" gnus-summary-set-bookmark
1632     "B" gnus-summary-remove-bookmark
1633     "#" gnus-summary-mark-as-processable
1634     "\M-#" gnus-summary-unmark-as-processable
1635     "S" gnus-summary-limit-include-expunged
1636     "C" gnus-summary-catchup
1637     "H" gnus-summary-catchup-to-here
1638     "h" gnus-summary-catchup-from-here
1639     "\C-c" gnus-summary-catchup-all
1640     "k" gnus-summary-kill-same-subject-and-select
1641     "K" gnus-summary-kill-same-subject
1642     "P" gnus-uu-mark-map)
1643
1644   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1645     "c" gnus-summary-clear-above
1646     "u" gnus-summary-tick-above
1647     "m" gnus-summary-mark-above
1648     "k" gnus-summary-kill-below)
1649
1650   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1651     "/" gnus-summary-limit-to-subject
1652     "n" gnus-summary-limit-to-articles
1653     "w" gnus-summary-pop-limit
1654     "s" gnus-summary-limit-to-subject
1655     "a" gnus-summary-limit-to-author
1656     "u" gnus-summary-limit-to-unread
1657     "m" gnus-summary-limit-to-marks
1658     "M" gnus-summary-limit-exclude-marks
1659     "v" gnus-summary-limit-to-score
1660     "*" gnus-summary-limit-include-cached
1661     "D" gnus-summary-limit-include-dormant
1662     "T" gnus-summary-limit-include-thread
1663     "d" gnus-summary-limit-exclude-dormant
1664     "t" gnus-summary-limit-to-age
1665     "." gnus-summary-limit-to-unseen
1666     "x" gnus-summary-limit-to-extra
1667     "p" gnus-summary-limit-to-display-predicate
1668     "E" gnus-summary-limit-include-expunged
1669     "c" gnus-summary-limit-exclude-childless-dormant
1670     "C" gnus-summary-limit-mark-excluded-as-read
1671     "o" gnus-summary-insert-old-articles
1672     "N" gnus-summary-insert-new-articles)
1673
1674   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1675     "n" gnus-summary-next-unread-article
1676     "p" gnus-summary-prev-unread-article
1677     "N" gnus-summary-next-article
1678     "P" gnus-summary-prev-article
1679     "\C-n" gnus-summary-next-same-subject
1680     "\C-p" gnus-summary-prev-same-subject
1681     "\M-n" gnus-summary-next-unread-subject
1682     "\M-p" gnus-summary-prev-unread-subject
1683     "f" gnus-summary-first-unread-article
1684     "b" gnus-summary-best-unread-article
1685     "j" gnus-summary-goto-article
1686     "g" gnus-summary-goto-subject
1687     "l" gnus-summary-goto-last-article
1688     "o" gnus-summary-pop-article)
1689
1690   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1691     "k" gnus-summary-kill-thread
1692     "l" gnus-summary-lower-thread
1693     "i" gnus-summary-raise-thread
1694     "T" gnus-summary-toggle-threads
1695     "t" gnus-summary-rethread-current
1696     "^" gnus-summary-reparent-thread
1697     "s" gnus-summary-show-thread
1698     "S" gnus-summary-show-all-threads
1699     "h" gnus-summary-hide-thread
1700     "H" gnus-summary-hide-all-threads
1701     "n" gnus-summary-next-thread
1702     "p" gnus-summary-prev-thread
1703     "u" gnus-summary-up-thread
1704     "o" gnus-summary-top-thread
1705     "d" gnus-summary-down-thread
1706     "#" gnus-uu-mark-thread
1707     "\M-#" gnus-uu-unmark-thread)
1708
1709   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1710     "g" gnus-summary-prepare
1711     "c" gnus-summary-insert-cached-articles)
1712
1713   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1714     "c" gnus-summary-catchup-and-exit
1715     "C" gnus-summary-catchup-all-and-exit
1716     "E" gnus-summary-exit-no-update
1717     "Q" gnus-summary-exit
1718     "Z" gnus-summary-exit
1719     "n" gnus-summary-catchup-and-goto-next-group
1720     "R" gnus-summary-reselect-current-group
1721     "G" gnus-summary-rescan-group
1722     "N" gnus-summary-next-group
1723     "s" gnus-summary-save-newsrc
1724     "P" gnus-summary-prev-group)
1725
1726   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1727     " " gnus-summary-next-page
1728     "n" gnus-summary-next-page
1729     "\177" gnus-summary-prev-page
1730     [delete] gnus-summary-prev-page
1731     "p" gnus-summary-prev-page
1732     "\r" gnus-summary-scroll-up
1733     "\M-\r" gnus-summary-scroll-down
1734     "<" gnus-summary-beginning-of-article
1735     ">" gnus-summary-end-of-article
1736     "b" gnus-summary-beginning-of-article
1737     "e" gnus-summary-end-of-article
1738     "^" gnus-summary-refer-parent-article
1739     "r" gnus-summary-refer-parent-article
1740     "D" gnus-summary-enter-digest-group
1741     "R" gnus-summary-refer-references
1742     "T" gnus-summary-refer-thread
1743     "g" gnus-summary-show-article
1744     "s" gnus-summary-isearch-article
1745     "P" gnus-summary-print-article
1746     "M" gnus-mailing-list-insinuate
1747     "t" gnus-article-babel)
1748
1749   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1750     "b" gnus-article-add-buttons
1751     "B" gnus-article-add-buttons-to-head
1752     "o" gnus-article-treat-overstrike
1753     "e" gnus-article-emphasize
1754     "w" gnus-article-fill-cited-article
1755     "Q" gnus-article-fill-long-lines
1756     "C" gnus-article-capitalize-sentences
1757     "c" gnus-article-remove-cr
1758     "q" gnus-article-de-quoted-unreadable
1759     "6" gnus-article-de-base64-unreadable
1760     "Z" gnus-article-decode-HZ
1761     "h" gnus-article-wash-html
1762     "u" gnus-article-unsplit-urls
1763     "s" gnus-summary-force-verify-and-decrypt
1764     "f" gnus-article-display-x-face
1765     "l" gnus-summary-stop-page-breaking
1766     "r" gnus-summary-caesar-message
1767     "m" gnus-summary-morse-message
1768     "t" gnus-summary-toggle-header
1769     "g" gnus-treat-smiley
1770     "v" gnus-summary-verbose-headers
1771     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1772     "p" gnus-article-verify-x-pgp-sig
1773     "d" gnus-article-treat-dumbquotes
1774     "k" gnus-article-outlook-deuglify-article)
1775
1776   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1777     "a" gnus-article-hide
1778     "h" gnus-article-hide-headers
1779     "b" gnus-article-hide-boring-headers
1780     "s" gnus-article-hide-signature
1781     "c" gnus-article-hide-citation
1782     "C" gnus-article-hide-citation-in-followups
1783     "l" gnus-article-hide-list-identifiers
1784     "p" gnus-article-hide-pgp
1785     "B" gnus-article-strip-banner
1786     "P" gnus-article-hide-pem
1787     "\C-c" gnus-article-hide-citation-maybe)
1788
1789   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1790     "a" gnus-article-highlight
1791     "h" gnus-article-highlight-headers
1792     "c" gnus-article-highlight-citation
1793     "s" gnus-article-highlight-signature)
1794
1795   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1796     "f" gnus-article-treat-fold-headers
1797     "u" gnus-article-treat-unfold-headers
1798     "n" gnus-article-treat-fold-newsgroups)
1799
1800   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1801     "x" gnus-article-display-x-face
1802     "s" gnus-treat-smiley
1803     "D" gnus-article-remove-images
1804     "f" gnus-treat-from-picon
1805     "m" gnus-treat-mail-picon
1806     "n" gnus-treat-newsgroups-picon)
1807
1808   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1809     "w" gnus-article-decode-mime-words
1810     "c" gnus-article-decode-charset
1811     "v" gnus-mime-view-all-parts
1812     "b" gnus-article-view-part)
1813
1814   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1815     "z" gnus-article-date-ut
1816     "u" gnus-article-date-ut
1817     "l" gnus-article-date-local
1818     "p" gnus-article-date-english
1819     "e" gnus-article-date-lapsed
1820     "o" gnus-article-date-original
1821     "i" gnus-article-date-iso8601
1822     "s" gnus-article-date-user)
1823
1824   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1825     "t" gnus-article-remove-trailing-blank-lines
1826     "l" gnus-article-strip-leading-blank-lines
1827     "m" gnus-article-strip-multiple-blank-lines
1828     "a" gnus-article-strip-blank-lines
1829     "A" gnus-article-strip-all-blank-lines
1830     "s" gnus-article-strip-leading-space
1831     "e" gnus-article-strip-trailing-space
1832     "w" gnus-article-remove-leading-whitespace)
1833
1834   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1835     "v" gnus-version
1836     "f" gnus-summary-fetch-faq
1837     "d" gnus-summary-describe-group
1838     "h" gnus-summary-describe-briefly
1839     "i" gnus-info-find-node
1840     "c" gnus-group-fetch-charter
1841     "C" gnus-group-fetch-control)
1842
1843   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1844     "e" gnus-summary-expire-articles
1845     "\M-\C-e" gnus-summary-expire-articles-now
1846     "\177" gnus-summary-delete-article
1847     [delete] gnus-summary-delete-article
1848     [backspace] gnus-summary-delete-article
1849     "m" gnus-summary-move-article
1850     "r" gnus-summary-respool-article
1851     "w" gnus-summary-edit-article
1852     "c" gnus-summary-copy-article
1853     "B" gnus-summary-crosspost-article
1854     "q" gnus-summary-respool-query
1855     "t" gnus-summary-respool-trace
1856     "i" gnus-summary-import-article
1857     "I" gnus-summary-create-article
1858     "p" gnus-summary-article-posted-p)
1859
1860   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1861     "o" gnus-summary-save-article
1862     "m" gnus-summary-save-article-mail
1863     "F" gnus-summary-write-article-file
1864     "r" gnus-summary-save-article-rmail
1865     "f" gnus-summary-save-article-file
1866     "b" gnus-summary-save-article-body-file
1867     "h" gnus-summary-save-article-folder
1868     "v" gnus-summary-save-article-vm
1869     "p" gnus-summary-pipe-output
1870     "P" gnus-summary-muttprint
1871     "s" gnus-soup-add-article)
1872
1873   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1874     "b" gnus-summary-display-buttonized
1875     "m" gnus-summary-repair-multipart
1876     "v" gnus-article-view-part
1877     "o" gnus-article-save-part
1878     "c" gnus-article-copy-part
1879     "C" gnus-article-view-part-as-charset
1880     "e" gnus-article-view-part-externally
1881     "E" gnus-article-encrypt-body
1882     "i" gnus-article-inline-part
1883     "|" gnus-article-pipe-part)
1884
1885   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1886     "p" gnus-summary-mark-as-processable
1887     "u" gnus-summary-unmark-as-processable
1888     "U" gnus-summary-unmark-all-processable
1889     "v" gnus-uu-mark-over
1890     "s" gnus-uu-mark-series
1891     "r" gnus-uu-mark-region
1892     "g" gnus-uu-unmark-region
1893     "R" gnus-uu-mark-by-regexp
1894     "G" gnus-uu-unmark-by-regexp
1895     "t" gnus-uu-mark-thread
1896     "T" gnus-uu-unmark-thread
1897     "a" gnus-uu-mark-all
1898     "b" gnus-uu-mark-buffer
1899     "S" gnus-uu-mark-sparse
1900     "k" gnus-summary-kill-process-mark
1901     "y" gnus-summary-yank-process-mark
1902     "w" gnus-summary-save-process-mark
1903     "i" gnus-uu-invert-processable)
1904
1905   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1906     ;;"x" gnus-uu-extract-any
1907     "m" gnus-summary-save-parts
1908     "u" gnus-uu-decode-uu
1909     "U" gnus-uu-decode-uu-and-save
1910     "s" gnus-uu-decode-unshar
1911     "S" gnus-uu-decode-unshar-and-save
1912     "o" gnus-uu-decode-save
1913     "O" gnus-uu-decode-save
1914     "b" gnus-uu-decode-binhex
1915     "B" gnus-uu-decode-binhex
1916     "p" gnus-uu-decode-postscript
1917     "P" gnus-uu-decode-postscript-and-save)
1918
1919   (gnus-define-keys
1920       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1921     "u" gnus-uu-decode-uu-view
1922     "U" gnus-uu-decode-uu-and-save-view
1923     "s" gnus-uu-decode-unshar-view
1924     "S" gnus-uu-decode-unshar-and-save-view
1925     "o" gnus-uu-decode-save-view
1926     "O" gnus-uu-decode-save-view
1927     "b" gnus-uu-decode-binhex-view
1928     "B" gnus-uu-decode-binhex-view
1929     "p" gnus-uu-decode-postscript-view
1930     "P" gnus-uu-decode-postscript-and-save-view))
1931
1932 (defvar gnus-article-post-menu nil)
1933
1934 (defconst gnus-summary-menu-maxlen 20)
1935
1936 (defun gnus-summary-menu-split (menu)
1937   ;; If we have lots of elements, divide them into groups of 20
1938   ;; and make a pane (or submenu) for each one.
1939   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1940       (let ((menu menu) sublists next
1941             (i 1))
1942         (while menu
1943           ;; Pull off the next gnus-summary-menu-maxlen elements
1944           ;; and make them the next element of sublist.
1945           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1946           (if next
1947               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1948                       nil))
1949           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1950                                              (aref (car (last menu)) 0)) menu)
1951                                sublists))
1952           (setq i (1+ i))
1953           (setq menu next))
1954         (nreverse sublists))
1955     ;; Few elements--put them all in one pane.
1956     menu))
1957
1958 (defun gnus-summary-make-menu-bar ()
1959   (gnus-turn-off-edit-menu 'summary)
1960
1961   (unless (boundp 'gnus-summary-misc-menu)
1962
1963     (easy-menu-define
1964       gnus-summary-kill-menu gnus-summary-mode-map ""
1965       (cons
1966        "Score"
1967        (nconc
1968         (list
1969          ["Customize" gnus-score-customize t])
1970         (gnus-make-score-map 'increase)
1971         (gnus-make-score-map 'lower)
1972         '(("Mark"
1973            ["Kill below" gnus-summary-kill-below t]
1974            ["Mark above" gnus-summary-mark-above t]
1975            ["Tick above" gnus-summary-tick-above t]
1976            ["Clear above" gnus-summary-clear-above t])
1977           ["Current score" gnus-summary-current-score t]
1978           ["Set score" gnus-summary-set-score t]
1979           ["Switch current score file..." gnus-score-change-score-file t]
1980           ["Set mark below..." gnus-score-set-mark-below t]
1981           ["Set expunge below..." gnus-score-set-expunge-below t]
1982           ["Edit current score file" gnus-score-edit-current-scores t]
1983           ["Edit score file" gnus-score-edit-file t]
1984           ["Trace score" gnus-score-find-trace t]
1985           ["Find words" gnus-score-find-favourite-words t]
1986           ["Rescore buffer" gnus-summary-rescore t]
1987           ["Increase score..." gnus-summary-increase-score t]
1988           ["Lower score..." gnus-summary-lower-score t]))))
1989
1990     ;; Define both the Article menu in the summary buffer and the
1991     ;; equivalent Commands menu in the article buffer here for
1992     ;; consistency.
1993     (let ((innards
1994            `(("Hide"
1995               ["All" gnus-article-hide t]
1996               ["Headers" gnus-article-hide-headers t]
1997               ["Signature" gnus-article-hide-signature t]
1998               ["Citation" gnus-article-hide-citation t]
1999               ["List identifiers" gnus-article-hide-list-identifiers t]
2000               ["PGP" gnus-article-hide-pgp t]
2001               ["Banner" gnus-article-strip-banner t]
2002               ["Boring headers" gnus-article-hide-boring-headers t])
2003              ("Highlight"
2004               ["All" gnus-article-highlight t]
2005               ["Headers" gnus-article-highlight-headers t]
2006               ["Signature" gnus-article-highlight-signature t]
2007               ["Citation" gnus-article-highlight-citation t])
2008              ("MIME"
2009               ["Words" gnus-article-decode-mime-words t]
2010               ["Charset" gnus-article-decode-charset t]
2011               ["QP" gnus-article-de-quoted-unreadable t]
2012               ["Base64" gnus-article-de-base64-unreadable t]
2013               ["View MIME buttons" gnus-summary-display-buttonized t]
2014               ["View all" gnus-mime-view-all-parts t]
2015               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2016               ["Encrypt body" gnus-article-encrypt-body t]
2017               ["Extract all parts" gnus-summary-save-parts t])
2018              ("Date"
2019               ["Local" gnus-article-date-local t]
2020               ["ISO8601" gnus-article-date-iso8601 t]
2021               ["UT" gnus-article-date-ut t]
2022               ["Original" gnus-article-date-original t]
2023               ["Lapsed" gnus-article-date-lapsed t]
2024               ["User-defined" gnus-article-date-user t])
2025              ("Display"
2026               ["Remove images" gnus-article-remove-images t]
2027               ["Toggle smiley" gnus-treat-smiley t]
2028               ["Show X-Face" gnus-article-display-x-face t]
2029               ["Show picons in From" gnus-treat-from-picon t]
2030               ["Show picons in mail headers" gnus-treat-mail-picon t]
2031               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2032               ("View as different encoding"
2033                ,@(gnus-summary-menu-split
2034                   (mapcar
2035                    (lambda (cs)
2036                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2037                      ;; forms for menu commands, we should provide intern'ed
2038                      ;; function symbols.
2039                      (let ((command (intern (format "\
2040 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2041                        (fset command
2042                              `(lambda ()
2043                                 (interactive)
2044                                 (let ((gnus-summary-show-article-charset-alist
2045                                        '((1 . ,cs))))
2046                                   (gnus-summary-show-article 1))))
2047                        `[,(symbol-name cs) ,command t]))
2048                    (sort (if (fboundp 'coding-system-list)
2049                              (coding-system-list)
2050                            (mapcar 'car mm-mime-mule-charset-alist))
2051                          'string<)))))
2052              ("Washing"
2053               ("Remove Blanks"
2054                ["Leading" gnus-article-strip-leading-blank-lines t]
2055                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2056                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2057                ["All of the above" gnus-article-strip-blank-lines t]
2058                ["All" gnus-article-strip-all-blank-lines t]
2059                ["Leading space" gnus-article-strip-leading-space t]
2060                ["Trailing space" gnus-article-strip-trailing-space t]
2061                ["Leading space in headers"
2062                 gnus-article-remove-leading-whitespace t])
2063               ["Overstrike" gnus-article-treat-overstrike t]
2064               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2065               ["Emphasis" gnus-article-emphasize t]
2066               ["Word wrap" gnus-article-fill-cited-article t]
2067               ["Fill long lines" gnus-article-fill-long-lines t]
2068               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2069               ["CR" gnus-article-remove-cr t]
2070               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2071               ["Base64" gnus-article-de-base64-unreadable t]
2072               ["Rot 13" gnus-summary-caesar-message
2073                ,@(if (featurep 'xemacs) '(t)
2074                    '(:help "\"Caesar rotate\" article by 13"))]
2075               ["Morse decode" gnus-summary-morse-message t]
2076               ["Unix pipe..." gnus-summary-pipe-message t]
2077               ["Add buttons" gnus-article-add-buttons t]
2078               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2079               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2080               ["Verbose header" gnus-summary-verbose-headers t]
2081               ["Toggle header" gnus-summary-toggle-header t]
2082               ["Unfold headers" gnus-article-treat-unfold-headers t]
2083               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2084               ["Html" gnus-article-wash-html t]
2085               ["URLs" gnus-article-unsplit-urls t]
2086               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2087               ["HZ" gnus-article-decode-HZ t]
2088               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2089               )
2090              ("Output"
2091               ["Save in default format" gnus-summary-save-article
2092                ,@(if (featurep 'xemacs) '(t)
2093                    '(:help "Save article using default method"))]
2094               ["Save in file" gnus-summary-save-article-file
2095                ,@(if (featurep 'xemacs) '(t)
2096                    '(:help "Save article in file"))]
2097               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2098               ["Save in MH folder" gnus-summary-save-article-folder t]
2099               ["Save in VM folder" gnus-summary-save-article-vm t]
2100               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2101               ["Save body in file" gnus-summary-save-article-body-file t]
2102               ["Pipe through a filter" gnus-summary-pipe-output t]
2103               ["Add to SOUP packet" gnus-soup-add-article t]
2104               ["Print with Muttprint" gnus-summary-muttprint t]
2105               ["Print" gnus-summary-print-article t])
2106              ("Backend"
2107               ["Respool article..." gnus-summary-respool-article t]
2108               ["Move article..." gnus-summary-move-article
2109                (gnus-check-backend-function
2110                 'request-move-article gnus-newsgroup-name)]
2111               ["Copy article..." gnus-summary-copy-article t]
2112               ["Crosspost article..." gnus-summary-crosspost-article
2113                (gnus-check-backend-function
2114                 'request-replace-article gnus-newsgroup-name)]
2115               ["Import file..." gnus-summary-import-article t]
2116               ["Create article..." gnus-summary-create-article t]
2117               ["Check if posted" gnus-summary-article-posted-p t]
2118               ["Edit article" gnus-summary-edit-article
2119                (not (gnus-group-read-only-p))]
2120               ["Delete article" gnus-summary-delete-article
2121                (gnus-check-backend-function
2122                 'request-expire-articles gnus-newsgroup-name)]
2123               ["Query respool" gnus-summary-respool-query t]
2124               ["Trace respool" gnus-summary-respool-trace t]
2125               ["Delete expirable articles" gnus-summary-expire-articles-now
2126                (gnus-check-backend-function
2127                 'request-expire-articles gnus-newsgroup-name)])
2128              ("Extract"
2129               ["Uudecode" gnus-uu-decode-uu
2130                ,@(if (featurep 'xemacs) '(t)
2131                    '(:help "Decode uuencoded article(s)"))]
2132               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2133               ["Unshar" gnus-uu-decode-unshar t]
2134               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2135               ["Save" gnus-uu-decode-save t]
2136               ["Binhex" gnus-uu-decode-binhex t]
2137               ["Postscript" gnus-uu-decode-postscript t]
2138               ["All MIME parts" gnus-summary-save-parts t])
2139              ("Cache"
2140               ["Enter article" gnus-cache-enter-article t]
2141               ["Remove article" gnus-cache-remove-article t])
2142              ["Translate" gnus-article-babel t]
2143              ["Select article buffer" gnus-summary-select-article-buffer t]
2144              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2145              ["Isearch article..." gnus-summary-isearch-article t]
2146              ["Beginning of the article" gnus-summary-beginning-of-article t]
2147              ["End of the article" gnus-summary-end-of-article t]
2148              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2149              ["Fetch referenced articles" gnus-summary-refer-references t]
2150              ["Fetch current thread" gnus-summary-refer-thread t]
2151              ["Fetch article with id..." gnus-summary-refer-article t]
2152              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2153              ["Redisplay" gnus-summary-show-article t]
2154              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2155       (easy-menu-define
2156         gnus-summary-article-menu gnus-summary-mode-map ""
2157         (cons "Article" innards))
2158
2159       (if (not (keymapp gnus-summary-article-menu))
2160           (easy-menu-define
2161             gnus-article-commands-menu gnus-article-mode-map ""
2162             (cons "Commands" innards))
2163         ;; in Emacs, don't share menu.
2164         (setq gnus-article-commands-menu
2165               (copy-keymap gnus-summary-article-menu))
2166         (define-key gnus-article-mode-map [menu-bar commands]
2167           (cons "Commands" gnus-article-commands-menu))))
2168
2169     (easy-menu-define
2170       gnus-summary-thread-menu gnus-summary-mode-map ""
2171       '("Threads"
2172         ["Toggle threading" gnus-summary-toggle-threads t]
2173         ["Hide threads" gnus-summary-hide-all-threads t]
2174         ["Show threads" gnus-summary-show-all-threads t]
2175         ["Hide thread" gnus-summary-hide-thread t]
2176         ["Show thread" gnus-summary-show-thread t]
2177         ["Go to next thread" gnus-summary-next-thread t]
2178         ["Go to previous thread" gnus-summary-prev-thread t]
2179         ["Go down thread" gnus-summary-down-thread t]
2180         ["Go up thread" gnus-summary-up-thread t]
2181         ["Top of thread" gnus-summary-top-thread t]
2182         ["Mark thread as read" gnus-summary-kill-thread t]
2183         ["Lower thread score" gnus-summary-lower-thread t]
2184         ["Raise thread score" gnus-summary-raise-thread t]
2185         ["Rethread current" gnus-summary-rethread-current t]))
2186
2187     (easy-menu-define
2188       gnus-summary-post-menu gnus-summary-mode-map ""
2189       `("Post"
2190         ["Send a message (mail or news)" gnus-summary-post-news
2191          ,@(if (featurep 'xemacs) '(t)
2192              '(:help "Post an article"))]
2193         ["Followup" gnus-summary-followup
2194          ,@(if (featurep 'xemacs) '(t)
2195              '(:help "Post followup to this article"))]
2196         ["Followup and yank" gnus-summary-followup-with-original
2197          ,@(if (featurep 'xemacs) '(t)
2198              '(:help "Post followup to this article, quoting its contents"))]
2199         ["Supersede article" gnus-summary-supersede-article t]
2200         ["Cancel article" gnus-summary-cancel-article
2201          ,@(if (featurep 'xemacs) '(t)
2202              '(:help "Cancel an article you posted"))]
2203         ["Reply" gnus-summary-reply t]
2204         ["Reply and yank" gnus-summary-reply-with-original t]
2205         ["Wide reply" gnus-summary-wide-reply t]
2206         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2207          ,@(if (featurep 'xemacs) '(t)
2208              '(:help "Mail a reply, quoting this article"))]
2209         ["Very wide reply" gnus-summary-very-wide-reply t]
2210         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2211          ,@(if (featurep 'xemacs) '(t)
2212              '(:help "Mail a very wide reply, quoting this article"))]
2213         ["Mail forward" gnus-summary-mail-forward t]
2214         ["Post forward" gnus-summary-post-forward t]
2215         ["Digest and mail" gnus-uu-digest-mail-forward t]
2216         ["Digest and post" gnus-uu-digest-post-forward t]
2217         ["Resend message" gnus-summary-resend-message t]
2218         ["Resend message edit" gnus-summary-resend-message-edit t]
2219         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2220         ["Send a mail" gnus-summary-mail-other-window t]
2221         ["Create a local message" gnus-summary-news-other-window t]
2222         ["Uuencode and post" gnus-uu-post-news
2223          ,@(if (featurep 'xemacs) '(t)
2224              '(:help "Post a uuencoded article"))]
2225         ["Followup via news" gnus-summary-followup-to-mail t]
2226         ["Followup via news and yank"
2227          gnus-summary-followup-to-mail-with-original t]
2228         ;;("Draft"
2229         ;;["Send" gnus-summary-send-draft t]
2230         ;;["Send bounced" gnus-resend-bounced-mail t])
2231         ))
2232
2233     (cond
2234      ((not (keymapp gnus-summary-post-menu))
2235       (setq gnus-article-post-menu gnus-summary-post-menu))
2236      ((not gnus-article-post-menu)
2237       ;; Don't share post menu.
2238       (setq gnus-article-post-menu
2239             (copy-keymap gnus-summary-post-menu))))
2240     (define-key gnus-article-mode-map [menu-bar post]
2241       (cons "Post" gnus-article-post-menu))
2242
2243     (easy-menu-define
2244       gnus-summary-misc-menu gnus-summary-mode-map ""
2245       `("Gnus"
2246         ("Mark Read"
2247          ["Mark as read" gnus-summary-mark-as-read-forward t]
2248          ["Mark same subject and select"
2249           gnus-summary-kill-same-subject-and-select t]
2250          ["Mark same subject" gnus-summary-kill-same-subject t]
2251          ["Catchup" gnus-summary-catchup
2252           ,@(if (featurep 'xemacs) '(t)
2253               '(:help "Mark unread articles in this group as read"))]
2254          ["Catchup all" gnus-summary-catchup-all t]
2255          ["Catchup to here" gnus-summary-catchup-to-here t]
2256          ["Catchup from here" gnus-summary-catchup-from-here t]
2257          ["Catchup region" gnus-summary-mark-region-as-read t]
2258          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2259         ("Mark Various"
2260          ["Tick" gnus-summary-tick-article-forward t]
2261          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2262          ["Remove marks" gnus-summary-clear-mark-forward t]
2263          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2264          ["Set bookmark" gnus-summary-set-bookmark t]
2265          ["Remove bookmark" gnus-summary-remove-bookmark t])
2266         ("Limit to"
2267          ["Marks..." gnus-summary-limit-to-marks t]
2268          ["Subject..." gnus-summary-limit-to-subject t]
2269          ["Author..." gnus-summary-limit-to-author t]
2270          ["Age..." gnus-summary-limit-to-age t]
2271          ["Extra..." gnus-summary-limit-to-extra t]
2272          ["Score..." gnus-summary-limit-to-score t]
2273          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2274          ["Unread" gnus-summary-limit-to-unread t]
2275          ["Unseen" gnus-summary-limit-to-unseen t]
2276          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2277          ["Articles" gnus-summary-limit-to-articles t]
2278          ["Pop limit" gnus-summary-pop-limit t]
2279          ["Show dormant" gnus-summary-limit-include-dormant t]
2280          ["Hide childless dormant"
2281           gnus-summary-limit-exclude-childless-dormant t]
2282          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2283          ["Hide marked" gnus-summary-limit-exclude-marks t]
2284          ["Show expunged" gnus-summary-limit-include-expunged t])
2285         ("Process Mark"
2286          ["Set mark" gnus-summary-mark-as-processable t]
2287          ["Remove mark" gnus-summary-unmark-as-processable t]
2288          ["Remove all marks" gnus-summary-unmark-all-processable t]
2289          ["Mark above" gnus-uu-mark-over t]
2290          ["Mark series" gnus-uu-mark-series t]
2291          ["Mark region" gnus-uu-mark-region t]
2292          ["Unmark region" gnus-uu-unmark-region t]
2293          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2294          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2295          ["Mark all" gnus-uu-mark-all t]
2296          ["Mark buffer" gnus-uu-mark-buffer t]
2297          ["Mark sparse" gnus-uu-mark-sparse t]
2298          ["Mark thread" gnus-uu-mark-thread t]
2299          ["Unmark thread" gnus-uu-unmark-thread t]
2300          ("Process Mark Sets"
2301           ["Kill" gnus-summary-kill-process-mark t]
2302           ["Yank" gnus-summary-yank-process-mark
2303            gnus-newsgroup-process-stack]
2304           ["Save" gnus-summary-save-process-mark t]))
2305         ("Scroll article"
2306          ["Page forward" gnus-summary-next-page
2307           ,@(if (featurep 'xemacs) '(t)
2308               '(:help "Show next page of article"))]
2309          ["Page backward" gnus-summary-prev-page
2310           ,@(if (featurep 'xemacs) '(t)
2311               '(:help "Show previous page of article"))]
2312          ["Line forward" gnus-summary-scroll-up t])
2313         ("Move"
2314          ["Next unread article" gnus-summary-next-unread-article t]
2315          ["Previous unread article" gnus-summary-prev-unread-article t]
2316          ["Next article" gnus-summary-next-article t]
2317          ["Previous article" gnus-summary-prev-article t]
2318          ["Next unread subject" gnus-summary-next-unread-subject t]
2319          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2320          ["Next article same subject" gnus-summary-next-same-subject t]
2321          ["Previous article same subject" gnus-summary-prev-same-subject t]
2322          ["First unread article" gnus-summary-first-unread-article t]
2323          ["Best unread article" gnus-summary-best-unread-article t]
2324          ["Go to subject number..." gnus-summary-goto-subject t]
2325          ["Go to article number..." gnus-summary-goto-article t]
2326          ["Go to the last article" gnus-summary-goto-last-article t]
2327          ["Pop article off history" gnus-summary-pop-article t])
2328         ("Sort"
2329          ["Sort by number" gnus-summary-sort-by-number t]
2330          ["Sort by author" gnus-summary-sort-by-author t]
2331          ["Sort by subject" gnus-summary-sort-by-subject t]
2332          ["Sort by date" gnus-summary-sort-by-date t]
2333          ["Sort by score" gnus-summary-sort-by-score t]
2334          ["Sort by lines" gnus-summary-sort-by-lines t]
2335          ["Sort by characters" gnus-summary-sort-by-chars t]
2336          ["Randomize" gnus-summary-sort-by-random t]
2337          ["Original sort" gnus-summary-sort-by-original t])
2338         ("Help"
2339          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2340          ["Describe group" gnus-summary-describe-group t]
2341          ["Fetch charter" gnus-group-fetch-charter
2342           ,@(if (featurep 'xemacs) nil
2343               '(:help "Display the charter of the current group"))]
2344          ["Fetch control message" gnus-group-fetch-control
2345           ,@(if (featurep 'xemacs) nil
2346               '(:help "Display the archived control message for the current group"))]
2347          ["Read manual" gnus-info-find-node t])
2348         ("Modes"
2349          ["Pick and read" gnus-pick-mode t]
2350          ["Binary" gnus-binary-mode t])
2351         ("Regeneration"
2352          ["Regenerate" gnus-summary-prepare t]
2353          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2354          ["Toggle threading" gnus-summary-toggle-threads t])
2355         ["See old articles" gnus-summary-insert-old-articles t]
2356         ["See new articles" gnus-summary-insert-new-articles t]
2357         ["Filter articles..." gnus-summary-execute-command t]
2358         ["Run command on subjects..." gnus-summary-universal-argument t]
2359         ["Search articles forward..." gnus-summary-search-article-forward t]
2360         ["Search articles backward..." gnus-summary-search-article-backward t]
2361         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2362         ["Expand window" gnus-summary-expand-window t]
2363         ["Expire expirable articles" gnus-summary-expire-articles
2364          (gnus-check-backend-function
2365           'request-expire-articles gnus-newsgroup-name)]
2366         ["Edit local kill file" gnus-summary-edit-local-kill t]
2367         ["Edit main kill file" gnus-summary-edit-global-kill t]
2368         ["Edit group parameters" gnus-summary-edit-parameters t]
2369         ["Customize group parameters" gnus-summary-customize-parameters t]
2370         ["Send a bug report" gnus-bug t]
2371         ("Exit"
2372          ["Catchup and exit" gnus-summary-catchup-and-exit
2373           ,@(if (featurep 'xemacs) '(t)
2374               '(:help "Mark unread articles in this group as read, then exit"))]
2375          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2376          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2377          ["Exit group" gnus-summary-exit
2378           ,@(if (featurep 'xemacs) '(t)
2379               '(:help "Exit current group, return to group selection mode"))]
2380          ["Exit group without updating" gnus-summary-exit-no-update t]
2381          ["Exit and goto next group" gnus-summary-next-group t]
2382          ["Exit and goto prev group" gnus-summary-prev-group t]
2383          ["Reselect group" gnus-summary-reselect-current-group t]
2384          ["Rescan group" gnus-summary-rescan-group t]
2385          ["Update dribble" gnus-summary-save-newsrc t])))
2386
2387     (gnus-run-hooks 'gnus-summary-menu-hook)))
2388
2389 (defvar gnus-summary-tool-bar-map nil)
2390
2391 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2392 (defun gnus-summary-make-tool-bar ()
2393   (if (and (fboundp 'tool-bar-add-item-from-menu)
2394            (default-value 'tool-bar-mode)
2395            (not gnus-summary-tool-bar-map))
2396       (setq gnus-summary-tool-bar-map
2397             (let ((tool-bar-map (make-sparse-keymap))
2398                   (load-path (mm-image-load-path)))
2399               (tool-bar-add-item-from-menu
2400                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2401               (tool-bar-add-item-from-menu
2402                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2403               (tool-bar-add-item-from-menu
2404                'gnus-summary-post-news "post" gnus-summary-mode-map)
2405               (tool-bar-add-item-from-menu
2406                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2407               (tool-bar-add-item-from-menu
2408                'gnus-summary-followup "followup" gnus-summary-mode-map)
2409               (tool-bar-add-item-from-menu
2410                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2411               (tool-bar-add-item-from-menu
2412                'gnus-summary-reply "reply" gnus-summary-mode-map)
2413               (tool-bar-add-item-from-menu
2414                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2415               (tool-bar-add-item-from-menu
2416                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2417               (tool-bar-add-item-from-menu
2418                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2419               (tool-bar-add-item-from-menu
2420                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2421               (tool-bar-add-item-from-menu
2422                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2423               (tool-bar-add-item-from-menu
2424                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2425               (tool-bar-add-item-from-menu
2426                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2427               (tool-bar-add-item-from-menu
2428                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2429               tool-bar-map)))
2430   (if gnus-summary-tool-bar-map
2431       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2432
2433 (defun gnus-score-set-default (var value)
2434   "A version of set that updates the GNU Emacs menu-bar."
2435   (set var value)
2436   ;; It is the message that forces the active status to be updated.
2437   (message ""))
2438
2439 (defun gnus-make-score-map (type)
2440   "Make a summary score map of type TYPE."
2441   (if t
2442       nil
2443     (let ((headers '(("author" "from" string)
2444                      ("subject" "subject" string)
2445                      ("article body" "body" string)
2446                      ("article head" "head" string)
2447                      ("xref" "xref" string)
2448                      ("extra header" "extra" string)
2449                      ("lines" "lines" number)
2450                      ("followups to author" "followup" string)))
2451           (types '((number ("less than" <)
2452                            ("greater than" >)
2453                            ("equal" =))
2454                    (string ("substring" s)
2455                            ("exact string" e)
2456                            ("fuzzy string" f)
2457                            ("regexp" r))))
2458           (perms '(("temporary" (current-time-string))
2459                    ("permanent" nil)
2460                    ("immediate" now)))
2461           header)
2462       (list
2463        (apply
2464         'nconc
2465         (list
2466          (if (eq type 'lower)
2467              "Lower score"
2468            "Increase score"))
2469         (let (outh)
2470           (while headers
2471             (setq header (car headers))
2472             (setq outh
2473                   (cons
2474                    (apply
2475                     'nconc
2476                     (list (car header))
2477                     (let ((ts (cdr (assoc (nth 2 header) types)))
2478                           outt)
2479                       (while ts
2480                         (setq outt
2481                               (cons
2482                                (apply
2483                                 'nconc
2484                                 (list (caar ts))
2485                                 (let ((ps perms)
2486                                       outp)
2487                                   (while ps
2488                                     (setq outp
2489                                           (cons
2490                                            (vector
2491                                             (caar ps)
2492                                             (list
2493                                              'gnus-summary-score-entry
2494                                              (nth 1 header)
2495                                              (if (or (string= (nth 1 header)
2496                                                               "head")
2497                                                      (string= (nth 1 header)
2498                                                               "body"))
2499                                                  ""
2500                                                (list 'gnus-summary-header
2501                                                      (nth 1 header)))
2502                                              (list 'quote (nth 1 (car ts)))
2503                                              (list 'gnus-score-delta-default
2504                                                    nil)
2505                                              (nth 1 (car ps))
2506                                              t)
2507                                             t)
2508                                            outp))
2509                                     (setq ps (cdr ps)))
2510                                   (list (nreverse outp))))
2511                                outt))
2512                         (setq ts (cdr ts)))
2513                       (list (nreverse outt))))
2514                    outh))
2515             (setq headers (cdr headers)))
2516           (list (nreverse outh))))))))
2517
2518 \f
2519
2520 (defun gnus-summary-mode (&optional group)
2521   "Major mode for reading articles.
2522
2523 All normal editing commands are switched off.
2524 \\<gnus-summary-mode-map>
2525 Each line in this buffer represents one article.  To read an
2526 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2527 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2528 respectively.
2529
2530 You can also post articles and send mail from this buffer.  To
2531 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2532 of an article, type `\\[gnus-summary-reply]'.
2533
2534 There are approx. one gazillion commands you can execute in this
2535 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2536
2537 The following commands are available:
2538
2539 \\{gnus-summary-mode-map}"
2540   (interactive)
2541   (kill-all-local-variables)
2542   (when (gnus-visual-p 'summary-menu 'menu)
2543     (gnus-summary-make-menu-bar)
2544     (gnus-summary-make-tool-bar))
2545   (gnus-summary-make-local-variables)
2546   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2547     (gnus-summary-make-local-variables))
2548   (gnus-make-thread-indent-array)
2549   (gnus-simplify-mode-line)
2550   (setq major-mode 'gnus-summary-mode)
2551   (setq mode-name "Summary")
2552   (make-local-variable 'minor-mode-alist)
2553   (use-local-map gnus-summary-mode-map)
2554   (buffer-disable-undo)
2555   (setq buffer-read-only t)             ;Disable modification
2556   (setq truncate-lines t)
2557   (setq selective-display t)
2558   (setq selective-display-ellipses t)   ;Display `...'
2559   (gnus-summary-set-display-table)
2560   (gnus-set-default-directory)
2561   (setq gnus-newsgroup-name group)
2562   (make-local-variable 'gnus-summary-line-format)
2563   (make-local-variable 'gnus-summary-line-format-spec)
2564   (make-local-variable 'gnus-summary-dummy-line-format)
2565   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2566   (make-local-variable 'gnus-summary-mark-positions)
2567   (make-local-hook 'pre-command-hook)
2568   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2569   (gnus-run-hooks 'gnus-summary-mode-hook)
2570   (turn-on-gnus-mailing-list-mode)
2571   (mm-enable-multibyte)
2572   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2573   (gnus-update-summary-mark-positions))
2574
2575 (defun gnus-summary-make-local-variables ()
2576   "Make all the local summary buffer variables."
2577   (let (global)
2578     (dolist (local gnus-summary-local-variables)
2579       (if (consp local)
2580           (progn
2581             (if (eq (cdr local) 'global)
2582                 ;; Copy the global value of the variable.
2583                 (setq global (symbol-value (car local)))
2584               ;; Use the value from the list.
2585               (setq global (eval (cdr local))))
2586             (set (make-local-variable (car local)) global))
2587         ;; Simple nil-valued local variable.
2588         (set (make-local-variable local) nil)))))
2589
2590 (defun gnus-summary-clear-local-variables ()
2591   (let ((locals gnus-summary-local-variables))
2592     (while locals
2593       (if (consp (car locals))
2594           (and (vectorp (caar locals))
2595                (set (caar locals) nil))
2596         (and (vectorp (car locals))
2597              (set (car locals) nil)))
2598       (setq locals (cdr locals)))))
2599
2600 ;; Summary data functions.
2601
2602 (defmacro gnus-data-number (data)
2603   `(car ,data))
2604
2605 (defmacro gnus-data-set-number (data number)
2606   `(setcar ,data ,number))
2607
2608 (defmacro gnus-data-mark (data)
2609   `(nth 1 ,data))
2610
2611 (defmacro gnus-data-set-mark (data mark)
2612   `(setcar (nthcdr 1 ,data) ,mark))
2613
2614 (defmacro gnus-data-pos (data)
2615   `(nth 2 ,data))
2616
2617 (defmacro gnus-data-set-pos (data pos)
2618   `(setcar (nthcdr 2 ,data) ,pos))
2619
2620 (defmacro gnus-data-header (data)
2621   `(nth 3 ,data))
2622
2623 (defmacro gnus-data-set-header (data header)
2624   `(setf (nth 3 ,data) ,header))
2625
2626 (defmacro gnus-data-level (data)
2627   `(nth 4 ,data))
2628
2629 (defmacro gnus-data-unread-p (data)
2630   `(= (nth 1 ,data) gnus-unread-mark))
2631
2632 (defmacro gnus-data-read-p (data)
2633   `(/= (nth 1 ,data) gnus-unread-mark))
2634
2635 (defmacro gnus-data-pseudo-p (data)
2636   `(consp (nth 3 ,data)))
2637
2638 (defmacro gnus-data-find (number)
2639   `(assq ,number gnus-newsgroup-data))
2640
2641 (defmacro gnus-data-find-list (number &optional data)
2642   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2643      (memq (assq ,number bdata)
2644            bdata)))
2645
2646 (defmacro gnus-data-make (number mark pos header level)
2647   `(list ,number ,mark ,pos ,header ,level))
2648
2649 (defun gnus-data-enter (after-article number mark pos header level offset)
2650   (let ((data (gnus-data-find-list after-article)))
2651     (unless data
2652       (error "No such article: %d" after-article))
2653     (setcdr data (cons (gnus-data-make number mark pos header level)
2654                        (cdr data)))
2655     (setq gnus-newsgroup-data-reverse nil)
2656     (gnus-data-update-list (cddr data) offset)))
2657
2658 (defun gnus-data-enter-list (after-article list &optional offset)
2659   (when list
2660     (let ((data (and after-article (gnus-data-find-list after-article)))
2661           (ilist list))
2662       (if (not (or data
2663                    after-article))
2664           (let ((odata gnus-newsgroup-data))
2665             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2666             (when offset
2667               (gnus-data-update-list odata offset)))
2668       ;; Find the last element in the list to be spliced into the main
2669         ;; list.
2670         (while (cdr list)
2671           (setq list (cdr list)))
2672         (if (not data)
2673             (progn
2674               (setcdr list gnus-newsgroup-data)
2675               (setq gnus-newsgroup-data ilist)
2676               (when offset
2677                 (gnus-data-update-list (cdr list) offset)))
2678           (setcdr list (cdr data))
2679           (setcdr data ilist)
2680           (when offset
2681             (gnus-data-update-list (cdr list) offset))))
2682       (setq gnus-newsgroup-data-reverse nil))))
2683
2684 (defun gnus-data-remove (article &optional offset)
2685   (let ((data gnus-newsgroup-data))
2686     (if (= (gnus-data-number (car data)) article)
2687         (progn
2688           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2689                 gnus-newsgroup-data-reverse nil)
2690           (when offset
2691             (gnus-data-update-list gnus-newsgroup-data offset)))
2692       (while (cdr data)
2693         (when (= (gnus-data-number (cadr data)) article)
2694           (setcdr data (cddr data))
2695           (when offset
2696             (gnus-data-update-list (cdr data) offset))
2697           (setq data nil
2698                 gnus-newsgroup-data-reverse nil))
2699         (setq data (cdr data))))))
2700
2701 (defmacro gnus-data-list (backward)
2702   `(if ,backward
2703        (or gnus-newsgroup-data-reverse
2704            (setq gnus-newsgroup-data-reverse
2705                  (reverse gnus-newsgroup-data)))
2706      gnus-newsgroup-data))
2707
2708 (defun gnus-data-update-list (data offset)
2709   "Add OFFSET to the POS of all data entries in DATA."
2710   (setq gnus-newsgroup-data-reverse nil)
2711   (while data
2712     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2713     (setq data (cdr data))))
2714
2715 (defun gnus-summary-article-pseudo-p (article)
2716   "Say whether this article is a pseudo article or not."
2717   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2718
2719 (defmacro gnus-summary-article-sparse-p (article)
2720   "Say whether this article is a sparse article or not."
2721   `(memq ,article gnus-newsgroup-sparse))
2722
2723 (defmacro gnus-summary-article-ancient-p (article)
2724   "Say whether this article is a sparse article or not."
2725   `(memq ,article gnus-newsgroup-ancient))
2726
2727 (defun gnus-article-parent-p (number)
2728   "Say whether this article is a parent or not."
2729   (let ((data (gnus-data-find-list number)))
2730     (and (cdr data)              ; There has to be an article after...
2731          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2732             (gnus-data-level (nth 1 data))))))
2733
2734 (defun gnus-article-children (number)
2735   "Return a list of all children to NUMBER."
2736   (let* ((data (gnus-data-find-list number))
2737          (level (gnus-data-level (car data)))
2738          children)
2739     (setq data (cdr data))
2740     (while (and data
2741                 (= (gnus-data-level (car data)) (1+ level)))
2742       (push (gnus-data-number (car data)) children)
2743       (setq data (cdr data)))
2744     children))
2745
2746 (defmacro gnus-summary-skip-intangible ()
2747   "If the current article is intangible, then jump to a different article."
2748   '(let ((to (get-text-property (point) 'gnus-intangible)))
2749      (and to (gnus-summary-goto-subject to))))
2750
2751 (defmacro gnus-summary-article-intangible-p ()
2752   "Say whether this article is intangible or not."
2753   '(get-text-property (point) 'gnus-intangible))
2754
2755 (defun gnus-article-read-p (article)
2756   "Say whether ARTICLE is read or not."
2757   (not (or (memq article gnus-newsgroup-marked)
2758            (memq article gnus-newsgroup-spam-marked)
2759            (memq article gnus-newsgroup-unreads)
2760            (memq article gnus-newsgroup-unselected)
2761            (memq article gnus-newsgroup-dormant))))
2762
2763 ;; Some summary mode macros.
2764
2765 (defmacro gnus-summary-article-number ()
2766   "The article number of the article on the current line.
2767 If there isn't an article number here, then we return the current
2768 article number."
2769   '(progn
2770      (gnus-summary-skip-intangible)
2771      (or (get-text-property (point) 'gnus-number)
2772          (gnus-summary-last-subject))))
2773
2774 (defmacro gnus-summary-article-header (&optional number)
2775   "Return the header of article NUMBER."
2776   `(gnus-data-header (gnus-data-find
2777                       ,(or number '(gnus-summary-article-number)))))
2778
2779 (defmacro gnus-summary-thread-level (&optional number)
2780   "Return the level of thread that starts with article NUMBER."
2781   `(if (and (eq gnus-summary-make-false-root 'dummy)
2782             (get-text-property (point) 'gnus-intangible))
2783        0
2784      (gnus-data-level (gnus-data-find
2785                        ,(or number '(gnus-summary-article-number))))))
2786
2787 (defmacro gnus-summary-article-mark (&optional number)
2788   "Return the mark of article NUMBER."
2789   `(gnus-data-mark (gnus-data-find
2790                     ,(or number '(gnus-summary-article-number)))))
2791
2792 (defmacro gnus-summary-article-pos (&optional number)
2793   "Return the position of the line of article NUMBER."
2794   `(gnus-data-pos (gnus-data-find
2795                    ,(or number '(gnus-summary-article-number)))))
2796
2797 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2798 (defmacro gnus-summary-article-subject (&optional number)
2799   "Return current subject string or nil if nothing."
2800   `(let ((headers
2801           ,(if number
2802                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2803              '(gnus-data-header (assq (gnus-summary-article-number)
2804                                       gnus-newsgroup-data)))))
2805      (and headers
2806           (vectorp headers)
2807           (mail-header-subject headers))))
2808
2809 (defmacro gnus-summary-article-score (&optional number)
2810   "Return current article score."
2811   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2812                   gnus-newsgroup-scored))
2813        gnus-summary-default-score 0))
2814
2815 (defun gnus-summary-article-children (&optional number)
2816   "Return a list of article numbers that are children of article NUMBER."
2817   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2818          (level (gnus-data-level (car data)))
2819          l children)
2820     (while (and (setq data (cdr data))
2821                 (> (setq l (gnus-data-level (car data))) level))
2822       (and (= (1+ level) l)
2823            (push (gnus-data-number (car data))
2824                  children)))
2825     (nreverse children)))
2826
2827 (defun gnus-summary-article-parent (&optional number)
2828   "Return the article number of the parent of article NUMBER."
2829   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2830                                     (gnus-data-list t)))
2831          (level (gnus-data-level (car data))))
2832     (if (zerop level)
2833         ()                              ; This is a root.
2834       ;; We search until we find an article with a level less than
2835       ;; this one.  That function has to be the parent.
2836       (while (and (setq data (cdr data))
2837                   (not (< (gnus-data-level (car data)) level))))
2838       (and data (gnus-data-number (car data))))))
2839
2840 (defun gnus-unread-mark-p (mark)
2841   "Say whether MARK is the unread mark."
2842   (= mark gnus-unread-mark))
2843
2844 (defun gnus-read-mark-p (mark)
2845   "Say whether MARK is one of the marks that mark as read.
2846 This is all marks except unread, ticked, dormant, and expirable."
2847   (not (or (= mark gnus-unread-mark)
2848            (= mark gnus-ticked-mark)
2849            (= mark gnus-dormant-mark)
2850            (= mark gnus-expirable-mark))))
2851
2852 (defmacro gnus-article-mark (number)
2853   "Return the MARK of article NUMBER.
2854 This macro should only be used when computing the mark the \"first\"
2855 time; i.e., when generating the summary lines.  After that,
2856 `gnus-summary-article-mark' should be used to examine the
2857 marks of articles."
2858   `(cond
2859     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2860 ;;;;    ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2861     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2862     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2863     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2864     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2865     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2866     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2867     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2868            gnus-ancient-mark))))
2869
2870 ;; Saving hidden threads.
2871
2872 (defmacro gnus-save-hidden-threads (&rest forms)
2873   "Save hidden threads, eval FORMS, and restore the hidden threads."
2874   (let ((config (make-symbol "config")))
2875     `(let ((,config (gnus-hidden-threads-configuration)))
2876        (unwind-protect
2877            (save-excursion
2878              ,@forms)
2879          (gnus-restore-hidden-threads-configuration ,config)))))
2880 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2881 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2882
2883 (defun gnus-data-compute-positions ()
2884   "Compute the positions of all articles."
2885   (setq gnus-newsgroup-data-reverse nil)
2886   (let ((data gnus-newsgroup-data))
2887     (save-excursion
2888       (gnus-save-hidden-threads
2889         (gnus-summary-show-all-threads)
2890         (goto-char (point-min))
2891         (while data
2892           (while (get-text-property (point) 'gnus-intangible)
2893             (forward-line 1))
2894           (gnus-data-set-pos (car data) (+ (point) 3))
2895           (setq data (cdr data))
2896           (forward-line 1))))))
2897
2898 (defun gnus-hidden-threads-configuration ()
2899   "Return the current hidden threads configuration."
2900   (save-excursion
2901     (let (config)
2902       (goto-char (point-min))
2903       (while (search-forward "\r" nil t)
2904         (push (1- (point)) config))
2905       config)))
2906
2907 (defun gnus-restore-hidden-threads-configuration (config)
2908   "Restore hidden threads configuration from CONFIG."
2909   (save-excursion
2910     (let (point buffer-read-only)
2911       (while (setq point (pop config))
2912         (when (and (< point (point-max))
2913                    (goto-char point)
2914                    (eq (char-after) ?\n))
2915           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2916
2917 ;; Various summary mode internalish functions.
2918
2919 (defun gnus-mouse-pick-article (e)
2920   (interactive "e")
2921   (mouse-set-point e)
2922   (gnus-summary-next-page nil t))
2923
2924 (defun gnus-summary-set-display-table ()
2925   "Change the display table.
2926 Odd characters have a tendency to mess
2927 up nicely formatted displays - we make all possible glyphs
2928 display only a single character."
2929
2930   ;; We start from the standard display table, if any.
2931   (let ((table (or (copy-sequence standard-display-table)
2932                    (make-display-table)))
2933         (i 32))
2934     ;; Nix out all the control chars...
2935     (while (>= (setq i (1- i)) 0)
2936       (aset table i [??]))
2937    ;; ... but not newline and cr, of course.  (cr is necessary for the
2938     ;; selective display).
2939     (aset table ?\n nil)
2940     (aset table ?\r nil)
2941     ;; We keep TAB as well.
2942     (aset table ?\t nil)
2943     ;; We nix out any glyphs over 126 that are not set already.
2944     (let ((i 256))
2945       (while (>= (setq i (1- i)) 127)
2946         ;; Only modify if the entry is nil.
2947         (unless (aref table i)
2948           (aset table i [??]))))
2949     (setq buffer-display-table table)))
2950
2951 (defun gnus-summary-set-article-display-arrow (pos)
2952   "Update the overlay arrow to point to line at position POS."
2953   (when (and gnus-summary-display-arrow
2954              (boundp 'overlay-arrow-position)
2955              (boundp 'overlay-arrow-string))
2956     (save-excursion
2957       (goto-char pos)
2958       (beginning-of-line)
2959       (unless overlay-arrow-position
2960         (setq overlay-arrow-position (make-marker)))
2961       (setq overlay-arrow-string "=>"
2962             overlay-arrow-position (set-marker overlay-arrow-position
2963                                                (point)
2964                                                (current-buffer))))))
2965
2966 (defun gnus-summary-buffer-name (group)
2967   "Return the summary buffer name of GROUP."
2968   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2969
2970 (defun gnus-summary-setup-buffer (group)
2971   "Initialize summary buffer."
2972   (let ((buffer (gnus-summary-buffer-name group))
2973         (dead-name (concat "*Dead Summary "
2974                            (gnus-group-decoded-name group) "*")))
2975     ;; If a dead summary buffer exists, we kill it.
2976     (when (gnus-buffer-live-p dead-name)
2977       (gnus-kill-buffer dead-name))
2978     (if (get-buffer buffer)
2979         (progn
2980           (set-buffer buffer)
2981           (setq gnus-summary-buffer (current-buffer))
2982           (not gnus-newsgroup-prepared))
2983       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2984       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2985       (gnus-summary-mode group)
2986       (when gnus-carpal
2987         (gnus-carpal-setup-buffer 'summary))
2988       (unless gnus-single-article-buffer
2989         (make-local-variable 'gnus-article-buffer)
2990         (make-local-variable 'gnus-article-current)
2991         (make-local-variable 'gnus-original-article-buffer))
2992       (setq gnus-newsgroup-name group)
2993       ;; Set any local variables in the group parameters.
2994       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2995       t)))
2996
2997 (defun gnus-set-global-variables ()
2998   "Set the global equivalents of the buffer-local variables.
2999 They are set to the latest values they had.  These reflect the summary
3000 buffer that was in action when the last article was fetched."
3001   (when (eq major-mode 'gnus-summary-mode)
3002     (setq gnus-summary-buffer (current-buffer))
3003     (let ((name gnus-newsgroup-name)
3004           (marked gnus-newsgroup-marked)
3005           (spam gnus-newsgroup-spam-marked)
3006           (unread gnus-newsgroup-unreads)
3007           (headers gnus-current-headers)
3008           (data gnus-newsgroup-data)
3009           (summary gnus-summary-buffer)
3010           (article-buffer gnus-article-buffer)
3011           (original gnus-original-article-buffer)
3012           (gac gnus-article-current)
3013           (reffed gnus-reffed-article-number)
3014           (score-file gnus-current-score-file)
3015           (default-charset gnus-newsgroup-charset)
3016           vlist)
3017       (let ((locals gnus-newsgroup-variables))
3018         (while locals
3019           (if (consp (car locals))
3020               (push (eval (caar locals)) vlist)
3021             (push (eval (car locals)) vlist))
3022           (setq locals (cdr locals)))
3023         (setq vlist (nreverse vlist)))
3024       (save-excursion
3025         (set-buffer gnus-group-buffer)
3026         (setq gnus-newsgroup-name name
3027               gnus-newsgroup-marked marked
3028               gnus-newsgroup-spam-marked spam
3029               gnus-newsgroup-unreads unread
3030               gnus-current-headers headers
3031               gnus-newsgroup-data data
3032               gnus-article-current gac
3033               gnus-summary-buffer summary
3034               gnus-article-buffer article-buffer
3035               gnus-original-article-buffer original
3036               gnus-reffed-article-number reffed
3037               gnus-current-score-file score-file
3038               gnus-newsgroup-charset default-charset)
3039         (let ((locals gnus-newsgroup-variables))
3040           (while locals
3041             (if (consp (car locals))
3042                 (set (caar locals) (pop vlist))
3043               (set (car locals) (pop vlist)))
3044             (setq locals (cdr locals))))
3045         ;; The article buffer also has local variables.
3046         (when (gnus-buffer-live-p gnus-article-buffer)
3047           (set-buffer gnus-article-buffer)
3048           (setq gnus-summary-buffer summary))))))
3049
3050 (defun gnus-summary-article-unread-p (article)
3051   "Say whether ARTICLE is unread or not."
3052   (memq article gnus-newsgroup-unreads))
3053
3054 (defun gnus-summary-first-article-p (&optional article)
3055   "Return whether ARTICLE is the first article in the buffer."
3056   (if (not (setq article (or article (gnus-summary-article-number))))
3057       nil
3058     (eq article (caar gnus-newsgroup-data))))
3059
3060 (defun gnus-summary-last-article-p (&optional article)
3061   "Return whether ARTICLE is the last article in the buffer."
3062   (if (not (setq article (or article (gnus-summary-article-number))))
3063       ;; All non-existent numbers are the last article.  :-)
3064       t
3065     (not (cdr (gnus-data-find-list article)))))
3066
3067 (defun gnus-make-thread-indent-array ()
3068   (let ((n 200))
3069     (unless (and gnus-thread-indent-array
3070                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3071       (setq gnus-thread-indent-array (make-vector 201 "")
3072             gnus-thread-indent-array-level gnus-thread-indent-level)
3073       (while (>= n 0)
3074         (aset gnus-thread-indent-array n
3075               (make-string (* n gnus-thread-indent-level) ? ))
3076         (setq n (1- n))))))
3077
3078 (defun gnus-update-summary-mark-positions ()
3079   "Compute where the summary marks are to go."
3080   (save-excursion
3081     (when (gnus-buffer-exists-p gnus-summary-buffer)
3082       (set-buffer gnus-summary-buffer))
3083     (let ((gnus-replied-mark 129)
3084           (gnus-score-below-mark 130)
3085           (gnus-score-over-mark 130)
3086           (gnus-download-mark 131)
3087           (spec gnus-summary-line-format-spec)
3088           gnus-visual pos)
3089       (save-excursion
3090         (gnus-set-work-buffer)
3091         (let ((gnus-summary-line-format-spec spec)
3092               (gnus-newsgroup-downloadable '((0 . t))))
3093           (gnus-summary-insert-line
3094            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
3095            0 nil 128 t nil "" nil 1)
3096           (goto-char (point-min))
3097           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3098                                              (- (point) (point-min) 1)))))
3099           (goto-char (point-min))
3100           (push (cons 'replied (and (search-forward "\201" nil t)
3101                                     (- (point) (point-min) 1)))
3102                 pos)
3103           (goto-char (point-min))
3104           (push (cons 'score (and (search-forward "\202" nil t)
3105                                   (- (point) (point-min) 1)))
3106                 pos)
3107           (goto-char (point-min))
3108           (push (cons 'download
3109                       (and (search-forward "\203" nil t)
3110                            (- (point) (point-min) 1)))
3111                 pos)))
3112       (setq gnus-summary-mark-positions pos))))
3113
3114 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3115   "Insert a dummy root in the summary buffer."
3116   (beginning-of-line)
3117   (gnus-add-text-properties
3118    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3119    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3120
3121 (defun gnus-summary-extract-address-component (from)
3122   (or (car (funcall gnus-extract-address-components from))
3123       from))
3124
3125 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3126   (let ((mail-parse-charset gnus-newsgroup-charset)
3127         ; Is it really necessary to do this next part for each summary line?
3128         ; Luckily, doesn't seem to slow things down much.
3129         (mail-parse-ignored-charsets
3130          (save-excursion (set-buffer gnus-summary-buffer)
3131                          gnus-newsgroup-ignored-charsets)))
3132     (or
3133      (and gnus-ignored-from-addresses
3134           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3135           (let ((extra-headers (mail-header-extra header))
3136                 to
3137                 newsgroups)
3138             (cond
3139              ((setq to (cdr (assq 'To extra-headers)))
3140               (concat "-> "
3141                       (inline
3142                         (gnus-summary-extract-address-component
3143                          (funcall gnus-decode-encoded-word-function to)))))
3144              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3145               (concat "=> " newsgroups)))))
3146      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3147
3148 (defun gnus-summary-insert-line (gnus-tmp-header
3149                                  gnus-tmp-level gnus-tmp-current
3150                                  gnus-tmp-unread gnus-tmp-replied
3151                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3152                                  &optional gnus-tmp-dummy gnus-tmp-score
3153                                  gnus-tmp-process)
3154   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3155          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3156          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3157          (gnus-tmp-score-char
3158           (if (or (null gnus-summary-default-score)
3159                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3160                       gnus-summary-zcore-fuzz))
3161               ?                         ;Whitespace
3162             (if (< gnus-tmp-score gnus-summary-default-score)
3163                 gnus-score-below-mark gnus-score-over-mark)))
3164          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3165          (gnus-tmp-replied
3166           (cond (gnus-tmp-process gnus-process-mark)
3167                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3168                  gnus-cached-mark)
3169                 (gnus-tmp-replied gnus-replied-mark)
3170                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3171                  gnus-forwarded-mark)
3172                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3173                  gnus-saved-mark)
3174                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3175                  gnus-recent-mark)
3176                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3177                  gnus-unseen-mark)
3178                 (t gnus-no-mark)))
3179          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3180          (gnus-tmp-name
3181           (cond
3182            ((string-match "<[^>]+> *$" gnus-tmp-from)
3183             (let ((beg (match-beginning 0)))
3184               (or (and (string-match "^\".+\"" gnus-tmp-from)
3185                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3186                   (substring gnus-tmp-from 0 beg))))
3187            ((string-match "(.+)" gnus-tmp-from)
3188             (substring gnus-tmp-from
3189                        (1+ (match-beginning 0)) (1- (match-end 0))))
3190            (t gnus-tmp-from)))
3191          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3192          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3193          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3194          (buffer-read-only nil))
3195     (when (string= gnus-tmp-name "")
3196       (setq gnus-tmp-name gnus-tmp-from))
3197     (unless (numberp gnus-tmp-lines)
3198       (setq gnus-tmp-lines -1))
3199     (if (= gnus-tmp-lines -1)
3200         (setq gnus-tmp-lines "?")
3201       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3202     (gnus-put-text-property
3203      (point)
3204      (progn (eval gnus-summary-line-format-spec) (point))
3205      'gnus-number gnus-tmp-number)
3206     (when (gnus-visual-p 'summary-highlight 'highlight)
3207       (forward-line -1)
3208       (gnus-run-hooks 'gnus-summary-update-hook)
3209       (forward-line 1))))
3210
3211 (defun gnus-summary-update-line (&optional dont-update)
3212   "Update summary line after change."
3213   (when (and gnus-summary-default-score
3214              (not gnus-summary-inhibit-highlight))
3215     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3216            (article (gnus-summary-article-number))
3217            (score (gnus-summary-article-score article)))
3218       (unless dont-update
3219         (if (and gnus-summary-mark-below
3220                  (< (gnus-summary-article-score)
3221                     gnus-summary-mark-below))
3222             ;; This article has a low score, so we mark it as read.
3223             (when (memq article gnus-newsgroup-unreads)
3224               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3225           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3226             ;; This article was previously marked as read on account
3227             ;; of a low score, but now it has risen, so we mark it as
3228             ;; unread.
3229             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3230         (gnus-summary-update-mark
3231          (if (or (null gnus-summary-default-score)
3232                  (<= (abs (- score gnus-summary-default-score))
3233                      gnus-summary-zcore-fuzz))
3234              ?                          ;Whitespace
3235            (if (< score gnus-summary-default-score)
3236                gnus-score-below-mark gnus-score-over-mark))
3237          'score))
3238       ;; Do visual highlighting.
3239       (when (gnus-visual-p 'summary-highlight 'highlight)
3240         (gnus-run-hooks 'gnus-summary-update-hook)))))
3241
3242 (defvar gnus-tmp-new-adopts nil)
3243
3244 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3245   "Return the number of articles in THREAD.
3246 This may be 0 in some cases -- if none of the articles in
3247 the thread are to be displayed."
3248   (let* ((number
3249          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3250           (cond
3251            ((not (listp thread))
3252             1)
3253            ((and (consp thread) (cdr thread))
3254             (apply
3255              '+ 1 (mapcar
3256                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3257            ((null thread)
3258             1)
3259            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3260             1)
3261            (t 0))))
3262     (when (and level (zerop level) gnus-tmp-new-adopts)
3263       (incf number
3264             (apply '+ (mapcar
3265                        'gnus-summary-number-of-articles-in-thread
3266                        gnus-tmp-new-adopts))))
3267     (if char
3268         (if (> number 1) gnus-not-empty-thread-mark
3269           gnus-empty-thread-mark)
3270       number)))
3271
3272 (defsubst gnus-summary-line-message-size (head)
3273   "Return pretty-printed version of message size.
3274 This function is intended to be used in
3275 `gnus-summary-line-format-alist', which see."
3276   (let ((c (or (mail-header-chars head) -1)))
3277     (cond ((< c 0) "n/a")               ; chars not available
3278           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3279           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3280           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3281           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3282
3283
3284 (defun gnus-summary-set-local-parameters (group)
3285   "Go through the local params of GROUP and set all variable specs in that list."
3286   (let ((params (gnus-group-find-parameter group))
3287         (vars '(quit-config))           ; Ignore quit-config.
3288         elem)
3289     (while params
3290       (setq elem (car params)
3291             params (cdr params))
3292       (and (consp elem)                 ; Has to be a cons.
3293            (consp (cdr elem))           ; The cdr has to be a list.
3294            (symbolp (car elem))         ; Has to be a symbol in there.
3295            (not (memq (car elem) vars))
3296            (ignore-errors               ; So we set it.
3297              (push (car elem) vars)
3298              (make-local-variable (car elem))
3299              (set (car elem) (eval (nth 1 elem))))))))
3300
3301 (defun gnus-summary-read-group (group &optional show-all no-article
3302                                       kill-buffer no-display backward
3303                                       select-articles)
3304   "Start reading news in newsgroup GROUP.
3305 If SHOW-ALL is non-nil, already read articles are also listed.
3306 If NO-ARTICLE is non-nil, no article is selected initially.
3307 If NO-DISPLAY, don't generate a summary buffer."
3308   (let (result)
3309     (while (and group
3310                 (null (setq result
3311                             (let ((gnus-auto-select-next nil))
3312                               (or (gnus-summary-read-group-1
3313                                    group show-all no-article
3314                                    kill-buffer no-display
3315                                    select-articles)
3316                                   (setq show-all nil
3317                                         select-articles nil)))))
3318                 (eq gnus-auto-select-next 'quietly))
3319       (set-buffer gnus-group-buffer)
3320       ;; The entry function called above goes to the next
3321       ;; group automatically, so we go two groups back
3322       ;; if we are searching for the previous group.
3323       (when backward
3324         (gnus-group-prev-unread-group 2))
3325       (if (not (equal group (gnus-group-group-name)))
3326           (setq group (gnus-group-group-name))
3327         (setq group nil)))
3328     result))
3329
3330 (defun gnus-summary-read-group-1 (group show-all no-article
3331                                         kill-buffer no-display
3332                                         &optional select-articles)
3333   ;; Killed foreign groups can't be entered.
3334   ;;  (when (and (not (gnus-group-native-p group))
3335   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3336   ;;    (error "Dead non-native groups can't be entered"))
3337   (gnus-message 5 "Retrieving newsgroup: %s..."
3338                 (gnus-group-decoded-name group))
3339   (let* ((new-group (gnus-summary-setup-buffer group))
3340          (quit-config (gnus-group-quit-config group))
3341          (did-select (and new-group (gnus-select-newsgroup
3342                                      group show-all select-articles))))
3343     (cond
3344      ;; This summary buffer exists already, so we just select it.
3345      ((not new-group)
3346       (gnus-set-global-variables)
3347       (when kill-buffer
3348         (gnus-kill-or-deaden-summary kill-buffer))
3349       (gnus-configure-windows 'summary 'force)
3350       (gnus-set-mode-line 'summary)
3351       (gnus-summary-position-point)
3352       (message "")
3353       t)
3354      ;; We couldn't select this group.
3355      ((null did-select)
3356       (when (and (eq major-mode 'gnus-summary-mode)
3357                  (not (equal (current-buffer) kill-buffer)))
3358         (kill-buffer (current-buffer))
3359         (if (not quit-config)
3360             (progn
3361               ;; Update the info -- marks might need to be removed,
3362               ;; for instance.
3363               (gnus-summary-update-info)
3364               (set-buffer gnus-group-buffer)
3365               (gnus-group-jump-to-group group)
3366               (gnus-group-next-unread-group 1))
3367           (gnus-handle-ephemeral-exit quit-config)))
3368       (let ((grpinfo (gnus-get-info group)))
3369         (if (null (gnus-info-read grpinfo))
3370             (gnus-message 3 "Group %s contains no messages"
3371                           (gnus-group-decoded-name group))
3372           (gnus-message 3 "Can't select group")))
3373       nil)
3374      ;; The user did a `C-g' while prompting for number of articles,
3375      ;; so we exit this group.
3376      ((eq did-select 'quit)
3377       (and (eq major-mode 'gnus-summary-mode)
3378            (not (equal (current-buffer) kill-buffer))
3379            (kill-buffer (current-buffer)))
3380       (when kill-buffer
3381         (gnus-kill-or-deaden-summary kill-buffer))
3382       (if (not quit-config)
3383           (progn
3384             (set-buffer gnus-group-buffer)
3385             (gnus-group-jump-to-group group)
3386             (gnus-group-next-unread-group 1)
3387             (gnus-configure-windows 'group 'force))
3388         (gnus-handle-ephemeral-exit quit-config))
3389       ;; Finally signal the quit.
3390       (signal 'quit nil))
3391      ;; The group was successfully selected.
3392      (t
3393       (gnus-set-global-variables)
3394       ;; Save the active value in effect when the group was entered.
3395       (setq gnus-newsgroup-active
3396             (gnus-copy-sequence
3397              (gnus-active gnus-newsgroup-name)))
3398       ;; You can change the summary buffer in some way with this hook.
3399       (gnus-run-hooks 'gnus-select-group-hook)
3400       (gnus-update-format-specifications
3401        nil 'summary 'summary-mode 'summary-dummy)
3402       (gnus-update-summary-mark-positions)
3403       ;; Do score processing.
3404       (when gnus-use-scoring
3405         (gnus-possibly-score-headers))
3406       ;; Check whether to fill in the gaps in the threads.
3407       (when gnus-build-sparse-threads
3408         (gnus-build-sparse-threads))
3409       ;; Find the initial limit.
3410       (if gnus-show-threads
3411           (if show-all
3412               (let ((gnus-newsgroup-dormant nil))
3413                 (gnus-summary-initial-limit show-all))
3414             (gnus-summary-initial-limit show-all))
3415         ;; When unthreaded, all articles are always shown.
3416         (setq gnus-newsgroup-limit
3417               (mapcar
3418                (lambda (header) (mail-header-number header))
3419                gnus-newsgroup-headers)))
3420       ;; Generate the summary buffer.
3421       (unless no-display
3422         (gnus-summary-prepare))
3423       (when gnus-use-trees
3424         (gnus-tree-open group)
3425         (setq gnus-summary-highlight-line-function
3426               'gnus-tree-highlight-article))
3427       ;; If the summary buffer is empty, but there are some low-scored
3428       ;; articles or some excluded dormants, we include these in the
3429       ;; buffer.
3430       (when (and (zerop (buffer-size))
3431                  (not no-display))
3432         (cond (gnus-newsgroup-dormant
3433                (gnus-summary-limit-include-dormant))
3434               ((and gnus-newsgroup-scored show-all)
3435                (gnus-summary-limit-include-expunged t))))
3436       ;; Function `gnus-apply-kill-file' must be called in this hook.
3437       (gnus-run-hooks 'gnus-apply-kill-hook)
3438       (if (and (zerop (buffer-size))
3439                (not no-display))
3440           (progn
3441             ;; This newsgroup is empty.
3442             (gnus-summary-catchup-and-exit nil t)
3443             (gnus-message 6 "No unread news")
3444             (when kill-buffer
3445               (gnus-kill-or-deaden-summary kill-buffer))
3446             ;; Return nil from this function.
3447             nil)
3448         ;; Hide conversation thread subtrees.  We cannot do this in
3449         ;; gnus-summary-prepare-hook since kill processing may not
3450         ;; work with hidden articles.
3451         (gnus-summary-maybe-hide-threads)
3452         (when kill-buffer
3453           (gnus-kill-or-deaden-summary kill-buffer))
3454         (gnus-summary-auto-select-subject)
3455         ;; Show first unread article if requested.
3456         (if (and (not no-article)
3457                  (not no-display)
3458                  gnus-newsgroup-unreads
3459                  gnus-auto-select-first)
3460             (progn
3461               (gnus-configure-windows 'summary)
3462               (let ((art (gnus-summary-article-number)))
3463                 (unless (or (memq art gnus-newsgroup-undownloaded)
3464                             (memq art gnus-newsgroup-downloadable))
3465                   (gnus-summary-goto-article art))))
3466           ;; Don't select any articles.
3467           (gnus-summary-position-point)
3468           (gnus-configure-windows 'summary 'force)
3469           (gnus-set-mode-line 'summary))
3470         (when (get-buffer-window gnus-group-buffer t)
3471           ;; Gotta use windows, because recenter does weird stuff if
3472           ;; the current buffer ain't the displayed window.
3473           (let ((owin (selected-window)))
3474             (select-window (get-buffer-window gnus-group-buffer t))
3475             (when (gnus-group-goto-group group)
3476               (recenter))
3477             (select-window owin)))
3478         ;; Mark this buffer as "prepared".
3479         (setq gnus-newsgroup-prepared t)
3480         (gnus-run-hooks 'gnus-summary-prepared-hook)
3481         t)))))
3482
3483 (defun gnus-summary-auto-select-subject ()
3484   "Select the subject line on initial group entry."
3485   (goto-char (point-min))
3486   (cond
3487    ((eq gnus-auto-select-subject 'best)
3488     (gnus-summary-best-unread-subject))
3489    ((eq gnus-auto-select-subject 'unread)
3490     (gnus-summary-first-unread-subject))
3491    ((eq gnus-auto-select-subject 'unseen)
3492     (gnus-summary-first-unseen-subject))
3493    ((eq gnus-auto-select-subject 'unseen-or-unread)
3494     (gnus-summary-first-unseen-or-unread-subject))
3495    ((eq gnus-auto-select-subject 'first)
3496     ;; Do nothing.
3497     )
3498    ((gnus-functionp gnus-auto-select-subject)
3499     (funcall gnus-auto-select-subject))))
3500
3501 (defun gnus-summary-prepare ()
3502   "Generate the summary buffer."
3503   (interactive)
3504   (let ((buffer-read-only nil))
3505     (erase-buffer)
3506     (setq gnus-newsgroup-data nil
3507           gnus-newsgroup-data-reverse nil)
3508     (gnus-run-hooks 'gnus-summary-generate-hook)
3509     ;; Generate the buffer, either with threads or without.
3510     (when gnus-newsgroup-headers
3511       (gnus-summary-prepare-threads
3512        (if gnus-show-threads
3513            (gnus-sort-gathered-threads
3514             (funcall gnus-summary-thread-gathering-function
3515                      (gnus-sort-threads
3516                       (gnus-cut-threads (gnus-make-threads)))))
3517          ;; Unthreaded display.
3518          (gnus-sort-articles gnus-newsgroup-headers))))
3519     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3520     ;; Call hooks for modifying summary buffer.
3521     (goto-char (point-min))
3522     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3523
3524 (defsubst gnus-general-simplify-subject (subject)
3525   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3526   (setq subject
3527         (cond
3528          ;; Truncate the subject.
3529          (gnus-simplify-subject-functions
3530           (gnus-map-function gnus-simplify-subject-functions subject))
3531          ((numberp gnus-summary-gather-subject-limit)
3532           (setq subject (gnus-simplify-subject-re subject))
3533           (if (> (length subject) gnus-summary-gather-subject-limit)
3534               (substring subject 0 gnus-summary-gather-subject-limit)
3535             subject))
3536          ;; Fuzzily simplify it.
3537          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3538           (gnus-simplify-subject-fuzzy subject))
3539          ;; Just remove the leading "Re:".
3540          (t
3541           (gnus-simplify-subject-re subject))))
3542
3543   (if (and gnus-summary-gather-exclude-subject
3544            (string-match gnus-summary-gather-exclude-subject subject))
3545       nil                         ; This article shouldn't be gathered
3546     subject))
3547
3548 (defun gnus-summary-simplify-subject-query ()
3549   "Query where the respool algorithm would put this article."
3550   (interactive)
3551   (gnus-summary-select-article)
3552   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3553
3554 (defun gnus-gather-threads-by-subject (threads)
3555   "Gather threads by looking at Subject headers."
3556   (if (not gnus-summary-make-false-root)
3557       threads
3558     (let ((hashtb (gnus-make-hashtable 1024))
3559           (prev threads)
3560           (result threads)
3561           subject hthread whole-subject)
3562       (while threads
3563         (setq subject (gnus-general-simplify-subject
3564                        (setq whole-subject (mail-header-subject
3565                                             (caar threads)))))
3566         (when subject
3567           (if (setq hthread (gnus-gethash subject hashtb))
3568               (progn
3569                 ;; We enter a dummy root into the thread, if we
3570                 ;; haven't done that already.
3571                 (unless (stringp (caar hthread))
3572                   (setcar hthread (list whole-subject (car hthread))))
3573                 ;; We add this new gathered thread to this gathered
3574                 ;; thread.
3575                 (setcdr (car hthread)
3576                         (nconc (cdar hthread) (list (car threads))))
3577                 ;; Remove it from the list of threads.
3578                 (setcdr prev (cdr threads))
3579                 (setq threads prev))
3580             ;; Enter this thread into the hash table.
3581             (gnus-sethash subject threads hashtb)))
3582         (setq prev threads)
3583         (setq threads (cdr threads)))
3584       result)))
3585
3586 (defun gnus-gather-threads-by-references (threads)
3587   "Gather threads by looking at References headers."
3588   (let ((idhashtb (gnus-make-hashtable 1024))
3589         (thhashtb (gnus-make-hashtable 1024))
3590         (prev threads)
3591         (result threads)
3592         ids references id gthread gid entered ref)
3593     (while threads
3594       (when (setq references (mail-header-references (caar threads)))
3595         (setq id (mail-header-id (caar threads))
3596               ids (inline (gnus-split-references references))
3597               entered nil)
3598         (while (setq ref (pop ids))
3599           (setq ids (delete ref ids))
3600           (if (not (setq gid (gnus-gethash ref idhashtb)))
3601               (progn
3602                 (gnus-sethash ref id idhashtb)
3603                 (gnus-sethash id threads thhashtb))
3604             (setq gthread (gnus-gethash gid thhashtb))
3605             (unless entered
3606               ;; We enter a dummy root into the thread, if we
3607               ;; haven't done that already.
3608               (unless (stringp (caar gthread))
3609                 (setcar gthread (list (mail-header-subject (caar gthread))
3610                                       (car gthread))))
3611               ;; We add this new gathered thread to this gathered
3612               ;; thread.
3613               (setcdr (car gthread)
3614                       (nconc (cdar gthread) (list (car threads)))))
3615             ;; Add it into the thread hash table.
3616             (gnus-sethash id gthread thhashtb)
3617             (setq entered t)
3618             ;; Remove it from the list of threads.
3619             (setcdr prev (cdr threads))
3620             (setq threads prev))))
3621       (setq prev threads)
3622       (setq threads (cdr threads)))
3623     result))
3624
3625 (defun gnus-sort-gathered-threads (threads)
3626   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3627   (let ((result threads))
3628     (while threads
3629       (when (stringp (caar threads))
3630         (setcdr (car threads)
3631                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3632       (setq threads (cdr threads)))
3633     result))
3634
3635 (defun gnus-thread-loop-p (root thread)
3636   "Say whether ROOT is in THREAD."
3637   (let ((stack (list thread))
3638         (infloop 0)
3639         th)
3640     (while (setq thread (pop stack))
3641       (setq th (cdr thread))
3642       (while (and th
3643                   (not (eq (caar th) root)))
3644         (pop th))
3645       (if th
3646           ;; We have found a loop.
3647           (let (ref-dep)
3648             (setcdr thread (delq (car th) (cdr thread)))
3649             (if (boundp (setq ref-dep (intern "none"
3650                                               gnus-newsgroup-dependencies)))
3651                 (setcdr (symbol-value ref-dep)
3652                         (nconc (cdr (symbol-value ref-dep))
3653                                (list (car th))))
3654               (set ref-dep (list nil (car th))))
3655             (setq infloop 1
3656                   stack nil))
3657         ;; Push all the subthreads onto the stack.
3658         (push (cdr thread) stack)))
3659     infloop))
3660
3661 (defun gnus-make-threads ()
3662   "Go through the dependency hashtb and find the roots.  Return all threads."
3663   (let (threads)
3664     (while (catch 'infloop
3665              (mapatoms
3666               (lambda (refs)
3667                 ;; Deal with self-referencing References loops.
3668                 (when (and (car (symbol-value refs))
3669                            (not (zerop
3670                                  (apply
3671                                   '+
3672                                   (mapcar
3673                                    (lambda (thread)
3674                                      (gnus-thread-loop-p
3675                                       (car (symbol-value refs)) thread))
3676                                    (cdr (symbol-value refs)))))))
3677                   (setq threads nil)
3678                   (throw 'infloop t))
3679                 (unless (car (symbol-value refs))
3680                   ;; These threads do not refer back to any other
3681                   ;; articles, so they're roots.
3682                   (setq threads (append (cdr (symbol-value refs)) threads))))
3683               gnus-newsgroup-dependencies)))
3684     threads))
3685
3686 ;; Build the thread tree.
3687 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3688   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3689
3690 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3691 if it was already present.
3692
3693 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3694 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3695 Message-IDs will be renamed to a unique Message-ID before being
3696 entered.
3697
3698 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3699   (let* ((id (mail-header-id header))
3700          (id-dep (and id (intern id dependencies)))
3701          parent-id ref ref-dep ref-header replaced)
3702     ;; Enter this `header' in the `dependencies' table.
3703     (cond
3704      ((not id-dep)
3705       (setq header nil))
3706      ;; The first two cases do the normal part: enter a new `header'
3707      ;; in the `dependencies' table.
3708      ((not (boundp id-dep))
3709       (set id-dep (list header)))
3710      ((null (car (symbol-value id-dep)))
3711       (setcar (symbol-value id-dep) header))
3712
3713      ;; From here the `header' was already present in the
3714      ;; `dependencies' table.
3715      (force-new
3716       ;; Overrides an existing entry;
3717       ;; just set the header part of the entry.
3718       (setcar (symbol-value id-dep) header)
3719       (setq replaced t))
3720
3721      ;; Renames the existing `header' to a unique Message-ID.
3722      ((not gnus-summary-ignore-duplicates)
3723       ;; An article with this Message-ID has already been seen.
3724       ;; We rename the Message-ID.
3725       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3726            (list header))
3727       (mail-header-set-id header id))
3728
3729      ;; The last case ignores an existing entry, except it adds any
3730      ;; additional Xrefs (in case the two articles came from different
3731      ;; servers.
3732      ;; Also sets `header' to `nil' meaning that the `dependencies'
3733      ;; table was *not* modified.
3734      (t
3735       (mail-header-set-xref
3736        (car (symbol-value id-dep))
3737        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3738                    "")
3739                (or (mail-header-xref header) "")))
3740       (setq header nil)))
3741
3742     (when (and header (not replaced))
3743       ;; First check that we are not creating a References loop.
3744       (setq parent-id (gnus-parent-id (mail-header-references header)))
3745       (setq ref parent-id)
3746       (while (and ref
3747                   (setq ref-dep (intern-soft ref dependencies))
3748                   (boundp ref-dep)
3749                   (setq ref-header (car (symbol-value ref-dep))))
3750         (if (string= id ref)
3751             ;; Yuk!  This is a reference loop.  Make the article be a
3752             ;; root article.
3753             (progn
3754               (mail-header-set-references (car (symbol-value id-dep)) "none")
3755               (setq ref nil)
3756               (setq parent-id nil))
3757           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3758       (setq ref-dep (intern (or parent-id "none") dependencies))
3759       (if (boundp ref-dep)
3760           (setcdr (symbol-value ref-dep)
3761                   (nconc (cdr (symbol-value ref-dep))
3762                          (list (symbol-value id-dep))))
3763         (set ref-dep (list nil (symbol-value id-dep)))))
3764     header))
3765
3766 (defun gnus-extract-message-id-from-in-reply-to (string)
3767   (if (string-match "<[^>]+>" string)
3768       (substring string (match-beginning 0) (match-end 0))
3769     nil))
3770
3771 (defun gnus-build-sparse-threads ()
3772   (let ((headers gnus-newsgroup-headers)
3773         (mail-parse-charset gnus-newsgroup-charset)
3774         (gnus-summary-ignore-duplicates t)
3775         header references generation relations
3776         subject child end new-child date)
3777     ;; First we create an alist of generations/relations, where
3778     ;; generations is how much we trust the relation, and the relation
3779     ;; is parent/child.
3780     (gnus-message 7 "Making sparse threads...")
3781     (save-excursion
3782       (nnheader-set-temp-buffer " *gnus sparse threads*")
3783       (while (setq header (pop headers))
3784         (when (and (setq references (mail-header-references header))
3785                    (not (string= references "")))
3786           (insert references)
3787           (setq child (mail-header-id header)
3788                 subject (mail-header-subject header)
3789                 date (mail-header-date header)
3790                 generation 0)
3791           (while (search-backward ">" nil t)
3792             (setq end (1+ (point)))
3793             (when (search-backward "<" nil t)
3794               (setq new-child (buffer-substring (point) end))
3795               (push (list (incf generation)
3796                           child (setq child new-child)
3797                           subject date)
3798                     relations)))
3799           (when child
3800             (push (list (1+ generation) child nil subject) relations))
3801           (erase-buffer)))
3802       (kill-buffer (current-buffer)))
3803     ;; Sort over trustworthiness.
3804     (mapcar
3805      (lambda (relation)
3806        (when (gnus-dependencies-add-header
3807               (make-full-mail-header
3808                gnus-reffed-article-number
3809                (nth 3 relation) "" (or (nth 4 relation) "")
3810                (nth 1 relation)
3811                (or (nth 2 relation) "") 0 0 "")
3812               gnus-newsgroup-dependencies nil)
3813          (push gnus-reffed-article-number gnus-newsgroup-limit)
3814          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3815          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3816                gnus-newsgroup-reads)
3817          (decf gnus-reffed-article-number)))
3818      (sort relations 'car-less-than-car))
3819     (gnus-message 7 "Making sparse threads...done")))
3820
3821 (defun gnus-build-old-threads ()
3822   ;; Look at all the articles that refer back to old articles, and
3823   ;; fetch the headers for the articles that aren't there.  This will
3824   ;; build complete threads - if the roots haven't been expired by the
3825   ;; server, that is.
3826   (let ((mail-parse-charset gnus-newsgroup-charset)
3827         id heads)
3828     (mapatoms
3829      (lambda (refs)
3830        (when (not (car (symbol-value refs)))
3831          (setq heads (cdr (symbol-value refs)))
3832          (while heads
3833            (if (memq (mail-header-number (caar heads))
3834                      gnus-newsgroup-dormant)
3835                (setq heads (cdr heads))
3836              (setq id (symbol-name refs))
3837              (while (and (setq id (gnus-build-get-header id))
3838                          (not (car (gnus-id-to-thread id)))))
3839              (setq heads nil)))))
3840      gnus-newsgroup-dependencies)))
3841
3842 ;; This function has to be called with point after the article number
3843 ;; on the beginning of the line.
3844 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3845   (let ((eol (gnus-point-at-eol))
3846         (buffer (current-buffer))
3847         header references in-reply-to)
3848
3849     ;; overview: [num subject from date id refs chars lines misc]
3850     (unwind-protect
3851         (let (x)
3852           (narrow-to-region (point) eol)
3853           (unless (eobp)
3854             (forward-char))
3855
3856           (setq header
3857                 (make-full-mail-header
3858                  number                 ; number
3859                  (condition-case ()     ; subject
3860                      (funcall gnus-decode-encoded-word-function
3861                               (setq x (nnheader-nov-field)))
3862                    (error x))
3863                  (condition-case ()     ; from
3864                      (funcall gnus-decode-encoded-word-function
3865                               (setq x (nnheader-nov-field)))
3866                    (error x))
3867                  (nnheader-nov-field)   ; date
3868                  (nnheader-nov-read-message-id) ; id
3869                  (setq references (nnheader-nov-field)) ; refs
3870                  (nnheader-nov-read-integer) ; chars
3871                  (nnheader-nov-read-integer) ; lines
3872                  (unless (eobp)
3873                    (if (looking-at "Xref: ")
3874                        (goto-char (match-end 0)))
3875                    (nnheader-nov-field)) ; Xref
3876                  (nnheader-nov-parse-extra)))) ; extra
3877
3878       (widen))
3879
3880     (when (and (string= references "")
3881                (setq in-reply-to (mail-header-extra header))
3882                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3883       (mail-header-set-references
3884        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3885
3886     (when gnus-alter-header-function
3887       (funcall gnus-alter-header-function header))
3888     (gnus-dependencies-add-header header dependencies force-new)))
3889
3890 (defun gnus-build-get-header (id)
3891   "Look through the buffer of NOV lines and find the header to ID.
3892 Enter this line into the dependencies hash table, and return
3893 the id of the parent article (if any)."
3894   (let ((deps gnus-newsgroup-dependencies)
3895         found header)
3896     (prog1
3897         (save-excursion
3898           (set-buffer nntp-server-buffer)
3899           (let ((case-fold-search nil))
3900             (goto-char (point-min))
3901             (while (and (not found)
3902                         (search-forward id nil t))
3903               (beginning-of-line)
3904               (setq found (looking-at
3905                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3906                                    (regexp-quote id))))
3907               (or found (beginning-of-line 2)))
3908             (when found
3909               (beginning-of-line)
3910               (and
3911                (setq header (gnus-nov-parse-line
3912                              (read (current-buffer)) deps))
3913                (gnus-parent-id (mail-header-references header))))))
3914       (when header
3915         (let ((number (mail-header-number header)))
3916           (push number gnus-newsgroup-limit)
3917           (push header gnus-newsgroup-headers)
3918           (if (memq number gnus-newsgroup-unselected)
3919               (progn
3920                 (setq gnus-newsgroup-unreads
3921                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3922                                                number))
3923                 (setq gnus-newsgroup-unselected
3924                       (delq number gnus-newsgroup-unselected)))
3925             (push number gnus-newsgroup-ancient)))))))
3926
3927 (defun gnus-build-all-threads ()
3928   "Read all the headers."
3929   (let ((gnus-summary-ignore-duplicates t)
3930         (mail-parse-charset gnus-newsgroup-charset)
3931         (dependencies gnus-newsgroup-dependencies)
3932         header article)
3933     (save-excursion
3934       (set-buffer nntp-server-buffer)
3935       (let ((case-fold-search nil))
3936         (goto-char (point-min))
3937         (while (not (eobp))
3938           (ignore-errors
3939             (setq article (read (current-buffer))
3940                   header (gnus-nov-parse-line article dependencies)))
3941           (when header
3942             (save-excursion
3943               (set-buffer gnus-summary-buffer)
3944               (push header gnus-newsgroup-headers)
3945               (if (memq (setq article (mail-header-number header))
3946                         gnus-newsgroup-unselected)
3947                   (progn
3948                     (setq gnus-newsgroup-unreads
3949                           (gnus-add-to-sorted-list
3950                            gnus-newsgroup-unreads article))
3951                     (setq gnus-newsgroup-unselected
3952                           (delq article gnus-newsgroup-unselected)))
3953                 (push article gnus-newsgroup-ancient)))
3954             (forward-line 1)))))))
3955
3956 (defun gnus-summary-update-article-line (article header)
3957   "Update the line for ARTICLE using HEADERS."
3958   (let* ((id (mail-header-id header))
3959          (thread (gnus-id-to-thread id)))
3960     (unless thread
3961       (error "Article in no thread"))
3962     ;; Update the thread.
3963     (setcar thread header)
3964     (gnus-summary-goto-subject article)
3965     (let* ((datal (gnus-data-find-list article))
3966            (data (car datal))
3967            (length (when (cdr datal)
3968                      (- (gnus-data-pos data)
3969                         (gnus-data-pos (cadr datal)))))
3970            (buffer-read-only nil)
3971            (level (gnus-summary-thread-level)))
3972       (gnus-delete-line)
3973       (gnus-summary-insert-line
3974        header level nil (gnus-article-mark article)
3975        (memq article gnus-newsgroup-replied)
3976        (memq article gnus-newsgroup-expirable)
3977        ;; Only insert the Subject string when it's different
3978        ;; from the previous Subject string.
3979        (if (and
3980             gnus-show-threads
3981             (gnus-subject-equal
3982              (condition-case ()
3983                  (mail-header-subject
3984                   (gnus-data-header
3985                    (cadr
3986                     (gnus-data-find-list
3987                      article
3988                      (gnus-data-list t)))))
3989                ;; Error on the side of excessive subjects.
3990                (error ""))
3991              (mail-header-subject header)))
3992            ""
3993          (mail-header-subject header))
3994        nil (cdr (assq article gnus-newsgroup-scored))
3995        (memq article gnus-newsgroup-processable))
3996       (when length
3997         (gnus-data-update-list
3998          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3999
4000 (defun gnus-summary-update-article (article &optional iheader)
4001   "Update ARTICLE in the summary buffer."
4002   (set-buffer gnus-summary-buffer)
4003   (let* ((header (gnus-summary-article-header article))
4004          (id (mail-header-id header))
4005          (data (gnus-data-find article))
4006          (thread (gnus-id-to-thread id))
4007          (references (mail-header-references header))
4008          (parent
4009           (gnus-id-to-thread
4010            (or (gnus-parent-id
4011                 (when (and references
4012                            (not (equal "" references)))
4013                   references))
4014                "none")))
4015          (buffer-read-only nil)
4016          (old (car thread)))
4017     (when thread
4018       (unless iheader
4019         (setcar thread nil)
4020         (when parent
4021           (delq thread parent)))
4022       (if (gnus-summary-insert-subject id header)
4023        ;; Set the (possibly) new article number in the data structure.
4024           (gnus-data-set-number data (gnus-id-to-article id))
4025         (setcar thread old)
4026         nil))))
4027
4028 (defun gnus-rebuild-thread (id &optional line)
4029   "Rebuild the thread containing ID.
4030 If LINE, insert the rebuilt thread starting on line LINE."
4031   (let ((buffer-read-only nil)
4032         old-pos current thread data)
4033     (if (not gnus-show-threads)
4034         (setq thread (list (car (gnus-id-to-thread id))))
4035       ;; Get the thread this article is part of.
4036       (setq thread (gnus-remove-thread id)))
4037     (setq old-pos (gnus-point-at-bol))
4038     (setq current (save-excursion
4039                     (and (re-search-backward "[\r\n]" nil t)
4040                          (gnus-summary-article-number))))
4041     ;; If this is a gathered thread, we have to go some re-gathering.
4042     (when (stringp (car thread))
4043       (let ((subject (car thread))
4044             roots thr)
4045         (setq thread (cdr thread))
4046         (while thread
4047           (unless (memq (setq thr (gnus-id-to-thread
4048                                    (gnus-root-id
4049                                     (mail-header-id (caar thread)))))
4050                         roots)
4051             (push thr roots))
4052           (setq thread (cdr thread)))
4053         ;; We now have all (unique) roots.
4054         (if (= (length roots) 1)
4055             ;; All the loose roots are now one solid root.
4056             (setq thread (car roots))
4057           (setq thread (cons subject (gnus-sort-threads roots))))))
4058     (let (threads)
4059       ;; We then insert this thread into the summary buffer.
4060       (when line
4061         (goto-char (point-min))
4062         (forward-line (1- line)))
4063       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4064         (if gnus-show-threads
4065             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4066           (gnus-summary-prepare-unthreaded thread))
4067         (setq data (nreverse gnus-newsgroup-data))
4068         (setq threads gnus-newsgroup-threads))
4069       ;; We splice the new data into the data structure.
4070       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4071       ;;!!! then we want to insert at the beginning of the buffer.
4072       ;;!!! That happens to be true with Gnus now, but that may
4073       ;;!!! change in the future.  Perhaps.
4074       (gnus-data-enter-list
4075        (if line nil current) data (- (point) old-pos))
4076       (setq gnus-newsgroup-threads
4077             (nconc threads gnus-newsgroup-threads))
4078       (gnus-data-compute-positions))))
4079
4080 (defun gnus-number-to-header (number)
4081   "Return the header for article NUMBER."
4082   (let ((headers gnus-newsgroup-headers))
4083     (while (and headers
4084                 (not (= number (mail-header-number (car headers)))))
4085       (pop headers))
4086     (when headers
4087       (car headers))))
4088
4089 (defun gnus-parent-headers (in-headers &optional generation)
4090   "Return the headers of the GENERATIONeth parent of HEADERS."
4091   (unless generation
4092     (setq generation 1))
4093   (let ((parent t)
4094         (headers in-headers)
4095         references)
4096     (while (and parent
4097                 (not (zerop generation))
4098                 (setq references (mail-header-references headers)))
4099       (setq headers (if (and references
4100                              (setq parent (gnus-parent-id references)))
4101                         (car (gnus-id-to-thread parent))
4102                       nil))
4103       (decf generation))
4104     (and (not (eq headers in-headers))
4105          headers)))
4106
4107 (defun gnus-id-to-thread (id)
4108   "Return the (sub-)thread where ID appears."
4109   (gnus-gethash id gnus-newsgroup-dependencies))
4110
4111 (defun gnus-id-to-article (id)
4112   "Return the article number of ID."
4113   (let ((thread (gnus-id-to-thread id)))
4114     (when (and thread
4115                (car thread))
4116       (mail-header-number (car thread)))))
4117
4118 (defun gnus-id-to-header (id)
4119   "Return the article headers of ID."
4120   (car (gnus-id-to-thread id)))
4121
4122 (defun gnus-article-displayed-root-p (article)
4123   "Say whether ARTICLE is a root(ish) article."
4124   (let ((level (gnus-summary-thread-level article))
4125         (refs (mail-header-references  (gnus-summary-article-header article)))
4126         particle)
4127     (cond
4128      ((null level) nil)
4129      ((zerop level) t)
4130      ((null refs) t)
4131      ((null (gnus-parent-id refs)) t)
4132      ((and (= 1 level)
4133            (null (setq particle (gnus-id-to-article
4134                                  (gnus-parent-id refs))))
4135            (null (gnus-summary-thread-level particle)))))))
4136
4137 (defun gnus-root-id (id)
4138   "Return the id of the root of the thread where ID appears."
4139   (let (last-id prev)
4140     (while (and id (setq prev (car (gnus-id-to-thread id))))
4141       (setq last-id id
4142             id (gnus-parent-id (mail-header-references prev))))
4143     last-id))
4144
4145 (defun gnus-articles-in-thread (thread)
4146   "Return the list of articles in THREAD."
4147   (cons (mail-header-number (car thread))
4148         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4149
4150 (defun gnus-remove-thread (id &optional dont-remove)
4151   "Remove the thread that has ID in it."
4152   (let (headers thread last-id)
4153     ;; First go up in this thread until we find the root.
4154     (setq last-id (gnus-root-id id)
4155           headers (message-flatten-list (gnus-id-to-thread last-id)))
4156     ;; We have now found the real root of this thread.  It might have
4157     ;; been gathered into some loose thread, so we have to search
4158     ;; through the threads to find the thread we wanted.
4159     (let ((threads gnus-newsgroup-threads)
4160           sub)
4161       (while threads
4162         (setq sub (car threads))
4163         (if (stringp (car sub))
4164             ;; This is a gathered thread, so we look at the roots
4165             ;; below it to find whether this article is in this
4166             ;; gathered root.
4167             (progn
4168               (setq sub (cdr sub))
4169               (while sub
4170                 (when (member (caar sub) headers)
4171                   (setq thread (car threads)
4172                         threads nil
4173                         sub nil))
4174                 (setq sub (cdr sub))))
4175           ;; It's an ordinary thread, so we check it.
4176           (when (eq (car sub) (car headers))
4177             (setq thread sub
4178                   threads nil)))
4179         (setq threads (cdr threads)))
4180       ;; If this article is in no thread, then it's a root.
4181       (if thread
4182           (unless dont-remove
4183             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4184         (setq thread (gnus-id-to-thread last-id)))
4185       (when thread
4186         (prog1
4187             thread                      ; We return this thread.
4188           (unless dont-remove
4189             (if (stringp (car thread))
4190                 (progn
4191                   ;; If we use dummy roots, then we have to remove the
4192                   ;; dummy root as well.
4193                   (when (eq gnus-summary-make-false-root 'dummy)
4194                     ;; We go to the dummy root by going to
4195                     ;; the first sub-"thread", and then one line up.
4196                     (gnus-summary-goto-article
4197                      (mail-header-number (caadr thread)))
4198                     (forward-line -1)
4199                     (gnus-delete-line)
4200                     (gnus-data-compute-positions))
4201                   (setq thread (cdr thread))
4202                   (while thread
4203                     (gnus-remove-thread-1 (car thread))
4204                     (setq thread (cdr thread))))
4205               (gnus-remove-thread-1 thread))))))))
4206
4207 (defun gnus-remove-thread-1 (thread)
4208   "Remove the thread THREAD recursively."
4209   (let ((number (mail-header-number (pop thread)))
4210         d)
4211     (setq thread (reverse thread))
4212     (while thread
4213       (gnus-remove-thread-1 (pop thread)))
4214     (when (setq d (gnus-data-find number))
4215       (goto-char (gnus-data-pos d))
4216       (gnus-summary-show-thread)
4217       (gnus-data-remove
4218        number
4219        (- (gnus-point-at-bol)
4220           (prog1
4221               (1+ (gnus-point-at-eol))
4222             (gnus-delete-line)))))))
4223
4224 (defun gnus-sort-threads-1 (threads func)
4225   (sort (mapcar (lambda (thread)
4226                   (cons (car thread)
4227                         (and (cdr thread)
4228                              (gnus-sort-threads-1 (cdr thread) func))))
4229                 threads) func))
4230
4231 (defun gnus-sort-threads (threads)
4232   "Sort THREADS."
4233   (if (not gnus-thread-sort-functions)
4234       threads
4235     (gnus-message 8 "Sorting threads...")
4236     (prog1
4237         (gnus-sort-threads-1
4238          threads
4239          (gnus-make-sort-function gnus-thread-sort-functions))
4240       (gnus-message 8 "Sorting threads...done"))))
4241
4242 (defun gnus-sort-articles (articles)
4243   "Sort ARTICLES."
4244   (when gnus-article-sort-functions
4245     (gnus-message 7 "Sorting articles...")
4246     (prog1
4247         (setq gnus-newsgroup-headers
4248               (sort articles (gnus-make-sort-function
4249                               gnus-article-sort-functions)))
4250       (gnus-message 7 "Sorting articles...done"))))
4251
4252 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4253 (defmacro gnus-thread-header (thread)
4254   "Return header of first article in THREAD.
4255 Note that THREAD must never, ever be anything else than a variable -
4256 using some other form will lead to serious barfage."
4257   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4258   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4259   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4260         (vector thread) 2))
4261
4262 (defsubst gnus-article-sort-by-number (h1 h2)
4263   "Sort articles by article number."
4264   (< (mail-header-number h1)
4265      (mail-header-number h2)))
4266
4267 (defun gnus-thread-sort-by-number (h1 h2)
4268   "Sort threads by root article number."
4269   (gnus-article-sort-by-number
4270    (gnus-thread-header h1) (gnus-thread-header h2)))
4271
4272 (defsubst gnus-article-sort-by-random (h1 h2)
4273   "Sort articles by article number."
4274   (zerop (random 2)))
4275
4276 (defun gnus-thread-sort-by-random (h1 h2)
4277   "Sort threads by root article number."
4278   (gnus-article-sort-by-random
4279    (gnus-thread-header h1) (gnus-thread-header h2)))
4280
4281 (defsubst gnus-article-sort-by-lines (h1 h2)
4282   "Sort articles by article Lines header."
4283   (< (mail-header-lines h1)
4284      (mail-header-lines h2)))
4285
4286 (defun gnus-thread-sort-by-lines (h1 h2)
4287   "Sort threads by root article Lines header."
4288   (gnus-article-sort-by-lines
4289    (gnus-thread-header h1) (gnus-thread-header h2)))
4290
4291 (defsubst gnus-article-sort-by-chars (h1 h2)
4292   "Sort articles by octet length."
4293   (< (mail-header-chars h1)
4294      (mail-header-chars h2)))
4295
4296 (defun gnus-thread-sort-by-chars (h1 h2)
4297   "Sort threads by root article octet length."
4298   (gnus-article-sort-by-chars
4299    (gnus-thread-header h1) (gnus-thread-header h2)))
4300
4301 (defsubst gnus-article-sort-by-author (h1 h2)
4302   "Sort articles by root author."
4303   (string-lessp
4304    (let ((extract (funcall
4305                    gnus-extract-address-components
4306                    (mail-header-from h1))))
4307      (or (car extract) (cadr extract) ""))
4308    (let ((extract (funcall
4309                    gnus-extract-address-components
4310                    (mail-header-from h2))))
4311      (or (car extract) (cadr extract) ""))))
4312
4313 (defun gnus-thread-sort-by-author (h1 h2)
4314   "Sort threads by root author."
4315   (gnus-article-sort-by-author
4316    (gnus-thread-header h1)  (gnus-thread-header h2)))
4317
4318 (defsubst gnus-article-sort-by-subject (h1 h2)
4319   "Sort articles by root subject."
4320   (string-lessp
4321    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4322    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4323
4324 (defun gnus-thread-sort-by-subject (h1 h2)
4325   "Sort threads by root subject."
4326   (gnus-article-sort-by-subject
4327    (gnus-thread-header h1) (gnus-thread-header h2)))
4328
4329 (defsubst gnus-article-sort-by-date (h1 h2)
4330   "Sort articles by root article date."
4331   (time-less-p
4332    (gnus-date-get-time (mail-header-date h1))
4333    (gnus-date-get-time (mail-header-date h2))))
4334
4335 (defun gnus-thread-sort-by-date (h1 h2)
4336   "Sort threads by root article date."
4337   (gnus-article-sort-by-date
4338    (gnus-thread-header h1) (gnus-thread-header h2)))
4339
4340 (defsubst gnus-article-sort-by-score (h1 h2)
4341   "Sort articles by root article score.
4342 Unscored articles will be counted as having a score of zero."
4343   (> (or (cdr (assq (mail-header-number h1)
4344                     gnus-newsgroup-scored))
4345          gnus-summary-default-score 0)
4346      (or (cdr (assq (mail-header-number h2)
4347                     gnus-newsgroup-scored))
4348          gnus-summary-default-score 0)))
4349
4350 (defun gnus-thread-sort-by-score (h1 h2)
4351   "Sort threads by root article score."
4352   (gnus-article-sort-by-score
4353    (gnus-thread-header h1) (gnus-thread-header h2)))
4354
4355 (defun gnus-thread-sort-by-total-score (h1 h2)
4356   "Sort threads by the sum of all scores in the thread.
4357 Unscored articles will be counted as having a score of zero."
4358   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4359
4360 (defun gnus-thread-total-score (thread)
4361   ;; This function find the total score of THREAD.
4362   (cond
4363    ((null thread)
4364     0)
4365    ((consp thread)
4366     (if (stringp (car thread))
4367         (apply gnus-thread-score-function 0
4368                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4369       (gnus-thread-total-score-1 thread)))
4370    (t
4371     (gnus-thread-total-score-1 (list thread)))))
4372
4373 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4374   "Sort threads such that the thread with the most recently arrived article comes first."
4375   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4376
4377 (defun gnus-thread-highest-number (thread)
4378   "Return the highest article number in THREAD."
4379   (apply 'max (mapcar (lambda (header)
4380                         (mail-header-number header))
4381                       (message-flatten-list thread))))
4382
4383 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4384   "Sort threads such that the thread with the most recently dated article comes first."
4385   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4386
4387 (defun gnus-thread-latest-date (thread)
4388   "Return the highest article date in THREAD."
4389   (let ((previous-time 0))
4390     (apply 'max (mapcar
4391                  (lambda (header)
4392                    (setq previous-time
4393                          (time-to-seconds
4394                           (mail-header-parse-date
4395                            (condition-case ()
4396                                (mail-header-date header)
4397                              (error previous-time))))))
4398                  (sort
4399                   (message-flatten-list thread)
4400                   (lambda (h1 h2)
4401                     (< (mail-header-number h1)
4402                        (mail-header-number h2))))))))
4403
4404 (defun gnus-thread-total-score-1 (root)
4405   ;; This function find the total score of the thread below ROOT.
4406   (setq root (car root))
4407   (apply gnus-thread-score-function
4408          (or (append
4409               (mapcar 'gnus-thread-total-score
4410                       (cdr (gnus-id-to-thread (mail-header-id root))))
4411               (when (> (mail-header-number root) 0)
4412                 (list (or (cdr (assq (mail-header-number root)
4413                                      gnus-newsgroup-scored))
4414                           gnus-summary-default-score 0))))
4415              (list gnus-summary-default-score)
4416              '(0))))
4417
4418 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4419 (defvar gnus-tmp-prev-subject nil)
4420 (defvar gnus-tmp-false-parent nil)
4421 (defvar gnus-tmp-root-expunged nil)
4422 (defvar gnus-tmp-dummy-line nil)
4423
4424 (eval-when-compile (defvar gnus-tmp-header))
4425 (defun gnus-extra-header (type &optional header)
4426   "Return the extra header of TYPE."
4427   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4428       ""))
4429
4430 (defvar gnus-tmp-thread-tree-header-string "")
4431
4432 (defcustom gnus-sum-thread-tree-root "> "
4433   "With %B spec, used for the root of a thread.
4434 If nil, use subject instead."
4435   :type 'string
4436   :group 'gnus-thread)
4437 (defcustom gnus-sum-thread-tree-single-indent ""
4438   "With %B spec, used for a thread with just one message.
4439 If nil, use subject instead."
4440   :type 'string
4441   :group 'gnus-thread)
4442 (defcustom gnus-sum-thread-tree-vertical "| "
4443   "With %B spec, used for drawing a vertical line."
4444   :type 'string
4445   :group 'gnus-thread)
4446 (defcustom gnus-sum-thread-tree-indent "  "
4447   "With %B spec, used for indenting."
4448   :type 'string
4449   :group 'gnus-thread)
4450 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4451   "With %B spec, used for a leaf with brothers."
4452   :type 'string
4453   :group 'gnus-thread)
4454 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4455   "With %B spec, used for a leaf without brothers."
4456   :type 'string
4457   :group 'gnus-thread)
4458
4459 (defun gnus-summary-prepare-threads (threads)
4460   "Prepare summary buffer from THREADS and indentation LEVEL.
4461 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4462 or a straight list of headers."
4463   (gnus-message 7 "Generating summary...")
4464
4465   (setq gnus-newsgroup-threads threads)
4466   (beginning-of-line)
4467
4468   (let ((gnus-tmp-level 0)
4469         (default-score (or gnus-summary-default-score 0))
4470         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4471         thread number subject stack state gnus-tmp-gathered beg-match
4472         new-roots gnus-tmp-new-adopts thread-end simp-subject
4473         gnus-tmp-header gnus-tmp-unread
4474         gnus-tmp-replied gnus-tmp-subject-or-nil
4475         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4476         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4477         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4478         tree-stack)
4479
4480     (setq gnus-tmp-prev-subject nil)
4481
4482     (if (vectorp (car threads))
4483         ;; If this is a straight (sic) list of headers, then a
4484         ;; threaded summary display isn't required, so we just create
4485         ;; an unthreaded one.
4486         (gnus-summary-prepare-unthreaded threads)
4487
4488       ;; Do the threaded display.
4489
4490       (while (or threads stack gnus-tmp-new-adopts new-roots)
4491
4492         (if (and (= gnus-tmp-level 0)
4493                  (or (not stack)
4494                      (= (caar stack) 0))
4495                  (not gnus-tmp-false-parent)
4496                  (or gnus-tmp-new-adopts new-roots))
4497             (if gnus-tmp-new-adopts
4498                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4499                       thread (list (car gnus-tmp-new-adopts))
4500                       gnus-tmp-header (caar thread)
4501                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4502               (when new-roots
4503                 (setq thread (list (car new-roots))
4504                       gnus-tmp-header (caar thread)
4505                       new-roots (cdr new-roots))))
4506
4507           (if threads
4508               ;; If there are some threads, we do them before the
4509               ;; threads on the stack.
4510               (setq thread threads
4511                     gnus-tmp-header (caar thread))
4512             ;; There were no current threads, so we pop something off
4513             ;; the stack.
4514             (setq state (car stack)
4515                   gnus-tmp-level (car state)
4516                   tree-stack (cadr state)
4517                   thread (caddr state)
4518                   stack (cdr stack)
4519                   gnus-tmp-header (caar thread))))
4520
4521         (setq gnus-tmp-false-parent nil)
4522         (setq gnus-tmp-root-expunged nil)
4523         (setq thread-end nil)
4524
4525         (if (stringp gnus-tmp-header)
4526             ;; The header is a dummy root.
4527             (cond
4528              ((eq gnus-summary-make-false-root 'adopt)
4529               ;; We let the first article adopt the rest.
4530               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4531                                                (cddar thread)))
4532               (setq gnus-tmp-gathered
4533                     (nconc (mapcar
4534                             (lambda (h) (mail-header-number (car h)))
4535                             (cddar thread))
4536                            gnus-tmp-gathered))
4537               (setq thread (cons (list (caar thread)
4538                                        (cadar thread))
4539                                  (cdr thread)))
4540               (setq gnus-tmp-level -1
4541                     gnus-tmp-false-parent t))
4542              ((eq gnus-summary-make-false-root 'empty)
4543               ;; We print adopted articles with empty subject fields.
4544               (setq gnus-tmp-gathered
4545                     (nconc (mapcar
4546                             (lambda (h) (mail-header-number (car h)))
4547                             (cddar thread))
4548                            gnus-tmp-gathered))
4549               (setq gnus-tmp-level -1))
4550              ((eq gnus-summary-make-false-root 'dummy)
4551               ;; We remember that we probably want to output a dummy
4552               ;; root.
4553               (setq gnus-tmp-dummy-line gnus-tmp-header)
4554               (setq gnus-tmp-prev-subject gnus-tmp-header))
4555              (t
4556               ;; We do not make a root for the gathered
4557               ;; sub-threads at all.
4558               (setq gnus-tmp-level -1)))
4559
4560           (setq number (mail-header-number gnus-tmp-header)
4561                 subject (mail-header-subject gnus-tmp-header)
4562                 simp-subject (gnus-simplify-subject-fully subject))
4563
4564           (cond
4565            ;; If the thread has changed subject, we might want to make
4566            ;; this subthread into a root.
4567            ((and (null gnus-thread-ignore-subject)
4568                  (not (zerop gnus-tmp-level))
4569                  gnus-tmp-prev-subject
4570                  (not (string= gnus-tmp-prev-subject simp-subject)))
4571             (setq new-roots (nconc new-roots (list (car thread)))
4572                   thread-end t
4573                   gnus-tmp-header nil))
4574            ;; If the article lies outside the current limit,
4575            ;; then we do not display it.
4576            ((not (memq number gnus-newsgroup-limit))
4577             (setq gnus-tmp-gathered
4578                   (nconc (mapcar
4579                           (lambda (h) (mail-header-number (car h)))
4580                           (cdar thread))
4581                          gnus-tmp-gathered))
4582             (setq gnus-tmp-new-adopts (if (cdar thread)
4583                                           (append gnus-tmp-new-adopts
4584                                                   (cdar thread))
4585                                         gnus-tmp-new-adopts)
4586                   thread-end t
4587                   gnus-tmp-header nil)
4588             (when (zerop gnus-tmp-level)
4589               (setq gnus-tmp-root-expunged t)))
4590            ;; Perhaps this article is to be marked as read?
4591            ((and gnus-summary-mark-below
4592                  (< (or (cdr (assq number gnus-newsgroup-scored))
4593                         default-score)
4594                     gnus-summary-mark-below)
4595                  ;; Don't touch sparse articles.
4596                  (not (gnus-summary-article-sparse-p number))
4597                  (not (gnus-summary-article-ancient-p number)))
4598             (setq gnus-newsgroup-unreads
4599                   (delq number gnus-newsgroup-unreads))
4600             (if gnus-newsgroup-auto-expire
4601                 (setq gnus-newsgroup-expirable
4602                       (gnus-add-to-sorted-list
4603                        gnus-newsgroup-expirable number))
4604               (push (cons number gnus-low-score-mark)
4605                     gnus-newsgroup-reads))))
4606
4607           (when gnus-tmp-header
4608             ;; We may have an old dummy line to output before this
4609             ;; article.
4610             (when (and gnus-tmp-dummy-line
4611                        (gnus-subject-equal
4612                         gnus-tmp-dummy-line
4613                         (mail-header-subject gnus-tmp-header)))
4614               (gnus-summary-insert-dummy-line
4615                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4616               (setq gnus-tmp-dummy-line nil))
4617
4618             ;; Compute the mark.
4619             (setq gnus-tmp-unread (gnus-article-mark number))
4620
4621             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4622                                   gnus-tmp-header gnus-tmp-level)
4623                   gnus-newsgroup-data)
4624
4625             ;; Actually insert the line.
4626             (setq
4627              gnus-tmp-subject-or-nil
4628              (cond
4629               ((and gnus-thread-ignore-subject
4630                     gnus-tmp-prev-subject
4631                     (not (string= gnus-tmp-prev-subject simp-subject)))
4632                subject)
4633               ((zerop gnus-tmp-level)
4634                (if (and (eq gnus-summary-make-false-root 'empty)
4635                         (memq number gnus-tmp-gathered)
4636                         gnus-tmp-prev-subject
4637                         (string= gnus-tmp-prev-subject simp-subject))
4638                    gnus-summary-same-subject
4639                  subject))
4640               (t gnus-summary-same-subject)))
4641             (if (and (eq gnus-summary-make-false-root 'adopt)
4642                      (= gnus-tmp-level 1)
4643                      (memq number gnus-tmp-gathered))
4644                 (setq gnus-tmp-opening-bracket ?\<
4645                       gnus-tmp-closing-bracket ?\>)
4646               (setq gnus-tmp-opening-bracket ?\[
4647                     gnus-tmp-closing-bracket ?\]))
4648             (setq
4649              gnus-tmp-indentation
4650              (aref gnus-thread-indent-array gnus-tmp-level)
4651              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4652              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4653                                 gnus-summary-default-score 0)
4654              gnus-tmp-score-char
4655              (if (or (null gnus-summary-default-score)
4656                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4657                          gnus-summary-zcore-fuzz))
4658                  ?                      ;Whitespace
4659                (if (< gnus-tmp-score gnus-summary-default-score)
4660                    gnus-score-below-mark gnus-score-over-mark))
4661              gnus-tmp-replied
4662              (cond ((memq number gnus-newsgroup-processable)
4663                     gnus-process-mark)
4664                    ((memq number gnus-newsgroup-cached)
4665                     gnus-cached-mark)
4666                    ((memq number gnus-newsgroup-replied)
4667                     gnus-replied-mark)
4668                    ((memq number gnus-newsgroup-forwarded)
4669                     gnus-forwarded-mark)
4670                    ((memq number gnus-newsgroup-saved)
4671                     gnus-saved-mark)
4672                    ((memq number gnus-newsgroup-recent)
4673                     gnus-recent-mark)
4674                    ((memq number gnus-newsgroup-unseen)
4675                     gnus-unseen-mark)
4676                    (t gnus-no-mark))
4677              gnus-tmp-from (mail-header-from gnus-tmp-header)
4678              gnus-tmp-name
4679              (cond
4680               ((string-match "<[^>]+> *$" gnus-tmp-from)
4681                (setq beg-match (match-beginning 0))
4682                (or (and (string-match "^\".+\"" gnus-tmp-from)
4683                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4684                    (substring gnus-tmp-from 0 beg-match)))
4685               ((string-match "(.+)" gnus-tmp-from)
4686                (substring gnus-tmp-from
4687                           (1+ (match-beginning 0)) (1- (match-end 0))))
4688               (t gnus-tmp-from))
4689              gnus-tmp-thread-tree-header-string
4690              (cond
4691               ((not gnus-show-threads) "")
4692               ((zerop gnus-tmp-level)
4693                (if (cdar thread)
4694                    (or gnus-sum-thread-tree-root subject)
4695                  (or gnus-sum-thread-tree-single-indent subject)))
4696               (t
4697                (concat (apply 'concat
4698                               (mapcar (lambda (item)
4699                                         (if (= item 1)
4700                                             gnus-sum-thread-tree-vertical
4701                                           gnus-sum-thread-tree-indent))
4702                                       (cdr (reverse tree-stack))))
4703                        (if (nth 1 thread)
4704                            gnus-sum-thread-tree-leaf-with-other
4705                          gnus-sum-thread-tree-single-leaf)))))
4706             (when (string= gnus-tmp-name "")
4707               (setq gnus-tmp-name gnus-tmp-from))
4708             (unless (numberp gnus-tmp-lines)
4709               (setq gnus-tmp-lines -1))
4710             (if (= gnus-tmp-lines -1)
4711                 (setq gnus-tmp-lines "?")
4712               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4713             (gnus-put-text-property
4714              (point)
4715              (progn (eval gnus-summary-line-format-spec) (point))
4716              'gnus-number number)
4717             (when gnus-visual-p
4718               (forward-line -1)
4719               (gnus-run-hooks 'gnus-summary-update-hook)
4720               (forward-line 1))
4721
4722             (setq gnus-tmp-prev-subject simp-subject)))
4723
4724         (when (nth 1 thread)
4725           (push (list (max 0 gnus-tmp-level)
4726                       (copy-list tree-stack)
4727                       (nthcdr 1 thread))
4728                 stack))
4729         (push (if (nth 1 thread) 1 0) tree-stack)
4730         (incf gnus-tmp-level)
4731         (setq threads (if thread-end nil (cdar thread)))
4732         (unless threads
4733           (setq gnus-tmp-level 0)))))
4734   (gnus-message 7 "Generating summary...done"))
4735
4736 (defun gnus-summary-prepare-unthreaded (headers)
4737   "Generate an unthreaded summary buffer based on HEADERS."
4738   (let (header number mark)
4739
4740     (beginning-of-line)
4741
4742     (while headers
4743       ;; We may have to root out some bad articles...
4744       (when (memq (setq number (mail-header-number
4745                                 (setq header (pop headers))))
4746                   gnus-newsgroup-limit)
4747         ;; Mark article as read when it has a low score.
4748         (when (and gnus-summary-mark-below
4749                    (< (or (cdr (assq number gnus-newsgroup-scored))
4750                           gnus-summary-default-score 0)
4751                       gnus-summary-mark-below)
4752                    (not (gnus-summary-article-ancient-p number)))
4753           (setq gnus-newsgroup-unreads
4754                 (delq number gnus-newsgroup-unreads))
4755           (if gnus-newsgroup-auto-expire
4756               (push number gnus-newsgroup-expirable)
4757             (push (cons number gnus-low-score-mark)
4758                   gnus-newsgroup-reads)))
4759
4760         (setq mark (gnus-article-mark number))
4761         (push (gnus-data-make number mark (1+ (point)) header 0)
4762               gnus-newsgroup-data)
4763         (gnus-summary-insert-line
4764          header 0 number
4765          mark (memq number gnus-newsgroup-replied)
4766          (memq number gnus-newsgroup-expirable)
4767          (mail-header-subject header) nil
4768          (cdr (assq number gnus-newsgroup-scored))
4769          (memq number gnus-newsgroup-processable))))))
4770
4771 (defun gnus-summary-remove-list-identifiers ()
4772   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4773   (let ((regexp (if (consp gnus-list-identifiers)
4774                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4775                   gnus-list-identifiers))
4776         changed subject)
4777     (when regexp
4778       (dolist (header gnus-newsgroup-headers)
4779         (setq subject (mail-header-subject header)
4780               changed nil)
4781         (while (string-match
4782                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4783                 subject)
4784           (setq subject
4785                 (concat (substring subject 0 (match-beginning 2))
4786                         (substring subject (match-end 0)))
4787                 changed t))
4788         (when (and changed
4789                    (string-match
4790                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4791           (setq subject
4792                 (concat (substring subject 0 (match-beginning 1))
4793                         (substring subject (match-end 1)))))
4794         (when changed
4795           (mail-header-set-subject header subject))))))
4796
4797 (defun gnus-fetch-headers (articles)
4798   "Fetch headers of ARTICLES."
4799   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4800     (gnus-message 5 "Fetching headers for %s..." name)
4801     (prog1
4802         (if (eq 'nov
4803                 (setq gnus-headers-retrieved-by
4804                       (gnus-retrieve-headers
4805                        articles gnus-newsgroup-name
4806                        ;; We might want to fetch old headers, but
4807                        ;; not if there is only 1 article.
4808                        (and (or (and
4809                                  (not (eq gnus-fetch-old-headers 'some))
4810                                  (not (numberp gnus-fetch-old-headers)))
4811                                 (> (length articles) 1))
4812                             gnus-fetch-old-headers))))
4813             (gnus-get-newsgroup-headers-xover
4814              articles nil nil gnus-newsgroup-name t)
4815           (gnus-get-newsgroup-headers))
4816       (gnus-message 5 "Fetching headers for %s...done" name))))
4817
4818 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4819   "Select newsgroup GROUP.
4820 If READ-ALL is non-nil, all articles in the group are selected.
4821 If SELECT-ARTICLES, only select those articles from GROUP."
4822   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4823          ;;!!! Dirty hack; should be removed.
4824          (gnus-summary-ignore-duplicates
4825           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4826               t
4827             gnus-summary-ignore-duplicates))
4828          (info (nth 2 entry))
4829          articles fetched-articles cached)
4830
4831     (unless (gnus-check-server
4832              (set (make-local-variable 'gnus-current-select-method)
4833                   (gnus-find-method-for-group group)))
4834       (error "Couldn't open server"))
4835
4836     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4837         (gnus-activate-group group)     ; Or we can activate it...
4838         (progn                          ; Or we bug out.
4839           (when (equal major-mode 'gnus-summary-mode)
4840             (kill-buffer (current-buffer)))
4841           (error "Couldn't activate group %s: %s"
4842                  group (gnus-status-message group))))
4843
4844     (unless (gnus-request-group group t)
4845       (when (equal major-mode 'gnus-summary-mode)
4846         (kill-buffer (current-buffer)))
4847       (error "Couldn't request group %s: %s"
4848              group (gnus-status-message group)))
4849
4850     (setq gnus-newsgroup-name group
4851           gnus-newsgroup-unselected nil
4852           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4853
4854     (let ((display (gnus-group-find-parameter group 'display)))
4855       (setq gnus-newsgroup-display
4856             (cond
4857              ((not (zerop (or (car-safe read-all) 0)))
4858               ;; The user entered the group with C-u SPC/RET, let's show
4859               ;; all articles.
4860               'gnus-not-ignore)
4861              ((eq display 'all)
4862               'gnus-not-ignore)
4863              ((arrayp display)
4864               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4865              ((numberp display)
4866               ;; The following is probably the "correct" solution, but
4867               ;; it makes Gnus fetch all headers and then limit the
4868               ;; articles (which is slow), so instead we hack the
4869               ;; select-articles parameter instead. -- Simon Josefsson
4870               ;; <jas@kth.se>
4871               ;;
4872               ;; (gnus-byte-compile
4873               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4874               ;;                         display)))))
4875               (setq select-articles
4876                     (gnus-uncompress-range
4877                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4878                              (if (> tmp 0)
4879                                  tmp
4880                                1))
4881                            (cdr (gnus-active group)))))
4882               nil)
4883              (t
4884               nil))))
4885
4886     (gnus-summary-setup-default-charset)
4887
4888     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4889     (when (gnus-virtual-group-p group)
4890       (setq cached gnus-newsgroup-cached))
4891
4892     (setq gnus-newsgroup-unreads
4893           (gnus-sorted-ndifference
4894            (gnus-sorted-ndifference gnus-newsgroup-unreads
4895                                     gnus-newsgroup-marked)
4896            gnus-newsgroup-dormant))
4897
4898     (setq gnus-newsgroup-processable nil)
4899
4900     (gnus-update-read-articles group gnus-newsgroup-unreads)
4901
4902     ;; Adjust and set lists of article marks.
4903     (when info
4904       (gnus-adjust-marked-articles info))
4905     (if (setq articles select-articles)
4906         (setq gnus-newsgroup-unselected
4907               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4908       (setq articles (gnus-articles-to-read group read-all)))
4909
4910     (cond
4911      ((null articles)
4912       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4913       'quit)
4914      ((eq articles 0) nil)
4915      (t
4916       ;; Init the dependencies hash table.
4917       (setq gnus-newsgroup-dependencies
4918             (gnus-make-hashtable (length articles)))
4919       (gnus-set-global-variables)
4920       ;; Retrieve the headers and read them in.
4921
4922       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4923
4924       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4925       (when cached
4926         (setq gnus-newsgroup-cached cached))
4927
4928       ;; Suppress duplicates?
4929       (when gnus-suppress-duplicates
4930         (gnus-dup-suppress-articles))
4931
4932       ;; Set the initial limit.
4933       (setq gnus-newsgroup-limit (copy-sequence articles))
4934       ;; Remove canceled articles from the list of unread articles.
4935       (setq fetched-articles
4936             (mapcar (lambda (headers) (mail-header-number headers))
4937                     gnus-newsgroup-headers))
4938       (setq gnus-newsgroup-articles fetched-articles)
4939       (setq gnus-newsgroup-unreads
4940             (gnus-sorted-nintersection
4941              gnus-newsgroup-unreads fetched-articles))
4942       (gnus-compute-unseen-list)
4943
4944       ;; Removed marked articles that do not exist.
4945       (gnus-update-missing-marks
4946        (gnus-sorted-difference articles fetched-articles))
4947       ;; We might want to build some more threads first.
4948       (when (and gnus-fetch-old-headers
4949                  (eq gnus-headers-retrieved-by 'nov))
4950         (if (eq gnus-fetch-old-headers 'invisible)
4951             (gnus-build-all-threads)
4952           (gnus-build-old-threads)))
4953       ;; Let the Gnus agent mark articles as read.
4954       (when gnus-agent
4955         (gnus-agent-get-undownloaded-list))
4956       ;; Remove list identifiers from subject
4957       (when gnus-list-identifiers
4958         (gnus-summary-remove-list-identifiers))
4959       ;; Check whether auto-expire is to be done in this group.
4960       (setq gnus-newsgroup-auto-expire
4961             (gnus-group-auto-expirable-p group))
4962       ;; Set up the article buffer now, if necessary.
4963       (unless gnus-single-article-buffer
4964         (gnus-article-setup-buffer))
4965       ;; First and last article in this newsgroup.
4966       (when gnus-newsgroup-headers
4967         (setq gnus-newsgroup-begin
4968               (mail-header-number (car gnus-newsgroup-headers))
4969               gnus-newsgroup-end
4970               (mail-header-number
4971                (gnus-last-element gnus-newsgroup-headers))))
4972       ;; GROUP is successfully selected.
4973       (or gnus-newsgroup-headers t)))))
4974
4975 (defun gnus-compute-unseen-list ()
4976   ;; The `seen' marks are treated specially.
4977   (if (not gnus-newsgroup-seen)
4978       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4979     (setq gnus-newsgroup-unseen
4980           (gnus-inverse-list-range-intersection
4981            gnus-newsgroup-articles gnus-newsgroup-seen))))
4982
4983 (defun gnus-summary-display-make-predicate (display)
4984   (require 'gnus-agent)
4985   (when (= (length display) 1)
4986     (setq display (car display)))
4987   (unless gnus-summary-display-cache
4988     (dolist (elem (append '((unread . unread)
4989                             (read . read)
4990                             (unseen . unseen))
4991                           gnus-article-mark-lists))
4992       (push (cons (cdr elem)
4993                   (gnus-byte-compile
4994                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4995             gnus-summary-display-cache)))
4996   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4997         (gnus-category-predicate-cache gnus-summary-display-cache))
4998     (gnus-get-predicate display)))
4999
5000 ;; Uses the dynamically bound `number' variable.
5001 (defvar number)
5002 (defun gnus-article-marked-p (type &optional article)
5003   (let ((article (or article number)))
5004     (cond
5005      ((eq type 'tick)
5006       (memq article gnus-newsgroup-marked))
5007      ((eq type 'spam)
5008       (memq article gnus-newsgroup-spam-marked))
5009      ((eq type 'unsend)
5010       (memq article gnus-newsgroup-unsendable))
5011      ((eq type 'undownload)
5012       (memq article gnus-newsgroup-undownloaded))
5013      ((eq type 'download)
5014       (memq article gnus-newsgroup-downloadable))
5015      ((eq type 'unread)
5016       (memq article gnus-newsgroup-unreads))
5017      ((eq type 'read)
5018       (memq article gnus-newsgroup-reads))
5019      ((eq type 'dormant)
5020       (memq article gnus-newsgroup-dormant) )
5021      ((eq type 'expire)
5022       (memq article gnus-newsgroup-expirable))
5023      ((eq type 'reply)
5024       (memq article gnus-newsgroup-replied))
5025      ((eq type 'killed)
5026       (memq article gnus-newsgroup-killed))
5027      ((eq type 'bookmark)
5028       (assq article gnus-newsgroup-bookmarks))
5029      ((eq type 'score)
5030       (assq article gnus-newsgroup-scored))
5031      ((eq type 'save)
5032       (memq article gnus-newsgroup-saved))
5033      ((eq type 'cache)
5034       (memq article gnus-newsgroup-cached))
5035      ((eq type 'forward)
5036       (memq article gnus-newsgroup-forwarded))
5037      ((eq type 'seen)
5038       (not (memq article gnus-newsgroup-unseen)))
5039      ((eq type 'recent)
5040       (memq article gnus-newsgroup-recent))
5041      (t t))))
5042
5043 (defun gnus-articles-to-read (group &optional read-all)
5044   "Find out what articles the user wants to read."
5045   (let* ((articles
5046           ;; Select all articles if `read-all' is non-nil, or if there
5047           ;; are no unread articles.
5048           (if (or read-all
5049                   (and (zerop (length gnus-newsgroup-marked))
5050                        (zerop (length gnus-newsgroup-unreads)))
5051                   ;; Fetch all if the predicate is non-nil.
5052                   gnus-newsgroup-display)
5053               ;; We want to select the headers for all the articles in
5054               ;; the group, so we select either all the active
5055               ;; articles in the group, or (if that's nil), the
5056               ;; articles in the cache.
5057               (or
5058                (gnus-uncompress-range (gnus-active group))
5059                (gnus-cache-articles-in-group group))
5060             ;; Select only the "normal" subset of articles.
5061             (gnus-sorted-nunion
5062              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5063              gnus-newsgroup-unreads)))
5064          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5065          (scored (length scored-list))
5066          (number (length articles))
5067          (marked (+ (length gnus-newsgroup-marked)
5068                     (length gnus-newsgroup-dormant)))
5069          (select
5070           (cond
5071            ((numberp read-all)
5072             read-all)
5073            ((numberp gnus-newsgroup-display)
5074             gnus-newsgroup-display)
5075            (t
5076             (condition-case ()
5077                 (cond
5078                  ((and (or (<= scored marked) (= scored number))
5079                        (numberp gnus-large-newsgroup)
5080                        (> number gnus-large-newsgroup))
5081                   (let* ((cursor-in-echo-area nil)
5082                          (initial (gnus-parameter-large-newsgroup-initial
5083                                    gnus-newsgroup-name))
5084                          (input
5085                           (read-string
5086                            (format
5087                             "How many articles from %s (%s %d): "
5088                             (gnus-limit-string
5089                              (gnus-group-decoded-name gnus-newsgroup-name)
5090                              35)
5091                             (if initial "max" "default")
5092                             number)
5093                            (if initial
5094                                (cons (number-to-string initial)
5095                                      0)))))
5096                     (if (string-match "^[ \t]*$" input) number input)))
5097                  ((and (> scored marked) (< scored number)
5098                        (> (- scored number) 20))
5099                   (let ((input
5100                          (read-string
5101                           (format "%s %s (%d scored, %d total): "
5102                                   "How many articles from"
5103                                   (gnus-group-decoded-name group)
5104                                   scored number))))
5105                     (if (string-match "^[ \t]*$" input)
5106                         number input)))
5107                  (t number))
5108               (quit
5109                (message "Quit getting the articles to read")
5110                nil))))))
5111     (setq select (if (stringp select) (string-to-number select) select))
5112     (if (or (null select) (zerop select))
5113         select
5114       (if (and (not (zerop scored)) (<= (abs select) scored))
5115           (progn
5116             (setq articles (sort scored-list '<))
5117             (setq number (length articles)))
5118         (setq articles (copy-sequence articles)))
5119
5120       (when (< (abs select) number)
5121         (if (< select 0)
5122             ;; Select the N oldest articles.
5123             (setcdr (nthcdr (1- (abs select)) articles) nil)
5124           ;; Select the N most recent articles.
5125           (setq articles (nthcdr (- number select) articles))))
5126       (setq gnus-newsgroup-unselected
5127             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5128       (when gnus-alter-articles-to-read-function
5129         (setq gnus-newsgroup-unreads
5130               (sort
5131                (funcall gnus-alter-articles-to-read-function
5132                         gnus-newsgroup-name gnus-newsgroup-unreads)
5133                '<)))
5134       articles)))
5135
5136 (defun gnus-killed-articles (killed articles)
5137   (let (out)
5138     (while articles
5139       (when (inline (gnus-member-of-range (car articles) killed))
5140         (push (car articles) out))
5141       (setq articles (cdr articles)))
5142     out))
5143
5144 (defun gnus-uncompress-marks (marks)
5145   "Uncompress the mark ranges in MARKS."
5146   (let ((uncompressed '(score bookmark))
5147         out)
5148     (while marks
5149       (if (memq (caar marks) uncompressed)
5150           (push (car marks) out)
5151         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5152       (setq marks (cdr marks)))
5153     out))
5154
5155 (defun gnus-article-mark-to-type (mark)
5156   "Return the type of MARK."
5157   (or (cadr (assq mark gnus-article-special-mark-lists))
5158       'list))
5159
5160 (defun gnus-article-unpropagatable-p (mark)
5161   "Return whether MARK should be propagated to backend."
5162   (memq mark gnus-article-unpropagated-mark-lists))
5163
5164 (defun gnus-adjust-marked-articles (info)
5165   "Set all article lists and remove all marks that are no longer valid."
5166   (let* ((marked-lists (gnus-info-marks info))
5167          (active (gnus-active (gnus-info-group info)))
5168          (min (car active))
5169          (max (cdr active))
5170          (types gnus-article-mark-lists)
5171          marks var articles article mark mark-type)
5172
5173     (dolist (marks marked-lists)
5174       (setq mark (car marks)
5175             mark-type (gnus-article-mark-to-type mark)
5176             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5177
5178       ;; We set the variable according to the type of the marks list,
5179       ;; and then adjust the marks to a subset of the active articles.
5180       (cond
5181        ;; Adjust "simple" lists.
5182        ((eq mark-type 'list)
5183         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5184         (when (memq mark '(tick dormant expire reply save))
5185           (while articles
5186             (when (or (< (setq article (pop articles)) min) (> article max))
5187               (set var (delq article (symbol-value var)))))))
5188        ;; Adjust assocs.
5189        ((eq mark-type 'tuple)
5190         (set var (setq articles (cdr marks)))
5191         (when (not (listp (cdr (symbol-value var))))
5192           (set var (list (symbol-value var))))
5193         (when (not (listp (cdr articles)))
5194           (setq articles (list articles)))
5195         (while articles
5196           (when (or (not (consp (setq article (pop articles))))
5197                     (< (car article) min)
5198                     (> (car article) max))
5199             (set var (delq article (symbol-value var))))))
5200        ;; Adjust ranges (sloppily).
5201        ((eq mark-type 'range)
5202         (cond
5203          ((eq mark 'seen)
5204           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5205           ;; It should be (seen (NUM1 . NUM2)).
5206           (when (numberp (cddr marks))
5207             (setcdr marks (list (cdr marks))))
5208           (setq articles (cdr marks))
5209           (while (and articles
5210                       (or (and (consp (car articles))
5211                                (> min (cdar articles)))
5212                           (and (numberp (car articles))
5213                                (> min (car articles)))))
5214             (pop articles))
5215           (set var articles))))))))
5216
5217 (defun gnus-update-missing-marks (missing)
5218   "Go through the list of MISSING articles and remove them from the mark lists."
5219   (when missing
5220     (let (var m)
5221       ;; Go through all types.
5222       (dolist (elem gnus-article-mark-lists)
5223         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5224           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5225           (when (symbol-value var)
5226             ;; This list has articles.  So we delete all missing
5227             ;; articles from it.
5228             (setq m missing)
5229             (while m
5230               (set var (delq (pop m) (symbol-value var))))))))))
5231
5232 (defun gnus-update-marks ()
5233   "Enter the various lists of marked articles into the newsgroup info list."
5234   (let ((types gnus-article-mark-lists)
5235         (info (gnus-get-info gnus-newsgroup-name))
5236         type list newmarked symbol delta-marks)
5237     (when info
5238       ;; Add all marks lists to the list of marks lists.
5239       (while (setq type (pop types))
5240         (setq list (symbol-value
5241                     (setq symbol
5242                           (intern (format "gnus-newsgroup-%s" (car type))))))
5243
5244         (when list
5245           ;; Get rid of the entries of the articles that have the
5246           ;; default score.
5247           (when (and (eq (cdr type) 'score)
5248                      gnus-save-score
5249                      list)
5250             (let* ((arts list)
5251                    (prev (cons nil list))
5252                    (all prev))
5253               (while arts
5254                 (if (or (not (consp (car arts)))
5255                         (= (cdar arts) gnus-summary-default-score))
5256                     (setcdr prev (cdr arts))
5257                   (setq prev arts))
5258                 (setq arts (cdr arts)))
5259               (setq list (cdr all)))))
5260
5261         (when (eq (cdr type) 'seen)
5262           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5263
5264         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5265           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5266
5267         (when (and (gnus-check-backend-function
5268                     'request-set-mark gnus-newsgroup-name)
5269                    (not (gnus-article-unpropagatable-p (cdr type))))
5270           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5271                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5272                  (add (gnus-remove-from-range
5273                        (gnus-copy-sequence list) old)))
5274             (when add
5275               (push (list add 'add (list (cdr type))) delta-marks))
5276             (when del
5277               (push (list del 'del (list (cdr type))) delta-marks))))
5278
5279         (when list
5280           (push (cons (cdr type) list) newmarked)))
5281
5282       (when delta-marks
5283         (unless (gnus-check-group gnus-newsgroup-name)
5284           (error "Can't open server for %s" gnus-newsgroup-name))
5285         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5286
5287       ;; Enter these new marks into the info of the group.
5288       (if (nthcdr 3 info)
5289           (setcar (nthcdr 3 info) newmarked)
5290         ;; Add the marks lists to the end of the info.
5291         (when newmarked
5292           (setcdr (nthcdr 2 info) (list newmarked))))
5293
5294       ;; Cut off the end of the info if there's nothing else there.
5295       (let ((i 5))
5296         (while (and (> i 2)
5297                     (not (nth i info)))
5298           (when (nthcdr (decf i) info)
5299             (setcdr (nthcdr i info) nil)))))))
5300
5301 (defun gnus-set-mode-line (where)
5302   "Set the mode line of the article or summary buffers.
5303 If WHERE is `summary', the summary mode line format will be used."
5304   ;; Is this mode line one we keep updated?
5305   (when (and (memq where gnus-updated-mode-lines)
5306              (symbol-value
5307               (intern (format "gnus-%s-mode-line-format-spec" where))))
5308     (let (mode-string)
5309       (save-excursion
5310         ;; We evaluate this in the summary buffer since these
5311         ;; variables are buffer-local to that buffer.
5312         (set-buffer gnus-summary-buffer)
5313        ;; We bind all these variables that are used in the `eval' form
5314         ;; below.
5315         (let* ((mformat (symbol-value
5316                          (intern
5317                           (format "gnus-%s-mode-line-format-spec" where))))
5318                (gnus-tmp-group-name (gnus-group-decoded-name
5319                                      gnus-newsgroup-name))
5320                (gnus-tmp-article-number (or gnus-current-article 0))
5321                (gnus-tmp-unread gnus-newsgroup-unreads)
5322                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5323                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5324                (gnus-tmp-unread-and-unselected
5325                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5326                             (zerop gnus-tmp-unselected))
5327                        "")
5328                       ((zerop gnus-tmp-unselected)
5329                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5330                       (t (format "{%d(+%d) more}"
5331                                  gnus-tmp-unread-and-unticked
5332                                  gnus-tmp-unselected))))
5333                (gnus-tmp-subject
5334                 (if (and gnus-current-headers
5335                          (vectorp gnus-current-headers))
5336                     (gnus-mode-string-quote
5337                      (mail-header-subject gnus-current-headers))
5338                   ""))
5339                bufname-length max-len
5340                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5341           (setq mode-string (eval mformat))
5342           (setq bufname-length (if (string-match "%b" mode-string)
5343                                    (- (length
5344                                        (buffer-name
5345                                         (if (eq where 'summary)
5346                                             nil
5347                                           (get-buffer gnus-article-buffer))))
5348                                       2)
5349                                  0))
5350           (setq max-len (max 4 (if gnus-mode-non-string-length
5351                                    (- (window-width)
5352                                       gnus-mode-non-string-length
5353                                       bufname-length)
5354                                  (length mode-string))))
5355           ;; We might have to chop a bit of the string off...
5356           (when (> (length mode-string) max-len)
5357             (setq mode-string
5358                   (concat (truncate-string-to-width mode-string (- max-len 3))
5359                           "...")))
5360           ;; Pad the mode string a bit.
5361           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5362       ;; Update the mode line.
5363       (setq mode-line-buffer-identification
5364             (gnus-mode-line-buffer-identification (list mode-string)))
5365       (set-buffer-modified-p t))))
5366
5367 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5368   "Go through the HEADERS list and add all Xrefs to a hash table.
5369 The resulting hash table is returned, or nil if no Xrefs were found."
5370   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5371          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5372          (xref-hashtb (gnus-make-hashtable))
5373          start group entry number xrefs header)
5374     (while headers
5375       (setq header (pop headers))
5376       (when (and (setq xrefs (mail-header-xref header))
5377                  (not (memq (setq number (mail-header-number header))
5378                             unreads)))
5379         (setq start 0)
5380         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5381           (setq start (match-end 0))
5382           (setq group (if prefix
5383                           (concat prefix (substring xrefs (match-beginning 1)
5384                                                     (match-end 1)))
5385                         (substring xrefs (match-beginning 1) (match-end 1))))
5386           (setq number
5387                 (string-to-int (substring xrefs (match-beginning 2)
5388                                           (match-end 2))))
5389           (if (setq entry (gnus-gethash group xref-hashtb))
5390               (setcdr entry (cons number (cdr entry)))
5391             (gnus-sethash group (cons number nil) xref-hashtb)))))
5392     (and start xref-hashtb)))
5393
5394 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5395   "Look through all the headers and mark the Xrefs as read."
5396   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5397         name entry info xref-hashtb idlist method nth4)
5398     (save-excursion
5399       (set-buffer gnus-group-buffer)
5400       (when (setq xref-hashtb
5401                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5402         (mapatoms
5403          (lambda (group)
5404            (unless (string= from-newsgroup (setq name (symbol-name group)))
5405              (setq idlist (symbol-value group))
5406              ;; Dead groups are not updated.
5407              (and (prog1
5408                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5409                             info (nth 2 entry))
5410                     (when (stringp (setq nth4 (gnus-info-method info)))
5411                       (setq nth4 (gnus-server-to-method nth4))))
5412                   ;; Only do the xrefs if the group has the same
5413                   ;; select method as the group we have just read.
5414                   (or (gnus-methods-equal-p
5415                        nth4 (gnus-find-method-for-group from-newsgroup))
5416                       virtual
5417                       (equal nth4 (setq method (gnus-find-method-for-group
5418                                                 from-newsgroup)))
5419                       (and (equal (car nth4) (car method))
5420                            (equal (nth 1 nth4) (nth 1 method))))
5421                   gnus-use-cross-reference
5422                   (or (not (eq gnus-use-cross-reference t))
5423                       virtual
5424                       ;; Only do cross-references on subscribed
5425                       ;; groups, if that is what is wanted.
5426                       (<= (gnus-info-level info) gnus-level-subscribed))
5427                   (gnus-group-make-articles-read name idlist))))
5428          xref-hashtb)))))
5429
5430 (defun gnus-compute-read-articles (group articles)
5431   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5432          (info (nth 2 entry))
5433          (active (gnus-active group))
5434          ninfo)
5435     (when entry
5436       ;; First peel off all invalid article numbers.
5437       (when active
5438         (let ((ids articles)
5439               id first)
5440           (while (setq id (pop ids))
5441             (when (and first (> id (cdr active)))
5442               ;; We'll end up in this situation in one particular
5443               ;; obscure situation.  If you re-scan a group and get
5444               ;; a new article that is cross-posted to a different
5445               ;; group that has not been re-scanned, you might get
5446               ;; crossposted article that has a higher number than
5447               ;; Gnus believes possible.  So we re-activate this
5448               ;; group as well.  This might mean doing the
5449               ;; crossposting thingy will *increase* the number
5450               ;; of articles in some groups.  Tsk, tsk.
5451               (setq active (or (gnus-activate-group group) active)))
5452             (when (or (> id (cdr active))
5453                       (< id (car active)))
5454               (setq articles (delq id articles))))))
5455       ;; If the read list is nil, we init it.
5456       (if (and active
5457                (null (gnus-info-read info))
5458                (> (car active) 1))
5459           (setq ninfo (cons 1 (1- (car active))))
5460         (setq ninfo (gnus-info-read info)))
5461       ;; Then we add the read articles to the range.
5462       (gnus-add-to-range
5463        ninfo (setq articles (sort articles '<))))))
5464
5465 (defun gnus-group-make-articles-read (group articles)
5466   "Update the info of GROUP to say that ARTICLES are read."
5467   (let* ((num 0)
5468          (entry (gnus-gethash group gnus-newsrc-hashtb))
5469          (info (nth 2 entry))
5470          (active (gnus-active group))
5471          range)
5472     (when entry
5473       (setq range (gnus-compute-read-articles group articles))
5474       (save-excursion
5475         (set-buffer gnus-group-buffer)
5476         (gnus-undo-register
5477           `(progn
5478              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5479              (gnus-info-set-read ',info ',(gnus-info-read info))
5480              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5481              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5482              (gnus-group-update-group ,group t))))
5483       ;; Add the read articles to the range.
5484       (gnus-info-set-read info range)
5485       (gnus-request-set-mark group (list (list range 'add '(read))))
5486       ;; Then we have to re-compute how many unread
5487       ;; articles there are in this group.
5488       (when active
5489         (cond
5490          ((not range)
5491           (setq num (- (1+ (cdr active)) (car active))))
5492          ((not (listp (cdr range)))
5493           (setq num (- (cdr active) (- (1+ (cdr range))
5494                                        (car range)))))
5495          (t
5496           (while range
5497             (if (numberp (car range))
5498                 (setq num (1+ num))
5499               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5500             (setq range (cdr range)))
5501           (setq num (- (cdr active) num))))
5502         ;; Update the number of unread articles.
5503         (setcar entry num)
5504         ;; Update the group buffer.
5505         (gnus-group-update-group group t)))))
5506
5507 (defvar gnus-newsgroup-none-id 0)
5508
5509 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5510   (let ((cur nntp-server-buffer)
5511         (dependencies
5512          (or dependencies
5513              (save-excursion (set-buffer gnus-summary-buffer)
5514                              gnus-newsgroup-dependencies)))
5515         headers id end ref
5516         (mail-parse-charset gnus-newsgroup-charset)
5517         (mail-parse-ignored-charsets
5518          (save-excursion (condition-case nil
5519                              (set-buffer gnus-summary-buffer)
5520                            (error))
5521                          gnus-newsgroup-ignored-charsets)))
5522     (save-excursion
5523       (set-buffer nntp-server-buffer)
5524       ;; Translate all TAB characters into SPACE characters.
5525       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5526       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5527       (gnus-run-hooks 'gnus-parse-headers-hook)
5528       (let ((case-fold-search t)
5529             in-reply-to header p lines chars)
5530         (goto-char (point-min))
5531         ;; Search to the beginning of the next header.  Error messages
5532         ;; do not begin with 2 or 3.
5533         (while (re-search-forward "^[23][0-9]+ " nil t)
5534           (setq id nil
5535                 ref nil)
5536           ;; This implementation of this function, with nine
5537           ;; search-forwards instead of the one re-search-forward and
5538           ;; a case (which basically was the old function) is actually
5539           ;; about twice as fast, even though it looks messier.  You
5540           ;; can't have everything, I guess.  Speed and elegance
5541           ;; doesn't always go hand in hand.
5542           (setq
5543            header
5544            (vector
5545             ;; Number.
5546             (prog1
5547                 (read cur)
5548               (end-of-line)
5549               (setq p (point))
5550               (narrow-to-region (point)
5551                                 (or (and (search-forward "\n.\n" nil t)
5552                                          (- (point) 2))
5553                                     (point))))
5554             ;; Subject.
5555             (progn
5556               (goto-char p)
5557               (if (search-forward "\nsubject:" nil t)
5558                   (funcall gnus-decode-encoded-word-function
5559                            (nnheader-header-value))
5560                 "(none)"))
5561             ;; From.
5562             (progn
5563               (goto-char p)
5564               (if (search-forward "\nfrom:" nil t)
5565                   (funcall gnus-decode-encoded-word-function
5566                            (nnheader-header-value))
5567                 "(nobody)"))
5568             ;; Date.
5569             (progn
5570               (goto-char p)
5571               (if (search-forward "\ndate:" nil t)
5572                   (nnheader-header-value) ""))
5573             ;; Message-ID.
5574             (progn
5575               (goto-char p)
5576               (setq id (if (re-search-forward
5577                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5578                            ;; We do it this way to make sure the Message-ID
5579                            ;; is (somewhat) syntactically valid.
5580                            (buffer-substring (match-beginning 1)
5581                                              (match-end 1))
5582                          ;; If there was no message-id, we just fake one
5583                          ;; to make subsequent routines simpler.
5584                          (nnheader-generate-fake-message-id))))
5585             ;; References.
5586             (progn
5587               (goto-char p)
5588               (if (search-forward "\nreferences:" nil t)
5589                   (progn
5590                     (setq end (point))
5591                     (prog1
5592                         (nnheader-header-value)
5593                       (setq ref
5594                             (buffer-substring
5595                              (progn
5596                                (end-of-line)
5597                                (search-backward ">" end t)
5598                                (1+ (point)))
5599                              (progn
5600                                (search-backward "<" end t)
5601                                (point))))))
5602                 ;; Get the references from the in-reply-to header if there
5603                 ;; were no references and the in-reply-to header looks
5604                 ;; promising.
5605                 (if (and (search-forward "\nin-reply-to:" nil t)
5606                          (setq in-reply-to (nnheader-header-value))
5607                          (string-match "<[^>]+>" in-reply-to))
5608                     (let (ref2)
5609                       (setq ref (substring in-reply-to (match-beginning 0)
5610                                            (match-end 0)))
5611                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5612                         (setq ref2 (substring in-reply-to (match-beginning 0)
5613                                               (match-end 0)))
5614                         (when (> (length ref2) (length ref))
5615                           (setq ref ref2)))
5616                       ref)
5617                   (setq ref nil))))
5618             ;; Chars.
5619             (progn
5620               (goto-char p)
5621               (if (search-forward "\nchars: " nil t)
5622                   (if (numberp (setq chars (ignore-errors (read cur))))
5623                       chars -1)
5624                 -1))
5625             ;; Lines.
5626             (progn
5627               (goto-char p)
5628               (if (search-forward "\nlines: " nil t)
5629                   (if (numberp (setq lines (ignore-errors (read cur))))
5630                       lines -1)
5631                 -1))
5632             ;; Xref.
5633             (progn
5634               (goto-char p)
5635               (and (search-forward "\nxref:" nil t)
5636                    (nnheader-header-value)))
5637             ;; Extra.
5638             (when gnus-extra-headers
5639               (let ((extra gnus-extra-headers)
5640                     out)
5641                 (while extra
5642                   (goto-char p)
5643                   (when (search-forward
5644                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5645                     (push (cons (car extra) (nnheader-header-value))
5646                           out))
5647                   (pop extra))
5648                 out))))
5649           (when (equal id ref)
5650             (setq ref nil))
5651
5652           (when gnus-alter-header-function
5653             (funcall gnus-alter-header-function header)
5654             (setq id (mail-header-id header)
5655                   ref (gnus-parent-id (mail-header-references header))))
5656
5657           (when (setq header
5658                       (gnus-dependencies-add-header
5659                        header dependencies force-new))
5660             (push header headers))
5661           (goto-char (point-max))
5662           (widen))
5663         (nreverse headers)))))
5664
5665 ;; Goes through the xover lines and returns a list of vectors
5666 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5667                                                   force-new dependencies
5668                                                   group also-fetch-heads)
5669   "Parse the news overview data in the server buffer.
5670 Return a list of headers that match SEQUENCE (see
5671 `nntp-retrieve-headers')."
5672   ;; Get the Xref when the users reads the articles since most/some
5673   ;; NNTP servers do not include Xrefs when using XOVER.
5674   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5675   (let ((mail-parse-charset gnus-newsgroup-charset)
5676         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5677         (cur nntp-server-buffer)
5678         (dependencies (or dependencies gnus-newsgroup-dependencies))
5679         (allp (cond
5680                ((eq gnus-read-all-available-headers t)
5681                 t)
5682                ((stringp gnus-read-all-available-headers)
5683                 (string-match gnus-read-all-available-headers group))
5684                (t
5685                 nil)))
5686         number headers header)
5687     (save-excursion
5688       (set-buffer nntp-server-buffer)
5689       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5690       ;; Allow the user to mangle the headers before parsing them.
5691       (gnus-run-hooks 'gnus-parse-headers-hook)
5692       (goto-char (point-min))
5693       (gnus-parse-without-error
5694         (while (and (or sequence allp)
5695                     (not (eobp)))
5696           (setq number (read cur))
5697           (when (not allp)
5698             (while (and sequence
5699                         (< (car sequence) number))
5700               (setq sequence (cdr sequence))))
5701           (when (and (or allp
5702                          (and sequence
5703                               (eq number (car sequence))))
5704                      (progn
5705                        (setq sequence (cdr sequence))
5706                        (setq header (inline
5707                                       (gnus-nov-parse-line
5708                                        number dependencies force-new)))))
5709             (push header headers))
5710           (forward-line 1)))
5711       ;; A common bug in inn is that if you have posted an article and
5712       ;; then retrieves the active file, it will answer correctly --
5713       ;; the new article is included.  However, a NOV entry for the
5714       ;; article may not have been generated yet, so this may fail.
5715       ;; We work around this problem by retrieving the last few
5716       ;; headers using HEAD.
5717       (if (or (not also-fetch-heads)
5718               (not sequence))
5719           ;; We (probably) got all the headers.
5720           (nreverse headers)
5721         (let ((gnus-nov-is-evil t))
5722           (nconc
5723            (nreverse headers)
5724            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5725              (gnus-get-newsgroup-headers))))))))
5726
5727 (defun gnus-article-get-xrefs ()
5728   "Fill in the Xref value in `gnus-current-headers', if necessary.
5729 This is meant to be called in `gnus-article-internal-prepare-hook'."
5730   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5731                                  gnus-current-headers)))
5732     (or (not gnus-use-cross-reference)
5733         (not headers)
5734         (and (mail-header-xref headers)
5735              (not (string= (mail-header-xref headers) "")))
5736         (let ((case-fold-search t)
5737               xref)
5738           (save-restriction
5739             (nnheader-narrow-to-headers)
5740             (goto-char (point-min))
5741             (when (or (and (not (eobp))
5742                            (eq (downcase (char-after)) ?x)
5743                            (looking-at "Xref:"))
5744                       (search-forward "\nXref:" nil t))
5745               (goto-char (1+ (match-end 0)))
5746               (setq xref (buffer-substring (point)
5747                                            (progn (end-of-line) (point))))
5748               (mail-header-set-xref headers xref)))))))
5749
5750 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5751   "Find article ID and insert the summary line for that article.
5752 OLD-HEADER can either be a header or a line number to insert
5753 the subject line on."
5754   (let* ((line (and (numberp old-header) old-header))
5755          (old-header (and (vectorp old-header) old-header))
5756          (header (cond ((and old-header use-old-header)
5757                         old-header)
5758                        ((and (numberp id)
5759                              (gnus-number-to-header id))
5760                         (gnus-number-to-header id))
5761                        (t
5762                         (gnus-read-header id))))
5763          (number (and (numberp id) id))
5764          d)
5765     (when header
5766       ;; Rebuild the thread that this article is part of and go to the
5767       ;; article we have fetched.
5768       (when (and (not gnus-show-threads)
5769                  old-header)
5770         (when (and number
5771                    (setq d (gnus-data-find (mail-header-number old-header))))
5772           (goto-char (gnus-data-pos d))
5773           (gnus-data-remove
5774            number
5775            (- (gnus-point-at-bol)
5776               (prog1
5777                   (1+ (gnus-point-at-eol))
5778                 (gnus-delete-line))))))
5779       (when old-header
5780         (mail-header-set-number header (mail-header-number old-header)))
5781       (setq gnus-newsgroup-sparse
5782             (delq (setq number (mail-header-number header))
5783                   gnus-newsgroup-sparse))
5784       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5785       (push number gnus-newsgroup-limit)
5786       (gnus-rebuild-thread (mail-header-id header) line)
5787       (gnus-summary-goto-subject number nil t))
5788     (when (and (numberp number)
5789                (> number 0))
5790       ;; We have to update the boundaries even if we can't fetch the
5791       ;; article if ID is a number -- so that the next `P' or `N'
5792       ;; command will fetch the previous (or next) article even
5793       ;; if the one we tried to fetch this time has been canceled.
5794       (when (> number gnus-newsgroup-end)
5795         (setq gnus-newsgroup-end number))
5796       (when (< number gnus-newsgroup-begin)
5797         (setq gnus-newsgroup-begin number))
5798       (setq gnus-newsgroup-unselected
5799             (delq number gnus-newsgroup-unselected)))
5800     ;; Report back a success?
5801     (and header (mail-header-number header))))
5802
5803 ;;; Process/prefix in the summary buffer
5804
5805 (defun gnus-summary-work-articles (n)
5806   "Return a list of articles to be worked upon.
5807 The prefix argument, the list of process marked articles, and the
5808 current article will be taken into consideration."
5809   (save-excursion
5810     (set-buffer gnus-summary-buffer)
5811     (cond
5812      (n
5813       ;; A numerical prefix has been given.
5814       (setq n (prefix-numeric-value n))
5815       (let ((backward (< n 0))
5816             (n (abs (prefix-numeric-value n)))
5817             articles article)
5818         (save-excursion
5819           (while
5820               (and (> n 0)
5821                    (push (setq article (gnus-summary-article-number))
5822                          articles)
5823                    (if backward
5824                        (gnus-summary-find-prev nil article)
5825                      (gnus-summary-find-next nil article)))
5826             (decf n)))
5827         (nreverse articles)))
5828      ((and (gnus-region-active-p) (mark))
5829       (message "region active")
5830       ;; Work on the region between point and mark.
5831       (let ((max (max (point) (mark)))
5832             articles article)
5833         (save-excursion
5834           (goto-char (min (min (point) (mark))))
5835           (while
5836               (and
5837                (push (setq article (gnus-summary-article-number)) articles)
5838                (gnus-summary-find-next nil article)
5839                (< (point) max)))
5840           (nreverse articles))))
5841      (gnus-newsgroup-processable
5842       ;; There are process-marked articles present.
5843       ;; Save current state.
5844       (gnus-summary-save-process-mark)
5845       ;; Return the list.
5846       (reverse gnus-newsgroup-processable))
5847      (t
5848       ;; Just return the current article.
5849       (list (gnus-summary-article-number))))))
5850
5851 (defmacro gnus-summary-iterate (arg &rest forms)
5852   "Iterate over the process/prefixed articles and do FORMS.
5853 ARG is the interactive prefix given to the command.  FORMS will be
5854 executed with point over the summary line of the articles."
5855   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5856     `(let ((,articles (gnus-summary-work-articles ,arg)))
5857        (while ,articles
5858          (gnus-summary-goto-subject (car ,articles))
5859          ,@forms
5860          (pop ,articles)))))
5861
5862 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5863 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5864
5865 (defun gnus-summary-save-process-mark ()
5866   "Push the current set of process marked articles on the stack."
5867   (interactive)
5868   (push (copy-sequence gnus-newsgroup-processable)
5869         gnus-newsgroup-process-stack))
5870
5871 (defun gnus-summary-kill-process-mark ()
5872   "Push the current set of process marked articles on the stack and unmark."
5873   (interactive)
5874   (gnus-summary-save-process-mark)
5875   (gnus-summary-unmark-all-processable))
5876
5877 (defun gnus-summary-yank-process-mark ()
5878   "Pop the last process mark state off the stack and restore it."
5879   (interactive)
5880   (unless gnus-newsgroup-process-stack
5881     (error "Empty mark stack"))
5882   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5883
5884 (defun gnus-summary-process-mark-set (set)
5885   "Make SET into the current process marked articles."
5886   (gnus-summary-unmark-all-processable)
5887   (while set
5888     (gnus-summary-set-process-mark (pop set))))
5889
5890 ;;; Searching and stuff
5891
5892 (defun gnus-summary-search-group (&optional backward use-level)
5893   "Search for next unread newsgroup.
5894 If optional argument BACKWARD is non-nil, search backward instead."
5895   (save-excursion
5896     (set-buffer gnus-group-buffer)
5897     (when (gnus-group-search-forward
5898            backward nil (if use-level (gnus-group-group-level) nil))
5899       (gnus-group-group-name))))
5900
5901 (defun gnus-summary-best-group (&optional exclude-group)
5902   "Find the name of the best unread group.
5903 If EXCLUDE-GROUP, do not go to this group."
5904   (save-excursion
5905     (set-buffer gnus-group-buffer)
5906     (save-excursion
5907       (gnus-group-best-unread-group exclude-group))))
5908
5909 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5910   (if backward (gnus-summary-find-prev)
5911     (let* ((dummy (gnus-summary-article-intangible-p))
5912            (article (or article (gnus-summary-article-number)))
5913            (arts (gnus-data-find-list article))
5914            result)
5915       (when (and (not dummy)
5916                  (or (not gnus-summary-check-current)
5917                      (not unread)
5918                      (not (gnus-data-unread-p (car arts)))))
5919         (setq arts (cdr arts)))
5920       (when (setq result
5921                   (if unread
5922                       (progn
5923                         (while arts
5924                           (when (or (and undownloaded
5925                                          (eq gnus-undownloaded-mark
5926                                              (gnus-data-mark (car arts))))
5927                                     (gnus-data-unread-p (car arts)))
5928                             (setq result (car arts)
5929                                   arts nil))
5930                           (setq arts (cdr arts)))
5931                         result)
5932                     (car arts)))
5933         (goto-char (gnus-data-pos result))
5934         (gnus-data-number result)))))
5935
5936 (defun gnus-summary-find-prev (&optional unread article)
5937   (let* ((eobp (eobp))
5938          (article (or article (gnus-summary-article-number)))
5939          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5940          result)
5941     (when (and (not eobp)
5942                (or (not gnus-summary-check-current)
5943                    (not unread)
5944                    (not (gnus-data-unread-p (car arts)))))
5945       (setq arts (cdr arts)))
5946     (when (setq result
5947                 (if unread
5948                     (progn
5949                       (while arts
5950                         (when (gnus-data-unread-p (car arts))
5951                           (setq result (car arts)
5952                                 arts nil))
5953                         (setq arts (cdr arts)))
5954                       result)
5955                   (car arts)))
5956       (goto-char (gnus-data-pos result))
5957       (gnus-data-number result))))
5958
5959 (defun gnus-summary-find-subject (subject &optional unread backward article)
5960   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5961          (article (or article (gnus-summary-article-number)))
5962          (articles (gnus-data-list backward))
5963          (arts (gnus-data-find-list article articles))
5964          result)
5965     (when (or (not gnus-summary-check-current)
5966               (not unread)
5967               (not (gnus-data-unread-p (car arts))))
5968       (setq arts (cdr arts)))
5969     (while arts
5970       (and (or (not unread)
5971                (gnus-data-unread-p (car arts)))
5972            (vectorp (gnus-data-header (car arts)))
5973            (gnus-subject-equal
5974             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5975            (setq result (car arts)
5976                  arts nil))
5977       (setq arts (cdr arts)))
5978     (and result
5979          (goto-char (gnus-data-pos result))
5980          (gnus-data-number result))))
5981
5982 (defun gnus-summary-search-forward (&optional unread subject backward)
5983   "Search forward for an article.
5984 If UNREAD, look for unread articles.  If SUBJECT, look for
5985 articles with that subject.  If BACKWARD, search backward instead."
5986   (cond (subject (gnus-summary-find-subject subject unread backward))
5987         (backward (gnus-summary-find-prev unread))
5988         (t (gnus-summary-find-next unread))))
5989
5990 (defun gnus-recenter (&optional n)
5991   "Center point in window and redisplay frame.
5992 Also do horizontal recentering."
5993   (interactive "P")
5994   (when (and gnus-auto-center-summary
5995              (not (eq gnus-auto-center-summary 'vertical)))
5996     (gnus-horizontal-recenter))
5997   (recenter n))
5998
5999 (defun gnus-summary-recenter ()
6000   "Center point in the summary window.
6001 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6002 displayed, no centering will be performed."
6003   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6004 ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6005   (interactive)
6006   (let* ((top (cond ((< (window-height) 4) 0)
6007                     ((< (window-height) 7) 1)
6008                     (t (if (numberp gnus-auto-center-summary)
6009                            gnus-auto-center-summary
6010                          2))))
6011          (height (1- (window-height)))
6012          (bottom (save-excursion (goto-char (point-max))
6013                                  (forward-line (- height))
6014                                  (point)))
6015          (window (get-buffer-window (current-buffer))))
6016     ;; The user has to want it.
6017     (when gnus-auto-center-summary
6018       (when (get-buffer-window gnus-article-buffer)
6019         ;; Only do recentering when the article buffer is displayed,
6020       ;; Set the window start to either `bottom', which is the biggest
6021         ;; possible valid number, or the second line from the top,
6022         ;; whichever is the least.
6023         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6024           (if (> bottom top-pos)
6025               ;; Keep the second line from the top visible
6026               (set-window-start window top-pos t)
6027             ;; Try to keep the bottom line visible; if it's partially
6028             ;; obscured, either scroll one more line to make it fully
6029             ;; visible, or revert to using TOP-POS.
6030             (save-excursion
6031               (goto-char (point-max))
6032               (forward-line -1)
6033               (let ((last-line-start (point)))
6034                 (goto-char bottom)
6035                 (set-window-start window (point) t)
6036                 (when (not (pos-visible-in-window-p last-line-start window))
6037                   (forward-line 1)
6038                   (set-window-start window (min (point) top-pos) t)))))))
6039       ;; Do horizontal recentering while we're at it.
6040       (when (and (get-buffer-window (current-buffer) t)
6041                  (not (eq gnus-auto-center-summary 'vertical)))
6042         (let ((selected (selected-window)))
6043           (select-window (get-buffer-window (current-buffer) t))
6044           (gnus-summary-position-point)
6045           (gnus-horizontal-recenter)
6046           (select-window selected))))))
6047
6048 (defun gnus-summary-jump-to-group (newsgroup)
6049   "Move point to NEWSGROUP in group mode buffer."
6050   ;; Keep update point of group mode buffer if visible.
6051   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6052       (save-window-excursion
6053         ;; Take care of tree window mode.
6054         (when (get-buffer-window gnus-group-buffer)
6055           (pop-to-buffer gnus-group-buffer))
6056         (gnus-group-jump-to-group newsgroup))
6057     (save-excursion
6058       ;; Take care of tree window mode.
6059       (if (get-buffer-window gnus-group-buffer)
6060           (pop-to-buffer gnus-group-buffer)
6061         (set-buffer gnus-group-buffer))
6062       (gnus-group-jump-to-group newsgroup))))
6063
6064 ;; This function returns a list of article numbers based on the
6065 ;; difference between the ranges of read articles in this group and
6066 ;; the range of active articles.
6067 (defun gnus-list-of-unread-articles (group)
6068   (let* ((read (gnus-info-read (gnus-get-info group)))
6069          (active (or (gnus-active group) (gnus-activate-group group)))
6070          (last (cdr active))
6071          first nlast unread)
6072     ;; If none are read, then all are unread.
6073     (if (not read)
6074         (setq first (car active))
6075       ;; If the range of read articles is a single range, then the
6076       ;; first unread article is the article after the last read
6077       ;; article.  Sounds logical, doesn't it?
6078       (if (and (not (listp (cdr read)))
6079                (or (< (car read) (car active))
6080                    (progn (setq read (list read))
6081                           nil)))
6082           (setq first (max (car active) (1+ (cdr read))))
6083         ;; `read' is a list of ranges.
6084         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6085                                   (caar read)))
6086                   1)
6087           (setq first (car active)))
6088         (while read
6089           (when first
6090             (while (< first nlast)
6091               (push first unread)
6092               (setq first (1+ first))))
6093           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6094           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6095           (setq read (cdr read)))))
6096     ;; And add the last unread articles.
6097     (while (<= first last)
6098       (push first unread)
6099       (setq first (1+ first)))
6100     ;; Return the list of unread articles.
6101     (delq 0 (nreverse unread))))
6102
6103 (defun gnus-list-of-read-articles (group)
6104   "Return a list of unread, unticked and non-dormant articles."
6105   (let* ((info (gnus-get-info group))
6106          (marked (gnus-info-marks info))
6107          (active (gnus-active group)))
6108     (and info active
6109          (gnus-list-range-difference
6110           (gnus-list-range-difference
6111            (gnus-sorted-complement
6112             (gnus-uncompress-range active)
6113             (gnus-list-of-unread-articles group))
6114            (cdr (assq 'dormant marked)))
6115           (cdr (assq 'tick marked))))))
6116
6117 ;; Various summary commands
6118
6119 (defun gnus-summary-select-article-buffer ()
6120   "Reconfigure windows to show article buffer."
6121   (interactive)
6122   (if (not (gnus-buffer-live-p gnus-article-buffer))
6123       (error "There is no article buffer for this summary buffer")
6124     (gnus-configure-windows 'article)
6125     (select-window (get-buffer-window gnus-article-buffer))))
6126
6127 (defun gnus-summary-universal-argument (arg)
6128   "Perform any operation on all articles that are process/prefixed."
6129   (interactive "P")
6130   (let ((articles (gnus-summary-work-articles arg))
6131         func article)
6132     (if (eq
6133          (setq
6134           func
6135           (key-binding
6136            (read-key-sequence
6137             (substitute-command-keys
6138              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6139          'undefined)
6140         (gnus-error 1 "Undefined key")
6141       (save-excursion
6142         (while articles
6143           (gnus-summary-goto-subject (setq article (pop articles)))
6144           (let (gnus-newsgroup-processable)
6145             (command-execute func))
6146           (gnus-summary-remove-process-mark article)))))
6147   (gnus-summary-position-point))
6148
6149 (defun gnus-summary-toggle-truncation (&optional arg)
6150   "Toggle truncation of summary lines.
6151 With arg, turn line truncation on if arg is positive."
6152   (interactive "P")
6153   (setq truncate-lines
6154         (if (null arg) (not truncate-lines)
6155           (> (prefix-numeric-value arg) 0)))
6156   (redraw-display))
6157
6158 (defun gnus-summary-find-uncancelled ()
6159   "Return the number of an uncancelled article.
6160 The current article is considered, then following articles, then previous
6161 articles.  If all articles are cancelled then return a dummy 0."
6162   (let (found)
6163     (dolist (rev '(nil t))
6164       (unless found      ; don't demand the reverse list if we don't need it
6165         (let ((data (gnus-data-find-list
6166                      (gnus-summary-article-number) (gnus-data-list rev))))
6167           (while (and data (not found))
6168             (if (not (eq gnus-canceled-mark (gnus-data-mark (car data))))
6169                 (setq found (gnus-data-number (car data))))
6170             (setq data (cdr data))))))
6171     (or found 0)))
6172
6173 (defun gnus-summary-reselect-current-group (&optional all rescan)
6174   "Exit and then reselect the current newsgroup.
6175 The prefix argument ALL means to select all articles."
6176   (interactive "P")
6177   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6178     (error "Ephemeral groups can't be reselected"))
6179   (let ((current-subject (gnus-summary-find-uncancelled))
6180         (group gnus-newsgroup-name))
6181     (setq gnus-newsgroup-begin nil)
6182     (gnus-summary-exit)
6183     ;; We have to adjust the point of group mode buffer because
6184     ;; point was moved to the next unread newsgroup by exiting.
6185     (gnus-summary-jump-to-group group)
6186     (when rescan
6187       (save-excursion
6188         (gnus-group-get-new-news-this-group 1)))
6189     (gnus-group-read-group all t)
6190     (gnus-summary-goto-subject current-subject nil t)))
6191
6192 (defun gnus-summary-rescan-group (&optional all)
6193   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6194   (interactive "P")
6195   (gnus-summary-reselect-current-group all t))
6196
6197 (defun gnus-summary-update-info (&optional non-destructive)
6198   (save-excursion
6199     (let ((group gnus-newsgroup-name))
6200       (when group
6201         (when gnus-newsgroup-kill-headers
6202           (setq gnus-newsgroup-killed
6203                 (gnus-compress-sequence
6204                  (gnus-sorted-union
6205                   (gnus-list-range-intersection
6206                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6207                   gnus-newsgroup-unreads)
6208                  t)))
6209         (unless (listp (cdr gnus-newsgroup-killed))
6210           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6211         (let ((headers gnus-newsgroup-headers))
6212           ;; Set the new ranges of read articles.
6213           (save-excursion
6214             (set-buffer gnus-group-buffer)
6215             (gnus-undo-force-boundary))
6216           (gnus-update-read-articles
6217            group (gnus-sorted-union
6218                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6219           ;; Set the current article marks.
6220           (let ((gnus-newsgroup-scored
6221                  (if (and (not gnus-save-score)
6222                           (not non-destructive))
6223                      nil
6224                    gnus-newsgroup-scored)))
6225             (save-excursion
6226               (gnus-update-marks)))
6227           ;; Do the cross-ref thing.
6228           (when gnus-use-cross-reference
6229             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6230           ;; Do not switch windows but change the buffer to work.
6231           (set-buffer gnus-group-buffer)
6232           (unless (gnus-ephemeral-group-p group)
6233             (gnus-group-update-group group)))))))
6234
6235 (defun gnus-summary-save-newsrc (&optional force)
6236   "Save the current number of read/marked articles in the dribble buffer.
6237 The dribble buffer will then be saved.
6238 If FORCE (the prefix), also save the .newsrc file(s)."
6239   (interactive "P")
6240   (gnus-summary-update-info t)
6241   (if force
6242       (gnus-save-newsrc-file)
6243     (gnus-dribble-save)))
6244
6245 (defun gnus-summary-exit (&optional temporary)
6246   "Exit reading current newsgroup, and then return to group selection mode.
6247 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6248   (interactive)
6249   (gnus-set-global-variables)
6250   (when (gnus-buffer-live-p gnus-article-buffer)
6251     (save-excursion
6252       (set-buffer gnus-article-buffer)
6253       (mm-destroy-parts gnus-article-mime-handles)
6254       ;; Set it to nil for safety reason.
6255       (setq gnus-article-mime-handle-alist nil)
6256       (setq gnus-article-mime-handles nil)))
6257   (gnus-kill-save-kill-buffer)
6258   (gnus-async-halt-prefetch)
6259   (let* ((group gnus-newsgroup-name)
6260          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6261          (mode major-mode)
6262          (group-point nil)
6263          (buf (current-buffer)))
6264     (unless quit-config
6265       ;; Do adaptive scoring, and possibly save score files.
6266       (when gnus-newsgroup-adaptive
6267         (gnus-score-adaptive))
6268       (when gnus-use-scoring
6269         (gnus-score-save)))
6270     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6271     ;; If we have several article buffers, we kill them at exit.
6272     (unless gnus-single-article-buffer
6273       (gnus-kill-buffer gnus-original-article-buffer)
6274       (setq gnus-article-current nil))
6275     (when gnus-use-cache
6276       (gnus-cache-possibly-remove-articles)
6277       (gnus-cache-save-buffers))
6278     (gnus-async-prefetch-remove-group group)
6279     (when gnus-suppress-duplicates
6280       (gnus-dup-enter-articles))
6281     (when gnus-use-trees
6282       (gnus-tree-close group))
6283     (when gnus-use-cache
6284       (gnus-cache-write-active))
6285     ;; Remove entries for this group.
6286     (nnmail-purge-split-history (gnus-group-real-name group))
6287     ;; Make all changes in this group permanent.
6288     (unless quit-config
6289       (gnus-run-hooks 'gnus-exit-group-hook)
6290       (gnus-summary-update-info))
6291     (gnus-close-group group)
6292     ;; Make sure where we were, and go to next newsgroup.
6293     (set-buffer gnus-group-buffer)
6294     (unless quit-config
6295       (gnus-group-jump-to-group group))
6296     (gnus-run-hooks 'gnus-summary-exit-hook)
6297     (unless (or quit-config
6298                 ;; If this group has disappeared from the summary
6299                 ;; buffer, don't skip forwards.
6300                 (not (string= group (gnus-group-group-name))))
6301       (gnus-group-next-unread-group 1))
6302     (setq group-point (point))
6303     (if temporary
6304         nil                             ;Nothing to do.
6305       ;; If we have several article buffers, we kill them at exit.
6306       (unless gnus-single-article-buffer
6307         (gnus-kill-buffer gnus-article-buffer)
6308         (gnus-kill-buffer gnus-original-article-buffer)
6309         (setq gnus-article-current nil))
6310       (set-buffer buf)
6311       (if (not gnus-kill-summary-on-exit)
6312           (progn
6313             (gnus-deaden-summary)
6314             (setq mode nil))
6315        ;; We set all buffer-local variables to nil.  It is unclear why
6316         ;; this is needed, but if we don't, buffer-local variables are
6317         ;; not garbage-collected, it seems.  This would the lead to en
6318         ;; ever-growing Emacs.
6319         (gnus-summary-clear-local-variables)
6320         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6321           (gnus-summary-clear-local-variables))
6322         (when (get-buffer gnus-article-buffer)
6323           (bury-buffer gnus-article-buffer))
6324         ;; We clear the global counterparts of the buffer-local
6325         ;; variables as well, just to be on the safe side.
6326         (set-buffer gnus-group-buffer)
6327         (gnus-summary-clear-local-variables)
6328         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6329           (gnus-summary-clear-local-variables)))
6330       (setq gnus-current-select-method gnus-select-method)
6331       (pop-to-buffer gnus-group-buffer)
6332       (if (not quit-config)
6333           (progn
6334             (goto-char group-point)
6335             (gnus-configure-windows 'group 'force))
6336         (gnus-handle-ephemeral-exit quit-config))
6337       ;; Return to group mode buffer.
6338       (when (eq mode 'gnus-summary-mode)
6339         (gnus-kill-buffer buf))
6340       ;; Clear the current group name.
6341       (unless quit-config
6342         (setq gnus-newsgroup-name nil)))))
6343
6344 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6345 (defun gnus-summary-exit-no-update (&optional no-questions)
6346   "Quit reading current newsgroup without updating read article info."
6347   (interactive)
6348   (let* ((group gnus-newsgroup-name)
6349          (quit-config (gnus-group-quit-config group)))
6350     (when (or no-questions
6351               gnus-expert-user
6352               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6353       (gnus-async-halt-prefetch)
6354       (mapcar 'funcall
6355               (delq 'gnus-summary-expire-articles
6356                     (copy-sequence gnus-summary-prepare-exit-hook)))
6357       (when (gnus-buffer-live-p gnus-article-buffer)
6358         (save-excursion
6359           (set-buffer gnus-article-buffer)
6360           (mm-destroy-parts gnus-article-mime-handles)
6361           ;; Set it to nil for safety reason.
6362           (setq gnus-article-mime-handle-alist nil)
6363           (setq gnus-article-mime-handles nil)))
6364       ;; If we have several article buffers, we kill them at exit.
6365       (unless gnus-single-article-buffer
6366         (gnus-kill-buffer gnus-article-buffer)
6367         (gnus-kill-buffer gnus-original-article-buffer)
6368         (setq gnus-article-current nil))
6369       (if (not gnus-kill-summary-on-exit)
6370           (gnus-deaden-summary)
6371         (gnus-close-group group)
6372         (gnus-summary-clear-local-variables)
6373         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6374           (gnus-summary-clear-local-variables))
6375         (set-buffer gnus-group-buffer)
6376         (gnus-summary-clear-local-variables)
6377         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6378           (gnus-summary-clear-local-variables))
6379         (when (get-buffer gnus-summary-buffer)
6380           (kill-buffer gnus-summary-buffer)))
6381       (unless gnus-single-article-buffer
6382         (setq gnus-article-current nil))
6383       (when gnus-use-trees
6384         (gnus-tree-close group))
6385       (gnus-async-prefetch-remove-group group)
6386       (when (get-buffer gnus-article-buffer)
6387         (bury-buffer gnus-article-buffer))
6388       ;; Return to the group buffer.
6389       (gnus-configure-windows 'group 'force)
6390       ;; Clear the current group name.
6391       (setq gnus-newsgroup-name nil)
6392       (when (equal (gnus-group-group-name) group)
6393         (gnus-group-next-unread-group 1))
6394       (when quit-config
6395         (gnus-handle-ephemeral-exit quit-config)))))
6396
6397 (defun gnus-handle-ephemeral-exit (quit-config)
6398   "Handle movement when leaving an ephemeral group.
6399 The state which existed when entering the ephemeral is reset."
6400   (if (not (buffer-name (car quit-config)))
6401       (gnus-configure-windows 'group 'force)
6402     (set-buffer (car quit-config))
6403     (cond ((eq major-mode 'gnus-summary-mode)
6404            (gnus-set-global-variables))
6405           ((eq major-mode 'gnus-article-mode)
6406            (save-excursion
6407              ;; The `gnus-summary-buffer' variable may point
6408              ;; to the old summary buffer when using a single
6409              ;; article buffer.
6410              (unless (gnus-buffer-live-p gnus-summary-buffer)
6411                (set-buffer gnus-group-buffer))
6412              (set-buffer gnus-summary-buffer)
6413              (gnus-set-global-variables))))
6414     (if (or (eq (cdr quit-config) 'article)
6415             (eq (cdr quit-config) 'pick))
6416         (progn
6417           ;; The current article may be from the ephemeral group
6418           ;; thus it is best that we reload this article
6419           (gnus-summary-show-article)
6420           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6421               (gnus-configure-windows 'pick 'force)
6422             (gnus-configure-windows (cdr quit-config) 'force)))
6423       (gnus-configure-windows (cdr quit-config) 'force))
6424     (when (eq major-mode 'gnus-summary-mode)
6425       (gnus-summary-next-subject 1 nil t)
6426       (gnus-summary-recenter)
6427       (gnus-summary-position-point))))
6428
6429 ;;; Dead summaries.
6430
6431 (defvar gnus-dead-summary-mode-map nil)
6432
6433 (unless gnus-dead-summary-mode-map
6434   (setq gnus-dead-summary-mode-map (make-keymap))
6435   (suppress-keymap gnus-dead-summary-mode-map)
6436   (substitute-key-definition
6437    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6438   (dolist (key '("\C-d" "\r" "\177" [delete]))
6439     (define-key gnus-dead-summary-mode-map
6440       key 'gnus-summary-wake-up-the-dead))
6441   (dolist (key '("q" "Q"))
6442     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6443
6444 (defvar gnus-dead-summary-mode nil
6445   "Minor mode for Gnus summary buffers.")
6446
6447 (defun gnus-dead-summary-mode (&optional arg)
6448   "Minor mode for Gnus summary buffers."
6449   (interactive "P")
6450   (when (eq major-mode 'gnus-summary-mode)
6451     (make-local-variable 'gnus-dead-summary-mode)
6452     (setq gnus-dead-summary-mode
6453           (if (null arg) (not gnus-dead-summary-mode)
6454             (> (prefix-numeric-value arg) 0)))
6455     (when gnus-dead-summary-mode
6456       (gnus-add-minor-mode
6457        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6458
6459 (defun gnus-deaden-summary ()
6460   "Make the current summary buffer into a dead summary buffer."
6461   ;; Kill any previous dead summary buffer.
6462   (when (and gnus-dead-summary
6463              (buffer-name gnus-dead-summary))
6464     (save-excursion
6465       (set-buffer gnus-dead-summary)
6466       (when gnus-dead-summary-mode
6467         (kill-buffer (current-buffer)))))
6468   ;; Make this the current dead summary.
6469   (setq gnus-dead-summary (current-buffer))
6470   (gnus-dead-summary-mode 1)
6471   (let ((name (buffer-name)))
6472     (when (string-match "Summary" name)
6473       (rename-buffer
6474        (concat (substring name 0 (match-beginning 0)) "Dead "
6475                (substring name (match-beginning 0)))
6476        t)
6477       (bury-buffer))))
6478
6479 (defun gnus-kill-or-deaden-summary (buffer)
6480   "Kill or deaden the summary BUFFER."
6481   (save-excursion
6482     (when (and (buffer-name buffer)
6483                (not gnus-single-article-buffer))
6484       (save-excursion
6485         (set-buffer buffer)
6486         (gnus-kill-buffer gnus-article-buffer)
6487         (gnus-kill-buffer gnus-original-article-buffer)))
6488     (cond
6489      ;; Kill the buffer.
6490      (gnus-kill-summary-on-exit
6491       (when (and gnus-use-trees
6492                  (gnus-buffer-exists-p buffer))
6493         (save-excursion
6494           (set-buffer buffer)
6495           (gnus-tree-close gnus-newsgroup-name)))
6496       (gnus-kill-buffer buffer))
6497      ;; Deaden the buffer.
6498      ((gnus-buffer-exists-p buffer)
6499       (save-excursion
6500         (set-buffer buffer)
6501         (gnus-deaden-summary))))))
6502
6503 (defun gnus-summary-wake-up-the-dead (&rest args)
6504   "Wake up the dead summary buffer."
6505   (interactive)
6506   (gnus-dead-summary-mode -1)
6507   (let ((name (buffer-name)))
6508     (when (string-match "Dead " name)
6509       (rename-buffer
6510        (concat (substring name 0 (match-beginning 0))
6511                (substring name (match-end 0)))
6512        t)))
6513   (gnus-message 3 "This dead summary is now alive again"))
6514
6515 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6516 (defun gnus-summary-fetch-faq (&optional faq-dir)
6517   "Fetch the FAQ for the current group.
6518 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6519 in."
6520   (interactive
6521    (list
6522     (when current-prefix-arg
6523       (completing-read
6524        "FAQ dir: " (and (listp gnus-group-faq-directory)
6525                         (mapcar (lambda (file) (list file))
6526                                 gnus-group-faq-directory))))))
6527   (let (gnus-faq-buffer)
6528     (when (setq gnus-faq-buffer
6529                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6530       (gnus-configure-windows 'summary-faq))))
6531
6532 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6533 (defun gnus-summary-describe-group (&optional force)
6534   "Describe the current newsgroup."
6535   (interactive "P")
6536   (gnus-group-describe-group force gnus-newsgroup-name))
6537
6538 (defun gnus-summary-describe-briefly ()
6539   "Describe summary mode commands briefly."
6540   (interactive)
6541   (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")))
6542
6543 ;; Walking around group mode buffer from summary mode.
6544
6545 (defun gnus-summary-next-group (&optional no-article target-group backward)
6546   "Exit current newsgroup and then select next unread newsgroup.
6547 If prefix argument NO-ARTICLE is non-nil, no article is selected
6548 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6549 previous group instead."
6550   (interactive "P")
6551   ;; Stop pre-fetching.
6552   (gnus-async-halt-prefetch)
6553   (let ((current-group gnus-newsgroup-name)
6554         (current-buffer (current-buffer))
6555         entered)
6556     (while (not entered)
6557       ;; Then we find what group we are supposed to enter.
6558       (set-buffer gnus-group-buffer)
6559       (gnus-group-jump-to-group current-group)
6560       (setq target-group
6561             (or target-group
6562                 (if (eq gnus-keep-same-level 'best)
6563                     (gnus-summary-best-group gnus-newsgroup-name)
6564                   (gnus-summary-search-group backward gnus-keep-same-level))))
6565       (if (not target-group)
6566           ;; There are no further groups, so we return to the group
6567           ;; buffer.
6568           (progn
6569             (gnus-message 5 "Returning to the group buffer")
6570             (setq entered t)
6571             (when (gnus-buffer-live-p current-buffer)
6572               (set-buffer current-buffer)
6573               (gnus-summary-exit))
6574             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6575         ;; We try to enter the target group.
6576         (gnus-group-jump-to-group target-group)
6577         (let ((unreads (gnus-group-group-unread)))
6578           (if (and (or (eq t unreads)
6579                        (and unreads (not (zerop unreads))))
6580                    (progn
6581                      ;; Now we semi-exit this group to update Xrefs
6582                      ;; and all variables.  We can't do a real exit,
6583                      ;; because the window conf must remain the same
6584                      ;; in case the user is prompted for info, and we
6585                      ;; don't want the window conf to change before
6586                      ;; that...
6587                      (when (gnus-buffer-live-p current-buffer)
6588                        (set-buffer current-buffer)
6589                        (gnus-summary-exit t))
6590                      (gnus-summary-read-group
6591                       target-group nil no-article
6592                       (and (buffer-name current-buffer) current-buffer)
6593                       nil backward)))
6594               (setq entered t)
6595             (setq current-group target-group
6596                   target-group nil)))))))
6597
6598 (defun gnus-summary-prev-group (&optional no-article)
6599   "Exit current newsgroup and then select previous unread newsgroup.
6600 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6601   (interactive "P")
6602   (gnus-summary-next-group no-article nil t))
6603
6604 ;; Walking around summary lines.
6605
6606 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6607   "Go to the first unread subject.
6608 If UNREAD is non-nil, go to the first unread article.
6609 Returns the article selected or nil if there are no unread articles."
6610   (interactive "P")
6611   (prog1
6612       (cond
6613        ;; Empty summary.
6614        ((null gnus-newsgroup-data)
6615         (gnus-message 3 "No articles in the group")
6616         nil)
6617        ;; Pick the first article.
6618        ((not unread)
6619         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6620         (gnus-data-number (car gnus-newsgroup-data)))
6621        ;; No unread articles.
6622        ((null gnus-newsgroup-unreads)
6623         (gnus-message 3 "No more unread articles")
6624         nil)
6625        ;; Find the first unread article.
6626        (t
6627         (let ((data gnus-newsgroup-data))
6628           (while (and data
6629                       (and (not (and undownloaded
6630                                      (eq gnus-undownloaded-mark
6631                                          (gnus-data-mark (car data)))))
6632                            (if unseen
6633                                (or (not (memq
6634                                          (gnus-data-number (car data))
6635                                          gnus-newsgroup-unseen))
6636                                    (not (gnus-data-unread-p (car data))))
6637                              (not (gnus-data-unread-p (car data))))))
6638             (setq data (cdr data)))
6639           (when data
6640             (goto-char (gnus-data-pos (car data)))
6641             (gnus-data-number (car data))))))
6642     (gnus-summary-position-point)))
6643
6644 (defun gnus-summary-next-subject (n &optional unread dont-display)
6645   "Go to next N'th summary line.
6646 If N is negative, go to the previous N'th subject line.
6647 If UNREAD is non-nil, only unread articles are selected.
6648 The difference between N and the actual number of steps taken is
6649 returned."
6650   (interactive "p")
6651   (let ((backward (< n 0))
6652         (n (abs n)))
6653     (while (and (> n 0)
6654                 (if backward
6655                     (gnus-summary-find-prev unread)
6656                   (gnus-summary-find-next unread)))
6657       (unless (zerop (setq n (1- n)))
6658         (gnus-summary-show-thread)))
6659     (when (/= 0 n)
6660       (gnus-message 7 "No more%s articles"
6661                     (if unread " unread" "")))
6662     (unless dont-display
6663       (gnus-summary-recenter)
6664       (gnus-summary-position-point))
6665     n))
6666
6667 (defun gnus-summary-next-unread-subject (n)
6668   "Go to next N'th unread summary line."
6669   (interactive "p")
6670   (gnus-summary-next-subject n t))
6671
6672 (defun gnus-summary-prev-subject (n &optional unread)
6673   "Go to previous N'th summary line.
6674 If optional argument UNREAD is non-nil, only unread article is selected."
6675   (interactive "p")
6676   (gnus-summary-next-subject (- n) unread))
6677
6678 (defun gnus-summary-prev-unread-subject (n)
6679   "Go to previous N'th unread summary line."
6680   (interactive "p")
6681   (gnus-summary-next-subject (- n) t))
6682
6683 (defun gnus-summary-goto-subject (article &optional force silent)
6684   "Go the subject line of ARTICLE.
6685 If FORCE, also allow jumping to articles not currently shown."
6686   (interactive "nArticle number: ")
6687   (unless (numberp article)
6688     (error "Article %s is not a number" article))
6689   (let ((b (point))
6690         (data (gnus-data-find article)))
6691     ;; We read in the article if we have to.
6692     (and (not data)
6693          force
6694          (gnus-summary-insert-subject
6695           article
6696           (if (or (numberp force) (vectorp force)) force)
6697           t)
6698          (setq data (gnus-data-find article)))
6699     (goto-char b)
6700     (if (not data)
6701         (progn
6702           (unless silent
6703             (gnus-message 3 "Can't find article %d" article))
6704           nil)
6705       (let ((pt (gnus-data-pos data)))
6706         (goto-char pt)
6707         (gnus-summary-set-article-display-arrow pt))
6708       (gnus-summary-position-point)
6709       article)))
6710
6711 ;; Walking around summary lines with displaying articles.
6712
6713 (defun gnus-summary-expand-window (&optional arg)
6714   "Make the summary buffer take up the entire Emacs frame.
6715 Given a prefix, will force an `article' buffer configuration."
6716   (interactive "P")
6717   (if arg
6718       (gnus-configure-windows 'article 'force)
6719     (gnus-configure-windows 'summary 'force)))
6720
6721 (defun gnus-summary-display-article (article &optional all-header)
6722   "Display ARTICLE in article buffer."
6723   (when (gnus-buffer-live-p gnus-article-buffer)
6724     (with-current-buffer gnus-article-buffer
6725       (mm-enable-multibyte)))
6726   (gnus-set-global-variables)
6727   (when (gnus-buffer-live-p gnus-article-buffer)
6728     (with-current-buffer gnus-article-buffer
6729       (setq gnus-article-charset gnus-newsgroup-charset)
6730       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6731       (mm-enable-multibyte)))
6732   (if (null article)
6733       nil
6734     (prog1
6735         (if gnus-summary-display-article-function
6736             (funcall gnus-summary-display-article-function article all-header)
6737           (gnus-article-prepare article all-header))
6738       (gnus-run-hooks 'gnus-select-article-hook)
6739       (when (and gnus-current-article
6740                  (not (zerop gnus-current-article)))
6741         (gnus-summary-goto-subject gnus-current-article))
6742       (gnus-summary-recenter)
6743       (when (and gnus-use-trees gnus-show-threads)
6744         (gnus-possibly-generate-tree article)
6745         (gnus-highlight-selected-tree article))
6746       ;; Successfully display article.
6747       (gnus-article-set-window-start
6748        (cdr (assq article gnus-newsgroup-bookmarks))))))
6749
6750 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6751   "Select the current article.
6752 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6753 non-nil, the article will be re-fetched even if it already present in
6754 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6755 be displayed."
6756   ;; Make sure we are in the summary buffer to work around bbdb bug.
6757   (unless (eq major-mode 'gnus-summary-mode)
6758     (set-buffer gnus-summary-buffer))
6759   (let ((article (or article (gnus-summary-article-number)))
6760         (all-headers (not (not all-headers))) ;Must be t or nil.
6761         gnus-summary-display-article-function)
6762     (and (not pseudo)
6763          (gnus-summary-article-pseudo-p article)
6764          (error "This is a pseudo-article"))
6765     (save-excursion
6766       (set-buffer gnus-summary-buffer)
6767       (if (or (and gnus-single-article-buffer
6768                    (or (null gnus-current-article)
6769                        (null gnus-article-current)
6770                        (null (get-buffer gnus-article-buffer))
6771                        (not (eq article (cdr gnus-article-current)))
6772                        (not (equal (car gnus-article-current)
6773                                    gnus-newsgroup-name))))
6774               (and (not gnus-single-article-buffer)
6775                    (or (null gnus-current-article)
6776                        (not (eq gnus-current-article article))))
6777               force)
6778           ;; The requested article is different from the current article.
6779           (progn
6780             (gnus-summary-display-article article all-headers)
6781             (when (gnus-buffer-live-p gnus-article-buffer)
6782               (with-current-buffer gnus-article-buffer
6783                 (if (not gnus-article-decoded-p) ;; a local variable
6784                     (mm-disable-multibyte))))
6785             (gnus-article-set-window-start
6786              (cdr (assq article gnus-newsgroup-bookmarks)))
6787             article)
6788         'old))))
6789
6790 (defun gnus-summary-force-verify-and-decrypt ()
6791   (interactive)
6792   (let ((mm-verify-option 'known)
6793         (mm-decrypt-option 'known)
6794         (gnus-buttonized-mime-types (append (list "multipart/signed"
6795                                                   "multipart/encrypted")
6796                                             gnus-buttonized-mime-types)))
6797     (gnus-summary-select-article nil 'force)))
6798
6799 (defun gnus-summary-set-current-mark (&optional current-mark)
6800   "Obsolete function."
6801   nil)
6802
6803 (defun gnus-summary-next-article (&optional unread subject backward push)
6804   "Select the next article.
6805 If UNREAD, only unread articles are selected.
6806 If SUBJECT, only articles with SUBJECT are selected.
6807 If BACKWARD, the previous article is selected instead of the next."
6808   (interactive "P")
6809   (cond
6810    ;; Is there such an article?
6811    ((and (gnus-summary-search-forward unread subject backward)
6812          (or (gnus-summary-display-article (gnus-summary-article-number))
6813              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6814     (gnus-summary-position-point))
6815    ;; If not, we try the first unread, if that is wanted.
6816    ((and subject
6817          gnus-auto-select-same
6818          (gnus-summary-first-unread-article))
6819     (gnus-summary-position-point)
6820     (gnus-message 6 "Wrapped"))
6821    ;; Try to get next/previous article not displayed in this group.
6822    ((and gnus-auto-extend-newsgroup
6823          (not unread) (not subject))
6824     (gnus-summary-goto-article
6825      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6826      nil (count-lines (point-min) (point))))
6827    ;; Go to next/previous group.
6828    (t
6829     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6830       (gnus-summary-jump-to-group gnus-newsgroup-name))
6831     (let ((cmd last-command-char)
6832           (point
6833            (save-excursion
6834              (set-buffer gnus-group-buffer)
6835              (point)))
6836           (group
6837            (if (eq gnus-keep-same-level 'best)
6838                (gnus-summary-best-group gnus-newsgroup-name)
6839              (gnus-summary-search-group backward gnus-keep-same-level))))
6840       ;; For some reason, the group window gets selected.  We change
6841       ;; it back.
6842       (select-window (get-buffer-window (current-buffer)))
6843       ;; Select next unread newsgroup automagically.
6844       (cond
6845        ((or (not gnus-auto-select-next)
6846             (not cmd))
6847         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6848        ((or (eq gnus-auto-select-next 'quietly)
6849             (and (eq gnus-auto-select-next 'slightly-quietly)
6850                  push)
6851             (and (eq gnus-auto-select-next 'almost-quietly)
6852                  (gnus-summary-last-article-p)))
6853         ;; Select quietly.
6854         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6855             (gnus-summary-exit)
6856           (gnus-message 7 "No more%s articles (%s)..."
6857                         (if unread " unread" "")
6858                         (if group (concat "selecting " group)
6859                           "exiting"))
6860           (gnus-summary-next-group nil group backward)))
6861        (t
6862         (when (gnus-key-press-event-p last-input-event)
6863           (gnus-summary-walk-group-buffer
6864            gnus-newsgroup-name cmd unread backward point))))))))
6865
6866 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6867   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6868                       (?\C-p (gnus-group-prev-unread-group 1))))
6869         (cursor-in-echo-area t)
6870         keve key group ended)
6871     (save-excursion
6872       (set-buffer gnus-group-buffer)
6873       (goto-char start)
6874       (setq group
6875             (if (eq gnus-keep-same-level 'best)
6876                 (gnus-summary-best-group gnus-newsgroup-name)
6877               (gnus-summary-search-group backward gnus-keep-same-level))))
6878     (while (not ended)
6879       (gnus-message
6880        5 "No more%s articles%s" (if unread " unread" "")
6881        (if (and group
6882                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6883            (format " (Type %s for %s [%s])"
6884                    (single-key-description cmd) group
6885                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6886          (format " (Type %s to exit %s)"
6887                  (single-key-description cmd)
6888                  gnus-newsgroup-name)))
6889       ;; Confirm auto selection.
6890       (setq key (car (setq keve (gnus-read-event-char))))
6891       (setq ended t)
6892       (cond
6893        ((assq key keystrokes)
6894         (let ((obuf (current-buffer)))
6895           (switch-to-buffer gnus-group-buffer)
6896           (when group
6897             (gnus-group-jump-to-group group))
6898           (eval (cadr (assq key keystrokes)))
6899           (setq group (gnus-group-group-name))
6900           (switch-to-buffer obuf))
6901         (setq ended nil))
6902        ((equal key cmd)
6903         (if (or (not group)
6904                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6905             (gnus-summary-exit)
6906           (gnus-summary-next-group nil group backward)))
6907        (t
6908         (push (cdr keve) unread-command-events))))))
6909
6910 (defun gnus-summary-next-unread-article ()
6911   "Select unread article after current one."
6912   (interactive)
6913   (gnus-summary-next-article
6914    (or (not (eq gnus-summary-goto-unread 'never))
6915        (gnus-summary-last-article-p (gnus-summary-article-number)))
6916    (and gnus-auto-select-same
6917         (gnus-summary-article-subject))))
6918
6919 (defun gnus-summary-prev-article (&optional unread subject)
6920   "Select the article after the current one.
6921 If UNREAD is non-nil, only unread articles are selected."
6922   (interactive "P")
6923   (gnus-summary-next-article unread subject t))
6924
6925 (defun gnus-summary-prev-unread-article ()
6926   "Select unread article before current one."
6927   (interactive)
6928   (gnus-summary-prev-article
6929    (or (not (eq gnus-summary-goto-unread 'never))
6930        (gnus-summary-first-article-p (gnus-summary-article-number)))
6931    (and gnus-auto-select-same
6932         (gnus-summary-article-subject))))
6933
6934 (defun gnus-summary-next-page (&optional lines circular)
6935   "Show next page of the selected article.
6936 If at the end of the current article, select the next article.
6937 LINES says how many lines should be scrolled up.
6938
6939 If CIRCULAR is non-nil, go to the start of the article instead of
6940 selecting the next article when reaching the end of the current
6941 article."
6942   (interactive "P")
6943   (setq gnus-summary-buffer (current-buffer))
6944   (gnus-set-global-variables)
6945   (let ((article (gnus-summary-article-number))
6946         (article-window (get-buffer-window gnus-article-buffer t))
6947         endp)
6948     ;; If the buffer is empty, we have no article.
6949     (unless article
6950       (error "No article to select"))
6951     (gnus-configure-windows 'article)
6952     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6953         (if (and (eq gnus-summary-goto-unread 'never)
6954                  (not (gnus-summary-last-article-p article)))
6955             (gnus-summary-next-article)
6956           (gnus-summary-next-unread-article))
6957       (if (or (null gnus-current-article)
6958               (null gnus-article-current)
6959               (/= article (cdr gnus-article-current))
6960               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6961           ;; Selected subject is different from current article's.
6962           (gnus-summary-display-article article)
6963         (when article-window
6964           (gnus-eval-in-buffer-window gnus-article-buffer
6965             (setq endp (gnus-article-next-page lines)))
6966           (when endp
6967             (cond (circular
6968                    (gnus-summary-beginning-of-article))
6969                   (lines
6970                    (gnus-message 3 "End of message"))
6971                   ((null lines)
6972                    (if (and (eq gnus-summary-goto-unread 'never)
6973                             (not (gnus-summary-last-article-p article)))
6974                        (gnus-summary-next-article)
6975                      (gnus-summary-next-unread-article))))))))
6976     (gnus-summary-recenter)
6977     (gnus-summary-position-point)))
6978
6979 (defun gnus-summary-prev-page (&optional lines move)
6980   "Show previous page of selected article.
6981 Argument LINES specifies lines to be scrolled down.
6982 If MOVE, move to the previous unread article if point is at
6983 the beginning of the buffer."
6984   (interactive "P")
6985   (let ((article (gnus-summary-article-number))
6986         (article-window (get-buffer-window gnus-article-buffer t))
6987         endp)
6988     (gnus-configure-windows 'article)
6989     (if (or (null gnus-current-article)
6990             (null gnus-article-current)
6991             (/= article (cdr gnus-article-current))
6992             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6993         ;; Selected subject is different from current article's.
6994         (gnus-summary-display-article article)
6995       (gnus-summary-recenter)
6996       (when article-window
6997         (gnus-eval-in-buffer-window gnus-article-buffer
6998           (setq endp (gnus-article-prev-page lines)))
6999         (when (and move endp)
7000           (cond (lines
7001                  (gnus-message 3 "Beginning of message"))
7002                 ((null lines)
7003                  (if (and (eq gnus-summary-goto-unread 'never)
7004                           (not (gnus-summary-first-article-p article)))
7005                      (gnus-summary-prev-article)
7006                    (gnus-summary-prev-unread-article))))))))
7007   (gnus-summary-position-point))
7008
7009 (defun gnus-summary-prev-page-or-article (&optional lines)
7010   "Show previous page of selected article.
7011 Argument LINES specifies lines to be scrolled down.
7012 If at the beginning of the article, go to the next article."
7013   (interactive "P")
7014   (gnus-summary-prev-page lines t))
7015
7016 (defun gnus-summary-scroll-up (lines)
7017   "Scroll up (or down) one line current article.
7018 Argument LINES specifies lines to be scrolled up (or down if negative)."
7019   (interactive "p")
7020   (gnus-configure-windows 'article)
7021   (gnus-summary-show-thread)
7022   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7023     (gnus-eval-in-buffer-window gnus-article-buffer
7024       (cond ((> lines 0)
7025              (when (gnus-article-next-page lines)
7026                (gnus-message 3 "End of message")))
7027             ((< lines 0)
7028              (gnus-article-prev-page (- lines))))))
7029   (gnus-summary-recenter)
7030   (gnus-summary-position-point))
7031
7032 (defun gnus-summary-scroll-down (lines)
7033   "Scroll down (or up) one line current article.
7034 Argument LINES specifies lines to be scrolled down (or up if negative)."
7035   (interactive "p")
7036   (gnus-summary-scroll-up (- lines)))
7037
7038 (defun gnus-summary-next-same-subject ()
7039   "Select next article which has the same subject as current one."
7040   (interactive)
7041   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7042
7043 (defun gnus-summary-prev-same-subject ()
7044   "Select previous article which has the same subject as current one."
7045   (interactive)
7046   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7047
7048 (defun gnus-summary-next-unread-same-subject ()
7049   "Select next unread article which has the same subject as current one."
7050   (interactive)
7051   (gnus-summary-next-article t (gnus-summary-article-subject)))
7052
7053 (defun gnus-summary-prev-unread-same-subject ()
7054   "Select previous unread article which has the same subject as current one."
7055   (interactive)
7056   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7057
7058 (defun gnus-summary-first-unread-article ()
7059   "Select the first unread article.
7060 Return nil if there are no unread articles."
7061   (interactive)
7062   (prog1
7063       (when (gnus-summary-first-subject t)
7064         (gnus-summary-show-thread)
7065         (gnus-summary-first-subject t)
7066         (gnus-summary-display-article (gnus-summary-article-number)))
7067     (gnus-summary-position-point)))
7068
7069 (defun gnus-summary-first-unread-subject ()
7070   "Place the point on the subject line of the first unread article.
7071 Return nil if there are no unread articles."
7072   (interactive)
7073   (prog1
7074       (when (gnus-summary-first-subject t)
7075         (gnus-summary-show-thread)
7076         (gnus-summary-first-subject t))
7077     (gnus-summary-position-point)))
7078
7079 (defun gnus-summary-first-unseen-subject ()
7080   "Place the point on the subject line of the first unseen article.
7081 Return nil if there are no unseen articles."
7082   (interactive)
7083   (prog1
7084       (when (gnus-summary-first-subject t t t)
7085         (gnus-summary-show-thread)
7086         (gnus-summary-first-subject t t t))
7087     (gnus-summary-position-point)))
7088
7089 (defun gnus-summary-first-unseen-or-unread-subject ()
7090   "Place the point on the subject line of the first unseen article.
7091 Return nil if there are no unseen articles."
7092   (interactive)
7093   (prog1
7094       (unless (when (gnus-summary-first-subject t t t)
7095                 (gnus-summary-show-thread)
7096                 (gnus-summary-first-subject t t t))
7097         (when (gnus-summary-first-subject t)
7098           (gnus-summary-show-thread)
7099           (gnus-summary-first-subject t)))
7100     (gnus-summary-position-point)))
7101
7102 (defun gnus-summary-first-article ()
7103   "Select the first article.
7104 Return nil if there are no articles."
7105   (interactive)
7106   (prog1
7107       (when (gnus-summary-first-subject)
7108         (gnus-summary-show-thread)
7109         (gnus-summary-first-subject)
7110         (gnus-summary-display-article (gnus-summary-article-number)))
7111     (gnus-summary-position-point)))
7112
7113 (defun gnus-summary-best-unread-article (&optional arg)
7114   "Select the unread article with the highest score.
7115 If given a prefix argument, select the next unread article that has a
7116 score higher than the default score."
7117   (interactive "P")
7118   (let ((article (if arg
7119                      (gnus-summary-better-unread-subject)
7120                    (gnus-summary-best-unread-subject))))
7121     (if article
7122         (gnus-summary-goto-article article)
7123       (error "No unread articles"))))
7124
7125 (defun gnus-summary-best-unread-subject ()
7126   "Select the unread subject with the highest score."
7127   (interactive)
7128   (let ((best -1000000)
7129         (data gnus-newsgroup-data)
7130         article score)
7131     (while data
7132       (and (gnus-data-unread-p (car data))
7133            (> (setq score
7134                     (gnus-summary-article-score (gnus-data-number (car data))))
7135               best)
7136            (setq best score
7137                  article (gnus-data-number (car data))))
7138       (setq data (cdr data)))
7139     (when article
7140       (gnus-summary-goto-subject article))
7141     (gnus-summary-position-point)
7142     article))
7143
7144 (defun gnus-summary-better-unread-subject ()
7145   "Select the first unread subject that has a score over the default score."
7146   (interactive)
7147   (let ((data gnus-newsgroup-data)
7148         article score)
7149     (while (and (setq article (gnus-data-number (car data)))
7150                 (or (gnus-data-read-p (car data))
7151                     (not (> (gnus-summary-article-score article)
7152                             gnus-summary-default-score))))
7153       (setq data (cdr data)))
7154     (when article
7155       (gnus-summary-goto-subject article))
7156     (gnus-summary-position-point)
7157     article))
7158
7159 (defun gnus-summary-last-subject ()
7160   "Go to the last displayed subject line in the group."
7161   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7162     (when article
7163       (gnus-summary-goto-subject article))))
7164
7165 (defun gnus-summary-goto-article (article &optional all-headers force)
7166   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7167 If ALL-HEADERS is non-nil, no header lines are hidden.
7168 If FORCE, go to the article even if it isn't displayed.  If FORCE
7169 is a number, it is the line the article is to be displayed on."
7170   (interactive
7171    (list
7172     (completing-read
7173      "Article number or Message-ID: "
7174      (mapcar (lambda (number) (list (int-to-string number)))
7175              gnus-newsgroup-limit))
7176     current-prefix-arg
7177     t))
7178   (prog1
7179       (if (and (stringp article)
7180                (string-match "@" article))
7181           (gnus-summary-refer-article article)
7182         (when (stringp article)
7183           (setq article (string-to-number article)))
7184         (if (gnus-summary-goto-subject article force)
7185             (gnus-summary-display-article article all-headers)
7186           (gnus-message 4 "Couldn't go to article %s" article) nil))
7187     (gnus-summary-position-point)))
7188
7189 (defun gnus-summary-goto-last-article ()
7190   "Go to the previously read article."
7191   (interactive)
7192   (prog1
7193       (when gnus-last-article
7194         (gnus-summary-goto-article gnus-last-article nil t))
7195     (gnus-summary-position-point)))
7196
7197 (defun gnus-summary-pop-article (number)
7198   "Pop one article off the history and go to the previous.
7199 NUMBER articles will be popped off."
7200   (interactive "p")
7201   (let (to)
7202     (setq gnus-newsgroup-history
7203           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7204     (if to
7205         (gnus-summary-goto-article (car to) nil t)
7206       (error "Article history empty")))
7207   (gnus-summary-position-point))
7208
7209 ;; Summary commands and functions for limiting the summary buffer.
7210
7211 (defun gnus-summary-limit-to-articles (n)
7212   "Limit the summary buffer to the next N articles.
7213 If not given a prefix, use the process marked articles instead."
7214   (interactive "P")
7215   (prog1
7216       (let ((articles (gnus-summary-work-articles n)))
7217         (setq gnus-newsgroup-processable nil)
7218         (gnus-summary-limit articles))
7219     (gnus-summary-position-point)))
7220
7221 (defun gnus-summary-pop-limit (&optional total)
7222   "Restore the previous limit.
7223 If given a prefix, remove all limits."
7224   (interactive "P")
7225   (when total
7226     (setq gnus-newsgroup-limits
7227           (list (mapcar (lambda (h) (mail-header-number h))
7228                         gnus-newsgroup-headers))))
7229   (unless gnus-newsgroup-limits
7230     (error "No limit to pop"))
7231   (prog1
7232       (gnus-summary-limit nil 'pop)
7233     (gnus-summary-position-point)))
7234
7235 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7236   "Limit the summary buffer to articles that have subjects that match a regexp.
7237 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7238   (interactive
7239    (list (read-string (if current-prefix-arg
7240                           "Exclude subject (regexp): "
7241                         "Limit to subject (regexp): "))
7242          nil current-prefix-arg))
7243   (unless header
7244     (setq header "subject"))
7245   (when (not (equal "" subject))
7246     (prog1
7247         (let ((articles (gnus-summary-find-matching
7248                          (or header "subject") subject 'all nil nil
7249                          not-matching)))
7250           (unless articles
7251             (error "Found no matches for \"%s\"" subject))
7252           (gnus-summary-limit articles))
7253       (gnus-summary-position-point))))
7254
7255 (defun gnus-summary-limit-to-author (from &optional not-matching)
7256   "Limit the summary buffer to articles that have authors that match a regexp.
7257 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7258   (interactive
7259    (list (read-string (if current-prefix-arg
7260                           "Exclude author (regexp): "
7261                         "Limit to author (regexp): "))
7262          current-prefix-arg))
7263   (gnus-summary-limit-to-subject from "from" not-matching))
7264
7265 (defun gnus-summary-limit-to-age (age &optional younger-p)
7266   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7267 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7268 articles that are younger than AGE days."
7269   (interactive
7270    (let ((younger current-prefix-arg)
7271          (days-got nil)
7272          days)
7273      (while (not days-got)
7274        (setq days (if younger
7275                       (read-string "Limit to articles within (in days): ")
7276                     (read-string "Limit to articles older than (in days): ")))
7277        (when (> (length days) 0)
7278          (setq days (read days)))
7279        (if (numberp days)
7280            (progn
7281              (setq days-got t)
7282              (if (< days 0)
7283                  (progn
7284                    (setq younger (not younger))
7285                    (setq days (* days -1)))))
7286          (message "Please enter a number.")
7287          (sleep-for 1)))
7288      (list days younger)))
7289   (prog1
7290       (let ((data gnus-newsgroup-data)
7291             (cutoff (days-to-time age))
7292             articles d date is-younger)
7293         (while (setq d (pop data))
7294           (when (and (vectorp (gnus-data-header d))
7295                      (setq date (mail-header-date (gnus-data-header d))))
7296             (setq is-younger (time-less-p
7297                               (time-since (condition-case ()
7298                                               (date-to-time date)
7299                                             (error '(0 0))))
7300                               cutoff))
7301             (when (if younger-p
7302                       is-younger
7303                     (not is-younger))
7304               (push (gnus-data-number d) articles))))
7305         (gnus-summary-limit (nreverse articles)))
7306     (gnus-summary-position-point)))
7307
7308 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7309   "Limit the summary buffer to articles that match an 'extra' header."
7310   (interactive
7311    (let ((header
7312           (intern
7313            (gnus-completing-read-with-default
7314             (symbol-name (car gnus-extra-headers))
7315             (if current-prefix-arg
7316                 "Exclude extra header:"
7317               "Limit extra header:")
7318             (mapcar (lambda (x)
7319                       (cons (symbol-name x) x))
7320                     gnus-extra-headers)
7321             nil
7322             t))))
7323      (list header
7324            (read-string (format "%s header %s (regexp): "
7325                                 (if current-prefix-arg "Exclude" "Limit to")
7326                                 header))
7327            current-prefix-arg)))
7328   (when (not (equal "" regexp))
7329     (prog1
7330         (let ((articles (gnus-summary-find-matching
7331                          (cons 'extra header) regexp 'all nil nil
7332                          not-matching)))
7333           (unless articles
7334             (error "Found no matches for \"%s\"" regexp))
7335           (gnus-summary-limit articles))
7336       (gnus-summary-position-point))))
7337
7338 (defun gnus-summary-limit-to-display-predicate ()
7339   "Limit the summary buffer to the predicated in the `display' group parameter."
7340   (interactive)
7341   (unless gnus-newsgroup-display
7342     (error "There is no `display' group parameter"))
7343   (let (articles)
7344     (dolist (number gnus-newsgroup-articles)
7345       (when (funcall gnus-newsgroup-display)
7346         (push number articles)))
7347     (gnus-summary-limit articles))
7348   (gnus-summary-position-point))
7349
7350 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7351 (make-obsolete
7352  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7353
7354 (defun gnus-summary-limit-to-unread (&optional all)
7355   "Limit the summary buffer to articles that are not marked as read.
7356 If ALL is non-nil, limit strictly to unread articles."
7357   (interactive "P")
7358   (if all
7359       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7360     (gnus-summary-limit-to-marks
7361      ;; Concat all the marks that say that an article is read and have
7362      ;; those removed.
7363      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7364            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7365            gnus-low-score-mark gnus-expirable-mark
7366            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7367            gnus-duplicate-mark gnus-souped-mark)
7368      'reverse)))
7369
7370 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7371 (make-obsolete 'gnus-summary-delete-marked-with
7372                'gnus-summary-limit-exclude-marks)
7373
7374 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7375   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7376 If REVERSE, limit the summary buffer to articles that are marked
7377 with MARKS.  MARKS can either be a string of marks or a list of marks.
7378 Returns how many articles were removed."
7379   (interactive "sMarks: ")
7380   (gnus-summary-limit-to-marks marks t))
7381
7382 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7383   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7384 If REVERSE (the prefix), limit the summary buffer to articles that are
7385 not marked with MARKS.  MARKS can either be a string of marks or a
7386 list of marks.
7387 Returns how many articles were removed."
7388   (interactive "sMarks: \nP")
7389   (prog1
7390       (let ((data gnus-newsgroup-data)
7391             (marks (if (listp marks) marks
7392                      (append marks nil))) ; Transform to list.
7393             articles)
7394         (while data
7395           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7396                   (memq (gnus-data-mark (car data)) marks))
7397             (push (gnus-data-number (car data)) articles))
7398           (setq data (cdr data)))
7399         (gnus-summary-limit articles))
7400     (gnus-summary-position-point)))
7401
7402 (defun gnus-summary-limit-to-score (score)
7403   "Limit to articles with score at or above SCORE."
7404   (interactive "NLimit to articles with score of at least: ")
7405   (let ((data gnus-newsgroup-data)
7406         articles)
7407     (while data
7408       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7409                 score)
7410         (push (gnus-data-number (car data)) articles))
7411       (setq data (cdr data)))
7412     (prog1
7413         (gnus-summary-limit articles)
7414       (gnus-summary-position-point))))
7415
7416 (defun gnus-summary-limit-to-unseen ()
7417   "Limit to unseen articles."
7418   (interactive)
7419   (prog1
7420       (gnus-summary-limit gnus-newsgroup-unseen)
7421     (gnus-summary-position-point)))
7422
7423 (defun gnus-summary-limit-include-thread (id)
7424   "Display all the hidden articles that is in the thread with ID in it.
7425 When called interactively, ID is the Message-ID of the current
7426 article."
7427   (interactive (list (mail-header-id (gnus-summary-article-header))))
7428   (let ((articles (gnus-articles-in-thread
7429                    (gnus-id-to-thread (gnus-root-id id)))))
7430     (prog1
7431         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7432       (gnus-summary-limit-include-matching-articles
7433        "subject"
7434        (regexp-quote (gnus-simplify-subject-re
7435                       (mail-header-subject (gnus-id-to-header id)))))
7436       (gnus-summary-position-point))))
7437
7438 (defun gnus-summary-limit-include-matching-articles (header regexp)
7439   "Display all the hidden articles that have HEADERs that match REGEXP."
7440   (interactive (list (read-string "Match on header: ")
7441                      (read-string "Regexp: ")))
7442   (let ((articles (gnus-find-matching-articles header regexp)))
7443     (prog1
7444         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7445       (gnus-summary-position-point))))
7446
7447 (defun gnus-summary-limit-include-dormant ()
7448   "Display all the hidden articles that are marked as dormant.
7449 Note that this command only works on a subset of the articles currently
7450 fetched for this group."
7451   (interactive)
7452   (unless gnus-newsgroup-dormant
7453     (error "There are no dormant articles in this group"))
7454   (prog1
7455       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7456     (gnus-summary-position-point)))
7457
7458 (defun gnus-summary-limit-exclude-dormant ()
7459   "Hide all dormant articles."
7460   (interactive)
7461   (prog1
7462       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7463     (gnus-summary-position-point)))
7464
7465 (defun gnus-summary-limit-exclude-childless-dormant ()
7466   "Hide all dormant articles that have no children."
7467   (interactive)
7468   (let ((data (gnus-data-list t))
7469         articles d children)
7470     ;; Find all articles that are either not dormant or have
7471     ;; children.
7472     (while (setq d (pop data))
7473       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7474                 (and (setq children
7475                            (gnus-article-children (gnus-data-number d)))
7476                      (let (found)
7477                        (while children
7478                          (when (memq (car children) articles)
7479                            (setq children nil
7480                                  found t))
7481                          (pop children))
7482                        found)))
7483         (push (gnus-data-number d) articles)))
7484     ;; Do the limiting.
7485     (prog1
7486         (gnus-summary-limit articles)
7487       (gnus-summary-position-point))))
7488
7489 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7490   "Mark all unread excluded articles as read.
7491 If ALL, mark even excluded ticked and dormants as read."
7492   (interactive "P")
7493   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7494   (let ((articles (gnus-sorted-ndifference
7495                    (sort
7496                     (mapcar (lambda (h) (mail-header-number h))
7497                             gnus-newsgroup-headers)
7498                     '<)
7499                    gnus-newsgroup-limit))
7500         article)
7501     (setq gnus-newsgroup-unreads
7502           (gnus-sorted-intersection gnus-newsgroup-unreads
7503                                     gnus-newsgroup-limit))
7504     (if all
7505         (setq gnus-newsgroup-dormant nil
7506               gnus-newsgroup-marked nil
7507               gnus-newsgroup-reads
7508               (nconc
7509                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7510                gnus-newsgroup-reads))
7511       (while (setq article (pop articles))
7512         (unless (or (memq article gnus-newsgroup-dormant)
7513                     (memq article gnus-newsgroup-marked))
7514           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7515
7516 (defun gnus-summary-limit (articles &optional pop)
7517   (if pop
7518       ;; We pop the previous limit off the stack and use that.
7519       (setq articles (car gnus-newsgroup-limits)
7520             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7521     ;; We use the new limit, so we push the old limit on the stack.
7522     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7523   ;; Set the limit.
7524   (setq gnus-newsgroup-limit articles)
7525   (let ((total (length gnus-newsgroup-data))
7526         (data (gnus-data-find-list (gnus-summary-article-number)))
7527         (gnus-summary-mark-below nil)   ; Inhibit this.
7528         found)
7529     ;; This will do all the work of generating the new summary buffer
7530     ;; according to the new limit.
7531     (gnus-summary-prepare)
7532     ;; Hide any threads, possibly.
7533     (gnus-summary-maybe-hide-threads)
7534     ;; Try to return to the article you were at, or one in the
7535     ;; neighborhood.
7536     (when data
7537       ;; We try to find some article after the current one.
7538       (while data
7539         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7540           (setq data nil
7541                 found t))
7542         (setq data (cdr data))))
7543     (unless found
7544       ;; If there is no data, that means that we were after the last
7545       ;; article.  The same goes when we can't find any articles
7546       ;; after the current one.
7547       (goto-char (point-max))
7548       (gnus-summary-find-prev))
7549     (gnus-set-mode-line 'summary)
7550     ;; We return how many articles were removed from the summary
7551     ;; buffer as a result of the new limit.
7552     (- total (length gnus-newsgroup-data))))
7553
7554 (defsubst gnus-invisible-cut-children (threads)
7555   (let ((num 0))
7556     (while threads
7557       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7558         (incf num))
7559       (pop threads))
7560     (< num 2)))
7561
7562 (defsubst gnus-cut-thread (thread)
7563   "Go forwards in the thread until we find an article that we want to display."
7564   (when (or (eq gnus-fetch-old-headers 'some)
7565             (eq gnus-fetch-old-headers 'invisible)
7566             (numberp gnus-fetch-old-headers)
7567             (eq gnus-build-sparse-threads 'some)
7568             (eq gnus-build-sparse-threads 'more))
7569     ;; Deal with old-fetched headers and sparse threads.
7570     (while (and
7571             thread
7572             (or
7573              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7574              (gnus-summary-article-ancient-p
7575               (mail-header-number (car thread))))
7576             (if (or (<= (length (cdr thread)) 1)
7577                     (eq gnus-fetch-old-headers 'invisible))
7578                 (setq gnus-newsgroup-limit
7579                       (delq (mail-header-number (car thread))
7580                             gnus-newsgroup-limit)
7581                       thread (cadr thread))
7582               (when (gnus-invisible-cut-children (cdr thread))
7583                 (let ((th (cdr thread)))
7584                   (while th
7585                     (if (memq (mail-header-number (caar th))
7586                               gnus-newsgroup-limit)
7587                         (setq thread (car th)
7588                               th nil)
7589                       (setq th (cdr th))))))))))
7590   thread)
7591
7592 (defun gnus-cut-threads (threads)
7593   "Cut off all uninteresting articles from the beginning of threads."
7594   (when (or (eq gnus-fetch-old-headers 'some)
7595             (eq gnus-fetch-old-headers 'invisible)
7596             (numberp gnus-fetch-old-headers)
7597             (eq gnus-build-sparse-threads 'some)
7598             (eq gnus-build-sparse-threads 'more))
7599     (let ((th threads))
7600       (while th
7601         (setcar th (gnus-cut-thread (car th)))
7602         (setq th (cdr th)))))
7603   ;; Remove nixed out threads.
7604   (delq nil threads))
7605
7606 (defun gnus-summary-initial-limit (&optional show-if-empty)
7607   "Figure out what the initial limit is supposed to be on group entry.
7608 This entails weeding out unwanted dormants, low-scored articles,
7609 fetch-old-headers verbiage, and so on."
7610   ;; Most groups have nothing to remove.
7611   (if (or gnus-inhibit-limiting
7612           (and (null gnus-newsgroup-dormant)
7613                (eq gnus-newsgroup-display 'gnus-not-ignore)
7614                (not (eq gnus-fetch-old-headers 'some))
7615                (not (numberp gnus-fetch-old-headers))
7616                (not (eq gnus-fetch-old-headers 'invisible))
7617                (null gnus-summary-expunge-below)
7618                (not (eq gnus-build-sparse-threads 'some))
7619                (not (eq gnus-build-sparse-threads 'more))
7620                (null gnus-thread-expunge-below)
7621                (not gnus-use-nocem)))
7622       ()                                ; Do nothing.
7623     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7624     (setq gnus-newsgroup-limit nil)
7625     (mapatoms
7626      (lambda (node)
7627        (unless (car (symbol-value node))
7628          ;; These threads have no parents -- they are roots.
7629          (let ((nodes (cdr (symbol-value node)))
7630                thread)
7631            (while nodes
7632              (if (and gnus-thread-expunge-below
7633                       (< (gnus-thread-total-score (car nodes))
7634                          gnus-thread-expunge-below))
7635                  (gnus-expunge-thread (pop nodes))
7636                (setq thread (pop nodes))
7637                (gnus-summary-limit-children thread))))))
7638      gnus-newsgroup-dependencies)
7639     ;; If this limitation resulted in an empty group, we might
7640     ;; pop the previous limit and use it instead.
7641     (when (and (not gnus-newsgroup-limit)
7642                show-if-empty)
7643       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7644     gnus-newsgroup-limit))
7645
7646 (defun gnus-summary-limit-children (thread)
7647   "Return 1 if this subthread is visible and 0 if it is not."
7648   ;; First we get the number of visible children to this thread.  This
7649   ;; is done by recursing down the thread using this function, so this
7650   ;; will really go down to a leaf article first, before slowly
7651   ;; working its way up towards the root.
7652   (when thread
7653     (let ((children
7654            (if (cdr thread)
7655                (apply '+ (mapcar 'gnus-summary-limit-children
7656                                  (cdr thread)))
7657              0))
7658           (number (mail-header-number (car thread)))
7659           score)
7660       (if (and
7661            (not (memq number gnus-newsgroup-marked))
7662            (or
7663             ;; If this article is dormant and has absolutely no visible
7664             ;; children, then this article isn't visible.
7665             (and (memq number gnus-newsgroup-dormant)
7666                  (zerop children))
7667             ;; If this is "fetch-old-headered" and there is no
7668             ;; visible children, then we don't want this article.
7669             (and (or (eq gnus-fetch-old-headers 'some)
7670                      (numberp gnus-fetch-old-headers))
7671                  (gnus-summary-article-ancient-p number)
7672                  (zerop children))
7673             ;; If this is "fetch-old-headered" and `invisible', then
7674             ;; we don't want this article.
7675             (and (eq gnus-fetch-old-headers 'invisible)
7676                  (gnus-summary-article-ancient-p number))
7677             ;; If this is a sparsely inserted article with no children,
7678             ;; we don't want it.
7679             (and (eq gnus-build-sparse-threads 'some)
7680                  (gnus-summary-article-sparse-p number)
7681                  (zerop children))
7682             ;; If we use expunging, and this article is really
7683             ;; low-scored, then we don't want this article.
7684             (when (and gnus-summary-expunge-below
7685                        (< (setq score
7686                                 (or (cdr (assq number gnus-newsgroup-scored))
7687                                     gnus-summary-default-score))
7688                           gnus-summary-expunge-below))
7689               ;; We increase the expunge-tally here, but that has
7690               ;; nothing to do with the limits, really.
7691               (incf gnus-newsgroup-expunged-tally)
7692               ;; We also mark as read here, if that's wanted.
7693               (when (and gnus-summary-mark-below
7694                          (< score gnus-summary-mark-below))
7695                 (setq gnus-newsgroup-unreads
7696                       (delq number gnus-newsgroup-unreads))
7697                 (if gnus-newsgroup-auto-expire
7698                     (push number gnus-newsgroup-expirable)
7699                   (push (cons number gnus-low-score-mark)
7700                         gnus-newsgroup-reads)))
7701               t)
7702             ;; Do the `display' group parameter.
7703             (and gnus-newsgroup-display
7704                  (not (funcall gnus-newsgroup-display)))
7705             ;; Check NoCeM things.
7706             (if (and gnus-use-nocem
7707                      (gnus-nocem-unwanted-article-p
7708                       (mail-header-id (car thread))))
7709                 (progn
7710                   (setq gnus-newsgroup-unreads
7711                         (delq number gnus-newsgroup-unreads))
7712                   t))))
7713           ;; Nope, invisible article.
7714           0
7715         ;; Ok, this article is to be visible, so we add it to the limit
7716         ;; and return 1.
7717         (push number gnus-newsgroup-limit)
7718         1))))
7719
7720 (defun gnus-expunge-thread (thread)
7721   "Mark all articles in THREAD as read."
7722   (let* ((number (mail-header-number (car thread))))
7723     (incf gnus-newsgroup-expunged-tally)
7724     ;; We also mark as read here, if that's wanted.
7725     (setq gnus-newsgroup-unreads
7726           (delq number gnus-newsgroup-unreads))
7727     (if gnus-newsgroup-auto-expire
7728         (push number gnus-newsgroup-expirable)
7729       (push (cons number gnus-low-score-mark)
7730             gnus-newsgroup-reads)))
7731   ;; Go recursively through all subthreads.
7732   (mapcar 'gnus-expunge-thread (cdr thread)))
7733
7734 ;; Summary article oriented commands
7735
7736 (defun gnus-summary-refer-parent-article (n)
7737   "Refer parent article N times.
7738 If N is negative, go to ancestor -N instead.
7739 The difference between N and the number of articles fetched is returned."
7740   (interactive "p")
7741   (let ((skip 1)
7742         error header ref)
7743     (when (not (natnump n))
7744       (setq skip (abs n)
7745             n 1))
7746     (while (and (> n 0)
7747                 (not error))
7748       (setq header (gnus-summary-article-header))
7749       (if (and (eq (mail-header-number header)
7750                    (cdr gnus-article-current))
7751                (equal gnus-newsgroup-name
7752                       (car gnus-article-current)))
7753           ;; If we try to find the parent of the currently
7754           ;; displayed article, then we take a look at the actual
7755           ;; References header, since this is slightly more
7756           ;; reliable than the References field we got from the
7757           ;; server.
7758           (save-excursion
7759             (set-buffer gnus-original-article-buffer)
7760             (nnheader-narrow-to-headers)
7761             (unless (setq ref (message-fetch-field "references"))
7762               (setq ref (message-fetch-field "in-reply-to")))
7763             (widen))
7764         (setq ref
7765               ;; It's not the current article, so we take a bet on
7766               ;; the value we got from the server.
7767               (mail-header-references header)))
7768       (if (and ref
7769                (not (equal ref "")))
7770           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7771             (gnus-message 1 "Couldn't find parent"))
7772         (gnus-message 1 "No references in article %d"
7773                       (gnus-summary-article-number))
7774         (setq error t))
7775       (decf n))
7776     (gnus-summary-position-point)
7777     n))
7778
7779 (defun gnus-summary-refer-references ()
7780   "Fetch all articles mentioned in the References header.
7781 Return the number of articles fetched."
7782   (interactive)
7783   (let ((ref (mail-header-references (gnus-summary-article-header)))
7784         (current (gnus-summary-article-number))
7785         (n 0))
7786     (if (or (not ref)
7787             (equal ref ""))
7788         (error "No References in the current article")
7789       ;; For each Message-ID in the References header...
7790       (while (string-match "<[^>]*>" ref)
7791         (incf n)
7792         ;; ... fetch that article.
7793         (gnus-summary-refer-article
7794          (prog1 (match-string 0 ref)
7795            (setq ref (substring ref (match-end 0))))))
7796       (gnus-summary-goto-subject current)
7797       (gnus-summary-position-point)
7798       n)))
7799
7800 (defun gnus-summary-refer-thread (&optional limit)
7801   "Fetch all articles in the current thread.
7802 If LIMIT (the numerical prefix), fetch that many old headers instead
7803 of what's specified by the `gnus-refer-thread-limit' variable."
7804   (interactive "P")
7805   (let ((id (mail-header-id (gnus-summary-article-header)))
7806         (limit (if limit (prefix-numeric-value limit)
7807                  gnus-refer-thread-limit)))
7808     ;; We want to fetch LIMIT *old* headers, but we also have to
7809     ;; re-fetch all the headers in the current buffer, because many of
7810     ;; them may be undisplayed.  So we adjust LIMIT.
7811     (when (numberp limit)
7812       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7813     (unless (eq gnus-fetch-old-headers 'invisible)
7814       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7815       ;; Retrieve the headers and read them in.
7816       (if (eq (gnus-retrieve-headers
7817                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7818               'nov)
7819           (gnus-build-all-threads)
7820         (error "Can't fetch thread from backends that don't support NOV"))
7821       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7822     (gnus-summary-limit-include-thread id)))
7823
7824 (defun gnus-summary-refer-article (message-id)
7825   "Fetch an article specified by MESSAGE-ID."
7826   (interactive "sMessage-ID: ")
7827   (when (and (stringp message-id)
7828              (not (zerop (length message-id))))
7829     ;; Construct the correct Message-ID if necessary.
7830     ;; Suggested by tale@pawl.rpi.edu.
7831     (unless (string-match "^<" message-id)
7832       (setq message-id (concat "<" message-id)))
7833     (unless (string-match ">$" message-id)
7834       (setq message-id (concat message-id ">")))
7835     (let* ((header (gnus-id-to-header message-id))
7836            (sparse (and header
7837                         (gnus-summary-article-sparse-p
7838                          (mail-header-number header))
7839                         (memq (mail-header-number header)
7840                               gnus-newsgroup-limit)))
7841            number)
7842       (cond
7843        ;; If the article is present in the buffer we just go to it.
7844        ((and header
7845              (or (not (gnus-summary-article-sparse-p
7846                        (mail-header-number header)))
7847                  sparse))
7848         (prog1
7849             (gnus-summary-goto-article
7850              (mail-header-number header) nil t)
7851           (when sparse
7852             (gnus-summary-update-article (mail-header-number header)))))
7853        (t
7854         ;; We fetch the article.
7855         (catch 'found
7856           (dolist (gnus-override-method (gnus-refer-article-methods))
7857             (gnus-check-server gnus-override-method)
7858             ;; Fetch the header, and display the article.
7859             (when (setq number (gnus-summary-insert-subject message-id))
7860               (gnus-summary-select-article nil nil nil number)
7861               (throw 'found t)))
7862           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7863
7864 (defun gnus-refer-article-methods ()
7865   "Return a list of referable methods."
7866   (cond
7867    ;; No method, so we default to current and native.
7868    ((null gnus-refer-article-method)
7869     (list gnus-current-select-method gnus-select-method))
7870    ;; Current.
7871    ((eq 'current gnus-refer-article-method)
7872     (list gnus-current-select-method))
7873    ;; List of select methods.
7874    ((not (and (symbolp (car gnus-refer-article-method))
7875               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7876     (let (out)
7877       (dolist (method gnus-refer-article-method)
7878         (push (if (eq 'current method)
7879                   gnus-current-select-method
7880                 method)
7881               out))
7882       (nreverse out)))
7883    ;; One single select method.
7884    (t
7885     (list gnus-refer-article-method))))
7886
7887 (defun gnus-summary-edit-parameters ()
7888   "Edit the group parameters of the current group."
7889   (interactive)
7890   (gnus-group-edit-group gnus-newsgroup-name 'params))
7891
7892 (defun gnus-summary-customize-parameters ()
7893   "Customize the group parameters of the current group."
7894   (interactive)
7895   (gnus-group-customize gnus-newsgroup-name))
7896
7897 (defun gnus-summary-enter-digest-group (&optional force)
7898   "Enter an nndoc group based on the current article.
7899 If FORCE, force a digest interpretation.  If not, try
7900 to guess what the document format is."
7901   (interactive "P")
7902   (let ((conf gnus-current-window-configuration))
7903     (save-excursion
7904       (gnus-summary-select-article))
7905     (setq gnus-current-window-configuration conf)
7906     (let* ((name (format "%s-%d"
7907                          (gnus-group-prefixed-name
7908                           gnus-newsgroup-name (list 'nndoc ""))
7909                          (save-excursion
7910                            (set-buffer gnus-summary-buffer)
7911                            gnus-current-article)))
7912            (ogroup gnus-newsgroup-name)
7913            (params (append (gnus-info-params (gnus-get-info ogroup))
7914                            (list (cons 'to-group ogroup))
7915                            (list (cons 'save-article-group ogroup))))
7916            (case-fold-search t)
7917            (buf (current-buffer))
7918            dig to-address)
7919       (save-excursion
7920         (set-buffer gnus-original-article-buffer)
7921         ;; Have the digest group inherit the main mail address of
7922         ;; the parent article.
7923         (when (setq to-address (or (gnus-fetch-field "reply-to")
7924                                    (gnus-fetch-field "from")))
7925           (setq params (append
7926                         (list (cons 'to-address
7927                                     (funcall gnus-decode-encoded-word-function
7928                                              to-address))))))
7929         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7930         (insert-buffer-substring gnus-original-article-buffer)
7931         ;; Remove lines that may lead nndoc to misinterpret the
7932         ;; document type.
7933         (narrow-to-region
7934          (goto-char (point-min))
7935          (or (search-forward "\n\n" nil t) (point)))
7936         (goto-char (point-min))
7937         (delete-matching-lines "^Path:\\|^From ")
7938         (widen))
7939       (unwind-protect
7940           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7941                     (gnus-newsgroup-ephemeral-ignored-charsets
7942                      gnus-newsgroup-ignored-charsets))
7943                 (gnus-group-read-ephemeral-group
7944                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7945                               (nndoc-article-type
7946                                ,(if force 'mbox 'guess)))
7947                  t nil nil nil
7948                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7949                                                         "ADAPT")))))
7950               ;; Make all postings to this group go to the parent group.
7951               (nconc (gnus-info-params (gnus-get-info name))
7952                      params)
7953             ;; Couldn't select this doc group.
7954             (switch-to-buffer buf)
7955             (gnus-set-global-variables)
7956             (gnus-configure-windows 'summary)
7957             (gnus-message 3 "Article couldn't be entered?"))
7958         (kill-buffer dig)))))
7959
7960 (defun gnus-summary-read-document (n)
7961   "Open a new group based on the current article(s).
7962 This will allow you to read digests and other similar
7963 documents as newsgroups.
7964 Obeys the standard process/prefix convention."
7965   (interactive "P")
7966   (let* ((articles (gnus-summary-work-articles n))
7967          (ogroup gnus-newsgroup-name)
7968          (params (append (gnus-info-params (gnus-get-info ogroup))
7969                          (list (cons 'to-group ogroup))))
7970          article group egroup groups vgroup)
7971     (while (setq article (pop articles))
7972       (setq group (format "%s-%d" gnus-newsgroup-name article))
7973       (gnus-summary-remove-process-mark article)
7974       (when (gnus-summary-display-article article)
7975         (save-excursion
7976           (with-temp-buffer
7977             (insert-buffer-substring gnus-original-article-buffer)
7978             ;; Remove some headers that may lead nndoc to make
7979             ;; the wrong guess.
7980             (message-narrow-to-head)
7981             (goto-char (point-min))
7982             (delete-matching-lines "^\\(Path\\):\\|^From ")
7983             (widen)
7984             (if (setq egroup
7985                       (gnus-group-read-ephemeral-group
7986                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7987                                      (nndoc-article-type guess))
7988                        t nil t))
7989                 (progn
7990             ;; Make all postings to this group go to the parent group.
7991                   (nconc (gnus-info-params (gnus-get-info egroup))
7992                          params)
7993                   (push egroup groups))
7994               ;; Couldn't select this doc group.
7995               (gnus-error 3 "Article couldn't be entered"))))))
7996     ;; Now we have selected all the documents.
7997     (cond
7998      ((not groups)
7999       (error "None of the articles could be interpreted as documents"))
8000      ((gnus-group-read-ephemeral-group
8001        (setq vgroup (format
8002                      "nnvirtual:%s-%s" gnus-newsgroup-name
8003                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8004        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8005        t
8006        (cons (current-buffer) 'summary)))
8007      (t
8008       (error "Couldn't select virtual nndoc group")))))
8009
8010 (defun gnus-summary-isearch-article (&optional regexp-p)
8011   "Do incremental search forward on the current article.
8012 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8013   (interactive "P")
8014   (gnus-summary-select-article)
8015   (gnus-configure-windows 'article)
8016   (gnus-eval-in-buffer-window gnus-article-buffer
8017     (save-restriction
8018       (widen)
8019       (isearch-forward regexp-p))))
8020
8021 (defun gnus-summary-search-article-forward (regexp &optional backward)
8022   "Search for an article containing REGEXP forward.
8023 If BACKWARD, search backward instead."
8024   (interactive
8025    (list (read-string
8026           (format "Search article %s (regexp%s): "
8027                   (if current-prefix-arg "backward" "forward")
8028                   (if gnus-last-search-regexp
8029                       (concat ", default " gnus-last-search-regexp)
8030                     "")))
8031          current-prefix-arg))
8032   (if (string-equal regexp "")
8033       (setq regexp (or gnus-last-search-regexp ""))
8034     (setq gnus-last-search-regexp regexp)
8035     (setq gnus-article-before-search gnus-current-article))
8036   ;; Intentionally set gnus-last-article.
8037   (setq gnus-last-article gnus-article-before-search)
8038   (let ((gnus-last-article gnus-last-article))
8039     (if (gnus-summary-search-article regexp backward)
8040         (gnus-summary-show-thread)
8041       (error "Search failed: \"%s\"" regexp))))
8042
8043 (defun gnus-summary-search-article-backward (regexp)
8044   "Search for an article containing REGEXP backward."
8045   (interactive
8046    (list (read-string
8047           (format "Search article backward (regexp%s): "
8048                   (if gnus-last-search-regexp
8049                       (concat ", default " gnus-last-search-regexp)
8050                     "")))))
8051   (gnus-summary-search-article-forward regexp 'backward))
8052
8053 (defun gnus-summary-search-article (regexp &optional backward)
8054   "Search for an article containing REGEXP.
8055 Optional argument BACKWARD means do search for backward.
8056 `gnus-select-article-hook' is not called during the search."
8057   ;; We have to require this here to make sure that the following
8058   ;; dynamic binding isn't shadowed by autoloading.
8059   (require 'gnus-async)
8060   (require 'gnus-art)
8061   (let ((gnus-select-article-hook nil)  ;Disable hook.
8062         (gnus-article-prepare-hook nil)
8063         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8064         (gnus-use-article-prefetch nil)
8065         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8066         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8067         (sum (current-buffer))
8068         (gnus-display-mime-function nil)
8069         (found nil)
8070         point)
8071     (gnus-save-hidden-threads
8072       (gnus-summary-select-article)
8073       (set-buffer gnus-article-buffer)
8074       (goto-char (window-point (get-buffer-window (current-buffer))))
8075       (when backward
8076         (forward-line -1))
8077       (while (not found)
8078         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8079         (if (if backward
8080                 (re-search-backward regexp nil t)
8081               (re-search-forward regexp nil t))
8082             ;; We found the regexp.
8083             (progn
8084               (setq found 'found)
8085               (beginning-of-line)
8086               (set-window-start
8087                (get-buffer-window (current-buffer))
8088                (point))
8089               (forward-line 1)
8090               (set-window-point
8091                (get-buffer-window (current-buffer))
8092                (point))
8093               (set-buffer sum)
8094               (setq point (point)))
8095           ;; We didn't find it, so we go to the next article.
8096           (set-buffer sum)
8097           (setq found 'not)
8098           (while (eq found 'not)
8099             (if (not (if backward (gnus-summary-find-prev)
8100                        (gnus-summary-find-next)))
8101                 ;; No more articles.
8102                 (setq found t)
8103               ;; Select the next article and adjust point.
8104               (unless (gnus-summary-article-sparse-p
8105                        (gnus-summary-article-number))
8106                 (setq found nil)
8107                 (gnus-summary-select-article)
8108                 (set-buffer gnus-article-buffer)
8109                 (widen)
8110                 (goto-char (if backward (point-max) (point-min))))))))
8111       (gnus-message 7 ""))
8112     ;; Return whether we found the regexp.
8113     (when (eq found 'found)
8114       (goto-char point)
8115       (gnus-summary-show-thread)
8116       (gnus-summary-goto-subject gnus-current-article)
8117       (gnus-summary-position-point)
8118       t)))
8119
8120 (defun gnus-find-matching-articles (header regexp)
8121   "Return a list of all articles that match REGEXP on HEADER.
8122 This search includes all articles in the current group that Gnus has
8123 fetched headers for, whether they are displayed or not."
8124   (let ((articles nil)
8125         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8126         (case-fold-search t))
8127     (dolist (header gnus-newsgroup-headers)
8128       (when (string-match regexp (funcall func header))
8129         (push (mail-header-number header) articles)))
8130     (nreverse articles)))
8131
8132 (defun gnus-summary-find-matching (header regexp &optional backward unread
8133                                           not-case-fold not-matching)
8134   "Return a list of all articles that match REGEXP on HEADER.
8135 The search stars on the current article and goes forwards unless
8136 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8137 If UNREAD is non-nil, only unread articles will
8138 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8139 in the comparisons. If NOT-MATCHING, return a list of all articles that
8140 not match REGEXP on HEADER."
8141   (let ((case-fold-search (not not-case-fold))
8142         articles d func)
8143     (if (consp header)
8144         (if (eq (car header) 'extra)
8145             (setq func
8146                   `(lambda (h)
8147                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8148                          "")))
8149           (error "%s is an invalid header" header))
8150       (unless (fboundp (intern (concat "mail-header-" header)))
8151         (error "%s is not a valid header" header))
8152       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8153     (dolist (d (if (eq backward 'all)
8154                    gnus-newsgroup-data
8155                  (gnus-data-find-list
8156                   (gnus-summary-article-number)
8157                   (gnus-data-list backward))))
8158       (when (and (or (not unread)       ; We want all articles...
8159                      (gnus-data-unread-p d)) ; Or just unreads.
8160                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8161                  (if not-matching
8162                      (not (string-match
8163                            regexp
8164                            (funcall func (gnus-data-header d))))
8165                    (string-match regexp
8166                                  (funcall func (gnus-data-header d)))))
8167         (push (gnus-data-number d) articles))) ; Success!
8168     (nreverse articles)))
8169
8170 (defun gnus-summary-execute-command (header regexp command &optional backward)
8171   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8172 If HEADER is an empty string (or nil), the match is done on the entire
8173 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8174   (interactive
8175    (list (let ((completion-ignore-case t))
8176            (completing-read
8177             "Header name: "
8178             (mapcar (lambda (header) (list (format "%s" header)))
8179                     (append
8180                      '("Number" "Subject" "From" "Lines" "Date"
8181                        "Message-ID" "Xref" "References" "Body")
8182                      gnus-extra-headers))
8183             nil 'require-match))
8184          (read-string "Regexp: ")
8185          (read-key-sequence "Command: ")
8186          current-prefix-arg))
8187   (when (equal header "Body")
8188     (setq header ""))
8189   ;; Hidden thread subtrees must be searched as well.
8190   (gnus-summary-show-all-threads)
8191   ;; We don't want to change current point nor window configuration.
8192   (save-excursion
8193     (save-window-excursion
8194       (let (gnus-visual
8195             gnus-treat-strip-trailing-blank-lines
8196             gnus-treat-strip-leading-blank-lines
8197             gnus-treat-strip-multiple-blank-lines
8198             gnus-treat-hide-boring-headers
8199             gnus-treat-fold-newsgroups
8200             gnus-article-prepare-hook)
8201         (gnus-message 6 "Executing %s..." (key-description command))
8202         ;; We'd like to execute COMMAND interactively so as to give arguments.
8203         (gnus-execute header regexp
8204                       `(call-interactively ',(key-binding command))
8205                       backward)
8206         (gnus-message 6 "Executing %s...done" (key-description command))))))
8207
8208 (defun gnus-summary-beginning-of-article ()
8209   "Scroll the article back to the beginning."
8210   (interactive)
8211   (gnus-summary-select-article)
8212   (gnus-configure-windows 'article)
8213   (gnus-eval-in-buffer-window gnus-article-buffer
8214     (widen)
8215     (goto-char (point-min))
8216     (when gnus-page-broken
8217       (gnus-narrow-to-page))))
8218
8219 (defun gnus-summary-end-of-article ()
8220   "Scroll to the end of the article."
8221   (interactive)
8222   (gnus-summary-select-article)
8223   (gnus-configure-windows 'article)
8224   (gnus-eval-in-buffer-window gnus-article-buffer
8225     (widen)
8226     (goto-char (point-max))
8227     (recenter -3)
8228     (when gnus-page-broken
8229       (gnus-narrow-to-page))))
8230
8231 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8232   "Truncate to LEN and quote all \"(\"'s in STRING."
8233   (gnus-replace-in-string (if (and len (> (length string) len))
8234                               (substring string 0 len)
8235                             string)
8236                           "[()]" "\\\\\\&"))
8237
8238 (defun gnus-summary-print-article (&optional filename n)
8239   "Generate and print a PostScript image of the N next (mail) articles.
8240
8241 If N is negative, print the N previous articles.  If N is nil and articles
8242 have been marked with the process mark, print these instead.
8243
8244 If the optional first argument FILENAME is nil, send the image to the
8245 printer.  If FILENAME is a string, save the PostScript image in a file with
8246 that name.  If FILENAME is a number, prompt the user for the name of the file
8247 to save in."
8248   (interactive (list (ps-print-preprint current-prefix-arg)))
8249   (dolist (article (gnus-summary-work-articles n))
8250     (gnus-summary-select-article nil nil 'pseudo article)
8251     (gnus-eval-in-buffer-window gnus-article-buffer
8252       (gnus-print-buffer))
8253     (gnus-summary-remove-process-mark article))
8254   (ps-despool filename))
8255
8256 (defun gnus-print-buffer ()
8257   (let ((buffer (generate-new-buffer " *print*")))
8258     (unwind-protect
8259         (progn
8260           (copy-to-buffer buffer (point-min) (point-max))
8261           (set-buffer buffer)
8262           (gnus-article-delete-invisible-text)
8263           (gnus-remove-text-with-property 'gnus-decoration)
8264           (when (gnus-visual-p 'article-highlight 'highlight)
8265             ;; Copy-to-buffer doesn't copy overlay.  So redo
8266             ;; highlight.
8267             (let ((gnus-article-buffer buffer))
8268               (gnus-article-highlight-citation t)
8269               (gnus-article-highlight-signature)))
8270           (let ((ps-left-header
8271                  (list
8272                   (concat "("
8273                           (gnus-summary-print-truncate-and-quote
8274                            (mail-header-subject gnus-current-headers)
8275                            66) ")")
8276                   (concat "("
8277                           (gnus-summary-print-truncate-and-quote
8278                            (mail-header-from gnus-current-headers)
8279                            45) ")")))
8280                 (ps-right-header
8281                  (list
8282                   "/pagenumberstring load"
8283                   (concat "("
8284                           (mail-header-date gnus-current-headers) ")"))))
8285             (gnus-run-hooks 'gnus-ps-print-hook)
8286             (save-excursion
8287               (if window-system
8288                   (ps-spool-buffer-with-faces)
8289                 (ps-spool-buffer)))))
8290       (kill-buffer buffer))))
8291
8292 (defun gnus-summary-show-article (&optional arg)
8293   "Force redisplaying of the current article.
8294 If ARG (the prefix) is a number, show the article with the charset
8295 defined in `gnus-summary-show-article-charset-alist', or the charset
8296 input.
8297 If ARG (the prefix) is non-nil and not a number, show the raw article
8298 without any article massaging functions being run.  Normally, the key strokes
8299 are `C-u g'."
8300   (interactive "P")
8301   (cond
8302    ((numberp arg)
8303     (gnus-summary-show-article t)
8304     (let ((gnus-newsgroup-charset
8305            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8306                (mm-read-coding-system
8307                 "View as charset: " ;; actually it is coding system.
8308                 (save-excursion
8309                   (set-buffer gnus-article-buffer)
8310                   (mm-detect-coding-region (point) (point-max))))))
8311           (gnus-newsgroup-ignored-charsets 'gnus-all))
8312       (gnus-summary-select-article nil 'force)
8313       (let ((deps gnus-newsgroup-dependencies)
8314             head header lines)
8315         (save-excursion
8316           (set-buffer gnus-original-article-buffer)
8317           (save-restriction
8318             (message-narrow-to-head)
8319             (setq head (buffer-string))
8320             (goto-char (point-min))
8321             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8322               (goto-char (point-max))
8323               (widen)
8324               (setq lines (1- (count-lines (point) (point-max))))))
8325           (with-temp-buffer
8326             (insert (format "211 %d Article retrieved.\n"
8327                             (cdr gnus-article-current)))
8328             (insert head)
8329             (if lines (insert (format "Lines: %d\n" lines)))
8330             (insert ".\n")
8331             (let ((nntp-server-buffer (current-buffer)))
8332               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8333         (gnus-data-set-header
8334          (gnus-data-find (cdr gnus-article-current))
8335          header)
8336         (gnus-summary-update-article-line
8337          (cdr gnus-article-current) header)
8338         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8339           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8340    ((not arg)
8341     ;; Select the article the normal way.
8342     (gnus-summary-select-article nil 'force))
8343    (t
8344     ;; We have to require this here to make sure that the following
8345     ;; dynamic binding isn't shadowed by autoloading.
8346     (require 'gnus-async)
8347     (require 'gnus-art)
8348     ;; Bind the article treatment functions to nil.
8349     (let ((gnus-have-all-headers t)
8350           gnus-article-prepare-hook
8351           gnus-article-decode-hook
8352           gnus-display-mime-function
8353           gnus-break-pages)
8354       ;; Destroy any MIME parts.
8355       (when (gnus-buffer-live-p gnus-article-buffer)
8356         (save-excursion
8357           (set-buffer gnus-article-buffer)
8358           (mm-destroy-parts gnus-article-mime-handles)
8359           ;; Set it to nil for safety reason.
8360           (setq gnus-article-mime-handle-alist nil)
8361           (setq gnus-article-mime-handles nil)))
8362       (gnus-summary-select-article nil 'force))))
8363   (gnus-summary-goto-subject gnus-current-article)
8364   (gnus-summary-position-point))
8365
8366 (defun gnus-summary-show-raw-article ()
8367   "Show the raw article without any article massaging functions being run."
8368   (interactive)
8369   (gnus-summary-show-article t))
8370
8371 (defun gnus-summary-verbose-headers (&optional arg)
8372   "Toggle permanent full header display.
8373 If ARG is a positive number, turn header display on.
8374 If ARG is a negative number, turn header display off."
8375   (interactive "P")
8376   (setq gnus-show-all-headers
8377         (cond ((or (not (numberp arg))
8378                    (zerop arg))
8379                (not gnus-show-all-headers))
8380               ((natnump arg)
8381                t)))
8382   (gnus-summary-show-article))
8383
8384 (defun gnus-summary-toggle-header (&optional arg)
8385   "Show the headers if they are hidden, or hide them if they are shown.
8386 If ARG is a positive number, show the entire header.
8387 If ARG is a negative number, hide the unwanted header lines."
8388   (interactive "P")
8389   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8390                      (get-buffer-window gnus-article-buffer t))))
8391     (with-current-buffer gnus-article-buffer
8392       (widen)
8393       (article-narrow-to-head)
8394       (let* ((buffer-read-only nil)
8395              (inhibit-point-motion-hooks t)
8396              (hidden (if (numberp arg)
8397                          (>= arg 0)
8398                        (gnus-article-hidden-text-p 'headers)))
8399              s e)
8400         (delete-region (point-min) (point-max))
8401         (with-current-buffer gnus-original-article-buffer
8402           (goto-char (setq s (point-min)))
8403           (setq e (if (search-forward "\n\n" nil t)
8404                       (1- (point))
8405                     (point-max))))
8406         (insert-buffer-substring gnus-original-article-buffer s e)
8407         (article-decode-encoded-words)
8408         (if hidden
8409             (let ((gnus-treat-hide-headers nil)
8410                   (gnus-treat-hide-boring-headers nil))
8411               (gnus-delete-wash-type 'headers)
8412               (gnus-treat-article 'head))
8413           (gnus-treat-article 'head))
8414         (widen)
8415         (if window
8416             (set-window-start window (goto-char (point-min))))
8417         (setq gnus-page-broken
8418               (when gnus-break-pages
8419                 (gnus-narrow-to-page)
8420                 t))
8421         (gnus-set-mode-line 'article)))))
8422
8423 (defun gnus-summary-show-all-headers ()
8424   "Make all header lines visible."
8425   (interactive)
8426   (gnus-summary-toggle-header 1))
8427
8428 (defun gnus-summary-caesar-message (&optional arg)
8429   "Caesar rotate the current article by 13.
8430 The numerical prefix specifies how many places to rotate each letter
8431 forward."
8432   (interactive "P")
8433   (gnus-summary-select-article)
8434   (let ((mail-header-separator ""))
8435     (gnus-eval-in-buffer-window gnus-article-buffer
8436       (save-restriction
8437         (widen)
8438         (let ((start (window-start))
8439               buffer-read-only)
8440           (message-caesar-buffer-body arg)
8441           (set-window-start (get-buffer-window (current-buffer)) start))))))
8442
8443 (autoload 'unmorse-region "morse"
8444   "Convert morse coded text in region to ordinary ASCII text."
8445   t)
8446
8447 (defun gnus-summary-morse-message (&optional arg)
8448   "Morse decode the current article."
8449   (interactive "P")
8450   (gnus-summary-select-article)
8451   (let ((mail-header-separator ""))
8452     (gnus-eval-in-buffer-window gnus-article-buffer
8453       (save-excursion
8454         (save-restriction
8455           (widen)
8456           (let ((pos (window-start))
8457                 buffer-read-only)
8458             (goto-char (point-min))
8459             (when (message-goto-body)
8460               (gnus-narrow-to-body))
8461             (goto-char (point-min))
8462             (while (re-search-forward "·" (point-max) t)
8463               (replace-match "."))
8464             (unmorse-region (point-min) (point-max))
8465             (widen)
8466             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8467
8468 (defun gnus-summary-stop-page-breaking ()
8469   "Stop page breaking in the current article."
8470   (interactive)
8471   (gnus-summary-select-article)
8472   (gnus-eval-in-buffer-window gnus-article-buffer
8473     (widen)
8474     (when (gnus-visual-p 'page-marker)
8475       (let ((buffer-read-only nil))
8476         (gnus-remove-text-with-property 'gnus-prev)
8477         (gnus-remove-text-with-property 'gnus-next))
8478       (setq gnus-page-broken nil))))
8479
8480 (defun gnus-summary-move-article (&optional n to-newsgroup
8481                                             select-method action)
8482   "Move the current article to a different newsgroup.
8483 If N is a positive number, move the N next articles.
8484 If N is a negative number, move the N previous articles.
8485 If N is nil and any articles have been marked with the process mark,
8486 move those articles instead.
8487 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8488 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8489 re-spool using this method.
8490
8491 When called interactively with TO-NEWSGROUP being nil, the value of
8492 the variable `gnus-move-split-methods' is used for finding a default
8493 for the target newsgroup.
8494
8495 For this function to work, both the current newsgroup and the
8496 newsgroup that you want to move to have to support the `request-move'
8497 and `request-accept' functions.
8498
8499 ACTION can be either `move' (the default), `crosspost' or `copy'."
8500   (interactive "P")
8501   (unless action
8502     (setq action 'move))
8503   ;; Check whether the source group supports the required functions.
8504   (cond ((and (eq action 'move)
8505               (not (gnus-check-backend-function
8506                     'request-move-article gnus-newsgroup-name)))
8507          (error "The current group does not support article moving"))
8508         ((and (eq action 'crosspost)
8509               (not (gnus-check-backend-function
8510                     'request-replace-article gnus-newsgroup-name)))
8511          (error "The current group does not support article editing")))
8512   (let ((articles (gnus-summary-work-articles n))
8513         (prefix (if (gnus-check-backend-function
8514                      'request-move-article gnus-newsgroup-name)
8515                     (gnus-group-real-prefix gnus-newsgroup-name)
8516                   ""))
8517         (names '((move "Move" "Moving")
8518                  (copy "Copy" "Copying")
8519                  (crosspost "Crosspost" "Crossposting")))
8520         (copy-buf (save-excursion
8521                     (nnheader-set-temp-buffer " *copy article*")))
8522         art-group to-method new-xref article to-groups)
8523     (unless (assq action names)
8524       (error "Unknown action %s" action))
8525     ;; Read the newsgroup name.
8526     (when (and (not to-newsgroup)
8527                (not select-method))
8528       (if (and gnus-move-split-methods
8529                (not
8530                 (and (memq gnus-current-article articles)
8531                      (gnus-buffer-live-p gnus-original-article-buffer))))
8532           ;; When `gnus-move-split-methods' is non-nil, we have to
8533           ;; select an article to give `gnus-read-move-group-name' an
8534           ;; opportunity to suggest an appropriate default.  However,
8535           ;; we needn't render or mark the article.
8536           (let ((gnus-display-mime-function nil)
8537                 (gnus-article-prepare-hook nil)
8538                 (gnus-mark-article-hook nil))
8539             (gnus-summary-select-article nil nil nil (car articles))))
8540       (setq to-newsgroup
8541             (gnus-read-move-group-name
8542              (cadr (assq action names))
8543              (symbol-value (intern (format "gnus-current-%s-group" action)))
8544              articles prefix))
8545       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8546     (setq to-method (or select-method
8547                         (gnus-server-to-method
8548                          (gnus-group-method to-newsgroup))))
8549     ;; Check the method we are to move this article to...
8550     (unless (gnus-check-backend-function
8551              'request-accept-article (car to-method))
8552       (error "%s does not support article copying" (car to-method)))
8553     (unless (gnus-check-server to-method)
8554       (error "Can't open server %s" (car to-method)))
8555     (gnus-message 6 "%s to %s: %s..."
8556                   (caddr (assq action names))
8557                   (or (car select-method) to-newsgroup) articles)
8558     (while articles
8559       (setq article (pop articles))
8560       (setq
8561        art-group
8562        (cond
8563         ;; Move the article.
8564         ((eq action 'move)
8565          ;; Remove this article from future suppression.
8566          (gnus-dup-unsuppress-article article)
8567          (gnus-request-move-article
8568           article                       ; Article to move
8569           gnus-newsgroup-name           ; From newsgroup
8570           (nth 1 (gnus-find-method-for-group
8571                   gnus-newsgroup-name)) ; Server
8572           (list 'gnus-request-accept-article
8573                 to-newsgroup (list 'quote select-method)
8574                 (not articles) t)       ; Accept form
8575           (not articles)))              ; Only save nov last time
8576         ;; Copy the article.
8577         ((eq action 'copy)
8578          (save-excursion
8579            (set-buffer copy-buf)
8580            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8581              (gnus-request-accept-article
8582               to-newsgroup select-method (not articles) t))))
8583         ;; Crosspost the article.
8584         ((eq action 'crosspost)
8585          (let ((xref (message-tokenize-header
8586                       (mail-header-xref (gnus-summary-article-header article))
8587                       " ")))
8588            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8589                                   ":" (number-to-string article)))
8590            (unless xref
8591              (setq xref (list (system-name))))
8592            (setq new-xref
8593                  (concat
8594                   (mapconcat 'identity
8595                              (delete "Xref:" (delete new-xref xref))
8596                              " ")
8597                   " " new-xref))
8598            (save-excursion
8599              (set-buffer copy-buf)
8600              ;; First put the article in the destination group.
8601              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8602              (when (consp (setq art-group
8603                                 (gnus-request-accept-article
8604                                  to-newsgroup select-method (not articles))))
8605                (setq new-xref (concat new-xref " " (car art-group)
8606                                       ":"
8607                                       (number-to-string (cdr art-group))))
8608                ;; Now we have the new Xrefs header, so we insert
8609                ;; it and replace the new article.
8610                (nnheader-replace-header "Xref" new-xref)
8611                (gnus-request-replace-article
8612                 (cdr art-group) to-newsgroup (current-buffer))
8613                art-group))))))
8614       (cond
8615        ((not art-group)
8616         (gnus-message 1 "Couldn't %s article %s: %s"
8617                       (cadr (assq action names)) article
8618                       (nnheader-get-report (car to-method))))
8619        ((eq art-group 'junk)
8620         (when (eq action 'move)
8621           (gnus-summary-mark-article article gnus-canceled-mark)
8622           (gnus-message 4 "Deleted article %s" article)))
8623        (t
8624         (let* ((pto-group (gnus-group-prefixed-name
8625                            (car art-group) to-method))
8626                (entry
8627                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8628                (info (nth 2 entry))
8629                (to-group (gnus-info-group info))
8630                to-marks)
8631           ;; Update the group that has been moved to.
8632           (when (and info
8633                      (memq action '(move copy)))
8634             (unless (member to-group to-groups)
8635               (push to-group to-groups))
8636
8637             (unless (memq article gnus-newsgroup-unreads)
8638               (push 'read to-marks)
8639               (gnus-info-set-read
8640                info (gnus-add-to-range (gnus-info-read info)
8641                                        (list (cdr art-group)))))
8642
8643             ;; See whether the article is to be put in the cache.
8644             (let ((marks gnus-article-mark-lists)
8645                   (to-article (cdr art-group)))
8646
8647               ;; Enter the article into the cache in the new group,
8648               ;; if that is required.
8649               (when gnus-use-cache
8650                 (gnus-cache-possibly-enter-article
8651                  to-group to-article
8652                  (memq article gnus-newsgroup-marked)
8653                  (memq article gnus-newsgroup-dormant)
8654                  (memq article gnus-newsgroup-unreads)))
8655
8656               (when gnus-preserve-marks
8657                 ;; Copy any marks over to the new group.
8658                 (when (and (equal to-group gnus-newsgroup-name)
8659                            (not (memq article gnus-newsgroup-unreads)))
8660                   ;; Mark this article as read in this group.
8661                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8662                   (setcdr (gnus-active to-group) to-article)
8663                   (setcdr gnus-newsgroup-active to-article))
8664
8665                 (while marks
8666                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8667                     (when (memq article (symbol-value
8668                                          (intern (format "gnus-newsgroup-%s"
8669                                                          (caar marks)))))
8670                       (push (cdar marks) to-marks)
8671                       ;; If the other group is the same as this group,
8672                       ;; then we have to add the mark to the list.
8673                       (when (equal to-group gnus-newsgroup-name)
8674                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8675                              (cons to-article
8676                                    (symbol-value
8677                                     (intern (format "gnus-newsgroup-%s"
8678                                                     (caar marks)))))))
8679                       ;; Copy the marks to other group.
8680                       (gnus-add-marked-articles
8681                        to-group (cdar marks) (list to-article) info)))
8682                   (setq marks (cdr marks)))
8683
8684                 (gnus-request-set-mark to-group (list (list (list to-article)
8685                                                             'add
8686                                                             to-marks))))
8687
8688               (gnus-dribble-enter
8689                (concat "(gnus-group-set-info '"
8690                        (gnus-prin1-to-string (gnus-get-info to-group))
8691                        ")"))))
8692
8693           ;; Update the Xref header in this article to point to
8694           ;; the new crossposted article we have just created.
8695           (when (eq action 'crosspost)
8696             (save-excursion
8697               (set-buffer copy-buf)
8698               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8699               (nnheader-replace-header "Xref" new-xref)
8700               (gnus-request-replace-article
8701                article gnus-newsgroup-name (current-buffer)))))
8702
8703         ;;;!!!Why is this necessary?
8704         (set-buffer gnus-summary-buffer)
8705
8706         (gnus-summary-goto-subject article)
8707         (when (eq action 'move)
8708           (gnus-summary-mark-article article gnus-canceled-mark))))
8709       (gnus-summary-remove-process-mark article))
8710     ;; Re-activate all groups that have been moved to.
8711     (save-excursion
8712       (set-buffer gnus-group-buffer)
8713       (let ((gnus-group-marked to-groups))
8714         (gnus-group-get-new-news-this-group nil t)))
8715
8716     (gnus-kill-buffer copy-buf)
8717     (gnus-summary-position-point)
8718     (gnus-set-mode-line 'summary)))
8719
8720 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8721   "Move the current article to a different newsgroup.
8722 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8723 When called interactively, if TO-NEWSGROUP is nil, use the value of
8724 the variable `gnus-move-split-methods' for finding a default target
8725 newsgroup.
8726 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8727 re-spool using this method."
8728   (interactive "P")
8729   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8730
8731 (defun gnus-summary-crosspost-article (&optional n)
8732   "Crosspost the current article to some other group."
8733   (interactive "P")
8734   (gnus-summary-move-article n nil nil 'crosspost))
8735
8736 (defcustom gnus-summary-respool-default-method nil
8737   "Default method type for respooling an article.
8738 If nil, use to the current newsgroup method."
8739   :type 'symbol
8740   :group 'gnus-summary-mail)
8741
8742 (defun gnus-summary-respool-article (&optional n method)
8743   "Respool the current article.
8744 The article will be squeezed through the mail spooling process again,
8745 which means that it will be put in some mail newsgroup or other
8746 depending on `nnmail-split-methods'.
8747 If N is a positive number, respool the N next articles.
8748 If N is a negative number, respool the N previous articles.
8749 If N is nil and any articles have been marked with the process mark,
8750 respool those articles instead.
8751
8752 Respooling can be done both from mail groups and \"real\" newsgroups.
8753 In the former case, the articles in question will be moved from the
8754 current group into whatever groups they are destined to.  In the
8755 latter case, they will be copied into the relevant groups."
8756   (interactive
8757    (list current-prefix-arg
8758          (let* ((methods (gnus-methods-using 'respool))
8759                 (methname
8760                  (symbol-name (or gnus-summary-respool-default-method
8761                                   (car (gnus-find-method-for-group
8762                                         gnus-newsgroup-name)))))
8763                 (method
8764                  (gnus-completing-read-with-default
8765                   methname "What backend do you want to use when respooling?"
8766                   methods nil t nil 'gnus-mail-method-history))
8767                 ms)
8768            (cond
8769             ((zerop (length (setq ms (gnus-servers-using-backend
8770                                       (intern method)))))
8771              (list (intern method) ""))
8772             ((= 1 (length ms))
8773              (car ms))
8774             (t
8775              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8776                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8777                            ms-alist))))))))
8778   (unless method
8779     (error "No method given for respooling"))
8780   (if (assoc (symbol-name
8781               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8782              (gnus-methods-using 'respool))
8783       (gnus-summary-move-article n nil method)
8784     (gnus-summary-copy-article n nil method)))
8785
8786 (defun gnus-summary-import-article (file &optional edit)
8787   "Import an arbitrary file into a mail newsgroup."
8788   (interactive "fImport file: \nP")
8789   (let ((group gnus-newsgroup-name)
8790         (now (current-time))
8791         atts lines group-art)
8792     (unless (gnus-check-backend-function 'request-accept-article group)
8793       (error "%s does not support article importing" group))
8794     (or (file-readable-p file)
8795         (not (file-regular-p file))
8796         (error "Can't read %s" file))
8797     (save-excursion
8798       (set-buffer (gnus-get-buffer-create " *import file*"))
8799       (erase-buffer)
8800       (nnheader-insert-file-contents file)
8801       (goto-char (point-min))
8802       (if (nnheader-article-p)
8803           (save-restriction
8804             (goto-char (point-min))
8805             (search-forward "\n\n" nil t)
8806             (narrow-to-region (point-min) (1- (point)))
8807             (goto-char (point-min))
8808             (unless (re-search-forward "^date:" nil t)
8809               (goto-char (point-max))
8810               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8811        ;; This doesn't look like an article, so we fudge some headers.
8812         (setq atts (file-attributes file)
8813               lines (count-lines (point-min) (point-max)))
8814         (insert "From: " (read-string "From: ") "\n"
8815                 "Subject: " (read-string "Subject: ") "\n"
8816                 "Date: " (message-make-date (nth 5 atts)) "\n"
8817                 "Message-ID: " (message-make-message-id) "\n"
8818                 "Lines: " (int-to-string lines) "\n"
8819                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8820       (setq group-art (gnus-request-accept-article group nil t))
8821       (kill-buffer (current-buffer)))
8822     (setq gnus-newsgroup-active (gnus-activate-group group))
8823     (forward-line 1)
8824     (gnus-summary-goto-article (cdr group-art) nil t)
8825     (when edit
8826       (gnus-summary-edit-article))))
8827
8828 (defun gnus-summary-create-article ()
8829   "Create an article in a mail newsgroup."
8830   (interactive)
8831   (let ((group gnus-newsgroup-name)
8832         (now (current-time))
8833         group-art)
8834     (unless (gnus-check-backend-function 'request-accept-article group)
8835       (error "%s does not support article importing" group))
8836     (save-excursion
8837       (set-buffer (gnus-get-buffer-create " *import file*"))
8838       (erase-buffer)
8839       (goto-char (point-min))
8840       ;; This doesn't look like an article, so we fudge some headers.
8841       (insert "From: " (read-string "From: ") "\n"
8842               "Subject: " (read-string "Subject: ") "\n"
8843               "Date: " (message-make-date now) "\n"
8844               "Message-ID: " (message-make-message-id) "\n")
8845       (setq group-art (gnus-request-accept-article group nil t))
8846       (kill-buffer (current-buffer)))
8847     (setq gnus-newsgroup-active (gnus-activate-group group))
8848     (forward-line 1)
8849     (gnus-summary-goto-article (cdr group-art) nil t)
8850     (gnus-summary-edit-article)))
8851
8852 (defun gnus-summary-article-posted-p ()
8853   "Say whether the current (mail) article is available from news as well.
8854 This will be the case if the article has both been mailed and posted."
8855   (interactive)
8856   (let ((id (mail-header-references (gnus-summary-article-header)))
8857         (gnus-override-method (car (gnus-refer-article-methods))))
8858     (if (gnus-request-head id "")
8859         (gnus-message 2 "The current message was found on %s"
8860                       gnus-override-method)
8861       (gnus-message 2 "The current message couldn't be found on %s"
8862                     gnus-override-method)
8863       nil)))
8864
8865 (defun gnus-summary-expire-articles (&optional now)
8866   "Expire all articles that are marked as expirable in the current group."
8867   (interactive)
8868   (when (gnus-check-backend-function
8869          'request-expire-articles gnus-newsgroup-name)
8870     ;; This backend supports expiry.
8871     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8872            (expirable (if total
8873                           (progn
8874                             ;; We need to update the info for
8875                             ;; this group for `gnus-list-of-read-articles'
8876                             ;; to give us the right answer.
8877                             (gnus-run-hooks 'gnus-exit-group-hook)
8878                             (gnus-summary-update-info)
8879                             (gnus-list-of-read-articles gnus-newsgroup-name))
8880                         (setq gnus-newsgroup-expirable
8881                               (sort gnus-newsgroup-expirable '<))))
8882            (expiry-wait (if now 'immediate
8883                           (gnus-group-find-parameter
8884                            gnus-newsgroup-name 'expiry-wait)))
8885            (nnmail-expiry-target
8886             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8887                 nnmail-expiry-target))
8888            es)
8889       (when expirable
8890         ;; There are expirable articles in this group, so we run them
8891         ;; through the expiry process.
8892         (gnus-message 6 "Expiring articles...")
8893         (unless (gnus-check-group gnus-newsgroup-name)
8894           (error "Can't open server for %s" gnus-newsgroup-name))
8895         ;; The list of articles that weren't expired is returned.
8896         (save-excursion
8897           (if expiry-wait
8898               (let ((nnmail-expiry-wait-function nil)
8899                     (nnmail-expiry-wait expiry-wait))
8900                 (setq es (gnus-request-expire-articles
8901                           expirable gnus-newsgroup-name)))
8902             (setq es (gnus-request-expire-articles
8903                       expirable gnus-newsgroup-name)))
8904           (unless total
8905             (setq gnus-newsgroup-expirable es))
8906           ;; We go through the old list of expirable, and mark all
8907           ;; really expired articles as nonexistent.
8908           (unless (eq es expirable) ;If nothing was expired, we don't mark.
8909             (let ((gnus-use-cache nil))
8910               (dolist (article expirable)
8911                 (when (and (not (memq article es))
8912                            (gnus-data-find article))
8913                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8914         (gnus-message 6 "Expiring articles...done")))))
8915
8916 (defun gnus-summary-expire-articles-now ()
8917   "Expunge all expirable articles in the current group.
8918 This means that *all* articles that are marked as expirable will be
8919 deleted forever, right now."
8920   (interactive)
8921   (or gnus-expert-user
8922       (gnus-yes-or-no-p
8923        "Are you really, really, really sure you want to delete all these messages? ")
8924       (error "Phew!"))
8925   (gnus-summary-expire-articles t))
8926
8927 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8928 (defun gnus-summary-delete-article (&optional n)
8929   "Delete the N next (mail) articles.
8930 This command actually deletes articles.  This is not a marking
8931 command.  The article will disappear forever from your life, never to
8932 return.
8933 If N is negative, delete backwards.
8934 If N is nil and articles have been marked with the process mark,
8935 delete these instead."
8936   (interactive "P")
8937   (unless (gnus-check-backend-function 'request-expire-articles
8938                                        gnus-newsgroup-name)
8939     (error "The current newsgroup does not support article deletion"))
8940   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8941     (error "Couldn't open server"))
8942   ;; Compute the list of articles to delete.
8943   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8944         (nnmail-expiry-target 'delete)
8945         not-deleted)
8946     (if (and gnus-novice-user
8947              (not (gnus-yes-or-no-p
8948                    (format "Do you really want to delete %s forever? "
8949                            (if (> (length articles) 1)
8950                                (format "these %s articles" (length articles))
8951                              "this article")))))
8952         ()
8953       ;; Delete the articles.
8954       (setq not-deleted (gnus-request-expire-articles
8955                          articles gnus-newsgroup-name 'force))
8956       (while articles
8957         (gnus-summary-remove-process-mark (car articles))
8958         ;; The backend might not have been able to delete the article
8959         ;; after all.
8960         (unless (memq (car articles) not-deleted)
8961           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8962         (setq articles (cdr articles)))
8963       (when not-deleted
8964         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8965     (gnus-summary-position-point)
8966     (gnus-set-mode-line 'summary)
8967     not-deleted))
8968
8969 (defun gnus-summary-edit-article (&optional arg)
8970   "Edit the current article.
8971 This will have permanent effect only in mail groups.
8972 If ARG is nil, edit the decoded articles.
8973 If ARG is 1, edit the raw articles.
8974 If ARG is 2, edit the raw articles even in read-only groups.
8975 If ARG is 3, edit the articles with the current handles.
8976 Otherwise, allow editing of articles even in read-only
8977 groups."
8978   (interactive "P")
8979   (let (force raw current-handles)
8980     (cond
8981      ((null arg))
8982      ((eq arg 1)
8983       (setq raw t))
8984      ((eq arg 2)
8985       (setq raw t
8986             force t))
8987      ((eq arg 3)
8988       (setq current-handles
8989             (and (gnus-buffer-live-p gnus-article-buffer)
8990                  (with-current-buffer gnus-article-buffer
8991                    (prog1
8992                        gnus-article-mime-handles
8993                      (setq gnus-article-mime-handles nil))))))
8994      (t
8995       (setq force t)))
8996     (when (and raw (not force)
8997                (member gnus-newsgroup-name '("nndraft:delayed"
8998                                              "nndraft:drafts"
8999                                              "nndraft:queue")))
9000       (error "Can't edit the raw article in group %s"
9001              gnus-newsgroup-name))
9002     (save-excursion
9003       (set-buffer gnus-summary-buffer)
9004       (let ((mail-parse-charset gnus-newsgroup-charset)
9005             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9006         (gnus-set-global-variables)
9007         (when (and (not force)
9008                    (gnus-group-read-only-p))
9009           (error "The current newsgroup does not support article editing"))
9010         (gnus-summary-show-article t)
9011         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9012           (with-current-buffer gnus-article-buffer
9013             (mm-enable-multibyte)))
9014         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9015             (setq raw t))
9016         (gnus-article-edit-article
9017          (if raw 'ignore
9018            `(lambda ()
9019               (let ((mbl mml-buffer-list))
9020                 (setq mml-buffer-list nil)
9021                 (mime-to-mml ,'current-handles)
9022                 (let ((mbl1 mml-buffer-list))
9023                   (setq mml-buffer-list mbl)
9024                   (set (make-local-variable 'mml-buffer-list) mbl1))
9025                 (make-local-hook 'kill-buffer-hook)
9026                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9027          `(lambda (no-highlight)
9028             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9029                   (message-options message-options)
9030                   (message-options-set-recipient)
9031                   (mail-parse-ignored-charsets
9032                    ',gnus-newsgroup-ignored-charsets))
9033               ,(if (not raw) '(progn
9034                                 (mml-to-mime)
9035                                 (mml-destroy-buffers)
9036                                 (remove-hook 'kill-buffer-hook
9037                                              'mml-destroy-buffers t)
9038                                 (kill-local-variable 'mml-buffer-list)))
9039               (gnus-summary-edit-article-done
9040                ,(or (mail-header-references gnus-current-headers) "")
9041                ,(gnus-group-read-only-p)
9042                ,gnus-summary-buffer no-highlight))))))))
9043
9044 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9045
9046 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9047                                                  no-highlight)
9048   "Make edits to the current article permanent."
9049   (interactive)
9050   (save-excursion
9051    ;; The buffer restriction contains the entire article if it exists.
9052     (when (article-goto-body)
9053       (let ((lines (count-lines (point) (point-max)))
9054             (length (- (point-max) (point)))
9055             (case-fold-search t)
9056             (body (copy-marker (point))))
9057         (goto-char (point-min))
9058         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9059           (delete-region (match-beginning 1) (match-end 1))
9060           (insert (number-to-string length)))
9061         (goto-char (point-min))
9062         (when (re-search-forward
9063                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9064           (delete-region (match-beginning 1) (match-end 1))
9065           (insert (number-to-string length)))
9066         (goto-char (point-min))
9067         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9068           (delete-region (match-beginning 1) (match-end 1))
9069           (insert (number-to-string lines))))))
9070   ;; Replace the article.
9071   (let ((buf (current-buffer)))
9072     (with-temp-buffer
9073       (insert-buffer-substring buf)
9074
9075       (if (and (not read-only)
9076                (not (gnus-request-replace-article
9077                      (cdr gnus-article-current) (car gnus-article-current)
9078                      (current-buffer) t)))
9079           (error "Couldn't replace article")
9080         ;; Update the summary buffer.
9081         (if (and references
9082                  (equal (message-tokenize-header references " ")
9083                         (message-tokenize-header
9084                          (or (message-fetch-field "references") "") " ")))
9085             ;; We only have to update this line.
9086             (save-excursion
9087               (save-restriction
9088                 (message-narrow-to-head)
9089                 (let ((head (buffer-string))
9090                       header)
9091                   (with-temp-buffer
9092                     (insert (format "211 %d Article retrieved.\n"
9093                                     (cdr gnus-article-current)))
9094                     (insert head)
9095                     (insert ".\n")
9096                     (let ((nntp-server-buffer (current-buffer)))
9097                       (setq header (car (gnus-get-newsgroup-headers
9098                                          nil t))))
9099                     (save-excursion
9100                       (set-buffer gnus-summary-buffer)
9101                       (gnus-data-set-header
9102                        (gnus-data-find (cdr gnus-article-current))
9103                        header)
9104                       (gnus-summary-update-article-line
9105                        (cdr gnus-article-current) header)
9106                       (if (gnus-summary-goto-subject
9107                            (cdr gnus-article-current) nil t)
9108                           (gnus-summary-update-secondary-mark
9109                            (cdr gnus-article-current))))))))
9110           ;; Update threads.
9111           (set-buffer (or buffer gnus-summary-buffer))
9112           (gnus-summary-update-article (cdr gnus-article-current))
9113           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9114               (gnus-summary-update-secondary-mark
9115                (cdr gnus-article-current))))
9116         ;; Prettify the article buffer again.
9117         (unless no-highlight
9118           (save-excursion
9119             (set-buffer gnus-article-buffer)
9120             ;;;!!! Fix this -- article should be rehighlighted.
9121             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9122             (set-buffer gnus-original-article-buffer)
9123             (gnus-request-article
9124              (cdr gnus-article-current)
9125              (car gnus-article-current) (current-buffer))))
9126         ;; Prettify the summary buffer line.
9127         (when (gnus-visual-p 'summary-highlight 'highlight)
9128           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9129
9130 (defun gnus-summary-edit-wash (key)
9131   "Perform editing command KEY in the article buffer."
9132   (interactive
9133    (list
9134     (progn
9135       (message "%s" (concat (this-command-keys) "- "))
9136       (read-char))))
9137   (message "")
9138   (gnus-summary-edit-article)
9139   (execute-kbd-macro (concat (this-command-keys) key))
9140   (gnus-article-edit-done))
9141
9142 ;;; Respooling
9143
9144 (defun gnus-summary-respool-query (&optional silent trace)
9145   "Query where the respool algorithm would put this article."
9146   (interactive)
9147   (let (gnus-mark-article-hook)
9148     (gnus-summary-select-article)
9149     (save-excursion
9150       (set-buffer gnus-original-article-buffer)
9151       (save-restriction
9152         (message-narrow-to-head)
9153         (let ((groups (nnmail-article-group 'identity trace)))
9154           (unless silent
9155             (if groups
9156                 (message "This message would go to %s"
9157                          (mapconcat 'car groups ", "))
9158               (message "This message would go to no groups"))
9159             groups))))))
9160
9161 (defun gnus-summary-respool-trace ()
9162   "Trace where the respool algorithm would put this article.
9163 Display a buffer showing all fancy splitting patterns which matched."
9164   (interactive)
9165   (gnus-summary-respool-query nil t))
9166
9167 ;; Summary marking commands.
9168
9169 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9170   "Mark articles which has the same subject as read, and then select the next.
9171 If UNMARK is positive, remove any kind of mark.
9172 If UNMARK is negative, tick articles."
9173   (interactive "P")
9174   (when unmark
9175     (setq unmark (prefix-numeric-value unmark)))
9176   (let ((count
9177          (gnus-summary-mark-same-subject
9178           (gnus-summary-article-subject) unmark)))
9179     ;; Select next unread article.  If auto-select-same mode, should
9180     ;; select the first unread article.
9181     (gnus-summary-next-article t (and gnus-auto-select-same
9182                                       (gnus-summary-article-subject)))
9183     (gnus-message 7 "%d article%s marked as %s"
9184                   count (if (= count 1) " is" "s are")
9185                   (if unmark "unread" "read"))))
9186
9187 (defun gnus-summary-kill-same-subject (&optional unmark)
9188   "Mark articles which has the same subject as read.
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     ;; If marked as read, go to next unread subject.
9198     (when (null unmark)
9199       ;; Go to next unread subject.
9200       (gnus-summary-next-subject 1 t))
9201     (gnus-message 7 "%d articles are marked as %s"
9202                   count (if unmark "unread" "read"))))
9203
9204 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9205   "Mark articles with same SUBJECT as read, and return marked number.
9206 If optional argument UNMARK is positive, remove any kinds of marks.
9207 If optional argument UNMARK is negative, mark articles as unread instead."
9208   (let ((count 1))
9209     (save-excursion
9210       (cond
9211        ((null unmark)                   ; Mark as read.
9212         (while (and
9213                 (progn
9214                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9215                   (gnus-summary-show-thread) t)
9216                 (gnus-summary-find-subject subject))
9217           (setq count (1+ count))))
9218        ((> unmark 0)                    ; Tick.
9219         (while (and
9220                 (progn
9221                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9222                   (gnus-summary-show-thread) t)
9223                 (gnus-summary-find-subject subject))
9224           (setq count (1+ count))))
9225        (t                               ; Mark as unread.
9226         (while (and
9227                 (progn
9228                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9229                   (gnus-summary-show-thread) t)
9230                 (gnus-summary-find-subject subject))
9231           (setq count (1+ count)))))
9232       (gnus-set-mode-line 'summary)
9233       ;; Return the number of marked articles.
9234       count)))
9235
9236 (defun gnus-summary-mark-as-processable (n &optional unmark)
9237   "Set the process mark on the next N articles.
9238 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9239 the process mark instead.  The difference between N and the actual
9240 number of articles marked is returned."
9241   (interactive "P")
9242   (if (and (null n) (gnus-region-active-p))
9243       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9244     (setq n (prefix-numeric-value n))
9245     (let ((backward (< n 0))
9246           (n (abs n)))
9247       (while (and
9248               (> n 0)
9249               (if unmark
9250                   (gnus-summary-remove-process-mark
9251                    (gnus-summary-article-number))
9252                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9253               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9254         (setq n (1- n)))
9255       (when (/= 0 n)
9256         (gnus-message 7 "No more articles"))
9257       (gnus-summary-recenter)
9258       (gnus-summary-position-point)
9259       n)))
9260
9261 (defun gnus-summary-unmark-as-processable (n)
9262   "Remove the process mark from the next N articles.
9263 If N is negative, unmark backward instead.  The difference between N and
9264 the actual number of articles unmarked is returned."
9265   (interactive "P")
9266   (gnus-summary-mark-as-processable n t))
9267
9268 (defun gnus-summary-unmark-all-processable ()
9269   "Remove the process mark from all articles."
9270   (interactive)
9271   (save-excursion
9272     (while gnus-newsgroup-processable
9273       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9274   (gnus-summary-position-point))
9275
9276 (defun gnus-summary-add-mark (article type)
9277   "Mark ARTICLE with a mark of TYPE."
9278   (let ((vtype (car (assq type gnus-article-mark-lists)))
9279         var)
9280     (if (not vtype)
9281         (error "No such mark type: %s" type)
9282       (setq var (intern (format "gnus-newsgroup-%s" type)))
9283       (set var (cons article (symbol-value var)))
9284       (if (memq type '(processable cached replied forwarded recent saved))
9285           (gnus-summary-update-secondary-mark article)
9286         ;;; !!! This is bogus.  We should find out what primary
9287         ;;; !!! mark we want to set.
9288         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9289
9290 (defun gnus-summary-mark-as-expirable (n)
9291   "Mark N articles forward as expirable.
9292 If N is negative, mark backward instead.  The difference between N and
9293 the actual number of articles marked is returned."
9294   (interactive "p")
9295   (gnus-summary-mark-forward n gnus-expirable-mark))
9296
9297 (defun gnus-summary-mark-as-spam (n)
9298   "Mark N articles forward as spam.
9299 If N is negative, mark backward instead.  The difference between N and
9300 the actual number of articles marked is returned."
9301   (interactive "p")
9302   (gnus-summary-mark-forward n gnus-spam-mark))
9303
9304 (defun gnus-summary-mark-article-as-replied (article)
9305   "Mark ARTICLE as replied to and update the summary line.
9306 ARTICLE can also be a list of articles."
9307   (interactive (list (gnus-summary-article-number)))
9308   (let ((articles (if (listp article) article (list article))))
9309     (dolist (article articles)
9310       (push article gnus-newsgroup-replied)
9311       (let ((buffer-read-only nil))
9312         (when (gnus-summary-goto-subject article nil t)
9313           (gnus-summary-update-secondary-mark article))))))
9314
9315 (defun gnus-summary-mark-article-as-forwarded (article)
9316   "Mark ARTICLE as forwarded and update the summary line.
9317 ARTICLE can also be a list of articles."
9318   (let ((articles (if (listp article) article (list article))))
9319     (dolist (article articles)
9320       (push article gnus-newsgroup-forwarded)
9321       (let ((buffer-read-only nil))
9322         (when (gnus-summary-goto-subject article nil t)
9323           (gnus-summary-update-secondary-mark article))))))
9324
9325 (defun gnus-summary-set-bookmark (article)
9326   "Set a bookmark in current article."
9327   (interactive (list (gnus-summary-article-number)))
9328   (when (or (not (get-buffer gnus-article-buffer))
9329             (not gnus-current-article)
9330             (not gnus-article-current)
9331             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9332     (error "No current article selected"))
9333   ;; Remove old bookmark, if one exists.
9334   (let ((old (assq article gnus-newsgroup-bookmarks)))
9335     (when old
9336       (setq gnus-newsgroup-bookmarks
9337             (delq old gnus-newsgroup-bookmarks))))
9338   ;; Set the new bookmark, which is on the form
9339   ;; (article-number . line-number-in-body).
9340   (push
9341    (cons article
9342          (save-excursion
9343            (set-buffer gnus-article-buffer)
9344            (count-lines
9345             (min (point)
9346                  (save-excursion
9347                    (goto-char (point-min))
9348                    (search-forward "\n\n" nil t)
9349                    (point)))
9350             (point))))
9351    gnus-newsgroup-bookmarks)
9352   (gnus-message 6 "A bookmark has been added to the current article."))
9353
9354 (defun gnus-summary-remove-bookmark (article)
9355   "Remove the bookmark from the current article."
9356   (interactive (list (gnus-summary-article-number)))
9357   ;; Remove old bookmark, if one exists.
9358   (let ((old (assq article gnus-newsgroup-bookmarks)))
9359     (if old
9360         (progn
9361           (setq gnus-newsgroup-bookmarks
9362                 (delq old gnus-newsgroup-bookmarks))
9363           (gnus-message 6 "Removed bookmark."))
9364       (gnus-message 6 "No bookmark in current article."))))
9365
9366 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9367 (defun gnus-summary-mark-as-dormant (n)
9368   "Mark N articles forward as dormant.
9369 If N is negative, mark backward instead.  The difference between N and
9370 the actual number of articles marked is returned."
9371   (interactive "p")
9372   (gnus-summary-mark-forward n gnus-dormant-mark))
9373
9374 (defun gnus-summary-set-process-mark (article)
9375   "Set the process mark on ARTICLE and update the summary line."
9376   (setq gnus-newsgroup-processable
9377         (cons article
9378               (delq article gnus-newsgroup-processable)))
9379   (when (gnus-summary-goto-subject article)
9380     (gnus-summary-show-thread)
9381     (gnus-summary-goto-subject article)
9382     (gnus-summary-update-secondary-mark article)))
9383
9384 (defun gnus-summary-remove-process-mark (article)
9385   "Remove the process mark from ARTICLE and update the summary line."
9386   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9387   (when (gnus-summary-goto-subject article)
9388     (gnus-summary-show-thread)
9389     (gnus-summary-goto-subject article)
9390     (gnus-summary-update-secondary-mark article)))
9391
9392 (defun gnus-summary-set-saved-mark (article)
9393   "Set the process mark on ARTICLE and update the summary line."
9394   (push article gnus-newsgroup-saved)
9395   (when (gnus-summary-goto-subject article)
9396     (gnus-summary-update-secondary-mark article)))
9397
9398 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9399   "Mark N articles as read forwards.
9400 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9401 The difference between N and the actual number of articles marked is
9402 returned.
9403 If NO-EXPIRE, auto-expiry will be inhibited."
9404   (interactive "p")
9405   (gnus-summary-show-thread)
9406   (let ((backward (< n 0))
9407         (gnus-summary-goto-unread
9408          (and gnus-summary-goto-unread
9409               (not (eq gnus-summary-goto-unread 'never))
9410               (not (memq mark (list gnus-unread-mark
9411                                     gnus-ticked-mark gnus-dormant-mark)))))
9412         (n (abs n))
9413         (mark (or mark gnus-del-mark)))
9414     (while (and (> n 0)
9415                 (gnus-summary-mark-article nil mark no-expire)
9416                 (zerop (gnus-summary-next-subject
9417                         (if backward -1 1)
9418                         (and gnus-summary-goto-unread
9419                              (not (eq gnus-summary-goto-unread 'never)))
9420                         t)))
9421       (setq n (1- n)))
9422     (when (/= 0 n)
9423       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9424     (gnus-summary-recenter)
9425     (gnus-summary-position-point)
9426     (gnus-set-mode-line 'summary)
9427     n))
9428
9429 (defun gnus-summary-mark-article-as-read (mark)
9430   "Mark the current article quickly as read with MARK."
9431   (let ((article (gnus-summary-article-number)))
9432     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9433     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9434     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9435     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9436     (push (cons article mark) gnus-newsgroup-reads)
9437     ;; Possibly remove from cache, if that is used.
9438     (when gnus-use-cache
9439       (gnus-cache-enter-remove-article article))
9440     ;; Allow the backend to change the mark.
9441     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9442     ;; Check for auto-expiry.
9443     (when (and gnus-newsgroup-auto-expire
9444                (memq mark gnus-auto-expirable-marks))
9445       (setq mark gnus-expirable-mark)
9446       ;; Let the backend know about the mark change.
9447       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9448       (push article gnus-newsgroup-expirable))
9449     ;; Set the mark in the buffer.
9450     (gnus-summary-update-mark mark 'unread)
9451     t))
9452
9453 (defun gnus-summary-mark-article-as-unread (mark)
9454   "Mark the current article quickly as unread with MARK."
9455   (let* ((article (gnus-summary-article-number))
9456          (old-mark (gnus-summary-article-mark article)))
9457     ;; Allow the backend to change the mark.
9458     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9459     (if (eq mark old-mark)
9460         t
9461       (if (<= article 0)
9462           (progn
9463             (gnus-error 1 "Can't mark negative article numbers")
9464             nil)
9465         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9466         (setq gnus-newsgroup-spam-marked
9467               (delq article gnus-newsgroup-spam-marked))
9468         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9469         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9470         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9471         (cond ((= mark gnus-ticked-mark)
9472                (setq gnus-newsgroup-marked
9473                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9474                                               article)))
9475               ((= mark gnus-spam-mark)
9476                (setq gnus-newsgroup-spam-marked
9477                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9478                                               article)))
9479               ((= mark gnus-dormant-mark)
9480                (setq gnus-newsgroup-dormant
9481                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9482                                               article)))
9483               (t
9484                (setq gnus-newsgroup-unreads
9485                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9486                                               article))))
9487         (gnus-pull article gnus-newsgroup-reads)
9488
9489         ;; See whether the article is to be put in the cache.
9490         (and gnus-use-cache
9491              (vectorp (gnus-summary-article-header article))
9492              (save-excursion
9493                (gnus-cache-possibly-enter-article
9494                 gnus-newsgroup-name article
9495                 (= mark gnus-ticked-mark)
9496                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9497
9498         ;; Fix the mark.
9499         (gnus-summary-update-mark mark 'unread)
9500         t))))
9501
9502 (defun gnus-summary-mark-article (&optional article mark no-expire)
9503   "Mark ARTICLE with MARK.  MARK can be any character.
9504 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9505 `??' (dormant) and `?E' (expirable).
9506 If MARK is nil, then the default character `?r' is used.
9507 If ARTICLE is nil, then the article on the current line will be
9508 marked.
9509 If NO-EXPIRE, auto-expiry will be inhibited."
9510   ;; The mark might be a string.
9511   (when (stringp mark)
9512     (setq mark (aref mark 0)))
9513   ;; If no mark is given, then we check auto-expiring.
9514   (when (null mark)
9515     (setq mark gnus-del-mark))
9516   (when (and (not no-expire)
9517              gnus-newsgroup-auto-expire
9518              (memq mark gnus-auto-expirable-marks))
9519     (setq mark gnus-expirable-mark))
9520   (let ((article (or article (gnus-summary-article-number)))
9521         (old-mark (gnus-summary-article-mark article)))
9522     ;; Allow the backend to change the mark.
9523     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9524     (if (eq mark old-mark)
9525         t
9526       (unless article
9527         (error "No article on current line"))
9528       (if (not (if (or (= mark gnus-unread-mark)
9529                        (= mark gnus-ticked-mark)
9530                        (= mark gnus-spam-mark)
9531                        (= mark gnus-dormant-mark))
9532                    (gnus-mark-article-as-unread article mark)
9533                  (gnus-mark-article-as-read article mark)))
9534           t
9535         ;; See whether the article is to be put in the cache.
9536         (and gnus-use-cache
9537              (not (= mark gnus-canceled-mark))
9538              (vectorp (gnus-summary-article-header article))
9539              (save-excursion
9540                (gnus-cache-possibly-enter-article
9541                 gnus-newsgroup-name article
9542                 (= mark gnus-ticked-mark)
9543                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9544
9545         (when (gnus-summary-goto-subject article nil t)
9546           (let ((buffer-read-only nil))
9547             (gnus-summary-show-thread)
9548             ;; Fix the mark.
9549             (gnus-summary-update-mark mark 'unread)
9550             t))))))
9551
9552 (defun gnus-summary-update-secondary-mark (article)
9553   "Update the secondary (read, process, cache) mark."
9554   (gnus-summary-update-mark
9555    (cond ((memq article gnus-newsgroup-processable)
9556           gnus-process-mark)
9557          ((memq article gnus-newsgroup-cached)
9558           gnus-cached-mark)
9559          ((memq article gnus-newsgroup-replied)
9560           gnus-replied-mark)
9561          ((memq article gnus-newsgroup-forwarded)
9562           gnus-forwarded-mark)
9563          ((memq article gnus-newsgroup-saved)
9564           gnus-saved-mark)
9565          ((memq article gnus-newsgroup-recent)
9566           gnus-recent-mark)
9567          ((memq article gnus-newsgroup-unseen)
9568           gnus-unseen-mark)
9569          (t gnus-no-mark))
9570    'replied)
9571   (when (gnus-visual-p 'summary-highlight 'highlight)
9572     (gnus-run-hooks 'gnus-summary-update-hook))
9573   t)
9574
9575 (defun gnus-summary-update-mark (mark type)
9576   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9577         (buffer-read-only nil))
9578     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9579     (when forward
9580       (when (looking-at "\r")
9581         (incf forward))
9582       (when (<= (+ forward (point)) (point-max))
9583         ;; Go to the right position on the line.
9584         (goto-char (+ forward (point)))
9585         ;; Replace the old mark with the new mark.
9586         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9587         ;; Optionally update the marks by some user rule.
9588         (when (eq type 'unread)
9589           (gnus-data-set-mark
9590            (gnus-data-find (gnus-summary-article-number)) mark)
9591           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9592
9593 (defun gnus-mark-article-as-read (article &optional mark)
9594   "Enter ARTICLE in the pertinent lists and remove it from others."
9595   ;; Make the article expirable.
9596   (let ((mark (or mark gnus-del-mark)))
9597     (setq gnus-newsgroup-expirable
9598           (if (= mark gnus-expirable-mark)
9599               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9600             (delq article gnus-newsgroup-expirable)))
9601     ;; Remove from unread and marked lists.
9602     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9603     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9604     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9605     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9606     (push (cons article mark) gnus-newsgroup-reads)
9607     ;; Possibly remove from cache, if that is used.
9608     (when gnus-use-cache
9609       (gnus-cache-enter-remove-article article))
9610     t))
9611
9612 (defun gnus-mark-article-as-unread (article &optional mark)
9613   "Enter ARTICLE in the pertinent lists and remove it from others."
9614   (let ((mark (or mark gnus-ticked-mark)))
9615     (if (<= article 0)
9616         (progn
9617           (gnus-error 1 "Can't mark negative article numbers")
9618           nil)
9619       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9620             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9621             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9622             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9623             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9624
9625       ;; Unsuppress duplicates?
9626       (when gnus-suppress-duplicates
9627         (gnus-dup-unsuppress-article article))
9628
9629       (cond ((= mark gnus-ticked-mark)
9630              (setq gnus-newsgroup-marked
9631                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9632             ((= mark gnus-spam-mark)
9633              (setq gnus-newsgroup-spam-marked
9634                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9635                                             article)))
9636             ((= mark gnus-dormant-mark)
9637              (setq gnus-newsgroup-dormant
9638                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9639             (t
9640              (setq gnus-newsgroup-unreads
9641                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9642       (gnus-pull article gnus-newsgroup-reads)
9643       t)))
9644
9645 (defalias 'gnus-summary-mark-as-unread-forward
9646   'gnus-summary-tick-article-forward)
9647 (make-obsolete 'gnus-summary-mark-as-unread-forward
9648                'gnus-summary-tick-article-forward)
9649 (defun gnus-summary-tick-article-forward (n)
9650   "Tick N articles forwards.
9651 If N is negative, tick backwards instead.
9652 The difference between N and the number of articles ticked is returned."
9653   (interactive "p")
9654   (gnus-summary-mark-forward n gnus-ticked-mark))
9655
9656 (defalias 'gnus-summary-mark-as-unread-backward
9657   'gnus-summary-tick-article-backward)
9658 (make-obsolete 'gnus-summary-mark-as-unread-backward
9659                'gnus-summary-tick-article-backward)
9660 (defun gnus-summary-tick-article-backward (n)
9661   "Tick N articles backwards.
9662 The difference between N and the number of articles ticked is returned."
9663   (interactive "p")
9664   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9665
9666 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9667 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9668 (defun gnus-summary-tick-article (&optional article clear-mark)
9669   "Mark current article as unread.
9670 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9671 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9672   (interactive)
9673   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9674                                        gnus-ticked-mark)))
9675
9676 (defun gnus-summary-mark-as-read-forward (n)
9677   "Mark N articles as read forwards.
9678 If N is negative, mark backwards instead.
9679 The difference between N and the actual number of articles marked is
9680 returned."
9681   (interactive "p")
9682   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9683
9684 (defun gnus-summary-mark-as-read-backward (n)
9685   "Mark the N articles as read backwards.
9686 The difference between N and the actual number of articles marked is
9687 returned."
9688   (interactive "p")
9689   (gnus-summary-mark-forward
9690    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9691
9692 (defun gnus-summary-mark-as-read (&optional article mark)
9693   "Mark current article as read.
9694 ARTICLE specifies the article to be marked as read.
9695 MARK specifies a string to be inserted at the beginning of the line."
9696   (gnus-summary-mark-article article mark))
9697
9698 (defun gnus-summary-clear-mark-forward (n)
9699   "Clear marks from N articles forward.
9700 If N is negative, clear backward instead.
9701 The difference between N and the number of marks cleared is returned."
9702   (interactive "p")
9703   (gnus-summary-mark-forward n gnus-unread-mark))
9704
9705 (defun gnus-summary-clear-mark-backward (n)
9706   "Clear marks from N articles backward.
9707 The difference between N and the number of marks cleared is returned."
9708   (interactive "p")
9709   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9710
9711 (defun gnus-summary-mark-unread-as-read ()
9712   "Intended to be used by `gnus-summary-mark-article-hook'."
9713   (when (memq gnus-current-article gnus-newsgroup-unreads)
9714     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9715
9716 (defun gnus-summary-mark-read-and-unread-as-read ()
9717   "Intended to be used by `gnus-summary-mark-article-hook'."
9718   (let ((mark (gnus-summary-article-mark)))
9719     (when (or (gnus-unread-mark-p mark)
9720               (gnus-read-mark-p mark))
9721       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9722
9723 (defun gnus-summary-mark-unread-as-ticked ()
9724   "Intended to be used by `gnus-summary-mark-article-hook'."
9725   (when (memq gnus-current-article gnus-newsgroup-unreads)
9726     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9727
9728 (defun gnus-summary-mark-region-as-read (point mark all)
9729   "Mark all unread articles between point and mark as read.
9730 If given a prefix, mark all articles between point and mark as read,
9731 even ticked and dormant ones."
9732   (interactive "r\nP")
9733   (save-excursion
9734     (let (article)
9735       (goto-char point)
9736       (beginning-of-line)
9737       (while (and
9738               (< (point) mark)
9739               (progn
9740                 (when (or all
9741                           (memq (setq article (gnus-summary-article-number))
9742                                 gnus-newsgroup-unreads))
9743                   (gnus-summary-mark-article article gnus-del-mark))
9744                 t)
9745               (gnus-summary-find-next))))))
9746
9747 (defun gnus-summary-mark-below (score mark)
9748   "Mark articles with score less than SCORE with MARK."
9749   (interactive "P\ncMark: ")
9750   (setq score (if score
9751                   (prefix-numeric-value score)
9752                 (or gnus-summary-default-score 0)))
9753   (save-excursion
9754     (set-buffer gnus-summary-buffer)
9755     (goto-char (point-min))
9756     (while
9757         (progn
9758           (and (< (gnus-summary-article-score) score)
9759                (gnus-summary-mark-article nil mark))
9760           (gnus-summary-find-next)))))
9761
9762 (defun gnus-summary-kill-below (&optional score)
9763   "Mark articles with score below SCORE as read."
9764   (interactive "P")
9765   (gnus-summary-mark-below score gnus-killed-mark))
9766
9767 (defun gnus-summary-clear-above (&optional score)
9768   "Clear all marks from articles with score above SCORE."
9769   (interactive "P")
9770   (gnus-summary-mark-above score gnus-unread-mark))
9771
9772 (defun gnus-summary-tick-above (&optional score)
9773   "Tick all articles with score above SCORE."
9774   (interactive "P")
9775   (gnus-summary-mark-above score gnus-ticked-mark))
9776
9777 (defun gnus-summary-mark-above (score mark)
9778   "Mark articles with score over SCORE with MARK."
9779   (interactive "P\ncMark: ")
9780   (setq score (if score
9781                   (prefix-numeric-value score)
9782                 (or gnus-summary-default-score 0)))
9783   (save-excursion
9784     (set-buffer gnus-summary-buffer)
9785     (goto-char (point-min))
9786     (while (and (progn
9787                   (when (> (gnus-summary-article-score) score)
9788                     (gnus-summary-mark-article nil mark))
9789                   t)
9790                 (gnus-summary-find-next)))))
9791
9792 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9793 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9794 (defun gnus-summary-limit-include-expunged (&optional no-error)
9795   "Display all the hidden articles that were expunged for low scores."
9796   (interactive)
9797   (let ((buffer-read-only nil))
9798     (let ((scored gnus-newsgroup-scored)
9799           headers h)
9800       (while scored
9801         (unless (gnus-summary-article-header (caar scored))
9802           (and (setq h (gnus-number-to-header (caar scored)))
9803                (< (cdar scored) gnus-summary-expunge-below)
9804                (push h headers)))
9805         (setq scored (cdr scored)))
9806       (if (not headers)
9807           (when (not no-error)
9808             (error "No expunged articles hidden"))
9809         (goto-char (point-min))
9810         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9811         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9812         (mapcar (lambda (x) (push (mail-header-number x)
9813                                   gnus-newsgroup-limit))
9814                 headers)
9815         (gnus-summary-prepare-unthreaded (nreverse headers))
9816         (goto-char (point-min))
9817         (gnus-summary-position-point)
9818         t))))
9819
9820 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9821   "Mark all unread articles in this newsgroup as read.
9822 If prefix argument ALL is non-nil, ticked and dormant articles will
9823 also be marked as read.
9824 If QUIETLY is non-nil, no questions will be asked.
9825 If TO-HERE is non-nil, it should be a point in the buffer.  All
9826 articles before (after, if REVERSE is set) this point will be marked as read.
9827 Note that this function will only catch up the unread article
9828 in the current summary buffer limitation.
9829 The number of articles marked as read is returned."
9830   (interactive "P")
9831   (prog1
9832       (save-excursion
9833         (when (or quietly
9834                   (not gnus-interactive-catchup) ;Without confirmation?
9835                   gnus-expert-user
9836                   (gnus-y-or-n-p
9837                    (if all
9838                        "Mark absolutely all articles as read? "
9839                      "Mark all unread articles as read? ")))
9840           (if (and not-mark
9841                    (not gnus-newsgroup-adaptive)
9842                    (not gnus-newsgroup-auto-expire)
9843                    (not gnus-suppress-duplicates)
9844                    (or (not gnus-use-cache)
9845                        (eq gnus-use-cache 'passive)))
9846               (progn
9847                 (when all
9848                   (setq gnus-newsgroup-marked nil
9849                         gnus-newsgroup-spam-marked nil
9850                         gnus-newsgroup-dormant nil))
9851                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9852             ;; We actually mark all articles as canceled, which we
9853             ;; have to do when using auto-expiry or adaptive scoring.
9854             (gnus-summary-show-all-threads)
9855             (if (and to-here reverse)
9856                 (progn
9857                   (goto-char to-here)
9858                   (while (and
9859                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9860                           (gnus-summary-find-next (not all) nil nil t))))
9861               (when (gnus-summary-first-subject (not all) t)
9862                 (while (and
9863                         (if to-here (< (point) to-here) t)
9864                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9865                         (gnus-summary-find-next (not all) nil nil t)))))
9866             (gnus-set-mode-line 'summary))
9867           t))
9868     (gnus-summary-position-point)))
9869
9870 (defun gnus-summary-catchup-to-here (&optional all)
9871   "Mark all unticked articles before the current one as read.
9872 If ALL is non-nil, also mark ticked and dormant articles as read."
9873   (interactive "P")
9874   (save-excursion
9875     (gnus-save-hidden-threads
9876       (let ((beg (point)))
9877         ;; We check that there are unread articles.
9878         (when (or all (gnus-summary-find-prev))
9879           (gnus-summary-catchup all t beg)))))
9880   (gnus-summary-position-point))
9881
9882 (defun gnus-summary-catchup-from-here (&optional all)
9883   "Mark all unticked articles after the current one as read.
9884 If ALL is non-nil, also mark ticked and dormant articles as read."
9885   (interactive "P")
9886   (save-excursion
9887     (gnus-save-hidden-threads
9888       (let ((beg (point)))
9889         ;; We check that there are unread articles.
9890         (when (or all (gnus-summary-find-next))
9891           (gnus-summary-catchup all t beg nil t)))))
9892
9893   (gnus-summary-position-point))
9894 (defun gnus-summary-catchup-all (&optional quietly)
9895   "Mark all articles in this newsgroup as read.
9896 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
9897 instead, which marks only unread articles as read."
9898   (interactive "P")
9899   (gnus-summary-catchup t quietly))
9900
9901 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9902   "Mark all unread articles in this group as read, then exit.
9903 If prefix argument ALL is non-nil, all articles are marked as read.
9904 If QUIETLY is non-nil, no questions will be asked."
9905   (interactive "P")
9906   (when (gnus-summary-catchup all quietly nil 'fast)
9907     ;; Select next newsgroup or exit.
9908     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9909              (eq gnus-auto-select-next 'quietly))
9910         (gnus-summary-next-group nil)
9911       (gnus-summary-exit))))
9912
9913 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9914   "Mark all articles in this newsgroup as read, and then exit.
9915 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
9916 instead, which marks only unread articles as read."
9917   (interactive "P")
9918   (gnus-summary-catchup-and-exit t quietly))
9919
9920 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9921   "Mark all articles in this group as read and select the next group.
9922 If given a prefix, mark all articles, unread as well as ticked, as
9923 read."
9924   (interactive "P")
9925   (save-excursion
9926     (gnus-summary-catchup all))
9927   (gnus-summary-next-group))
9928
9929 ;;;
9930 ;;; with article
9931 ;;;
9932
9933 (defmacro gnus-with-article (article &rest forms)
9934   "Select ARTICLE and perform FORMS in the original article buffer.
9935 Then replace the article with the result."
9936   `(progn
9937      ;; We don't want the article to be marked as read.
9938      (let (gnus-mark-article-hook)
9939        (gnus-summary-select-article t t nil ,article))
9940      (set-buffer gnus-original-article-buffer)
9941      ,@forms
9942      (if (not (gnus-check-backend-function
9943                'request-replace-article (car gnus-article-current)))
9944          (gnus-message 5 "Read-only group; not replacing")
9945        (unless (gnus-request-replace-article
9946                 ,article (car gnus-article-current)
9947                 (current-buffer) t)
9948          (error "Couldn't replace article")))
9949      ;; The cache and backlog have to be flushed somewhat.
9950      (when gnus-keep-backlog
9951        (gnus-backlog-remove-article
9952         (car gnus-article-current) (cdr gnus-article-current)))
9953      (when gnus-use-cache
9954        (gnus-cache-update-article
9955         (car gnus-article-current) (cdr gnus-article-current)))))
9956
9957 (put 'gnus-with-article 'lisp-indent-function 1)
9958 (put 'gnus-with-article 'edebug-form-spec '(form body))
9959
9960 ;; Thread-based commands.
9961
9962 (defun gnus-summary-articles-in-thread (&optional article)
9963   "Return a list of all articles in the current thread.
9964 If ARTICLE is non-nil, return all articles in the thread that starts
9965 with that article."
9966   (let* ((article (or article (gnus-summary-article-number)))
9967          (data (gnus-data-find-list article))
9968          (top-level (gnus-data-level (car data)))
9969          (top-subject
9970           (cond ((null gnus-thread-operation-ignore-subject)
9971                  (gnus-simplify-subject-re
9972                   (mail-header-subject (gnus-data-header (car data)))))
9973                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9974                  (gnus-simplify-subject-fuzzy
9975                   (mail-header-subject (gnus-data-header (car data)))))
9976                 (t nil)))
9977          (end-point (save-excursion
9978                       (if (gnus-summary-go-to-next-thread)
9979                           (point) (point-max))))
9980          articles)
9981     (while (and data
9982                 (< (gnus-data-pos (car data)) end-point))
9983       (when (or (not top-subject)
9984                 (string= top-subject
9985                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9986                              (gnus-simplify-subject-fuzzy
9987                               (mail-header-subject
9988                                (gnus-data-header (car data))))
9989                            (gnus-simplify-subject-re
9990                             (mail-header-subject
9991                              (gnus-data-header (car data)))))))
9992         (push (gnus-data-number (car data)) articles))
9993       (unless (and (setq data (cdr data))
9994                    (> (gnus-data-level (car data)) top-level))
9995         (setq data nil)))
9996     ;; Return the list of articles.
9997     (nreverse articles)))
9998
9999 (defun gnus-summary-rethread-current ()
10000   "Rethread the thread the current article is part of."
10001   (interactive)
10002   (let* ((gnus-show-threads t)
10003          (article (gnus-summary-article-number))
10004          (id (mail-header-id (gnus-summary-article-header)))
10005          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10006     (unless id
10007       (error "No article on the current line"))
10008     (gnus-rebuild-thread id)
10009     (gnus-summary-goto-subject article)))
10010
10011 (defun gnus-summary-reparent-thread ()
10012   "Make the current article child of the marked (or previous) article.
10013
10014 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10015 is non-nil or the Subject: of both articles are the same."
10016   (interactive)
10017   (unless (not (gnus-group-read-only-p))
10018     (error "The current newsgroup does not support article editing"))
10019   (unless (<= (length gnus-newsgroup-processable) 1)
10020     (error "No more than one article may be marked"))
10021   (save-window-excursion
10022     (let ((gnus-article-buffer " *reparent*")
10023           (current-article (gnus-summary-article-number))
10024           ;; First grab the marked article, otherwise one line up.
10025           (parent-article (if (not (null gnus-newsgroup-processable))
10026                               (car gnus-newsgroup-processable)
10027                             (save-excursion
10028                               (if (eq (forward-line -1) 0)
10029                                   (gnus-summary-article-number)
10030                                 (error "Beginning of summary buffer"))))))
10031       (unless (not (eq current-article parent-article))
10032         (error "An article may not be self-referential"))
10033       (let ((message-id (mail-header-id
10034                          (gnus-summary-article-header parent-article))))
10035         (unless (and message-id (not (equal message-id "")))
10036           (error "No message-id in desired parent"))
10037         (gnus-with-article current-article
10038           (save-restriction
10039             (goto-char (point-min))
10040             (message-narrow-to-head)
10041             (if (re-search-forward "^References: " nil t)
10042                 (progn
10043                   (re-search-forward "^[^ \t]" nil t)
10044                   (forward-line -1)
10045                   (end-of-line)
10046                   (insert " " message-id))
10047               (insert "References: " message-id "\n"))))
10048         (set-buffer gnus-summary-buffer)
10049         (gnus-summary-unmark-all-processable)
10050         (gnus-summary-update-article current-article)
10051         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10052             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10053         (gnus-summary-rethread-current)
10054         (gnus-message 3 "Article %d is now the child of article %d"
10055                       current-article parent-article)))))
10056
10057 (defun gnus-summary-toggle-threads (&optional arg)
10058   "Toggle showing conversation threads.
10059 If ARG is positive number, turn showing conversation threads on."
10060   (interactive "P")
10061   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10062     (setq gnus-show-threads
10063           (if (null arg) (not gnus-show-threads)
10064             (> (prefix-numeric-value arg) 0)))
10065     (gnus-summary-prepare)
10066     (gnus-summary-goto-subject current)
10067     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10068     (gnus-summary-position-point)))
10069
10070 (defun gnus-summary-show-all-threads ()
10071   "Show all threads."
10072   (interactive)
10073   (save-excursion
10074     (let ((buffer-read-only nil))
10075       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10076   (gnus-summary-position-point))
10077
10078 (defun gnus-summary-show-thread ()
10079   "Show thread subtrees.
10080 Returns nil if no thread was there to be shown."
10081   (interactive)
10082   (let ((buffer-read-only nil)
10083         (orig (point))
10084         ;; first goto end then to beg, to have point at beg after let
10085         (end (progn (end-of-line) (point)))
10086         (beg (progn (beginning-of-line) (point))))
10087     (prog1
10088         ;; Any hidden lines here?
10089         (search-forward "\r" end t)
10090       (subst-char-in-region beg end ?\^M ?\n t)
10091       (goto-char orig)
10092       (gnus-summary-position-point))))
10093
10094 (defun gnus-summary-maybe-hide-threads ()
10095   "If requested, hide the threads that should be hidden."
10096   (when (and gnus-show-threads
10097              gnus-thread-hide-subtree)
10098     (gnus-summary-hide-all-threads
10099      (if (or (consp gnus-thread-hide-subtree)
10100              (gnus-functionp gnus-thread-hide-subtree))
10101          (gnus-make-predicate gnus-thread-hide-subtree)
10102        nil))))
10103
10104 ;;; Hiding predicates.
10105
10106 (defun gnus-article-unread-p (header)
10107   (memq (mail-header-number header) gnus-newsgroup-unreads))
10108
10109 (defun gnus-article-unseen-p (header)
10110   (memq (mail-header-number header) gnus-newsgroup-unseen))
10111
10112 (defun gnus-map-articles (predicate articles)
10113   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10114   (apply 'gnus-or (mapcar predicate
10115                           (mapcar 'gnus-summary-article-header articles))))
10116
10117 (defun gnus-summary-hide-all-threads (&optional predicate)
10118   "Hide all thread subtrees.
10119 If PREDICATE is supplied, threads that satisfy this predicate
10120 will not be hidden."
10121   (interactive)
10122   (save-excursion
10123     (goto-char (point-min))
10124     (let ((end nil))
10125       (while (not end)
10126         (when (or (not predicate)
10127                   (gnus-map-articles
10128                    predicate (gnus-summary-article-children)))
10129             (gnus-summary-hide-thread))
10130         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10131   (gnus-summary-position-point))
10132
10133 (defun gnus-summary-hide-thread ()
10134   "Hide thread subtrees.
10135 If PREDICATE is supplied, threads that satisfy this predicate
10136 will not be hidden.
10137 Returns nil if no threads were there to be hidden."
10138   (interactive)
10139   (let ((buffer-read-only nil)
10140         (start (point))
10141         (article (gnus-summary-article-number)))
10142     (goto-char start)
10143     ;; Go forward until either the buffer ends or the subthread
10144     ;; ends.
10145     (when (and (not (eobp))
10146                (or (zerop (gnus-summary-next-thread 1 t))
10147                    (goto-char (point-max))))
10148       (prog1
10149           (if (and (> (point) start)
10150                    (search-backward "\n" start t))
10151               (progn
10152                 (subst-char-in-region start (point) ?\n ?\^M)
10153                 (gnus-summary-goto-subject article))
10154             (goto-char start)
10155             nil)))))
10156
10157 (defun gnus-summary-go-to-next-thread (&optional previous)
10158   "Go to the same level (or less) next thread.
10159 If PREVIOUS is non-nil, go to previous thread instead.
10160 Return the article number moved to, or nil if moving was impossible."
10161   (let ((level (gnus-summary-thread-level))
10162         (way (if previous -1 1))
10163         (beg (point)))
10164     (forward-line way)
10165     (while (and (not (eobp))
10166                 (< level (gnus-summary-thread-level)))
10167       (forward-line way))
10168     (if (eobp)
10169         (progn
10170           (goto-char beg)
10171           nil)
10172       (setq beg (point))
10173       (prog1
10174           (gnus-summary-article-number)
10175         (goto-char beg)))))
10176
10177 (defun gnus-summary-next-thread (n &optional silent)
10178   "Go to the same level next N'th thread.
10179 If N is negative, search backward instead.
10180 Returns the difference between N and the number of skips actually
10181 done.
10182
10183 If SILENT, don't output messages."
10184   (interactive "p")
10185   (let ((backward (< n 0))
10186         (n (abs n)))
10187     (while (and (> n 0)
10188                 (gnus-summary-go-to-next-thread backward))
10189       (decf n))
10190     (unless silent
10191       (gnus-summary-position-point))
10192     (when (and (not silent) (/= 0 n))
10193       (gnus-message 7 "No more threads"))
10194     n))
10195
10196 (defun gnus-summary-prev-thread (n)
10197   "Go to the same level previous N'th thread.
10198 Returns the difference between N and the number of skips actually
10199 done."
10200   (interactive "p")
10201   (gnus-summary-next-thread (- n)))
10202
10203 (defun gnus-summary-go-down-thread ()
10204   "Go down one level in the current thread."
10205   (let ((children (gnus-summary-article-children)))
10206     (when children
10207       (gnus-summary-goto-subject (car children)))))
10208
10209 (defun gnus-summary-go-up-thread ()
10210   "Go up one level in the current thread."
10211   (let ((parent (gnus-summary-article-parent)))
10212     (when parent
10213       (gnus-summary-goto-subject parent))))
10214
10215 (defun gnus-summary-down-thread (n)
10216   "Go down thread N steps.
10217 If N is negative, go up instead.
10218 Returns the difference between N and how many steps down that were
10219 taken."
10220   (interactive "p")
10221   (let ((up (< n 0))
10222         (n (abs n)))
10223     (while (and (> n 0)
10224                 (if up (gnus-summary-go-up-thread)
10225                   (gnus-summary-go-down-thread)))
10226       (setq n (1- n)))
10227     (gnus-summary-position-point)
10228     (when (/= 0 n)
10229       (gnus-message 7 "Can't go further"))
10230     n))
10231
10232 (defun gnus-summary-up-thread (n)
10233   "Go up thread N steps.
10234 If N is negative, go down instead.
10235 Returns the difference between N and how many steps down that were
10236 taken."
10237   (interactive "p")
10238   (gnus-summary-down-thread (- n)))
10239
10240 (defun gnus-summary-top-thread ()
10241   "Go to the top of the thread."
10242   (interactive)
10243   (while (gnus-summary-go-up-thread))
10244   (gnus-summary-article-number))
10245
10246 (defun gnus-summary-kill-thread (&optional unmark)
10247   "Mark articles under current thread as read.
10248 If the prefix argument is positive, remove any kinds of marks.
10249 If the prefix argument is negative, tick articles instead."
10250   (interactive "P")
10251   (when unmark
10252     (setq unmark (prefix-numeric-value unmark)))
10253   (let ((articles (gnus-summary-articles-in-thread)))
10254     (save-excursion
10255       ;; Expand the thread.
10256       (gnus-summary-show-thread)
10257       ;; Mark all the articles.
10258       (while articles
10259         (gnus-summary-goto-subject (car articles))
10260         (cond ((null unmark)
10261                (gnus-summary-mark-article-as-read gnus-killed-mark))
10262               ((> unmark 0)
10263                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10264               (t
10265                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10266         (setq articles (cdr articles))))
10267     ;; Hide killed subtrees.
10268     (and (null unmark)
10269          gnus-thread-hide-killed
10270          (gnus-summary-hide-thread))
10271     ;; If marked as read, go to next unread subject.
10272     (when (null unmark)
10273       ;; Go to next unread subject.
10274       (gnus-summary-next-subject 1 t)))
10275   (gnus-set-mode-line 'summary))
10276
10277 ;; Summary sorting commands
10278
10279 (defun gnus-summary-sort-by-number (&optional reverse)
10280   "Sort the summary buffer by article number.
10281 Argument REVERSE means reverse order."
10282   (interactive "P")
10283   (gnus-summary-sort 'number reverse))
10284
10285 (defun gnus-summary-sort-by-random (&optional reverse)
10286   "Randomize the order in the summary buffer.
10287 Argument REVERSE means to randomize in reverse order."
10288   (interactive "P")
10289   (gnus-summary-sort 'random reverse))
10290
10291 (defun gnus-summary-sort-by-author (&optional reverse)
10292   "Sort the summary buffer by author name alphabetically.
10293 If `case-fold-search' is non-nil, case of letters is ignored.
10294 Argument REVERSE means reverse order."
10295   (interactive "P")
10296   (gnus-summary-sort 'author reverse))
10297
10298 (defun gnus-summary-sort-by-subject (&optional reverse)
10299   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10300 If `case-fold-search' is non-nil, case of letters is ignored.
10301 Argument REVERSE means reverse order."
10302   (interactive "P")
10303   (gnus-summary-sort 'subject reverse))
10304
10305 (defun gnus-summary-sort-by-date (&optional reverse)
10306   "Sort the summary buffer by date.
10307 Argument REVERSE means reverse order."
10308   (interactive "P")
10309   (gnus-summary-sort 'date reverse))
10310
10311 (defun gnus-summary-sort-by-score (&optional reverse)
10312   "Sort the summary buffer by score.
10313 Argument REVERSE means reverse order."
10314   (interactive "P")
10315   (gnus-summary-sort 'score reverse))
10316
10317 (defun gnus-summary-sort-by-lines (&optional reverse)
10318   "Sort the summary buffer by the number of lines.
10319 Argument REVERSE means reverse order."
10320   (interactive "P")
10321   (gnus-summary-sort 'lines reverse))
10322
10323 (defun gnus-summary-sort-by-chars (&optional reverse)
10324   "Sort the summary buffer by article length.
10325 Argument REVERSE means reverse order."
10326   (interactive "P")
10327   (gnus-summary-sort 'chars reverse))
10328
10329 (defun gnus-summary-sort-by-original (&optional reverse)
10330   "Sort the summary buffer using the default sorting method.
10331 Argument REVERSE means reverse order."
10332   (interactive "P")
10333   (let* ((buffer-read-only)
10334          (gnus-summary-prepare-hook nil))
10335     ;; We do the sorting by regenerating the threads.
10336     (gnus-summary-prepare)
10337     ;; Hide subthreads if needed.
10338     (gnus-summary-maybe-hide-threads)))
10339
10340 (defun gnus-summary-sort (predicate reverse)
10341   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10342   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10343          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10344          (gnus-thread-sort-functions
10345           (if (not reverse)
10346               thread
10347             `(lambda (t1 t2)
10348                (,thread t2 t1))))
10349          (gnus-sort-gathered-threads-function
10350           gnus-thread-sort-functions)
10351          (gnus-article-sort-functions
10352           (if (not reverse)
10353               article
10354             `(lambda (t1 t2)
10355                (,article t2 t1))))
10356          (buffer-read-only)
10357          (gnus-summary-prepare-hook nil))
10358     ;; We do the sorting by regenerating the threads.
10359     (gnus-summary-prepare)
10360     ;; Hide subthreads if needed.
10361     (gnus-summary-maybe-hide-threads)))
10362
10363 ;; Summary saving commands.
10364
10365 (defun gnus-summary-save-article (&optional n not-saved)
10366   "Save the current article using the default saver function.
10367 If N is a positive number, save the N next articles.
10368 If N is a negative number, save the N previous articles.
10369 If N is nil and any articles have been marked with the process mark,
10370 save those articles instead.
10371 The variable `gnus-default-article-saver' specifies the saver function."
10372   (interactive "P")
10373   (let* ((articles (gnus-summary-work-articles n))
10374          (save-buffer (save-excursion
10375                         (nnheader-set-temp-buffer " *Gnus Save*")))
10376          (num (length articles))
10377          header file)
10378     (dolist (article articles)
10379       (setq header (gnus-summary-article-header article))
10380       (if (not (vectorp header))
10381           ;; This is a pseudo-article.
10382           (if (assq 'name header)
10383               (gnus-copy-file (cdr (assq 'name header)))
10384             (gnus-message 1 "Article %d is unsaveable" article))
10385         ;; This is a real article.
10386         (save-window-excursion
10387           (let ((gnus-display-mime-function nil)
10388                 (gnus-article-prepare-hook nil))
10389             (gnus-summary-select-article t nil nil article)))
10390         (save-excursion
10391           (set-buffer save-buffer)
10392           (erase-buffer)
10393           (insert-buffer-substring gnus-original-article-buffer))
10394         (setq file (gnus-article-save save-buffer file num))
10395         (gnus-summary-remove-process-mark article)
10396         (unless not-saved
10397           (gnus-summary-set-saved-mark article))))
10398     (gnus-kill-buffer save-buffer)
10399     (gnus-summary-position-point)
10400     (gnus-set-mode-line 'summary)
10401     n))
10402
10403 (defun gnus-summary-pipe-output (&optional arg)
10404   "Pipe the current article to a subprocess.
10405 If N is a positive number, pipe the N next articles.
10406 If N is a negative number, pipe the N previous articles.
10407 If N is nil and any articles have been marked with the process mark,
10408 pipe those articles instead."
10409   (interactive "P")
10410   (require 'gnus-art)
10411   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10412     (gnus-summary-save-article arg t))
10413   (let ((buffer (get-buffer "*Shell Command Output*")))
10414     (if (and buffer
10415              (with-current-buffer buffer (> (point-max) (point-min))))
10416         (gnus-configure-windows 'pipe))))
10417
10418 (defun gnus-summary-save-article-mail (&optional arg)
10419   "Append the current article to an mail file.
10420 If N is a positive number, save the N next articles.
10421 If N is a negative number, save the N previous articles.
10422 If N is nil and any articles have been marked with the process mark,
10423 save those articles instead."
10424   (interactive "P")
10425   (require 'gnus-art)
10426   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10427     (gnus-summary-save-article arg)))
10428
10429 (defun gnus-summary-save-article-rmail (&optional arg)
10430   "Append the current article to an rmail file.
10431 If N is a positive number, save the N next articles.
10432 If N is a negative number, save the N previous articles.
10433 If N is nil and any articles have been marked with the process mark,
10434 save those articles instead."
10435   (interactive "P")
10436   (require 'gnus-art)
10437   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10438     (gnus-summary-save-article arg)))
10439
10440 (defun gnus-summary-save-article-file (&optional arg)
10441   "Append the current article to a file.
10442 If N is a positive number, save the N next articles.
10443 If N is a negative number, save the N previous articles.
10444 If N is nil and any articles have been marked with the process mark,
10445 save those articles instead."
10446   (interactive "P")
10447   (require 'gnus-art)
10448   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10449     (gnus-summary-save-article arg)))
10450
10451 (defun gnus-summary-write-article-file (&optional arg)
10452   "Write the current article to a file, deleting the previous file.
10453 If N is a positive number, save the N next articles.
10454 If N is a negative number, save the N previous articles.
10455 If N is nil and any articles have been marked with the process mark,
10456 save those articles instead."
10457   (interactive "P")
10458   (require 'gnus-art)
10459   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10460     (gnus-summary-save-article arg)))
10461
10462 (defun gnus-summary-save-article-body-file (&optional arg)
10463   "Append the current article body to a file.
10464 If N is a positive number, save the N next articles.
10465 If N is a negative number, save the N previous articles.
10466 If N is nil and any articles have been marked with the process mark,
10467 save those articles instead."
10468   (interactive "P")
10469   (require 'gnus-art)
10470   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10471     (gnus-summary-save-article arg)))
10472
10473 (defun gnus-summary-muttprint (&optional arg)
10474   "Print the current article using Muttprint.
10475 If N is a positive number, save the N next articles.
10476 If N is a negative number, save the N previous articles.
10477 If N is nil and any articles have been marked with the process mark,
10478 save those articles instead."
10479   (interactive "P")
10480   (require 'gnus-art)
10481   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10482     (gnus-summary-save-article arg t)))
10483
10484 (defun gnus-summary-pipe-message (program)
10485   "Pipe the current article through PROGRAM."
10486   (interactive "sProgram: ")
10487   (gnus-summary-select-article)
10488   (let ((mail-header-separator ""))
10489     (gnus-eval-in-buffer-window gnus-article-buffer
10490       (save-restriction
10491         (widen)
10492         (let ((start (window-start))
10493               buffer-read-only)
10494           (message-pipe-buffer-body program)
10495           (set-window-start (get-buffer-window (current-buffer)) start))))))
10496
10497 (defun gnus-get-split-value (methods)
10498   "Return a value based on the split METHODS."
10499   (let (split-name method result match)
10500     (when methods
10501       (save-excursion
10502         (set-buffer gnus-original-article-buffer)
10503         (save-restriction
10504           (nnheader-narrow-to-headers)
10505           (while (and methods (not split-name))
10506             (goto-char (point-min))
10507             (setq method (pop methods))
10508             (setq match (car method))
10509             (when (cond
10510                    ((stringp match)
10511                     ;; Regular expression.
10512                     (ignore-errors
10513                       (re-search-forward match nil t)))
10514                    ((gnus-functionp match)
10515                     ;; Function.
10516                     (save-restriction
10517                       (widen)
10518                       (setq result (funcall match gnus-newsgroup-name))))
10519                    ((consp match)
10520                     ;; Form.
10521                     (save-restriction
10522                       (widen)
10523                       (setq result (eval match)))))
10524               (setq split-name (cdr method))
10525               (cond ((stringp result)
10526                      (push (expand-file-name
10527                             result gnus-article-save-directory)
10528                            split-name))
10529                     ((consp result)
10530                      (setq split-name (append result split-name)))))))))
10531     (nreverse split-name)))
10532
10533 (defun gnus-valid-move-group-p (group)
10534   (and (boundp group)
10535        (symbol-name group)
10536        (symbol-value group)
10537        (gnus-get-function (gnus-find-method-for-group
10538                            (symbol-name group)) 'request-accept-article t)))
10539
10540 (defun gnus-read-move-group-name (prompt default articles prefix)
10541   "Read a group name."
10542   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10543          (minibuffer-confirm-incomplete nil) ; XEmacs
10544          (prom
10545           (format "%s %s to:"
10546                   prompt
10547                   (if (> (length articles) 1)
10548                       (format "these %d articles" (length articles))
10549                     "this article")))
10550          (to-newsgroup
10551           (cond
10552            ((null split-name)
10553             (gnus-completing-read-with-default
10554              default prom
10555              gnus-active-hashtb
10556              'gnus-valid-move-group-p
10557              nil prefix
10558              'gnus-group-history))
10559            ((= 1 (length split-name))
10560             (gnus-completing-read-with-default
10561              (car split-name) prom
10562              gnus-active-hashtb
10563              'gnus-valid-move-group-p
10564              nil nil
10565              'gnus-group-history))
10566            (t
10567             (gnus-completing-read-with-default
10568              nil prom
10569              (mapcar (lambda (el) (list el))
10570                      (nreverse split-name))
10571              nil nil nil
10572              'gnus-group-history))))
10573          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10574     (when to-newsgroup
10575       (if (or (string= to-newsgroup "")
10576               (string= to-newsgroup prefix))
10577           (setq to-newsgroup default))
10578       (unless to-newsgroup
10579         (error "No group name entered"))
10580       (or (gnus-active to-newsgroup)
10581           (gnus-activate-group to-newsgroup nil nil to-method)
10582           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10583                                      to-newsgroup))
10584               (or (and (gnus-request-create-group to-newsgroup to-method)
10585                        (gnus-activate-group
10586                         to-newsgroup nil nil to-method)
10587                        (gnus-subscribe-group to-newsgroup))
10588                   (error "Couldn't create group %s" to-newsgroup)))
10589           (error "No such group: %s" to-newsgroup)))
10590     to-newsgroup))
10591
10592 (defun gnus-summary-save-parts (type dir n &optional reverse)
10593   "Save parts matching TYPE to DIR.
10594 If REVERSE, save parts that do not match TYPE."
10595   (interactive
10596    (list (read-string "Save parts of type: "
10597                       (or (car gnus-summary-save-parts-type-history)
10598                           gnus-summary-save-parts-default-mime)
10599                       'gnus-summary-save-parts-type-history)
10600          (setq gnus-summary-save-parts-last-directory
10601                (read-file-name "Save to directory: "
10602                                gnus-summary-save-parts-last-directory
10603                                nil t))
10604          current-prefix-arg))
10605   (gnus-summary-iterate n
10606     (let ((gnus-display-mime-function nil)
10607           (gnus-inhibit-treatment t))
10608       (gnus-summary-select-article))
10609     (save-excursion
10610       (set-buffer gnus-article-buffer)
10611       (let ((handles (or gnus-article-mime-handles
10612                          (mm-dissect-buffer nil gnus-article-loose-mime)
10613                          (mm-uu-dissect))))
10614         (when handles
10615           (gnus-summary-save-parts-1 type dir handles reverse)
10616           (unless gnus-article-mime-handles ;; Don't destroy this case.
10617             (mm-destroy-parts handles)))))))
10618
10619 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10620   (if (stringp (car handle))
10621       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10622               (cdr handle))
10623     (when (if reverse
10624               (not (string-match type (mm-handle-media-type handle)))
10625             (string-match type (mm-handle-media-type handle)))
10626       (let ((file (expand-file-name
10627                    (file-name-nondirectory
10628                     (or
10629                      (mail-content-type-get
10630                       (mm-handle-disposition handle) 'filename)
10631                      (concat gnus-newsgroup-name
10632                              "." (number-to-string
10633                                   (cdr gnus-article-current)))))
10634                    dir)))
10635         (unless (file-exists-p file)
10636           (mm-save-part-to-file handle file))))))
10637
10638 ;; Summary extract commands
10639
10640 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10641   (let ((buffer-read-only nil)
10642         (article (gnus-summary-article-number))
10643         after-article b e)
10644     (unless (gnus-summary-goto-subject article)
10645       (error "No such article: %d" article))
10646     (gnus-summary-position-point)
10647     ;; If all commands are to be bunched up on one line, we collect
10648     ;; them here.
10649     (unless gnus-view-pseudos-separately
10650       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10651             files action)
10652         (while ps
10653           (setq action (cdr (assq 'action (car ps))))
10654           (setq files (list (cdr (assq 'name (car ps)))))
10655           (while (and ps (cdr ps)
10656                       (string= (or action "1")
10657                                (or (cdr (assq 'action (cadr ps))) "2")))
10658             (push (cdr (assq 'name (cadr ps))) files)
10659             (setcdr ps (cddr ps)))
10660           (when files
10661             (when (not (string-match "%s" action))
10662               (push " " files))
10663             (push " " files)
10664             (when (assq 'execute (car ps))
10665               (setcdr (assq 'execute (car ps))
10666                       (funcall (if (string-match "%s" action)
10667                                    'format 'concat)
10668                                action
10669                                (mapconcat
10670                                 (lambda (f)
10671                                   (if (equal f " ")
10672                                       f
10673                                     (mm-quote-arg f)))
10674                                 files " ")))))
10675           (setq ps (cdr ps)))))
10676     (if (and gnus-view-pseudos (not not-view))
10677         (while pslist
10678           (when (assq 'execute (car pslist))
10679             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10680                                   (eq gnus-view-pseudos 'not-confirm)))
10681           (setq pslist (cdr pslist)))
10682       (save-excursion
10683         (while pslist
10684           (setq after-article (or (cdr (assq 'article (car pslist)))
10685                                   (gnus-summary-article-number)))
10686           (gnus-summary-goto-subject after-article)
10687           (forward-line 1)
10688           (setq b (point))
10689           (insert "    " (file-name-nondirectory
10690                           (cdr (assq 'name (car pslist))))
10691                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10692           (setq e (point))
10693           (forward-line -1)             ; back to `b'
10694           (gnus-add-text-properties
10695            b (1- e) (list 'gnus-number gnus-reffed-article-number
10696                           gnus-mouse-face-prop gnus-mouse-face))
10697           (gnus-data-enter
10698            after-article gnus-reffed-article-number
10699            gnus-unread-mark b (car pslist) 0 (- e b))
10700           (setq gnus-newsgroup-unreads
10701                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10702                                          gnus-reffed-article-number))
10703           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10704           (setq pslist (cdr pslist)))))))
10705
10706 (defun gnus-pseudos< (p1 p2)
10707   (let ((c1 (cdr (assq 'action p1)))
10708         (c2 (cdr (assq 'action p2))))
10709     (and c1 c2 (string< c1 c2))))
10710
10711 (defun gnus-request-pseudo-article (props)
10712   (cond ((assq 'execute props)
10713          (gnus-execute-command (cdr (assq 'execute props)))))
10714   (let ((gnus-current-article (gnus-summary-article-number)))
10715     (gnus-run-hooks 'gnus-mark-article-hook)))
10716
10717 (defun gnus-execute-command (command &optional automatic)
10718   (save-excursion
10719     (gnus-article-setup-buffer)
10720     (set-buffer gnus-article-buffer)
10721     (setq buffer-read-only nil)
10722     (let ((command (if automatic command
10723                      (read-string "Command: " (cons command 0)))))
10724       (erase-buffer)
10725       (insert "$ " command "\n\n")
10726       (if gnus-view-pseudo-asynchronously
10727           (start-process "gnus-execute" (current-buffer) shell-file-name
10728                          shell-command-switch command)
10729         (call-process shell-file-name nil t nil
10730                       shell-command-switch command)))))
10731
10732 ;; Summary kill commands.
10733
10734 (defun gnus-summary-edit-global-kill (article)
10735   "Edit the \"global\" kill file."
10736   (interactive (list (gnus-summary-article-number)))
10737   (gnus-group-edit-global-kill article))
10738
10739 (defun gnus-summary-edit-local-kill ()
10740   "Edit a local kill file applied to the current newsgroup."
10741   (interactive)
10742   (setq gnus-current-headers (gnus-summary-article-header))
10743   (gnus-group-edit-local-kill
10744    (gnus-summary-article-number) gnus-newsgroup-name))
10745
10746 ;;; Header reading.
10747
10748 (defun gnus-read-header (id &optional header)
10749   "Read the headers of article ID and enter them into the Gnus system."
10750   (let ((group gnus-newsgroup-name)
10751         (gnus-override-method
10752          (or
10753           gnus-override-method
10754           (and (gnus-news-group-p gnus-newsgroup-name)
10755                (car (gnus-refer-article-methods)))))
10756         where)
10757     ;; First we check to see whether the header in question is already
10758     ;; fetched.
10759     (if (stringp id)
10760         ;; This is a Message-ID.
10761         (setq header (or header (gnus-id-to-header id)))
10762       ;; This is an article number.
10763       (setq header (or header (gnus-summary-article-header id))))
10764     (if (and header
10765              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10766         ;; We have found the header.
10767         header
10768       ;; If this is a sparse article, we have to nix out its
10769       ;; previous entry in the thread hashtb.
10770       (when (and header
10771                  (gnus-summary-article-sparse-p (mail-header-number header)))
10772         (let* ((parent (gnus-parent-id (mail-header-references header)))
10773                (thread (and parent (gnus-id-to-thread parent))))
10774           (when thread
10775             (delq (assq header thread) thread))))
10776       ;; We have to really fetch the header to this article.
10777       (save-excursion
10778         (set-buffer nntp-server-buffer)
10779         (when (setq where (gnus-request-head id group))
10780           (nnheader-fold-continuation-lines)
10781           (goto-char (point-max))
10782           (insert ".\n")
10783           (goto-char (point-min))
10784           (insert "211 ")
10785           (princ (cond
10786                   ((numberp id) id)
10787                   ((cdr where) (cdr where))
10788                   (header (mail-header-number header))
10789                   (t gnus-reffed-article-number))
10790                  (current-buffer))
10791           (insert " Article retrieved.\n"))
10792         (if (or (not where)
10793                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10794             ()                          ; Malformed head.
10795           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10796             (when (and (stringp id)
10797                        (not (string= (gnus-group-real-name group)
10798                                      (car where))))
10799               ;; If we fetched by Message-ID and the article came
10800               ;; from a different group, we fudge some bogus article
10801               ;; numbers for this article.
10802               (mail-header-set-number header gnus-reffed-article-number))
10803             (save-excursion
10804               (set-buffer gnus-summary-buffer)
10805               (decf gnus-reffed-article-number)
10806               (gnus-remove-header (mail-header-number header))
10807               (push header gnus-newsgroup-headers)
10808               (setq gnus-current-headers header)
10809               (push (mail-header-number header) gnus-newsgroup-limit)))
10810           header)))))
10811
10812 (defun gnus-remove-header (number)
10813   "Remove header NUMBER from `gnus-newsgroup-headers'."
10814   (if (and gnus-newsgroup-headers
10815            (= number (mail-header-number (car gnus-newsgroup-headers))))
10816       (pop gnus-newsgroup-headers)
10817     (let ((headers gnus-newsgroup-headers))
10818       (while (and (cdr headers)
10819                   (not (= number (mail-header-number (cadr headers)))))
10820         (pop headers))
10821       (when (cdr headers)
10822         (setcdr headers (cddr headers))))))
10823
10824 ;;;
10825 ;;; summary highlights
10826 ;;;
10827
10828 (defun gnus-highlight-selected-summary ()
10829   "Highlight selected article in summary buffer."
10830   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10831   (when gnus-summary-selected-face
10832     (save-excursion
10833       (let* ((beg (progn (beginning-of-line) (point)))
10834              (end (progn (end-of-line) (point)))
10835              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10836              (from (if (get-text-property beg gnus-mouse-face-prop)
10837                        beg
10838                      (or (next-single-property-change
10839                           beg gnus-mouse-face-prop nil end)
10840                          beg)))
10841              (to
10842               (if (= from end)
10843                   (- from 2)
10844                 (or (next-single-property-change
10845                      from gnus-mouse-face-prop nil end)
10846                     end))))
10847         ;; If no mouse-face prop on line we will have to = from = end,
10848         ;; so we highlight the entire line instead.
10849         (when (= (+ to 2) from)
10850           (setq from beg)
10851           (setq to end))
10852         (if gnus-newsgroup-selected-overlay
10853             ;; Move old overlay.
10854             (gnus-move-overlay
10855              gnus-newsgroup-selected-overlay from to (current-buffer))
10856           ;; Create new overlay.
10857           (gnus-overlay-put
10858            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10859            'face gnus-summary-selected-face))))))
10860
10861 (defvar gnus-summary-highlight-line-cached nil)
10862 (defvar gnus-summary-highlight-line-trigger nil)
10863 (defun gnus-summary-highlight-line-0 ()
10864   (if (and (eq gnus-summary-highlight-line-trigger 
10865                gnus-summary-highlight)
10866            gnus-summary-highlight-line-cached)
10867       gnus-summary-highlight-line-cached
10868     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
10869           gnus-summary-highlight-line-cached
10870           (let* ((cond (list 'cond))
10871                  (c cond)
10872                  (list gnus-summary-highlight))
10873             (while list
10874               (setcdr c (cons (list (caar list) (list 'quote (cdar list))) nil))
10875               (setq c (cdr c)
10876                     list (cdr list)))
10877             (gnus-byte-compile (list 'lambda nil cond))))))
10878
10879 (defvar gnus-summary-highlight-line-downloaded-alist nil)
10880 (defvar gnus-summary-highlight-line-downloaded-cached nil)
10881
10882 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10883 (defun gnus-summary-highlight-line ()
10884   "Highlight current line according to `gnus-summary-highlight'."
10885   (let*
10886       ((list gnus-summary-highlight)
10887        (beg (gnus-point-at-bol))
10888        (article (gnus-summary-article-number))
10889        (score (or (cdr (assq (or article gnus-current-article)
10890                              gnus-newsgroup-scored))
10891                   gnus-summary-default-score 0))
10892        (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10893        (inhibit-read-only t)
10894        (default gnus-summary-default-score)
10895        (default-high gnus-summary-default-high-score)
10896        (default-low gnus-summary-default-low-score)
10897        (downloaded
10898         (and
10899          (boundp 'gnus-agent-article-alist)
10900          gnus-agent-article-alist
10901          ;; Optimized for when gnus-summary-highlight-line is
10902          ;; called multiple times for articles in ascending
10903          ;; order (i.e. initial generation of summary buffer).
10904          (progn 
10905            (unless (and
10906                     (eq gnus-summary-highlight-line-downloaded-alist
10907                         gnus-agent-article-alist)
10908                     (<= (caar gnus-summary-highlight-line-downloaded-cached)
10909                         article))
10910              (setq gnus-summary-highlight-line-downloaded-alist
10911                    gnus-agent-article-alist)
10912              (setq gnus-summary-highlight-line-downloaded-cached
10913                    gnus-agent-article-alist))
10914            (let (n)
10915              (while (and (< (caar gnus-summary-highlight-line-downloaded-cached)
10916                             article)
10917                          (setq n (cdr gnus-summary-highlight-line-downloaded-cached)))
10918                (setq gnus-summary-highlight-line-downloaded-cached n)))
10919            (and (eq (caar gnus-summary-highlight-line-downloaded-cached) article)
10920                 (cdar gnus-summary-highlight-line-downloaded-cached))))))
10921     (let ((face (funcall (gnus-summary-highlight-line-0))))
10922       (unless (eq face (get-text-property beg 'face))
10923         (gnus-put-text-property-excluding-characters-with-faces
10924          beg (gnus-point-at-eol) 'face
10925          (setq face (if (boundp face) (symbol-value face) face)))
10926         (when gnus-summary-highlight-line-function
10927           (funcall gnus-summary-highlight-line-function article face))))))
10928
10929 (defun gnus-update-read-articles (group unread &optional compute)
10930   "Update the list of read articles in GROUP.
10931 UNREAD is a sorted list."
10932   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10933          (entry (gnus-gethash group gnus-newsrc-hashtb))
10934          (info (nth 2 entry))
10935          (prev 1)
10936          read)
10937     (if (or (not info) (not active))
10938         ;; There is no info on this group if it was, in fact,
10939         ;; killed.  Gnus stores no information on killed groups, so
10940         ;; there's nothing to be done.
10941         ;; One could store the information somewhere temporarily,
10942         ;; perhaps...  Hmmm...
10943         ()
10944       ;; Remove any negative articles numbers.
10945       (while (and unread (< (car unread) 0))
10946         (setq unread (cdr unread)))
10947       ;; Remove any expired article numbers
10948       (while (and unread (< (car unread) (car active)))
10949         (setq unread (cdr unread)))
10950       ;; Compute the ranges of read articles by looking at the list of
10951       ;; unread articles.
10952       (while unread
10953         (when (/= (car unread) prev)
10954           (push (if (= prev (1- (car unread))) prev
10955                   (cons prev (1- (car unread))))
10956                 read))
10957         (setq prev (1+ (car unread)))
10958         (setq unread (cdr unread)))
10959       (when (<= prev (cdr active))
10960         (push (cons prev (cdr active)) read))
10961       (setq read (if (> (length read) 1) (nreverse read) read))
10962       (if compute
10963           read
10964         (save-excursion
10965           (let (setmarkundo)
10966             ;; Propagate the read marks to the backend.
10967             (when (gnus-check-backend-function 'request-set-mark group)
10968               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10969                     (add (gnus-remove-from-range read (gnus-info-read info))))
10970                 (when (or add del)
10971                   (unless (gnus-check-group group)
10972                     (error "Can't open server for %s" group))
10973                   (gnus-request-set-mark
10974                    group (delq nil (list (if add (list add 'add '(read)))
10975                                          (if del (list del 'del '(read))))))
10976                   (setq setmarkundo
10977                         `(gnus-request-set-mark
10978                           ,group
10979                           ',(delq nil (list
10980                                        (if del (list del 'add '(read)))
10981                                        (if add (list add 'del '(read))))))))))
10982             (set-buffer gnus-group-buffer)
10983             (gnus-undo-register
10984               `(progn
10985                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10986                  (gnus-info-set-read ',info ',(gnus-info-read info))
10987                  (gnus-get-unread-articles-in-group ',info
10988                                                     (gnus-active ,group))
10989                  (gnus-group-update-group ,group t)
10990                  ,setmarkundo))))
10991         ;; Enter this list into the group info.
10992         (gnus-info-set-read info read)
10993         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10994         (gnus-get-unread-articles-in-group info (gnus-active group))
10995         t))))
10996
10997 (defun gnus-offer-save-summaries ()
10998   "Offer to save all active summary buffers."
10999   (let (buffers)
11000     ;; Go through all buffers and find all summaries.
11001     (dolist (buffer (buffer-list))
11002       (when (and (setq buffer (buffer-name buffer))
11003                  (string-match "Summary" buffer)
11004                  (save-excursion
11005                    (set-buffer buffer)
11006                    ;; We check that this is, indeed, a summary buffer.
11007                    (and (eq major-mode 'gnus-summary-mode)
11008                         ;; Also make sure this isn't bogus.
11009                         gnus-newsgroup-prepared
11010                         ;; Also make sure that this isn't a
11011                         ;; dead summary buffer.
11012                         (not gnus-dead-summary-mode))))
11013         (push buffer buffers)))
11014     ;; Go through all these summary buffers and offer to save them.
11015     (when buffers
11016       (save-excursion
11017         (map-y-or-n-p
11018          "Update summary buffer %s? "
11019          (lambda (buf)
11020            (switch-to-buffer buf)
11021            (gnus-summary-exit))
11022          buffers)))))
11023
11024 (defun gnus-summary-setup-default-charset ()
11025   "Setup newsgroup default charset."
11026   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11027       (setq gnus-newsgroup-charset nil)
11028     (let* ((ignored-charsets
11029             (or gnus-newsgroup-ephemeral-ignored-charsets
11030                 (append
11031                  (and gnus-newsgroup-name
11032                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11033                  gnus-newsgroup-ignored-charsets))))
11034       (setq gnus-newsgroup-charset
11035             (or gnus-newsgroup-ephemeral-charset
11036                 (and gnus-newsgroup-name
11037                      (gnus-parameter-charset gnus-newsgroup-name))
11038                 gnus-default-charset))
11039       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11040            ignored-charsets))))
11041
11042 ;;;
11043 ;;; Mime Commands
11044 ;;;
11045
11046 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11047   "Display the current article buffer fully MIME-buttonized.
11048 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11049 treated as multipart/mixed."
11050   (interactive "P")
11051   (require 'gnus-art)
11052   (let ((gnus-unbuttonized-mime-types nil)
11053         (gnus-mime-display-multipart-as-mixed show-all-parts))
11054     (gnus-summary-show-article)))
11055
11056 (defun gnus-summary-repair-multipart (article)
11057   "Add a Content-Type header to a multipart article without one."
11058   (interactive (list (gnus-summary-article-number)))
11059   (gnus-with-article article
11060     (message-narrow-to-head)
11061     (message-remove-header "Mime-Version")
11062     (goto-char (point-max))
11063     (insert "Mime-Version: 1.0\n")
11064     (widen)
11065     (when (search-forward "\n--" nil t)
11066       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11067         (message-narrow-to-head)
11068         (message-remove-header "Content-Type")
11069         (goto-char (point-max))
11070         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11071                         separator))
11072         (widen))))
11073   (let (gnus-mark-article-hook)
11074     (gnus-summary-select-article t t nil article)))
11075
11076 (defun gnus-summary-toggle-display-buttonized ()
11077   "Toggle the buttonizing of the article buffer."
11078   (interactive)
11079   (require 'gnus-art)
11080   (if (setq gnus-inhibit-mime-unbuttonizing
11081             (not gnus-inhibit-mime-unbuttonizing))
11082       (let ((gnus-unbuttonized-mime-types nil))
11083         (gnus-summary-show-article))
11084     (gnus-summary-show-article)))
11085
11086 ;;;
11087 ;;; Generic summary marking commands
11088 ;;;
11089
11090 (defvar gnus-summary-marking-alist
11091   '((read gnus-del-mark "d")
11092     (unread gnus-unread-mark "u")
11093     (ticked gnus-ticked-mark "!")
11094     (dormant gnus-dormant-mark "?")
11095     (expirable gnus-expirable-mark "e"))
11096   "An alist of names/marks/keystrokes.")
11097
11098 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11099 (defvar gnus-summary-mark-map)
11100
11101 (defun gnus-summary-make-all-marking-commands ()
11102   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11103   (dolist (elem gnus-summary-marking-alist)
11104     (apply 'gnus-summary-make-marking-command elem)))
11105
11106 (defun gnus-summary-make-marking-command (name mark keystroke)
11107   (let ((map (make-sparse-keymap)))
11108     (define-key gnus-summary-generic-mark-map keystroke map)
11109     (dolist (lway `((next "next" next nil "n")
11110                     (next-unread "next unread" next t "N")
11111                     (prev "previous" prev nil "p")
11112                     (prev-unread "previous unread" prev t "P")
11113                     (nomove "" nil nil ,keystroke)))
11114       (let ((func (gnus-summary-make-marking-command-1
11115                    mark (car lway) lway name)))
11116         (setq func (eval func))
11117         (define-key map (nth 4 lway) func)))))
11118
11119 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11120   `(defun ,(intern
11121             (format "gnus-summary-put-mark-as-%s%s"
11122                     name (if (eq way 'nomove)
11123                              ""
11124                            (concat "-" (symbol-name way)))))
11125      (n)
11126      ,(format
11127        "Mark the current article as %s%s.
11128 If N, the prefix, then repeat N times.
11129 If N is negative, move in reverse order.
11130 The difference between N and the actual number of articles marked is
11131 returned."
11132        name (cadr lway))
11133      (interactive "p")
11134      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11135
11136 (defun gnus-summary-generic-mark (n mark move unread)
11137   "Mark N articles with MARK."
11138   (unless (eq major-mode 'gnus-summary-mode)
11139     (error "This command can only be used in the summary buffer"))
11140   (gnus-summary-show-thread)
11141   (let ((nummove
11142          (cond
11143           ((eq move 'next) 1)
11144           ((eq move 'prev) -1)
11145           (t 0))))
11146     (if (zerop nummove)
11147         (setq n 1)
11148       (when (< n 0)
11149         (setq n (abs n)
11150               nummove (* -1 nummove))))
11151     (while (and (> n 0)
11152                 (gnus-summary-mark-article nil mark)
11153                 (zerop (gnus-summary-next-subject nummove unread t)))
11154       (setq n (1- n)))
11155     (when (/= 0 n)
11156       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11157     (gnus-summary-recenter)
11158     (gnus-summary-position-point)
11159     (gnus-set-mode-line 'summary)
11160     n))
11161
11162 (defun gnus-summary-insert-articles (articles)
11163   (when (setq articles
11164               (gnus-sorted-difference articles
11165                                       (mapcar (lambda (h)
11166                                                 (mail-header-number h))
11167                                               gnus-newsgroup-headers)))
11168     (setq gnus-newsgroup-headers
11169           (merge 'list
11170                  gnus-newsgroup-headers
11171                  (gnus-fetch-headers articles)
11172                  'gnus-article-sort-by-number))
11173     ;; Suppress duplicates?
11174     (when gnus-suppress-duplicates
11175       (gnus-dup-suppress-articles))
11176
11177     ;; We might want to build some more threads first.
11178     (when (and gnus-fetch-old-headers
11179                (eq gnus-headers-retrieved-by 'nov))
11180       (if (eq gnus-fetch-old-headers 'invisible)
11181           (gnus-build-all-threads)
11182         (gnus-build-old-threads)))
11183     ;; Let the Gnus agent mark articles as read.
11184     (when gnus-agent
11185       (gnus-agent-get-undownloaded-list))
11186     ;; Remove list identifiers from subject
11187     (when gnus-list-identifiers
11188       (gnus-summary-remove-list-identifiers))
11189     ;; First and last article in this newsgroup.
11190     (when gnus-newsgroup-headers
11191       (setq gnus-newsgroup-begin
11192             (mail-header-number (car gnus-newsgroup-headers))
11193             gnus-newsgroup-end
11194             (mail-header-number
11195              (gnus-last-element gnus-newsgroup-headers))))
11196     (when gnus-use-scoring
11197       (gnus-possibly-score-headers))))
11198
11199 (defun gnus-summary-insert-old-articles (&optional all)
11200   "Insert all old articles in this group.
11201 If ALL is non-nil, already read articles become readable.
11202 If ALL is a number, fetch this number of articles."
11203   (interactive "P")
11204   (prog1
11205       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11206             older len)
11207         (setq older
11208               ;; Some nntp servers lie about their active range.  When this happens, the active
11209               ;; range can be in the millions.
11210               ;; Use a compressed range to avoid creating a huge list.
11211               (gnus-range-difference (list gnus-newsgroup-active) old))
11212         (setq len (gnus-range-length older))
11213         (cond
11214          ((null older) nil)
11215          ((numberp all)
11216           (if (< all len)
11217               (let ((older-range (nreverse older)))
11218                 (setq older nil)
11219
11220                 (while (> all 0)
11221                   (let* ((r (pop older-range))
11222                          (min (if (numberp r) r (car r)))
11223                          (max (if (numberp r) r (cdr r))))
11224                     (while (and (<= min max)
11225                                 (> all 0))
11226                       (push max older)
11227                       (setq all (1- all)
11228                             max (1- max))))))
11229             (setq older (gnus-uncompress-range older))))
11230          (all
11231           (setq older (gnus-uncompress-range older)))
11232          (t
11233           (when (and (numberp gnus-large-newsgroup)
11234                    (> len gnus-large-newsgroup))
11235               (let* ((cursor-in-echo-area nil)
11236                      (initial (gnus-parameter-large-newsgroup-initial
11237                                gnus-newsgroup-name))
11238                      (input
11239                       (read-string
11240                        (format
11241                         "How many articles from %s (%s %d): "
11242                         (gnus-limit-string
11243                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11244                         (if initial "max" "default")
11245                         len)
11246                        (if initial
11247                            (cons (number-to-string initial)
11248                                  0)))))
11249                 (unless (string-match "^[ \t]*$" input)
11250                   (setq all (string-to-number input))
11251                   (if (< all len)
11252                       (let ((older-range (nreverse older)))
11253                         (setq older nil)
11254
11255                         (while (> all 0)
11256                           (let* ((r (pop older-range))
11257                                  (min (if (numberp r) r (car r)))
11258                                  (max (if (numberp r) r (cdr r))))
11259                             (while (and (<= min max)
11260                                         (> all 0))
11261                               (push max older)
11262                               (setq all (1- all)
11263                                     max (1- max))))))))))
11264           (setq older (gnus-uncompress-range older))))
11265         (if (not older)
11266             (message "No old news.")
11267           (gnus-summary-insert-articles older)
11268           (gnus-summary-limit (gnus-sorted-nunion old older))))
11269     (gnus-summary-position-point)))
11270
11271 (defun gnus-summary-insert-new-articles ()
11272   "Insert all new articles in this group."
11273   (interactive)
11274   (prog1
11275       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11276             (old-active gnus-newsgroup-active)
11277             (nnmail-fetched-sources (list t))
11278             i new)
11279         (setq gnus-newsgroup-active
11280               (gnus-activate-group gnus-newsgroup-name 'scan))
11281         (setq i (cdr gnus-newsgroup-active))
11282         (while (> i (cdr old-active))
11283           (push i new)
11284           (decf i))
11285         (if (not new)
11286             (message "No gnus is bad news.")
11287           (gnus-summary-insert-articles new)
11288           (setq gnus-newsgroup-unreads
11289                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11290           (gnus-summary-limit (gnus-sorted-nunion old new))))
11291     (gnus-summary-position-point)))
11292
11293 (gnus-summary-make-all-marking-commands)
11294
11295 (gnus-ems-redefine)
11296
11297 (provide 'gnus-sum)
11298
11299 (run-hooks 'gnus-sum-load-hook)
11300
11301 ;;; gnus-sum.el ends here