(gnus-summary-tool-bar-gnome): Don't use
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-fetch-old-headers nil
66   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
67 If an unread article in the group refers to an older, already
68 read (or just marked as read) article, the old article will not
69 normally be displayed in the Summary buffer.  If this variable is
70 t, Gnus will attempt to grab the headers to the old articles, and
71 thereby build complete threads.  If it has the value `some', all
72 old headers will be fetched but only enough headers to connect
73 otherwise loose threads will be displayed.  This variable can
74 also be a number.  In that case, no more than that number of old
75 headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work.
79
80 This feature can seriously impact performance it ignores all
81 locally cached header entries."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const :tag "on" t)
85                  (const some)
86                  (const invisible)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 200
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :version "22.1"
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :version "22.1"
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-zcore-fuzz 0
242   "*Fuzziness factor for the zcore in the summary buffer.
243 Articles with scores closer than this to `gnus-summary-default-score'
244 will not be marked."
245   :group 'gnus-summary-format
246   :type 'integer)
247
248 (defcustom gnus-simplify-subject-fuzzy-regexp nil
249   "*Strings to be removed when doing fuzzy matches.
250 This can either be a regular expression or list of regular expressions
251 that will be removed from subject strings if fuzzy subject
252 simplification is selected."
253   :group 'gnus-thread
254   :type '(repeat regexp))
255
256 (defcustom gnus-show-threads t
257   "*If non-nil, display threads in summary mode."
258   :group 'gnus-thread
259   :type 'boolean)
260
261 (defcustom gnus-thread-hide-subtree nil
262   "*If non-nil, hide all threads initially.
263 This can be a predicate specifier which says which threads to hide.
264 If threads are hidden, you have to run the command
265 `gnus-summary-show-thread' by hand or select an article."
266   :group 'gnus-thread
267   :type '(radio (sexp :format "Non-nil\n"
268                       :match (lambda (widget value)
269                                (not (or (consp value) (functionp value))))
270                       :value t)
271                 (const nil)
272                 (sexp :tag "Predicate specifier")))
273
274 (defcustom gnus-thread-hide-killed t
275   "*If non-nil, hide killed threads automatically."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-ignore-subject t
280   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
281 If nil, articles that have different subjects from their parents will
282 start separate threads."
283   :group 'gnus-thread
284   :type 'boolean)
285
286 (defcustom gnus-thread-operation-ignore-subject t
287   "*If non-nil, subjects will be ignored when doing thread commands.
288 This affects commands like `gnus-summary-kill-thread' and
289 `gnus-summary-lower-thread'.
290
291 If this variable is nil, articles in the same thread with different
292 subjects will not be included in the operation in question.  If this
293 variable is `fuzzy', only articles that have subjects that are fuzzily
294 equal will be included."
295   :group 'gnus-thread
296   :type '(choice (const :tag "off" nil)
297                  (const fuzzy)
298                  (sexp :tag "on" t)))
299
300 (defcustom gnus-thread-indent-level 4
301   "*Number that says how much each sub-thread should be indented."
302   :group 'gnus-thread
303   :type 'integer)
304
305 (defcustom gnus-auto-extend-newsgroup t
306   "*If non-nil, extend newsgroup forward and backward when requested."
307   :group 'gnus-summary-choose
308   :type 'boolean)
309
310 (defcustom gnus-auto-select-first t
311   "*If non-nil, select the article under point.
312 Which article this is is controlled by the `gnus-auto-select-subject'
313 variable.
314
315 If you want to prevent automatic selection of articles in some
316 newsgroups, set the variable to nil in `gnus-select-group-hook'."
317   :group 'gnus-group-select
318   :type '(choice (const :tag "none" nil)
319                  (sexp :menu-tag "first" t)))
320
321 (defcustom gnus-auto-select-subject 'unread
322   "*Says what subject to place under point when entering a group.
323
324 This variable can either be the symbols `first' (place point on the
325 first subject), `unread' (place point on the subject line of the first
326 unread article), `best' (place point on the subject line of the
327 higest-scored article), `unseen' (place point on the subject line of
328 the first unseen article), `unseen-or-unread' (place point on the subject
329 line of the first unseen article or, if all article have been seen, on the
330 subject line of the first unread article), or a function to be called to
331 place point on some subject line."
332   :version "22.1"
333   :group 'gnus-group-select
334   :type '(choice (const best)
335                  (const unread)
336                  (const first)
337                  (const unseen)
338                  (const unseen-or-unread)))
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-auto-goto-ignores 'unfetched
366   "*Says how to handle unfetched articles when maneuvering.
367
368 This variable can either be the symbols nil (maneuver to any
369 article), `undownloaded' (maneuvering while unplugged ignores articles
370 that have not been fetched), `always-undownloaded' (maneuvering always
371 ignores articles that have not been fetched), `unfetched' (maneuvering
372 ignores articles whose headers have not been fetched).
373
374 NOTE: The list of unfetched articles will always be nil when plugged
375 and, when unplugged, a subset of the undownloaded article list."
376   :version "22.1"
377   :group 'gnus-summary-maneuvering
378   :type '(choice (const :tag "None" nil)
379                  (const :tag "Undownloaded when unplugged" undownloaded)
380                  (const :tag "Undownloaded" always-undownloaded)
381                  (const :tag "Unfetched" unfetched)))
382
383 (defcustom gnus-summary-check-current nil
384   "*If non-nil, consider the current article when moving.
385 The \"unread\" movement commands will stay on the same line if the
386 current article is unread."
387   :group 'gnus-summary-maneuvering
388   :type 'boolean)
389
390 (defcustom gnus-auto-center-summary 2
391   "*If non-nil, always center the current summary buffer.
392 In particular, if `vertical' do only vertical recentering.  If non-nil
393 and non-`vertical', do both horizontal and vertical recentering."
394   :group 'gnus-summary-maneuvering
395   :type '(choice (const :tag "none" nil)
396                  (const vertical)
397                  (integer :tag "height")
398                  (sexp :menu-tag "both" t)))
399
400 (defvar gnus-auto-center-group t
401   "*If non-nil, always center the group buffer.")
402
403 (defcustom gnus-show-all-headers nil
404   "*If non-nil, don't hide any headers."
405   :group 'gnus-article-hiding
406   :group 'gnus-article-headers
407   :type 'boolean)
408
409 (defcustom gnus-summary-ignore-duplicates nil
410   "*If non-nil, ignore articles with identical Message-ID headers."
411   :group 'gnus-summary
412   :type 'boolean)
413
414 (defcustom gnus-single-article-buffer t
415   "*If non-nil, display all articles in the same buffer.
416 If nil, each group will get its own article buffer."
417   :group 'gnus-article-various
418   :type 'boolean)
419
420 (defcustom gnus-break-pages t
421   "*If non-nil, do page breaking on articles.
422 The page delimiter is specified by the `gnus-page-delimiter'
423 variable."
424   :group 'gnus-article-various
425   :type 'boolean)
426
427 (defcustom gnus-move-split-methods nil
428   "*Variable used to suggest where articles are to be moved to.
429 It uses the same syntax as the `gnus-split-methods' variable.
430 However, whereas `gnus-split-methods' specifies file names as targets,
431 this variable specifies group names."
432   :group 'gnus-summary-mail
433   :type '(repeat (choice (list :value (fun) function)
434                          (cons :value ("" "") regexp (repeat string))
435                          (sexp :value nil))))
436
437 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
438   "Function used to compute default prefix for article move/copy/etc prompts.
439 The function should take one argument, a group name, and return a
440 string with the suggested prefix."
441   :group 'gnus-summary-mail
442   :type 'function)
443
444 ;; FIXME: Although the custom type is `character' for the following variables,
445 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
446
447 (defcustom gnus-unread-mark ?           ;Whitespace
448   "*Mark used for unread articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-ticked-mark ?!
453   "*Mark used for ticked articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-dormant-mark ??
458   "*Mark used for dormant articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-del-mark ?r
463   "*Mark used for del'd articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-read-mark ?R
468   "*Mark used for read articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-expirable-mark ?E
473   "*Mark used for expirable articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-killed-mark ?K
478   "*Mark used for killed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-spam-mark ?$
483   "*Mark used for spam articles."
484   :version "22.1"
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-souped-mark ?F
489   "*Mark used for souped articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-kill-file-mark ?X
494   "*Mark used for articles killed by kill files."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-low-score-mark ?Y
499   "*Mark used for articles with a low score."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-catchup-mark ?C
504   "*Mark used for articles that are caught up."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-replied-mark ?A
509   "*Mark used for articles that have been replied to."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-forwarded-mark ?F
514   "*Mark used for articles that have been forwarded."
515   :version "22.1"
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-recent-mark ?N
520   "*Mark used for articles that are recent."
521   :version "22.1"
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-cached-mark ?*
526   "*Mark used for articles that are in the cache."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-saved-mark ?S
531   "*Mark used for articles that have been saved."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unseen-mark ?.
536   "*Mark used for articles that haven't been seen."
537   :version "22.1"
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-no-mark ?               ;Whitespace
542   "*Mark used for articles that have no other secondary mark."
543   :version "22.1"
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-ancient-mark ?O
548   "*Mark used for ancient articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-sparse-mark ?Q
553   "*Mark used for sparsely reffed articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-canceled-mark ?G
558   "*Mark used for canceled articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-duplicate-mark ?M
563   "*Mark used for duplicate articles."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-undownloaded-mark ?-
568   "*Mark used for articles that weren't downloaded."
569   :version "22.1"
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloaded-mark ?+
574   "*Mark used for articles that were downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-downloadable-mark ?%
579   "*Mark used for articles that are to be downloaded."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-unsendable-mark ?=
584   "*Mark used for articles that won't be sent."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-over-mark ?+
589   "*Score mark used for articles with high scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-score-below-mark ?-
594   "*Score mark used for articles with low scores."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-empty-thread-mark ?     ;Whitespace
599   "*There is no thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-not-empty-thread-mark ?=
604   "*There is a thread under the article."
605   :group 'gnus-summary-marks
606   :type 'character)
607
608 (defcustom gnus-view-pseudo-asynchronously nil
609   "*If non-nil, Gnus will view pseudo-articles asynchronously."
610   :group 'gnus-extract-view
611   :type 'boolean)
612
613 (defcustom gnus-auto-expirable-marks
614   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
615         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
616         gnus-souped-mark gnus-duplicate-mark)
617   "*The list of marks converted into expiration if a group is auto-expirable."
618   :version "21.1"
619   :group 'gnus-summary
620   :type '(repeat character))
621
622 (defcustom gnus-inhibit-user-auto-expire t
623   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
624   :version "21.1"
625   :group 'gnus-summary
626   :type 'boolean)
627
628 (defcustom gnus-view-pseudos nil
629   "*If `automatic', pseudo-articles will be viewed automatically.
630 If `not-confirm', pseudos will be viewed automatically, and the user
631 will not be asked to confirm the command."
632   :group 'gnus-extract-view
633   :type '(choice (const :tag "off" nil)
634                  (const automatic)
635                  (const not-confirm)))
636
637 (defcustom gnus-view-pseudos-separately t
638   "*If non-nil, one pseudo-article will be created for each file to be viewed.
639 If nil, all files that use the same viewing command will be given as a
640 list of parameters to that command."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-insert-pseudo-articles t
645   "*If non-nil, insert pseudo-articles when decoding articles."
646   :group 'gnus-extract-view
647   :type 'boolean)
648
649 (defcustom gnus-summary-dummy-line-format
650   "   %(:                             :%) %S\n"
651   "*The format specification for the dummy roots in the summary buffer.
652 It works along the same lines as a normal formatting string,
653 with some simple extensions.
654
655 %S  The subject
656
657 General format specifiers can also be used.
658 See `(gnus)Formatting Variables'."
659   :link '(custom-manual "(gnus)Formatting Variables")
660   :group 'gnus-threading
661   :type 'string)
662
663 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
664   "*The format specification for the summary mode line.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions:
667
668 %G  Group name
669 %p  Unprefixed group name
670 %A  Current article number
671 %z  Current article score
672 %V  Gnus version
673 %U  Number of unread articles in the group
674 %e  Number of unselected articles in the group
675 %Z  A string with unread/unselected article counts
676 %g  Shortish group name
677 %S  Subject of the current article
678 %u  User-defined spec
679 %s  Current score file name
680 %d  Number of dormant articles
681 %r  Number of articles that have been marked as read in this session
682 %E  Number of articles expunged by the score files"
683   :group 'gnus-summary-format
684   :type 'string)
685
686 (defcustom gnus-list-identifiers nil
687   "Regexp that matches list identifiers to be removed from subject.
688 This can also be a list of regexps."
689   :version "21.1"
690   :group 'gnus-summary-format
691   :group 'gnus-article-hiding
692   :type '(choice (const :tag "none" nil)
693                  (regexp :value ".*")
694                  (repeat :value (".*") regexp)))
695
696 (defcustom gnus-summary-mark-below 0
697   "*Mark all articles with a score below this variable as read.
698 This variable is local to each summary buffer and usually set by the
699 score file."
700   :group 'gnus-score-default
701   :type 'integer)
702
703 (defun gnus-widget-reversible-match (widget value)
704   "Ignoring WIDGET, convert VALUE to internal form.
705 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
706   ;; (debug value)
707   (or (symbolp value)
708       (and (listp value)
709            (eq (length value) 2)
710            (eq (nth 0 value) 'not)
711            (symbolp (nth 1 value)))))
712
713 (defun gnus-widget-reversible-to-internal (widget value)
714   "Ignoring WIDGET, convert VALUE to internal form.
715 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
716 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
717   ;; (debug value)
718   (if (atom value)
719       (list value nil)
720     (list (nth 1 value) t)))
721
722 (defun gnus-widget-reversible-to-external (widget value)
723   "Ignoring WIDGET, convert VALUE to external form.
724 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
725 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
726   ;; (debug value)
727   (if (nth 1 value)
728       (list 'not (nth 0 value))
729     (nth 0 value)))
730
731 (define-widget 'gnus-widget-reversible 'group
732   "A `group' that convert values."
733   :match 'gnus-widget-reversible-match
734   :value-to-internal 'gnus-widget-reversible-to-internal
735   :value-to-external 'gnus-widget-reversible-to-external)
736
737 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
738   "*List of functions used for sorting articles in the summary buffer.
739
740 Each function takes two articles and returns non-nil if the first
741 article should be sorted before the other.  If you use more than one
742 function, the primary sort function should be the last.  You should
743 probably always include `gnus-article-sort-by-number' in the list of
744 sorting functions -- preferably first.  Also note that sorting by date
745 is often much slower than sorting by number, and the sorting order is
746 very similar.  (Sorting by date means sorting by the time the message
747 was sent, sorting by number means sorting by arrival time.)
748
749 Each item can also be a list `(not F)' where F is a function;
750 this reverses the sort order.
751
752 Ready-made functions include `gnus-article-sort-by-number',
753 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
754 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
755 and `gnus-article-sort-by-score'.
756
757 When threading is turned on, the variable `gnus-thread-sort-functions'
758 controls how articles are sorted."
759   :group 'gnus-summary-sort
760   :type '(repeat (gnus-widget-reversible
761                   (choice (function-item gnus-article-sort-by-number)
762                           (function-item gnus-article-sort-by-author)
763                           (function-item gnus-article-sort-by-subject)
764                           (function-item gnus-article-sort-by-date)
765                           (function-item gnus-article-sort-by-score)
766                           (function-item gnus-article-sort-by-random)
767                           (function :tag "other"))
768                   (boolean :tag "Reverse order"))))
769
770
771 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
772   "*List of functions used for sorting threads in the summary buffer.
773 By default, threads are sorted by article number.
774
775 Each function takes two threads and returns non-nil if the first
776 thread should be sorted before the other.  If you use more than one
777 function, the primary sort function should be the last.  You should
778 probably always include `gnus-thread-sort-by-number' in the list of
779 sorting functions -- preferably first.  Also note that sorting by date
780 is often much slower than sorting by number, and the sorting order is
781 very similar.  (Sorting by date means sorting by the time the message
782 was sent, sorting by number means sorting by arrival time.)
783
784 Each list item can also be a list `(not F)' where F is a
785 function; this specifies reversed sort order.
786
787 Ready-made functions include `gnus-thread-sort-by-number',
788 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
789 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
790 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
791 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
792 and `gnus-thread-sort-by-total-score' (see
793 `gnus-thread-score-function').
794
795 When threading is turned off, the variable
796 `gnus-article-sort-functions' controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat
799           (gnus-widget-reversible
800            (choice (function-item gnus-thread-sort-by-number)
801                    (function-item gnus-thread-sort-by-author)
802                    (function-item gnus-thread-sort-by-recipient)
803                    (function-item gnus-thread-sort-by-subject)
804                    (function-item gnus-thread-sort-by-date)
805                    (function-item gnus-thread-sort-by-score)
806                    (function-item gnus-thread-sort-by-most-recent-number)
807                    (function-item gnus-thread-sort-by-most-recent-date)
808                    (function-item gnus-thread-sort-by-random)
809                    (function-item gnus-thread-sort-by-total-score)
810                    (function :tag "other"))
811            (boolean :tag "Reverse order"))))
812
813 (defcustom gnus-thread-score-function '+
814   "*Function used for calculating the total score of a thread.
815
816 The function is called with the scores of the article and each
817 subthread and should then return the score of the thread.
818
819 Some functions you can use are `+', `max', or `min'."
820   :group 'gnus-summary-sort
821   :type 'function)
822
823 (defcustom gnus-summary-expunge-below nil
824   "All articles that have a score less than this variable will be expunged.
825 This variable is local to the summary buffers."
826   :group 'gnus-score-default
827   :type '(choice (const :tag "off" nil)
828                  integer))
829
830 (defcustom gnus-thread-expunge-below nil
831   "All threads that have a total score less than this variable will be expunged.
832 See `gnus-thread-score-function' for en explanation of what a
833 \"thread score\" is.
834
835 This variable is local to the summary buffers."
836   :group 'gnus-threading
837   :group 'gnus-score-default
838   :type '(choice (const :tag "off" nil)
839                  integer))
840
841 (defcustom gnus-summary-mode-hook nil
842   "*A hook for Gnus summary mode.
843 This hook is run before any variables are set in the summary buffer."
844   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
845   :group 'gnus-summary-various
846   :type 'hook)
847
848 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
849 (when (featurep 'xemacs)
850   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
851   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
852   (add-hook 'gnus-summary-mode-hook
853             'gnus-xmas-switch-horizontal-scrollbar-off))
854
855 (defcustom gnus-summary-menu-hook nil
856   "*Hook run after the creation of the summary mode menu."
857   :group 'gnus-summary-visual
858   :type 'hook)
859
860 (defcustom gnus-summary-exit-hook nil
861   "*A hook called on exit from the summary buffer.
862 It will be called with point in the group buffer."
863   :group 'gnus-summary-exit
864   :type 'hook)
865
866 (defcustom gnus-summary-prepare-hook nil
867   "*A hook called after the summary buffer has been generated.
868 If you want to modify the summary buffer, you can use this hook."
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 (defcustom gnus-summary-prepared-hook nil
873   "*A hook called as the last thing after the summary buffer has been generated."
874   :group 'gnus-summary-various
875   :type 'hook)
876
877 (defcustom gnus-summary-generate-hook nil
878   "*A hook run just before generating the summary buffer.
879 This hook is commonly used to customize threading variables and the
880 like."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-select-group-hook nil
885   "*A hook called when a newsgroup is selected.
886
887 If you'd like to simplify subjects like the
888 `gnus-summary-next-same-subject' command does, you can use the
889 following hook:
890
891  (add-hook gnus-select-group-hook
892            (lambda ()
893              (mapcar (lambda (header)
894                        (mail-header-set-subject
895                         header
896                         (gnus-simplify-subject
897                          (mail-header-subject header) 're-only)))
898                      gnus-newsgroup-headers)))"
899   :group 'gnus-group-select
900   :type 'hook)
901
902 (defcustom gnus-select-article-hook nil
903   "*A hook called when an article is selected."
904   :group 'gnus-summary-choose
905   :options '(gnus-agent-fetch-selected-article)
906   :type 'hook)
907
908 (defcustom gnus-visual-mark-article-hook
909   (list 'gnus-highlight-selected-summary)
910   "*Hook run after selecting an article in the summary buffer.
911 It is meant to be used for highlighting the article in some way.  It
912 is not run if `gnus-visual' is nil."
913   :group 'gnus-summary-visual
914   :type 'hook)
915
916 (defcustom gnus-parse-headers-hook nil
917   "*A hook called before parsing the headers."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-exit-group-hook nil
922   "*A hook called when exiting summary mode.
923 This hook is not called from the non-updating exit commands like `Q'."
924   :group 'gnus-various
925   :type 'hook)
926
927 (defcustom gnus-summary-update-hook
928   (list 'gnus-summary-highlight-line)
929   "*A hook called when a summary line is changed.
930 The hook will not be called if `gnus-visual' is nil.
931
932 The default function `gnus-summary-highlight-line' will
933 highlight the line according to the `gnus-summary-highlight'
934 variable."
935   :group 'gnus-summary-visual
936   :type 'hook)
937
938 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
939   "*A hook called when an article is selected for the first time.
940 The hook is intended to mark an article as read (or unread)
941 automatically when it is selected."
942   :group 'gnus-summary-choose
943   :type 'hook)
944
945 (defcustom gnus-group-no-more-groups-hook nil
946   "*A hook run when returning to group mode having no more (unread) groups."
947   :group 'gnus-group-select
948   :type 'hook)
949
950 (defcustom gnus-ps-print-hook nil
951   "*A hook run before ps-printing something from Gnus."
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-move-hook nil
956   "*A hook called after an article is moved, copied, respooled, or crossposted."
957   :version "22.1"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-delete-hook nil
962   "*A hook called after an article is deleted."
963   :version "22.1"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-expire-hook nil
968   "*A hook called after an article is expired."
969   :version "22.1"
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-display-arrow
974   (and (fboundp 'display-graphic-p)
975        (display-graphic-p))
976   "*If non-nil, display an arrow highlighting the current article."
977   :version "22.1"
978   :group 'gnus-summary
979   :type 'boolean)
980
981 (defcustom gnus-summary-selected-face 'gnus-summary-selected
982   "Face used for highlighting the current article in the summary buffer."
983   :group 'gnus-summary-visual
984   :type 'face)
985
986 (defvar gnus-tmp-downloaded nil)
987
988 (defcustom gnus-summary-highlight
989   '(((eq mark gnus-canceled-mark)
990      . gnus-summary-cancelled)
991     ((and uncached (> score default-high))
992      . gnus-summary-high-undownloaded)
993     ((and uncached (< score default-low))
994      . gnus-summary-low-undownloaded)
995     (uncached
996      . gnus-summary-normal-undownloaded)
997     ((and (> score default-high)
998           (or (eq mark gnus-dormant-mark)
999               (eq mark gnus-ticked-mark)))
1000      . gnus-summary-high-ticked)
1001     ((and (< score default-low)
1002           (or (eq mark gnus-dormant-mark)
1003               (eq mark gnus-ticked-mark)))
1004      . gnus-summary-low-ticked)
1005     ((or (eq mark gnus-dormant-mark)
1006          (eq mark gnus-ticked-mark))
1007      . gnus-summary-normal-ticked)
1008     ((and (> score default-high) (eq mark gnus-ancient-mark))
1009      . gnus-summary-high-ancient)
1010     ((and (< score default-low) (eq mark gnus-ancient-mark))
1011      . gnus-summary-low-ancient)
1012     ((eq mark gnus-ancient-mark)
1013      . gnus-summary-normal-ancient)
1014     ((and (> score default-high) (eq mark gnus-unread-mark))
1015      . gnus-summary-high-unread)
1016     ((and (< score default-low) (eq mark gnus-unread-mark))
1017      . gnus-summary-low-unread)
1018     ((eq mark gnus-unread-mark)
1019      . gnus-summary-normal-unread)
1020     ((> score default-high)
1021      . gnus-summary-high-read)
1022     ((< score default-low)
1023      . gnus-summary-low-read)
1024     (t
1025      . gnus-summary-normal-read))
1026   "*Controls the highlighting of summary buffer lines.
1027
1028 A list of (FORM . FACE) pairs.  When deciding how a a particular
1029 summary line should be displayed, each form is evaluated.  The content
1030 of the face field after the first true form is used.  You can change
1031 how those summary lines are displayed, by editing the face field.
1032
1033 You can use the following variables in the FORM field.
1034
1035 score:        The article's score
1036 default:      The default article score.
1037 default-high: The default score for high scored articles.
1038 default-low:  The default score for low scored articles.
1039 below:        The score below which articles are automatically marked as read.
1040 mark:         The article's mark.
1041 uncached:     Non-nil if the article is uncached."
1042   :group 'gnus-summary-visual
1043   :type '(repeat (cons (sexp :tag "Form" nil)
1044                        face)))
1045
1046 (defcustom gnus-alter-header-function nil
1047   "Function called to allow alteration of article header structures.
1048 The function is called with one parameter, the article header vector,
1049 which it may alter in any way."
1050   :type '(choice (const :tag "None" nil)
1051                  function)
1052   :group 'gnus-summary)
1053
1054 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1055   "Variable that says which function should be used to decode a string with encoded words.")
1056
1057 (defcustom gnus-extra-headers '(To Newsgroups)
1058   "*Extra headers to parse."
1059   :version "21.1"
1060   :group 'gnus-summary
1061   :type '(repeat symbol))
1062
1063 (defcustom gnus-ignored-from-addresses
1064   (and user-mail-address  
1065        (not (string= user-mail-address ""))
1066        (regexp-quote user-mail-address))
1067   "*Regexp of From headers that may be suppressed in favor of To headers."
1068   :version "21.1"
1069   :group 'gnus-summary
1070   :type 'regexp)
1071
1072 (defcustom gnus-summary-to-prefix "-> "
1073   "*String prefixed to the To field in the summary line when
1074 using `gnus-ignored-from-addresses'."
1075   :version "22.1"
1076   :group 'gnus-summary
1077   :type 'string)
1078
1079 (defcustom gnus-summary-newsgroup-prefix "=> "
1080   "*String prefixed to the Newsgroup field in the summary
1081 line when using `gnus-ignored-from-addresses'."
1082   :version "22.1"
1083   :group 'gnus-summary
1084   :type 'string)
1085
1086 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1087   "List of charsets that should be ignored.
1088 When these charsets are used in the \"charset\" parameter, the
1089 default charset will be used instead."
1090   :version "21.1"
1091   :type '(repeat symbol)
1092   :group 'gnus-charset)
1093
1094 (gnus-define-group-parameter
1095  ignored-charsets
1096  :type list
1097  :function-document
1098  "Return the ignored charsets of GROUP."
1099  :variable gnus-group-ignored-charsets-alist
1100  :variable-default
1101  '(("alt\\.chinese\\.text" iso-8859-1))
1102  :variable-document
1103  "Alist of regexps (to match group names) and charsets that should be ignored.
1104 When these charsets are used in the \"charset\" parameter, the
1105 default charset will be used instead."
1106  :variable-group gnus-charset
1107  :variable-type '(repeat (cons (regexp :tag "Group")
1108                                (repeat symbol)))
1109  :parameter-type '(choice :tag "Ignored charsets"
1110                           :value nil
1111                           (repeat (symbol)))
1112  :parameter-document       "\
1113 List of charsets that should be ignored.
1114
1115 When these charsets are used in the \"charset\" parameter, the
1116 default charset will be used instead.")
1117
1118 (defcustom gnus-group-highlight-words-alist nil
1119   "Alist of group regexps and highlight regexps.
1120 This variable uses the same syntax as `gnus-emphasis-alist'."
1121   :version "21.1"
1122   :type '(repeat (cons (regexp :tag "Group")
1123                        (repeat (list (regexp :tag "Highlight regexp")
1124                                      (number :tag "Group for entire word" 0)
1125                                      (number :tag "Group for displayed part" 0)
1126                                      (symbol :tag "Face"
1127                                              gnus-emphasis-highlight-words)))))
1128   :group 'gnus-summary-visual)
1129
1130 (defcustom gnus-summary-show-article-charset-alist
1131   nil
1132   "Alist of number and charset.
1133 The article will be shown with the charset corresponding to the
1134 numbered argument.
1135 For example: ((1 . cn-gb-2312) (2 . big5))."
1136   :version "21.1"
1137   :type '(repeat (cons (number :tag "Argument" 1)
1138                        (symbol :tag "Charset")))
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-preserve-marks t
1142   "Whether marks are preserved when moving, copying and respooling messages."
1143   :version "21.1"
1144   :type 'boolean
1145   :group 'gnus-summary-marks)
1146
1147 (defcustom gnus-alter-articles-to-read-function nil
1148   "Function to be called to alter the list of articles to be selected."
1149   :type '(choice (const nil) function)
1150   :group 'gnus-summary)
1151
1152 (defcustom gnus-orphan-score nil
1153   "*All orphans get this score added.  Set in the score file."
1154   :group 'gnus-score-default
1155   :type '(choice (const nil)
1156                  integer))
1157
1158 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1159   "*A regexp to match MIME parts when saving multiple parts of a
1160 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1161 This regexp will be used by default when prompting the user for which
1162 type of files to save."
1163   :group 'gnus-summary
1164   :type 'regexp)
1165
1166 (defcustom gnus-read-all-available-headers nil
1167   "Whether Gnus should parse all headers made available to it.
1168 This is mostly relevant for slow back ends where the user may
1169 wish to widen the summary buffer to include all headers
1170 that were fetched.  Say, for nnultimate groups."
1171   :version "22.1"
1172   :group 'gnus-summary
1173   :type '(choice boolean regexp))
1174
1175 (defcustom gnus-summary-muttprint-program "muttprint"
1176   "Command (and optional arguments) used to run Muttprint."
1177   :version "22.1"
1178   :group 'gnus-summary
1179   :type 'string)
1180
1181 (defcustom gnus-article-loose-mime t
1182   "If non-nil, don't require MIME-Version header.
1183 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1184 supply the MIME-Version header or deliberately strip it from the mail.
1185 If non-nil (the default), Gnus will treat some articles as MIME
1186 even if the MIME-Version header is missing."
1187   :version "22.1"
1188   :type 'boolean
1189   :group 'gnus-article-mime)
1190
1191 (defcustom gnus-article-emulate-mime t
1192   "If non-nil, use MIME emulation for uuencode and the like.
1193 This means that Gnus will search message bodies for text that look
1194 like uuencoded bits, yEncoded bits, and so on, and present that using
1195 the normal Gnus MIME machinery."
1196   :version "22.1"
1197   :type 'boolean
1198   :group 'gnus-article-mime)
1199
1200 ;;; Internal variables
1201
1202 (defvar gnus-summary-display-cache nil)
1203 (defvar gnus-article-mime-handles nil)
1204 (defvar gnus-article-decoded-p nil)
1205 (defvar gnus-article-charset nil)
1206 (defvar gnus-article-ignored-charsets nil)
1207 (defvar gnus-scores-exclude-files nil)
1208 (defvar gnus-page-broken nil)
1209
1210 (defvar gnus-original-article nil)
1211 (defvar gnus-article-internal-prepare-hook nil)
1212 (defvar gnus-newsgroup-process-stack nil)
1213
1214 (defvar gnus-thread-indent-array nil)
1215 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1216 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1217   "Function called to sort the articles within a thread after it has been gathered together.")
1218
1219 (defvar gnus-summary-save-parts-type-history nil)
1220 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1221
1222 ;; Avoid highlighting in kill files.
1223 (defvar gnus-summary-inhibit-highlight nil)
1224 (defvar gnus-newsgroup-selected-overlay nil)
1225 (defvar gnus-inhibit-limiting nil)
1226 (defvar gnus-newsgroup-adaptive-score-file nil)
1227 (defvar gnus-current-score-file nil)
1228 (defvar gnus-current-move-group nil)
1229 (defvar gnus-current-copy-group nil)
1230 (defvar gnus-current-crosspost-group nil)
1231 (defvar gnus-newsgroup-display nil)
1232
1233 (defvar gnus-newsgroup-dependencies nil)
1234 (defvar gnus-newsgroup-adaptive nil)
1235 (defvar gnus-summary-display-article-function nil)
1236 (defvar gnus-summary-highlight-line-function nil
1237   "Function called after highlighting a summary line.")
1238
1239 (defvar gnus-summary-line-format-alist
1240   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1241     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1242     (?s gnus-tmp-subject-or-nil ?s)
1243     (?n gnus-tmp-name ?s)
1244     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1245         ?s)
1246     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1247             gnus-tmp-from) ?s)
1248     (?F gnus-tmp-from ?s)
1249     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1250     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1251     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1252     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1253     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1254     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1255     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1256     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1257     (?L gnus-tmp-lines ?s)
1258     (?O gnus-tmp-downloaded ?c)
1259     (?I gnus-tmp-indentation ?s)
1260     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1261     (?R gnus-tmp-replied ?c)
1262     (?\[ gnus-tmp-opening-bracket ?c)
1263     (?\] gnus-tmp-closing-bracket ?c)
1264     (?\> (make-string gnus-tmp-level ? ) ?s)
1265     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1266     (?i gnus-tmp-score ?d)
1267     (?z gnus-tmp-score-char ?c)
1268     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1269     (?U gnus-tmp-unread ?c)
1270     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1271         ?s)
1272     (?t (gnus-summary-number-of-articles-in-thread
1273          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1274         ?d)
1275     (?e (gnus-summary-number-of-articles-in-thread
1276          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1277         ?c)
1278     (?u gnus-tmp-user-defined ?s)
1279     (?P (gnus-pick-line-number) ?d)
1280     (?B gnus-tmp-thread-tree-header-string ?s)
1281     (user-date (gnus-user-date
1282                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1283   "An alist of format specifications that can appear in summary lines.
1284 These are paired with what variables they correspond with, along with
1285 the type of the variable (string, integer, character, etc).")
1286
1287 (defvar gnus-summary-dummy-line-format-alist
1288   `((?S gnus-tmp-subject ?s)
1289     (?N gnus-tmp-number ?d)
1290     (?u gnus-tmp-user-defined ?s)))
1291
1292 (defvar gnus-summary-mode-line-format-alist
1293   `((?G gnus-tmp-group-name ?s)
1294     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1295     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1296     (?A gnus-tmp-article-number ?d)
1297     (?Z gnus-tmp-unread-and-unselected ?s)
1298     (?V gnus-version ?s)
1299     (?U gnus-tmp-unread-and-unticked ?d)
1300     (?S gnus-tmp-subject ?s)
1301     (?e gnus-tmp-unselected ?d)
1302     (?u gnus-tmp-user-defined ?s)
1303     (?d (length gnus-newsgroup-dormant) ?d)
1304     (?t (length gnus-newsgroup-marked) ?d)
1305     (?h (length gnus-newsgroup-spam-marked) ?d)
1306     (?r (length gnus-newsgroup-reads) ?d)
1307     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1308     (?E gnus-newsgroup-expunged-tally ?d)
1309     (?s (gnus-current-score-file-nondirectory) ?s)))
1310
1311 (defvar gnus-last-search-regexp nil
1312   "Default regexp for article search command.")
1313
1314 (defvar gnus-last-shell-command nil
1315   "Default shell command on article.")
1316
1317 (defvar gnus-newsgroup-agentized nil
1318   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1319 (defvar gnus-newsgroup-begin nil)
1320 (defvar gnus-newsgroup-end nil)
1321 (defvar gnus-newsgroup-last-rmail nil)
1322 (defvar gnus-newsgroup-last-mail nil)
1323 (defvar gnus-newsgroup-last-folder nil)
1324 (defvar gnus-newsgroup-last-file nil)
1325 (defvar gnus-newsgroup-auto-expire nil)
1326 (defvar gnus-newsgroup-active nil)
1327
1328 (defvar gnus-newsgroup-data nil)
1329 (defvar gnus-newsgroup-data-reverse nil)
1330 (defvar gnus-newsgroup-limit nil)
1331 (defvar gnus-newsgroup-limits nil)
1332 (defvar gnus-summary-use-undownloaded-faces nil)
1333
1334 (defvar gnus-newsgroup-unreads nil
1335   "Sorted list of unread articles in the current newsgroup.")
1336
1337 (defvar gnus-newsgroup-unselected nil
1338   "Sorted list of unselected unread articles in the current newsgroup.")
1339
1340 (defvar gnus-newsgroup-reads nil
1341   "Alist of read articles and article marks in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-expunged-tally nil)
1344
1345 (defvar gnus-newsgroup-marked nil
1346   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1347
1348 (defvar gnus-newsgroup-spam-marked nil
1349   "List of ranges of articles that have been marked as spam.")
1350
1351 (defvar gnus-newsgroup-killed nil
1352   "List of ranges of articles that have been through the scoring process.")
1353
1354 (defvar gnus-newsgroup-cached nil
1355   "Sorted list of articles that come from the article cache.")
1356
1357 (defvar gnus-newsgroup-saved nil
1358   "List of articles that have been saved.")
1359
1360 (defvar gnus-newsgroup-kill-headers nil)
1361
1362 (defvar gnus-newsgroup-replied nil
1363   "List of articles that have been replied to in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-forwarded nil
1366   "List of articles that have been forwarded in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-recent nil
1369   "List of articles that have are recent in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expirable nil
1372   "Sorted list of articles in the current newsgroup that can be expired.")
1373
1374 (defvar gnus-newsgroup-processable nil
1375   "List of articles in the current newsgroup that can be processed.")
1376
1377 (defvar gnus-newsgroup-downloadable nil
1378   "Sorted list of articles in the current newsgroup that can be processed.")
1379
1380 (defvar gnus-newsgroup-unfetched nil
1381   "Sorted list of articles in the current newsgroup whose headers have
1382 not been fetched into the agent.
1383
1384 This list will always be a subset of gnus-newsgroup-undownloaded.")
1385
1386 (defvar gnus-newsgroup-undownloaded nil
1387   "List of articles in the current newsgroup that haven't been downloaded.")
1388
1389 (defvar gnus-newsgroup-unsendable nil
1390   "List of articles in the current newsgroup that won't be sent.")
1391
1392 (defvar gnus-newsgroup-bookmarks nil
1393   "List of articles in the current newsgroup that have bookmarks.")
1394
1395 (defvar gnus-newsgroup-dormant nil
1396   "Sorted list of dormant articles in the current newsgroup.")
1397
1398 (defvar gnus-newsgroup-unseen nil
1399   "List of unseen articles in the current newsgroup.")
1400
1401 (defvar gnus-newsgroup-seen nil
1402   "Range of seen articles in the current newsgroup.")
1403
1404 (defvar gnus-newsgroup-articles nil
1405   "List of articles in the current newsgroup.")
1406
1407 (defvar gnus-newsgroup-scored nil
1408   "List of scored articles in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-headers nil
1411   "List of article headers in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-threads nil)
1414
1415 (defvar gnus-newsgroup-prepared nil
1416   "Whether the current group has been prepared properly.")
1417
1418 (defvar gnus-newsgroup-ancient nil
1419   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-sparse nil)
1422
1423 (defvar gnus-current-article nil)
1424 (defvar gnus-article-current nil)
1425 (defvar gnus-current-headers nil)
1426 (defvar gnus-have-all-headers nil)
1427 (defvar gnus-last-article nil)
1428 (defvar gnus-newsgroup-history nil)
1429 (defvar gnus-newsgroup-charset nil)
1430 (defvar gnus-newsgroup-ephemeral-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1432
1433 (defvar gnus-article-before-search nil)
1434
1435 (defvar gnus-summary-local-variables
1436   '(gnus-newsgroup-name
1437     gnus-newsgroup-begin gnus-newsgroup-end
1438     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1439     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1440     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1441     gnus-newsgroup-unselected gnus-newsgroup-marked
1442     gnus-newsgroup-spam-marked
1443     gnus-newsgroup-reads gnus-newsgroup-saved
1444     gnus-newsgroup-replied gnus-newsgroup-forwarded
1445     gnus-newsgroup-recent
1446     gnus-newsgroup-expirable
1447     gnus-newsgroup-processable gnus-newsgroup-killed
1448     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1449     gnus-newsgroup-unfetched
1450     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1451     gnus-newsgroup-seen gnus-newsgroup-articles
1452     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1453     gnus-newsgroup-headers gnus-newsgroup-threads
1454     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1455     gnus-current-article gnus-current-headers gnus-have-all-headers
1456     gnus-last-article gnus-article-internal-prepare-hook
1457     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1458     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1459     gnus-thread-expunge-below
1460     gnus-score-alist gnus-current-score-file
1461     (gnus-summary-expunge-below . global)
1462     (gnus-summary-mark-below . global)
1463     (gnus-orphan-score . global)
1464     gnus-newsgroup-active gnus-scores-exclude-files
1465     gnus-newsgroup-history gnus-newsgroup-ancient
1466     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1467     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1468     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1469     (gnus-newsgroup-expunged-tally . 0)
1470     gnus-cache-removable-articles gnus-newsgroup-cached
1471     gnus-newsgroup-data gnus-newsgroup-data-reverse
1472     gnus-newsgroup-limit gnus-newsgroup-limits
1473     gnus-newsgroup-charset gnus-newsgroup-display
1474     gnus-summary-use-undownloaded-faces)
1475   "Variables that are buffer-local to the summary buffers.")
1476
1477 (defvar gnus-newsgroup-variables nil
1478   "A list of variables that have separate values in different newsgroups.
1479 A list of newsgroup (summary buffer) local variables, or cons of
1480 variables and their default expressions to be evalled (when the default
1481 values are not nil), that should be made global while the summary buffer
1482 is active.
1483
1484 Note: The default expressions will be evaluated (using function `eval')
1485 before assignment to the local variable rather than just assigned to it.
1486 If the default expression is the symbol `global', that symbol will not
1487 be evaluated but the global value of the local variable will be used
1488 instead.
1489
1490 These variables can be used to set variables in the group parameters
1491 while still allowing them to affect operations done in other buffers.
1492 For example:
1493
1494 \(setq gnus-newsgroup-variables
1495      '(message-use-followup-to
1496        (gnus-visible-headers .
1497          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1498 ")
1499
1500 ;; Byte-compiler warning.
1501 (eval-when-compile
1502   ;; Bind features so that require will believe that gnus-sum has
1503   ;; already been loaded (avoids infinite recursion)
1504   (let ((features (cons 'gnus-sum features)))
1505     ;; Several of the declarations in gnus-sum are needed to load the
1506     ;; following files. Right now, these definitions have been
1507     ;; compiled but not defined (evaluated).  We could either do a
1508     ;; eval-and-compile about all of the declarations or evaluate the
1509     ;; source file.
1510     (if (boundp 'gnus-newsgroup-variables)
1511         nil
1512       (load "gnus-sum.el" t t t))
1513     (require 'gnus)
1514     (require 'gnus-art)))
1515
1516 ;; MIME stuff.
1517
1518 (defvar gnus-decode-encoded-word-methods
1519   '(mail-decode-encoded-word-string)
1520   "List of methods used to decode encoded words.
1521
1522 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1523 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1524 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1525 whose names match REGEXP.
1526
1527 For example:
1528 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1529  mail-decode-encoded-word-string
1530  (\"chinese\" . rfc1843-decode-string))")
1531
1532 (defvar gnus-decode-encoded-word-methods-cache nil)
1533
1534 (defun gnus-multi-decode-encoded-word-string (string)
1535   "Apply the functions from `gnus-encoded-word-methods' that match."
1536   (unless (and gnus-decode-encoded-word-methods-cache
1537                (eq gnus-newsgroup-name
1538                    (car gnus-decode-encoded-word-methods-cache)))
1539     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1540     (mapcar (lambda (x)
1541               (if (symbolp x)
1542                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1543                 (if (and gnus-newsgroup-name
1544                          (string-match (car x) gnus-newsgroup-name))
1545                     (nconc gnus-decode-encoded-word-methods-cache
1546                            (list (cdr x))))))
1547             gnus-decode-encoded-word-methods))
1548   (let ((xlist gnus-decode-encoded-word-methods-cache))
1549     (pop xlist)
1550     (while xlist
1551       (setq string (funcall (pop xlist) string))))
1552   string)
1553
1554 ;; Subject simplification.
1555
1556 (defun gnus-simplify-whitespace (str)
1557   "Remove excessive whitespace from STR."
1558   ;; Multiple spaces.
1559   (while (string-match "[ \t][ \t]+" str)
1560     (setq str (concat (substring str 0 (match-beginning 0))
1561                         " "
1562                         (substring str (match-end 0)))))
1563   ;; Leading spaces.
1564   (when (string-match "^[ \t]+" str)
1565     (setq str (substring str (match-end 0))))
1566   ;; Trailing spaces.
1567   (when (string-match "[ \t]+$" str)
1568     (setq str (substring str 0 (match-beginning 0))))
1569   str)
1570
1571 (defun gnus-simplify-all-whitespace (str)
1572   "Remove all whitespace from STR."
1573   (while (string-match "[ \t\n]+" str)
1574     (setq str (replace-match "" nil nil str)))
1575   str)
1576
1577 (defsubst gnus-simplify-subject-re (subject)
1578   "Remove \"Re:\" from subject lines."
1579   (if (string-match message-subject-re-regexp subject)
1580       (substring subject (match-end 0))
1581     subject))
1582
1583 (defun gnus-simplify-subject (subject &optional re-only)
1584   "Remove `Re:' and words in parentheses.
1585 If RE-ONLY is non-nil, strip leading `Re:'s only."
1586   (let ((case-fold-search t))           ;Ignore case.
1587     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1588     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1589       (setq subject (substring subject (match-end 0))))
1590     ;; Remove uninteresting prefixes.
1591     (when (and (not re-only)
1592                gnus-simplify-ignored-prefixes
1593                (string-match gnus-simplify-ignored-prefixes subject))
1594       (setq subject (substring subject (match-end 0))))
1595     ;; Remove words in parentheses from end.
1596     (unless re-only
1597       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1598         (setq subject (substring subject 0 (match-beginning 0)))))
1599     ;; Return subject string.
1600     subject))
1601
1602 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1603 ;; all whitespace.
1604 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1605   (goto-char (point-min))
1606   (while (re-search-forward regexp nil t)
1607     (replace-match (or newtext ""))))
1608
1609 (defun gnus-simplify-buffer-fuzzy ()
1610   "Simplify string in the buffer fuzzily.
1611 The string in the accessible portion of the current buffer is simplified.
1612 It is assumed to be a single-line subject.
1613 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1614 matter is removed.  Additional things can be deleted by setting
1615 `gnus-simplify-subject-fuzzy-regexp'."
1616   (let ((case-fold-search t)
1617         (modified-tick))
1618     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1619
1620     (while (not (eq modified-tick (buffer-modified-tick)))
1621       (setq modified-tick (buffer-modified-tick))
1622       (cond
1623        ((listp gnus-simplify-subject-fuzzy-regexp)
1624         (mapcar 'gnus-simplify-buffer-fuzzy-step
1625                 gnus-simplify-subject-fuzzy-regexp))
1626        (gnus-simplify-subject-fuzzy-regexp
1627         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1628       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1629       (gnus-simplify-buffer-fuzzy-step
1630        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1631       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1632
1633     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1634     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1635     (gnus-simplify-buffer-fuzzy-step " $")
1636     (gnus-simplify-buffer-fuzzy-step "^ +")))
1637
1638 (defun gnus-simplify-subject-fuzzy (subject)
1639   "Simplify a subject string fuzzily.
1640 See `gnus-simplify-buffer-fuzzy' for details."
1641   (save-excursion
1642     (gnus-set-work-buffer)
1643     (let ((case-fold-search t))
1644       ;; Remove uninteresting prefixes.
1645       (when (and gnus-simplify-ignored-prefixes
1646                  (string-match gnus-simplify-ignored-prefixes subject))
1647         (setq subject (substring subject (match-end 0))))
1648       (insert subject)
1649       (inline (gnus-simplify-buffer-fuzzy))
1650       (buffer-string))))
1651
1652 (defsubst gnus-simplify-subject-fully (subject)
1653   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1654   (cond
1655    (gnus-simplify-subject-functions
1656     (gnus-map-function gnus-simplify-subject-functions subject))
1657    ((null gnus-summary-gather-subject-limit)
1658     (gnus-simplify-subject-re subject))
1659    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1660     (gnus-simplify-subject-fuzzy subject))
1661    ((numberp gnus-summary-gather-subject-limit)
1662     (gnus-limit-string (gnus-simplify-subject-re subject)
1663                        gnus-summary-gather-subject-limit))
1664    (t
1665     subject)))
1666
1667 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1668   "Check whether two subjects are equal.
1669 If optional argument SIMPLE-FIRST is t, first argument is already
1670 simplified."
1671   (cond
1672    ((null simple-first)
1673     (equal (gnus-simplify-subject-fully s1)
1674            (gnus-simplify-subject-fully s2)))
1675    (t
1676     (equal s1
1677            (gnus-simplify-subject-fully s2)))))
1678
1679 (defun gnus-summary-bubble-group ()
1680   "Increase the score of the current group.
1681 This is a handy function to add to `gnus-summary-exit-hook' to
1682 increase the score of each group you read."
1683   (gnus-group-add-score gnus-newsgroup-name))
1684
1685 \f
1686 ;;;
1687 ;;; Gnus summary mode
1688 ;;;
1689
1690 (put 'gnus-summary-mode 'mode-class 'special)
1691
1692 (defvar gnus-article-commands-menu)
1693
1694 ;; Non-orthogonal keys
1695
1696 (gnus-define-keys gnus-summary-mode-map
1697   " " gnus-summary-next-page
1698   "\177" gnus-summary-prev-page
1699   [delete] gnus-summary-prev-page
1700   [backspace] gnus-summary-prev-page
1701   "\r" gnus-summary-scroll-up
1702   "\M-\r" gnus-summary-scroll-down
1703   "n" gnus-summary-next-unread-article
1704   "p" gnus-summary-prev-unread-article
1705   "N" gnus-summary-next-article
1706   "P" gnus-summary-prev-article
1707   "\M-\C-n" gnus-summary-next-same-subject
1708   "\M-\C-p" gnus-summary-prev-same-subject
1709   "\M-n" gnus-summary-next-unread-subject
1710   "\M-p" gnus-summary-prev-unread-subject
1711   "." gnus-summary-first-unread-article
1712   "," gnus-summary-best-unread-article
1713   "\M-s" gnus-summary-search-article-forward
1714   "\M-r" gnus-summary-search-article-backward
1715   "<" gnus-summary-beginning-of-article
1716   ">" gnus-summary-end-of-article
1717   "j" gnus-summary-goto-article
1718   "^" gnus-summary-refer-parent-article
1719   "\M-^" gnus-summary-refer-article
1720   "u" gnus-summary-tick-article-forward
1721   "!" gnus-summary-tick-article-forward
1722   "U" gnus-summary-tick-article-backward
1723   "d" gnus-summary-mark-as-read-forward
1724   "D" gnus-summary-mark-as-read-backward
1725   "E" gnus-summary-mark-as-expirable
1726   "\M-u" gnus-summary-clear-mark-forward
1727   "\M-U" gnus-summary-clear-mark-backward
1728   "k" gnus-summary-kill-same-subject-and-select
1729   "\C-k" gnus-summary-kill-same-subject
1730   "\M-\C-k" gnus-summary-kill-thread
1731   "\M-\C-l" gnus-summary-lower-thread
1732   "e" gnus-summary-edit-article
1733   "#" gnus-summary-mark-as-processable
1734   "\M-#" gnus-summary-unmark-as-processable
1735   "\M-\C-t" gnus-summary-toggle-threads
1736   "\M-\C-s" gnus-summary-show-thread
1737   "\M-\C-h" gnus-summary-hide-thread
1738   "\M-\C-f" gnus-summary-next-thread
1739   "\M-\C-b" gnus-summary-prev-thread
1740   [(meta down)] gnus-summary-next-thread
1741   [(meta up)] gnus-summary-prev-thread
1742   "\M-\C-u" gnus-summary-up-thread
1743   "\M-\C-d" gnus-summary-down-thread
1744   "&" gnus-summary-execute-command
1745   "c" gnus-summary-catchup-and-exit
1746   "\C-w" gnus-summary-mark-region-as-read
1747   "\C-t" gnus-summary-toggle-truncation
1748   "?" gnus-summary-mark-as-dormant
1749   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1750   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1751   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1752   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1753   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1754   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1755   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1756   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1757   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1758   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1759   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1760   "=" gnus-summary-expand-window
1761   "\C-x\C-s" gnus-summary-reselect-current-group
1762   "\M-g" gnus-summary-rescan-group
1763   "w" gnus-summary-stop-page-breaking
1764   "\C-c\C-r" gnus-summary-caesar-message
1765   "f" gnus-summary-followup
1766   "F" gnus-summary-followup-with-original
1767   "C" gnus-summary-cancel-article
1768   "r" gnus-summary-reply
1769   "R" gnus-summary-reply-with-original
1770   "\C-c\C-f" gnus-summary-mail-forward
1771   "o" gnus-summary-save-article
1772   "\C-o" gnus-summary-save-article-mail
1773   "|" gnus-summary-pipe-output
1774   "\M-k" gnus-summary-edit-local-kill
1775   "\M-K" gnus-summary-edit-global-kill
1776   ;; "V" gnus-version
1777   "\C-c\C-d" gnus-summary-describe-group
1778   "q" gnus-summary-exit
1779   "Q" gnus-summary-exit-no-update
1780   "\C-c\C-i" gnus-info-find-node
1781   gnus-mouse-2 gnus-mouse-pick-article
1782   [follow-link] mouse-face
1783   "m" gnus-summary-mail-other-window
1784   "a" gnus-summary-post-news
1785   "i" gnus-summary-news-other-window
1786   "x" gnus-summary-limit-to-unread
1787   "s" gnus-summary-isearch-article
1788   "t" gnus-summary-toggle-header
1789   "g" gnus-summary-show-article
1790   "l" gnus-summary-goto-last-article
1791   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1792   "\C-d" gnus-summary-enter-digest-group
1793   "\M-\C-d" gnus-summary-read-document
1794   "\M-\C-e" gnus-summary-edit-parameters
1795   "\M-\C-a" gnus-summary-customize-parameters
1796   "\C-c\C-b" gnus-bug
1797   "*" gnus-cache-enter-article
1798   "\M-*" gnus-cache-remove-article
1799   "\M-&" gnus-summary-universal-argument
1800   "\C-l" gnus-recenter
1801   "I" gnus-summary-increase-score
1802   "L" gnus-summary-lower-score
1803   "\M-i" gnus-symbolic-argument
1804   "h" gnus-summary-select-article-buffer
1805
1806   "b" gnus-article-view-part
1807   "\M-t" gnus-summary-toggle-display-buttonized
1808
1809   "V" gnus-summary-score-map
1810   "X" gnus-uu-extract-map
1811   "S" gnus-summary-send-map)
1812
1813 ;; Sort of orthogonal keymap
1814 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1815   "t" gnus-summary-tick-article-forward
1816   "!" gnus-summary-tick-article-forward
1817   "d" gnus-summary-mark-as-read-forward
1818   "r" gnus-summary-mark-as-read-forward
1819   "c" gnus-summary-clear-mark-forward
1820   " " gnus-summary-clear-mark-forward
1821   "e" gnus-summary-mark-as-expirable
1822   "x" gnus-summary-mark-as-expirable
1823   "?" gnus-summary-mark-as-dormant
1824   "b" gnus-summary-set-bookmark
1825   "B" gnus-summary-remove-bookmark
1826   "#" gnus-summary-mark-as-processable
1827   "\M-#" gnus-summary-unmark-as-processable
1828   "S" gnus-summary-limit-include-expunged
1829   "C" gnus-summary-catchup
1830   "H" gnus-summary-catchup-to-here
1831   "h" gnus-summary-catchup-from-here
1832   "\C-c" gnus-summary-catchup-all
1833   "k" gnus-summary-kill-same-subject-and-select
1834   "K" gnus-summary-kill-same-subject
1835   "P" gnus-uu-mark-map)
1836
1837 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1838   "c" gnus-summary-clear-above
1839   "u" gnus-summary-tick-above
1840   "m" gnus-summary-mark-above
1841   "k" gnus-summary-kill-below)
1842
1843 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1844   "/" gnus-summary-limit-to-subject
1845   "n" gnus-summary-limit-to-articles
1846   "w" gnus-summary-pop-limit
1847   "s" gnus-summary-limit-to-subject
1848   "a" gnus-summary-limit-to-author
1849   "u" gnus-summary-limit-to-unread
1850   "m" gnus-summary-limit-to-marks
1851   "M" gnus-summary-limit-exclude-marks
1852   "v" gnus-summary-limit-to-score
1853   "*" gnus-summary-limit-include-cached
1854   "D" gnus-summary-limit-include-dormant
1855   "T" gnus-summary-limit-include-thread
1856   "d" gnus-summary-limit-exclude-dormant
1857   "t" gnus-summary-limit-to-age
1858   "." gnus-summary-limit-to-unseen
1859   "x" gnus-summary-limit-to-extra
1860   "p" gnus-summary-limit-to-display-predicate
1861   "E" gnus-summary-limit-include-expunged
1862   "c" gnus-summary-limit-exclude-childless-dormant
1863   "C" gnus-summary-limit-mark-excluded-as-read
1864   "o" gnus-summary-insert-old-articles
1865   "N" gnus-summary-insert-new-articles
1866   "r" gnus-summary-limit-to-replied
1867   "R" gnus-summary-limit-to-recipient)
1868
1869 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1870   "n" gnus-summary-next-unread-article
1871   "p" gnus-summary-prev-unread-article
1872   "N" gnus-summary-next-article
1873   "P" gnus-summary-prev-article
1874   "\C-n" gnus-summary-next-same-subject
1875   "\C-p" gnus-summary-prev-same-subject
1876   "\M-n" gnus-summary-next-unread-subject
1877   "\M-p" gnus-summary-prev-unread-subject
1878   "f" gnus-summary-first-unread-article
1879   "b" gnus-summary-best-unread-article
1880   "j" gnus-summary-goto-article
1881   "g" gnus-summary-goto-subject
1882   "l" gnus-summary-goto-last-article
1883   "o" gnus-summary-pop-article)
1884
1885 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1886   "k" gnus-summary-kill-thread
1887   "l" gnus-summary-lower-thread
1888   "i" gnus-summary-raise-thread
1889   "T" gnus-summary-toggle-threads
1890   "t" gnus-summary-rethread-current
1891   "^" gnus-summary-reparent-thread
1892   "s" gnus-summary-show-thread
1893   "S" gnus-summary-show-all-threads
1894   "h" gnus-summary-hide-thread
1895   "H" gnus-summary-hide-all-threads
1896   "n" gnus-summary-next-thread
1897   "p" gnus-summary-prev-thread
1898   "u" gnus-summary-up-thread
1899   "o" gnus-summary-top-thread
1900   "d" gnus-summary-down-thread
1901   "#" gnus-uu-mark-thread
1902   "\M-#" gnus-uu-unmark-thread)
1903
1904 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1905   "g" gnus-summary-prepare
1906   "c" gnus-summary-insert-cached-articles
1907   "d" gnus-summary-insert-dormant-articles)
1908
1909 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1910   "c" gnus-summary-catchup-and-exit
1911   "C" gnus-summary-catchup-all-and-exit
1912   "E" gnus-summary-exit-no-update
1913   "Q" gnus-summary-exit
1914   "Z" gnus-summary-exit
1915   "n" gnus-summary-catchup-and-goto-next-group
1916   "p" gnus-summary-catchup-and-goto-prev-group
1917   "R" gnus-summary-reselect-current-group
1918   "G" gnus-summary-rescan-group
1919   "N" gnus-summary-next-group
1920   "s" gnus-summary-save-newsrc
1921   "P" gnus-summary-prev-group)
1922
1923 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1924   " " gnus-summary-next-page
1925   "n" gnus-summary-next-page
1926   "\177" gnus-summary-prev-page
1927   [delete] gnus-summary-prev-page
1928   "p" gnus-summary-prev-page
1929   "\r" gnus-summary-scroll-up
1930   "\M-\r" gnus-summary-scroll-down
1931   "<" gnus-summary-beginning-of-article
1932   ">" gnus-summary-end-of-article
1933   "b" gnus-summary-beginning-of-article
1934   "e" gnus-summary-end-of-article
1935   "^" gnus-summary-refer-parent-article
1936   "r" gnus-summary-refer-parent-article
1937   "D" gnus-summary-enter-digest-group
1938   "R" gnus-summary-refer-references
1939   "T" gnus-summary-refer-thread
1940   "g" gnus-summary-show-article
1941   "s" gnus-summary-isearch-article
1942   "P" gnus-summary-print-article
1943   "M" gnus-mailing-list-insinuate
1944   "t" gnus-article-babel)
1945
1946 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1947   "b" gnus-article-add-buttons
1948   "B" gnus-article-add-buttons-to-head
1949   "o" gnus-article-treat-overstrike
1950   "e" gnus-article-emphasize
1951   "w" gnus-article-fill-cited-article
1952   "Q" gnus-article-fill-long-lines
1953   "C" gnus-article-capitalize-sentences
1954   "c" gnus-article-remove-cr
1955   "q" gnus-article-de-quoted-unreadable
1956   "6" gnus-article-de-base64-unreadable
1957   "Z" gnus-article-decode-HZ
1958   "A" gnus-article-treat-ansi-sequences
1959   "h" gnus-article-wash-html
1960   "u" gnus-article-unsplit-urls
1961   "s" gnus-summary-force-verify-and-decrypt
1962   "f" gnus-article-display-x-face
1963   "l" gnus-summary-stop-page-breaking
1964   "r" gnus-summary-caesar-message
1965   "m" gnus-summary-morse-message
1966   "t" gnus-summary-toggle-header
1967   "g" gnus-treat-smiley
1968   "v" gnus-summary-verbose-headers
1969   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1970   "p" gnus-article-verify-x-pgp-sig
1971   "d" gnus-article-treat-dumbquotes
1972   "i" gnus-summary-idna-message)
1973
1974 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1975   ;; mnemonic: deuglif*Y*
1976   "u" gnus-article-outlook-unwrap-lines
1977   "a" gnus-article-outlook-repair-attribution
1978   "c" gnus-article-outlook-rearrange-citation
1979   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1980
1981 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1982   "a" gnus-article-hide
1983   "h" gnus-article-hide-headers
1984   "b" gnus-article-hide-boring-headers
1985   "s" gnus-article-hide-signature
1986   "c" gnus-article-hide-citation
1987   "C" gnus-article-hide-citation-in-followups
1988   "l" gnus-article-hide-list-identifiers
1989   "B" gnus-article-strip-banner
1990   "P" gnus-article-hide-pem
1991   "\C-c" gnus-article-hide-citation-maybe)
1992
1993 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1994   "a" gnus-article-highlight
1995   "h" gnus-article-highlight-headers
1996   "c" gnus-article-highlight-citation
1997   "s" gnus-article-highlight-signature)
1998
1999 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2000   "f" gnus-article-treat-fold-headers
2001   "u" gnus-article-treat-unfold-headers
2002   "n" gnus-article-treat-fold-newsgroups)
2003
2004 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2005   "x" gnus-article-display-x-face
2006   "d" gnus-article-display-face
2007   "s" gnus-treat-smiley
2008   "D" gnus-article-remove-images
2009   "f" gnus-treat-from-picon
2010   "m" gnus-treat-mail-picon
2011   "n" gnus-treat-newsgroups-picon)
2012
2013 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2014   "w" gnus-article-decode-mime-words
2015   "c" gnus-article-decode-charset
2016   "v" gnus-mime-view-all-parts
2017   "b" gnus-article-view-part)
2018
2019 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2020   "z" gnus-article-date-ut
2021   "u" gnus-article-date-ut
2022   "l" gnus-article-date-local
2023   "p" gnus-article-date-english
2024   "e" gnus-article-date-lapsed
2025   "o" gnus-article-date-original
2026   "i" gnus-article-date-iso8601
2027   "s" gnus-article-date-user)
2028
2029 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2030   "t" gnus-article-remove-trailing-blank-lines
2031   "l" gnus-article-strip-leading-blank-lines
2032   "m" gnus-article-strip-multiple-blank-lines
2033   "a" gnus-article-strip-blank-lines
2034   "A" gnus-article-strip-all-blank-lines
2035   "s" gnus-article-strip-leading-space
2036   "e" gnus-article-strip-trailing-space
2037   "w" gnus-article-remove-leading-whitespace)
2038
2039 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2040   "v" gnus-version
2041   "f" gnus-summary-fetch-faq
2042   "d" gnus-summary-describe-group
2043   "h" gnus-summary-describe-briefly
2044   "i" gnus-info-find-node
2045   "c" gnus-group-fetch-charter
2046   "C" gnus-group-fetch-control)
2047
2048 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2049   "e" gnus-summary-expire-articles
2050   "\M-\C-e" gnus-summary-expire-articles-now
2051   "\177" gnus-summary-delete-article
2052   [delete] gnus-summary-delete-article
2053   [backspace] gnus-summary-delete-article
2054   "m" gnus-summary-move-article
2055   "r" gnus-summary-respool-article
2056   "w" gnus-summary-edit-article
2057   "c" gnus-summary-copy-article
2058   "B" gnus-summary-crosspost-article
2059   "q" gnus-summary-respool-query
2060   "t" gnus-summary-respool-trace
2061   "i" gnus-summary-import-article
2062   "I" gnus-summary-create-article
2063   "p" gnus-summary-article-posted-p)
2064
2065 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2066   "o" gnus-summary-save-article
2067   "m" gnus-summary-save-article-mail
2068   "F" gnus-summary-write-article-file
2069   "r" gnus-summary-save-article-rmail
2070   "f" gnus-summary-save-article-file
2071   "b" gnus-summary-save-article-body-file
2072   "h" gnus-summary-save-article-folder
2073   "v" gnus-summary-save-article-vm
2074   "p" gnus-summary-pipe-output
2075   "P" gnus-summary-muttprint
2076   "s" gnus-soup-add-article)
2077
2078 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2079   "b" gnus-summary-display-buttonized
2080   "m" gnus-summary-repair-multipart
2081   "v" gnus-article-view-part
2082   "o" gnus-article-save-part
2083   "O" gnus-article-save-part-and-strip
2084   "r" gnus-article-replace-part
2085   "d" gnus-article-delete-part
2086   "j" gnus-article-jump-to-part
2087   "c" gnus-article-copy-part
2088   "C" gnus-article-view-part-as-charset
2089   "e" gnus-article-view-part-externally
2090   "E" gnus-article-encrypt-body
2091   "i" gnus-article-inline-part
2092   "|" gnus-article-pipe-part)
2093
2094 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2095   "p" gnus-summary-mark-as-processable
2096   "u" gnus-summary-unmark-as-processable
2097   "U" gnus-summary-unmark-all-processable
2098   "v" gnus-uu-mark-over
2099   "s" gnus-uu-mark-series
2100   "r" gnus-uu-mark-region
2101   "g" gnus-uu-unmark-region
2102   "R" gnus-uu-mark-by-regexp
2103   "G" gnus-uu-unmark-by-regexp
2104   "t" gnus-uu-mark-thread
2105   "T" gnus-uu-unmark-thread
2106   "a" gnus-uu-mark-all
2107   "b" gnus-uu-mark-buffer
2108   "S" gnus-uu-mark-sparse
2109   "k" gnus-summary-kill-process-mark
2110   "y" gnus-summary-yank-process-mark
2111   "w" gnus-summary-save-process-mark
2112   "i" gnus-uu-invert-processable)
2113
2114 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2115   ;;"x" gnus-uu-extract-any
2116   "m" gnus-summary-save-parts
2117   "u" gnus-uu-decode-uu
2118   "U" gnus-uu-decode-uu-and-save
2119   "s" gnus-uu-decode-unshar
2120   "S" gnus-uu-decode-unshar-and-save
2121   "o" gnus-uu-decode-save
2122   "O" gnus-uu-decode-save
2123   "b" gnus-uu-decode-binhex
2124   "B" gnus-uu-decode-binhex
2125   "p" gnus-uu-decode-postscript
2126   "P" gnus-uu-decode-postscript-and-save)
2127
2128 (gnus-define-keys
2129     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2130   "u" gnus-uu-decode-uu-view
2131   "U" gnus-uu-decode-uu-and-save-view
2132   "s" gnus-uu-decode-unshar-view
2133   "S" gnus-uu-decode-unshar-and-save-view
2134   "o" gnus-uu-decode-save-view
2135   "O" gnus-uu-decode-save-view
2136   "b" gnus-uu-decode-binhex-view
2137   "B" gnus-uu-decode-binhex-view
2138   "p" gnus-uu-decode-postscript-view
2139   "P" gnus-uu-decode-postscript-and-save-view)
2140
2141 (defvar gnus-article-post-menu nil)
2142
2143 (defconst gnus-summary-menu-maxlen 20)
2144
2145 (defun gnus-summary-menu-split (menu)
2146   ;; If we have lots of elements, divide them into groups of 20
2147   ;; and make a pane (or submenu) for each one.
2148   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2149       (let ((menu menu) sublists next
2150             (i 1))
2151         (while menu
2152           ;; Pull off the next gnus-summary-menu-maxlen elements
2153           ;; and make them the next element of sublist.
2154           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2155           (if next
2156               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2157                       nil))
2158           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2159                                              (aref (car (last menu)) 0)) menu)
2160                                sublists))
2161           (setq i (1+ i))
2162           (setq menu next))
2163         (nreverse sublists))
2164     ;; Few elements--put them all in one pane.
2165     menu))
2166
2167 (defun gnus-summary-make-menu-bar ()
2168   (gnus-turn-off-edit-menu 'summary)
2169
2170   (unless (boundp 'gnus-summary-misc-menu)
2171
2172     (easy-menu-define
2173       gnus-summary-kill-menu gnus-summary-mode-map ""
2174       (cons
2175        "Score"
2176        (nconc
2177         (list
2178          ["Customize" gnus-score-customize t])
2179         (gnus-make-score-map 'increase)
2180         (gnus-make-score-map 'lower)
2181         '(("Mark"
2182            ["Kill below" gnus-summary-kill-below t]
2183            ["Mark above" gnus-summary-mark-above t]
2184            ["Tick above" gnus-summary-tick-above t]
2185            ["Clear above" gnus-summary-clear-above t])
2186           ["Current score" gnus-summary-current-score t]
2187           ["Set score" gnus-summary-set-score t]
2188           ["Switch current score file..." gnus-score-change-score-file t]
2189           ["Set mark below..." gnus-score-set-mark-below t]
2190           ["Set expunge below..." gnus-score-set-expunge-below t]
2191           ["Edit current score file" gnus-score-edit-current-scores t]
2192           ["Edit score file" gnus-score-edit-file t]
2193           ["Trace score" gnus-score-find-trace t]
2194           ["Find words" gnus-score-find-favourite-words t]
2195           ["Rescore buffer" gnus-summary-rescore t]
2196           ["Increase score..." gnus-summary-increase-score t]
2197           ["Lower score..." gnus-summary-lower-score t]))))
2198
2199     ;; Define both the Article menu in the summary buffer and the
2200     ;; equivalent Commands menu in the article buffer here for
2201     ;; consistency.
2202     (let ((innards
2203            `(("Hide"
2204               ["All" gnus-article-hide t]
2205               ["Headers" gnus-article-hide-headers t]
2206               ["Signature" gnus-article-hide-signature t]
2207               ["Citation" gnus-article-hide-citation t]
2208               ["List identifiers" gnus-article-hide-list-identifiers t]
2209               ["Banner" gnus-article-strip-banner t]
2210               ["Boring headers" gnus-article-hide-boring-headers t])
2211              ("Highlight"
2212               ["All" gnus-article-highlight t]
2213               ["Headers" gnus-article-highlight-headers t]
2214               ["Signature" gnus-article-highlight-signature t]
2215               ["Citation" gnus-article-highlight-citation t])
2216              ("MIME"
2217               ["Words" gnus-article-decode-mime-words t]
2218               ["Charset" gnus-article-decode-charset t]
2219               ["QP" gnus-article-de-quoted-unreadable t]
2220               ["Base64" gnus-article-de-base64-unreadable t]
2221               ["View MIME buttons" gnus-summary-display-buttonized t]
2222               ["View all" gnus-mime-view-all-parts t]
2223               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2224               ["Encrypt body" gnus-article-encrypt-body
2225                :active (not (gnus-group-read-only-p))
2226                ,@(if (featurep 'xemacs) nil
2227                    '(:help "Encrypt the message body on disk"))]
2228               ["Extract all parts..." gnus-summary-save-parts t]
2229               ("Multipart"
2230                ["Repair multipart" gnus-summary-repair-multipart t]
2231                ["Pipe part..." gnus-article-pipe-part t]
2232                ["Inline part" gnus-article-inline-part t]
2233                ["Encrypt body" gnus-article-encrypt-body
2234                 :active (not (gnus-group-read-only-p))
2235                ,@(if (featurep 'xemacs) nil
2236                    '(:help "Encrypt the message body on disk"))]
2237                ["View part externally" gnus-article-view-part-externally t]
2238                ["View part with charset..." gnus-article-view-part-as-charset t]
2239                ["Copy part" gnus-article-copy-part t]
2240                ["Save part..." gnus-article-save-part t]
2241                ["View part" gnus-article-view-part t]))
2242              ("Date"
2243               ["Local" gnus-article-date-local t]
2244               ["ISO8601" gnus-article-date-iso8601 t]
2245               ["UT" gnus-article-date-ut t]
2246               ["Original" gnus-article-date-original t]
2247               ["Lapsed" gnus-article-date-lapsed t]
2248               ["User-defined" gnus-article-date-user t])
2249              ("Display"
2250               ["Remove images" gnus-article-remove-images t]
2251               ["Toggle smiley" gnus-treat-smiley t]
2252               ["Show X-Face" gnus-article-display-x-face t]
2253               ["Show picons in From" gnus-treat-from-picon t]
2254               ["Show picons in mail headers" gnus-treat-mail-picon t]
2255               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2256               ("View as different encoding"
2257                ,@(gnus-summary-menu-split
2258                   (mapcar
2259                    (lambda (cs)
2260                      ;; Since easymenu under Emacs doesn't allow
2261                      ;; lambda forms for menu commands, we should
2262                      ;; provide intern'ed function symbols.
2263                      (let ((command (intern (format "\
2264 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2265                        (fset command
2266                              `(lambda ()
2267                                 (interactive)
2268                                 (let ((gnus-summary-show-article-charset-alist
2269                                        '((1 . ,cs))))
2270                                   (gnus-summary-show-article 1))))
2271                        `[,(symbol-name cs) ,command t]))
2272                    (sort (if (fboundp 'coding-system-list)
2273                              (coding-system-list)
2274                            (mapcar 'car mm-mime-mule-charset-alist))
2275                          'string<)))))
2276              ("Washing"
2277               ("Remove Blanks"
2278                ["Leading" gnus-article-strip-leading-blank-lines t]
2279                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2280                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2281                ["All of the above" gnus-article-strip-blank-lines t]
2282                ["All" gnus-article-strip-all-blank-lines t]
2283                ["Leading space" gnus-article-strip-leading-space t]
2284                ["Trailing space" gnus-article-strip-trailing-space t]
2285                ["Leading space in headers"
2286                 gnus-article-remove-leading-whitespace t])
2287               ["Overstrike" gnus-article-treat-overstrike t]
2288               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2289               ["Emphasis" gnus-article-emphasize t]
2290               ["Word wrap" gnus-article-fill-cited-article t]
2291               ["Fill long lines" gnus-article-fill-long-lines t]
2292               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2293               ["Remove CR" gnus-article-remove-cr t]
2294               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2295               ["Base64" gnus-article-de-base64-unreadable t]
2296               ["Rot 13" gnus-summary-caesar-message
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "\"Caesar rotate\" article by 13"))]
2299               ["De-IDNA" gnus-summary-idna-message t]
2300               ["Morse decode" gnus-summary-morse-message t]
2301               ["Unix pipe..." gnus-summary-pipe-message t]
2302               ["Add buttons" gnus-article-add-buttons t]
2303               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2304               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2305               ["Verbose header" gnus-summary-verbose-headers t]
2306               ["Toggle header" gnus-summary-toggle-header t]
2307               ["Unfold headers" gnus-article-treat-unfold-headers t]
2308               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2309               ["Html" gnus-article-wash-html t]
2310               ["Unsplit URLs" gnus-article-unsplit-urls t]
2311               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2312               ["Decode HZ" gnus-article-decode-HZ t]
2313               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2314               ("(Outlook) Deuglify"
2315                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2316                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2317                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2318                ["Full (Outlook) deuglify"
2319                 gnus-article-outlook-deuglify-article t])
2320               )
2321              ("Output"
2322               ["Save in default format..." gnus-summary-save-article
2323                ,@(if (featurep 'xemacs) '(t)
2324                    '(:help "Save article using default method"))]
2325               ["Save in file..." gnus-summary-save-article-file
2326                ,@(if (featurep 'xemacs) '(t)
2327                    '(:help "Save article in file"))]
2328               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2329               ["Save in MH folder..." gnus-summary-save-article-folder t]
2330               ["Save in VM folder..." gnus-summary-save-article-vm t]
2331               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2332               ["Save body in file..." gnus-summary-save-article-body-file t]
2333               ["Pipe through a filter..." gnus-summary-pipe-output t]
2334               ["Add to SOUP packet" gnus-soup-add-article t]
2335               ["Print with Muttprint..." gnus-summary-muttprint t]
2336               ["Print" gnus-summary-print-article
2337                ,@(if (featurep 'xemacs) '(t)
2338                    '(:help "Generate and print a PostScript image"))])
2339              ("Copy, move,... (Backend)"
2340               ,@(if (featurep 'xemacs) nil
2341                   '(:help "Copying, moving, expiring articles..."))
2342               ["Respool article..." gnus-summary-respool-article t]
2343               ["Move article..." gnus-summary-move-article
2344                (gnus-check-backend-function
2345                 'request-move-article gnus-newsgroup-name)]
2346               ["Copy article..." gnus-summary-copy-article t]
2347               ["Crosspost article..." gnus-summary-crosspost-article
2348                (gnus-check-backend-function
2349                 'request-replace-article gnus-newsgroup-name)]
2350               ["Import file..." gnus-summary-import-article
2351                (gnus-check-backend-function
2352                 'request-accept-article gnus-newsgroup-name)]
2353               ["Create article..." gnus-summary-create-article
2354                (gnus-check-backend-function
2355                 'request-accept-article gnus-newsgroup-name)]
2356               ["Check if posted" gnus-summary-article-posted-p t]
2357               ["Edit article" gnus-summary-edit-article
2358                (not (gnus-group-read-only-p))]
2359               ["Delete article" gnus-summary-delete-article
2360                (gnus-check-backend-function
2361                 'request-expire-articles gnus-newsgroup-name)]
2362               ["Query respool" gnus-summary-respool-query t]
2363               ["Trace respool" gnus-summary-respool-trace t]
2364               ["Delete expirable articles" gnus-summary-expire-articles-now
2365                (gnus-check-backend-function
2366                 'request-expire-articles gnus-newsgroup-name)])
2367              ("Extract"
2368               ["Uudecode" gnus-uu-decode-uu
2369                ,@(if (featurep 'xemacs) '(t)
2370                    '(:help "Decode uuencoded article(s)"))]
2371               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2372               ["Unshar" gnus-uu-decode-unshar t]
2373               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2374               ["Save" gnus-uu-decode-save t]
2375               ["Binhex" gnus-uu-decode-binhex t]
2376               ["Postscript" gnus-uu-decode-postscript t]
2377               ["All MIME parts" gnus-summary-save-parts t])
2378              ("Cache"
2379               ["Enter article" gnus-cache-enter-article t]
2380               ["Remove article" gnus-cache-remove-article t])
2381              ["Translate" gnus-article-babel t]
2382              ["Select article buffer" gnus-summary-select-article-buffer t]
2383              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2384              ["Isearch article..." gnus-summary-isearch-article t]
2385              ["Beginning of the article" gnus-summary-beginning-of-article t]
2386              ["End of the article" gnus-summary-end-of-article t]
2387              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2388              ["Fetch referenced articles" gnus-summary-refer-references t]
2389              ["Fetch current thread" gnus-summary-refer-thread t]
2390              ["Fetch article with id..." gnus-summary-refer-article t]
2391              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2392              ["Redisplay" gnus-summary-show-article t]
2393              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2394       (easy-menu-define
2395         gnus-summary-article-menu gnus-summary-mode-map ""
2396         (cons "Article" innards))
2397
2398       (if (not (keymapp gnus-summary-article-menu))
2399           (easy-menu-define
2400             gnus-article-commands-menu gnus-article-mode-map ""
2401             (cons "Commands" innards))
2402         ;; in Emacs, don't share menu.
2403         (setq gnus-article-commands-menu
2404               (copy-keymap gnus-summary-article-menu))
2405         (define-key gnus-article-mode-map [menu-bar commands]
2406           (cons "Commands" gnus-article-commands-menu))))
2407
2408     (easy-menu-define
2409       gnus-summary-thread-menu gnus-summary-mode-map ""
2410       '("Threads"
2411         ["Find all messages in thread" gnus-summary-refer-thread t]
2412         ["Toggle threading" gnus-summary-toggle-threads t]
2413         ["Hide threads" gnus-summary-hide-all-threads t]
2414         ["Show threads" gnus-summary-show-all-threads t]
2415         ["Hide thread" gnus-summary-hide-thread t]
2416         ["Show thread" gnus-summary-show-thread t]
2417         ["Go to next thread" gnus-summary-next-thread t]
2418         ["Go to previous thread" gnus-summary-prev-thread t]
2419         ["Go down thread" gnus-summary-down-thread t]
2420         ["Go up thread" gnus-summary-up-thread t]
2421         ["Top of thread" gnus-summary-top-thread t]
2422         ["Mark thread as read" gnus-summary-kill-thread t]
2423         ["Lower thread score" gnus-summary-lower-thread t]
2424         ["Raise thread score" gnus-summary-raise-thread t]
2425         ["Rethread current" gnus-summary-rethread-current t]))
2426
2427     (easy-menu-define
2428       gnus-summary-post-menu gnus-summary-mode-map ""
2429       `("Post"
2430         ["Send a message (mail or news)" gnus-summary-post-news
2431          ,@(if (featurep 'xemacs) '(t)
2432              '(:help "Compose a new message (mail or news)"))]
2433         ["Followup" gnus-summary-followup
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Post followup to this article"))]
2436         ["Followup and yank" gnus-summary-followup-with-original
2437          ,@(if (featurep 'xemacs) '(t)
2438              '(:help "Post followup to this article, quoting its contents"))]
2439         ["Supersede article" gnus-summary-supersede-article t]
2440         ["Cancel article" gnus-summary-cancel-article
2441          ,@(if (featurep 'xemacs) '(t)
2442              '(:help "Cancel an article you posted"))]
2443         ["Reply" gnus-summary-reply t]
2444         ["Reply and yank" gnus-summary-reply-with-original t]
2445         ["Wide reply" gnus-summary-wide-reply t]
2446         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2447          ,@(if (featurep 'xemacs) '(t)
2448              '(:help "Mail a reply, quoting this article"))]
2449         ["Very wide reply" gnus-summary-very-wide-reply t]
2450         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2451          ,@(if (featurep 'xemacs) '(t)
2452              '(:help "Mail a very wide reply, quoting this article"))]
2453         ["Mail forward" gnus-summary-mail-forward t]
2454         ["Post forward" gnus-summary-post-forward t]
2455         ["Digest and mail" gnus-uu-digest-mail-forward t]
2456         ["Digest and post" gnus-uu-digest-post-forward t]
2457         ["Resend message" gnus-summary-resend-message t]
2458         ["Resend message edit" gnus-summary-resend-message-edit t]
2459         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2460         ["Send a mail" gnus-summary-mail-other-window t]
2461         ["Create a local message" gnus-summary-news-other-window t]
2462         ["Uuencode and post" gnus-uu-post-news
2463          ,@(if (featurep 'xemacs) '(t)
2464              '(:help "Post a uuencoded article"))]
2465         ["Followup via news" gnus-summary-followup-to-mail t]
2466         ["Followup via news and yank"
2467          gnus-summary-followup-to-mail-with-original t]
2468         ;;("Draft"
2469         ;;["Send" gnus-summary-send-draft t]
2470         ;;["Send bounced" gnus-resend-bounced-mail t])
2471         ))
2472
2473     (cond
2474      ((not (keymapp gnus-summary-post-menu))
2475       (setq gnus-article-post-menu gnus-summary-post-menu))
2476      ((not gnus-article-post-menu)
2477       ;; Don't share post menu.
2478       (setq gnus-article-post-menu
2479             (copy-keymap gnus-summary-post-menu))))
2480     (define-key gnus-article-mode-map [menu-bar post]
2481       (cons "Post" gnus-article-post-menu))
2482
2483     (easy-menu-define
2484       gnus-summary-misc-menu gnus-summary-mode-map ""
2485       `("Gnus"
2486         ("Mark Read"
2487          ["Mark as read" gnus-summary-mark-as-read-forward t]
2488          ["Mark same subject and select"
2489           gnus-summary-kill-same-subject-and-select t]
2490          ["Mark same subject" gnus-summary-kill-same-subject t]
2491          ["Catchup" gnus-summary-catchup
2492           ,@(if (featurep 'xemacs) '(t)
2493               '(:help "Mark unread articles in this group as read"))]
2494          ["Catchup all" gnus-summary-catchup-all t]
2495          ["Catchup to here" gnus-summary-catchup-to-here t]
2496          ["Catchup from here" gnus-summary-catchup-from-here t]
2497          ["Catchup region" gnus-summary-mark-region-as-read
2498           (gnus-mark-active-p)]
2499          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2500         ("Mark Various"
2501          ["Tick" gnus-summary-tick-article-forward t]
2502          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2503          ["Remove marks" gnus-summary-clear-mark-forward t]
2504          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2505          ["Set bookmark" gnus-summary-set-bookmark t]
2506          ["Remove bookmark" gnus-summary-remove-bookmark t])
2507         ("Limit to"
2508          ["Marks..." gnus-summary-limit-to-marks t]
2509          ["Subject..." gnus-summary-limit-to-subject t]
2510          ["Author..." gnus-summary-limit-to-author t]
2511          ["Recipient..." gnus-summary-limit-to-recipient t]
2512          ["Age..." gnus-summary-limit-to-age t]
2513          ["Extra..." gnus-summary-limit-to-extra t]
2514          ["Score..." gnus-summary-limit-to-score t]
2515          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2516          ["Unread" gnus-summary-limit-to-unread t]
2517          ["Unseen" gnus-summary-limit-to-unseen t]
2518          ["Replied" gnus-summary-limit-to-replied t]
2519          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2520          ["Next articles" gnus-summary-limit-to-articles t]
2521          ["Pop limit" gnus-summary-pop-limit t]
2522          ["Show dormant" gnus-summary-limit-include-dormant t]
2523          ["Hide childless dormant"
2524           gnus-summary-limit-exclude-childless-dormant t]
2525          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2526          ["Hide marked" gnus-summary-limit-exclude-marks t]
2527          ["Show expunged" gnus-summary-limit-include-expunged t])
2528         ("Process Mark"
2529          ["Set mark" gnus-summary-mark-as-processable t]
2530          ["Remove mark" gnus-summary-unmark-as-processable t]
2531          ["Remove all marks" gnus-summary-unmark-all-processable t]
2532          ["Invert marks" gnus-uu-invert-processable t]
2533          ["Mark above" gnus-uu-mark-over t]
2534          ["Mark series" gnus-uu-mark-series t]
2535          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2536          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2537          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2538          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2539          ["Mark all" gnus-uu-mark-all t]
2540          ["Mark buffer" gnus-uu-mark-buffer t]
2541          ["Mark sparse" gnus-uu-mark-sparse t]
2542          ["Mark thread" gnus-uu-mark-thread t]
2543          ["Unmark thread" gnus-uu-unmark-thread t]
2544          ("Process Mark Sets"
2545           ["Kill" gnus-summary-kill-process-mark t]
2546           ["Yank" gnus-summary-yank-process-mark
2547            gnus-newsgroup-process-stack]
2548           ["Save" gnus-summary-save-process-mark t]
2549           ["Run command on marked..." gnus-summary-universal-argument t]))
2550         ("Scroll article"
2551          ["Page forward" gnus-summary-next-page
2552           ,@(if (featurep 'xemacs) '(t)
2553               '(:help "Show next page of article"))]
2554          ["Page backward" gnus-summary-prev-page
2555           ,@(if (featurep 'xemacs) '(t)
2556               '(:help "Show previous page of article"))]
2557          ["Line forward" gnus-summary-scroll-up t])
2558         ("Move"
2559          ["Next unread article" gnus-summary-next-unread-article t]
2560          ["Previous unread article" gnus-summary-prev-unread-article t]
2561          ["Next article" gnus-summary-next-article t]
2562          ["Previous article" gnus-summary-prev-article t]
2563          ["Next unread subject" gnus-summary-next-unread-subject t]
2564          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2565          ["Next article same subject" gnus-summary-next-same-subject t]
2566          ["Previous article same subject" gnus-summary-prev-same-subject t]
2567          ["First unread article" gnus-summary-first-unread-article t]
2568          ["Best unread article" gnus-summary-best-unread-article t]
2569          ["Go to subject number..." gnus-summary-goto-subject t]
2570          ["Go to article number..." gnus-summary-goto-article t]
2571          ["Go to the last article" gnus-summary-goto-last-article t]
2572          ["Pop article off history" gnus-summary-pop-article t])
2573         ("Sort"
2574          ["Sort by number" gnus-summary-sort-by-number t]
2575          ["Sort by author" gnus-summary-sort-by-author t]
2576          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2577          ["Sort by subject" gnus-summary-sort-by-subject t]
2578          ["Sort by date" gnus-summary-sort-by-date t]
2579          ["Sort by score" gnus-summary-sort-by-score t]
2580          ["Sort by lines" gnus-summary-sort-by-lines t]
2581          ["Sort by characters" gnus-summary-sort-by-chars t]
2582          ["Randomize" gnus-summary-sort-by-random t]
2583          ["Original sort" gnus-summary-sort-by-original t])
2584         ("Help"
2585          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2586          ["Describe group" gnus-summary-describe-group t]
2587          ["Fetch charter" gnus-group-fetch-charter
2588           ,@(if (featurep 'xemacs) nil
2589               '(:help "Display the charter of the current group"))]
2590          ["Fetch control message" gnus-group-fetch-control
2591           ,@(if (featurep 'xemacs) nil
2592               '(:help "Display the archived control message for the current group"))]
2593          ["Read manual" gnus-info-find-node t])
2594         ("Modes"
2595          ["Pick and read" gnus-pick-mode t]
2596          ["Binary" gnus-binary-mode t])
2597         ("Regeneration"
2598          ["Regenerate" gnus-summary-prepare t]
2599          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2600          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2601          ["Toggle threading" gnus-summary-toggle-threads t])
2602         ["See old articles" gnus-summary-insert-old-articles t]
2603         ["See new articles" gnus-summary-insert-new-articles t]
2604         ["Filter articles..." gnus-summary-execute-command t]
2605         ["Run command on articles..." gnus-summary-universal-argument t]
2606         ["Search articles forward..." gnus-summary-search-article-forward t]
2607         ["Search articles backward..." gnus-summary-search-article-backward t]
2608         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2609         ["Expand window" gnus-summary-expand-window t]
2610         ["Expire expirable articles" gnus-summary-expire-articles
2611          (gnus-check-backend-function
2612           'request-expire-articles gnus-newsgroup-name)]
2613         ["Edit local kill file" gnus-summary-edit-local-kill t]
2614         ["Edit main kill file" gnus-summary-edit-global-kill t]
2615         ["Edit group parameters" gnus-summary-edit-parameters t]
2616         ["Customize group parameters" gnus-summary-customize-parameters t]
2617         ["Send a bug report" gnus-bug t]
2618         ("Exit"
2619          ["Catchup and exit" gnus-summary-catchup-and-exit
2620           ,@(if (featurep 'xemacs) '(t)
2621               '(:help "Mark unread articles in this group as read, then exit"))]
2622          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2623          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2624          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2625          ["Exit group" gnus-summary-exit
2626           ,@(if (featurep 'xemacs) '(t)
2627               '(:help "Exit current group, return to group selection mode"))]
2628          ["Exit group without updating" gnus-summary-exit-no-update t]
2629          ["Exit and goto next group" gnus-summary-next-group t]
2630          ["Exit and goto prev group" gnus-summary-prev-group t]
2631          ["Reselect group" gnus-summary-reselect-current-group t]
2632          ["Rescan group" gnus-summary-rescan-group t]
2633          ["Update dribble" gnus-summary-save-newsrc t])))
2634
2635     (gnus-run-hooks 'gnus-summary-menu-hook)))
2636
2637 (defvar gnus-summary-tool-bar-map nil)
2638
2639 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2640 ;; affect _new_ message buffers.  We might add a function that walks thru all
2641 ;; summary-mode buffers and force the update.
2642 (defun gnus-summary-tool-bar-update (&optional symbol value)
2643   "Update summary mode toolbar.
2644 Setter function for custom variables."
2645   (setq-default gnus-summary-tool-bar-map nil)
2646   (when symbol
2647     ;; When used as ":set" function:
2648     (set-default symbol value))
2649   (when (gnus-buffer-live-p gnus-summary-buffer)
2650     (with-current-buffer gnus-summary-buffer
2651       (gnus-summary-make-tool-bar))))
2652
2653 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2654                                      'gnus-summary-tool-bar-gnome
2655                                    'gnus-summary-tool-bar-retro)
2656   "Specifies the Gnus summary tool bar.
2657
2658 It can be either a list or a symbol refering to a list.  See
2659 `gmm-tool-bar-from-list' for the format of the list.  The
2660 default key map is `gnus-summary-mode-map'.
2661
2662 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2663 `gnus-summary-tool-bar-retro'."
2664   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2665                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2666                  (repeat :tag "User defined list" gmm-tool-bar-item)
2667                  (symbol))
2668   :version "23.0" ;; No Gnus
2669   :initialize 'custom-initialize-default
2670   :set 'gnus-summary-tool-bar-update
2671   :group 'gnus-summary)
2672
2673 (defcustom gnus-summary-tool-bar-gnome
2674   '((gnus-summary-post-news "mail/compose" nil)
2675     (gnus-summary-insert-new-articles "mail/inbox" nil
2676                                       :visible (or (not gnus-agent)
2677                                                    gnus-plugged))
2678     (gnus-summary-reply-with-original "mail/reply")
2679     (gnus-summary-reply "mail/reply" nil :visible nil)
2680     (gnus-summary-followup-with-original "mail/reply-all")
2681     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2682     (gnus-summary-mail-forward "mail/forward")
2683     (gnus-summary-save-article "mail/save")
2684     (gnus-summary-search-article-forward "search" nil :visible nil)
2685     (gnus-summary-print-article "print")
2686     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2687     ;; Some new commands that may need more suitable icons:
2688     (gnus-summary-save-newsrc "save" nil :visible nil)
2689     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2690     (gnus-summary-prev-article "left-arrow")
2691     (gnus-summary-next-article "right-arrow")
2692     (gnus-summary-next-page "next-page")
2693     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2694     ;;
2695     ;; Maybe some sort-by-... could be added:
2696     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2697     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2698     (gnus-summary-mark-as-expirable
2699      "delete" nil
2700      :visible (gnus-check-backend-function 'request-expire-articles
2701                                            gnus-newsgroup-name))
2702     (gnus-summary-mark-as-spam
2703      "mail/spam" t :visible (spam-group-ham-contents-p gnus-newsgroup-name)
2704      :help "Mark as spam")
2705     (gnus-summary-mark-as-read-forward
2706      "mail/not-spam" nil :visible (spam-group-spam-contents-p gnus-newsgroup-name))
2707     ;;
2708     (gnus-summary-exit "exit")
2709     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2710     (gnus-info-find-node "help"))
2711   "List of functions for the summary tool bar (GNOME style).
2712
2713 See `gmm-tool-bar-from-list' for the format of the list."
2714   :type '(repeat gmm-tool-bar-item)
2715   :version "23.0" ;; No Gnus
2716   :initialize 'custom-initialize-default
2717   :set 'gnus-summary-tool-bar-update
2718   :group 'gnus-summary)
2719
2720 (defcustom gnus-summary-tool-bar-retro
2721   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2722     (gnus-summary-next-unread-article "gnus/next-ur")
2723     (gnus-summary-post-news "gnus/post")
2724     (gnus-summary-followup-with-original "gnus/fuwo")
2725     (gnus-summary-followup "gnus/followup")
2726     (gnus-summary-reply-with-original "gnus/reply-wo")
2727     (gnus-summary-reply "gnus/reply")
2728     (gnus-summary-caesar-message "gnus/rot13")
2729     (gnus-uu-decode-uu "gnus/uu-decode")
2730     (gnus-summary-save-article-file "gnus/save-aif")
2731     (gnus-summary-save-article "gnus/save-art")
2732     (gnus-uu-post-news "gnus/uu-post")
2733     (gnus-summary-catchup "gnus/catchup")
2734     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2735     (gnus-summary-exit "gnus/exit-summ")
2736     ;; Some new command that may need more suitable icons:
2737     (gnus-summary-print-article "gnus/print" nil :visible nil)
2738     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2739     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2740     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2741     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2742     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2743     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2744     ;;
2745     (gnus-info-find-node "gnus/help" nil :visible nil))
2746   "List of functions for the summary tool bar (retro look).
2747
2748 See `gmm-tool-bar-from-list' for the format of the list."
2749   :type '(repeat gmm-tool-bar-item)
2750   :version "23.0" ;; No Gnus
2751   :initialize 'custom-initialize-default
2752   :set 'gnus-summary-tool-bar-update
2753   :group 'gnus-summary)
2754
2755 (defcustom gnus-summary-tool-bar-zap-list t
2756   "List of icon items from the global tool bar.
2757 These items are not displayed in the Gnus summary mode tool bar.
2758
2759 See `gmm-tool-bar-from-list' for the format of the list."
2760   :type 'gmm-tool-bar-zap-list
2761   :version "23.0" ;; No Gnus
2762   :initialize 'custom-initialize-default
2763   :set 'gnus-summary-tool-bar-update
2764   :group 'gnus-summary)
2765
2766 (defun gnus-summary-make-tool-bar (&optional force)
2767   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2768 When FORCE, rebuild the tool bar."
2769   (when (and (not (featurep 'xemacs))
2770              (boundp 'tool-bar-mode)
2771              tool-bar-mode
2772              (or (not gnus-summary-tool-bar-map) force))
2773     (let* ((load-path
2774             (gmm-image-load-path "gnus" "mail/save.xpm" 'load-path))
2775            (image-load-path
2776             (gmm-image-load-path "gnus" "mail/save.xpm" 'image-load-path))
2777            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2778                                         gnus-summary-tool-bar-zap-list
2779                                         'gnus-summary-mode-map)))
2780       (when map
2781         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2782         ;; uses it's value.
2783         (setq gnus-summary-tool-bar-map map))))
2784   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2785
2786 (defun gnus-score-set-default (var value)
2787   "A version of set that updates the GNU Emacs menu-bar."
2788   (set var value)
2789   ;; It is the message that forces the active status to be updated.
2790   (message ""))
2791
2792 (defun gnus-make-score-map (type)
2793   "Make a summary score map of type TYPE."
2794   (if t
2795       nil
2796     (let ((headers '(("author" "from" string)
2797                      ("subject" "subject" string)
2798                      ("article body" "body" string)
2799                      ("article head" "head" string)
2800                      ("xref" "xref" string)
2801                      ("extra header" "extra" string)
2802                      ("lines" "lines" number)
2803                      ("followups to author" "followup" string)))
2804           (types '((number ("less than" <)
2805                            ("greater than" >)
2806                            ("equal" =))
2807                    (string ("substring" s)
2808                            ("exact string" e)
2809                            ("fuzzy string" f)
2810                            ("regexp" r))))
2811           (perms '(("temporary" (current-time-string))
2812                    ("permanent" nil)
2813                    ("immediate" now)))
2814           header)
2815       (list
2816        (apply
2817         'nconc
2818         (list
2819          (if (eq type 'lower)
2820              "Lower score"
2821            "Increase score"))
2822         (let (outh)
2823           (while headers
2824             (setq header (car headers))
2825             (setq outh
2826                   (cons
2827                    (apply
2828                     'nconc
2829                     (list (car header))
2830                     (let ((ts (cdr (assoc (nth 2 header) types)))
2831                           outt)
2832                       (while ts
2833                         (setq outt
2834                               (cons
2835                                (apply
2836                                 'nconc
2837                                 (list (caar ts))
2838                                 (let ((ps perms)
2839                                       outp)
2840                                   (while ps
2841                                     (setq outp
2842                                           (cons
2843                                            (vector
2844                                             (caar ps)
2845                                             (list
2846                                              'gnus-summary-score-entry
2847                                              (nth 1 header)
2848                                              (if (or (string= (nth 1 header)
2849                                                               "head")
2850                                                      (string= (nth 1 header)
2851                                                               "body"))
2852                                                  ""
2853                                                (list 'gnus-summary-header
2854                                                      (nth 1 header)))
2855                                              (list 'quote (nth 1 (car ts)))
2856                                              (list 'gnus-score-delta-default
2857                                                    nil)
2858                                              (nth 1 (car ps))
2859                                              t)
2860                                             t)
2861                                            outp))
2862                                     (setq ps (cdr ps)))
2863                                   (list (nreverse outp))))
2864                                outt))
2865                         (setq ts (cdr ts)))
2866                       (list (nreverse outt))))
2867                    outh))
2868             (setq headers (cdr headers)))
2869           (list (nreverse outh))))))))
2870
2871 \f
2872
2873 (defun gnus-summary-mode (&optional group)
2874   "Major mode for reading articles.
2875
2876 All normal editing commands are switched off.
2877 \\<gnus-summary-mode-map>
2878 Each line in this buffer represents one article.  To read an
2879 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2880 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2881 respectively.
2882
2883 You can also post articles and send mail from this buffer.  To
2884 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2885 of an article, type `\\[gnus-summary-reply]'.
2886
2887 There are approx. one gazillion commands you can execute in this
2888 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2889
2890 The following commands are available:
2891
2892 \\{gnus-summary-mode-map}"
2893   (interactive)
2894   (kill-all-local-variables)
2895   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2896     (gnus-summary-make-local-variables))
2897   (gnus-summary-make-local-variables)
2898   (setq gnus-newsgroup-name group)
2899   (when (gnus-visual-p 'summary-menu 'menu)
2900     (gnus-summary-make-menu-bar)
2901     (gnus-summary-make-tool-bar))
2902   (gnus-make-thread-indent-array)
2903   (gnus-simplify-mode-line)
2904   (setq major-mode 'gnus-summary-mode)
2905   (setq mode-name "Summary")
2906   (make-local-variable 'minor-mode-alist)
2907   (use-local-map gnus-summary-mode-map)
2908   (buffer-disable-undo)
2909   (setq buffer-read-only t              ;Disable modification
2910         show-trailing-whitespace nil)
2911   (setq truncate-lines t)
2912   (setq selective-display t)
2913   (setq selective-display-ellipses t)   ;Display `...'
2914   (gnus-summary-set-display-table)
2915   (gnus-set-default-directory)
2916   (make-local-variable 'gnus-summary-line-format)
2917   (make-local-variable 'gnus-summary-line-format-spec)
2918   (make-local-variable 'gnus-summary-dummy-line-format)
2919   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2920   (make-local-variable 'gnus-summary-mark-positions)
2921   (gnus-make-local-hook 'pre-command-hook)
2922   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2923   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2924   (turn-on-gnus-mailing-list-mode)
2925   (mm-enable-multibyte)
2926   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2927   (gnus-update-summary-mark-positions))
2928
2929 (defun gnus-summary-make-local-variables ()
2930   "Make all the local summary buffer variables."
2931   (let (global)
2932     (dolist (local gnus-summary-local-variables)
2933       (if (consp local)
2934           (progn
2935             (if (eq (cdr local) 'global)
2936                 ;; Copy the global value of the variable.
2937                 (setq global (symbol-value (car local)))
2938               ;; Use the value from the list.
2939               (setq global (eval (cdr local))))
2940             (set (make-local-variable (car local)) global))
2941         ;; Simple nil-valued local variable.
2942         (set (make-local-variable local) nil)))))
2943
2944 (defun gnus-summary-clear-local-variables ()
2945   (let ((locals gnus-summary-local-variables))
2946     (while locals
2947       (if (consp (car locals))
2948           (and (symbolp (caar locals))
2949                (set (caar locals) nil))
2950         (and (symbolp (car locals))
2951              (set (car locals) nil)))
2952       (setq locals (cdr locals)))))
2953
2954 ;; Summary data functions.
2955
2956 (defmacro gnus-data-number (data)
2957   `(car ,data))
2958
2959 (defmacro gnus-data-set-number (data number)
2960   `(setcar ,data ,number))
2961
2962 (defmacro gnus-data-mark (data)
2963   `(nth 1 ,data))
2964
2965 (defmacro gnus-data-set-mark (data mark)
2966   `(setcar (nthcdr 1 ,data) ,mark))
2967
2968 (defmacro gnus-data-pos (data)
2969   `(nth 2 ,data))
2970
2971 (defmacro gnus-data-set-pos (data pos)
2972   `(setcar (nthcdr 2 ,data) ,pos))
2973
2974 (defmacro gnus-data-header (data)
2975   `(nth 3 ,data))
2976
2977 (defmacro gnus-data-set-header (data header)
2978   `(setf (nth 3 ,data) ,header))
2979
2980 (defmacro gnus-data-level (data)
2981   `(nth 4 ,data))
2982
2983 (defmacro gnus-data-unread-p (data)
2984   `(= (nth 1 ,data) gnus-unread-mark))
2985
2986 (defmacro gnus-data-read-p (data)
2987   `(/= (nth 1 ,data) gnus-unread-mark))
2988
2989 (defmacro gnus-data-pseudo-p (data)
2990   `(consp (nth 3 ,data)))
2991
2992 (defmacro gnus-data-find (number)
2993   `(assq ,number gnus-newsgroup-data))
2994
2995 (defmacro gnus-data-find-list (number &optional data)
2996   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2997      (memq (assq ,number bdata)
2998            bdata)))
2999
3000 (defmacro gnus-data-make (number mark pos header level)
3001   `(list ,number ,mark ,pos ,header ,level))
3002
3003 (defun gnus-data-enter (after-article number mark pos header level offset)
3004   (let ((data (gnus-data-find-list after-article)))
3005     (unless data
3006       (error "No such article: %d" after-article))
3007     (setcdr data (cons (gnus-data-make number mark pos header level)
3008                        (cdr data)))
3009     (setq gnus-newsgroup-data-reverse nil)
3010     (gnus-data-update-list (cddr data) offset)))
3011
3012 (defun gnus-data-enter-list (after-article list &optional offset)
3013   (when list
3014     (let ((data (and after-article (gnus-data-find-list after-article)))
3015           (ilist list))
3016       (if (not (or data
3017                    after-article))
3018           (let ((odata gnus-newsgroup-data))
3019             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3020             (when offset
3021               (gnus-data-update-list odata offset)))
3022         ;; Find the last element in the list to be spliced into the main
3023         ;; list.
3024         (setq list (last list))
3025         (if (not data)
3026             (progn
3027               (setcdr list gnus-newsgroup-data)
3028               (setq gnus-newsgroup-data ilist)
3029               (when offset
3030                 (gnus-data-update-list (cdr list) offset)))
3031           (setcdr list (cdr data))
3032           (setcdr data ilist)
3033           (when offset
3034             (gnus-data-update-list (cdr list) offset))))
3035       (setq gnus-newsgroup-data-reverse nil))))
3036
3037 (defun gnus-data-remove (article &optional offset)
3038   (let ((data gnus-newsgroup-data))
3039     (if (= (gnus-data-number (car data)) article)
3040         (progn
3041           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3042                 gnus-newsgroup-data-reverse nil)
3043           (when offset
3044             (gnus-data-update-list gnus-newsgroup-data offset)))
3045       (while (cdr data)
3046         (when (= (gnus-data-number (cadr data)) article)
3047           (setcdr data (cddr data))
3048           (when offset
3049             (gnus-data-update-list (cdr data) offset))
3050           (setq data nil
3051                 gnus-newsgroup-data-reverse nil))
3052         (setq data (cdr data))))))
3053
3054 (defmacro gnus-data-list (backward)
3055   `(if ,backward
3056        (or gnus-newsgroup-data-reverse
3057            (setq gnus-newsgroup-data-reverse
3058                  (reverse gnus-newsgroup-data)))
3059      gnus-newsgroup-data))
3060
3061 (defun gnus-data-update-list (data offset)
3062   "Add OFFSET to the POS of all data entries in DATA."
3063   (setq gnus-newsgroup-data-reverse nil)
3064   (while data
3065     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3066     (setq data (cdr data))))
3067
3068 (defun gnus-summary-article-pseudo-p (article)
3069   "Say whether this article is a pseudo article or not."
3070   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3071
3072 (defmacro gnus-summary-article-sparse-p (article)
3073   "Say whether this article is a sparse article or not."
3074   `(memq ,article gnus-newsgroup-sparse))
3075
3076 (defmacro gnus-summary-article-ancient-p (article)
3077   "Say whether this article is a sparse article or not."
3078   `(memq ,article gnus-newsgroup-ancient))
3079
3080 (defun gnus-article-parent-p (number)
3081   "Say whether this article is a parent or not."
3082   (let ((data (gnus-data-find-list number)))
3083     (and (cdr data)              ; There has to be an article after...
3084          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3085             (gnus-data-level (nth 1 data))))))
3086
3087 (defun gnus-article-children (number)
3088   "Return a list of all children to NUMBER."
3089   (let* ((data (gnus-data-find-list number))
3090          (level (gnus-data-level (car data)))
3091          children)
3092     (setq data (cdr data))
3093     (while (and data
3094                 (= (gnus-data-level (car data)) (1+ level)))
3095       (push (gnus-data-number (car data)) children)
3096       (setq data (cdr data)))
3097     children))
3098
3099 (defmacro gnus-summary-skip-intangible ()
3100   "If the current article is intangible, then jump to a different article."
3101   '(let ((to (get-text-property (point) 'gnus-intangible)))
3102      (and to (gnus-summary-goto-subject to))))
3103
3104 (defmacro gnus-summary-article-intangible-p ()
3105   "Say whether this article is intangible or not."
3106   '(get-text-property (point) 'gnus-intangible))
3107
3108 (defun gnus-article-read-p (article)
3109   "Say whether ARTICLE is read or not."
3110   (not (or (memq article gnus-newsgroup-marked)
3111            (memq article gnus-newsgroup-spam-marked)
3112            (memq article gnus-newsgroup-unreads)
3113            (memq article gnus-newsgroup-unselected)
3114            (memq article gnus-newsgroup-dormant))))
3115
3116 ;; Some summary mode macros.
3117
3118 (defmacro gnus-summary-article-number ()
3119   "The article number of the article on the current line.
3120 If there isn't an article number here, then we return the current
3121 article number."
3122   '(progn
3123      (gnus-summary-skip-intangible)
3124      (or (get-text-property (point) 'gnus-number)
3125          (gnus-summary-last-subject))))
3126
3127 (defmacro gnus-summary-article-header (&optional number)
3128   "Return the header of article NUMBER."
3129   `(gnus-data-header (gnus-data-find
3130                       ,(or number '(gnus-summary-article-number)))))
3131
3132 (defmacro gnus-summary-thread-level (&optional number)
3133   "Return the level of thread that starts with article NUMBER."
3134   `(if (and (eq gnus-summary-make-false-root 'dummy)
3135             (get-text-property (point) 'gnus-intangible))
3136        0
3137      (gnus-data-level (gnus-data-find
3138                        ,(or number '(gnus-summary-article-number))))))
3139
3140 (defmacro gnus-summary-article-mark (&optional number)
3141   "Return the mark of article NUMBER."
3142   `(gnus-data-mark (gnus-data-find
3143                     ,(or number '(gnus-summary-article-number)))))
3144
3145 (defmacro gnus-summary-article-pos (&optional number)
3146   "Return the position of the line of article NUMBER."
3147   `(gnus-data-pos (gnus-data-find
3148                    ,(or number '(gnus-summary-article-number)))))
3149
3150 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3151 (defmacro gnus-summary-article-subject (&optional number)
3152   "Return current subject string or nil if nothing."
3153   `(let ((headers
3154           ,(if number
3155                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3156              '(gnus-data-header (assq (gnus-summary-article-number)
3157                                       gnus-newsgroup-data)))))
3158      (and headers
3159           (vectorp headers)
3160           (mail-header-subject headers))))
3161
3162 (defmacro gnus-summary-article-score (&optional number)
3163   "Return current article score."
3164   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3165                   gnus-newsgroup-scored))
3166        gnus-summary-default-score 0))
3167
3168 (defun gnus-summary-article-children (&optional number)
3169   "Return a list of article numbers that are children of article NUMBER."
3170   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3171          (level (gnus-data-level (car data)))
3172          l children)
3173     (while (and (setq data (cdr data))
3174                 (> (setq l (gnus-data-level (car data))) level))
3175       (and (= (1+ level) l)
3176            (push (gnus-data-number (car data))
3177                  children)))
3178     (nreverse children)))
3179
3180 (defun gnus-summary-article-parent (&optional number)
3181   "Return the article number of the parent of article NUMBER."
3182   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3183                                     (gnus-data-list t)))
3184          (level (gnus-data-level (car data))))
3185     (if (zerop level)
3186         ()                              ; This is a root.
3187       ;; We search until we find an article with a level less than
3188       ;; this one.  That function has to be the parent.
3189       (while (and (setq data (cdr data))
3190                   (not (< (gnus-data-level (car data)) level))))
3191       (and data (gnus-data-number (car data))))))
3192
3193 (defun gnus-unread-mark-p (mark)
3194   "Say whether MARK is the unread mark."
3195   (= mark gnus-unread-mark))
3196
3197 (defun gnus-read-mark-p (mark)
3198   "Say whether MARK is one of the marks that mark as read.
3199 This is all marks except unread, ticked, dormant, and expirable."
3200   (not (or (= mark gnus-unread-mark)
3201            (= mark gnus-ticked-mark)
3202            (= mark gnus-spam-mark)
3203            (= mark gnus-dormant-mark)
3204            (= mark gnus-expirable-mark))))
3205
3206 (defmacro gnus-article-mark (number)
3207   "Return the MARK of article NUMBER.
3208 This macro should only be used when computing the mark the \"first\"
3209 time; i.e., when generating the summary lines.  After that,
3210 `gnus-summary-article-mark' should be used to examine the
3211 marks of articles."
3212   `(cond
3213     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3214     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3215     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3216     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3217     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3218     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3219     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3220     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3221            gnus-ancient-mark))))
3222
3223 ;; Saving hidden threads.
3224
3225 (defmacro gnus-save-hidden-threads (&rest forms)
3226   "Save hidden threads, eval FORMS, and restore the hidden threads."
3227   (let ((config (make-symbol "config")))
3228     `(let ((,config (gnus-hidden-threads-configuration)))
3229        (unwind-protect
3230            (save-excursion
3231              ,@forms)
3232          (gnus-restore-hidden-threads-configuration ,config)))))
3233 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3234 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3235
3236 (defun gnus-data-compute-positions ()
3237   "Compute the positions of all articles."
3238   (setq gnus-newsgroup-data-reverse nil)
3239   (let ((data gnus-newsgroup-data))
3240     (save-excursion
3241       (gnus-save-hidden-threads
3242         (gnus-summary-show-all-threads)
3243         (goto-char (point-min))
3244         (while data
3245           (while (get-text-property (point) 'gnus-intangible)
3246             (forward-line 1))
3247           (gnus-data-set-pos (car data) (+ (point) 3))
3248           (setq data (cdr data))
3249           (forward-line 1))))))
3250
3251 (defun gnus-hidden-threads-configuration ()
3252   "Return the current hidden threads configuration."
3253   (save-excursion
3254     (let (config)
3255       (goto-char (point-min))
3256       (while (search-forward "\r" nil t)
3257         (push (1- (point)) config))
3258       config)))
3259
3260 (defun gnus-restore-hidden-threads-configuration (config)
3261   "Restore hidden threads configuration from CONFIG."
3262   (save-excursion
3263     (let (point buffer-read-only)
3264       (while (setq point (pop config))
3265         (when (and (< point (point-max))
3266                    (goto-char point)
3267                    (eq (char-after) ?\n))
3268           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3269
3270 ;; Various summary mode internalish functions.
3271
3272 (defun gnus-mouse-pick-article (e)
3273   (interactive "e")
3274   (mouse-set-point e)
3275   (gnus-summary-next-page nil t))
3276
3277 (defun gnus-summary-set-display-table ()
3278   "Change the display table.
3279 Odd characters have a tendency to mess
3280 up nicely formatted displays - we make all possible glyphs
3281 display only a single character."
3282
3283   ;; We start from the standard display table, if any.
3284   (let ((table (or (copy-sequence standard-display-table)
3285                    (make-display-table)))
3286         (i 32))
3287     ;; Nix out all the control chars...
3288     (while (>= (setq i (1- i)) 0)
3289       (aset table i [??]))
3290    ;; ... but not newline and cr, of course.  (cr is necessary for the
3291     ;; selective display).
3292     (aset table ?\n nil)
3293     (aset table ?\r nil)
3294     ;; We keep TAB as well.
3295     (aset table ?\t nil)
3296     ;; We nix out any glyphs over 126 that are not set already.
3297     (let ((i 256))
3298       (while (>= (setq i (1- i)) 127)
3299         ;; Only modify if the entry is nil.
3300         (unless (aref table i)
3301           (aset table i [??]))))
3302     (setq buffer-display-table table)))
3303
3304 (defun gnus-summary-set-article-display-arrow (pos)
3305   "Update the overlay arrow to point to line at position POS."
3306   (when (and gnus-summary-display-arrow
3307              (boundp 'overlay-arrow-position)
3308              (boundp 'overlay-arrow-string))
3309     (save-excursion
3310       (goto-char pos)
3311       (beginning-of-line)
3312       (unless overlay-arrow-position
3313         (setq overlay-arrow-position (make-marker)))
3314       (setq overlay-arrow-string "=>"
3315             overlay-arrow-position (set-marker overlay-arrow-position
3316                                                (point)
3317                                                (current-buffer))))))
3318
3319 (defun gnus-summary-setup-buffer (group)
3320   "Initialize summary buffer."
3321   (let ((buffer (gnus-summary-buffer-name group))
3322         (dead-name (concat "*Dead Summary "
3323                            (gnus-group-decoded-name group) "*")))
3324     ;; If a dead summary buffer exists, we kill it.
3325     (when (gnus-buffer-live-p dead-name)
3326       (gnus-kill-buffer dead-name))
3327     (if (get-buffer buffer)
3328         (progn
3329           (set-buffer buffer)
3330           (setq gnus-summary-buffer (current-buffer))
3331           (not gnus-newsgroup-prepared))
3332       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3333       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3334       (gnus-summary-mode group)
3335       (when gnus-carpal
3336         (gnus-carpal-setup-buffer 'summary))
3337       (unless gnus-single-article-buffer
3338         (make-local-variable 'gnus-article-buffer)
3339         (make-local-variable 'gnus-article-current)
3340         (make-local-variable 'gnus-original-article-buffer))
3341       (setq gnus-newsgroup-name group)
3342       ;; Set any local variables in the group parameters.
3343       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3344       t)))
3345
3346 (defun gnus-set-global-variables ()
3347   "Set the global equivalents of the buffer-local variables.
3348 They are set to the latest values they had.  These reflect the summary
3349 buffer that was in action when the last article was fetched."
3350   (when (eq major-mode 'gnus-summary-mode)
3351     (setq gnus-summary-buffer (current-buffer))
3352     (let ((name gnus-newsgroup-name)
3353           (marked gnus-newsgroup-marked)
3354           (spam gnus-newsgroup-spam-marked)
3355           (unread gnus-newsgroup-unreads)
3356           (headers gnus-current-headers)
3357           (data gnus-newsgroup-data)
3358           (summary gnus-summary-buffer)
3359           (article-buffer gnus-article-buffer)
3360           (original gnus-original-article-buffer)
3361           (gac gnus-article-current)
3362           (reffed gnus-reffed-article-number)
3363           (score-file gnus-current-score-file)
3364           (default-charset gnus-newsgroup-charset)
3365           vlist)
3366       (let ((locals gnus-newsgroup-variables))
3367         (while locals
3368           (if (consp (car locals))
3369               (push (eval (caar locals)) vlist)
3370             (push (eval (car locals)) vlist))
3371           (setq locals (cdr locals)))
3372         (setq vlist (nreverse vlist)))
3373       (with-current-buffer gnus-group-buffer
3374         (setq gnus-newsgroup-name name
3375               gnus-newsgroup-marked marked
3376               gnus-newsgroup-spam-marked spam
3377               gnus-newsgroup-unreads unread
3378               gnus-current-headers headers
3379               gnus-newsgroup-data data
3380               gnus-article-current gac
3381               gnus-summary-buffer summary
3382               gnus-article-buffer article-buffer
3383               gnus-original-article-buffer original
3384               gnus-reffed-article-number reffed
3385               gnus-current-score-file score-file
3386               gnus-newsgroup-charset default-charset)
3387         (let ((locals gnus-newsgroup-variables))
3388           (while locals
3389             (if (consp (car locals))
3390                 (set (caar locals) (pop vlist))
3391               (set (car locals) (pop vlist)))
3392             (setq locals (cdr locals))))
3393         ;; The article buffer also has local variables.
3394         (when (gnus-buffer-live-p gnus-article-buffer)
3395           (set-buffer gnus-article-buffer)
3396           (setq gnus-summary-buffer summary))))))
3397
3398 (defun gnus-summary-article-unread-p (article)
3399   "Say whether ARTICLE is unread or not."
3400   (memq article gnus-newsgroup-unreads))
3401
3402 (defun gnus-summary-first-article-p (&optional article)
3403   "Return whether ARTICLE is the first article in the buffer."
3404   (if (not (setq article (or article (gnus-summary-article-number))))
3405       nil
3406     (eq article (caar gnus-newsgroup-data))))
3407
3408 (defun gnus-summary-last-article-p (&optional article)
3409   "Return whether ARTICLE is the last article in the buffer."
3410   (if (not (setq article (or article (gnus-summary-article-number))))
3411       ;; All non-existent numbers are the last article.  :-)
3412       t
3413     (not (cdr (gnus-data-find-list article)))))
3414
3415 (defun gnus-make-thread-indent-array ()
3416   (let ((n 200))
3417     (unless (and gnus-thread-indent-array
3418                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3419       (setq gnus-thread-indent-array (make-vector 201 "")
3420             gnus-thread-indent-array-level gnus-thread-indent-level)
3421       (while (>= n 0)
3422         (aset gnus-thread-indent-array n
3423               (make-string (* n gnus-thread-indent-level) ? ))
3424         (setq n (1- n))))))
3425
3426 (defun gnus-update-summary-mark-positions ()
3427   "Compute where the summary marks are to go."
3428   (save-excursion
3429     (when (gnus-buffer-exists-p gnus-summary-buffer)
3430       (set-buffer gnus-summary-buffer))
3431     (let ((spec gnus-summary-line-format-spec)
3432           pos)
3433       (save-excursion
3434         (gnus-set-work-buffer)
3435         (let ((gnus-tmp-unread ?Z)
3436               (gnus-replied-mark ?Z)
3437               (gnus-score-below-mark ?Z)
3438               (gnus-score-over-mark ?Z)
3439               (gnus-undownloaded-mark ?Z)
3440               (gnus-summary-line-format-spec spec)
3441               (gnus-newsgroup-downloadable '(0))
3442               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3443               case-fold-search ignores)
3444           ;; Here, all marks are bound to Z.
3445           (gnus-summary-insert-line header
3446                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3447           (goto-char (point-min))
3448           ;; Memorize the positions of the same characters as dummy marks.
3449           (while (re-search-forward "[A-D]" nil t)
3450             (push (point) ignores))
3451           (erase-buffer)
3452           ;; We use A-D as dummy marks in order to know column positions
3453           ;; where marks should be inserted.
3454           (setq gnus-tmp-unread ?A
3455                 gnus-replied-mark ?B
3456                 gnus-score-below-mark ?C
3457                 gnus-score-over-mark ?C
3458                 gnus-undownloaded-mark ?D)
3459           (gnus-summary-insert-line header
3460                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3461           ;; Ignore characters which aren't dummy marks.
3462           (dolist (p ignores)
3463             (delete-region (goto-char (1- p)) p)
3464             (insert ?Z))
3465           (goto-char (point-min))
3466           (setq pos (list (cons 'unread
3467                                 (and (search-forward "A" nil t)
3468                                      (- (point) (point-min) 1)))))
3469           (goto-char (point-min))
3470           (push (cons 'replied (and (search-forward "B" nil t)
3471                                     (- (point) (point-min) 1)))
3472                 pos)
3473           (goto-char (point-min))
3474           (push (cons 'score (and (search-forward "C" nil t)
3475                                   (- (point) (point-min) 1)))
3476                 pos)
3477           (goto-char (point-min))
3478           (push (cons 'download (and (search-forward "D" nil t)
3479                                      (- (point) (point-min) 1)))
3480                 pos)))
3481       (setq gnus-summary-mark-positions pos))))
3482
3483 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3484   "Insert a dummy root in the summary buffer."
3485   (beginning-of-line)
3486   (gnus-add-text-properties
3487    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3488    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3489
3490 (defun gnus-summary-extract-address-component (from)
3491   (or (car (funcall gnus-extract-address-components from))
3492       from))
3493
3494 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3495   (let ((mail-parse-charset gnus-newsgroup-charset)
3496         ; Is it really necessary to do this next part for each summary line?
3497         ; Luckily, doesn't seem to slow things down much.
3498         (mail-parse-ignored-charsets
3499          (with-current-buffer gnus-summary-buffer
3500            gnus-newsgroup-ignored-charsets)))
3501     (or
3502      (and gnus-ignored-from-addresses
3503           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3504           (let ((extra-headers (mail-header-extra header))
3505                 to
3506                 newsgroups)
3507             (cond
3508              ((setq to (cdr (assq 'To extra-headers)))
3509               (concat gnus-summary-to-prefix
3510                       (inline
3511                         (gnus-summary-extract-address-component
3512                          (funcall gnus-decode-encoded-word-function to)))))
3513              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3514               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3515      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3516
3517 (defun gnus-summary-insert-line (gnus-tmp-header
3518                                  gnus-tmp-level gnus-tmp-current
3519                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3520                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3521                                  &optional gnus-tmp-dummy gnus-tmp-score
3522                                  gnus-tmp-process)
3523   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3524          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3525          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3526          (gnus-tmp-score-char
3527           (if (or (null gnus-summary-default-score)
3528                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3529                       gnus-summary-zcore-fuzz))
3530               ?                         ;Whitespace
3531             (if (< gnus-tmp-score gnus-summary-default-score)
3532                 gnus-score-below-mark gnus-score-over-mark)))
3533          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3534          (gnus-tmp-replied
3535           (cond (gnus-tmp-process gnus-process-mark)
3536                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3537                  gnus-cached-mark)
3538                 (gnus-tmp-replied gnus-replied-mark)
3539                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3540                  gnus-forwarded-mark)
3541                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3542                  gnus-saved-mark)
3543                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3544                  gnus-recent-mark)
3545                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3546                  gnus-unseen-mark)
3547                 (t gnus-no-mark)))
3548          (gnus-tmp-downloaded
3549           (cond (undownloaded
3550                  gnus-undownloaded-mark)
3551                 (gnus-newsgroup-agentized
3552                  gnus-downloaded-mark)
3553                 (t
3554                  gnus-no-mark)))
3555          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3556          (gnus-tmp-name
3557           (cond
3558            ((string-match "<[^>]+> *$" gnus-tmp-from)
3559             (let ((beg (match-beginning 0)))
3560               (or (and (string-match "^\".+\"" gnus-tmp-from)
3561                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3562                   (substring gnus-tmp-from 0 beg))))
3563            ((string-match "(.+)" gnus-tmp-from)
3564             (substring gnus-tmp-from
3565                        (1+ (match-beginning 0)) (1- (match-end 0))))
3566            (t gnus-tmp-from)))
3567          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3568          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3569          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3570          (buffer-read-only nil))
3571     (when (string= gnus-tmp-name "")
3572       (setq gnus-tmp-name gnus-tmp-from))
3573     (unless (numberp gnus-tmp-lines)
3574       (setq gnus-tmp-lines -1))
3575     (if (= gnus-tmp-lines -1)
3576         (setq gnus-tmp-lines "?")
3577       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3578       (gnus-put-text-property
3579      (point)
3580      (progn (eval gnus-summary-line-format-spec) (point))
3581        'gnus-number gnus-tmp-number)
3582     (when (gnus-visual-p 'summary-highlight 'highlight)
3583       (forward-line -1)
3584       (gnus-run-hooks 'gnus-summary-update-hook)
3585       (forward-line 1))))
3586
3587 (defun gnus-summary-update-line (&optional dont-update)
3588   "Update summary line after change."
3589   (when (and gnus-summary-default-score
3590              (not gnus-summary-inhibit-highlight))
3591     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3592            (article (gnus-summary-article-number))
3593            (score (gnus-summary-article-score article)))
3594       (unless dont-update
3595         (if (and gnus-summary-mark-below
3596                  (< (gnus-summary-article-score)
3597                     gnus-summary-mark-below))
3598             ;; This article has a low score, so we mark it as read.
3599             (when (memq article gnus-newsgroup-unreads)
3600               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3601           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3602             ;; This article was previously marked as read on account
3603             ;; of a low score, but now it has risen, so we mark it as
3604             ;; unread.
3605             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3606         (gnus-summary-update-mark
3607          (if (or (null gnus-summary-default-score)
3608                  (<= (abs (- score gnus-summary-default-score))
3609                      gnus-summary-zcore-fuzz))
3610              ?                          ;Whitespace
3611            (if (< score gnus-summary-default-score)
3612                gnus-score-below-mark gnus-score-over-mark))
3613          'score))
3614       ;; Do visual highlighting.
3615       (when (gnus-visual-p 'summary-highlight 'highlight)
3616         (gnus-run-hooks 'gnus-summary-update-hook)))))
3617
3618 (defvar gnus-tmp-new-adopts nil)
3619
3620 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3621   "Return the number of articles in THREAD.
3622 This may be 0 in some cases -- if none of the articles in
3623 the thread are to be displayed."
3624   (let* ((number
3625          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3626           (cond
3627            ((not (listp thread))
3628             1)
3629            ((and (consp thread) (cdr thread))
3630             (apply
3631              '+ 1 (mapcar
3632                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3633            ((null thread)
3634             1)
3635            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3636             1)
3637            (t 0))))
3638     (when (and level (zerop level) gnus-tmp-new-adopts)
3639       (incf number
3640             (apply '+ (mapcar
3641                        'gnus-summary-number-of-articles-in-thread
3642                        gnus-tmp-new-adopts))))
3643     (if char
3644         (if (> number 1) gnus-not-empty-thread-mark
3645           gnus-empty-thread-mark)
3646       number)))
3647
3648 (defsubst gnus-summary-line-message-size (head)
3649   "Return pretty-printed version of message size.
3650 This function is intended to be used in
3651 `gnus-summary-line-format-alist'."
3652   (let ((c (or (mail-header-chars head) -1)))
3653     (cond ((< c 0) "n/a")               ; chars not available
3654           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3655           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3656           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3657           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3658
3659
3660 (defun gnus-summary-set-local-parameters (group)
3661   "Go through the local params of GROUP and set all variable specs in that list."
3662   (let ((vars '(quit-config)))          ; Ignore quit-config.
3663     (dolist (elem (gnus-group-find-parameter group))
3664       (and (consp elem)                 ; Has to be a cons.
3665            (consp (cdr elem))           ; The cdr has to be a list.
3666            (symbolp (car elem))         ; Has to be a symbol in there.
3667            (not (memq (car elem) vars))
3668            (ignore-errors               ; So we set it.
3669              (push (car elem) vars)
3670              (make-local-variable (car elem))
3671              (set (car elem) (eval (nth 1 elem))))))))
3672
3673 (defun gnus-summary-read-group (group &optional show-all no-article
3674                                       kill-buffer no-display backward
3675                                       select-articles)
3676   "Start reading news in newsgroup GROUP.
3677 If SHOW-ALL is non-nil, already read articles are also listed.
3678 If NO-ARTICLE is non-nil, no article is selected initially.
3679 If NO-DISPLAY, don't generate a summary buffer."
3680   (let (result)
3681     (while (and group
3682                 (null (setq result
3683                             (let ((gnus-auto-select-next nil))
3684                               (or (gnus-summary-read-group-1
3685                                    group show-all no-article
3686                                    kill-buffer no-display
3687                                    select-articles)
3688                                   (setq show-all nil
3689                                         select-articles nil)))))
3690                 (eq gnus-auto-select-next 'quietly))
3691       (set-buffer gnus-group-buffer)
3692       ;; The entry function called above goes to the next
3693       ;; group automatically, so we go two groups back
3694       ;; if we are searching for the previous group.
3695       (when backward
3696         (gnus-group-prev-unread-group 2))
3697       (if (not (equal group (gnus-group-group-name)))
3698           (setq group (gnus-group-group-name))
3699         (setq group nil)))
3700     result))
3701
3702 (defun gnus-summary-read-group-1 (group show-all no-article
3703                                         kill-buffer no-display
3704                                         &optional select-articles)
3705   ;; Killed foreign groups can't be entered.
3706   ;;  (when (and (not (gnus-group-native-p group))
3707   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3708   ;;    (error "Dead non-native groups can't be entered"))
3709   (gnus-message 5 "Retrieving newsgroup: %s..."
3710                 (gnus-group-decoded-name group))
3711   (let* ((new-group (gnus-summary-setup-buffer group))
3712          (quit-config (gnus-group-quit-config group))
3713          (did-select (and new-group (gnus-select-newsgroup
3714                                      group show-all select-articles))))
3715     (cond
3716      ;; This summary buffer exists already, so we just select it.
3717      ((not new-group)
3718       (gnus-set-global-variables)
3719       (when kill-buffer
3720         (gnus-kill-or-deaden-summary kill-buffer))
3721       (gnus-configure-windows 'summary 'force)
3722       (gnus-set-mode-line 'summary)
3723       (gnus-summary-position-point)
3724       (message "")
3725       t)
3726      ;; We couldn't select this group.
3727      ((null did-select)
3728       (when (and (eq major-mode 'gnus-summary-mode)
3729                  (not (equal (current-buffer) kill-buffer)))
3730         (kill-buffer (current-buffer))
3731         (if (not quit-config)
3732             (progn
3733               ;; Update the info -- marks might need to be removed,
3734               ;; for instance.
3735               (gnus-summary-update-info)
3736               (set-buffer gnus-group-buffer)
3737               (gnus-group-jump-to-group group)
3738               (gnus-group-next-unread-group 1))
3739           (gnus-handle-ephemeral-exit quit-config)))
3740       (let ((grpinfo (gnus-get-info group)))
3741         (if (null (gnus-info-read grpinfo))
3742             (gnus-message 3 "Group %s contains no messages"
3743                           (gnus-group-decoded-name group))
3744           (gnus-message 3 "Can't select group")))
3745       nil)
3746      ;; The user did a `C-g' while prompting for number of articles,
3747      ;; so we exit this group.
3748      ((eq did-select 'quit)
3749       (and (eq major-mode 'gnus-summary-mode)
3750            (not (equal (current-buffer) kill-buffer))
3751            (kill-buffer (current-buffer)))
3752       (when kill-buffer
3753         (gnus-kill-or-deaden-summary kill-buffer))
3754       (if (not quit-config)
3755           (progn
3756             (set-buffer gnus-group-buffer)
3757             (gnus-group-jump-to-group group)
3758             (gnus-group-next-unread-group 1)
3759             (gnus-configure-windows 'group 'force))
3760         (gnus-handle-ephemeral-exit quit-config))
3761       ;; Finally signal the quit.
3762       (signal 'quit nil))
3763      ;; The group was successfully selected.
3764      (t
3765       (gnus-set-global-variables)
3766       ;; Save the active value in effect when the group was entered.
3767       (setq gnus-newsgroup-active
3768             (gnus-copy-sequence
3769              (gnus-active gnus-newsgroup-name)))
3770       ;; You can change the summary buffer in some way with this hook.
3771       (gnus-run-hooks 'gnus-select-group-hook)
3772       (when (memq 'summary (gnus-update-format-specifications
3773                             nil 'summary 'summary-mode 'summary-dummy))
3774         ;; The format specification for the summary line was updated,
3775         ;; so we need to update the mark positions as well.
3776         (gnus-update-summary-mark-positions))
3777       ;; Do score processing.
3778       (when gnus-use-scoring
3779         (gnus-possibly-score-headers))
3780       ;; Check whether to fill in the gaps in the threads.
3781       (when gnus-build-sparse-threads
3782         (gnus-build-sparse-threads))
3783       ;; Find the initial limit.
3784       (if show-all
3785           (let ((gnus-newsgroup-dormant nil))
3786             (gnus-summary-initial-limit show-all))
3787         (gnus-summary-initial-limit show-all))
3788       ;; Generate the summary buffer.
3789       (unless no-display
3790         (gnus-summary-prepare))
3791       (when gnus-use-trees
3792         (gnus-tree-open group)
3793         (setq gnus-summary-highlight-line-function
3794               'gnus-tree-highlight-article))
3795       ;; If the summary buffer is empty, but there are some low-scored
3796       ;; articles or some excluded dormants, we include these in the
3797       ;; buffer.
3798       (when (and (zerop (buffer-size))
3799                  (not no-display))
3800         (cond (gnus-newsgroup-dormant
3801                (gnus-summary-limit-include-dormant))
3802               ((and gnus-newsgroup-scored show-all)
3803                (gnus-summary-limit-include-expunged t))))
3804       ;; Function `gnus-apply-kill-file' must be called in this hook.
3805       (gnus-run-hooks 'gnus-apply-kill-hook)
3806       (if (and (zerop (buffer-size))
3807                (not no-display))
3808           (progn
3809             ;; This newsgroup is empty.
3810             (gnus-summary-catchup-and-exit nil t)
3811             (gnus-message 6 "No unread news")
3812             (when kill-buffer
3813               (gnus-kill-or-deaden-summary kill-buffer))
3814             ;; Return nil from this function.
3815             nil)
3816         ;; Hide conversation thread subtrees.  We cannot do this in
3817         ;; gnus-summary-prepare-hook since kill processing may not
3818         ;; work with hidden articles.
3819         (gnus-summary-maybe-hide-threads)
3820         (when kill-buffer
3821           (gnus-kill-or-deaden-summary kill-buffer))
3822         (gnus-summary-auto-select-subject)
3823         ;; Show first unread article if requested.
3824         (if (and (not no-article)
3825                  (not no-display)
3826                  gnus-newsgroup-unreads
3827                  gnus-auto-select-first)
3828             (progn
3829               (gnus-configure-windows 'summary)
3830               (let ((art (gnus-summary-article-number)))
3831                 (unless (and (not gnus-plugged)
3832                              (or (memq art gnus-newsgroup-undownloaded)
3833                                  (memq art gnus-newsgroup-downloadable)))
3834                   (gnus-summary-goto-article art))))
3835           ;; Don't select any articles.
3836           (gnus-summary-position-point)
3837           (gnus-configure-windows 'summary 'force)
3838           (gnus-set-mode-line 'summary))
3839         (when (and gnus-auto-center-group
3840                    (get-buffer-window gnus-group-buffer t))
3841           ;; Gotta use windows, because recenter does weird stuff if
3842           ;; the current buffer ain't the displayed window.
3843           (let ((owin (selected-window)))
3844             (select-window (get-buffer-window gnus-group-buffer t))
3845             (when (gnus-group-goto-group group)
3846               (recenter))
3847             (select-window owin)))
3848         ;; Mark this buffer as "prepared".
3849         (setq gnus-newsgroup-prepared t)
3850         (gnus-run-hooks 'gnus-summary-prepared-hook)
3851         (unless (gnus-ephemeral-group-p group)
3852           (gnus-group-update-group group))
3853         t)))))
3854
3855 (defun gnus-summary-auto-select-subject ()
3856   "Select the subject line on initial group entry."
3857   (goto-char (point-min))
3858   (cond
3859    ((eq gnus-auto-select-subject 'best)
3860     (gnus-summary-best-unread-subject))
3861    ((eq gnus-auto-select-subject 'unread)
3862     (gnus-summary-first-unread-subject))
3863    ((eq gnus-auto-select-subject 'unseen)
3864     (gnus-summary-first-unseen-subject))
3865    ((eq gnus-auto-select-subject 'unseen-or-unread)
3866     (gnus-summary-first-unseen-or-unread-subject))
3867    ((eq gnus-auto-select-subject 'first)
3868     ;; Do nothing.
3869     )
3870    ((functionp gnus-auto-select-subject)
3871     (funcall gnus-auto-select-subject))))
3872
3873 (defun gnus-summary-prepare ()
3874   "Generate the summary buffer."
3875   (interactive)
3876   (let ((buffer-read-only nil))
3877     (erase-buffer)
3878     (setq gnus-newsgroup-data nil
3879           gnus-newsgroup-data-reverse nil)
3880     (gnus-run-hooks 'gnus-summary-generate-hook)
3881     ;; Generate the buffer, either with threads or without.
3882     (when gnus-newsgroup-headers
3883       (gnus-summary-prepare-threads
3884        (if gnus-show-threads
3885            (gnus-sort-gathered-threads
3886             (funcall gnus-summary-thread-gathering-function
3887                      (gnus-sort-threads
3888                       (gnus-cut-threads (gnus-make-threads)))))
3889          ;; Unthreaded display.
3890          (gnus-sort-articles gnus-newsgroup-headers))))
3891     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3892     ;; Call hooks for modifying summary buffer.
3893     (goto-char (point-min))
3894     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3895
3896 (defsubst gnus-general-simplify-subject (subject)
3897   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3898   (setq subject
3899         (cond
3900          ;; Truncate the subject.
3901          (gnus-simplify-subject-functions
3902           (gnus-map-function gnus-simplify-subject-functions subject))
3903          ((numberp gnus-summary-gather-subject-limit)
3904           (setq subject (gnus-simplify-subject-re subject))
3905           (if (> (length subject) gnus-summary-gather-subject-limit)
3906               (substring subject 0 gnus-summary-gather-subject-limit)
3907             subject))
3908          ;; Fuzzily simplify it.
3909          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3910           (gnus-simplify-subject-fuzzy subject))
3911          ;; Just remove the leading "Re:".
3912          (t
3913           (gnus-simplify-subject-re subject))))
3914
3915   (if (and gnus-summary-gather-exclude-subject
3916            (string-match gnus-summary-gather-exclude-subject subject))
3917       nil                         ; This article shouldn't be gathered
3918     subject))
3919
3920 (defun gnus-summary-simplify-subject-query ()
3921   "Query where the respool algorithm would put this article."
3922   (interactive)
3923   (gnus-summary-select-article)
3924   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3925
3926 (defun gnus-gather-threads-by-subject (threads)
3927   "Gather threads by looking at Subject headers."
3928   (if (not gnus-summary-make-false-root)
3929       threads
3930     (let ((hashtb (gnus-make-hashtable 1024))
3931           (prev threads)
3932           (result threads)
3933           subject hthread whole-subject)
3934       (while threads
3935         (setq subject (gnus-general-simplify-subject
3936                        (setq whole-subject (mail-header-subject
3937                                             (caar threads)))))
3938         (when subject
3939           (if (setq hthread (gnus-gethash subject hashtb))
3940               (progn
3941                 ;; We enter a dummy root into the thread, if we
3942                 ;; haven't done that already.
3943                 (unless (stringp (caar hthread))
3944                   (setcar hthread (list whole-subject (car hthread))))
3945                 ;; We add this new gathered thread to this gathered
3946                 ;; thread.
3947                 (setcdr (car hthread)
3948                         (nconc (cdar hthread) (list (car threads))))
3949                 ;; Remove it from the list of threads.
3950                 (setcdr prev (cdr threads))
3951                 (setq threads prev))
3952             ;; Enter this thread into the hash table.
3953             (gnus-sethash subject
3954                           (if gnus-summary-make-false-root-always
3955                               (progn
3956                                 ;; If you want a dummy root above all
3957                                 ;; threads...
3958                                 (setcar threads (list whole-subject
3959                                                       (car threads)))
3960                                 threads)
3961                             threads)
3962                           hashtb)))
3963         (setq prev threads)
3964         (setq threads (cdr threads)))
3965       result)))
3966
3967 (defun gnus-gather-threads-by-references (threads)
3968   "Gather threads by looking at References headers."
3969   (let ((idhashtb (gnus-make-hashtable 1024))
3970         (thhashtb (gnus-make-hashtable 1024))
3971         (prev threads)
3972         (result threads)
3973         ids references id gthread gid entered ref)
3974     (while threads
3975       (when (setq references (mail-header-references (caar threads)))
3976         (setq id (mail-header-id (caar threads))
3977               ids (inline (gnus-split-references references))
3978               entered nil)
3979         (while (setq ref (pop ids))
3980           (setq ids (delete ref ids))
3981           (if (not (setq gid (gnus-gethash ref idhashtb)))
3982               (progn
3983                 (gnus-sethash ref id idhashtb)
3984                 (gnus-sethash id threads thhashtb))
3985             (setq gthread (gnus-gethash gid thhashtb))
3986             (unless entered
3987               ;; We enter a dummy root into the thread, if we
3988               ;; haven't done that already.
3989               (unless (stringp (caar gthread))
3990                 (setcar gthread (list (mail-header-subject (caar gthread))
3991                                       (car gthread))))
3992               ;; We add this new gathered thread to this gathered
3993               ;; thread.
3994               (setcdr (car gthread)
3995                       (nconc (cdar gthread) (list (car threads)))))
3996             ;; Add it into the thread hash table.
3997             (gnus-sethash id gthread thhashtb)
3998             (setq entered t)
3999             ;; Remove it from the list of threads.
4000             (setcdr prev (cdr threads))
4001             (setq threads prev))))
4002       (setq prev threads)
4003       (setq threads (cdr threads)))
4004     result))
4005
4006 (defun gnus-sort-gathered-threads (threads)
4007   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4008   (let ((result threads))
4009     (while threads
4010       (when (stringp (caar threads))
4011         (setcdr (car threads)
4012                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4013       (setq threads (cdr threads)))
4014     result))
4015
4016 (defun gnus-thread-loop-p (root thread)
4017   "Say whether ROOT is in THREAD."
4018   (let ((stack (list thread))
4019         (infloop 0)
4020         th)
4021     (while (setq thread (pop stack))
4022       (setq th (cdr thread))
4023       (while (and th
4024                   (not (eq (caar th) root)))
4025         (pop th))
4026       (if th
4027           ;; We have found a loop.
4028           (let (ref-dep)
4029             (setcdr thread (delq (car th) (cdr thread)))
4030             (if (boundp (setq ref-dep (intern "none"
4031                                               gnus-newsgroup-dependencies)))
4032                 (setcdr (symbol-value ref-dep)
4033                         (nconc (cdr (symbol-value ref-dep))
4034                                (list (car th))))
4035               (set ref-dep (list nil (car th))))
4036             (setq infloop 1
4037                   stack nil))
4038         ;; Push all the subthreads onto the stack.
4039         (push (cdr thread) stack)))
4040     infloop))
4041
4042 (defun gnus-make-threads ()
4043   "Go through the dependency hashtb and find the roots.  Return all threads."
4044   (let (threads)
4045     (while (catch 'infloop
4046              (mapatoms
4047               (lambda (refs)
4048                 ;; Deal with self-referencing References loops.
4049                 (when (and (car (symbol-value refs))
4050                            (not (zerop
4051                                  (apply
4052                                   '+
4053                                   (mapcar
4054                                    (lambda (thread)
4055                                      (gnus-thread-loop-p
4056                                       (car (symbol-value refs)) thread))
4057                                    (cdr (symbol-value refs)))))))
4058                   (setq threads nil)
4059                   (throw 'infloop t))
4060                 (unless (car (symbol-value refs))
4061                   ;; These threads do not refer back to any other
4062                   ;; articles, so they're roots.
4063                   (setq threads (append (cdr (symbol-value refs)) threads))))
4064               gnus-newsgroup-dependencies)))
4065     threads))
4066
4067 ;; Build the thread tree.
4068 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4069   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4070
4071 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4072 if it was already present.
4073
4074 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4075 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4076 Message-IDs will be renamed to a unique Message-ID before being
4077 entered.
4078
4079 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4080   (let* ((id (mail-header-id header))
4081          (id-dep (and id (intern id dependencies)))
4082          parent-id ref ref-dep ref-header replaced)
4083     ;; Enter this `header' in the `dependencies' table.
4084     (cond
4085      ((not id-dep)
4086       (setq header nil))
4087      ;; The first two cases do the normal part: enter a new `header'
4088      ;; in the `dependencies' table.
4089      ((not (boundp id-dep))
4090       (set id-dep (list header)))
4091      ((null (car (symbol-value id-dep)))
4092       (setcar (symbol-value id-dep) header))
4093
4094      ;; From here the `header' was already present in the
4095      ;; `dependencies' table.
4096      (force-new
4097       ;; Overrides an existing entry;
4098       ;; just set the header part of the entry.
4099       (setcar (symbol-value id-dep) header)
4100       (setq replaced t))
4101
4102      ;; Renames the existing `header' to a unique Message-ID.
4103      ((not gnus-summary-ignore-duplicates)
4104       ;; An article with this Message-ID has already been seen.
4105       ;; We rename the Message-ID.
4106       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4107            (list header))
4108       (mail-header-set-id header id))
4109
4110      ;; The last case ignores an existing entry, except it adds any
4111      ;; additional Xrefs (in case the two articles came from different
4112      ;; servers.
4113      ;; Also sets `header' to `nil' meaning that the `dependencies'
4114      ;; table was *not* modified.
4115      (t
4116       (mail-header-set-xref
4117        (car (symbol-value id-dep))
4118        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4119                    "")
4120                (or (mail-header-xref header) "")))
4121       (setq header nil)))
4122
4123     (when (and header (not replaced))
4124       ;; First check that we are not creating a References loop.
4125       (setq parent-id (gnus-parent-id (mail-header-references header)))
4126       (setq ref parent-id)
4127       (while (and ref
4128                   (setq ref-dep (intern-soft ref dependencies))
4129                   (boundp ref-dep)
4130                   (setq ref-header (car (symbol-value ref-dep))))
4131         (if (string= id ref)
4132             ;; Yuk!  This is a reference loop.  Make the article be a
4133             ;; root article.
4134             (progn
4135               (mail-header-set-references (car (symbol-value id-dep)) "none")
4136               (setq ref nil)
4137               (setq parent-id nil))
4138           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4139       (setq ref-dep (intern (or parent-id "none") dependencies))
4140       (if (boundp ref-dep)
4141           (setcdr (symbol-value ref-dep)
4142                   (nconc (cdr (symbol-value ref-dep))
4143                          (list (symbol-value id-dep))))
4144         (set ref-dep (list nil (symbol-value id-dep)))))
4145     header))
4146
4147 (defun gnus-extract-message-id-from-in-reply-to (string)
4148   (if (string-match "<[^>]+>" string)
4149       (substring string (match-beginning 0) (match-end 0))
4150     nil))
4151
4152 (defun gnus-build-sparse-threads ()
4153   (let ((headers gnus-newsgroup-headers)
4154         (mail-parse-charset gnus-newsgroup-charset)
4155         (gnus-summary-ignore-duplicates t)
4156         header references generation relations
4157         subject child end new-child date)
4158     ;; First we create an alist of generations/relations, where
4159     ;; generations is how much we trust the relation, and the relation
4160     ;; is parent/child.
4161     (gnus-message 7 "Making sparse threads...")
4162     (save-excursion
4163       (nnheader-set-temp-buffer " *gnus sparse threads*")
4164       (while (setq header (pop headers))
4165         (when (and (setq references (mail-header-references header))
4166                    (not (string= references "")))
4167           (insert references)
4168           (setq child (mail-header-id header)
4169                 subject (mail-header-subject header)
4170                 date (mail-header-date header)
4171                 generation 0)
4172           (while (search-backward ">" nil t)
4173             (setq end (1+ (point)))
4174             (when (search-backward "<" nil t)
4175               (setq new-child (buffer-substring (point) end))
4176               (push (list (incf generation)
4177                           child (setq child new-child)
4178                           subject date)
4179                     relations)))
4180           (when child
4181             (push (list (1+ generation) child nil subject) relations))
4182           (erase-buffer)))
4183       (kill-buffer (current-buffer)))
4184     ;; Sort over trustworthiness.
4185     (mapcar
4186      (lambda (relation)
4187        (when (gnus-dependencies-add-header
4188               (make-full-mail-header
4189                gnus-reffed-article-number
4190                (nth 3 relation) "" (or (nth 4 relation) "")
4191                (nth 1 relation)
4192                (or (nth 2 relation) "") 0 0 "")
4193               gnus-newsgroup-dependencies nil)
4194          (push gnus-reffed-article-number gnus-newsgroup-limit)
4195          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4196          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4197                gnus-newsgroup-reads)
4198          (decf gnus-reffed-article-number)))
4199      (sort relations 'car-less-than-car))
4200     (gnus-message 7 "Making sparse threads...done")))
4201
4202 (defun gnus-build-old-threads ()
4203   ;; Look at all the articles that refer back to old articles, and
4204   ;; fetch the headers for the articles that aren't there.  This will
4205   ;; build complete threads - if the roots haven't been expired by the
4206   ;; server, that is.
4207   (let ((mail-parse-charset gnus-newsgroup-charset)
4208         id heads)
4209     (mapatoms
4210      (lambda (refs)
4211        (when (not (car (symbol-value refs)))
4212          (setq heads (cdr (symbol-value refs)))
4213          (while heads
4214            (if (memq (mail-header-number (caar heads))
4215                      gnus-newsgroup-dormant)
4216                (setq heads (cdr heads))
4217              (setq id (symbol-name refs))
4218              (while (and (setq id (gnus-build-get-header id))
4219                          (not (car (gnus-id-to-thread id)))))
4220              (setq heads nil)))))
4221      gnus-newsgroup-dependencies)))
4222
4223 (defsubst gnus-remove-odd-characters (string)
4224   "Translate STRING into something that doesn't contain weird characters."
4225   (mm-subst-char-in-string
4226    ?\r ?\-
4227    (mm-subst-char-in-string ?\n ?\- string t) t))
4228
4229 ;; This function has to be called with point after the article number
4230 ;; on the beginning of the line.
4231 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4232   (let ((eol (point-at-eol))
4233         (buffer (current-buffer))
4234         header references in-reply-to)
4235
4236     ;; overview: [num subject from date id refs chars lines misc]
4237     (unwind-protect
4238         (let (x)
4239           (narrow-to-region (point) eol)
4240           (unless (eobp)
4241             (forward-char))
4242
4243           (setq header
4244                 (make-full-mail-header
4245                  number                 ; number
4246                  (condition-case ()     ; subject
4247                      (gnus-remove-odd-characters
4248                       (funcall gnus-decode-encoded-word-function
4249                                (setq x (nnheader-nov-field))))
4250                    (error x))
4251                  (condition-case ()     ; from
4252                      (gnus-remove-odd-characters
4253                       (funcall gnus-decode-encoded-word-function
4254                                (setq x (nnheader-nov-field))))
4255                    (error x))
4256                  (nnheader-nov-field)   ; date
4257                  (nnheader-nov-read-message-id number)  ; id
4258                  (setq references (nnheader-nov-field)) ; refs
4259                  (nnheader-nov-read-integer) ; chars
4260                  (nnheader-nov-read-integer) ; lines
4261                  (unless (eobp)
4262                    (if (looking-at "Xref: ")
4263                        (goto-char (match-end 0)))
4264                    (nnheader-nov-field)) ; Xref
4265                  (nnheader-nov-parse-extra)))) ; extra
4266
4267       (widen))
4268
4269     (when (and (string= references "")
4270                (setq in-reply-to (mail-header-extra header))
4271                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4272       (mail-header-set-references
4273        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4274
4275     (when gnus-alter-header-function
4276       (funcall gnus-alter-header-function header))
4277     (gnus-dependencies-add-header header dependencies force-new)))
4278
4279 (defun gnus-build-get-header (id)
4280   "Look through the buffer of NOV lines and find the header to ID.
4281 Enter this line into the dependencies hash table, and return
4282 the id of the parent article (if any)."
4283   (let ((deps gnus-newsgroup-dependencies)
4284         found header)
4285     (prog1
4286         (save-excursion
4287           (set-buffer nntp-server-buffer)
4288           (let ((case-fold-search nil))
4289             (goto-char (point-min))
4290             (while (and (not found)
4291                         (search-forward id nil t))
4292               (beginning-of-line)
4293               (setq found (looking-at
4294                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4295                                    (regexp-quote id))))
4296               (or found (beginning-of-line 2)))
4297             (when found
4298               (beginning-of-line)
4299               (and
4300                (setq header (gnus-nov-parse-line
4301                              (read (current-buffer)) deps))
4302                (gnus-parent-id (mail-header-references header))))))
4303       (when header
4304         (let ((number (mail-header-number header)))
4305           (push number gnus-newsgroup-limit)
4306           (push header gnus-newsgroup-headers)
4307           (if (memq number gnus-newsgroup-unselected)
4308               (progn
4309                 (setq gnus-newsgroup-unreads
4310                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4311                                                number))
4312                 (setq gnus-newsgroup-unselected
4313                       (delq number gnus-newsgroup-unselected)))
4314             (push number gnus-newsgroup-ancient)))))))
4315
4316 (defun gnus-build-all-threads ()
4317   "Read all the headers."
4318   (let ((gnus-summary-ignore-duplicates t)
4319         (mail-parse-charset gnus-newsgroup-charset)
4320         (dependencies gnus-newsgroup-dependencies)
4321         header article)
4322     (save-excursion
4323       (set-buffer nntp-server-buffer)
4324       (let ((case-fold-search nil))
4325         (goto-char (point-min))
4326         (while (not (eobp))
4327           (ignore-errors
4328             (setq article (read (current-buffer))
4329                   header (gnus-nov-parse-line article dependencies)))
4330           (when header
4331             (with-current-buffer gnus-summary-buffer
4332               (push header gnus-newsgroup-headers)
4333               (if (memq (setq article (mail-header-number header))
4334                         gnus-newsgroup-unselected)
4335                   (progn
4336                     (setq gnus-newsgroup-unreads
4337                           (gnus-add-to-sorted-list
4338                            gnus-newsgroup-unreads article))
4339                     (setq gnus-newsgroup-unselected
4340                           (delq article gnus-newsgroup-unselected)))
4341                 (push article gnus-newsgroup-ancient)))
4342             (forward-line 1)))))))
4343
4344 (defun gnus-summary-update-article-line (article header)
4345   "Update the line for ARTICLE using HEADER."
4346   (let* ((id (mail-header-id header))
4347          (thread (gnus-id-to-thread id)))
4348     (unless thread
4349       (error "Article in no thread"))
4350     ;; Update the thread.
4351     (setcar thread header)
4352     (gnus-summary-goto-subject article)
4353     (let* ((datal (gnus-data-find-list article))
4354            (data (car datal))
4355            (buffer-read-only nil)
4356            (level (gnus-summary-thread-level)))
4357       (gnus-delete-line)
4358       (let ((inserted (- (point)
4359                          (progn
4360                            (gnus-summary-insert-line
4361                             header level nil
4362                             (memq article gnus-newsgroup-undownloaded)
4363                             (gnus-article-mark article)
4364                             (memq article gnus-newsgroup-replied)
4365                             (memq article gnus-newsgroup-expirable)
4366                             ;; Only insert the Subject string when it's different
4367                             ;; from the previous Subject string.
4368                             (if (and
4369                                  gnus-show-threads
4370                                  (gnus-subject-equal
4371                                   (condition-case ()
4372                                       (mail-header-subject
4373                                        (gnus-data-header
4374                                         (cadr
4375                                          (gnus-data-find-list
4376                                           article
4377                                           (gnus-data-list t)))))
4378                                     ;; Error on the side of excessive subjects.
4379                                     (error ""))
4380                                   (mail-header-subject header)))
4381                                 ""
4382                               (mail-header-subject header))
4383                             nil (cdr (assq article gnus-newsgroup-scored))
4384                             (memq article gnus-newsgroup-processable))
4385                            (point)))))
4386         (when (cdr datal)
4387           (gnus-data-update-list
4388            (cdr datal)
4389            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4390
4391 (defun gnus-summary-update-article (article &optional iheader)
4392   "Update ARTICLE in the summary buffer."
4393   (set-buffer gnus-summary-buffer)
4394   (let* ((header (gnus-summary-article-header article))
4395          (id (mail-header-id header))
4396          (data (gnus-data-find article))
4397          (thread (gnus-id-to-thread id))
4398          (references (mail-header-references header))
4399          (parent
4400           (gnus-id-to-thread
4401            (or (gnus-parent-id
4402                 (when (and references
4403                            (not (equal "" references)))
4404                   references))
4405                "none")))
4406          (buffer-read-only nil)
4407          (old (car thread)))
4408     (when thread
4409       (unless iheader
4410         (setcar thread nil)
4411         (when parent
4412           (delq thread parent)))
4413       (if (gnus-summary-insert-subject id header)
4414           ;; Set the (possibly) new article number in the data structure.
4415           (gnus-data-set-number data (gnus-id-to-article id))
4416         (setcar thread old)
4417         nil))))
4418
4419 (defun gnus-rebuild-thread (id &optional line)
4420   "Rebuild the thread containing ID.
4421 If LINE, insert the rebuilt thread starting on line LINE."
4422   (let ((buffer-read-only nil)
4423         old-pos current thread data)
4424     (if (not gnus-show-threads)
4425         (setq thread (list (car (gnus-id-to-thread id))))
4426       ;; Get the thread this article is part of.
4427       (setq thread (gnus-remove-thread id)))
4428     (setq old-pos (point-at-bol))
4429     (setq current (save-excursion
4430                     (and (re-search-backward "[\r\n]" nil t)
4431                          (gnus-summary-article-number))))
4432     ;; If this is a gathered thread, we have to go some re-gathering.
4433     (when (stringp (car thread))
4434       (let ((subject (car thread))
4435             roots thr)
4436         (setq thread (cdr thread))
4437         (while thread
4438           (unless (memq (setq thr (gnus-id-to-thread
4439                                    (gnus-root-id
4440                                     (mail-header-id (caar thread)))))
4441                         roots)
4442             (push thr roots))
4443           (setq thread (cdr thread)))
4444         ;; We now have all (unique) roots.
4445         (if (= (length roots) 1)
4446             ;; All the loose roots are now one solid root.
4447             (setq thread (car roots))
4448           (setq thread (cons subject (gnus-sort-threads roots))))))
4449     (let (threads)
4450       ;; We then insert this thread into the summary buffer.
4451       (when line
4452         (goto-char (point-min))
4453         (forward-line (1- line)))
4454       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4455         (if gnus-show-threads
4456             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4457           (gnus-summary-prepare-unthreaded thread))
4458         (setq data (nreverse gnus-newsgroup-data))
4459         (setq threads gnus-newsgroup-threads))
4460       ;; We splice the new data into the data structure.
4461       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4462       ;;!!! then we want to insert at the beginning of the buffer.
4463       ;;!!! That happens to be true with Gnus now, but that may
4464       ;;!!! change in the future.  Perhaps.
4465       (gnus-data-enter-list
4466        (if line nil current) data (- (point) old-pos))
4467       (setq gnus-newsgroup-threads
4468             (nconc threads gnus-newsgroup-threads))
4469       (gnus-data-compute-positions))))
4470
4471 (defun gnus-number-to-header (number)
4472   "Return the header for article NUMBER."
4473   (let ((headers gnus-newsgroup-headers))
4474     (while (and headers
4475                 (not (= number (mail-header-number (car headers)))))
4476       (pop headers))
4477     (when headers
4478       (car headers))))
4479
4480 (defun gnus-parent-headers (in-headers &optional generation)
4481   "Return the headers of the GENERATIONeth parent of HEADERS."
4482   (unless generation
4483     (setq generation 1))
4484   (let ((parent t)
4485         (headers in-headers)
4486         references)
4487     (while (and parent
4488                 (not (zerop generation))
4489                 (setq references (mail-header-references headers)))
4490       (setq headers (if (and references
4491                              (setq parent (gnus-parent-id references)))
4492                         (car (gnus-id-to-thread parent))
4493                       nil))
4494       (decf generation))
4495     (and (not (eq headers in-headers))
4496          headers)))
4497
4498 (defun gnus-id-to-thread (id)
4499   "Return the (sub-)thread where ID appears."
4500   (gnus-gethash id gnus-newsgroup-dependencies))
4501
4502 (defun gnus-id-to-article (id)
4503   "Return the article number of ID."
4504   (let ((thread (gnus-id-to-thread id)))
4505     (when (and thread
4506                (car thread))
4507       (mail-header-number (car thread)))))
4508
4509 (defun gnus-id-to-header (id)
4510   "Return the article headers of ID."
4511   (car (gnus-id-to-thread id)))
4512
4513 (defun gnus-article-displayed-root-p (article)
4514   "Say whether ARTICLE is a root(ish) article."
4515   (let ((level (gnus-summary-thread-level article))
4516         (refs (mail-header-references  (gnus-summary-article-header article)))
4517         particle)
4518     (cond
4519      ((null level) nil)
4520      ((zerop level) t)
4521      ((null refs) t)
4522      ((null (gnus-parent-id refs)) t)
4523      ((and (= 1 level)
4524            (null (setq particle (gnus-id-to-article
4525                                  (gnus-parent-id refs))))
4526            (null (gnus-summary-thread-level particle)))))))
4527
4528 (defun gnus-root-id (id)
4529   "Return the id of the root of the thread where ID appears."
4530   (let (last-id prev)
4531     (while (and id (setq prev (car (gnus-id-to-thread id))))
4532       (setq last-id id
4533             id (gnus-parent-id (mail-header-references prev))))
4534     last-id))
4535
4536 (defun gnus-articles-in-thread (thread)
4537   "Return the list of articles in THREAD."
4538   (cons (mail-header-number (car thread))
4539         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4540
4541 (defun gnus-remove-thread (id &optional dont-remove)
4542   "Remove the thread that has ID in it."
4543   (let (headers thread last-id)
4544     ;; First go up in this thread until we find the root.
4545     (setq last-id (gnus-root-id id)
4546           headers (message-flatten-list (gnus-id-to-thread last-id)))
4547     ;; We have now found the real root of this thread.  It might have
4548     ;; been gathered into some loose thread, so we have to search
4549     ;; through the threads to find the thread we wanted.
4550     (let ((threads gnus-newsgroup-threads)
4551           sub)
4552       (while threads
4553         (setq sub (car threads))
4554         (if (stringp (car sub))
4555             ;; This is a gathered thread, so we look at the roots
4556             ;; below it to find whether this article is in this
4557             ;; gathered root.
4558             (progn
4559               (setq sub (cdr sub))
4560               (while sub
4561                 (when (member (caar sub) headers)
4562                   (setq thread (car threads)
4563                         threads nil
4564                         sub nil))
4565                 (setq sub (cdr sub))))
4566           ;; It's an ordinary thread, so we check it.
4567           (when (eq (car sub) (car headers))
4568             (setq thread sub
4569                   threads nil)))
4570         (setq threads (cdr threads)))
4571       ;; If this article is in no thread, then it's a root.
4572       (if thread
4573           (unless dont-remove
4574             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4575         (setq thread (gnus-id-to-thread last-id)))
4576       (when thread
4577         (prog1
4578             thread                      ; We return this thread.
4579           (unless dont-remove
4580             (if (stringp (car thread))
4581                 (progn
4582                   ;; If we use dummy roots, then we have to remove the
4583                   ;; dummy root as well.
4584                   (when (eq gnus-summary-make-false-root 'dummy)
4585                     ;; We go to the dummy root by going to
4586                     ;; the first sub-"thread", and then one line up.
4587                     (gnus-summary-goto-article
4588                      (mail-header-number (caadr thread)))
4589                     (forward-line -1)
4590                     (gnus-delete-line)
4591                     (gnus-data-compute-positions))
4592                   (setq thread (cdr thread))
4593                   (while thread
4594                     (gnus-remove-thread-1 (car thread))
4595                     (setq thread (cdr thread))))
4596               (gnus-remove-thread-1 thread))))))))
4597
4598 (defun gnus-remove-thread-1 (thread)
4599   "Remove the thread THREAD recursively."
4600   (let ((number (mail-header-number (pop thread)))
4601         d)
4602     (setq thread (reverse thread))
4603     (while thread
4604       (gnus-remove-thread-1 (pop thread)))
4605     (when (setq d (gnus-data-find number))
4606       (goto-char (gnus-data-pos d))
4607       (gnus-summary-show-thread)
4608       (gnus-data-remove
4609        number
4610        (- (point-at-bol)
4611           (prog1
4612               (1+ (point-at-eol))
4613             (gnus-delete-line)))))))
4614
4615 (defun gnus-sort-threads-1 (threads func)
4616   (sort (mapcar (lambda (thread)
4617                   (cons (car thread)
4618                         (and (cdr thread)
4619                              (gnus-sort-threads-1 (cdr thread) func))))
4620                 threads) func))
4621
4622 (defun gnus-sort-threads (threads)
4623   "Sort THREADS."
4624   (if (not gnus-thread-sort-functions)
4625       threads
4626     (gnus-message 8 "Sorting threads...")
4627     (let ((max-lisp-eval-depth 5000))
4628       (prog1 (gnus-sort-threads-1
4629          threads
4630          (gnus-make-sort-function gnus-thread-sort-functions))
4631         (gnus-message 8 "Sorting threads...done")))))
4632
4633 (defun gnus-sort-articles (articles)
4634   "Sort ARTICLES."
4635   (when gnus-article-sort-functions
4636     (gnus-message 7 "Sorting articles...")
4637     (prog1
4638         (setq gnus-newsgroup-headers
4639               (sort articles (gnus-make-sort-function
4640                               gnus-article-sort-functions)))
4641       (gnus-message 7 "Sorting articles...done"))))
4642
4643 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4644 (defmacro gnus-thread-header (thread)
4645   "Return header of first article in THREAD.
4646 Note that THREAD must never, ever be anything else than a variable -
4647 using some other form will lead to serious barfage."
4648   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4649   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4650   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4651         (vector thread) 2))
4652
4653 (defsubst gnus-article-sort-by-number (h1 h2)
4654   "Sort articles by article number."
4655   (< (mail-header-number h1)
4656      (mail-header-number h2)))
4657
4658 (defun gnus-thread-sort-by-number (h1 h2)
4659   "Sort threads by root article number."
4660   (gnus-article-sort-by-number
4661    (gnus-thread-header h1) (gnus-thread-header h2)))
4662
4663 (defsubst gnus-article-sort-by-random (h1 h2)
4664   "Sort articles by article number."
4665   (zerop (random 2)))
4666
4667 (defun gnus-thread-sort-by-random (h1 h2)
4668   "Sort threads by root article number."
4669   (gnus-article-sort-by-random
4670    (gnus-thread-header h1) (gnus-thread-header h2)))
4671
4672 (defsubst gnus-article-sort-by-lines (h1 h2)
4673   "Sort articles by article Lines header."
4674   (< (mail-header-lines h1)
4675      (mail-header-lines h2)))
4676
4677 (defun gnus-thread-sort-by-lines (h1 h2)
4678   "Sort threads by root article Lines header."
4679   (gnus-article-sort-by-lines
4680    (gnus-thread-header h1) (gnus-thread-header h2)))
4681
4682 (defsubst gnus-article-sort-by-chars (h1 h2)
4683   "Sort articles by octet length."
4684   (< (mail-header-chars h1)
4685      (mail-header-chars h2)))
4686
4687 (defun gnus-thread-sort-by-chars (h1 h2)
4688   "Sort threads by root article octet length."
4689   (gnus-article-sort-by-chars
4690    (gnus-thread-header h1) (gnus-thread-header h2)))
4691
4692 (defsubst gnus-article-sort-by-author (h1 h2)
4693   "Sort articles by root author."
4694   (string-lessp
4695    (let ((extract (funcall
4696                    gnus-extract-address-components
4697                    (mail-header-from h1))))
4698      (or (car extract) (cadr extract) ""))
4699    (let ((extract (funcall
4700                    gnus-extract-address-components
4701                    (mail-header-from h2))))
4702      (or (car extract) (cadr extract) ""))))
4703
4704 (defun gnus-thread-sort-by-author (h1 h2)
4705   "Sort threads by root author."
4706   (gnus-article-sort-by-author
4707    (gnus-thread-header h1)  (gnus-thread-header h2)))
4708
4709 (defsubst gnus-article-sort-by-recipient (h1 h2)
4710   "Sort articles by recipient."
4711   (string-lessp
4712    (let ((extract (funcall
4713                    gnus-extract-address-components
4714                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4715      (or (car extract) (cadr extract)))
4716    (let ((extract (funcall
4717                    gnus-extract-address-components
4718                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4719      (or (car extract) (cadr extract)))))
4720
4721 (defun gnus-thread-sort-by-recipient (h1 h2)
4722   "Sort threads by root recipient."
4723   (gnus-article-sort-by-recipient
4724    (gnus-thread-header h1) (gnus-thread-header h2)))
4725
4726 (defsubst gnus-article-sort-by-subject (h1 h2)
4727   "Sort articles by root subject."
4728   (string-lessp
4729    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4730    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4731
4732 (defun gnus-thread-sort-by-subject (h1 h2)
4733   "Sort threads by root subject."
4734   (gnus-article-sort-by-subject
4735    (gnus-thread-header h1) (gnus-thread-header h2)))
4736
4737 (defsubst gnus-article-sort-by-date (h1 h2)
4738   "Sort articles by root article date."
4739   (time-less-p
4740    (gnus-date-get-time (mail-header-date h1))
4741    (gnus-date-get-time (mail-header-date h2))))
4742
4743 (defun gnus-thread-sort-by-date (h1 h2)
4744   "Sort threads by root article date."
4745   (gnus-article-sort-by-date
4746    (gnus-thread-header h1) (gnus-thread-header h2)))
4747
4748 (defsubst gnus-article-sort-by-score (h1 h2)
4749   "Sort articles by root article score.
4750 Unscored articles will be counted as having a score of zero."
4751   (> (or (cdr (assq (mail-header-number h1)
4752                     gnus-newsgroup-scored))
4753          gnus-summary-default-score 0)
4754      (or (cdr (assq (mail-header-number h2)
4755                     gnus-newsgroup-scored))
4756          gnus-summary-default-score 0)))
4757
4758 (defun gnus-thread-sort-by-score (h1 h2)
4759   "Sort threads by root article score."
4760   (gnus-article-sort-by-score
4761    (gnus-thread-header h1) (gnus-thread-header h2)))
4762
4763 (defun gnus-thread-sort-by-total-score (h1 h2)
4764   "Sort threads by the sum of all scores in the thread.
4765 Unscored articles will be counted as having a score of zero."
4766   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4767
4768 (defun gnus-thread-total-score (thread)
4769   ;; This function find the total score of THREAD.
4770   (cond
4771    ((null thread)
4772     0)
4773    ((consp thread)
4774     (if (stringp (car thread))
4775         (apply gnus-thread-score-function 0
4776                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4777       (gnus-thread-total-score-1 thread)))
4778    (t
4779     (gnus-thread-total-score-1 (list thread)))))
4780
4781 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4782   "Sort threads such that the thread with the most recently arrived article comes first."
4783   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4784
4785 (defun gnus-thread-highest-number (thread)
4786   "Return the highest article number in THREAD."
4787   (apply 'max (mapcar (lambda (header)
4788                         (mail-header-number header))
4789                       (message-flatten-list thread))))
4790
4791 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4792   "Sort threads such that the thread with the most recently dated article comes first."
4793   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4794
4795 (defun gnus-thread-latest-date (thread)
4796   "Return the highest article date in THREAD."
4797   (let ((previous-time 0))
4798     (apply 'max
4799            (mapcar
4800             (lambda (header)
4801               (setq previous-time
4802                     (condition-case ()
4803                         (time-to-seconds (mail-header-parse-date
4804                                           (mail-header-date header)))
4805                       (error previous-time))))
4806             (sort
4807              (message-flatten-list thread)
4808              (lambda (h1 h2)
4809                (< (mail-header-number h1)
4810                   (mail-header-number h2))))))))
4811
4812 (defun gnus-thread-total-score-1 (root)
4813   ;; This function find the total score of the thread below ROOT.
4814   (setq root (car root))
4815   (apply gnus-thread-score-function
4816          (or (append
4817               (mapcar 'gnus-thread-total-score
4818                       (cdr (gnus-id-to-thread (mail-header-id root))))
4819               (when (> (mail-header-number root) 0)
4820                 (list (or (cdr (assq (mail-header-number root)
4821                                      gnus-newsgroup-scored))
4822                           gnus-summary-default-score 0))))
4823              (list gnus-summary-default-score)
4824              '(0))))
4825
4826 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4827 (defvar gnus-tmp-prev-subject nil)
4828 (defvar gnus-tmp-false-parent nil)
4829 (defvar gnus-tmp-root-expunged nil)
4830 (defvar gnus-tmp-dummy-line nil)
4831
4832 (eval-when-compile (defvar gnus-tmp-header))
4833 (defun gnus-extra-header (type &optional header)
4834   "Return the extra header of TYPE."
4835   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4836       ""))
4837
4838 (defvar gnus-tmp-thread-tree-header-string "")
4839
4840 (defcustom gnus-sum-thread-tree-root "> "
4841   "With %B spec, used for the root of a thread.
4842 If nil, use subject instead."
4843   :version "22.1"
4844   :type '(radio (const :format "%v  " nil) string)
4845   :group 'gnus-thread)
4846
4847 (defcustom gnus-sum-thread-tree-false-root "> "
4848   "With %B spec, used for a false root of a thread.
4849 If nil, use subject instead."
4850   :version "22.1"
4851   :type '(radio (const :format "%v  " nil) string)
4852   :group 'gnus-thread)
4853
4854 (defcustom gnus-sum-thread-tree-single-indent ""
4855   "With %B spec, used for a thread with just one message.
4856 If nil, use subject instead."
4857   :version "22.1"
4858   :type '(radio (const :format "%v  " nil) string)
4859   :group 'gnus-thread)
4860
4861 (defcustom gnus-sum-thread-tree-vertical "| "
4862   "With %B spec, used for drawing a vertical line."
4863   :version "22.1"
4864   :type 'string
4865   :group 'gnus-thread)
4866
4867 (defcustom gnus-sum-thread-tree-indent "  "
4868   "With %B spec, used for indenting."
4869   :version "22.1"
4870   :type 'string
4871   :group 'gnus-thread)
4872
4873 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4874   "With %B spec, used for a leaf with brothers."
4875   :version "22.1"
4876   :type 'string
4877   :group 'gnus-thread)
4878
4879 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4880   "With %B spec, used for a leaf without brothers."
4881   :version "22.1"
4882   :type 'string
4883   :group 'gnus-thread)
4884
4885 (defun gnus-summary-prepare-threads (threads)
4886   "Prepare summary buffer from THREADS and indentation LEVEL.
4887 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4888 or a straight list of headers."
4889   (gnus-message 7 "Generating summary...")
4890
4891   (setq gnus-newsgroup-threads threads)
4892   (beginning-of-line)
4893
4894   (let ((gnus-tmp-level 0)
4895         (default-score (or gnus-summary-default-score 0))
4896         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4897         (building-line-count gnus-summary-display-while-building)
4898         (building-count (integerp gnus-summary-display-while-building))
4899         thread number subject stack state gnus-tmp-gathered beg-match
4900         new-roots gnus-tmp-new-adopts thread-end simp-subject
4901         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4902         gnus-tmp-replied gnus-tmp-subject-or-nil
4903         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4904         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4905         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4906         tree-stack)
4907
4908     (setq gnus-tmp-prev-subject nil
4909           gnus-tmp-thread-tree-header-string "")
4910
4911     (if (vectorp (car threads))
4912         ;; If this is a straight (sic) list of headers, then a
4913         ;; threaded summary display isn't required, so we just create
4914         ;; an unthreaded one.
4915         (gnus-summary-prepare-unthreaded threads)
4916
4917       ;; Do the threaded display.
4918
4919       (if gnus-summary-display-while-building
4920           (switch-to-buffer (buffer-name)))
4921       (while (or threads stack gnus-tmp-new-adopts new-roots)
4922
4923         (if (and (= gnus-tmp-level 0)
4924                  (or (not stack)
4925                      (= (caar stack) 0))
4926                  (not gnus-tmp-false-parent)
4927                  (or gnus-tmp-new-adopts new-roots))
4928             (if gnus-tmp-new-adopts
4929                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4930                       thread (list (car gnus-tmp-new-adopts))
4931                       gnus-tmp-header (caar thread)
4932                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4933               (when new-roots
4934                 (setq thread (list (car new-roots))
4935                       gnus-tmp-header (caar thread)
4936                       new-roots (cdr new-roots))))
4937
4938           (if threads
4939               ;; If there are some threads, we do them before the
4940               ;; threads on the stack.
4941               (setq thread threads
4942                     gnus-tmp-header (caar thread))
4943             ;; There were no current threads, so we pop something off
4944             ;; the stack.
4945             (setq state (car stack)
4946                   gnus-tmp-level (car state)
4947                   tree-stack (cadr state)
4948                   thread (caddr state)
4949                   stack (cdr stack)
4950                   gnus-tmp-header (caar thread))))
4951
4952         (setq gnus-tmp-false-parent nil)
4953         (setq gnus-tmp-root-expunged nil)
4954         (setq thread-end nil)
4955
4956         (if (stringp gnus-tmp-header)
4957             ;; The header is a dummy root.
4958             (cond
4959              ((eq gnus-summary-make-false-root 'adopt)
4960               ;; We let the first article adopt the rest.
4961               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4962                                                (cddar thread)))
4963               (setq gnus-tmp-gathered
4964                     (nconc (mapcar
4965                             (lambda (h) (mail-header-number (car h)))
4966                             (cddar thread))
4967                            gnus-tmp-gathered))
4968               (setq thread (cons (list (caar thread)
4969                                        (cadar thread))
4970                                  (cdr thread)))
4971               (setq gnus-tmp-level -1
4972                     gnus-tmp-false-parent t))
4973              ((eq gnus-summary-make-false-root 'empty)
4974               ;; We print adopted articles with empty subject fields.
4975               (setq gnus-tmp-gathered
4976                     (nconc (mapcar
4977                             (lambda (h) (mail-header-number (car h)))
4978                             (cddar thread))
4979                            gnus-tmp-gathered))
4980               (setq gnus-tmp-level -1))
4981              ((eq gnus-summary-make-false-root 'dummy)
4982               ;; We remember that we probably want to output a dummy
4983               ;; root.
4984               (setq gnus-tmp-dummy-line gnus-tmp-header)
4985               (setq gnus-tmp-prev-subject gnus-tmp-header))
4986              (t
4987               ;; We do not make a root for the gathered
4988               ;; sub-threads at all.
4989               (setq gnus-tmp-level -1)))
4990
4991           (setq number (mail-header-number gnus-tmp-header)
4992                 subject (mail-header-subject gnus-tmp-header)
4993                 simp-subject (gnus-simplify-subject-fully subject))
4994
4995           (cond
4996            ;; If the thread has changed subject, we might want to make
4997            ;; this subthread into a root.
4998            ((and (null gnus-thread-ignore-subject)
4999                  (not (zerop gnus-tmp-level))
5000                  gnus-tmp-prev-subject
5001                  (not (string= gnus-tmp-prev-subject simp-subject)))
5002             (setq new-roots (nconc new-roots (list (car thread)))
5003                   thread-end t
5004                   gnus-tmp-header nil))
5005            ;; If the article lies outside the current limit,
5006            ;; then we do not display it.
5007            ((not (memq number gnus-newsgroup-limit))
5008             (setq gnus-tmp-gathered
5009                   (nconc (mapcar
5010                           (lambda (h) (mail-header-number (car h)))
5011                           (cdar thread))
5012                          gnus-tmp-gathered))
5013             (setq gnus-tmp-new-adopts (if (cdar thread)
5014                                           (append gnus-tmp-new-adopts
5015                                                   (cdar thread))
5016                                         gnus-tmp-new-adopts)
5017                   thread-end t
5018                   gnus-tmp-header nil)
5019             (when (zerop gnus-tmp-level)
5020               (setq gnus-tmp-root-expunged t)))
5021            ;; Perhaps this article is to be marked as read?
5022            ((and gnus-summary-mark-below
5023                  (< (or (cdr (assq number gnus-newsgroup-scored))
5024                         default-score)
5025                     gnus-summary-mark-below)
5026                  ;; Don't touch sparse articles.
5027                  (not (gnus-summary-article-sparse-p number))
5028                  (not (gnus-summary-article-ancient-p number)))
5029             (setq gnus-newsgroup-unreads
5030                   (delq number gnus-newsgroup-unreads))
5031             (if gnus-newsgroup-auto-expire
5032                 (setq gnus-newsgroup-expirable
5033                       (gnus-add-to-sorted-list
5034                        gnus-newsgroup-expirable number))
5035               (push (cons number gnus-low-score-mark)
5036                     gnus-newsgroup-reads))))
5037
5038           (when gnus-tmp-header
5039             ;; We may have an old dummy line to output before this
5040             ;; article.
5041             (when (and gnus-tmp-dummy-line
5042                        (gnus-subject-equal
5043                         gnus-tmp-dummy-line
5044                         (mail-header-subject gnus-tmp-header)))
5045               (gnus-summary-insert-dummy-line
5046                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5047               (setq gnus-tmp-dummy-line nil))
5048
5049             ;; Compute the mark.
5050             (setq gnus-tmp-unread (gnus-article-mark number))
5051
5052             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5053                                   gnus-tmp-header gnus-tmp-level)
5054                   gnus-newsgroup-data)
5055
5056             ;; Actually insert the line.
5057             (setq
5058              gnus-tmp-subject-or-nil
5059              (cond
5060               ((and gnus-thread-ignore-subject
5061                     gnus-tmp-prev-subject
5062                     (not (string= gnus-tmp-prev-subject simp-subject)))
5063                subject)
5064               ((zerop gnus-tmp-level)
5065                (if (and (eq gnus-summary-make-false-root 'empty)
5066                         (memq number gnus-tmp-gathered)
5067                         gnus-tmp-prev-subject
5068                         (string= gnus-tmp-prev-subject simp-subject))
5069                    gnus-summary-same-subject
5070                  subject))
5071               (t gnus-summary-same-subject)))
5072             (if (and (eq gnus-summary-make-false-root 'adopt)
5073                      (= gnus-tmp-level 1)
5074                      (memq number gnus-tmp-gathered))
5075                 (setq gnus-tmp-opening-bracket ?\<
5076                       gnus-tmp-closing-bracket ?\>)
5077               (setq gnus-tmp-opening-bracket ?\[
5078                     gnus-tmp-closing-bracket ?\]))
5079             (setq
5080              gnus-tmp-indentation
5081              (aref gnus-thread-indent-array gnus-tmp-level)
5082              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5083              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5084                                 gnus-summary-default-score 0)
5085              gnus-tmp-score-char
5086              (if (or (null gnus-summary-default-score)
5087                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5088                          gnus-summary-zcore-fuzz))
5089                  ?                      ;Whitespace
5090                (if (< gnus-tmp-score gnus-summary-default-score)
5091                    gnus-score-below-mark gnus-score-over-mark))
5092              gnus-tmp-replied
5093              (cond ((memq number gnus-newsgroup-processable)
5094                     gnus-process-mark)
5095                    ((memq number gnus-newsgroup-cached)
5096                     gnus-cached-mark)
5097                    ((memq number gnus-newsgroup-replied)
5098                     gnus-replied-mark)
5099                    ((memq number gnus-newsgroup-forwarded)
5100                     gnus-forwarded-mark)
5101                    ((memq number gnus-newsgroup-saved)
5102                     gnus-saved-mark)
5103                    ((memq number gnus-newsgroup-recent)
5104                     gnus-recent-mark)
5105                    ((memq number gnus-newsgroup-unseen)
5106                     gnus-unseen-mark)
5107                    (t gnus-no-mark))
5108              gnus-tmp-downloaded
5109              (cond ((memq number gnus-newsgroup-undownloaded)
5110                     gnus-undownloaded-mark)
5111                    (gnus-newsgroup-agentized
5112                     gnus-downloaded-mark)
5113                    (t
5114                     gnus-no-mark))
5115              gnus-tmp-from (mail-header-from gnus-tmp-header)
5116              gnus-tmp-name
5117              (cond
5118               ((string-match "<[^>]+> *$" gnus-tmp-from)
5119                (setq beg-match (match-beginning 0))
5120                (or (and (string-match "^\".+\"" gnus-tmp-from)
5121                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5122                    (substring gnus-tmp-from 0 beg-match)))
5123               ((string-match "(.+)" gnus-tmp-from)
5124                (substring gnus-tmp-from
5125                           (1+ (match-beginning 0)) (1- (match-end 0))))
5126               (t gnus-tmp-from))
5127
5128              ;; Do the %B string
5129              gnus-tmp-thread-tree-header-string
5130              (cond
5131               ((not gnus-show-threads) "")
5132               ((zerop gnus-tmp-level)
5133                (cond ((cdar thread)
5134                       (or gnus-sum-thread-tree-root subject))
5135                      (gnus-tmp-new-adopts
5136                       (or gnus-sum-thread-tree-false-root subject))
5137                      (t
5138                       (or gnus-sum-thread-tree-single-indent subject))))
5139               (t
5140                (concat (apply 'concat
5141                               (mapcar (lambda (item)
5142                                         (if (= item 1)
5143                                             gnus-sum-thread-tree-vertical
5144                                           gnus-sum-thread-tree-indent))
5145                                       (cdr (reverse tree-stack))))
5146                        (if (nth 1 thread)
5147                            gnus-sum-thread-tree-leaf-with-other
5148                          gnus-sum-thread-tree-single-leaf)))))
5149             (when (string= gnus-tmp-name "")
5150               (setq gnus-tmp-name gnus-tmp-from))
5151             (unless (numberp gnus-tmp-lines)
5152               (setq gnus-tmp-lines -1))
5153             (if (= gnus-tmp-lines -1)
5154                 (setq gnus-tmp-lines "?")
5155               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5156               (gnus-put-text-property
5157              (point)
5158              (progn (eval gnus-summary-line-format-spec) (point))
5159                'gnus-number number)
5160             (when gnus-visual-p
5161               (forward-line -1)
5162               (gnus-run-hooks 'gnus-summary-update-hook)
5163               (forward-line 1))
5164
5165             (setq gnus-tmp-prev-subject simp-subject)))
5166
5167         (when (nth 1 thread)
5168           (push (list (max 0 gnus-tmp-level)
5169                       (copy-sequence tree-stack)
5170                       (nthcdr 1 thread))
5171                 stack))
5172         (push (if (nth 1 thread) 1 0) tree-stack)
5173         (incf gnus-tmp-level)
5174         (setq threads (if thread-end nil (cdar thread)))
5175         (if gnus-summary-display-while-building
5176             (if building-count
5177                 (progn
5178                   ;; use a set frequency
5179                   (setq building-line-count (1- building-line-count))
5180                   (when (= building-line-count 0)
5181                     (sit-for 0)
5182                     (setq building-line-count
5183                           gnus-summary-display-while-building)))
5184               ;; always
5185               (sit-for 0)))
5186         (unless threads
5187           (setq gnus-tmp-level 0)))))
5188   (gnus-message 7 "Generating summary...done"))
5189
5190 (defun gnus-summary-prepare-unthreaded (headers)
5191   "Generate an unthreaded summary buffer based on HEADERS."
5192   (let (header number mark)
5193
5194     (beginning-of-line)
5195
5196     (while headers
5197       ;; We may have to root out some bad articles...
5198       (when (memq (setq number (mail-header-number
5199                                 (setq header (pop headers))))
5200                   gnus-newsgroup-limit)
5201         ;; Mark article as read when it has a low score.
5202         (when (and gnus-summary-mark-below
5203                    (< (or (cdr (assq number gnus-newsgroup-scored))
5204                           gnus-summary-default-score 0)
5205                       gnus-summary-mark-below)
5206                    (not (gnus-summary-article-ancient-p number)))
5207           (setq gnus-newsgroup-unreads
5208                 (delq number gnus-newsgroup-unreads))
5209           (if gnus-newsgroup-auto-expire
5210               (push number gnus-newsgroup-expirable)
5211             (push (cons number gnus-low-score-mark)
5212                   gnus-newsgroup-reads)))
5213
5214         (setq mark (gnus-article-mark number))
5215         (push (gnus-data-make number mark (1+ (point)) header 0)
5216               gnus-newsgroup-data)
5217         (gnus-summary-insert-line
5218          header 0 number
5219          (memq number gnus-newsgroup-undownloaded)
5220          mark (memq number gnus-newsgroup-replied)
5221          (memq number gnus-newsgroup-expirable)
5222          (mail-header-subject header) nil
5223          (cdr (assq number gnus-newsgroup-scored))
5224          (memq number gnus-newsgroup-processable))))))
5225
5226 (defun gnus-summary-remove-list-identifiers ()
5227   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5228   (let ((regexp (if (consp gnus-list-identifiers)
5229                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5230                   gnus-list-identifiers))
5231         changed subject)
5232     (when regexp
5233       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5234       (dolist (header gnus-newsgroup-headers)
5235         (setq subject (mail-header-subject header)
5236               changed nil)
5237         (while (string-match regexp subject)
5238           (setq subject
5239                 (concat (substring subject 0 (match-beginning 1))
5240                         (substring subject (match-end 0)))
5241                 changed t))
5242         (when changed
5243           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5244             (setq subject
5245                   (concat (substring subject 0 (match-beginning 1))
5246                           (substring subject (match-end 1)))))
5247           (mail-header-set-subject header subject))))))
5248
5249 (defun gnus-fetch-headers (articles)
5250   "Fetch headers of ARTICLES."
5251   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5252     (gnus-message 5 "Fetching headers for %s..." name)
5253     (prog1
5254         (if (eq 'nov
5255                 (setq gnus-headers-retrieved-by
5256                       (gnus-retrieve-headers
5257                        articles gnus-newsgroup-name
5258                        ;; We might want to fetch old headers, but
5259                        ;; not if there is only 1 article.
5260                        (and (or (and
5261                                  (not (eq gnus-fetch-old-headers 'some))
5262                                  (not (numberp gnus-fetch-old-headers)))
5263                                 (> (length articles) 1))
5264                             gnus-fetch-old-headers))))
5265             (gnus-get-newsgroup-headers-xover
5266              articles nil nil gnus-newsgroup-name t)
5267           (gnus-get-newsgroup-headers))
5268       (gnus-message 5 "Fetching headers for %s...done" name))))
5269
5270 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5271   "Select newsgroup GROUP.
5272 If READ-ALL is non-nil, all articles in the group are selected.
5273 If SELECT-ARTICLES, only select those articles from GROUP."
5274   (let* ((entry (gnus-group-entry group))
5275          ;;!!! Dirty hack; should be removed.
5276          (gnus-summary-ignore-duplicates
5277           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5278               t
5279             gnus-summary-ignore-duplicates))
5280          (info (nth 2 entry))
5281          articles fetched-articles cached)
5282
5283     (unless (gnus-check-server
5284              (set (make-local-variable 'gnus-current-select-method)
5285                   (gnus-find-method-for-group group)))
5286       (error "Couldn't open server"))
5287
5288     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5289         (gnus-activate-group group)     ; Or we can activate it...
5290         (progn                          ; Or we bug out.
5291           (when (equal major-mode 'gnus-summary-mode)
5292             (gnus-kill-buffer (current-buffer)))
5293           (error "Couldn't activate group %s: %s"
5294                  group (gnus-status-message group))))
5295
5296     (unless (gnus-request-group group t)
5297       (when (equal major-mode 'gnus-summary-mode)
5298         (gnus-kill-buffer (current-buffer)))
5299       (error "Couldn't request group %s: %s"
5300              group (gnus-status-message group)))
5301
5302     (when gnus-agent
5303       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5304
5305       (setq gnus-summary-use-undownloaded-faces
5306             (gnus-agent-find-parameter
5307              group
5308              'agent-enable-undownloaded-faces)))
5309
5310     (setq gnus-newsgroup-name group
5311           gnus-newsgroup-unselected nil
5312           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5313
5314     (let ((display (gnus-group-find-parameter group 'display)))
5315       (setq gnus-newsgroup-display
5316             (cond
5317              ((not (zerop (or (car-safe read-all) 0)))
5318               ;; The user entered the group with C-u SPC/RET, let's show
5319               ;; all articles.
5320               'gnus-not-ignore)
5321              ((eq display 'all)
5322               'gnus-not-ignore)
5323              ((arrayp display)
5324               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5325              ((numberp display)
5326               ;; The following is probably the "correct" solution, but
5327               ;; it makes Gnus fetch all headers and then limit the
5328               ;; articles (which is slow), so instead we hack the
5329               ;; select-articles parameter instead. -- Simon Josefsson
5330               ;; <jas@kth.se>
5331               ;;
5332               ;; (gnus-byte-compile
5333               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5334               ;;                         display)))))
5335               (setq select-articles
5336                     (gnus-uncompress-range
5337                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5338                              (if (> tmp 0)
5339                                  tmp
5340                                1))
5341                            (cdr (gnus-active group)))))
5342               nil)
5343              (t
5344               nil))))
5345
5346     (gnus-summary-setup-default-charset)
5347
5348     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5349     (when (gnus-virtual-group-p group)
5350       (setq cached gnus-newsgroup-cached))
5351
5352     (setq gnus-newsgroup-unreads
5353           (gnus-sorted-ndifference
5354            (gnus-sorted-ndifference gnus-newsgroup-unreads
5355                                     gnus-newsgroup-marked)
5356            gnus-newsgroup-dormant))
5357
5358     (setq gnus-newsgroup-processable nil)
5359
5360     (gnus-update-read-articles group gnus-newsgroup-unreads)
5361
5362     ;; Adjust and set lists of article marks.
5363     (when info
5364       (gnus-adjust-marked-articles info))
5365     (if (setq articles select-articles)
5366         (setq gnus-newsgroup-unselected
5367               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5368       (setq articles (gnus-articles-to-read group read-all)))
5369
5370     (cond
5371      ((null articles)
5372       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5373       'quit)
5374      ((eq articles 0) nil)
5375      (t
5376       ;; Init the dependencies hash table.
5377       (setq gnus-newsgroup-dependencies
5378             (gnus-make-hashtable (length articles)))
5379       (gnus-set-global-variables)
5380       ;; Retrieve the headers and read them in.
5381
5382       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5383
5384       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5385       (when cached
5386         (setq gnus-newsgroup-cached cached))
5387
5388       ;; Suppress duplicates?
5389       (when gnus-suppress-duplicates
5390         (gnus-dup-suppress-articles))
5391
5392       ;; Set the initial limit.
5393       (setq gnus-newsgroup-limit (copy-sequence articles))
5394       ;; Remove canceled articles from the list of unread articles.
5395       (setq fetched-articles
5396             (mapcar (lambda (headers) (mail-header-number headers))
5397                     gnus-newsgroup-headers))
5398       (setq gnus-newsgroup-articles fetched-articles)
5399       (setq gnus-newsgroup-unreads
5400             (gnus-sorted-nintersection
5401              gnus-newsgroup-unreads fetched-articles))
5402       (gnus-compute-unseen-list)
5403
5404       ;; Removed marked articles that do not exist.
5405       (gnus-update-missing-marks
5406        (gnus-sorted-difference articles fetched-articles))
5407       ;; We might want to build some more threads first.
5408       (when (and gnus-fetch-old-headers
5409                  (eq gnus-headers-retrieved-by 'nov))
5410         (if (eq gnus-fetch-old-headers 'invisible)
5411             (gnus-build-all-threads)
5412           (gnus-build-old-threads)))
5413       ;; Let the Gnus agent mark articles as read.
5414       (when gnus-agent
5415         (gnus-agent-get-undownloaded-list))
5416       ;; Remove list identifiers from subject
5417       (when gnus-list-identifiers
5418         (gnus-summary-remove-list-identifiers))
5419       ;; Check whether auto-expire is to be done in this group.
5420       (setq gnus-newsgroup-auto-expire
5421             (gnus-group-auto-expirable-p group))
5422       ;; Set up the article buffer now, if necessary.
5423       (unless gnus-single-article-buffer
5424         (gnus-article-setup-buffer))
5425       ;; First and last article in this newsgroup.
5426       (when gnus-newsgroup-headers
5427         (setq gnus-newsgroup-begin
5428               (mail-header-number (car gnus-newsgroup-headers))
5429               gnus-newsgroup-end
5430               (mail-header-number
5431                (gnus-last-element gnus-newsgroup-headers))))
5432       ;; GROUP is successfully selected.
5433       (or gnus-newsgroup-headers t)))))
5434
5435 (defun gnus-compute-unseen-list ()
5436   ;; The `seen' marks are treated specially.
5437   (if (not gnus-newsgroup-seen)
5438       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5439     (setq gnus-newsgroup-unseen
5440           (gnus-inverse-list-range-intersection
5441            gnus-newsgroup-articles gnus-newsgroup-seen))))
5442
5443 (defun gnus-summary-display-make-predicate (display)
5444   (require 'gnus-agent)
5445   (when (= (length display) 1)
5446     (setq display (car display)))
5447   (unless gnus-summary-display-cache
5448     (dolist (elem (append '((unread . unread)
5449                             (read . read)
5450                             (unseen . unseen))
5451                           gnus-article-mark-lists))
5452       (push (cons (cdr elem)
5453                   (gnus-byte-compile
5454                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5455             gnus-summary-display-cache)))
5456   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5457         (gnus-category-predicate-cache gnus-summary-display-cache))
5458     (gnus-get-predicate display)))
5459
5460 ;; Uses the dynamically bound `number' variable.
5461 (eval-when-compile
5462   (defvar number))
5463 (defun gnus-article-marked-p (type &optional article)
5464   (let ((article (or article number)))
5465     (cond
5466      ((eq type 'tick)
5467       (memq article gnus-newsgroup-marked))
5468      ((eq type 'spam)
5469       (memq article gnus-newsgroup-spam-marked))
5470      ((eq type 'unsend)
5471       (memq article gnus-newsgroup-unsendable))
5472      ((eq type 'undownload)
5473       (memq article gnus-newsgroup-undownloaded))
5474      ((eq type 'download)
5475       (memq article gnus-newsgroup-downloadable))
5476      ((eq type 'unread)
5477       (memq article gnus-newsgroup-unreads))
5478      ((eq type 'read)
5479       (memq article gnus-newsgroup-reads))
5480      ((eq type 'dormant)
5481       (memq article gnus-newsgroup-dormant) )
5482      ((eq type 'expire)
5483       (memq article gnus-newsgroup-expirable))
5484      ((eq type 'reply)
5485       (memq article gnus-newsgroup-replied))
5486      ((eq type 'killed)
5487       (memq article gnus-newsgroup-killed))
5488      ((eq type 'bookmark)
5489       (assq article gnus-newsgroup-bookmarks))
5490      ((eq type 'score)
5491       (assq article gnus-newsgroup-scored))
5492      ((eq type 'save)
5493       (memq article gnus-newsgroup-saved))
5494      ((eq type 'cache)
5495       (memq article gnus-newsgroup-cached))
5496      ((eq type 'forward)
5497       (memq article gnus-newsgroup-forwarded))
5498      ((eq type 'seen)
5499       (not (memq article gnus-newsgroup-unseen)))
5500      ((eq type 'recent)
5501       (memq article gnus-newsgroup-recent))
5502      (t t))))
5503
5504 (defun gnus-articles-to-read (group &optional read-all)
5505   "Find out what articles the user wants to read."
5506   (let* ((articles
5507           ;; Select all articles if `read-all' is non-nil, or if there
5508           ;; are no unread articles.
5509           (if (or read-all
5510                   (and (zerop (length gnus-newsgroup-marked))
5511                        (zerop (length gnus-newsgroup-unreads)))
5512                   ;; Fetch all if the predicate is non-nil.
5513                   gnus-newsgroup-display)
5514               ;; We want to select the headers for all the articles in
5515               ;; the group, so we select either all the active
5516               ;; articles in the group, or (if that's nil), the
5517               ;; articles in the cache.
5518               (or
5519                (gnus-uncompress-range (gnus-active group))
5520                (gnus-cache-articles-in-group group))
5521             ;; Select only the "normal" subset of articles.
5522             (gnus-sorted-nunion
5523              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5524              gnus-newsgroup-unreads)))
5525          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5526          (scored (length scored-list))
5527          (number (length articles))
5528          (marked (+ (length gnus-newsgroup-marked)
5529                     (length gnus-newsgroup-dormant)))
5530          (select
5531           (cond
5532            ((numberp read-all)
5533             read-all)
5534            ((numberp gnus-newsgroup-display)
5535             gnus-newsgroup-display)
5536            (t
5537             (condition-case ()
5538                 (cond
5539                  ((and (or (<= scored marked) (= scored number))
5540                        (numberp gnus-large-newsgroup)
5541                        (> number gnus-large-newsgroup))
5542                   (let* ((cursor-in-echo-area nil)
5543                          (initial (gnus-parameter-large-newsgroup-initial
5544                                    gnus-newsgroup-name))
5545                          (input
5546                           (read-string
5547                            (format
5548                             "How many articles from %s (%s %d): "
5549                             (gnus-limit-string
5550                              (gnus-group-decoded-name gnus-newsgroup-name)
5551                              35)
5552                             (if initial "max" "default")
5553                             number)
5554                            (if initial
5555                                (cons (number-to-string initial)
5556                                      0)))))
5557                     (if (string-match "^[ \t]*$" input) number input)))
5558                  ((and (> scored marked) (< scored number)
5559                        (> (- scored number) 20))
5560                   (let ((input
5561                          (read-string
5562                           (format "%s %s (%d scored, %d total): "
5563                                   "How many articles from"
5564                                   (gnus-group-decoded-name group)
5565                                   scored number))))
5566                     (if (string-match "^[ \t]*$" input)
5567                         number input)))
5568                  (t number))
5569               (quit
5570                (message "Quit getting the articles to read")
5571                nil))))))
5572     (setq select (if (stringp select) (string-to-number select) select))
5573     (if (or (null select) (zerop select))
5574         select
5575       (if (and (not (zerop scored)) (<= (abs select) scored))
5576           (progn
5577             (setq articles (sort scored-list '<))
5578             (setq number (length articles)))
5579         (setq articles (copy-sequence articles)))
5580
5581       (when (< (abs select) number)
5582         (if (< select 0)
5583             ;; Select the N oldest articles.
5584             (setcdr (nthcdr (1- (abs select)) articles) nil)
5585           ;; Select the N most recent articles.
5586           (setq articles (nthcdr (- number select) articles))))
5587       (setq gnus-newsgroup-unselected
5588             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5589       (when gnus-alter-articles-to-read-function
5590         (setq articles
5591               (sort
5592                (funcall gnus-alter-articles-to-read-function
5593                         gnus-newsgroup-name articles)
5594                '<)))
5595       articles)))
5596
5597 (defun gnus-killed-articles (killed articles)
5598   (let (out)
5599     (while articles
5600       (when (inline (gnus-member-of-range (car articles) killed))
5601         (push (car articles) out))
5602       (setq articles (cdr articles)))
5603     out))
5604
5605 (defun gnus-uncompress-marks (marks)
5606   "Uncompress the mark ranges in MARKS."
5607   (let ((uncompressed '(score bookmark))
5608         out)
5609     (while marks
5610       (if (memq (caar marks) uncompressed)
5611           (push (car marks) out)
5612         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5613       (setq marks (cdr marks)))
5614     out))
5615
5616 (defun gnus-article-mark-to-type (mark)
5617   "Return the type of MARK."
5618   (or (cadr (assq mark gnus-article-special-mark-lists))
5619       'list))
5620
5621 (defun gnus-article-unpropagatable-p (mark)
5622   "Return whether MARK should be propagated to back end."
5623   (memq mark gnus-article-unpropagated-mark-lists))
5624
5625 (defun gnus-adjust-marked-articles (info)
5626   "Set all article lists and remove all marks that are no longer valid."
5627   (let* ((marked-lists (gnus-info-marks info))
5628          (active (gnus-active (gnus-info-group info)))
5629          (min (car active))
5630          (max (cdr active))
5631          (types gnus-article-mark-lists)
5632          marks var articles article mark mark-type
5633          bgn end)
5634
5635     (dolist (marks marked-lists)
5636       (setq mark (car marks)
5637             mark-type (gnus-article-mark-to-type mark)
5638             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5639
5640       ;; We set the variable according to the type of the marks list,
5641       ;; and then adjust the marks to a subset of the active articles.
5642       (cond
5643        ;; Adjust "simple" lists - compressed yet unsorted
5644        ((eq mark-type 'list)
5645         ;; Simultaneously uncompress and clip to active range
5646         ;; See gnus-uncompress-range for a description of possible marks
5647         (let (l lh)
5648           (if (not (cadr marks))
5649               (set var nil)
5650             (setq articles (if (numberp (cddr marks))
5651                                (list (cdr marks))
5652                              (cdr marks))
5653                   lh (cons nil nil)
5654                   l lh)
5655
5656             (while (setq article (pop articles))
5657               (cond ((consp article)
5658                      (setq bgn (max (car article) min)
5659                            end (min (cdr article) max))
5660                      (while (<= bgn end)
5661                        (setq l (setcdr l (cons bgn nil))
5662                              bgn (1+ bgn))))
5663                     ((and (<= min article)
5664                           (>= max article))
5665                      (setq l (setcdr l (cons article nil))))))
5666             (set var (cdr lh)))))
5667        ;; Adjust assocs.
5668        ((eq mark-type 'tuple)
5669         (set var (setq articles (cdr marks)))
5670         (when (not (listp (cdr (symbol-value var))))
5671           (set var (list (symbol-value var))))
5672         (when (not (listp (cdr articles)))
5673           (setq articles (list articles)))
5674         (while articles
5675           (when (or (not (consp (setq article (pop articles))))
5676                     (< (car article) min)
5677                     (> (car article) max))
5678             (set var (delq article (symbol-value var))))))
5679        ;; Adjust ranges (sloppily).
5680        ((eq mark-type 'range)
5681         (cond
5682          ((eq mark 'seen)
5683           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5684           ;; It should be (seen (NUM1 . NUM2)).
5685           (when (numberp (cddr marks))
5686             (setcdr marks (list (cdr marks))))
5687           (setq articles (cdr marks))
5688           (while (and articles
5689                       (or (and (consp (car articles))
5690                                (> min (cdar articles)))
5691                           (and (numberp (car articles))
5692                                (> min (car articles)))))
5693             (pop articles))
5694           (set var articles))))))))
5695
5696 (defun gnus-update-missing-marks (missing)
5697   "Go through the list of MISSING articles and remove them from the mark lists."
5698   (when missing
5699     (let (var m)
5700       ;; Go through all types.
5701       (dolist (elem gnus-article-mark-lists)
5702         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5703           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5704           (when (symbol-value var)
5705             ;; This list has articles.  So we delete all missing
5706             ;; articles from it.
5707             (setq m missing)
5708             (while m
5709               (set var (delq (pop m) (symbol-value var))))))))))
5710
5711 (defun gnus-update-marks ()
5712   "Enter the various lists of marked articles into the newsgroup info list."
5713   (let ((types gnus-article-mark-lists)
5714         (info (gnus-get-info gnus-newsgroup-name))
5715         type list newmarked symbol delta-marks)
5716     (when info
5717       ;; Add all marks lists to the list of marks lists.
5718       (while (setq type (pop types))
5719         (setq list (symbol-value
5720                     (setq symbol
5721                           (intern (format "gnus-newsgroup-%s" (car type))))))
5722
5723         (when list
5724           ;; Get rid of the entries of the articles that have the
5725           ;; default score.
5726           (when (and (eq (cdr type) 'score)
5727                      gnus-save-score
5728                      list)
5729             (let* ((arts list)
5730                    (prev (cons nil list))
5731                    (all prev))
5732               (while arts
5733                 (if (or (not (consp (car arts)))
5734                         (= (cdar arts) gnus-summary-default-score))
5735                     (setcdr prev (cdr arts))
5736                   (setq prev arts))
5737                 (setq arts (cdr arts)))
5738               (setq list (cdr all)))))
5739
5740         (when (eq (cdr type) 'seen)
5741           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5742
5743         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5744           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5745
5746         (when (and (gnus-check-backend-function
5747                     'request-set-mark gnus-newsgroup-name)
5748                    (not (gnus-article-unpropagatable-p (cdr type))))
5749           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5750                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5751                  (add (gnus-remove-from-range
5752                        (gnus-copy-sequence list) old)))
5753             (when add
5754               (push (list add 'add (list (cdr type))) delta-marks))
5755             (when del
5756               (push (list del 'del (list (cdr type))) delta-marks))))
5757
5758         (when list
5759           (push (cons (cdr type) list) newmarked)))
5760
5761       (when delta-marks
5762         (unless (gnus-check-group gnus-newsgroup-name)
5763           (error "Can't open server for %s" gnus-newsgroup-name))
5764         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5765
5766       ;; Enter these new marks into the info of the group.
5767       (if (nthcdr 3 info)
5768           (setcar (nthcdr 3 info) newmarked)
5769         ;; Add the marks lists to the end of the info.
5770         (when newmarked
5771           (setcdr (nthcdr 2 info) (list newmarked))))
5772
5773       ;; Cut off the end of the info if there's nothing else there.
5774       (let ((i 5))
5775         (while (and (> i 2)
5776                     (not (nth i info)))
5777           (when (nthcdr (decf i) info)
5778             (setcdr (nthcdr i info) nil)))))))
5779
5780 (defun gnus-set-mode-line (where)
5781   "Set the mode line of the article or summary buffers.
5782 If WHERE is `summary', the summary mode line format will be used."
5783   ;; Is this mode line one we keep updated?
5784   (when (and (memq where gnus-updated-mode-lines)
5785              (symbol-value
5786               (intern (format "gnus-%s-mode-line-format-spec" where))))
5787     (let (mode-string)
5788       (save-excursion
5789         ;; We evaluate this in the summary buffer since these
5790         ;; variables are buffer-local to that buffer.
5791         (set-buffer gnus-summary-buffer)
5792        ;; We bind all these variables that are used in the `eval' form
5793         ;; below.
5794         (let* ((mformat (symbol-value
5795                          (intern
5796                           (format "gnus-%s-mode-line-format-spec" where))))
5797                (gnus-tmp-group-name (gnus-group-decoded-name
5798                                      gnus-newsgroup-name))
5799                (gnus-tmp-article-number (or gnus-current-article 0))
5800                (gnus-tmp-unread gnus-newsgroup-unreads)
5801                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5802                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5803                (gnus-tmp-unread-and-unselected
5804                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5805                             (zerop gnus-tmp-unselected))
5806                        "")
5807                       ((zerop gnus-tmp-unselected)
5808                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5809                       (t (format "{%d(+%d) more}"
5810                                  gnus-tmp-unread-and-unticked
5811                                  gnus-tmp-unselected))))
5812                (gnus-tmp-subject
5813                 (if (and gnus-current-headers
5814                          (vectorp gnus-current-headers))
5815                     (gnus-mode-string-quote
5816                      (mail-header-subject gnus-current-headers))
5817                   ""))
5818                bufname-length max-len
5819                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5820           (setq mode-string (eval mformat))
5821           (setq bufname-length (if (string-match "%b" mode-string)
5822                                    (- (length
5823                                        (buffer-name
5824                                         (if (eq where 'summary)
5825                                             nil
5826                                           (get-buffer gnus-article-buffer))))
5827                                       2)
5828                                  0))
5829           (setq max-len (max 4 (if gnus-mode-non-string-length
5830                                    (- (window-width)
5831                                       gnus-mode-non-string-length
5832                                       bufname-length)
5833                                  (length mode-string))))
5834           ;; We might have to chop a bit of the string off...
5835           (when (> (length mode-string) max-len)
5836             (setq mode-string
5837                   (concat (truncate-string-to-width mode-string (- max-len 3))
5838                           "...")))
5839           ;; Pad the mode string a bit.
5840           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5841       ;; Update the mode line.
5842       (setq mode-line-buffer-identification
5843             (gnus-mode-line-buffer-identification (list mode-string)))
5844       (set-buffer-modified-p t))))
5845
5846 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5847   "Go through the HEADERS list and add all Xrefs to a hash table.
5848 The resulting hash table is returned, or nil if no Xrefs were found."
5849   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5850          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5851          (xref-hashtb (gnus-make-hashtable))
5852          start group entry number xrefs header)
5853     (while headers
5854       (setq header (pop headers))
5855       (when (and (setq xrefs (mail-header-xref header))
5856                  (not (memq (setq number (mail-header-number header))
5857                             unreads)))
5858         (setq start 0)
5859         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5860           (setq start (match-end 0))
5861           (setq group (if prefix
5862                           (concat prefix (substring xrefs (match-beginning 1)
5863                                                     (match-end 1)))
5864                         (substring xrefs (match-beginning 1) (match-end 1))))
5865           (setq number
5866                 (string-to-number (substring xrefs (match-beginning 2)
5867                                           (match-end 2))))
5868           (if (setq entry (gnus-gethash group xref-hashtb))
5869               (setcdr entry (cons number (cdr entry)))
5870             (gnus-sethash group (cons number nil) xref-hashtb)))))
5871     (and start xref-hashtb)))
5872
5873 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5874   "Look through all the headers and mark the Xrefs as read."
5875   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5876         name info xref-hashtb idlist method nth4)
5877     (save-excursion
5878       (set-buffer gnus-group-buffer)
5879       (when (setq xref-hashtb
5880                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5881         (mapatoms
5882          (lambda (group)
5883            (unless (string= from-newsgroup (setq name (symbol-name group)))
5884              (setq idlist (symbol-value group))
5885              ;; Dead groups are not updated.
5886              (and (prog1
5887                       (setq info (gnus-get-info name))
5888                     (when (stringp (setq nth4 (gnus-info-method info)))
5889                       (setq nth4 (gnus-server-to-method nth4))))
5890                   ;; Only do the xrefs if the group has the same
5891                   ;; select method as the group we have just read.
5892                   (or (gnus-methods-equal-p
5893                        nth4 (gnus-find-method-for-group from-newsgroup))
5894                       virtual
5895                       (equal nth4 (setq method (gnus-find-method-for-group
5896                                                 from-newsgroup)))
5897                       (and (equal (car nth4) (car method))
5898                            (equal (nth 1 nth4) (nth 1 method))))
5899                   gnus-use-cross-reference
5900                   (or (not (eq gnus-use-cross-reference t))
5901                       virtual
5902                       ;; Only do cross-references on subscribed
5903                       ;; groups, if that is what is wanted.
5904                       (<= (gnus-info-level info) gnus-level-subscribed))
5905                   (gnus-group-make-articles-read name idlist))))
5906          xref-hashtb)))))
5907
5908 (defun gnus-compute-read-articles (group articles)
5909   (let* ((entry (gnus-group-entry group))
5910          (info (nth 2 entry))
5911          (active (gnus-active group))
5912          ninfo)
5913     (when entry
5914       ;; First peel off all invalid article numbers.
5915       (when active
5916         (let ((ids articles)
5917               id first)
5918           (while (setq id (pop ids))
5919             (when (and first (> id (cdr active)))
5920               ;; We'll end up in this situation in one particular
5921               ;; obscure situation.  If you re-scan a group and get
5922               ;; a new article that is cross-posted to a different
5923               ;; group that has not been re-scanned, you might get
5924               ;; crossposted article that has a higher number than
5925               ;; Gnus believes possible.  So we re-activate this
5926               ;; group as well.  This might mean doing the
5927               ;; crossposting thingy will *increase* the number
5928               ;; of articles in some groups.  Tsk, tsk.
5929               (setq active (or (gnus-activate-group group) active)))
5930             (when (or (> id (cdr active))
5931                       (< id (car active)))
5932               (setq articles (delq id articles))))))
5933       ;; If the read list is nil, we init it.
5934       (if (and active
5935                (null (gnus-info-read info))
5936                (> (car active) 1))
5937           (setq ninfo (cons 1 (1- (car active))))
5938         (setq ninfo (gnus-info-read info)))
5939       ;; Then we add the read articles to the range.
5940       (gnus-add-to-range
5941        ninfo (setq articles (sort articles '<))))))
5942
5943 (defun gnus-group-make-articles-read (group articles)
5944   "Update the info of GROUP to say that ARTICLES are read."
5945   (let* ((num 0)
5946          (entry (gnus-group-entry group))
5947          (info (nth 2 entry))
5948          (active (gnus-active group))
5949          range)
5950     (when entry
5951       (setq range (gnus-compute-read-articles group articles))
5952       (with-current-buffer gnus-group-buffer
5953         (gnus-undo-register
5954           `(progn
5955              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5956              (gnus-info-set-read ',info ',(gnus-info-read info))
5957              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5958              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5959              (gnus-group-update-group ,group t))))
5960       ;; Add the read articles to the range.
5961       (gnus-info-set-read info range)
5962       (gnus-request-set-mark group (list (list range 'add '(read))))
5963       ;; Then we have to re-compute how many unread
5964       ;; articles there are in this group.
5965       (when active
5966         (cond
5967          ((not range)
5968           (setq num (- (1+ (cdr active)) (car active))))
5969          ((not (listp (cdr range)))
5970           (setq num (- (cdr active) (- (1+ (cdr range))
5971                                        (car range)))))
5972          (t
5973           (while range
5974             (if (numberp (car range))
5975                 (setq num (1+ num))
5976               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5977             (setq range (cdr range)))
5978           (setq num (- (cdr active) num))))
5979         ;; Update the number of unread articles.
5980         (setcar entry num)
5981         ;; Update the group buffer.
5982         (unless (gnus-ephemeral-group-p group)
5983           (gnus-group-update-group group t))))))
5984
5985 (defvar gnus-newsgroup-none-id 0)
5986
5987 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5988   (let ((cur nntp-server-buffer)
5989         (dependencies
5990          (or dependencies
5991              (with-current-buffer gnus-summary-buffer
5992                gnus-newsgroup-dependencies)))
5993         headers id end ref number
5994         (mail-parse-charset gnus-newsgroup-charset)
5995         (mail-parse-ignored-charsets
5996          (save-excursion (condition-case nil
5997                              (set-buffer gnus-summary-buffer)
5998                            (error))
5999                          gnus-newsgroup-ignored-charsets)))
6000     (save-excursion
6001       (set-buffer nntp-server-buffer)
6002       ;; Translate all TAB characters into SPACE characters.
6003       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6004       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6005       (ietf-drums-unfold-fws)
6006       (gnus-run-hooks 'gnus-parse-headers-hook)
6007       (let ((case-fold-search t)
6008             in-reply-to header p lines chars)
6009         (goto-char (point-min))
6010         ;; Search to the beginning of the next header.  Error messages
6011         ;; do not begin with 2 or 3.
6012         (while (re-search-forward "^[23][0-9]+ " nil t)
6013           (setq id nil
6014                 ref nil)
6015           ;; This implementation of this function, with nine
6016           ;; search-forwards instead of the one re-search-forward and
6017           ;; a case (which basically was the old function) is actually
6018           ;; about twice as fast, even though it looks messier.  You
6019           ;; can't have everything, I guess.  Speed and elegance
6020           ;; doesn't always go hand in hand.
6021           (setq
6022            header
6023            (vector
6024             ;; Number.
6025             (prog1
6026                 (setq number (read cur))
6027               (end-of-line)
6028               (setq p (point))
6029               (narrow-to-region (point)
6030                                 (or (and (search-forward "\n.\n" nil t)
6031                                          (- (point) 2))
6032                                     (point))))
6033             ;; Subject.
6034             (progn
6035               (goto-char p)
6036               (if (search-forward "\nsubject:" nil t)
6037                   (funcall gnus-decode-encoded-word-function
6038                            (nnheader-header-value))
6039                 "(none)"))
6040             ;; From.
6041             (progn
6042               (goto-char p)
6043               (if (search-forward "\nfrom:" nil t)
6044                   (funcall gnus-decode-encoded-word-function
6045                            (nnheader-header-value))
6046                 "(nobody)"))
6047             ;; Date.
6048             (progn
6049               (goto-char p)
6050               (if (search-forward "\ndate:" nil t)
6051                   (nnheader-header-value) ""))
6052             ;; Message-ID.
6053             (progn
6054               (goto-char p)
6055               (setq id (if (re-search-forward
6056                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6057                            ;; We do it this way to make sure the Message-ID
6058                            ;; is (somewhat) syntactically valid.
6059                            (buffer-substring (match-beginning 1)
6060                                              (match-end 1))
6061                          ;; If there was no message-id, we just fake one
6062                          ;; to make subsequent routines simpler.
6063                          (nnheader-generate-fake-message-id number))))
6064             ;; References.
6065             (progn
6066               (goto-char p)
6067               (if (search-forward "\nreferences:" nil t)
6068                   (progn
6069                     (setq end (point))
6070                     (prog1
6071                         (nnheader-header-value)
6072                       (setq ref
6073                             (buffer-substring
6074                              (progn
6075                                (end-of-line)
6076                                (search-backward ">" end t)
6077                                (1+ (point)))
6078                              (progn
6079                                (search-backward "<" end t)
6080                                (point))))))
6081                 ;; Get the references from the in-reply-to header if there
6082                 ;; were no references and the in-reply-to header looks
6083                 ;; promising.
6084                 (if (and (search-forward "\nin-reply-to:" nil t)
6085                          (setq in-reply-to (nnheader-header-value))
6086                          (string-match "<[^>]+>" in-reply-to))
6087                     (let (ref2)
6088                       (setq ref (substring in-reply-to (match-beginning 0)
6089                                            (match-end 0)))
6090                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6091                         (setq ref2 (substring in-reply-to (match-beginning 0)
6092                                               (match-end 0)))
6093                         (when (> (length ref2) (length ref))
6094                           (setq ref ref2)))
6095                       ref)
6096                   (setq ref nil))))
6097             ;; Chars.
6098             (progn
6099               (goto-char p)
6100               (if (search-forward "\nchars: " nil t)
6101                   (if (numberp (setq chars (ignore-errors (read cur))))
6102                       chars -1)
6103                 -1))
6104             ;; Lines.
6105             (progn
6106               (goto-char p)
6107               (if (search-forward "\nlines: " nil t)
6108                   (if (numberp (setq lines (ignore-errors (read cur))))
6109                       lines -1)
6110                 -1))
6111             ;; Xref.
6112             (progn
6113               (goto-char p)
6114               (and (search-forward "\nxref:" nil t)
6115                    (nnheader-header-value)))
6116             ;; Extra.
6117             (when gnus-extra-headers
6118               (let ((extra gnus-extra-headers)
6119                     out)
6120                 (while extra
6121                   (goto-char p)
6122                   (when (search-forward
6123                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6124                     (push (cons (car extra) (nnheader-header-value))
6125                           out))
6126                   (pop extra))
6127                 out))))
6128           (when (equal id ref)
6129             (setq ref nil))
6130
6131           (when gnus-alter-header-function
6132             (funcall gnus-alter-header-function header)
6133             (setq id (mail-header-id header)
6134                   ref (gnus-parent-id (mail-header-references header))))
6135
6136           (when (setq header
6137                       (gnus-dependencies-add-header
6138                        header dependencies force-new))
6139             (push header headers))
6140           (goto-char (point-max))
6141           (widen))
6142         (nreverse headers)))))
6143
6144 ;; Goes through the xover lines and returns a list of vectors
6145 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6146                                                   force-new dependencies
6147                                                   group also-fetch-heads)
6148   "Parse the news overview data in the server buffer.
6149 Return a list of headers that match SEQUENCE (see
6150 `nntp-retrieve-headers')."
6151   ;; Get the Xref when the users reads the articles since most/some
6152   ;; NNTP servers do not include Xrefs when using XOVER.
6153   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6154   (let ((mail-parse-charset gnus-newsgroup-charset)
6155         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6156         (cur nntp-server-buffer)
6157         (dependencies (or dependencies gnus-newsgroup-dependencies))
6158         (allp (cond
6159                ((eq gnus-read-all-available-headers t)
6160                 t)
6161                ((stringp gnus-read-all-available-headers)
6162                 (string-match gnus-read-all-available-headers group))
6163                (t
6164                 nil)))
6165         number headers header)
6166     (save-excursion
6167       (set-buffer nntp-server-buffer)
6168       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6169       ;; Allow the user to mangle the headers before parsing them.
6170       (gnus-run-hooks 'gnus-parse-headers-hook)
6171       (goto-char (point-min))
6172       (gnus-parse-without-error
6173         (while (and (or sequence allp)
6174                     (not (eobp)))
6175           (setq number (read cur))
6176           (when (not allp)
6177             (while (and sequence
6178                         (< (car sequence) number))
6179               (setq sequence (cdr sequence))))
6180           (when (and (or allp
6181                          (and sequence
6182                               (eq number (car sequence))))
6183                      (progn
6184                        (setq sequence (cdr sequence))
6185                        (setq header (inline
6186                                       (gnus-nov-parse-line
6187                                        number dependencies force-new)))))
6188             (push header headers))
6189           (forward-line 1)))
6190       ;; A common bug in inn is that if you have posted an article and
6191       ;; then retrieves the active file, it will answer correctly --
6192       ;; the new article is included.  However, a NOV entry for the
6193       ;; article may not have been generated yet, so this may fail.
6194       ;; We work around this problem by retrieving the last few
6195       ;; headers using HEAD.
6196       (if (or (not also-fetch-heads)
6197               (not sequence))
6198           ;; We (probably) got all the headers.
6199           (nreverse headers)
6200         (let ((gnus-nov-is-evil t))
6201           (nconc
6202            (nreverse headers)
6203            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6204              (gnus-get-newsgroup-headers))))))))
6205
6206 (defun gnus-article-get-xrefs ()
6207   "Fill in the Xref value in `gnus-current-headers', if necessary.
6208 This is meant to be called in `gnus-article-internal-prepare-hook'."
6209   (let ((headers (with-current-buffer gnus-summary-buffer
6210                    gnus-current-headers)))
6211     (or (not gnus-use-cross-reference)
6212         (not headers)
6213         (and (mail-header-xref headers)
6214              (not (string= (mail-header-xref headers) "")))
6215         (let ((case-fold-search t)
6216               xref)
6217           (save-restriction
6218             (nnheader-narrow-to-headers)
6219             (goto-char (point-min))
6220             (when (or (and (not (eobp))
6221                            (eq (downcase (char-after)) ?x)
6222                            (looking-at "Xref:"))
6223                       (search-forward "\nXref:" nil t))
6224               (goto-char (1+ (match-end 0)))
6225               (setq xref (buffer-substring (point) (point-at-eol)))
6226               (mail-header-set-xref headers xref)))))))
6227
6228 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6229   "Find article ID and insert the summary line for that article.
6230 OLD-HEADER can either be a header or a line number to insert
6231 the subject line on."
6232   (let* ((line (and (numberp old-header) old-header))
6233          (old-header (and (vectorp old-header) old-header))
6234          (header (cond ((and old-header use-old-header)
6235                         old-header)
6236                        ((and (numberp id)
6237                              (gnus-number-to-header id))
6238                         (gnus-number-to-header id))
6239                        (t
6240                         (gnus-read-header id))))
6241          (number (and (numberp id) id))
6242          d)
6243     (when header
6244       ;; Rebuild the thread that this article is part of and go to the
6245       ;; article we have fetched.
6246       (when (and (not gnus-show-threads)
6247                  old-header)
6248         (when (and number
6249                    (setq d (gnus-data-find (mail-header-number old-header))))
6250           (goto-char (gnus-data-pos d))
6251           (gnus-data-remove
6252            number
6253            (- (point-at-bol)
6254               (prog1
6255                   (1+ (point-at-eol))
6256                 (gnus-delete-line))))))
6257       ;; Remove list identifiers from subject.
6258       (when gnus-list-identifiers
6259         (let ((gnus-newsgroup-headers (list header)))
6260           (gnus-summary-remove-list-identifiers)))
6261       (when old-header
6262         (mail-header-set-number header (mail-header-number old-header)))
6263       (setq gnus-newsgroup-sparse
6264             (delq (setq number (mail-header-number header))
6265                   gnus-newsgroup-sparse))
6266       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6267       (push number gnus-newsgroup-limit)
6268       (gnus-rebuild-thread (mail-header-id header) line)
6269       (gnus-summary-goto-subject number nil t))
6270     (when (and (numberp number)
6271                (> number 0))
6272       ;; We have to update the boundaries even if we can't fetch the
6273       ;; article if ID is a number -- so that the next `P' or `N'
6274       ;; command will fetch the previous (or next) article even
6275       ;; if the one we tried to fetch this time has been canceled.
6276       (when (> number gnus-newsgroup-end)
6277         (setq gnus-newsgroup-end number))
6278       (when (< number gnus-newsgroup-begin)
6279         (setq gnus-newsgroup-begin number))
6280       (setq gnus-newsgroup-unselected
6281             (delq number gnus-newsgroup-unselected)))
6282     ;; Report back a success?
6283     (and header (mail-header-number header))))
6284
6285 ;;; Process/prefix in the summary buffer
6286
6287 (defun gnus-summary-work-articles (n)
6288   "Return a list of articles to be worked upon.
6289 The prefix argument, the list of process marked articles, and the
6290 current article will be taken into consideration."
6291   (save-excursion
6292     (set-buffer gnus-summary-buffer)
6293     (cond
6294      (n
6295       ;; A numerical prefix has been given.
6296       (setq n (prefix-numeric-value n))
6297       (let ((backward (< n 0))
6298             (n (abs (prefix-numeric-value n)))
6299             articles article)
6300         (save-excursion
6301           (while
6302               (and (> n 0)
6303                    (push (setq article (gnus-summary-article-number))
6304                          articles)
6305                    (if backward
6306                        (gnus-summary-find-prev nil article)
6307                      (gnus-summary-find-next nil article)))
6308             (decf n)))
6309         (nreverse articles)))
6310      ((and (gnus-region-active-p) (mark))
6311       (message "region active")
6312       ;; Work on the region between point and mark.
6313       (let ((max (max (point) (mark)))
6314             articles article)
6315         (save-excursion
6316           (goto-char (min (point) (mark)))
6317           (while
6318               (and
6319                (push (setq article (gnus-summary-article-number)) articles)
6320                (gnus-summary-find-next nil article)
6321                (< (point) max)))
6322           (nreverse articles))))
6323      (gnus-newsgroup-processable
6324       ;; There are process-marked articles present.
6325       ;; Save current state.
6326       (gnus-summary-save-process-mark)
6327       ;; Return the list.
6328       (reverse gnus-newsgroup-processable))
6329      (t
6330       ;; Just return the current article.
6331       (list (gnus-summary-article-number))))))
6332
6333 (defmacro gnus-summary-iterate (arg &rest forms)
6334   "Iterate over the process/prefixed articles and do FORMS.
6335 ARG is the interactive prefix given to the command.  FORMS will be
6336 executed with point over the summary line of the articles."
6337   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6338     `(let ((,articles (gnus-summary-work-articles ,arg)))
6339        (while ,articles
6340          (gnus-summary-goto-subject (car ,articles))
6341          ,@forms
6342          (pop ,articles)))))
6343
6344 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6345 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6346
6347 (defun gnus-summary-save-process-mark ()
6348   "Push the current set of process marked articles on the stack."
6349   (interactive)
6350   (push (copy-sequence gnus-newsgroup-processable)
6351         gnus-newsgroup-process-stack))
6352
6353 (defun gnus-summary-kill-process-mark ()
6354   "Push the current set of process marked articles on the stack and unmark."
6355   (interactive)
6356   (gnus-summary-save-process-mark)
6357   (gnus-summary-unmark-all-processable))
6358
6359 (defun gnus-summary-yank-process-mark ()
6360   "Pop the last process mark state off the stack and restore it."
6361   (interactive)
6362   (unless gnus-newsgroup-process-stack
6363     (error "Empty mark stack"))
6364   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6365
6366 (defun gnus-summary-process-mark-set (set)
6367   "Make SET into the current process marked articles."
6368   (gnus-summary-unmark-all-processable)
6369   (mapc 'gnus-summary-set-process-mark set))
6370
6371 ;;; Searching and stuff
6372
6373 (defun gnus-summary-search-group (&optional backward use-level)
6374   "Search for next unread newsgroup.
6375 If optional argument BACKWARD is non-nil, search backward instead."
6376   (save-excursion
6377     (set-buffer gnus-group-buffer)
6378     (when (gnus-group-search-forward
6379            backward nil (if use-level (gnus-group-group-level) nil))
6380       (gnus-group-group-name))))
6381
6382 (defun gnus-summary-best-group (&optional exclude-group)
6383   "Find the name of the best unread group.
6384 If EXCLUDE-GROUP, do not go to this group."
6385   (with-current-buffer gnus-group-buffer
6386     (save-excursion
6387       (gnus-group-best-unread-group exclude-group))))
6388
6389 (defun gnus-summary-find-next (&optional unread article backward)
6390   (if backward
6391       (gnus-summary-find-prev unread article)
6392     (let* ((dummy (gnus-summary-article-intangible-p))
6393            (article (or article (gnus-summary-article-number)))
6394            (data (gnus-data-find-list article))
6395            result)
6396       (when (and (not dummy)
6397                  (or (not gnus-summary-check-current)
6398                      (not unread)
6399                      (not (gnus-data-unread-p (car data)))))
6400         (setq data (cdr data)))
6401       (when (setq result
6402                   (if unread
6403                       (progn
6404                         (while data
6405                           (unless (memq (gnus-data-number (car data))
6406                                         (cond
6407                                          ((eq gnus-auto-goto-ignores
6408                                               'always-undownloaded)
6409                                           gnus-newsgroup-undownloaded)
6410                                          (gnus-plugged
6411                                           nil)
6412                                          ((eq gnus-auto-goto-ignores
6413                                               'unfetched)
6414                                           gnus-newsgroup-unfetched)
6415                                          ((eq gnus-auto-goto-ignores
6416                                               'undownloaded)
6417                                           gnus-newsgroup-undownloaded)))
6418                             (when (gnus-data-unread-p (car data))
6419                               (setq result (car data)
6420                                     data nil)))
6421                           (setq data (cdr data)))
6422                         result)
6423                     (car data)))
6424         (goto-char (gnus-data-pos result))
6425         (gnus-data-number result)))))
6426
6427 (defun gnus-summary-find-prev (&optional unread article)
6428   (let* ((eobp (eobp))
6429          (article (or article (gnus-summary-article-number)))
6430          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6431          result)
6432     (when (and (not eobp)
6433                (or (not gnus-summary-check-current)
6434                    (not unread)
6435                    (not (gnus-data-unread-p (car data)))))
6436       (setq data (cdr data)))
6437     (when (setq result
6438                 (if unread
6439                     (progn
6440                       (while data
6441                         (unless (memq (gnus-data-number (car data))
6442                                       (cond
6443                                        ((eq gnus-auto-goto-ignores
6444                                             'always-undownloaded)
6445                                         gnus-newsgroup-undownloaded)
6446                                        (gnus-plugged
6447                                         nil)
6448                                        ((eq gnus-auto-goto-ignores
6449                                             'unfetched)
6450                                         gnus-newsgroup-unfetched)
6451                                        ((eq gnus-auto-goto-ignores
6452                                             'undownloaded)
6453                                         gnus-newsgroup-undownloaded)))
6454                           (when (gnus-data-unread-p (car data))
6455                             (setq result (car data)
6456                                   data nil)))
6457                         (setq data (cdr data)))
6458                       result)
6459                   (car data)))
6460       (goto-char (gnus-data-pos result))
6461       (gnus-data-number result))))
6462
6463 (defun gnus-summary-find-subject (subject &optional unread backward article)
6464   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6465          (article (or article (gnus-summary-article-number)))
6466          (articles (gnus-data-list backward))
6467          (arts (gnus-data-find-list article articles))
6468          result)
6469     (when (or (not gnus-summary-check-current)
6470               (not unread)
6471               (not (gnus-data-unread-p (car arts))))
6472       (setq arts (cdr arts)))
6473     (while arts
6474       (and (or (not unread)
6475                (gnus-data-unread-p (car arts)))
6476            (vectorp (gnus-data-header (car arts)))
6477            (gnus-subject-equal
6478             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6479            (setq result (car arts)
6480                  arts nil))
6481       (setq arts (cdr arts)))
6482     (and result
6483          (goto-char (gnus-data-pos result))
6484          (gnus-data-number result))))
6485
6486 (defun gnus-summary-search-forward (&optional unread subject backward)
6487   "Search forward for an article.
6488 If UNREAD, look for unread articles.  If SUBJECT, look for
6489 articles with that subject.  If BACKWARD, search backward instead."
6490   (cond (subject (gnus-summary-find-subject subject unread backward))
6491         (backward (gnus-summary-find-prev unread))
6492         (t (gnus-summary-find-next unread))))
6493
6494 (defun gnus-recenter (&optional n)
6495   "Center point in window and redisplay frame.
6496 Also do horizontal recentering."
6497   (interactive "P")
6498   (when (and gnus-auto-center-summary
6499              (not (eq gnus-auto-center-summary 'vertical)))
6500     (gnus-horizontal-recenter))
6501   (recenter n))
6502
6503 (defun gnus-summary-recenter ()
6504   "Center point in the summary window.
6505 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6506 displayed, no centering will be performed."
6507   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6508   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6509   (interactive)
6510   ;; The user has to want it.
6511   (when gnus-auto-center-summary
6512     (let* ((top (cond ((< (window-height) 4) 0)
6513                       ((< (window-height) 7) 1)
6514                       (t (if (numberp gnus-auto-center-summary)
6515                              gnus-auto-center-summary
6516                            (/ (1- (window-height)) 2)))))
6517            (height (1- (window-height)))
6518            (bottom (save-excursion (goto-char (point-max))
6519                                    (forward-line (- height))
6520                                    (point)))
6521            (window (get-buffer-window (current-buffer))))
6522       (when (get-buffer-window gnus-article-buffer)
6523         ;; Only do recentering when the article buffer is displayed,
6524         ;; Set the window start to either `bottom', which is the biggest
6525         ;; possible valid number, or the second line from the top,
6526         ;; whichever is the least.
6527         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6528           (if (> bottom top-pos)
6529               ;; Keep the second line from the top visible
6530               (set-window-start window top-pos t)
6531             ;; Try to keep the bottom line visible; if it's partially
6532             ;; obscured, either scroll one more line to make it fully
6533             ;; visible, or revert to using TOP-POS.
6534             (save-excursion
6535               (goto-char (point-max))
6536               (forward-line -1)
6537               (let ((last-line-start (point)))
6538                 (goto-char bottom)
6539                 (set-window-start window (point) t)
6540                 (when (not (pos-visible-in-window-p last-line-start window))
6541                   (forward-line 1)
6542                   (set-window-start window (min (point) top-pos) t)))))))
6543       ;; Do horizontal recentering while we're at it.
6544       (when (and (get-buffer-window (current-buffer) t)
6545                  (not (eq gnus-auto-center-summary 'vertical)))
6546         (let ((selected (selected-window)))
6547           (select-window (get-buffer-window (current-buffer) t))
6548           (gnus-summary-position-point)
6549           (gnus-horizontal-recenter)
6550           (select-window selected))))))
6551
6552 (defun gnus-summary-jump-to-group (newsgroup)
6553   "Move point to NEWSGROUP in group mode buffer."
6554   ;; Keep update point of group mode buffer if visible.
6555   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6556       (save-window-excursion
6557         ;; Take care of tree window mode.
6558         (when (get-buffer-window gnus-group-buffer)
6559           (pop-to-buffer gnus-group-buffer))
6560         (gnus-group-jump-to-group newsgroup))
6561     (save-excursion
6562       ;; Take care of tree window mode.
6563       (if (get-buffer-window gnus-group-buffer)
6564           (pop-to-buffer gnus-group-buffer)
6565         (set-buffer gnus-group-buffer))
6566       (gnus-group-jump-to-group newsgroup))))
6567
6568 ;; This function returns a list of article numbers based on the
6569 ;; difference between the ranges of read articles in this group and
6570 ;; the range of active articles.
6571 (defun gnus-list-of-unread-articles (group)
6572   (let* ((read (gnus-info-read (gnus-get-info group)))
6573          (active (or (gnus-active group) (gnus-activate-group group)))
6574          (last (or (cdr active)
6575                    (error "Group %s couldn't be activated " group)))
6576          first nlast unread)
6577     ;; If none are read, then all are unread.
6578     (if (not read)
6579         (setq first (car active))
6580       ;; If the range of read articles is a single range, then the
6581       ;; first unread article is the article after the last read
6582       ;; article.  Sounds logical, doesn't it?
6583       (if (and (not (listp (cdr read)))
6584                (or (< (car read) (car active))
6585                    (progn (setq read (list read))
6586                           nil)))
6587           (setq first (max (car active) (1+ (cdr read))))
6588         ;; `read' is a list of ranges.
6589         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6590                                   (caar read)))
6591                   1)
6592           (setq first (car active)))
6593         (while read
6594           (when first
6595             (while (< first nlast)
6596               (setq unread (cons first unread)
6597                     first (1+ first))))
6598           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6599           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6600           (setq read (cdr read)))))
6601     ;; And add the last unread articles.
6602     (while (<= first last)
6603       (setq unread (cons first unread)
6604             first (1+ first)))
6605     ;; Return the list of unread articles.
6606     (delq 0 (nreverse unread))))
6607
6608 (defun gnus-list-of-read-articles (group)
6609   "Return a list of unread, unticked and non-dormant articles."
6610   (let* ((info (gnus-get-info group))
6611          (marked (gnus-info-marks info))
6612          (active (gnus-active group)))
6613     (and info active
6614          (gnus-list-range-difference
6615           (gnus-list-range-difference
6616            (gnus-sorted-complement
6617             (gnus-uncompress-range active)
6618             (gnus-list-of-unread-articles group))
6619            (cdr (assq 'dormant marked)))
6620           (cdr (assq 'tick marked))))))
6621
6622 ;; This function returns a sequence of article numbers based on the
6623 ;; difference between the ranges of read articles in this group and
6624 ;; the range of active articles.
6625 (defun gnus-sequence-of-unread-articles (group)
6626   (let* ((read (gnus-info-read (gnus-get-info group)))
6627          (active (or (gnus-active group) (gnus-activate-group group)))
6628          (last (cdr active))
6629          first nlast unread)
6630     ;; If none are read, then all are unread.
6631     (if (not read)
6632         (setq first (car active))
6633       ;; If the range of read articles is a single range, then the
6634       ;; first unread article is the article after the last read
6635       ;; article.  Sounds logical, doesn't it?
6636       (if (and (not (listp (cdr read)))
6637                (or (< (car read) (car active))
6638                    (progn (setq read (list read))
6639                           nil)))
6640           (setq first (max (car active) (1+ (cdr read))))
6641         ;; `read' is a list of ranges.
6642         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6643                                   (caar read)))
6644                   1)
6645           (setq first (car active)))
6646         (while read
6647           (when first
6648             (push (cons first nlast) unread))
6649           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6650           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6651           (setq read (cdr read)))))
6652     ;; And add the last unread articles.
6653     (cond ((not (and first last))
6654            nil)
6655           ((< first last)
6656            (push (cons first last) unread))
6657           ((= first last)
6658            (push first unread)))
6659     ;; Return the sequence of unread articles.
6660     (delq 0 (nreverse unread))))
6661
6662 ;; Various summary commands
6663
6664 (defun gnus-summary-select-article-buffer ()
6665   "Reconfigure windows to show article buffer."
6666   (interactive)
6667   (if (not (gnus-buffer-live-p gnus-article-buffer))
6668       (error "There is no article buffer for this summary buffer")
6669     (gnus-configure-windows 'article)
6670     (select-window (get-buffer-window gnus-article-buffer))))
6671
6672 (defun gnus-summary-universal-argument (arg)
6673   "Perform any operation on all articles that are process/prefixed."
6674   (interactive "P")
6675   (let ((articles (gnus-summary-work-articles arg))
6676         func article)
6677     (if (eq
6678          (setq
6679           func
6680           (key-binding
6681            (read-key-sequence
6682             (substitute-command-keys
6683              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6684          'undefined)
6685         (gnus-error 1 "Undefined key")
6686       (save-excursion
6687         (while articles
6688           (gnus-summary-goto-subject (setq article (pop articles)))
6689           (let (gnus-newsgroup-processable)
6690             (command-execute func))
6691           (gnus-summary-remove-process-mark article)))))
6692   (gnus-summary-position-point))
6693
6694 (defun gnus-summary-toggle-truncation (&optional arg)
6695   "Toggle truncation of summary lines.
6696 With ARG, turn line truncation on if ARG is positive."
6697   (interactive "P")
6698   (setq truncate-lines
6699         (if (null arg) (not truncate-lines)
6700           (> (prefix-numeric-value arg) 0)))
6701   (redraw-display))
6702
6703 (defun gnus-summary-find-for-reselect ()
6704   "Return the number of an article to stay on across a reselect.
6705 The current article is considered, then following articles, then previous
6706 articles.  An article is sought which is not cancelled and isn't a temporary
6707 insertion from another group.  If there's no such then return a dummy 0."
6708   (let (found)
6709     (dolist (rev '(nil t))
6710       (unless found      ; don't demand the reverse list if we don't need it
6711         (let ((data (gnus-data-find-list
6712                      (gnus-summary-article-number) (gnus-data-list rev))))
6713           (while (and data (not found))
6714             (if (and (< 0 (gnus-data-number (car data)))
6715                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6716                 (setq found (gnus-data-number (car data))))
6717             (setq data (cdr data))))))
6718     (or found 0)))
6719
6720 (defun gnus-summary-reselect-current-group (&optional all rescan)
6721   "Exit and then reselect the current newsgroup.
6722 The prefix argument ALL means to select all articles."
6723   (interactive "P")
6724   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6725     (error "Ephemeral groups can't be reselected"))
6726   (let ((current-subject (gnus-summary-find-for-reselect))
6727         (group gnus-newsgroup-name))
6728     (setq gnus-newsgroup-begin nil)
6729     (gnus-summary-exit nil 'leave-hidden)
6730     ;; We have to adjust the point of group mode buffer because
6731     ;; point was moved to the next unread newsgroup by exiting.
6732     (gnus-summary-jump-to-group group)
6733     (when rescan
6734       (save-excursion
6735         (gnus-group-get-new-news-this-group 1)))
6736     (gnus-group-read-group all t)
6737     (gnus-summary-goto-subject current-subject nil t)))
6738
6739 (defun gnus-summary-rescan-group (&optional all)
6740   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6741   (interactive "P")
6742   (gnus-summary-reselect-current-group all t))
6743
6744 (defun gnus-summary-update-info (&optional non-destructive)
6745   (save-excursion
6746     (let ((group gnus-newsgroup-name))
6747       (when group
6748         (when gnus-newsgroup-kill-headers
6749           (setq gnus-newsgroup-killed
6750                 (gnus-compress-sequence
6751                  (gnus-sorted-union
6752                   (gnus-list-range-intersection
6753                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6754                   gnus-newsgroup-unreads)
6755                  t)))
6756         (unless (listp (cdr gnus-newsgroup-killed))
6757           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6758         (let ((headers gnus-newsgroup-headers))
6759           ;; Set the new ranges of read articles.
6760           (with-current-buffer gnus-group-buffer
6761             (gnus-undo-force-boundary))
6762           (gnus-update-read-articles
6763            group (gnus-sorted-union
6764                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6765           ;; Set the current article marks.
6766           (let ((gnus-newsgroup-scored
6767                  (if (and (not gnus-save-score)
6768                           (not non-destructive))
6769                      nil
6770                    gnus-newsgroup-scored)))
6771             (save-excursion
6772               (gnus-update-marks)))
6773           ;; Do the cross-ref thing.
6774           (when gnus-use-cross-reference
6775             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6776           ;; Do not switch windows but change the buffer to work.
6777           (set-buffer gnus-group-buffer)
6778           (unless (gnus-ephemeral-group-p group)
6779             (gnus-group-update-group group)))))))
6780
6781 (defun gnus-summary-save-newsrc (&optional force)
6782   "Save the current number of read/marked articles in the dribble buffer.
6783 The dribble buffer will then be saved.
6784 If FORCE (the prefix), also save the .newsrc file(s)."
6785   (interactive "P")
6786   (gnus-summary-update-info t)
6787   (if force
6788       (gnus-save-newsrc-file)
6789     (gnus-dribble-save)))
6790
6791 (defun gnus-summary-exit (&optional temporary leave-hidden)
6792   "Exit reading current newsgroup, and then return to group selection mode.
6793 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6794   (interactive)
6795   (gnus-set-global-variables)
6796   (when (gnus-buffer-live-p gnus-article-buffer)
6797     (save-excursion
6798       (set-buffer gnus-article-buffer)
6799       (mm-destroy-parts gnus-article-mime-handles)
6800       ;; Set it to nil for safety reason.
6801       (setq gnus-article-mime-handle-alist nil)
6802       (setq gnus-article-mime-handles nil)))
6803   (gnus-kill-save-kill-buffer)
6804   (gnus-async-halt-prefetch)
6805   (let* ((group gnus-newsgroup-name)
6806          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6807          (gnus-group-is-exiting-p t)
6808          (mode major-mode)
6809          (group-point nil)
6810          (buf (current-buffer)))
6811     (unless quit-config
6812       ;; Do adaptive scoring, and possibly save score files.
6813       (when gnus-newsgroup-adaptive
6814         (gnus-score-adaptive))
6815       (when gnus-use-scoring
6816         (gnus-score-save)))
6817     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6818     ;; If we have several article buffers, we kill them at exit.
6819     (unless gnus-single-article-buffer
6820       (gnus-kill-buffer gnus-original-article-buffer)
6821       (setq gnus-article-current nil))
6822     (when gnus-use-cache
6823       (gnus-cache-possibly-remove-articles)
6824       (gnus-cache-save-buffers))
6825     (gnus-async-prefetch-remove-group group)
6826     (when gnus-suppress-duplicates
6827       (gnus-dup-enter-articles))
6828     (when gnus-use-trees
6829       (gnus-tree-close group))
6830     (when gnus-use-cache
6831       (gnus-cache-write-active))
6832     ;; Remove entries for this group.
6833     (nnmail-purge-split-history (gnus-group-real-name group))
6834     ;; Make all changes in this group permanent.
6835     (unless quit-config
6836       (gnus-run-hooks 'gnus-exit-group-hook)
6837       (gnus-summary-update-info))
6838     (gnus-close-group group)
6839     ;; Make sure where we were, and go to next newsgroup.
6840     (set-buffer gnus-group-buffer)
6841     (unless quit-config
6842       (gnus-group-jump-to-group group))
6843     (gnus-run-hooks 'gnus-summary-exit-hook)
6844     (unless (or quit-config
6845                 ;; If this group has disappeared from the summary
6846                 ;; buffer, don't skip forwards.
6847                 (not (string= group (gnus-group-group-name))))
6848       (gnus-group-next-unread-group 1))
6849     (setq group-point (point))
6850     (if temporary
6851         nil                             ;Nothing to do.
6852       ;; If we have several article buffers, we kill them at exit.
6853       (unless gnus-single-article-buffer
6854         (gnus-kill-buffer gnus-article-buffer)
6855         (gnus-kill-buffer gnus-original-article-buffer)
6856         (setq gnus-article-current nil))
6857       (set-buffer buf)
6858       (if (not gnus-kill-summary-on-exit)
6859           (progn
6860             (gnus-deaden-summary)
6861             (setq mode nil))
6862         ;; We set all buffer-local variables to nil.  It is unclear why
6863         ;; this is needed, but if we don't, buffer-local variables are
6864         ;; not garbage-collected, it seems.  This would the lead to en
6865         ;; ever-growing Emacs.
6866         (gnus-summary-clear-local-variables)
6867         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6868           (gnus-summary-clear-local-variables))
6869         (when (get-buffer gnus-article-buffer)
6870           (bury-buffer gnus-article-buffer))
6871         ;; Return to group mode buffer.
6872         (when (eq mode 'gnus-summary-mode)
6873           (gnus-kill-buffer buf)))
6874       (setq gnus-current-select-method gnus-select-method)
6875       (set-buffer gnus-group-buffer)
6876       (if quit-config
6877           (gnus-handle-ephemeral-exit quit-config)
6878         (goto-char group-point)
6879         ;; If gnus-group-buffer is already displayed, make sure we also move
6880         ;; the cursor in the window that displays it.
6881         (let ((win (get-buffer-window (current-buffer) 0)))
6882           (if win (set-window-point win (point))))
6883         (unless leave-hidden
6884           (gnus-configure-windows 'group 'force)))
6885       ;; Clear the current group name.
6886       (unless quit-config
6887         (setq gnus-newsgroup-name nil)))))
6888
6889 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6890 (defun gnus-summary-exit-no-update (&optional no-questions)
6891   "Quit reading current newsgroup without updating read article info."
6892   (interactive)
6893   (let* ((group gnus-newsgroup-name)
6894          (gnus-group-is-exiting-p t)
6895          (gnus-group-is-exiting-without-update-p t)
6896          (quit-config (gnus-group-quit-config group)))
6897     (when (or no-questions
6898               gnus-expert-user
6899               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6900       (gnus-async-halt-prefetch)
6901       (run-hooks 'gnus-summary-prepare-exit-hook)
6902       (when (gnus-buffer-live-p gnus-article-buffer)
6903         (save-excursion
6904           (set-buffer gnus-article-buffer)
6905           (mm-destroy-parts gnus-article-mime-handles)
6906           ;; Set it to nil for safety reason.
6907           (setq gnus-article-mime-handle-alist nil)
6908           (setq gnus-article-mime-handles nil)))
6909       ;; If we have several article buffers, we kill them at exit.
6910       (unless gnus-single-article-buffer
6911         (gnus-kill-buffer gnus-article-buffer)
6912         (gnus-kill-buffer gnus-original-article-buffer)
6913         (setq gnus-article-current nil))
6914       (if (not gnus-kill-summary-on-exit)
6915           (gnus-deaden-summary)
6916         (gnus-close-group group)
6917         (gnus-summary-clear-local-variables)
6918         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6919           (gnus-summary-clear-local-variables))
6920         (gnus-kill-buffer gnus-summary-buffer))
6921       (unless gnus-single-article-buffer
6922         (setq gnus-article-current nil))
6923       (when gnus-use-trees
6924         (gnus-tree-close group))
6925       (gnus-async-prefetch-remove-group group)
6926       (when (get-buffer gnus-article-buffer)
6927         (bury-buffer gnus-article-buffer))
6928       ;; Return to the group buffer.
6929       (gnus-configure-windows 'group 'force)
6930       ;; Clear the current group name.
6931       (setq gnus-newsgroup-name nil)
6932       (unless (gnus-ephemeral-group-p group)
6933         (gnus-group-update-group group))
6934       (when (equal (gnus-group-group-name) group)
6935         (gnus-group-next-unread-group 1))
6936       (when quit-config
6937         (gnus-handle-ephemeral-exit quit-config)))))
6938
6939 (defun gnus-handle-ephemeral-exit (quit-config)
6940   "Handle movement when leaving an ephemeral group.
6941 The state which existed when entering the ephemeral is reset."
6942   (if (not (buffer-name (car quit-config)))
6943       (gnus-configure-windows 'group 'force)
6944     (set-buffer (car quit-config))
6945     (cond ((eq major-mode 'gnus-summary-mode)
6946            (gnus-set-global-variables))
6947           ((eq major-mode 'gnus-article-mode)
6948            (save-excursion
6949              ;; The `gnus-summary-buffer' variable may point
6950              ;; to the old summary buffer when using a single
6951              ;; article buffer.
6952              (unless (gnus-buffer-live-p gnus-summary-buffer)
6953                (set-buffer gnus-group-buffer))
6954              (set-buffer gnus-summary-buffer)
6955              (gnus-set-global-variables))))
6956     (if (or (eq (cdr quit-config) 'article)
6957             (eq (cdr quit-config) 'pick))
6958         (progn
6959           ;; The current article may be from the ephemeral group
6960           ;; thus it is best that we reload this article
6961           ;;
6962           ;; If we're exiting from a large digest, this can be
6963           ;; extremely slow.  So, it's better not to reload it. -- jh.
6964           ;;(gnus-summary-show-article)
6965           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6966               (gnus-configure-windows 'pick 'force)
6967             (gnus-configure-windows (cdr quit-config) 'force)))
6968       (gnus-configure-windows (cdr quit-config) 'force))
6969     (when (eq major-mode 'gnus-summary-mode)
6970       (gnus-summary-next-subject 1 nil t)
6971       (gnus-summary-recenter)
6972       (gnus-summary-position-point))))
6973
6974 ;;; Dead summaries.
6975
6976 (defvar gnus-dead-summary-mode-map nil)
6977
6978 (unless gnus-dead-summary-mode-map
6979   (setq gnus-dead-summary-mode-map (make-keymap))
6980   (suppress-keymap gnus-dead-summary-mode-map)
6981   (substitute-key-definition
6982    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6983   (dolist (key '("\C-d" "\r" "\177" [delete]))
6984     (define-key gnus-dead-summary-mode-map
6985       key 'gnus-summary-wake-up-the-dead))
6986   (dolist (key '("q" "Q"))
6987     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6988
6989 (defvar gnus-dead-summary-mode nil
6990   "Minor mode for Gnus summary buffers.")
6991
6992 (defun gnus-dead-summary-mode (&optional arg)
6993   "Minor mode for Gnus summary buffers."
6994   (interactive "P")
6995   (when (eq major-mode 'gnus-summary-mode)
6996     (make-local-variable 'gnus-dead-summary-mode)
6997     (setq gnus-dead-summary-mode
6998           (if (null arg) (not gnus-dead-summary-mode)
6999             (> (prefix-numeric-value arg) 0)))
7000     (when gnus-dead-summary-mode
7001       (add-minor-mode
7002        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7003
7004 (defun gnus-deaden-summary ()
7005   "Make the current summary buffer into a dead summary buffer."
7006   ;; Kill any previous dead summary buffer.
7007   (when (and gnus-dead-summary
7008              (buffer-name gnus-dead-summary))
7009     (with-current-buffer gnus-dead-summary
7010       (when gnus-dead-summary-mode
7011         (kill-buffer (current-buffer)))))
7012   ;; Make this the current dead summary.
7013   (setq gnus-dead-summary (current-buffer))
7014   (gnus-dead-summary-mode 1)
7015   (let ((name (buffer-name)))
7016     (when (string-match "Summary" name)
7017       (rename-buffer
7018        (concat (substring name 0 (match-beginning 0)) "Dead "
7019                (substring name (match-beginning 0)))
7020        t)
7021       (bury-buffer))))
7022
7023 (defun gnus-kill-or-deaden-summary (buffer)
7024   "Kill or deaden the summary BUFFER."
7025   (save-excursion
7026     (when (and (buffer-name buffer)
7027                (not gnus-single-article-buffer))
7028       (with-current-buffer buffer
7029         (gnus-kill-buffer gnus-article-buffer)
7030         (gnus-kill-buffer gnus-original-article-buffer)))
7031     (cond
7032      ;; Kill the buffer.
7033      (gnus-kill-summary-on-exit
7034       (when (and gnus-use-trees
7035                  (gnus-buffer-exists-p buffer))
7036         (save-excursion
7037           (set-buffer buffer)
7038           (gnus-tree-close gnus-newsgroup-name)))
7039       (gnus-kill-buffer buffer))
7040      ;; Deaden the buffer.
7041      ((gnus-buffer-exists-p buffer)
7042       (save-excursion
7043         (set-buffer buffer)
7044         (gnus-deaden-summary))))))
7045
7046 (defun gnus-summary-wake-up-the-dead (&rest args)
7047   "Wake up the dead summary buffer."
7048   (interactive)
7049   (gnus-dead-summary-mode -1)
7050   (let ((name (buffer-name)))
7051     (when (string-match "Dead " name)
7052       (rename-buffer
7053        (concat (substring name 0 (match-beginning 0))
7054                (substring name (match-end 0)))
7055        t)))
7056   (gnus-message 3 "This dead summary is now alive again"))
7057
7058 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7059 (defun gnus-summary-fetch-faq (&optional faq-dir)
7060   "Fetch the FAQ for the current group.
7061 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7062 in."
7063   (interactive
7064    (list
7065     (when current-prefix-arg
7066       (completing-read
7067        "FAQ dir: " (and (listp gnus-group-faq-directory)
7068                         (mapcar 'list
7069                                 gnus-group-faq-directory))))))
7070   (let (gnus-faq-buffer)
7071     (when (setq gnus-faq-buffer
7072                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7073       (gnus-configure-windows 'summary-faq))))
7074
7075 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7076 (defun gnus-summary-describe-group (&optional force)
7077   "Describe the current newsgroup."
7078   (interactive "P")
7079   (gnus-group-describe-group force gnus-newsgroup-name))
7080
7081 (defun gnus-summary-describe-briefly ()
7082   "Describe summary mode commands briefly."
7083   (interactive)
7084   (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")))
7085
7086 ;; Walking around group mode buffer from summary mode.
7087
7088 (defun gnus-summary-next-group (&optional no-article target-group backward)
7089   "Exit current newsgroup and then select next unread newsgroup.
7090 If prefix argument NO-ARTICLE is non-nil, no article is selected
7091 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7092 previous group instead."
7093   (interactive "P")
7094   ;; Stop pre-fetching.
7095   (gnus-async-halt-prefetch)
7096   (let ((current-group gnus-newsgroup-name)
7097         (current-buffer (current-buffer))
7098         entered)
7099     ;; First we semi-exit this group to update Xrefs and all variables.
7100     ;; We can't do a real exit, because the window conf must remain
7101     ;; the same in case the user is prompted for info, and we don't
7102     ;; want the window conf to change before that...
7103     (gnus-summary-exit t)
7104     (while (not entered)
7105       ;; Then we find what group we are supposed to enter.
7106       (set-buffer gnus-group-buffer)
7107       (gnus-group-jump-to-group current-group)
7108       (setq target-group
7109             (or target-group
7110                 (if (eq gnus-keep-same-level 'best)
7111                     (gnus-summary-best-group gnus-newsgroup-name)
7112                   (gnus-summary-search-group backward gnus-keep-same-level))))
7113       (if (not target-group)
7114           ;; There are no further groups, so we return to the group
7115           ;; buffer.
7116           (progn
7117             (gnus-message 5 "Returning to the group buffer")
7118             (setq entered t)
7119             (when (gnus-buffer-live-p current-buffer)
7120               (set-buffer current-buffer)
7121               (gnus-summary-exit))
7122             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7123         ;; We try to enter the target group.
7124         (gnus-group-jump-to-group target-group)
7125         (let ((unreads (gnus-group-group-unread)))
7126           (if (and (or (eq t unreads)
7127                        (and unreads (not (zerop unreads))))
7128                    (gnus-summary-read-group
7129                     target-group nil no-article
7130                     (and (buffer-name current-buffer) current-buffer)
7131                     nil backward))
7132               (setq entered t)
7133             (setq current-group target-group
7134                   target-group nil)))))))
7135
7136 (defun gnus-summary-prev-group (&optional no-article)
7137   "Exit current newsgroup and then select previous unread newsgroup.
7138 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7139   (interactive "P")
7140   (gnus-summary-next-group no-article nil t))
7141
7142 ;; Walking around summary lines.
7143
7144 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7145   "Go to the first subject satisfying any non-nil constraint.
7146 If UNREAD is non-nil, the article should be unread.
7147 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7148 If UNSEEN is non-nil, the article should be unseen.
7149 Returns the article selected or nil if there are no matching articles."
7150   (interactive "P")
7151   (cond
7152    ;; Empty summary.
7153    ((null gnus-newsgroup-data)
7154     (gnus-message 3 "No articles in the group")
7155     nil)
7156    ;; Pick the first article.
7157    ((not (or unread undownloaded unseen))
7158     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7159     (gnus-data-number (car gnus-newsgroup-data)))
7160    ;; Find the first unread article.
7161    (t
7162     (let ((data gnus-newsgroup-data))
7163       (while (and data
7164                   (let ((num (gnus-data-number (car data))))
7165                     (or (memq num gnus-newsgroup-unfetched)
7166                         (not (or (and unread
7167                                       (memq num gnus-newsgroup-unreads))
7168                                  (and undownloaded
7169                                       (memq num gnus-newsgroup-undownloaded))
7170                                  (and unseen
7171                                       (memq num gnus-newsgroup-unseen)))))))
7172         (setq data (cdr data)))
7173       (prog1
7174           (if data
7175               (progn
7176                 (goto-char (gnus-data-pos (car data)))
7177                 (gnus-data-number (car data)))
7178             (gnus-message 3 "No more%s articles"
7179                           (let* ((r (when unread " unread"))
7180                                  (d (when undownloaded " undownloaded"))
7181                                  (s (when unseen " unseen"))
7182                                  (l (delq nil (list r d s))))
7183                             (cond ((= 3 (length l))
7184                                    (concat r "," d ", or" s))
7185                                   ((= 2 (length l))
7186                                    (concat (car l) ", or" (cadr l)))
7187                                   ((= 1 (length l))
7188                                    (car l))
7189                                   (t
7190                                    ""))))
7191             nil
7192             )
7193         (gnus-summary-position-point))))))
7194
7195 (defun gnus-summary-next-subject (n &optional unread dont-display)
7196   "Go to next N'th summary line.
7197 If N is negative, go to the previous N'th subject line.
7198 If UNREAD is non-nil, only unread articles are selected.
7199 The difference between N and the actual number of steps taken is
7200 returned."
7201   (interactive "p")
7202   (let ((backward (< n 0))
7203         (n (abs n)))
7204     (while (and (> n 0)
7205                 (if backward
7206                     (gnus-summary-find-prev unread)
7207                   (gnus-summary-find-next unread)))
7208       (unless (zerop (setq n (1- n)))
7209         (gnus-summary-show-thread)))
7210     (when (/= 0 n)
7211       (gnus-message 7 "No more%s articles"
7212                     (if unread " unread" "")))
7213     (unless dont-display
7214       (gnus-summary-recenter)
7215       (gnus-summary-position-point))
7216     n))
7217
7218 (defun gnus-summary-next-unread-subject (n)
7219   "Go to next N'th unread summary line."
7220   (interactive "p")
7221   (gnus-summary-next-subject n t))
7222
7223 (defun gnus-summary-prev-subject (n &optional unread)
7224   "Go to previous N'th summary line.
7225 If optional argument UNREAD is non-nil, only unread article is selected."
7226   (interactive "p")
7227   (gnus-summary-next-subject (- n) unread))
7228
7229 (defun gnus-summary-prev-unread-subject (n)
7230   "Go to previous N'th unread summary line."
7231   (interactive "p")
7232   (gnus-summary-next-subject (- n) t))
7233
7234 (defun gnus-summary-goto-subjects (articles)
7235   "Insert the subject header for ARTICLES in the current buffer."
7236   (save-excursion
7237     (dolist (article articles)
7238       (gnus-summary-goto-subject article t)))
7239   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7240   (gnus-summary-position-point))
7241
7242 (defun gnus-summary-goto-subject (article &optional force silent)
7243   "Go the subject line of ARTICLE.
7244 If FORCE, also allow jumping to articles not currently shown."
7245   (interactive "nArticle number: ")
7246   (unless (numberp article)
7247     (error "Article %s is not a number" article))
7248   (let ((b (point))
7249         (data (gnus-data-find article)))
7250     ;; We read in the article if we have to.
7251     (and (not data)
7252          force
7253          (gnus-summary-insert-subject
7254           article
7255           (if (or (numberp force) (vectorp force)) force)
7256           t)
7257          (setq data (gnus-data-find article)))
7258     (goto-char b)
7259     (if (not data)
7260         (progn
7261           (unless silent
7262             (gnus-message 3 "Can't find article %d" article))
7263           nil)
7264       (let ((pt (gnus-data-pos data)))
7265         (goto-char pt)
7266         (gnus-summary-set-article-display-arrow pt))
7267       (gnus-summary-position-point)
7268       article)))
7269
7270 ;; Walking around summary lines with displaying articles.
7271
7272 (defun gnus-summary-expand-window (&optional arg)
7273   "Make the summary buffer take up the entire Emacs frame.
7274 Given a prefix, will force an `article' buffer configuration."
7275   (interactive "P")
7276   (if arg
7277       (gnus-configure-windows 'article 'force)
7278     (gnus-configure-windows 'summary 'force)))
7279
7280 (defun gnus-summary-display-article (article &optional all-header)
7281   "Display ARTICLE in article buffer."
7282   (when (gnus-buffer-live-p gnus-article-buffer)
7283     (with-current-buffer gnus-article-buffer
7284       (mm-enable-multibyte)))
7285   (gnus-set-global-variables)
7286   (when (gnus-buffer-live-p gnus-article-buffer)
7287     (with-current-buffer gnus-article-buffer
7288       (setq gnus-article-charset gnus-newsgroup-charset)
7289       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7290       (mm-enable-multibyte)))
7291   (if (null article)
7292       nil
7293     (prog1
7294         (if gnus-summary-display-article-function
7295             (funcall gnus-summary-display-article-function article all-header)
7296           (gnus-article-prepare article all-header))
7297       (gnus-run-hooks 'gnus-select-article-hook)
7298       (when (and gnus-current-article
7299                  (not (zerop gnus-current-article)))
7300         (gnus-summary-goto-subject gnus-current-article))
7301       (gnus-summary-recenter)
7302       (when (and gnus-use-trees gnus-show-threads)
7303         (gnus-possibly-generate-tree article)
7304         (gnus-highlight-selected-tree article))
7305       ;; Successfully display article.
7306       (gnus-article-set-window-start
7307        (cdr (assq article gnus-newsgroup-bookmarks))))))
7308
7309 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7310   "Select the current article.
7311 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7312 non-nil, the article will be re-fetched even if it already present in
7313 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7314 be displayed."
7315   ;; Make sure we are in the summary buffer to work around bbdb bug.
7316   (unless (eq major-mode 'gnus-summary-mode)
7317     (set-buffer gnus-summary-buffer))
7318   (let ((article (or article (gnus-summary-article-number)))
7319         (all-headers (not (not all-headers))) ;Must be t or nil.
7320         gnus-summary-display-article-function)
7321     (and (not pseudo)
7322          (gnus-summary-article-pseudo-p article)
7323          (error "This is a pseudo-article"))
7324     (save-excursion
7325       (set-buffer gnus-summary-buffer)
7326       (if (or (and gnus-single-article-buffer
7327                    (or (null gnus-current-article)
7328                        (null gnus-article-current)
7329                        (null (get-buffer gnus-article-buffer))
7330                        (not (eq article (cdr gnus-article-current)))
7331                        (not (equal (car gnus-article-current)
7332                                    gnus-newsgroup-name))))
7333               (and (not gnus-single-article-buffer)
7334                    (or (null gnus-current-article)
7335                        (not (eq gnus-current-article article))))
7336               force)
7337           ;; The requested article is different from the current article.
7338           (progn
7339             (gnus-summary-display-article article all-headers)
7340             (when (gnus-buffer-live-p gnus-article-buffer)
7341               (with-current-buffer gnus-article-buffer
7342                 (if (not gnus-article-decoded-p) ;; a local variable
7343                     (mm-disable-multibyte))))
7344             (gnus-article-set-window-start
7345              (cdr (assq article gnus-newsgroup-bookmarks)))
7346             article)
7347         'old))))
7348
7349 (defun gnus-summary-force-verify-and-decrypt ()
7350   "Display buttons for signed/encrypted parts and verify/decrypt them."
7351   (interactive)
7352   (let ((mm-verify-option 'known)
7353         (mm-decrypt-option 'known)
7354         (gnus-article-emulate-mime t)
7355         (gnus-buttonized-mime-types (append (list "multipart/signed"
7356                                                   "multipart/encrypted")
7357                                             gnus-buttonized-mime-types)))
7358     (gnus-summary-select-article nil 'force)))
7359
7360 (defun gnus-summary-set-current-mark (&optional current-mark)
7361   "Obsolete function."
7362   nil)
7363
7364 (defun gnus-summary-next-article (&optional unread subject backward push)
7365   "Select the next article.
7366 If UNREAD, only unread articles are selected.
7367 If SUBJECT, only articles with SUBJECT are selected.
7368 If BACKWARD, the previous article is selected instead of the next."
7369   (interactive "P")
7370   (cond
7371    ;; Is there such an article?
7372    ((and (gnus-summary-search-forward unread subject backward)
7373          (or (gnus-summary-display-article (gnus-summary-article-number))
7374              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7375     (gnus-summary-position-point))
7376    ;; If not, we try the first unread, if that is wanted.
7377    ((and subject
7378          gnus-auto-select-same
7379          (gnus-summary-first-unread-article))
7380     (gnus-summary-position-point)
7381     (gnus-message 6 "Wrapped"))
7382    ;; Try to get next/previous article not displayed in this group.
7383    ((and gnus-auto-extend-newsgroup
7384          (not unread) (not subject))
7385     (gnus-summary-goto-article
7386      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7387      nil (count-lines (point-min) (point))))
7388    ;; Go to next/previous group.
7389    (t
7390     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7391       (gnus-summary-jump-to-group gnus-newsgroup-name))
7392     (let ((cmd last-command-char)
7393           (point
7394            (with-current-buffer gnus-group-buffer
7395              (point)))
7396           (group
7397            (if (eq gnus-keep-same-level 'best)
7398                (gnus-summary-best-group gnus-newsgroup-name)
7399              (gnus-summary-search-group backward gnus-keep-same-level))))
7400       ;; For some reason, the group window gets selected.  We change
7401       ;; it back.
7402       (select-window (get-buffer-window (current-buffer)))
7403       ;; Select next unread newsgroup automagically.
7404       (cond
7405        ((or (not gnus-auto-select-next)
7406             (not cmd))
7407         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7408        ((or (eq gnus-auto-select-next 'quietly)
7409             (and (eq gnus-auto-select-next 'slightly-quietly)
7410                  push)
7411             (and (eq gnus-auto-select-next 'almost-quietly)
7412                  (gnus-summary-last-article-p)))
7413         ;; Select quietly.
7414         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7415             (gnus-summary-exit)
7416           (gnus-message 7 "No more%s articles (%s)..."
7417                         (if unread " unread" "")
7418                         (if group (concat "selecting " group)
7419                           "exiting"))
7420           (gnus-summary-next-group nil group backward)))
7421        (t
7422         (when (gnus-key-press-event-p last-input-event)
7423           (gnus-summary-walk-group-buffer
7424            gnus-newsgroup-name cmd unread backward point))))))))
7425
7426 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7427   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7428                       (?\C-p (gnus-group-prev-unread-group 1))))
7429         (cursor-in-echo-area t)
7430         keve key group ended prompt)
7431     (save-excursion
7432       (set-buffer gnus-group-buffer)
7433       (goto-char start)
7434       (setq group
7435             (if (eq gnus-keep-same-level 'best)
7436                 (gnus-summary-best-group gnus-newsgroup-name)
7437               (gnus-summary-search-group backward gnus-keep-same-level))))
7438     (while (not ended)
7439       (setq prompt
7440             (format
7441              "No more%s articles%s " (if unread " unread" "")
7442              (if (and group
7443                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7444                  (format " (Type %s for %s [%s])"
7445                          (single-key-description cmd)
7446                          (gnus-group-decoded-name group)
7447                          (gnus-group-unread group))
7448                (format " (Type %s to exit %s)"
7449                        (single-key-description cmd)
7450                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7451       ;; Confirm auto selection.
7452       (setq key (car (setq keve (gnus-read-event-char prompt)))
7453             ended t)
7454       (cond
7455        ((assq key keystrokes)
7456         (let ((obuf (current-buffer)))
7457           (switch-to-buffer gnus-group-buffer)
7458           (when group
7459             (gnus-group-jump-to-group group))
7460           (eval (cadr (assq key keystrokes)))
7461           (setq group (gnus-group-group-name))
7462           (switch-to-buffer obuf))
7463         (setq ended nil))
7464        ((equal key cmd)
7465         (if (or (not group)
7466                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7467             (gnus-summary-exit)
7468           (gnus-summary-next-group nil group backward)))
7469        (t
7470         (push (cdr keve) unread-command-events))))))
7471
7472 (defun gnus-summary-next-unread-article ()
7473   "Select unread article after current one."
7474   (interactive)
7475   (gnus-summary-next-article
7476    (or (not (eq gnus-summary-goto-unread 'never))
7477        (gnus-summary-last-article-p (gnus-summary-article-number)))
7478    (and gnus-auto-select-same
7479         (gnus-summary-article-subject))))
7480
7481 (defun gnus-summary-prev-article (&optional unread subject)
7482   "Select the article after the current one.
7483 If UNREAD is non-nil, only unread articles are selected."
7484   (interactive "P")
7485   (gnus-summary-next-article unread subject t))
7486
7487 (defun gnus-summary-prev-unread-article ()
7488   "Select unread article before current one."
7489   (interactive)
7490   (gnus-summary-prev-article
7491    (or (not (eq gnus-summary-goto-unread 'never))
7492        (gnus-summary-first-article-p (gnus-summary-article-number)))
7493    (and gnus-auto-select-same
7494         (gnus-summary-article-subject))))
7495
7496 (defun gnus-summary-next-page (&optional lines circular stop)
7497   "Show next page of the selected article.
7498 If at the end of the current article, select the next article.
7499 LINES says how many lines should be scrolled up.
7500
7501 If CIRCULAR is non-nil, go to the start of the article instead of
7502 selecting the next article when reaching the end of the current
7503 article.
7504
7505 If STOP is non-nil, just stop when reaching the end of the message.
7506
7507 Also see the variable `gnus-article-skip-boring'."
7508   (interactive "P")
7509   (setq gnus-summary-buffer (current-buffer))
7510   (gnus-set-global-variables)
7511   (let ((article (gnus-summary-article-number))
7512         (article-window (get-buffer-window gnus-article-buffer t))
7513         endp)
7514     ;; If the buffer is empty, we have no article.
7515     (unless article
7516       (error "No article to select"))
7517     (gnus-configure-windows 'article)
7518     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7519         (if (and (eq gnus-summary-goto-unread 'never)
7520                  (not (gnus-summary-last-article-p article)))
7521             (gnus-summary-next-article)
7522           (gnus-summary-next-unread-article))
7523       (if (or (null gnus-current-article)
7524               (null gnus-article-current)
7525               (/= article (cdr gnus-article-current))
7526               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7527           ;; Selected subject is different from current article's.
7528           (gnus-summary-display-article article)
7529         (when article-window
7530           (gnus-eval-in-buffer-window gnus-article-buffer
7531             (setq endp (or (gnus-article-next-page lines)
7532                            (gnus-article-only-boring-p))))
7533           (when endp
7534             (cond (stop
7535                    (gnus-message 3 "End of message"))
7536                   (circular
7537                    (gnus-summary-beginning-of-article))
7538                   (lines
7539                    (gnus-message 3 "End of message"))
7540                   ((null lines)
7541                    (if (and (eq gnus-summary-goto-unread 'never)
7542                             (not (gnus-summary-last-article-p article)))
7543                        (gnus-summary-next-article)
7544                      (gnus-summary-next-unread-article))))))))
7545     (gnus-summary-recenter)
7546     (gnus-summary-position-point)))
7547
7548 (defun gnus-summary-prev-page (&optional lines move)
7549   "Show previous page of selected article.
7550 Argument LINES specifies lines to be scrolled down.
7551 If MOVE, move to the previous unread article if point is at
7552 the beginning of the buffer."
7553   (interactive "P")
7554   (let ((article (gnus-summary-article-number))
7555         (article-window (get-buffer-window gnus-article-buffer t))
7556         endp)
7557     (gnus-configure-windows 'article)
7558     (if (or (null gnus-current-article)
7559             (null gnus-article-current)
7560             (/= article (cdr gnus-article-current))
7561             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7562         ;; Selected subject is different from current article's.
7563         (gnus-summary-display-article article)
7564       (gnus-summary-recenter)
7565       (when article-window
7566         (gnus-eval-in-buffer-window gnus-article-buffer
7567           (setq endp (gnus-article-prev-page lines)))
7568         (when (and move endp)
7569           (cond (lines
7570                  (gnus-message 3 "Beginning of message"))
7571                 ((null lines)
7572                  (if (and (eq gnus-summary-goto-unread 'never)
7573                           (not (gnus-summary-first-article-p article)))
7574                      (gnus-summary-prev-article)
7575                    (gnus-summary-prev-unread-article))))))))
7576   (gnus-summary-position-point))
7577
7578 (defun gnus-summary-prev-page-or-article (&optional lines)
7579   "Show previous page of selected article.
7580 Argument LINES specifies lines to be scrolled down.
7581 If at the beginning of the article, go to the next article."
7582   (interactive "P")
7583   (gnus-summary-prev-page lines t))
7584
7585 (defun gnus-summary-scroll-up (lines)
7586   "Scroll up (or down) one line current article.
7587 Argument LINES specifies lines to be scrolled up (or down if negative)."
7588   (interactive "p")
7589   (gnus-configure-windows 'article)
7590   (gnus-summary-show-thread)
7591   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7592     (gnus-eval-in-buffer-window gnus-article-buffer
7593       (cond ((> lines 0)
7594              (when (gnus-article-next-page lines)
7595                (gnus-message 3 "End of message")))
7596             ((< lines 0)
7597              (gnus-article-prev-page (- lines))))))
7598   (gnus-summary-recenter)
7599   (gnus-summary-position-point))
7600
7601 (defun gnus-summary-scroll-down (lines)
7602   "Scroll down (or up) one line current article.
7603 Argument LINES specifies lines to be scrolled down (or up if negative)."
7604   (interactive "p")
7605   (gnus-summary-scroll-up (- lines)))
7606
7607 (defun gnus-summary-next-same-subject ()
7608   "Select next article which has the same subject as current one."
7609   (interactive)
7610   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7611
7612 (defun gnus-summary-prev-same-subject ()
7613   "Select previous article which has the same subject as current one."
7614   (interactive)
7615   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7616
7617 (defun gnus-summary-next-unread-same-subject ()
7618   "Select next unread article which has the same subject as current one."
7619   (interactive)
7620   (gnus-summary-next-article t (gnus-summary-article-subject)))
7621
7622 (defun gnus-summary-prev-unread-same-subject ()
7623   "Select previous unread article which has the same subject as current one."
7624   (interactive)
7625   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7626
7627 (defun gnus-summary-first-unread-article ()
7628   "Select the first unread article.
7629 Return nil if there are no unread articles."
7630   (interactive)
7631   (prog1
7632       (when (gnus-summary-first-subject t)
7633         (gnus-summary-show-thread)
7634         (gnus-summary-first-subject t)
7635         (gnus-summary-display-article (gnus-summary-article-number)))
7636     (gnus-summary-position-point)))
7637
7638 (defun gnus-summary-first-unread-subject ()
7639   "Place the point on the subject line of the first unread article.
7640 Return nil if there are no unread articles."
7641   (interactive)
7642   (prog1
7643       (when (gnus-summary-first-subject t)
7644         (gnus-summary-show-thread)
7645         (gnus-summary-first-subject t))
7646     (gnus-summary-position-point)))
7647
7648 (defun gnus-summary-first-unseen-subject ()
7649   "Place the point on the subject line of the first unseen article.
7650 Return nil if there are no unseen articles."
7651   (interactive)
7652   (prog1
7653       (when (gnus-summary-first-subject nil nil t)
7654         (gnus-summary-show-thread)
7655         (gnus-summary-first-subject nil nil t))
7656     (gnus-summary-position-point)))
7657
7658 (defun gnus-summary-first-unseen-or-unread-subject ()
7659   "Place the point on the subject line of the first unseen article or,
7660 if all article have been seen, on the subject line of the first unread
7661 article."
7662   (interactive)
7663   (prog1
7664       (unless (when (gnus-summary-first-subject nil nil t)
7665                 (gnus-summary-show-thread)
7666                 (gnus-summary-first-subject nil nil t))
7667         (when (gnus-summary-first-subject t)
7668           (gnus-summary-show-thread)
7669           (gnus-summary-first-subject t)))
7670     (gnus-summary-position-point)))
7671
7672 (defun gnus-summary-first-article ()
7673   "Select the first article.
7674 Return nil if there are no articles."
7675   (interactive)
7676   (prog1
7677       (when (gnus-summary-first-subject)
7678         (gnus-summary-show-thread)
7679         (gnus-summary-first-subject)
7680         (gnus-summary-display-article (gnus-summary-article-number)))
7681     (gnus-summary-position-point)))
7682
7683 (defun gnus-summary-best-unread-article (&optional arg)
7684   "Select the unread article with the highest score.
7685 If given a prefix argument, select the next unread article that has a
7686 score higher than the default score."
7687   (interactive "P")
7688   (let ((article (if arg
7689                      (gnus-summary-better-unread-subject)
7690                    (gnus-summary-best-unread-subject))))
7691     (if article
7692         (gnus-summary-goto-article article)
7693       (error "No unread articles"))))
7694
7695 (defun gnus-summary-best-unread-subject ()
7696   "Select the unread subject with the highest score."
7697   (interactive)
7698   (let ((best -1000000)
7699         (data gnus-newsgroup-data)
7700         article score)
7701     (while data
7702       (and (gnus-data-unread-p (car data))
7703            (> (setq score
7704                     (gnus-summary-article-score (gnus-data-number (car data))))
7705               best)
7706            (setq best score
7707                  article (gnus-data-number (car data))))
7708       (setq data (cdr data)))
7709     (when article
7710       (gnus-summary-goto-subject article))
7711     (gnus-summary-position-point)
7712     article))
7713
7714 (defun gnus-summary-better-unread-subject ()
7715   "Select the first unread subject that has a score over the default score."
7716   (interactive)
7717   (let ((data gnus-newsgroup-data)
7718         article score)
7719     (while (and (setq article (gnus-data-number (car data)))
7720                 (or (gnus-data-read-p (car data))
7721                     (not (> (gnus-summary-article-score article)
7722                             gnus-summary-default-score))))
7723       (setq data (cdr data)))
7724     (when article
7725       (gnus-summary-goto-subject article))
7726     (gnus-summary-position-point)
7727     article))
7728
7729 (defun gnus-summary-last-subject ()
7730   "Go to the last displayed subject line in the group."
7731   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7732     (when article
7733       (gnus-summary-goto-subject article))))
7734
7735 (defun gnus-summary-goto-article (article &optional all-headers force)
7736   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7737 If ALL-HEADERS is non-nil, no header lines are hidden.
7738 If FORCE, go to the article even if it isn't displayed.  If FORCE
7739 is a number, it is the line the article is to be displayed on."
7740   (interactive
7741    (list
7742     (completing-read
7743      "Article number or Message-ID: "
7744      (mapcar (lambda (number) (list (int-to-string number)))
7745              gnus-newsgroup-limit))
7746     current-prefix-arg
7747     t))
7748   (prog1
7749       (if (and (stringp article)
7750                (string-match "@\\|%40" article))
7751           (gnus-summary-refer-article article)
7752         (when (stringp article)
7753           (setq article (string-to-number article)))
7754         (if (gnus-summary-goto-subject article force)
7755             (gnus-summary-display-article article all-headers)
7756           (gnus-message 4 "Couldn't go to article %s" article) nil))
7757     (gnus-summary-position-point)))
7758
7759 (defun gnus-summary-goto-last-article ()
7760   "Go to the previously read article."
7761   (interactive)
7762   (prog1
7763       (when gnus-last-article
7764         (gnus-summary-goto-article gnus-last-article nil t))
7765     (gnus-summary-position-point)))
7766
7767 (defun gnus-summary-pop-article (number)
7768   "Pop one article off the history and go to the previous.
7769 NUMBER articles will be popped off."
7770   (interactive "p")
7771   (let (to)
7772     (setq gnus-newsgroup-history
7773           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7774     (if to
7775         (gnus-summary-goto-article (car to) nil t)
7776       (error "Article history empty")))
7777   (gnus-summary-position-point))
7778
7779 ;; Summary commands and functions for limiting the summary buffer.
7780
7781 (defun gnus-summary-limit-to-articles (n)
7782   "Limit the summary buffer to the next N articles.
7783 If not given a prefix, use the process marked articles instead."
7784   (interactive "P")
7785   (prog1
7786       (let ((articles (gnus-summary-work-articles n)))
7787         (setq gnus-newsgroup-processable nil)
7788         (gnus-summary-limit articles))
7789     (gnus-summary-position-point)))
7790
7791 (defun gnus-summary-pop-limit (&optional total)
7792   "Restore the previous limit.
7793 If given a prefix, remove all limits."
7794   (interactive "P")
7795   (when total
7796     (setq gnus-newsgroup-limits
7797           (list (mapcar (lambda (h) (mail-header-number h))
7798                         gnus-newsgroup-headers))))
7799   (unless gnus-newsgroup-limits
7800     (error "No limit to pop"))
7801   (prog1
7802       (gnus-summary-limit nil 'pop)
7803     (gnus-summary-position-point)))
7804
7805 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7806   "Limit the summary buffer to articles that have subjects that match a regexp.
7807 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7808   (interactive
7809    (list (read-string (if current-prefix-arg
7810                           "Exclude subject (regexp): "
7811                         "Limit to subject (regexp): "))
7812          nil current-prefix-arg))
7813   (unless header
7814     (setq header "subject"))
7815   (when (not (equal "" subject))
7816     (prog1
7817         (let ((articles (gnus-summary-find-matching
7818                          (or header "subject") subject 'all nil nil
7819                          not-matching)))
7820           (unless articles
7821             (error "Found no matches for \"%s\"" subject))
7822           (gnus-summary-limit articles))
7823       (gnus-summary-position-point))))
7824
7825 (defun gnus-summary-limit-to-author (from &optional not-matching)
7826   "Limit the summary buffer to articles that have authors that match a regexp.
7827 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7828   (interactive
7829    (list (read-string (if current-prefix-arg
7830                           "Exclude author (regexp): "
7831                         "Limit to author (regexp): "))
7832          current-prefix-arg))
7833   (gnus-summary-limit-to-subject from "from" not-matching))
7834
7835 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7836   "Limit the summary buffer to articles with the given RECIPIENT.
7837
7838 If NOT-MATCHING, exclude RECIPIENT.
7839
7840 To and Cc headers are checked.  You need to include them in
7841 `nnmail-extra-headers'."
7842   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7843   (interactive
7844    (list (read-string (format "%s recipient (regexp): "
7845                               (if current-prefix-arg "Exclude" "Limit to")))
7846          current-prefix-arg))
7847   (when (not (equal "" recipient))
7848     (prog1 (let* ((to
7849                    (if (memq 'To nnmail-extra-headers)
7850                        (gnus-summary-find-matching
7851                         (cons 'extra 'To) recipient 'all nil nil
7852                         not-matching)
7853                      (gnus-message
7854                       1 "`To' isn't present in `nnmail-extra-headers'")
7855                      (sit-for 1)
7856                      nil))
7857                   (cc
7858                    (if (memq 'Cc nnmail-extra-headers)
7859                        (gnus-summary-find-matching
7860                         (cons 'extra 'Cc) recipient 'all nil nil
7861                         not-matching)
7862                      (gnus-message
7863                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7864                      (sit-for 1)
7865                      nil))
7866                   (articles
7867                    (if not-matching
7868                        ;; We need the numbers that are in both lists:
7869                        (mapcar (lambda (a)
7870                                  (and (memq a to) a))
7871                                cc)
7872                      (nconc to cc))))
7873              (unless articles
7874                (error "Found no matches for \"%s\"" recipient))
7875              (gnus-summary-limit articles))
7876       (gnus-summary-position-point))))
7877
7878 (defun gnus-summary-limit-to-age (age &optional younger-p)
7879   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7880 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7881 articles that are younger than AGE days."
7882   (interactive
7883    (let ((younger current-prefix-arg)
7884          (days-got nil)
7885          days)
7886      (while (not days-got)
7887        (setq days (if younger
7888                       (read-string "Limit to articles younger than (in days, older when negative): ")
7889                     (read-string
7890                      "Limit to articles older than (in days, younger when negative): ")))
7891        (when (> (length days) 0)
7892          (setq days (read days)))
7893        (if (numberp days)
7894            (progn
7895              (setq days-got t)
7896              (when (< days 0)
7897                (setq younger (not younger))
7898                (setq days (* days -1))))
7899          (message "Please enter a number.")
7900          (sleep-for 1)))
7901      (list days younger)))
7902   (prog1
7903       (let ((data gnus-newsgroup-data)
7904             (cutoff (days-to-time age))
7905             articles d date is-younger)
7906         (while (setq d (pop data))
7907           (when (and (vectorp (gnus-data-header d))
7908                      (setq date (mail-header-date (gnus-data-header d))))
7909             (setq is-younger (time-less-p
7910                               (time-since (condition-case ()
7911                                               (date-to-time date)
7912                                             (error '(0 0))))
7913                               cutoff))
7914             (when (if younger-p
7915                       is-younger
7916                     (not is-younger))
7917               (push (gnus-data-number d) articles))))
7918         (gnus-summary-limit (nreverse articles)))
7919     (gnus-summary-position-point)))
7920
7921 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7922   "Limit the summary buffer to articles that match an 'extra' header."
7923   (interactive
7924    (let ((header
7925           (intern
7926            (gnus-completing-read-with-default
7927             (symbol-name (car gnus-extra-headers))
7928             (if current-prefix-arg
7929                 "Exclude extra header"
7930               "Limit extra header")
7931             (mapcar (lambda (x)
7932                       (cons (symbol-name x) x))
7933                     gnus-extra-headers)
7934             nil
7935             t))))
7936      (list header
7937            (read-string (format "%s header %s (regexp): "
7938                                 (if current-prefix-arg "Exclude" "Limit to")
7939                                 header))
7940            current-prefix-arg)))
7941   (when (not (equal "" regexp))
7942     (prog1
7943         (let ((articles (gnus-summary-find-matching
7944                          (cons 'extra header) regexp 'all nil nil
7945                          not-matching)))
7946           (unless articles
7947             (error "Found no matches for \"%s\"" regexp))
7948           (gnus-summary-limit articles))
7949       (gnus-summary-position-point))))
7950
7951 (defun gnus-summary-limit-to-display-predicate ()
7952   "Limit the summary buffer to the predicated in the `display' group parameter."
7953   (interactive)
7954   (unless gnus-newsgroup-display
7955     (error "There is no `display' group parameter"))
7956   (let (articles)
7957     (dolist (number gnus-newsgroup-articles)
7958       (when (funcall gnus-newsgroup-display)
7959         (push number articles)))
7960     (gnus-summary-limit articles))
7961   (gnus-summary-position-point))
7962
7963 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7964 (make-obsolete
7965  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7966
7967 (defun gnus-summary-limit-to-unread (&optional all)
7968   "Limit the summary buffer to articles that are not marked as read.
7969 If ALL is non-nil, limit strictly to unread articles."
7970   (interactive "P")
7971   (if all
7972       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7973     (gnus-summary-limit-to-marks
7974      ;; Concat all the marks that say that an article is read and have
7975      ;; those removed.
7976      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7977            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7978            gnus-low-score-mark gnus-expirable-mark
7979            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7980            gnus-duplicate-mark gnus-souped-mark)
7981      'reverse)))
7982
7983 (defun gnus-summary-limit-to-replied (&optional unreplied)
7984   "Limit the summary buffer to replied articles.
7985 If UNREPLIED (the prefix), limit to unreplied articles."
7986   (interactive "P")
7987   (if unreplied
7988       (gnus-summary-limit
7989        (gnus-set-difference gnus-newsgroup-articles
7990         gnus-newsgroup-replied))
7991     (gnus-summary-limit gnus-newsgroup-replied))
7992   (gnus-summary-position-point))
7993
7994 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7995 (make-obsolete 'gnus-summary-delete-marked-with
7996                'gnus-summary-limit-exclude-marks)
7997
7998 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7999   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8000 If REVERSE, limit the summary buffer to articles that are marked
8001 with MARKS.  MARKS can either be a string of marks or a list of marks.
8002 Returns how many articles were removed."
8003   (interactive "sMarks: ")
8004   (gnus-summary-limit-to-marks marks t))
8005
8006 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8007   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8008 If REVERSE (the prefix), limit the summary buffer to articles that are
8009 not marked with MARKS.  MARKS can either be a string of marks or a
8010 list of marks.
8011 Returns how many articles were removed."
8012   (interactive "sMarks: \nP")
8013   (prog1
8014       (let ((data gnus-newsgroup-data)
8015             (marks (if (listp marks) marks
8016                      (append marks nil))) ; Transform to list.
8017             articles)
8018         (while data
8019           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8020                   (memq (gnus-data-mark (car data)) marks))
8021             (push (gnus-data-number (car data)) articles))
8022           (setq data (cdr data)))
8023         (gnus-summary-limit articles))
8024     (gnus-summary-position-point)))
8025
8026 (defun gnus-summary-limit-to-score (score)
8027   "Limit to articles with score at or above SCORE."
8028   (interactive "NLimit to articles with score of at least: ")
8029   (let ((data gnus-newsgroup-data)
8030         articles)
8031     (while data
8032       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8033                 score)
8034         (push (gnus-data-number (car data)) articles))
8035       (setq data (cdr data)))
8036     (prog1
8037         (gnus-summary-limit articles)
8038       (gnus-summary-position-point))))
8039
8040 (defun gnus-summary-limit-to-unseen ()
8041   "Limit to unseen articles."
8042   (interactive)
8043   (prog1
8044       (gnus-summary-limit gnus-newsgroup-unseen)
8045     (gnus-summary-position-point)))
8046
8047 (defun gnus-summary-limit-include-thread (id)
8048   "Display all the hidden articles that is in the thread with ID in it.
8049 When called interactively, ID is the Message-ID of the current
8050 article."
8051   (interactive (list (mail-header-id (gnus-summary-article-header))))
8052   (let ((articles (gnus-articles-in-thread
8053                    (gnus-id-to-thread (gnus-root-id id)))))
8054     (prog1
8055         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8056       (gnus-summary-limit-include-matching-articles
8057        "subject"
8058        (regexp-quote (gnus-simplify-subject-re
8059                       (mail-header-subject (gnus-id-to-header id)))))
8060       (gnus-summary-position-point))))
8061
8062 (defun gnus-summary-limit-include-matching-articles (header regexp)
8063   "Display all the hidden articles that have HEADERs that match REGEXP."
8064   (interactive (list (read-string "Match on header: ")
8065                      (read-string "Regexp: ")))
8066   (let ((articles (gnus-find-matching-articles header regexp)))
8067     (prog1
8068         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8069       (gnus-summary-position-point))))
8070
8071 (defun gnus-summary-insert-dormant-articles ()
8072   "Insert all the dormant articles for this group into the current buffer."
8073   (interactive)
8074   (let ((gnus-verbose (max 6 gnus-verbose)))
8075     (if (not gnus-newsgroup-dormant)
8076         (gnus-message 3 "No cached articles for this group")
8077       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8078
8079 (defun gnus-summary-limit-include-dormant ()
8080   "Display all the hidden articles that are marked as dormant.
8081 Note that this command only works on a subset of the articles currently
8082 fetched for this group."
8083   (interactive)
8084   (unless gnus-newsgroup-dormant
8085     (error "There are no dormant articles in this group"))
8086   (prog1
8087       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8088     (gnus-summary-position-point)))
8089
8090 (defun gnus-summary-limit-exclude-dormant ()
8091   "Hide all dormant articles."
8092   (interactive)
8093   (prog1
8094       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8095     (gnus-summary-position-point)))
8096
8097 (defun gnus-summary-limit-exclude-childless-dormant ()
8098   "Hide all dormant articles that have no children."
8099   (interactive)
8100   (let ((data (gnus-data-list t))
8101         articles d children)
8102     ;; Find all articles that are either not dormant or have
8103     ;; children.
8104     (while (setq d (pop data))
8105       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8106                 (and (setq children
8107                            (gnus-article-children (gnus-data-number d)))
8108                      (let (found)
8109                        (while children
8110                          (when (memq (car children) articles)
8111                            (setq children nil
8112                                  found t))
8113                          (pop children))
8114                        found)))
8115         (push (gnus-data-number d) articles)))
8116     ;; Do the limiting.
8117     (prog1
8118         (gnus-summary-limit articles)
8119       (gnus-summary-position-point))))
8120
8121 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8122   "Mark all unread excluded articles as read.
8123 If ALL, mark even excluded ticked and dormants as read."
8124   (interactive "P")
8125   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8126   (let ((articles (gnus-sorted-ndifference
8127                    (sort
8128                     (mapcar (lambda (h) (mail-header-number h))
8129                             gnus-newsgroup-headers)
8130                     '<)
8131                    gnus-newsgroup-limit))
8132         article)
8133     (setq gnus-newsgroup-unreads
8134           (gnus-sorted-intersection gnus-newsgroup-unreads
8135                                     gnus-newsgroup-limit))
8136     (if all
8137         (setq gnus-newsgroup-dormant nil
8138               gnus-newsgroup-marked nil
8139               gnus-newsgroup-reads
8140               (nconc
8141                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8142                gnus-newsgroup-reads))
8143       (while (setq article (pop articles))
8144         (unless (or (memq article gnus-newsgroup-dormant)
8145                     (memq article gnus-newsgroup-marked))
8146           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8147
8148 (defun gnus-summary-limit (articles &optional pop)
8149   (if pop
8150       ;; We pop the previous limit off the stack and use that.
8151       (setq articles (car gnus-newsgroup-limits)
8152             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8153     ;; We use the new limit, so we push the old limit on the stack.
8154     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8155   ;; Set the limit.
8156   (setq gnus-newsgroup-limit articles)
8157   (let ((total (length gnus-newsgroup-data))
8158         (data (gnus-data-find-list (gnus-summary-article-number)))
8159         (gnus-summary-mark-below nil)   ; Inhibit this.
8160         found)
8161     ;; This will do all the work of generating the new summary buffer
8162     ;; according to the new limit.
8163     (gnus-summary-prepare)
8164     ;; Hide any threads, possibly.
8165     (gnus-summary-maybe-hide-threads)
8166     ;; Try to return to the article you were at, or one in the
8167     ;; neighborhood.
8168     (when data
8169       ;; We try to find some article after the current one.
8170       (while data
8171         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8172           (setq data nil
8173                 found t))
8174         (setq data (cdr data))))
8175     (unless found
8176       ;; If there is no data, that means that we were after the last
8177       ;; article.  The same goes when we can't find any articles
8178       ;; after the current one.
8179       (goto-char (point-max))
8180       (gnus-summary-find-prev))
8181     (gnus-set-mode-line 'summary)
8182     ;; We return how many articles were removed from the summary
8183     ;; buffer as a result of the new limit.
8184     (- total (length gnus-newsgroup-data))))
8185
8186 (defsubst gnus-invisible-cut-children (threads)
8187   (let ((num 0))
8188     (while threads
8189       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8190         (incf num))
8191       (pop threads))
8192     (< num 2)))
8193
8194 (defsubst gnus-cut-thread (thread)
8195   "Go forwards in the thread until we find an article that we want to display."
8196   (when (or (eq gnus-fetch-old-headers 'some)
8197             (eq gnus-fetch-old-headers 'invisible)
8198             (numberp gnus-fetch-old-headers)
8199             (eq gnus-build-sparse-threads 'some)
8200             (eq gnus-build-sparse-threads 'more))
8201     ;; Deal with old-fetched headers and sparse threads.
8202     (while (and
8203             thread
8204             (or
8205              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8206              (gnus-summary-article-ancient-p
8207               (mail-header-number (car thread))))
8208             (if (or (<= (length (cdr thread)) 1)
8209                     (eq gnus-fetch-old-headers 'invisible))
8210                 (setq gnus-newsgroup-limit
8211                       (delq (mail-header-number (car thread))
8212                             gnus-newsgroup-limit)
8213                       thread (cadr thread))
8214               (when (gnus-invisible-cut-children (cdr thread))
8215                 (let ((th (cdr thread)))
8216                   (while th
8217                     (if (memq (mail-header-number (caar th))
8218                               gnus-newsgroup-limit)
8219                         (setq thread (car th)
8220                               th nil)
8221                       (setq th (cdr th))))))))))
8222   thread)
8223
8224 (defun gnus-cut-threads (threads)
8225   "Cut off all uninteresting articles from the beginning of THREADS."
8226   (when (or (eq gnus-fetch-old-headers 'some)
8227             (eq gnus-fetch-old-headers 'invisible)
8228             (numberp gnus-fetch-old-headers)
8229             (eq gnus-build-sparse-threads 'some)
8230             (eq gnus-build-sparse-threads 'more))
8231     (let ((th threads))
8232       (while th
8233         (setcar th (gnus-cut-thread (car th)))
8234         (setq th (cdr th)))))
8235   ;; Remove nixed out threads.
8236   (delq nil threads))
8237
8238 (defun gnus-summary-initial-limit (&optional show-if-empty)
8239   "Figure out what the initial limit is supposed to be on group entry.
8240 This entails weeding out unwanted dormants, low-scored articles,
8241 fetch-old-headers verbiage, and so on."
8242   ;; Most groups have nothing to remove.
8243   (if (or gnus-inhibit-limiting
8244           (and (null gnus-newsgroup-dormant)
8245                (eq gnus-newsgroup-display 'gnus-not-ignore)
8246                (not (eq gnus-fetch-old-headers 'some))
8247                (not (numberp gnus-fetch-old-headers))
8248                (not (eq gnus-fetch-old-headers 'invisible))
8249                (null gnus-summary-expunge-below)
8250                (not (eq gnus-build-sparse-threads 'some))
8251                (not (eq gnus-build-sparse-threads 'more))
8252                (null gnus-thread-expunge-below)
8253                (not gnus-use-nocem)))
8254       ()                                ; Do nothing.
8255     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8256     (setq gnus-newsgroup-limit nil)
8257     (mapatoms
8258      (lambda (node)
8259        (unless (car (symbol-value node))
8260          ;; These threads have no parents -- they are roots.
8261          (let ((nodes (cdr (symbol-value node)))
8262                thread)
8263            (while nodes
8264              (if (and gnus-thread-expunge-below
8265                       (< (gnus-thread-total-score (car nodes))
8266                          gnus-thread-expunge-below))
8267                  (gnus-expunge-thread (pop nodes))
8268                (setq thread (pop nodes))
8269                (gnus-summary-limit-children thread))))))
8270      gnus-newsgroup-dependencies)
8271     ;; If this limitation resulted in an empty group, we might
8272     ;; pop the previous limit and use it instead.
8273     (when (and (not gnus-newsgroup-limit)
8274                show-if-empty)
8275       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8276     gnus-newsgroup-limit))
8277
8278 (defun gnus-summary-limit-children (thread)
8279   "Return 1 if this subthread is visible and 0 if it is not."
8280   ;; First we get the number of visible children to this thread.  This
8281   ;; is done by recursing down the thread using this function, so this
8282   ;; will really go down to a leaf article first, before slowly
8283   ;; working its way up towards the root.
8284   (when thread
8285     (let* ((max-lisp-eval-depth 5000)
8286            (children
8287            (if (cdr thread)
8288                (apply '+ (mapcar 'gnus-summary-limit-children
8289                                  (cdr thread)))
8290              0))
8291           (number (mail-header-number (car thread)))
8292           score)
8293       (if (and
8294            (not (memq number gnus-newsgroup-marked))
8295            (or
8296             ;; If this article is dormant and has absolutely no visible
8297             ;; children, then this article isn't visible.
8298             (and (memq number gnus-newsgroup-dormant)
8299                  (zerop children))
8300             ;; If this is "fetch-old-headered" and there is no
8301             ;; visible children, then we don't want this article.
8302             (and (or (eq gnus-fetch-old-headers 'some)
8303                      (numberp gnus-fetch-old-headers))
8304                  (gnus-summary-article-ancient-p number)
8305                  (zerop children))
8306             ;; If this is "fetch-old-headered" and `invisible', then
8307             ;; we don't want this article.
8308             (and (eq gnus-fetch-old-headers 'invisible)
8309                  (gnus-summary-article-ancient-p number))
8310             ;; If this is a sparsely inserted article with no children,
8311             ;; we don't want it.
8312             (and (eq gnus-build-sparse-threads 'some)
8313                  (gnus-summary-article-sparse-p number)
8314                  (zerop children))
8315             ;; If we use expunging, and this article is really
8316             ;; low-scored, then we don't want this article.
8317             (when (and gnus-summary-expunge-below
8318                        (< (setq score
8319                                 (or (cdr (assq number gnus-newsgroup-scored))
8320                                     gnus-summary-default-score))
8321                           gnus-summary-expunge-below))
8322               ;; We increase the expunge-tally here, but that has
8323               ;; nothing to do with the limits, really.
8324               (incf gnus-newsgroup-expunged-tally)
8325               ;; We also mark as read here, if that's wanted.
8326               (when (and gnus-summary-mark-below
8327                          (< score gnus-summary-mark-below))
8328                 (setq gnus-newsgroup-unreads
8329                       (delq number gnus-newsgroup-unreads))
8330                 (if gnus-newsgroup-auto-expire
8331                     (push number gnus-newsgroup-expirable)
8332                   (push (cons number gnus-low-score-mark)
8333                         gnus-newsgroup-reads)))
8334               t)
8335             ;; Do the `display' group parameter.
8336             (and gnus-newsgroup-display
8337                  (not (funcall gnus-newsgroup-display)))
8338             ;; Check NoCeM things.
8339             (when (and gnus-use-nocem
8340                        (gnus-nocem-unwanted-article-p
8341                         (mail-header-id (car thread))))
8342               (setq gnus-newsgroup-unreads
8343                     (delq number gnus-newsgroup-unreads))
8344               t)))
8345           ;; Nope, invisible article.
8346           0
8347         ;; Ok, this article is to be visible, so we add it to the limit
8348         ;; and return 1.
8349         (push number gnus-newsgroup-limit)
8350         1))))
8351
8352 (defun gnus-expunge-thread (thread)
8353   "Mark all articles in THREAD as read."
8354   (let* ((number (mail-header-number (car thread))))
8355     (incf gnus-newsgroup-expunged-tally)
8356     ;; We also mark as read here, if that's wanted.
8357     (setq gnus-newsgroup-unreads
8358           (delq number gnus-newsgroup-unreads))
8359     (if gnus-newsgroup-auto-expire
8360         (push number gnus-newsgroup-expirable)
8361       (push (cons number gnus-low-score-mark)
8362             gnus-newsgroup-reads)))
8363   ;; Go recursively through all subthreads.
8364   (mapcar 'gnus-expunge-thread (cdr thread)))
8365
8366 ;; Summary article oriented commands
8367
8368 (defun gnus-summary-refer-parent-article (n)
8369   "Refer parent article N times.
8370 If N is negative, go to ancestor -N instead.
8371 The difference between N and the number of articles fetched is returned."
8372   (interactive "p")
8373   (let ((skip 1)
8374         error header ref)
8375     (when (not (natnump n))
8376       (setq skip (abs n)
8377             n 1))
8378     (while (and (> n 0)
8379                 (not error))
8380       (setq header (gnus-summary-article-header))
8381       (if (and (eq (mail-header-number header)
8382                    (cdr gnus-article-current))
8383                (equal gnus-newsgroup-name
8384                       (car gnus-article-current)))
8385           ;; If we try to find the parent of the currently
8386           ;; displayed article, then we take a look at the actual
8387           ;; References header, since this is slightly more
8388           ;; reliable than the References field we got from the
8389           ;; server.
8390           (save-excursion
8391             (set-buffer gnus-original-article-buffer)
8392             (nnheader-narrow-to-headers)
8393             (unless (setq ref (message-fetch-field "references"))
8394               (when (setq ref (message-fetch-field "in-reply-to"))
8395                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8396             (widen))
8397         (setq ref
8398               ;; It's not the current article, so we take a bet on
8399               ;; the value we got from the server.
8400               (mail-header-references header)))
8401       (if (and ref
8402                (not (equal ref "")))
8403           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8404             (gnus-message 1 "Couldn't find parent"))
8405         (gnus-message 1 "No references in article %d"
8406                       (gnus-summary-article-number))
8407         (setq error t))
8408       (decf n))
8409     (gnus-summary-position-point)
8410     n))
8411
8412 (defun gnus-summary-refer-references ()
8413   "Fetch all articles mentioned in the References header.
8414 Return the number of articles fetched."
8415   (interactive)
8416   (let ((ref (mail-header-references (gnus-summary-article-header)))
8417         (current (gnus-summary-article-number))
8418         (n 0))
8419     (if (or (not ref)
8420             (equal ref ""))
8421         (error "No References in the current article")
8422       ;; For each Message-ID in the References header...
8423       (while (string-match "<[^>]*>" ref)
8424         (incf n)
8425         ;; ... fetch that article.
8426         (gnus-summary-refer-article
8427          (prog1 (match-string 0 ref)
8428            (setq ref (substring ref (match-end 0))))))
8429       (gnus-summary-goto-subject current)
8430       (gnus-summary-position-point)
8431       n)))
8432
8433 (defun gnus-summary-refer-thread (&optional limit)
8434   "Fetch all articles in the current thread.
8435 If LIMIT (the numerical prefix), fetch that many old headers instead
8436 of what's specified by the `gnus-refer-thread-limit' variable."
8437   (interactive "P")
8438   (let ((id (mail-header-id (gnus-summary-article-header)))
8439         (limit (if limit (prefix-numeric-value limit)
8440                  gnus-refer-thread-limit)))
8441     (unless (eq gnus-fetch-old-headers 'invisible)
8442       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8443       ;; Retrieve the headers and read them in.
8444       (if (eq (if (numberp limit)
8445                   (gnus-retrieve-headers
8446                    (list (min
8447                           (+ (mail-header-number
8448                               (gnus-summary-article-header))
8449                              limit)
8450                           gnus-newsgroup-end))
8451                    gnus-newsgroup-name (* limit 2))
8452                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8453                 ;; headers.
8454                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8455                                        gnus-newsgroup-name limit))
8456               'nov)
8457           (gnus-build-all-threads)
8458         (error "Can't fetch thread from back ends that don't support NOV"))
8459       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8460     (gnus-summary-limit-include-thread id)))
8461
8462 (defun gnus-summary-refer-article (message-id)
8463   "Fetch an article specified by MESSAGE-ID."
8464   (interactive "sMessage-ID: ")
8465   (when (and (stringp message-id)
8466              (not (zerop (length message-id))))
8467     (setq message-id (gnus-replace-in-string message-id " " ""))
8468     ;; Construct the correct Message-ID if necessary.
8469     ;; Suggested by tale@pawl.rpi.edu.
8470     (unless (string-match "^<" message-id)
8471       (setq message-id (concat "<" message-id)))
8472     (unless (string-match ">$" message-id)
8473       (setq message-id (concat message-id ">")))
8474     ;; People often post MIDs from URLs, so unhex it:
8475     (unless (string-match "@" message-id)
8476       (setq message-id (gnus-url-unhex-string message-id)))
8477     (let* ((header (gnus-id-to-header message-id))
8478            (sparse (and header
8479                         (gnus-summary-article-sparse-p
8480                          (mail-header-number header))
8481                         (memq (mail-header-number header)
8482                               gnus-newsgroup-limit)))
8483            number)
8484       (cond
8485        ;; If the article is present in the buffer we just go to it.
8486        ((and header
8487              (or (not (gnus-summary-article-sparse-p
8488                        (mail-header-number header)))
8489                  sparse))
8490         (prog1
8491             (gnus-summary-goto-article
8492              (mail-header-number header) nil t)
8493           (when sparse
8494             (gnus-summary-update-article (mail-header-number header)))))
8495        (t
8496         ;; We fetch the article.
8497         (catch 'found
8498           (dolist (gnus-override-method (gnus-refer-article-methods))
8499             (when (and (gnus-check-server gnus-override-method)
8500                        ;; Fetch the header,
8501                        (setq number (gnus-summary-insert-subject message-id)))
8502               ;; and display the article.
8503               (gnus-summary-select-article nil nil nil number)
8504               (throw 'found t)))
8505           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8506
8507 (defun gnus-refer-article-methods ()
8508   "Return a list of referable methods."
8509   (cond
8510    ;; No method, so we default to current and native.
8511    ((null gnus-refer-article-method)
8512     (list gnus-current-select-method gnus-select-method))
8513    ;; Current.
8514    ((eq 'current gnus-refer-article-method)
8515     (list gnus-current-select-method))
8516    ;; List of select methods.
8517    ((not (and (symbolp (car gnus-refer-article-method))
8518               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8519     (let (out)
8520       (dolist (method gnus-refer-article-method)
8521         (push (if (eq 'current method)
8522                   gnus-current-select-method
8523                 method)
8524               out))
8525       (nreverse out)))
8526    ;; One single select method.
8527    (t
8528     (list gnus-refer-article-method))))
8529
8530 (defun gnus-summary-edit-parameters ()
8531   "Edit the group parameters of the current group."
8532   (interactive)
8533   (gnus-group-edit-group gnus-newsgroup-name 'params))
8534
8535 (defun gnus-summary-customize-parameters ()
8536   "Customize the group parameters of the current group."
8537   (interactive)
8538   (gnus-group-customize gnus-newsgroup-name))
8539
8540 (defun gnus-summary-enter-digest-group (&optional force)
8541   "Enter an nndoc group based on the current article.
8542 If FORCE, force a digest interpretation.  If not, try
8543 to guess what the document format is."
8544   (interactive "P")
8545   (let ((conf gnus-current-window-configuration))
8546     (save-window-excursion
8547       (save-excursion
8548         (let (gnus-article-prepare-hook
8549               gnus-display-mime-function
8550               gnus-break-pages)
8551           (gnus-summary-select-article))))
8552     (setq gnus-current-window-configuration conf)
8553     (let* ((name (format "%s-%d"
8554                          (gnus-group-prefixed-name
8555                           gnus-newsgroup-name (list 'nndoc ""))
8556                          (with-current-buffer gnus-summary-buffer
8557                            gnus-current-article)))
8558            (ogroup gnus-newsgroup-name)
8559            (params (append (gnus-info-params (gnus-get-info ogroup))
8560                            (list (cons 'to-group ogroup))
8561                            (list (cons 'parent-group ogroup))
8562                            (list (cons 'save-article-group ogroup))))
8563            (case-fold-search t)
8564            (buf (current-buffer))
8565            dig to-address)
8566       (save-excursion
8567         (set-buffer gnus-original-article-buffer)
8568         ;; Have the digest group inherit the main mail address of
8569         ;; the parent article.
8570         (when (setq to-address (or (gnus-fetch-field "reply-to")
8571                                    (gnus-fetch-field "from")))
8572           (setq params (append
8573                         (list (cons 'to-address
8574                                     (funcall gnus-decode-encoded-word-function
8575                                              to-address))))))
8576         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8577         (insert-buffer-substring gnus-original-article-buffer)
8578         ;; Remove lines that may lead nndoc to misinterpret the
8579         ;; document type.
8580         (narrow-to-region
8581          (goto-char (point-min))
8582          (or (search-forward "\n\n" nil t) (point)))
8583         (goto-char (point-min))
8584         (delete-matching-lines "^Path:\\|^From ")
8585         (widen))
8586       (unwind-protect
8587           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8588                     (gnus-newsgroup-ephemeral-ignored-charsets
8589                      gnus-newsgroup-ignored-charsets))
8590                 (gnus-group-read-ephemeral-group
8591                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8592                               (nndoc-article-type
8593                                ,(if force 'mbox 'guess)))
8594                  t nil nil nil
8595                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8596                                                         "ADAPT")))))
8597               ;; Make all postings to this group go to the parent group.
8598               (nconc (gnus-info-params (gnus-get-info name))
8599                      params)
8600             ;; Couldn't select this doc group.
8601             (switch-to-buffer buf)
8602             (gnus-set-global-variables)
8603             (gnus-configure-windows 'summary)
8604             (gnus-message 3 "Article couldn't be entered?"))
8605         (kill-buffer dig)))))
8606
8607 (defun gnus-summary-read-document (n)
8608   "Open a new group based on the current article(s).
8609 This will allow you to read digests and other similar
8610 documents as newsgroups.
8611 Obeys the standard process/prefix convention."
8612   (interactive "P")
8613   (let* ((ogroup gnus-newsgroup-name)
8614          (params (append (gnus-info-params (gnus-get-info ogroup))
8615                          (list (cons 'to-group ogroup))))
8616          group egroup groups vgroup)
8617     (dolist (article (gnus-summary-work-articles n))
8618       (setq group (format "%s-%d" gnus-newsgroup-name article))
8619       (gnus-summary-remove-process-mark article)
8620       (when (gnus-summary-display-article article)
8621         (save-excursion
8622           (with-temp-buffer
8623             (insert-buffer-substring gnus-original-article-buffer)
8624             ;; Remove some headers that may lead nndoc to make
8625             ;; the wrong guess.
8626             (message-narrow-to-head)
8627             (goto-char (point-min))
8628             (delete-matching-lines "^Path:\\|^From ")
8629             (widen)
8630             (if (setq egroup
8631                       (gnus-group-read-ephemeral-group
8632                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8633                                      (nndoc-article-type guess))
8634                        t nil t))
8635                 (progn
8636             ;; Make all postings to this group go to the parent group.
8637                   (nconc (gnus-info-params (gnus-get-info egroup))
8638                          params)
8639                   (push egroup groups))
8640               ;; Couldn't select this doc group.
8641               (gnus-error 3 "Article couldn't be entered"))))))
8642     ;; Now we have selected all the documents.
8643     (cond
8644      ((not groups)
8645       (error "None of the articles could be interpreted as documents"))
8646      ((gnus-group-read-ephemeral-group
8647        (setq vgroup (format
8648                      "nnvirtual:%s-%s" gnus-newsgroup-name
8649                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8650        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8651        t
8652        (cons (current-buffer) 'summary)))
8653      (t
8654       (error "Couldn't select virtual nndoc group")))))
8655
8656 (defun gnus-summary-isearch-article (&optional regexp-p)
8657   "Do incremental search forward on the current article.
8658 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8659   (interactive "P")
8660   (gnus-summary-select-article)
8661   (gnus-configure-windows 'article)
8662   (gnus-eval-in-buffer-window gnus-article-buffer
8663     (save-restriction
8664       (widen)
8665       (isearch-forward regexp-p))))
8666
8667 (defun gnus-summary-search-article-forward (regexp &optional backward)
8668   "Search for an article containing REGEXP forward.
8669 If BACKWARD, search backward instead."
8670   (interactive
8671    (list (read-string
8672           (format "Search article %s (regexp%s): "
8673                   (if current-prefix-arg "backward" "forward")
8674                   (if gnus-last-search-regexp
8675                       (concat ", default " gnus-last-search-regexp)
8676                     "")))
8677          current-prefix-arg))
8678   (if (string-equal regexp "")
8679       (setq regexp (or gnus-last-search-regexp ""))
8680     (setq gnus-last-search-regexp regexp)
8681     (setq gnus-article-before-search gnus-current-article))
8682   ;; Intentionally set gnus-last-article.
8683   (setq gnus-last-article gnus-article-before-search)
8684   (let ((gnus-last-article gnus-last-article))
8685     (if (gnus-summary-search-article regexp backward)
8686         (gnus-summary-show-thread)
8687       (signal 'search-failed (list regexp)))))
8688
8689 (defun gnus-summary-search-article-backward (regexp)
8690   "Search for an article containing REGEXP backward."
8691   (interactive
8692    (list (read-string
8693           (format "Search article backward (regexp%s): "
8694                   (if gnus-last-search-regexp
8695                       (concat ", default " gnus-last-search-regexp)
8696                     "")))))
8697   (gnus-summary-search-article-forward regexp 'backward))
8698
8699 (defun gnus-summary-search-article (regexp &optional backward)
8700   "Search for an article containing REGEXP.
8701 Optional argument BACKWARD means do search for backward.
8702 `gnus-select-article-hook' is not called during the search."
8703   ;; We have to require this here to make sure that the following
8704   ;; dynamic binding isn't shadowed by autoloading.
8705   (require 'gnus-async)
8706   (require 'gnus-art)
8707   (let ((gnus-select-article-hook nil)  ;Disable hook.
8708         (gnus-article-prepare-hook nil)
8709         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8710         (gnus-use-article-prefetch nil)
8711         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8712         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8713         (gnus-visual nil)
8714         (gnus-keep-backlog nil)
8715         (gnus-break-pages nil)
8716         (gnus-summary-display-arrow nil)
8717         (gnus-updated-mode-lines nil)
8718         (gnus-auto-center-summary nil)
8719         (sum (current-buffer))
8720         (gnus-display-mime-function nil)
8721         (found nil)
8722         point)
8723     (gnus-save-hidden-threads
8724       (gnus-summary-select-article)
8725       (set-buffer gnus-article-buffer)
8726       (goto-char (window-point (get-buffer-window (current-buffer))))
8727       (when backward
8728         (forward-line -1))
8729       (while (not found)
8730         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8731         (if (if backward
8732                 (re-search-backward regexp nil t)
8733               (re-search-forward regexp nil t))
8734             ;; We found the regexp.
8735             (progn
8736               (setq found 'found)
8737               (beginning-of-line)
8738               (set-window-start
8739                (get-buffer-window (current-buffer))
8740                (point))
8741               (forward-line 1)
8742               (set-window-point
8743                (get-buffer-window (current-buffer))
8744                (point))
8745               (set-buffer sum)
8746               (setq point (point)))
8747           ;; We didn't find it, so we go to the next article.
8748           (set-buffer sum)
8749           (setq found 'not)
8750           (while (eq found 'not)
8751             (if (not (if backward (gnus-summary-find-prev)
8752                        (gnus-summary-find-next)))
8753                 ;; No more articles.
8754                 (setq found t)
8755               ;; Select the next article and adjust point.
8756               (unless (gnus-summary-article-sparse-p
8757                        (gnus-summary-article-number))
8758                 (setq found nil)
8759                 (gnus-summary-select-article)
8760                 (set-buffer gnus-article-buffer)
8761                 (widen)
8762                 (goto-char (if backward (point-max) (point-min))))))))
8763       (gnus-message 7 ""))
8764     ;; Return whether we found the regexp.
8765     (when (eq found 'found)
8766       (goto-char point)
8767       (gnus-summary-show-thread)
8768       (gnus-summary-goto-subject gnus-current-article)
8769       (gnus-summary-position-point)
8770       t)))
8771
8772 (defun gnus-find-matching-articles (header regexp)
8773   "Return a list of all articles that match REGEXP on HEADER.
8774 This search includes all articles in the current group that Gnus has
8775 fetched headers for, whether they are displayed or not."
8776   (let ((articles nil)
8777         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8778         (case-fold-search t))
8779     (dolist (header gnus-newsgroup-headers)
8780       (when (string-match regexp (funcall func header))
8781         (push (mail-header-number header) articles)))
8782     (nreverse articles)))
8783
8784 (defun gnus-summary-find-matching (header regexp &optional backward unread
8785                                           not-case-fold not-matching)
8786   "Return a list of all articles that match REGEXP on HEADER.
8787 The search stars on the current article and goes forwards unless
8788 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8789 If UNREAD is non-nil, only unread articles will
8790 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8791 in the comparisons. If NOT-MATCHING, return a list of all articles that
8792 not match REGEXP on HEADER."
8793   (let ((case-fold-search (not not-case-fold))
8794         articles d func)
8795     (if (consp header)
8796         (if (eq (car header) 'extra)
8797             (setq func
8798                   `(lambda (h)
8799                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8800                          "")))
8801           (error "%s is an invalid header" header))
8802       (unless (fboundp (intern (concat "mail-header-" header)))
8803         (error "%s is not a valid header" header))
8804       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8805     (dolist (d (if (eq backward 'all)
8806                    gnus-newsgroup-data
8807                  (gnus-data-find-list
8808                   (gnus-summary-article-number)
8809                   (gnus-data-list backward))))
8810       (when (and (or (not unread)       ; We want all articles...
8811                      (gnus-data-unread-p d)) ; Or just unreads.
8812                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8813                  (if not-matching
8814                      (not (string-match
8815                            regexp
8816                            (funcall func (gnus-data-header d))))
8817                    (string-match regexp
8818                                  (funcall func (gnus-data-header d)))))
8819         (push (gnus-data-number d) articles))) ; Success!
8820     (nreverse articles)))
8821
8822 (defun gnus-summary-execute-command (header regexp command &optional backward)
8823   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8824 If HEADER is an empty string (or nil), the match is done on the entire
8825 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8826   (interactive
8827    (list (let ((completion-ignore-case t))
8828            (completing-read
8829             "Header name: "
8830             (mapcar (lambda (header) (list (format "%s" header)))
8831                     (append
8832                      '("Number" "Subject" "From" "Lines" "Date"
8833                        "Message-ID" "Xref" "References" "Body")
8834                      gnus-extra-headers))
8835             nil 'require-match))
8836          (read-string "Regexp: ")
8837          (read-key-sequence "Command: ")
8838          current-prefix-arg))
8839   (when (equal header "Body")
8840     (setq header ""))
8841   ;; Hidden thread subtrees must be searched as well.
8842   (gnus-summary-show-all-threads)
8843   ;; We don't want to change current point nor window configuration.
8844   (save-excursion
8845     (save-window-excursion
8846       (let (gnus-visual
8847             gnus-treat-strip-trailing-blank-lines
8848             gnus-treat-strip-leading-blank-lines
8849             gnus-treat-strip-multiple-blank-lines
8850             gnus-treat-hide-boring-headers
8851             gnus-treat-fold-newsgroups
8852             gnus-article-prepare-hook)
8853         (gnus-message 6 "Executing %s..." (key-description command))
8854         ;; We'd like to execute COMMAND interactively so as to give arguments.
8855         (gnus-execute header regexp
8856                       `(call-interactively ',(key-binding command))
8857                       backward)
8858         (gnus-message 6 "Executing %s...done" (key-description command))))))
8859
8860 (defun gnus-summary-beginning-of-article ()
8861   "Scroll the article back to the beginning."
8862   (interactive)
8863   (gnus-summary-select-article)
8864   (gnus-configure-windows 'article)
8865   (gnus-eval-in-buffer-window gnus-article-buffer
8866     (widen)
8867     (goto-char (point-min))
8868     (when gnus-break-pages
8869       (gnus-narrow-to-page))))
8870
8871 (defun gnus-summary-end-of-article ()
8872   "Scroll to the end of the article."
8873   (interactive)
8874   (gnus-summary-select-article)
8875   (gnus-configure-windows 'article)
8876   (gnus-eval-in-buffer-window gnus-article-buffer
8877     (widen)
8878     (goto-char (point-max))
8879     (recenter -3)
8880     (when gnus-break-pages
8881       (when (re-search-backward page-delimiter nil t)
8882         (narrow-to-region (match-end 0) (point-max)))
8883       (gnus-narrow-to-page))))
8884
8885 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8886   "Truncate to LEN and quote all \"(\"'s in STRING."
8887   (gnus-replace-in-string (if (and len (> (length string) len))
8888                               (substring string 0 len)
8889                             string)
8890                           "[()]" "\\\\\\&"))
8891
8892 (defun gnus-summary-print-article (&optional filename n)
8893   "Generate and print a PostScript image of the process-marked (mail) articles.
8894
8895 If used interactively, print the current article if none are
8896 process-marked.  With prefix arg, prompt the user for the name of the
8897 file to save in.
8898
8899 When used from Lisp, accept two optional args FILENAME and N.  N means
8900 to print the next N articles.  If N is negative, print the N previous
8901 articles.  If N is nil and articles have been marked with the process
8902 mark, print these instead.
8903
8904 If the optional first argument FILENAME is nil, send the image to the
8905 printer.  If FILENAME is a string, save the PostScript image in a file with
8906 that name.  If FILENAME is a number, prompt the user for the name of the file
8907 to save in."
8908   (interactive (list (ps-print-preprint current-prefix-arg)))
8909   (dolist (article (gnus-summary-work-articles n))
8910     (gnus-summary-select-article nil nil 'pseudo article)
8911     (gnus-eval-in-buffer-window gnus-article-buffer
8912       (gnus-print-buffer))
8913     (gnus-summary-remove-process-mark article))
8914   (ps-despool filename))
8915
8916 (defun gnus-print-buffer ()
8917   (let ((buffer (generate-new-buffer " *print*")))
8918     (unwind-protect
8919         (progn
8920           (copy-to-buffer buffer (point-min) (point-max))
8921           (set-buffer buffer)
8922           (gnus-remove-text-with-property 'gnus-decoration)
8923           (when (gnus-visual-p 'article-highlight 'highlight)
8924             ;; Copy-to-buffer doesn't copy overlay.  So redo
8925             ;; highlight.
8926             (let ((gnus-article-buffer buffer))
8927               (gnus-article-highlight-citation t)
8928               (gnus-article-highlight-signature)
8929               (gnus-article-emphasize)
8930               (gnus-article-delete-invisible-text)))
8931           (let ((ps-left-header
8932                  (list
8933                   (concat "("
8934                           (gnus-summary-print-truncate-and-quote
8935                            (mail-header-subject gnus-current-headers)
8936                            66) ")")
8937                   (concat "("
8938                           (gnus-summary-print-truncate-and-quote
8939                            (mail-header-from gnus-current-headers)
8940                            45) ")")))
8941                 (ps-right-header
8942                  (list
8943                   "/pagenumberstring load"
8944                   (concat "("
8945                           (mail-header-date gnus-current-headers) ")"))))
8946             (gnus-run-hooks 'gnus-ps-print-hook)
8947             (save-excursion
8948               (if window-system
8949                   (ps-spool-buffer-with-faces)
8950                 (ps-spool-buffer)))))
8951       (kill-buffer buffer))))
8952
8953 (defun gnus-summary-show-article (&optional arg)
8954   "Force redisplaying of the current article.
8955 If ARG (the prefix) is a number, show the article with the charset
8956 defined in `gnus-summary-show-article-charset-alist', or the charset
8957 input.
8958 If ARG (the prefix) is non-nil and not a number, show the raw article
8959 without any article massaging functions being run.  Normally, the key
8960 strokes are `C-u g'."
8961   (interactive "P")
8962   (cond
8963    ((numberp arg)
8964     (gnus-summary-show-article t)
8965     (let ((gnus-newsgroup-charset
8966            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8967                (mm-read-coding-system
8968                 "View as charset: " ;; actually it is coding system.
8969                 (with-current-buffer gnus-article-buffer
8970                   (mm-detect-coding-region (point) (point-max))))))
8971           (gnus-newsgroup-ignored-charsets 'gnus-all))
8972       (gnus-summary-select-article nil 'force)
8973       (let ((deps gnus-newsgroup-dependencies)
8974             head header lines)
8975         (save-excursion
8976           (set-buffer gnus-original-article-buffer)
8977           (save-restriction
8978             (message-narrow-to-head)
8979             (setq head (buffer-string))
8980             (goto-char (point-min))
8981             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8982               (goto-char (point-max))
8983               (widen)
8984               (setq lines (1- (count-lines (point) (point-max))))))
8985           (with-temp-buffer
8986             (insert (format "211 %d Article retrieved.\n"
8987                             (cdr gnus-article-current)))
8988             (insert head)
8989             (if lines (insert (format "Lines: %d\n" lines)))
8990             (insert ".\n")
8991             (let ((nntp-server-buffer (current-buffer)))
8992               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8993         (gnus-data-set-header
8994          (gnus-data-find (cdr gnus-article-current))
8995          header)
8996         (gnus-summary-update-article-line
8997          (cdr gnus-article-current) header)
8998         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8999           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9000    ((not arg)
9001     ;; Select the article the normal way.
9002     (gnus-summary-select-article nil 'force))
9003    (t
9004     ;; We have to require this here to make sure that the following
9005     ;; dynamic binding isn't shadowed by autoloading.
9006     (require 'gnus-async)
9007     (require 'gnus-art)
9008     ;; Bind the article treatment functions to nil.
9009     (let ((gnus-have-all-headers t)
9010           gnus-article-prepare-hook
9011           gnus-article-decode-hook
9012           gnus-display-mime-function
9013           gnus-break-pages)
9014       ;; Destroy any MIME parts.
9015       (when (gnus-buffer-live-p gnus-article-buffer)
9016         (save-excursion
9017           (set-buffer gnus-article-buffer)
9018           (mm-destroy-parts gnus-article-mime-handles)
9019           ;; Set it to nil for safety reason.
9020           (setq gnus-article-mime-handle-alist nil)
9021           (setq gnus-article-mime-handles nil)))
9022       (gnus-summary-select-article nil 'force))))
9023   (gnus-summary-goto-subject gnus-current-article)
9024   (gnus-summary-position-point))
9025
9026 (defun gnus-summary-show-raw-article ()
9027   "Show the raw article without any article massaging functions being run."
9028   (interactive)
9029   (gnus-summary-show-article t))
9030
9031 (defun gnus-summary-verbose-headers (&optional arg)
9032   "Toggle permanent full header display.
9033 If ARG is a positive number, turn header display on.
9034 If ARG is a negative number, turn header display off."
9035   (interactive "P")
9036   (setq gnus-show-all-headers
9037         (cond ((or (not (numberp arg))
9038                    (zerop arg))
9039                (not gnus-show-all-headers))
9040               ((natnump arg)
9041                t)))
9042   (gnus-summary-show-article))
9043
9044 (defun gnus-summary-toggle-header (&optional arg)
9045   "Show the headers if they are hidden, or hide them if they are shown.
9046 If ARG is a positive number, show the entire header.
9047 If ARG is a negative number, hide the unwanted header lines."
9048   (interactive "P")
9049   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9050                      (get-buffer-window gnus-article-buffer t))))
9051     (with-current-buffer gnus-article-buffer
9052       (widen)
9053       (article-narrow-to-head)
9054       (let* ((buffer-read-only nil)
9055              (inhibit-point-motion-hooks t)
9056              (hidden (if (numberp arg)
9057                          (>= arg 0)
9058                        (or (not (looking-at "[^ \t\n]+:"))
9059                            (gnus-article-hidden-text-p 'headers))))
9060              s e)
9061         (delete-region (point-min) (point-max))
9062         (with-current-buffer gnus-original-article-buffer
9063           (goto-char (setq s (point-min)))
9064           (setq e (if (search-forward "\n\n" nil t)
9065                       (1- (point))
9066                     (point-max))))
9067         (insert-buffer-substring gnus-original-article-buffer s e)
9068         (run-hooks 'gnus-article-decode-hook)
9069         (if hidden
9070             (let ((gnus-treat-hide-headers nil)
9071                   (gnus-treat-hide-boring-headers nil))
9072               (gnus-delete-wash-type 'headers)
9073               (gnus-treat-article 'head))
9074           (gnus-treat-article 'head))
9075         (widen)
9076         (if window
9077             (set-window-start window (goto-char (point-min))))
9078         (if gnus-break-pages
9079             (gnus-narrow-to-page)
9080           (when (gnus-visual-p 'page-marker)
9081             (let ((buffer-read-only nil))
9082               (gnus-remove-text-with-property 'gnus-prev)
9083               (gnus-remove-text-with-property 'gnus-next))))
9084         (gnus-set-mode-line 'article)))))
9085
9086 (defun gnus-summary-show-all-headers ()
9087   "Make all header lines visible."
9088   (interactive)
9089   (gnus-summary-toggle-header 1))
9090
9091 (defun gnus-summary-caesar-message (&optional arg)
9092   "Caesar rotate the current article by 13.
9093 The numerical prefix specifies how many places to rotate each letter
9094 forward."
9095   (interactive "P")
9096   (gnus-summary-select-article)
9097   (let ((mail-header-separator ""))
9098     (gnus-eval-in-buffer-window gnus-article-buffer
9099       (save-restriction
9100         (widen)
9101         (let ((start (window-start))
9102               buffer-read-only)
9103           (message-caesar-buffer-body arg)
9104           (set-window-start (get-buffer-window (current-buffer)) start)))))
9105   ;; Create buttons and stuff...
9106   (gnus-treat-article nil))
9107
9108 (defun gnus-summary-idna-message (&optional arg)
9109   "Decode IDNA encoded domain names in the current articles.
9110 IDNA encoded domain names looks like `xn--bar'.  If a string
9111 remain unencoded after running this function, it is likely an
9112 invalid IDNA string (`xn--bar' is invalid).
9113
9114 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9115 installed for this command to work."
9116   (interactive "P")
9117   (if (not (and (condition-case nil (require 'idna)
9118                   (file-error))
9119                 (mm-coding-system-p 'utf-8)
9120                 (executable-find (symbol-value 'idna-program))))
9121       (gnus-message
9122        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9123     (gnus-summary-select-article)
9124     (let ((mail-header-separator ""))
9125       (gnus-eval-in-buffer-window gnus-article-buffer
9126         (save-restriction
9127           (widen)
9128           (let ((start (window-start))
9129                 buffer-read-only)
9130             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9131               (replace-match (idna-to-unicode (match-string 1))))
9132             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9133
9134 (autoload 'unmorse-region "morse"
9135   "Convert morse coded text in region to ordinary ASCII text."
9136   t)
9137
9138 (defun gnus-summary-morse-message (&optional arg)
9139   "Morse decode the current article."
9140   (interactive "P")
9141   (gnus-summary-select-article)
9142   (let ((mail-header-separator ""))
9143     (gnus-eval-in-buffer-window gnus-article-buffer
9144       (save-excursion
9145         (save-restriction
9146           (widen)
9147           (let ((pos (window-start))
9148                 buffer-read-only)
9149             (goto-char (point-min))
9150             (when (message-goto-body)
9151               (gnus-narrow-to-body))
9152             (goto-char (point-min))
9153             (while (search-forward "·" (point-max) t)
9154               (replace-match "."))
9155             (unmorse-region (point-min) (point-max))
9156             (widen)
9157             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9158
9159 (defun gnus-summary-stop-page-breaking ()
9160   "Stop page breaking in the current article."
9161   (interactive)
9162   (gnus-summary-select-article)
9163   (gnus-eval-in-buffer-window gnus-article-buffer
9164     (widen)
9165     (when (gnus-visual-p 'page-marker)
9166       (let ((buffer-read-only nil))
9167         (gnus-remove-text-with-property 'gnus-prev)
9168         (gnus-remove-text-with-property 'gnus-next))
9169       (setq gnus-page-broken nil))))
9170
9171 (defun gnus-summary-move-article (&optional n to-newsgroup
9172                                             select-method action)
9173   "Move the current article to a different newsgroup.
9174 If N is a positive number, move the N next articles.
9175 If N is a negative number, move the N previous articles.
9176 If N is nil and any articles have been marked with the process mark,
9177 move those articles instead.
9178 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9179 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9180 re-spool using this method.
9181
9182 When called interactively with TO-NEWSGROUP being nil, the value of
9183 the variable `gnus-move-split-methods' is used for finding a default
9184 for the target newsgroup.
9185
9186 For this function to work, both the current newsgroup and the
9187 newsgroup that you want to move to have to support the `request-move'
9188 and `request-accept' functions.
9189
9190 ACTION can be either `move' (the default), `crosspost' or `copy'."
9191   (interactive "P")
9192   (unless action
9193     (setq action 'move))
9194   ;; Check whether the source group supports the required functions.
9195   (cond ((and (eq action 'move)
9196               (not (gnus-check-backend-function
9197                     'request-move-article gnus-newsgroup-name)))
9198          (error "The current group does not support article moving"))
9199         ((and (eq action 'crosspost)
9200               (not (gnus-check-backend-function
9201                     'request-replace-article gnus-newsgroup-name)))
9202          (error "The current group does not support article editing")))
9203   (let ((articles (gnus-summary-work-articles n))
9204         (prefix (if (gnus-check-backend-function
9205                      'request-move-article gnus-newsgroup-name)
9206                     (funcall gnus-move-group-prefix-function
9207                              gnus-newsgroup-name)
9208                   ""))
9209         (names '((move "Move" "Moving")
9210                  (copy "Copy" "Copying")
9211                  (crosspost "Crosspost" "Crossposting")))
9212         (copy-buf (save-excursion
9213                     (nnheader-set-temp-buffer " *copy article*")))
9214         art-group to-method new-xref article to-groups articles-to-update-marks)
9215     (unless (assq action names)
9216       (error "Unknown action %s" action))
9217     ;; Read the newsgroup name.
9218     (when (and (not to-newsgroup)
9219                (not select-method))
9220       (if (and gnus-move-split-methods
9221                (not
9222                 (and (memq gnus-current-article articles)
9223                      (gnus-buffer-live-p gnus-original-article-buffer))))
9224           ;; When `gnus-move-split-methods' is non-nil, we have to
9225           ;; select an article to give `gnus-read-move-group-name' an
9226           ;; opportunity to suggest an appropriate default.  However,
9227           ;; we needn't render or mark the article.
9228           (let ((gnus-display-mime-function nil)
9229                 (gnus-article-prepare-hook nil)
9230                 (gnus-mark-article-hook nil))
9231             (gnus-summary-select-article nil nil nil (car articles))))
9232       (setq to-newsgroup
9233             (gnus-read-move-group-name
9234              (cadr (assq action names))
9235              (symbol-value (intern (format "gnus-current-%s-group" action)))
9236              articles prefix))
9237       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9238     (setq to-method (or select-method
9239                         (gnus-server-to-method
9240                          (gnus-group-method to-newsgroup))))
9241     ;; Check the method we are to move this article to...
9242     (unless (gnus-check-backend-function
9243              'request-accept-article (car to-method))
9244       (error "%s does not support article copying" (car to-method)))
9245     (unless (gnus-check-server to-method)
9246       (error "Can't open server %s" (car to-method)))
9247     (gnus-message 6 "%s to %s: %s..."
9248                   (caddr (assq action names))
9249                   (or (car select-method) to-newsgroup) articles)
9250     (while articles
9251       (setq article (pop articles))
9252       (setq
9253        art-group
9254        (cond
9255         ;; Move the article.
9256         ((eq action 'move)
9257          ;; Remove this article from future suppression.
9258          (gnus-dup-unsuppress-article article)
9259          (let* ((from-method (gnus-find-method-for-group
9260                               gnus-newsgroup-name))
9261                 (to-method (gnus-find-method-for-group
9262                             to-newsgroup))
9263                 (move-is-internal (gnus-method-equal from-method to-method)))
9264          (gnus-request-move-article
9265           article                       ; Article to move
9266           gnus-newsgroup-name           ; From newsgroup
9267           (nth 1 (gnus-find-method-for-group
9268                   gnus-newsgroup-name)) ; Server
9269           (list 'gnus-request-accept-article
9270                 to-newsgroup (list 'quote select-method)
9271                 (not articles) t)       ; Accept form
9272           (not articles)                ; Only save nov last time
9273           move-is-internal)))           ; is this move internal?
9274         ;; Copy the article.
9275         ((eq action 'copy)
9276          (save-excursion
9277            (set-buffer copy-buf)
9278            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9279              (save-restriction
9280                (nnheader-narrow-to-headers)
9281                (dolist (hdr gnus-copy-article-ignored-headers)
9282                  (message-remove-header hdr t)))
9283              (gnus-request-accept-article
9284               to-newsgroup select-method (not articles) t))))
9285         ;; Crosspost the article.
9286         ((eq action 'crosspost)
9287          (let ((xref (message-tokenize-header
9288                       (mail-header-xref (gnus-summary-article-header article))
9289                       " ")))
9290            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9291                                   ":" (number-to-string article)))
9292            (unless xref
9293              (setq xref (list (system-name))))
9294            (setq new-xref
9295                  (concat
9296                   (mapconcat 'identity
9297                              (delete "Xref:" (delete new-xref xref))
9298                              " ")
9299                   " " new-xref))
9300            (save-excursion
9301              (set-buffer copy-buf)
9302              ;; First put the article in the destination group.
9303              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9304              (when (consp (setq art-group
9305                                 (gnus-request-accept-article
9306                                  to-newsgroup select-method (not articles))))
9307                (setq new-xref (concat new-xref " " (car art-group)
9308                                       ":"
9309                                       (number-to-string (cdr art-group))))
9310                ;; Now we have the new Xrefs header, so we insert
9311                ;; it and replace the new article.
9312                (nnheader-replace-header "Xref" new-xref)
9313                (gnus-request-replace-article
9314                 (cdr art-group) to-newsgroup (current-buffer))
9315                art-group))))))
9316       (cond
9317        ((not art-group)
9318         (gnus-message 1 "Couldn't %s article %s: %s"
9319                       (cadr (assq action names)) article
9320                       (nnheader-get-report (car to-method))))
9321        ((eq art-group 'junk)
9322         (when (eq action 'move)
9323           (gnus-summary-mark-article article gnus-canceled-mark)
9324           (gnus-message 4 "Deleted article %s" article)
9325           ;; run the delete hook
9326           (run-hook-with-args 'gnus-summary-article-delete-hook
9327                               action
9328                               (gnus-data-header
9329                                (assoc article (gnus-data-list nil)))
9330                               gnus-newsgroup-name nil
9331                               select-method)))
9332        (t
9333         (let* ((pto-group (gnus-group-prefixed-name
9334                            (car art-group) to-method))
9335                (info (gnus-get-info pto-group))
9336                (to-group (gnus-info-group info))
9337                to-marks)
9338           ;; Update the group that has been moved to.
9339           (when (and info
9340                      (memq action '(move copy)))
9341             (unless (member to-group to-groups)
9342               (push to-group to-groups))
9343
9344             (unless (memq article gnus-newsgroup-unreads)
9345               (push 'read to-marks)
9346               (gnus-info-set-read
9347                info (gnus-add-to-range (gnus-info-read info)
9348                                        (list (cdr art-group)))))
9349
9350             ;; See whether the article is to be put in the cache.
9351             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9352                              gnus-article-mark-lists
9353                            (delete '(expirable . expire)
9354                                    (copy-sequence gnus-article-mark-lists))))
9355                   (to-article (cdr art-group)))
9356
9357               ;; Enter the article into the cache in the new group,
9358               ;; if that is required.
9359               (when gnus-use-cache
9360                 (gnus-cache-possibly-enter-article
9361                  to-group to-article
9362                  (memq article gnus-newsgroup-marked)
9363                  (memq article gnus-newsgroup-dormant)
9364                  (memq article gnus-newsgroup-unreads)))
9365
9366               (when gnus-preserve-marks
9367                 ;; Copy any marks over to the new group.
9368                 (when (and (equal to-group gnus-newsgroup-name)
9369                            (not (memq article gnus-newsgroup-unreads)))
9370                   ;; Mark this article as read in this group.
9371                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9372                   (setcdr (gnus-active to-group) to-article)
9373                   (setcdr gnus-newsgroup-active to-article))
9374
9375                 (while marks
9376                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9377                     (when (memq article (symbol-value
9378                                          (intern (format "gnus-newsgroup-%s"
9379                                                          (caar marks)))))
9380                       (push (cdar marks) to-marks)
9381                       ;; If the other group is the same as this group,
9382                       ;; then we have to add the mark to the list.
9383                       (when (equal to-group gnus-newsgroup-name)
9384                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9385                              (cons to-article
9386                                    (symbol-value
9387                                     (intern (format "gnus-newsgroup-%s"
9388                                                     (caar marks)))))))
9389                       ;; Copy the marks to other group.
9390                       (gnus-add-marked-articles
9391                        to-group (cdar marks) (list to-article) info)))
9392                   (setq marks (cdr marks)))
9393
9394                 (gnus-request-set-mark
9395                  to-group (list (list (list to-article) 'add to-marks))))
9396
9397               (gnus-dribble-enter
9398                (concat "(gnus-group-set-info '"
9399                        (gnus-prin1-to-string (gnus-get-info to-group))
9400                        ")"))))
9401
9402           ;; Update the Xref header in this article to point to
9403           ;; the new crossposted article we have just created.
9404           (when (eq action 'crosspost)
9405             (save-excursion
9406               (set-buffer copy-buf)
9407               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9408               (nnheader-replace-header "Xref" new-xref)
9409               (gnus-request-replace-article
9410                article gnus-newsgroup-name (current-buffer))))
9411
9412           ;; run the move/copy/crosspost/respool hook
9413           (run-hook-with-args 'gnus-summary-article-move-hook
9414                               action
9415                               (gnus-data-header
9416                                (assoc article (gnus-data-list nil)))
9417                               gnus-newsgroup-name
9418                               to-newsgroup
9419                               select-method))
9420
9421         ;;;!!!Why is this necessary?
9422         (set-buffer gnus-summary-buffer)
9423         
9424         (gnus-summary-goto-subject article)
9425         (when (eq action 'move)
9426           (gnus-summary-mark-article article gnus-canceled-mark))))
9427       (push article articles-to-update-marks))
9428
9429     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9430     ;; Re-activate all groups that have been moved to.
9431     (save-excursion
9432       (set-buffer gnus-group-buffer)
9433       (let ((gnus-group-marked to-groups))
9434         (gnus-group-get-new-news-this-group nil t)))
9435     
9436     (gnus-kill-buffer copy-buf)
9437     (gnus-summary-position-point)
9438     (gnus-set-mode-line 'summary)))
9439
9440 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9441   "Copy the current article to some other group.
9442 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9443 When called interactively, if TO-NEWSGROUP is nil, use the value of
9444 the variable `gnus-move-split-methods' for finding a default target
9445 newsgroup.
9446 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9447 re-spool using this method."
9448   (interactive "P")
9449   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9450
9451 (defun gnus-summary-crosspost-article (&optional n)
9452   "Crosspost the current article to some other group."
9453   (interactive "P")
9454   (gnus-summary-move-article n nil nil 'crosspost))
9455
9456 (defcustom gnus-summary-respool-default-method nil
9457   "Default method type for respooling an article.
9458 If nil, use to the current newsgroup method."
9459   :type 'symbol
9460   :group 'gnus-summary-mail)
9461
9462 (defcustom gnus-summary-display-while-building nil
9463   "If non-nil, show and update the summary buffer as it's being built.
9464 If the value is t, update the buffer after every line is inserted.  If
9465 the value is an integer (N), update the display every N lines."
9466   :version "22.1"
9467   :group 'gnus-thread
9468   :type '(choice (const :tag "off" nil)
9469                  number
9470                  (const :tag "frequently" t)))
9471
9472 (defun gnus-summary-respool-article (&optional n method)
9473   "Respool the current article.
9474 The article will be squeezed through the mail spooling process again,
9475 which means that it will be put in some mail newsgroup or other
9476 depending on `nnmail-split-methods'.
9477 If N is a positive number, respool the N next articles.
9478 If N is a negative number, respool the N previous articles.
9479 If N is nil and any articles have been marked with the process mark,
9480 respool those articles instead.
9481
9482 Respooling can be done both from mail groups and \"real\" newsgroups.
9483 In the former case, the articles in question will be moved from the
9484 current group into whatever groups they are destined to.  In the
9485 latter case, they will be copied into the relevant groups."
9486   (interactive
9487    (list current-prefix-arg
9488          (let* ((methods (gnus-methods-using 'respool))
9489                 (methname
9490                  (symbol-name (or gnus-summary-respool-default-method
9491                                   (car (gnus-find-method-for-group
9492                                         gnus-newsgroup-name)))))
9493                 (method
9494                  (gnus-completing-read-with-default
9495                   methname "Backend to use when respooling"
9496                   methods nil t nil 'gnus-mail-method-history))
9497                 ms)
9498            (cond
9499             ((zerop (length (setq ms (gnus-servers-using-backend
9500                                       (intern method)))))
9501              (list (intern method) ""))
9502             ((= 1 (length ms))
9503              (car ms))
9504             (t
9505              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9506                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9507                            ms-alist))))))))
9508   (unless method
9509     (error "No method given for respooling"))
9510   (if (assoc (symbol-name
9511               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9512              (gnus-methods-using 'respool))
9513       (gnus-summary-move-article n nil method)
9514     (gnus-summary-copy-article n nil method)))
9515
9516 (defun gnus-summary-import-article (file &optional edit)
9517   "Import an arbitrary file into a mail newsgroup."
9518   (interactive "fImport file: \nP")
9519   (let ((group gnus-newsgroup-name)
9520         (now (current-time))
9521         atts lines group-art)
9522     (unless (gnus-check-backend-function 'request-accept-article group)
9523       (error "%s does not support article importing" group))
9524     (or (file-readable-p file)
9525         (not (file-regular-p file))
9526         (error "Can't read %s" file))
9527     (save-excursion
9528       (set-buffer (gnus-get-buffer-create " *import file*"))
9529       (erase-buffer)
9530       (nnheader-insert-file-contents file)
9531       (goto-char (point-min))
9532       (if (nnheader-article-p)
9533           (save-restriction
9534             (goto-char (point-min))
9535             (search-forward "\n\n" nil t)
9536             (narrow-to-region (point-min) (1- (point)))
9537             (goto-char (point-min))
9538             (unless (re-search-forward "^date:" nil t)
9539               (goto-char (point-max))
9540               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9541        ;; This doesn't look like an article, so we fudge some headers.
9542         (setq atts (file-attributes file)
9543               lines (count-lines (point-min) (point-max)))
9544         (insert "From: " (read-string "From: ") "\n"
9545                 "Subject: " (read-string "Subject: ") "\n"
9546                 "Date: " (message-make-date (nth 5 atts)) "\n"
9547                 "Message-ID: " (message-make-message-id) "\n"
9548                 "Lines: " (int-to-string lines) "\n"
9549                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9550       (setq group-art (gnus-request-accept-article group nil t))
9551       (kill-buffer (current-buffer)))
9552     (setq gnus-newsgroup-active (gnus-activate-group group))
9553     (forward-line 1)
9554     (gnus-summary-goto-article (cdr group-art) nil t)
9555     (when edit
9556       (gnus-summary-edit-article))))
9557
9558 (defun gnus-summary-create-article ()
9559   "Create an article in a mail newsgroup."
9560   (interactive)
9561   (let ((group gnus-newsgroup-name)
9562         (now (current-time))
9563         group-art)
9564     (unless (gnus-check-backend-function 'request-accept-article group)
9565       (error "%s does not support article importing" group))
9566     (save-excursion
9567       (set-buffer (gnus-get-buffer-create " *import file*"))
9568       (erase-buffer)
9569       (goto-char (point-min))
9570       ;; This doesn't look like an article, so we fudge some headers.
9571       (insert "From: " (read-string "From: ") "\n"
9572               "Subject: " (read-string "Subject: ") "\n"
9573               "Date: " (message-make-date now) "\n"
9574               "Message-ID: " (message-make-message-id) "\n")
9575       (setq group-art (gnus-request-accept-article group nil t))
9576       (kill-buffer (current-buffer)))
9577     (setq gnus-newsgroup-active (gnus-activate-group group))
9578     (forward-line 1)
9579     (gnus-summary-goto-article (cdr group-art) nil t)
9580     (gnus-summary-edit-article)))
9581
9582 (defun gnus-summary-article-posted-p ()
9583   "Say whether the current (mail) article is available from news as well.
9584 This will be the case if the article has both been mailed and posted."
9585   (interactive)
9586   (let ((id (mail-header-references (gnus-summary-article-header)))
9587         (gnus-override-method (car (gnus-refer-article-methods))))
9588     (if (gnus-request-head id "")
9589         (gnus-message 2 "The current message was found on %s"
9590                       gnus-override-method)
9591       (gnus-message 2 "The current message couldn't be found on %s"
9592                     gnus-override-method)
9593       nil)))
9594
9595 (defun gnus-summary-expire-articles (&optional now)
9596   "Expire all articles that are marked as expirable in the current group."
9597   (interactive)
9598   (when (and (not gnus-group-is-exiting-without-update-p)
9599              (gnus-check-backend-function
9600               'request-expire-articles gnus-newsgroup-name))
9601     ;; This backend supports expiry.
9602     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9603            (expirable (if total
9604                           (progn
9605                             ;; We need to update the info for
9606                             ;; this group for `gnus-list-of-read-articles'
9607                             ;; to give us the right answer.
9608                             (gnus-run-hooks 'gnus-exit-group-hook)
9609                             (gnus-summary-update-info)
9610                             (gnus-list-of-read-articles gnus-newsgroup-name))
9611                         (setq gnus-newsgroup-expirable
9612                               (sort gnus-newsgroup-expirable '<))))
9613            (expiry-wait (if now 'immediate
9614                           (gnus-group-find-parameter
9615                            gnus-newsgroup-name 'expiry-wait)))
9616            (nnmail-expiry-target
9617             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9618                 nnmail-expiry-target))
9619            es)
9620       (when expirable
9621         ;; There are expirable articles in this group, so we run them
9622         ;; through the expiry process.
9623         (gnus-message 6 "Expiring articles...")
9624         (unless (gnus-check-group gnus-newsgroup-name)
9625           (error "Can't open server for %s" gnus-newsgroup-name))
9626         ;; The list of articles that weren't expired is returned.
9627         (save-excursion
9628           (if expiry-wait
9629               (let ((nnmail-expiry-wait-function nil)
9630                     (nnmail-expiry-wait expiry-wait))
9631                 (setq es (gnus-request-expire-articles
9632                           expirable gnus-newsgroup-name)))
9633             (setq es (gnus-request-expire-articles
9634                       expirable gnus-newsgroup-name)))
9635           (unless total
9636             (setq gnus-newsgroup-expirable es))
9637           ;; We go through the old list of expirable, and mark all
9638           ;; really expired articles as nonexistent.
9639           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9640             (let ((gnus-use-cache nil))
9641               (dolist (article expirable)
9642                 (when (and (not (memq article es))
9643                            (gnus-data-find article))
9644                   (gnus-summary-mark-article article gnus-canceled-mark)
9645                   (run-hook-with-args 'gnus-summary-article-expire-hook
9646                                       'delete
9647                                       (gnus-data-header
9648                                        (assoc article (gnus-data-list nil)))
9649                                       gnus-newsgroup-name
9650                                       nil
9651                                       nil))))))
9652         (gnus-message 6 "Expiring articles...done")))))
9653
9654 (defun gnus-summary-expire-articles-now ()
9655   "Expunge all expirable articles in the current group.
9656 This means that *all* articles that are marked as expirable will be
9657 deleted forever, right now."
9658   (interactive)
9659   (or gnus-expert-user
9660       (gnus-yes-or-no-p
9661        "Are you really, really, really sure you want to delete all these messages? ")
9662       (error "Phew!"))
9663   (gnus-summary-expire-articles t))
9664
9665 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9666 (defun gnus-summary-delete-article (&optional n)
9667   "Delete the N next (mail) articles.
9668 This command actually deletes articles.  This is not a marking
9669 command.  The article will disappear forever from your life, never to
9670 return.
9671
9672 If N is negative, delete backwards.
9673 If N is nil and articles have been marked with the process mark,
9674 delete these instead.
9675
9676 If `gnus-novice-user' is non-nil you will be asked for
9677 confirmation before the articles are deleted."
9678   (interactive "P")
9679   (unless (gnus-check-backend-function 'request-expire-articles
9680                                        gnus-newsgroup-name)
9681     (error "The current newsgroup does not support article deletion"))
9682   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9683     (error "Couldn't open server"))
9684   ;; Compute the list of articles to delete.
9685   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9686         (nnmail-expiry-target 'delete)
9687         not-deleted)
9688     (if (and gnus-novice-user
9689              (not (gnus-yes-or-no-p
9690                    (format "Do you really want to delete %s forever? "
9691                            (if (> (length articles) 1)
9692                                (format "these %s articles" (length articles))
9693                              "this article")))))
9694         ()
9695       ;; Delete the articles.
9696       (setq not-deleted (gnus-request-expire-articles
9697                          articles gnus-newsgroup-name 'force))
9698       (while articles
9699         (gnus-summary-remove-process-mark (car articles))
9700         ;; The backend might not have been able to delete the article
9701         ;; after all.
9702         (unless (memq (car articles) not-deleted)
9703           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9704         (let* ((article (car articles))
9705                (ghead  (gnus-data-header
9706                                     (assoc article (gnus-data-list nil)))))
9707           (run-hook-with-args 'gnus-summary-article-delete-hook
9708                               'delete ghead gnus-newsgroup-name nil
9709                               nil))
9710         (setq articles (cdr articles)))
9711       (when not-deleted
9712         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9713     (gnus-summary-position-point)
9714     (gnus-set-mode-line 'summary)
9715     not-deleted))
9716
9717 (defun gnus-summary-edit-article (&optional arg)
9718   "Edit the current article.
9719 This will have permanent effect only in mail groups.
9720 If ARG is nil, edit the decoded articles.
9721 If ARG is 1, edit the raw articles.
9722 If ARG is 2, edit the raw articles even in read-only groups.
9723 If ARG is 3, edit the articles with the current handles.
9724 Otherwise, allow editing of articles even in read-only
9725 groups."
9726   (interactive "P")
9727   (let (force raw current-handles)
9728     (cond
9729      ((null arg))
9730      ((eq arg 1)
9731       (setq raw t))
9732      ((eq arg 2)
9733       (setq raw t
9734             force t))
9735      ((eq arg 3)
9736       (setq current-handles
9737             (and (gnus-buffer-live-p gnus-article-buffer)
9738                  (with-current-buffer gnus-article-buffer
9739                    (prog1
9740                        gnus-article-mime-handles
9741                      (setq gnus-article-mime-handles nil))))))
9742      (t
9743       (setq force t)))
9744     (when (and raw (not force)
9745                (member gnus-newsgroup-name '("nndraft:delayed"
9746                                              "nndraft:drafts"
9747                                              "nndraft:queue")))
9748       (error "Can't edit the raw article in group %s"
9749              gnus-newsgroup-name))
9750     (save-excursion
9751       (set-buffer gnus-summary-buffer)
9752       (let ((mail-parse-charset gnus-newsgroup-charset)
9753             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9754         (gnus-set-global-variables)
9755         (when (and (not force)
9756                    (gnus-group-read-only-p))
9757           (error "The current newsgroup does not support article editing"))
9758         (gnus-summary-show-article t)
9759         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9760           (with-current-buffer gnus-article-buffer
9761             (mm-enable-multibyte)))
9762         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9763             (setq raw t))
9764         (gnus-article-edit-article
9765          (if raw 'ignore
9766            `(lambda ()
9767               (let ((mbl mml-buffer-list))
9768                 (setq mml-buffer-list nil)
9769                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9770                   (mime-to-mml ,'current-handles))
9771                 (let ((mbl1 mml-buffer-list))
9772                   (setq mml-buffer-list mbl)
9773                   (set (make-local-variable 'mml-buffer-list) mbl1))
9774                 (gnus-make-local-hook 'kill-buffer-hook)
9775                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9776          `(lambda (no-highlight)
9777             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9778                   (message-options message-options)
9779                   (message-options-set-recipient)
9780                   (mail-parse-ignored-charsets
9781                    ',gnus-newsgroup-ignored-charsets))
9782               ,(if (not raw) '(progn
9783                                 (mml-to-mime)
9784                                 (mml-destroy-buffers)
9785                                 (remove-hook 'kill-buffer-hook
9786                                              'mml-destroy-buffers t)
9787                                 (kill-local-variable 'mml-buffer-list)))
9788               (gnus-summary-edit-article-done
9789                ,(or (mail-header-references gnus-current-headers) "")
9790                ,(gnus-group-read-only-p)
9791                ,gnus-summary-buffer no-highlight))))))))
9792
9793 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9794
9795 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9796                                                  no-highlight)
9797   "Make edits to the current article permanent."
9798   (interactive)
9799   (save-excursion
9800    ;; The buffer restriction contains the entire article if it exists.
9801     (when (article-goto-body)
9802       (let ((lines (count-lines (point) (point-max)))
9803             (length (- (point-max) (point)))
9804             (case-fold-search t)
9805             (body (copy-marker (point))))
9806         (goto-char (point-min))
9807         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9808           (delete-region (match-beginning 1) (match-end 1))
9809           (insert (number-to-string length)))
9810         (goto-char (point-min))
9811         (when (re-search-forward
9812                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9813           (delete-region (match-beginning 1) (match-end 1))
9814           (insert (number-to-string length)))
9815         (goto-char (point-min))
9816         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9817           (delete-region (match-beginning 1) (match-end 1))
9818           (insert (number-to-string lines))))))
9819   ;; Replace the article.
9820   (let ((buf (current-buffer)))
9821     (with-temp-buffer
9822       (insert-buffer-substring buf)
9823
9824       (if (and (not read-only)
9825                (not (gnus-request-replace-article
9826                      (cdr gnus-article-current) (car gnus-article-current)
9827                      (current-buffer) t)))
9828           (error "Couldn't replace article")
9829         ;; Update the summary buffer.
9830         (if (and references
9831                  (equal (message-tokenize-header references " ")
9832                         (message-tokenize-header
9833                          (or (message-fetch-field "references") "") " ")))
9834             ;; We only have to update this line.
9835             (save-excursion
9836               (save-restriction
9837                 (message-narrow-to-head)
9838                 (let ((head (buffer-substring-no-properties
9839                              (point-min) (point-max)))
9840                       header)
9841                   (with-temp-buffer
9842                     (insert (format "211 %d Article retrieved.\n"
9843                                     (cdr gnus-article-current)))
9844                     (insert head)
9845                     (insert ".\n")
9846                     (let ((nntp-server-buffer (current-buffer)))
9847                       (setq header (car (gnus-get-newsgroup-headers
9848                                          nil t))))
9849                     (save-excursion
9850                       (set-buffer gnus-summary-buffer)
9851                       (gnus-data-set-header
9852                        (gnus-data-find (cdr gnus-article-current))
9853                        header)
9854                       (gnus-summary-update-article-line
9855                        (cdr gnus-article-current) header)
9856                       (if (gnus-summary-goto-subject
9857                            (cdr gnus-article-current) nil t)
9858                           (gnus-summary-update-secondary-mark
9859                            (cdr gnus-article-current))))))))
9860           ;; Update threads.
9861           (set-buffer (or buffer gnus-summary-buffer))
9862           (gnus-summary-update-article (cdr gnus-article-current))
9863           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9864               (gnus-summary-update-secondary-mark
9865                (cdr gnus-article-current))))
9866         ;; Prettify the article buffer again.
9867         (unless no-highlight
9868           (save-excursion
9869             (set-buffer gnus-article-buffer)
9870             ;;;!!! Fix this -- article should be rehighlighted.
9871             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9872             (set-buffer gnus-original-article-buffer)
9873             (gnus-request-article
9874              (cdr gnus-article-current)
9875              (car gnus-article-current) (current-buffer))))
9876         ;; Prettify the summary buffer line.
9877         (when (gnus-visual-p 'summary-highlight 'highlight)
9878           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9879
9880 (defun gnus-summary-edit-wash (key)
9881   "Perform editing command KEY in the article buffer."
9882   (interactive
9883    (list
9884     (progn
9885       (message "%s" (concat (this-command-keys) "- "))
9886       (read-char))))
9887   (message "")
9888   (gnus-summary-edit-article)
9889   (execute-kbd-macro (concat (this-command-keys) key))
9890   (gnus-article-edit-done))
9891
9892 ;;; Respooling
9893
9894 (defun gnus-summary-respool-query (&optional silent trace)
9895   "Query where the respool algorithm would put this article."
9896   (interactive)
9897   (let (gnus-mark-article-hook)
9898     (gnus-summary-select-article)
9899     (save-excursion
9900       (set-buffer gnus-original-article-buffer)
9901       (let ((groups (nnmail-article-group 'identity trace)))
9902         (unless silent
9903           (if groups
9904               (message "This message would go to %s"
9905                        (mapconcat 'car groups ", "))
9906             (message "This message would go to no groups"))
9907           groups)))))
9908
9909 (defun gnus-summary-respool-trace ()
9910   "Trace where the respool algorithm would put this article.
9911 Display a buffer showing all fancy splitting patterns which matched."
9912   (interactive)
9913   (gnus-summary-respool-query nil t))
9914
9915 ;; Summary marking commands.
9916
9917 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9918   "Mark articles which has the same subject as read, and then select the next.
9919 If UNMARK is positive, remove any kind of mark.
9920 If UNMARK is negative, tick articles."
9921   (interactive "P")
9922   (when unmark
9923     (setq unmark (prefix-numeric-value unmark)))
9924   (let ((count
9925          (gnus-summary-mark-same-subject
9926           (gnus-summary-article-subject) unmark)))
9927     ;; Select next unread article.  If auto-select-same mode, should
9928     ;; select the first unread article.
9929     (gnus-summary-next-article t (and gnus-auto-select-same
9930                                       (gnus-summary-article-subject)))
9931     (gnus-message 7 "%d article%s marked as %s"
9932                   count (if (= count 1) " is" "s are")
9933                   (if unmark "unread" "read"))))
9934
9935 (defun gnus-summary-kill-same-subject (&optional unmark)
9936   "Mark articles which has the same subject as read.
9937 If UNMARK is positive, remove any kind of mark.
9938 If UNMARK is negative, tick articles."
9939   (interactive "P")
9940   (when unmark
9941     (setq unmark (prefix-numeric-value unmark)))
9942   (let ((count
9943          (gnus-summary-mark-same-subject
9944           (gnus-summary-article-subject) unmark)))
9945     ;; If marked as read, go to next unread subject.
9946     (when (null unmark)
9947       ;; Go to next unread subject.
9948       (gnus-summary-next-subject 1 t))
9949     (gnus-message 7 "%d articles are marked as %s"
9950                   count (if unmark "unread" "read"))))
9951
9952 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9953   "Mark articles with same SUBJECT as read, and return marked number.
9954 If optional argument UNMARK is positive, remove any kinds of marks.
9955 If optional argument UNMARK is negative, mark articles as unread instead."
9956   (let ((count 1))
9957     (save-excursion
9958       (cond
9959        ((null unmark)                   ; Mark as read.
9960         (while (and
9961                 (progn
9962                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9963                   (gnus-summary-show-thread) t)
9964                 (gnus-summary-find-subject subject))
9965           (setq count (1+ count))))
9966        ((> unmark 0)                    ; Tick.
9967         (while (and
9968                 (progn
9969                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9970                   (gnus-summary-show-thread) t)
9971                 (gnus-summary-find-subject subject))
9972           (setq count (1+ count))))
9973        (t                               ; Mark as unread.
9974         (while (and
9975                 (progn
9976                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9977                   (gnus-summary-show-thread) t)
9978                 (gnus-summary-find-subject subject))
9979           (setq count (1+ count)))))
9980       (gnus-set-mode-line 'summary)
9981       ;; Return the number of marked articles.
9982       count)))
9983
9984 (defun gnus-summary-mark-as-processable (n &optional unmark)
9985   "Set the process mark on the next N articles.
9986 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9987 the process mark instead.  The difference between N and the actual
9988 number of articles marked is returned."
9989   (interactive "P")
9990   (if (and (null n) (gnus-region-active-p))
9991       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9992     (setq n (prefix-numeric-value n))
9993     (let ((backward (< n 0))
9994           (n (abs n)))
9995       (while (and
9996               (> n 0)
9997               (if unmark
9998                   (gnus-summary-remove-process-mark
9999                    (gnus-summary-article-number))
10000                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10001               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10002         (setq n (1- n)))
10003       (when (/= 0 n)
10004         (gnus-message 7 "No more articles"))
10005       (gnus-summary-recenter)
10006       (gnus-summary-position-point)
10007       n)))
10008
10009 (defun gnus-summary-unmark-as-processable (n)
10010   "Remove the process mark from the next N articles.
10011 If N is negative, unmark backward instead.  The difference between N and
10012 the actual number of articles unmarked is returned."
10013   (interactive "P")
10014   (gnus-summary-mark-as-processable n t))
10015
10016 (defun gnus-summary-unmark-all-processable ()
10017   "Remove the process mark from all articles."
10018   (interactive)
10019   (save-excursion
10020     (while gnus-newsgroup-processable
10021       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10022   (gnus-summary-position-point))
10023
10024 (defun gnus-summary-add-mark (article type)
10025   "Mark ARTICLE with a mark of TYPE."
10026   (let ((vtype (car (assq type gnus-article-mark-lists)))
10027         var)
10028     (if (not vtype)
10029         (error "No such mark type: %s" type)
10030       (setq var (intern (format "gnus-newsgroup-%s" type)))
10031       (set var (cons article (symbol-value var)))
10032       (if (memq type '(processable cached replied forwarded recent saved))
10033           (gnus-summary-update-secondary-mark article)
10034         ;;; !!! This is bogus.  We should find out what primary
10035         ;;; !!! mark we want to set.
10036         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10037
10038 (defun gnus-summary-mark-as-expirable (n)
10039   "Mark N articles forward as expirable.
10040 If N is negative, mark backward instead.  The difference between N and
10041 the actual number of articles marked is returned."
10042   (interactive "p")
10043   (gnus-summary-mark-forward n gnus-expirable-mark))
10044
10045 (defun gnus-summary-mark-as-spam (n)
10046   "Mark N articles forward as spam.
10047 If N is negative, mark backward instead.  The difference between N and
10048 the actual number of articles marked is returned."
10049   (interactive "p")
10050   (gnus-summary-mark-forward n gnus-spam-mark))
10051
10052 (defun gnus-summary-mark-article-as-replied (article)
10053   "Mark ARTICLE as replied to and update the summary line.
10054 ARTICLE can also be a list of articles."
10055   (interactive (list (gnus-summary-article-number)))
10056   (let ((articles (if (listp article) article (list article))))
10057     (dolist (article articles)
10058       (unless (numberp article)
10059         (error "%s is not a number" article))
10060       (push article gnus-newsgroup-replied)
10061       (let ((buffer-read-only nil))
10062         (when (gnus-summary-goto-subject article nil t)
10063           (gnus-summary-update-secondary-mark article))))))
10064
10065 (defun gnus-summary-mark-article-as-forwarded (article)
10066   "Mark ARTICLE as forwarded and update the summary line.
10067 ARTICLE can also be a list of articles."
10068   (let ((articles (if (listp article) article (list article))))
10069     (dolist (article articles)
10070       (push article gnus-newsgroup-forwarded)
10071       (let ((buffer-read-only nil))
10072         (when (gnus-summary-goto-subject article nil t)
10073           (gnus-summary-update-secondary-mark article))))))
10074
10075 (defun gnus-summary-set-bookmark (article)
10076   "Set a bookmark in current article."
10077   (interactive (list (gnus-summary-article-number)))
10078   (when (or (not (get-buffer gnus-article-buffer))
10079             (not gnus-current-article)
10080             (not gnus-article-current)
10081             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10082     (error "No current article selected"))
10083   ;; Remove old bookmark, if one exists.
10084   (gnus-pull article gnus-newsgroup-bookmarks)
10085   ;; Set the new bookmark, which is on the form
10086   ;; (article-number . line-number-in-body).
10087   (push
10088    (cons article
10089          (with-current-buffer gnus-article-buffer
10090            (count-lines
10091             (min (point)
10092                  (save-excursion
10093                    (article-goto-body)
10094                    (point)))
10095             (point))))
10096    gnus-newsgroup-bookmarks)
10097   (gnus-message 6 "A bookmark has been added to the current article."))
10098
10099 (defun gnus-summary-remove-bookmark (article)
10100   "Remove the bookmark from the current article."
10101   (interactive (list (gnus-summary-article-number)))
10102   ;; Remove old bookmark, if one exists.
10103   (if (not (assq article gnus-newsgroup-bookmarks))
10104       (gnus-message 6 "No bookmark in current article.")
10105     (gnus-pull article gnus-newsgroup-bookmarks)
10106     (gnus-message 6 "Removed bookmark.")))
10107
10108 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10109 (defun gnus-summary-mark-as-dormant (n)
10110   "Mark N articles forward as dormant.
10111 If N is negative, mark backward instead.  The difference between N and
10112 the actual number of articles marked is returned."
10113   (interactive "p")
10114   (gnus-summary-mark-forward n gnus-dormant-mark))
10115
10116 (defun gnus-summary-set-process-mark (article)
10117   "Set the process mark on ARTICLE and update the summary line."
10118   (setq gnus-newsgroup-processable
10119         (cons article
10120               (delq article gnus-newsgroup-processable)))
10121   (when (gnus-summary-goto-subject article)
10122     (gnus-summary-show-thread)
10123     (gnus-summary-goto-subject article)
10124     (gnus-summary-update-secondary-mark article)))
10125
10126 (defun gnus-summary-remove-process-mark (&rest articles)
10127   "Remove the process mark from ARTICLES and update the summary line."
10128   (dolist (article articles)
10129     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10130     (when (gnus-summary-goto-subject article)
10131       (gnus-summary-show-thread)
10132       (gnus-summary-goto-subject article)
10133       (gnus-summary-update-secondary-mark article)))
10134   t)
10135
10136 (defun gnus-summary-set-saved-mark (article)
10137   "Set the process mark on ARTICLE and update the summary line."
10138   (push article gnus-newsgroup-saved)
10139   (when (gnus-summary-goto-subject article)
10140     (gnus-summary-update-secondary-mark article)))
10141
10142 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10143   "Mark N articles as read forwards.
10144 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10145 The difference between N and the actual number of articles marked is
10146 returned.
10147 If NO-EXPIRE, auto-expiry will be inhibited."
10148   (interactive "p")
10149   (gnus-summary-show-thread)
10150   (let ((backward (< n 0))
10151         (gnus-summary-goto-unread
10152          (and gnus-summary-goto-unread
10153               (not (eq gnus-summary-goto-unread 'never))
10154               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10155                                     gnus-ticked-mark gnus-dormant-mark)))))
10156         (n (abs n))
10157         (mark (or mark gnus-del-mark)))
10158     (while (and (> n 0)
10159                 (gnus-summary-mark-article nil mark no-expire)
10160                 (zerop (gnus-summary-next-subject
10161                         (if backward -1 1)
10162                         (and gnus-summary-goto-unread
10163                              (not (eq gnus-summary-goto-unread 'never)))
10164                         t)))
10165       (setq n (1- n)))
10166     (when (/= 0 n)
10167       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10168     (gnus-summary-recenter)
10169     (gnus-summary-position-point)
10170     (gnus-set-mode-line 'summary)
10171     n))
10172
10173 (defun gnus-summary-mark-article-as-read (mark)
10174   "Mark the current article quickly as read with MARK."
10175   (let ((article (gnus-summary-article-number)))
10176     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10177     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10178     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10179     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10180     (push (cons article mark) gnus-newsgroup-reads)
10181     ;; Possibly remove from cache, if that is used.
10182     (when gnus-use-cache
10183       (gnus-cache-enter-remove-article article))
10184     ;; Allow the backend to change the mark.
10185     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10186     ;; Check for auto-expiry.
10187     (when (and gnus-newsgroup-auto-expire
10188                (memq mark gnus-auto-expirable-marks))
10189       (setq mark gnus-expirable-mark)
10190       ;; Let the backend know about the mark change.
10191       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10192       (push article gnus-newsgroup-expirable))
10193     ;; Set the mark in the buffer.
10194     (gnus-summary-update-mark mark 'unread)
10195     t))
10196
10197 (defun gnus-summary-mark-article-as-unread (mark)
10198   "Mark the current article quickly as unread with MARK."
10199   (let* ((article (gnus-summary-article-number))
10200          (old-mark (gnus-summary-article-mark article)))
10201     ;; Allow the backend to change the mark.
10202     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10203     (if (eq mark old-mark)
10204         t
10205       (if (<= article 0)
10206           (progn
10207             (gnus-error 1 "Can't mark negative article numbers")
10208             nil)
10209         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10210         (setq gnus-newsgroup-spam-marked
10211               (delq article gnus-newsgroup-spam-marked))
10212         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10213         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10214         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10215         (cond ((= mark gnus-ticked-mark)
10216                (setq gnus-newsgroup-marked
10217                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10218                                               article)))
10219               ((= mark gnus-spam-mark)
10220                (setq gnus-newsgroup-spam-marked
10221                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10222                                               article)))
10223               ((= mark gnus-dormant-mark)
10224                (setq gnus-newsgroup-dormant
10225                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10226                                               article)))
10227               (t
10228                (setq gnus-newsgroup-unreads
10229                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10230                                               article))))
10231         (gnus-pull article gnus-newsgroup-reads)
10232
10233         ;; See whether the article is to be put in the cache.
10234         (and gnus-use-cache
10235              (vectorp (gnus-summary-article-header article))
10236              (save-excursion
10237                (gnus-cache-possibly-enter-article
10238                 gnus-newsgroup-name article
10239                 (= mark gnus-ticked-mark)
10240                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10241
10242         ;; Fix the mark.
10243         (gnus-summary-update-mark mark 'unread)
10244         t))))
10245
10246 (defun gnus-summary-mark-article (&optional article mark no-expire)
10247   "Mark ARTICLE with MARK.  MARK can be any character.
10248 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10249 `??' (dormant) and `?E' (expirable).
10250 If MARK is nil, then the default character `?r' is used.
10251 If ARTICLE is nil, then the article on the current line will be
10252 marked.
10253 If NO-EXPIRE, auto-expiry will be inhibited."
10254   ;; The mark might be a string.
10255   (when (stringp mark)
10256     (setq mark (aref mark 0)))
10257   ;; If no mark is given, then we check auto-expiring.
10258   (when (null mark)
10259     (setq mark gnus-del-mark))
10260   (when (and (not no-expire)
10261              gnus-newsgroup-auto-expire
10262              (memq mark gnus-auto-expirable-marks))
10263     (setq mark gnus-expirable-mark))
10264   (let ((article (or article (gnus-summary-article-number)))
10265         (old-mark (gnus-summary-article-mark article)))
10266     ;; Allow the backend to change the mark.
10267     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10268     (if (eq mark old-mark)
10269         t
10270       (unless article
10271         (error "No article on current line"))
10272       (if (not (if (or (= mark gnus-unread-mark)
10273                        (= mark gnus-ticked-mark)
10274                        (= mark gnus-spam-mark)
10275                        (= mark gnus-dormant-mark))
10276                    (gnus-mark-article-as-unread article mark)
10277                  (gnus-mark-article-as-read article mark)))
10278           t
10279         ;; See whether the article is to be put in the cache.
10280         (and gnus-use-cache
10281              (not (= mark gnus-canceled-mark))
10282              (vectorp (gnus-summary-article-header article))
10283              (save-excursion
10284                (gnus-cache-possibly-enter-article
10285                 gnus-newsgroup-name article
10286                 (= mark gnus-ticked-mark)
10287                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10288
10289         (when (gnus-summary-goto-subject article nil t)
10290           (let ((buffer-read-only nil))
10291             (gnus-summary-show-thread)
10292             ;; Fix the mark.
10293             (gnus-summary-update-mark mark 'unread)
10294             t))))))
10295
10296 (defun gnus-summary-update-secondary-mark (article)
10297   "Update the secondary (read, process, cache) mark."
10298   (gnus-summary-update-mark
10299    (cond ((memq article gnus-newsgroup-processable)
10300           gnus-process-mark)
10301          ((memq article gnus-newsgroup-cached)
10302           gnus-cached-mark)
10303          ((memq article gnus-newsgroup-replied)
10304           gnus-replied-mark)
10305          ((memq article gnus-newsgroup-forwarded)
10306           gnus-forwarded-mark)
10307          ((memq article gnus-newsgroup-saved)
10308           gnus-saved-mark)
10309          ((memq article gnus-newsgroup-recent)
10310           gnus-recent-mark)
10311          ((memq article gnus-newsgroup-unseen)
10312           gnus-unseen-mark)
10313          (t gnus-no-mark))
10314    'replied)
10315   (when (gnus-visual-p 'summary-highlight 'highlight)
10316     (gnus-run-hooks 'gnus-summary-update-hook))
10317   t)
10318
10319 (defun gnus-summary-update-download-mark (article)
10320   "Update the download mark."
10321   (gnus-summary-update-mark
10322    (cond ((memq article gnus-newsgroup-undownloaded)
10323           gnus-undownloaded-mark)
10324          (gnus-newsgroup-agentized
10325           gnus-downloaded-mark)
10326          (t
10327           gnus-no-mark))
10328    'download)
10329   (gnus-summary-update-line t)
10330   t)
10331
10332 (defun gnus-summary-update-mark (mark type)
10333   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10334         (buffer-read-only nil))
10335     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10336     (when forward
10337       (when (looking-at "\r")
10338         (incf forward))
10339       (when (<= (+ forward (point)) (point-max))
10340         ;; Go to the right position on the line.
10341         (goto-char (+ forward (point)))
10342         ;; Replace the old mark with the new mark.
10343         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10344         ;; Optionally update the marks by some user rule.
10345         (when (eq type 'unread)
10346           (gnus-data-set-mark
10347            (gnus-data-find (gnus-summary-article-number)) mark)
10348           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10349
10350 (defun gnus-mark-article-as-read (article &optional mark)
10351   "Enter ARTICLE in the pertinent lists and remove it from others."
10352   ;; Make the article expirable.
10353   (let ((mark (or mark gnus-del-mark)))
10354     (setq gnus-newsgroup-expirable
10355           (if (= mark gnus-expirable-mark)
10356               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10357             (delq article gnus-newsgroup-expirable)))
10358     ;; Remove from unread and marked lists.
10359     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10360     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10361     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10362     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10363     (push (cons article mark) gnus-newsgroup-reads)
10364     ;; Possibly remove from cache, if that is used.
10365     (when gnus-use-cache
10366       (gnus-cache-enter-remove-article article))
10367     t))
10368
10369 (defun gnus-mark-article-as-unread (article &optional mark)
10370   "Enter ARTICLE in the pertinent lists and remove it from others."
10371   (let ((mark (or mark gnus-ticked-mark)))
10372     (if (<= article 0)
10373         (progn
10374           (gnus-error 1 "Can't mark negative article numbers")
10375           nil)
10376       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10377             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10378             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10379             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10380             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10381
10382       ;; Unsuppress duplicates?
10383       (when gnus-suppress-duplicates
10384         (gnus-dup-unsuppress-article article))
10385
10386       (cond ((= mark gnus-ticked-mark)
10387              (setq gnus-newsgroup-marked
10388                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10389             ((= mark gnus-spam-mark)
10390              (setq gnus-newsgroup-spam-marked
10391                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10392                                             article)))
10393             ((= mark gnus-dormant-mark)
10394              (setq gnus-newsgroup-dormant
10395                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10396             (t
10397              (setq gnus-newsgroup-unreads
10398                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10399       (gnus-pull article gnus-newsgroup-reads)
10400       t)))
10401
10402 (defalias 'gnus-summary-mark-as-unread-forward
10403   'gnus-summary-tick-article-forward)
10404 (make-obsolete 'gnus-summary-mark-as-unread-forward
10405                'gnus-summary-tick-article-forward)
10406 (defun gnus-summary-tick-article-forward (n)
10407   "Tick N articles forwards.
10408 If N is negative, tick backwards instead.
10409 The difference between N and the number of articles ticked is returned."
10410   (interactive "p")
10411   (gnus-summary-mark-forward n gnus-ticked-mark))
10412
10413 (defalias 'gnus-summary-mark-as-unread-backward
10414   'gnus-summary-tick-article-backward)
10415 (make-obsolete 'gnus-summary-mark-as-unread-backward
10416                'gnus-summary-tick-article-backward)
10417 (defun gnus-summary-tick-article-backward (n)
10418   "Tick N articles backwards.
10419 The difference between N and the number of articles ticked is returned."
10420   (interactive "p")
10421   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10422
10423 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10424 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10425 (defun gnus-summary-tick-article (&optional article clear-mark)
10426   "Mark current article as unread.
10427 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10428 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10429   (interactive)
10430   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10431                                        gnus-ticked-mark)))
10432
10433 (defun gnus-summary-mark-as-read-forward (n)
10434   "Mark N articles as read forwards.
10435 If N is negative, mark backwards instead.
10436 The difference between N and the actual number of articles marked is
10437 returned."
10438   (interactive "p")
10439   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10440
10441 (defun gnus-summary-mark-as-read-backward (n)
10442   "Mark the N articles as read backwards.
10443 The difference between N and the actual number of articles marked is
10444 returned."
10445   (interactive "p")
10446   (gnus-summary-mark-forward
10447    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10448
10449 (defun gnus-summary-mark-as-read (&optional article mark)
10450   "Mark current article as read.
10451 ARTICLE specifies the article to be marked as read.
10452 MARK specifies a string to be inserted at the beginning of the line."
10453   (gnus-summary-mark-article article mark))
10454
10455 (defun gnus-summary-clear-mark-forward (n)
10456   "Clear marks from N articles forward.
10457 If N is negative, clear backward instead.
10458 The difference between N and the number of marks cleared is returned."
10459   (interactive "p")
10460   (gnus-summary-mark-forward n gnus-unread-mark))
10461
10462 (defun gnus-summary-clear-mark-backward (n)
10463   "Clear marks from N articles backward.
10464 The difference between N and the number of marks cleared is returned."
10465   (interactive "p")
10466   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10467
10468 (defun gnus-summary-mark-unread-as-read ()
10469   "Intended to be used by `gnus-summary-mark-article-hook'."
10470   (when (memq gnus-current-article gnus-newsgroup-unreads)
10471     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10472
10473 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10474   "Intended to be used by `gnus-summary-mark-article-hook'."
10475   (let ((mark (gnus-summary-article-mark)))
10476     (when (or (gnus-unread-mark-p mark)
10477               (gnus-read-mark-p mark))
10478       (gnus-summary-mark-article gnus-current-article
10479                                  (or new-mark gnus-read-mark)))))
10480
10481 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10482   "Intended to be used by `gnus-summary-mark-article-hook'."
10483   (let ((mark (gnus-summary-article-mark)))
10484     (when (or (gnus-unread-mark-p mark)
10485               (gnus-read-mark-p mark))
10486       (gnus-summary-mark-article (gnus-summary-article-number)
10487                                  (or new-mark gnus-read-mark)))))
10488
10489 (defun gnus-summary-mark-unread-as-ticked ()
10490   "Intended to be used by `gnus-summary-mark-article-hook'."
10491   (when (memq gnus-current-article gnus-newsgroup-unreads)
10492     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10493
10494 (defun gnus-summary-mark-region-as-read (point mark all)
10495   "Mark all unread articles between point and mark as read.
10496 If given a prefix, mark all articles between point and mark as read,
10497 even ticked and dormant ones."
10498   (interactive "r\nP")
10499   (save-excursion
10500     (let (article)
10501       (goto-char point)
10502       (beginning-of-line)
10503       (while (and
10504               (< (point) mark)
10505               (progn
10506                 (when (or all
10507                           (memq (setq article (gnus-summary-article-number))
10508                                 gnus-newsgroup-unreads))
10509                   (gnus-summary-mark-article article gnus-del-mark))
10510                 t)
10511               (gnus-summary-find-next))))))
10512
10513 (defun gnus-summary-mark-below (score mark)
10514   "Mark articles with score less than SCORE with MARK."
10515   (interactive "P\ncMark: ")
10516   (setq score (if score
10517                   (prefix-numeric-value score)
10518                 (or gnus-summary-default-score 0)))
10519   (save-excursion
10520     (set-buffer gnus-summary-buffer)
10521     (goto-char (point-min))
10522     (while
10523         (progn
10524           (and (< (gnus-summary-article-score) score)
10525                (gnus-summary-mark-article nil mark))
10526           (gnus-summary-find-next)))))
10527
10528 (defun gnus-summary-kill-below (&optional score)
10529   "Mark articles with score below SCORE as read."
10530   (interactive "P")
10531   (gnus-summary-mark-below score gnus-killed-mark))
10532
10533 (defun gnus-summary-clear-above (&optional score)
10534   "Clear all marks from articles with score above SCORE."
10535   (interactive "P")
10536   (gnus-summary-mark-above score gnus-unread-mark))
10537
10538 (defun gnus-summary-tick-above (&optional score)
10539   "Tick all articles with score above SCORE."
10540   (interactive "P")
10541   (gnus-summary-mark-above score gnus-ticked-mark))
10542
10543 (defun gnus-summary-mark-above (score mark)
10544   "Mark articles with score over SCORE with MARK."
10545   (interactive "P\ncMark: ")
10546   (setq score (if score
10547                   (prefix-numeric-value score)
10548                 (or gnus-summary-default-score 0)))
10549   (save-excursion
10550     (set-buffer gnus-summary-buffer)
10551     (goto-char (point-min))
10552     (while (and (progn
10553                   (when (> (gnus-summary-article-score) score)
10554                     (gnus-summary-mark-article nil mark))
10555                   t)
10556                 (gnus-summary-find-next)))))
10557
10558 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10559 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10560 (defun gnus-summary-limit-include-expunged (&optional no-error)
10561   "Display all the hidden articles that were expunged for low scores."
10562   (interactive)
10563   (let ((buffer-read-only nil))
10564     (let ((scored gnus-newsgroup-scored)
10565           headers h)
10566       (while scored
10567         (unless (gnus-summary-article-header (caar scored))
10568           (and (setq h (gnus-number-to-header (caar scored)))
10569                (< (cdar scored) gnus-summary-expunge-below)
10570                (push h headers)))
10571         (setq scored (cdr scored)))
10572       (if (not headers)
10573           (when (not no-error)
10574             (error "No expunged articles hidden"))
10575         (goto-char (point-min))
10576         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10577         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10578         (mapcar (lambda (x) (push (mail-header-number x)
10579                                   gnus-newsgroup-limit))
10580                 headers)
10581         (gnus-summary-prepare-unthreaded (nreverse headers))
10582         (goto-char (point-min))
10583         (gnus-summary-position-point)
10584         t))))
10585
10586 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10587   "Mark all unread articles in this newsgroup as read.
10588 If prefix argument ALL is non-nil, ticked and dormant articles will
10589 also be marked as read.
10590 If QUIETLY is non-nil, no questions will be asked.
10591
10592 If TO-HERE is non-nil, it should be a point in the buffer.  All
10593 articles before (after, if REVERSE is set) this point will be marked
10594 as read.
10595
10596 Note that this function will only catch up the unread article
10597 in the current summary buffer limitation.
10598
10599 The number of articles marked as read is returned."
10600   (interactive "P")
10601   (prog1
10602       (save-excursion
10603         (when (or quietly
10604                   (not gnus-interactive-catchup) ;Without confirmation?
10605                   gnus-expert-user
10606                   (gnus-y-or-n-p
10607                    (if all
10608                        "Mark absolutely all articles as read? "
10609                      "Mark all unread articles as read? ")))
10610           (if (and not-mark
10611                    (not gnus-newsgroup-adaptive)
10612                    (not gnus-newsgroup-auto-expire)
10613                    (not gnus-suppress-duplicates)
10614                    (or (not gnus-use-cache)
10615                        (eq gnus-use-cache 'passive)))
10616               (progn
10617                 (when all
10618                   (setq gnus-newsgroup-marked nil
10619                         gnus-newsgroup-spam-marked nil
10620                         gnus-newsgroup-dormant nil))
10621                 (setq gnus-newsgroup-unreads
10622                       (gnus-sorted-nunion
10623                        (gnus-intersection gnus-newsgroup-unreads
10624                                           gnus-newsgroup-downloadable)
10625                        gnus-newsgroup-unfetched)))
10626             ;; We actually mark all articles as canceled, which we
10627             ;; have to do when using auto-expiry or adaptive scoring.
10628             (gnus-summary-show-all-threads)
10629             (if (and to-here reverse)
10630                 (progn
10631                   (goto-char to-here)
10632                   (gnus-summary-mark-current-read-and-unread-as-read
10633                    gnus-catchup-mark)
10634                   (while (gnus-summary-find-next (not all))
10635                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10636               (when (gnus-summary-first-subject (not all))
10637                 (while (and
10638                         (if to-here (< (point) to-here) t)
10639                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10640                         (gnus-summary-find-next (not all))))))
10641             (gnus-set-mode-line 'summary))
10642           t))
10643     (gnus-summary-position-point)))
10644
10645 (defun gnus-summary-catchup-to-here (&optional all)
10646   "Mark all unticked articles before the current one as read.
10647 If ALL is non-nil, also mark ticked and dormant articles as read."
10648   (interactive "P")
10649   (save-excursion
10650     (gnus-save-hidden-threads
10651       (let ((beg (point)))
10652         ;; We check that there are unread articles.
10653         (when (or all (gnus-summary-find-prev))
10654           (gnus-summary-catchup all t beg)))))
10655   (gnus-summary-position-point))
10656
10657 (defun gnus-summary-catchup-from-here (&optional all)
10658   "Mark all unticked articles after (and including) the current one as read.
10659 If ALL is non-nil, also mark ticked and dormant articles as read."
10660   (interactive "P")
10661   (save-excursion
10662     (gnus-save-hidden-threads
10663       (let ((beg (point)))
10664         ;; We check that there are unread articles.
10665         (when (or all (gnus-summary-find-next))
10666           (gnus-summary-catchup all t beg nil t)))))
10667   (gnus-summary-position-point))
10668
10669 (defun gnus-summary-catchup-all (&optional quietly)
10670   "Mark all articles in this newsgroup as read.
10671 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10672 instead, which marks only unread articles as read."
10673   (interactive "P")
10674   (gnus-summary-catchup t quietly))
10675
10676 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10677   "Mark all unread articles in this group as read, then exit.
10678 If prefix argument ALL is non-nil, all articles are marked as read.
10679 If QUIETLY is non-nil, no questions will be asked."
10680   (interactive "P")
10681   (when (gnus-summary-catchup all quietly nil 'fast)
10682     ;; Select next newsgroup or exit.
10683     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10684              (eq gnus-auto-select-next 'quietly))
10685         (gnus-summary-next-group nil)
10686       (gnus-summary-exit))))
10687
10688 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10689   "Mark all articles in this newsgroup as read, and then exit.
10690 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10691 instead, which marks only unread articles as read."
10692   (interactive "P")
10693   (gnus-summary-catchup-and-exit t quietly))
10694
10695 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10696   "Mark all articles in this group as read and select the next group.
10697 If given a prefix, mark all articles, unread as well as ticked, as
10698 read."
10699   (interactive "P")
10700   (save-excursion
10701     (gnus-summary-catchup all))
10702   (gnus-summary-next-group))
10703
10704 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10705   "Mark all articles in this group as read and select the previous group.
10706 If given a prefix, mark all articles, unread as well as ticked, as
10707 read."
10708   (interactive "P")
10709   (save-excursion
10710     (gnus-summary-catchup all))
10711   (gnus-summary-next-group nil nil t))
10712
10713 ;;;
10714 ;;; with article
10715 ;;;
10716
10717 (defmacro gnus-with-article (article &rest forms)
10718   "Select ARTICLE and perform FORMS in the original article buffer.
10719 Then replace the article with the result."
10720   `(progn
10721      ;; We don't want the article to be marked as read.
10722      (let (gnus-mark-article-hook)
10723        (gnus-summary-select-article t t nil ,article))
10724      (set-buffer gnus-original-article-buffer)
10725      ,@forms
10726      (if (not (gnus-check-backend-function
10727                'request-replace-article (car gnus-article-current)))
10728          (gnus-message 5 "Read-only group; not replacing")
10729        (unless (gnus-request-replace-article
10730                 ,article (car gnus-article-current)
10731                 (current-buffer) t)
10732          (error "Couldn't replace article")))
10733      ;; The cache and backlog have to be flushed somewhat.
10734      (when gnus-keep-backlog
10735        (gnus-backlog-remove-article
10736         (car gnus-article-current) (cdr gnus-article-current)))
10737      (when gnus-use-cache
10738        (gnus-cache-update-article
10739         (car gnus-article-current) (cdr gnus-article-current)))))
10740
10741 (put 'gnus-with-article 'lisp-indent-function 1)
10742 (put 'gnus-with-article 'edebug-form-spec '(form body))
10743
10744 ;; Thread-based commands.
10745
10746 (defun gnus-summary-articles-in-thread (&optional article)
10747   "Return a list of all articles in the current thread.
10748 If ARTICLE is non-nil, return all articles in the thread that starts
10749 with that article."
10750   (let* ((article (or article (gnus-summary-article-number)))
10751          (data (gnus-data-find-list article))
10752          (top-level (gnus-data-level (car data)))
10753          (top-subject
10754           (cond ((null gnus-thread-operation-ignore-subject)
10755                  (gnus-simplify-subject-re
10756                   (mail-header-subject (gnus-data-header (car data)))))
10757                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10758                  (gnus-simplify-subject-fuzzy
10759                   (mail-header-subject (gnus-data-header (car data)))))
10760                 (t nil)))
10761          (end-point (save-excursion
10762                       (if (gnus-summary-go-to-next-thread)
10763                           (point) (point-max))))
10764          articles)
10765     (while (and data
10766                 (< (gnus-data-pos (car data)) end-point))
10767       (when (or (not top-subject)
10768                 (string= top-subject
10769                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10770                              (gnus-simplify-subject-fuzzy
10771                               (mail-header-subject
10772                                (gnus-data-header (car data))))
10773                            (gnus-simplify-subject-re
10774                             (mail-header-subject
10775                              (gnus-data-header (car data)))))))
10776         (push (gnus-data-number (car data)) articles))
10777       (unless (and (setq data (cdr data))
10778                    (> (gnus-data-level (car data)) top-level))
10779         (setq data nil)))
10780     ;; Return the list of articles.
10781     (nreverse articles)))
10782
10783 (defun gnus-summary-rethread-current ()
10784   "Rethread the thread the current article is part of."
10785   (interactive)
10786   (let* ((gnus-show-threads t)
10787          (article (gnus-summary-article-number))
10788          (id (mail-header-id (gnus-summary-article-header)))
10789          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10790     (unless id
10791       (error "No article on the current line"))
10792     (gnus-rebuild-thread id)
10793     (gnus-summary-goto-subject article)))
10794
10795 (defun gnus-summary-reparent-thread ()
10796   "Make the current article child of the marked (or previous) article.
10797
10798 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10799 is non-nil or the Subject: of both articles are the same."
10800   (interactive)
10801   (unless (not (gnus-group-read-only-p))
10802     (error "The current newsgroup does not support article editing"))
10803   (unless (<= (length gnus-newsgroup-processable) 1)
10804     (error "No more than one article may be marked"))
10805   (save-window-excursion
10806     (let ((gnus-article-buffer " *reparent*")
10807           (current-article (gnus-summary-article-number))
10808           ;; First grab the marked article, otherwise one line up.
10809           (parent-article (if (not (null gnus-newsgroup-processable))
10810                               (car gnus-newsgroup-processable)
10811                             (save-excursion
10812                               (if (eq (forward-line -1) 0)
10813                                   (gnus-summary-article-number)
10814                                 (error "Beginning of summary buffer"))))))
10815       (unless (not (eq current-article parent-article))
10816         (error "An article may not be self-referential"))
10817       (let ((message-id (mail-header-id
10818                          (gnus-summary-article-header parent-article))))
10819         (unless (and message-id (not (equal message-id "")))
10820           (error "No message-id in desired parent"))
10821         (gnus-with-article current-article
10822           (save-restriction
10823             (goto-char (point-min))
10824             (message-narrow-to-head)
10825             (if (re-search-forward "^References: " nil t)
10826                 (progn
10827                   (re-search-forward "^[^ \t]" nil t)
10828                   (forward-line -1)
10829                   (end-of-line)
10830                   (insert " " message-id))
10831               (insert "References: " message-id "\n"))))
10832         (set-buffer gnus-summary-buffer)
10833         (gnus-summary-unmark-all-processable)
10834         (gnus-summary-update-article current-article)
10835         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10836             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10837         (gnus-summary-rethread-current)
10838         (gnus-message 3 "Article %d is now the child of article %d"
10839                       current-article parent-article)))))
10840
10841 (defun gnus-summary-toggle-threads (&optional arg)
10842   "Toggle showing conversation threads.
10843 If ARG is positive number, turn showing conversation threads on."
10844   (interactive "P")
10845   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10846     (setq gnus-show-threads
10847           (if (null arg) (not gnus-show-threads)
10848             (> (prefix-numeric-value arg) 0)))
10849     (gnus-summary-prepare)
10850     (gnus-summary-goto-subject current)
10851     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10852     (gnus-summary-position-point)))
10853
10854 (defun gnus-summary-show-all-threads ()
10855   "Show all threads."
10856   (interactive)
10857   (save-excursion
10858     (let ((buffer-read-only nil))
10859       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10860   (gnus-summary-position-point))
10861
10862 (defun gnus-summary-show-thread ()
10863   "Show thread subtrees.
10864 Returns nil if no thread was there to be shown."
10865   (interactive)
10866   (let ((buffer-read-only nil)
10867         (orig (point))
10868         (end (point-at-eol))
10869         ;; Leave point at bol
10870         (beg (progn (beginning-of-line) (point))))
10871     (prog1
10872         ;; Any hidden lines here?
10873         (search-forward "\r" end t)
10874       (subst-char-in-region beg end ?\^M ?\n t)
10875       (goto-char orig)
10876       (gnus-summary-position-point))))
10877
10878 (defun gnus-summary-maybe-hide-threads ()
10879   "If requested, hide the threads that should be hidden."
10880   (when (and gnus-show-threads
10881              gnus-thread-hide-subtree)
10882     (gnus-summary-hide-all-threads
10883      (if (or (consp gnus-thread-hide-subtree)
10884              (functionp gnus-thread-hide-subtree))
10885          (gnus-make-predicate gnus-thread-hide-subtree)
10886        nil))))
10887
10888 ;;; Hiding predicates.
10889
10890 (defun gnus-article-unread-p (header)
10891   (memq (mail-header-number header) gnus-newsgroup-unreads))
10892
10893 (defun gnus-article-unseen-p (header)
10894   (memq (mail-header-number header) gnus-newsgroup-unseen))
10895
10896 (defun gnus-map-articles (predicate articles)
10897   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10898   (apply 'gnus-or (mapcar predicate
10899                           (mapcar 'gnus-summary-article-header articles))))
10900
10901 (defun gnus-summary-hide-all-threads (&optional predicate)
10902   "Hide all thread subtrees.
10903 If PREDICATE is supplied, threads that satisfy this predicate
10904 will not be hidden."
10905   (interactive)
10906   (save-excursion
10907     (goto-char (point-min))
10908     (let ((end nil))
10909       (while (not end)
10910         (when (or (not predicate)
10911                   (gnus-map-articles
10912                    predicate (gnus-summary-article-children)))
10913             (gnus-summary-hide-thread))
10914         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10915   (gnus-summary-position-point))
10916
10917 (defun gnus-summary-hide-thread ()
10918   "Hide thread subtrees.
10919 If PREDICATE is supplied, threads that satisfy this predicate
10920 will not be hidden.
10921 Returns nil if no threads were there to be hidden."
10922   (interactive)
10923   (let ((buffer-read-only nil)
10924         (start (point))
10925         (article (gnus-summary-article-number)))
10926     (goto-char start)
10927     ;; Go forward until either the buffer ends or the subthread
10928     ;; ends.
10929     (when (and (not (eobp))
10930                (or (zerop (gnus-summary-next-thread 1 t))
10931                    (goto-char (point-max))))
10932       (prog1
10933           (if (and (> (point) start)
10934                    (search-backward "\n" start t))
10935               (progn
10936                 (subst-char-in-region start (point) ?\n ?\^M)
10937                 (gnus-summary-goto-subject article))
10938             (goto-char start)
10939             nil)))))
10940
10941 (defun gnus-summary-go-to-next-thread (&optional previous)
10942   "Go to the same level (or less) next thread.
10943 If PREVIOUS is non-nil, go to previous thread instead.
10944 Return the article number moved to, or nil if moving was impossible."
10945   (let ((level (gnus-summary-thread-level))
10946         (way (if previous -1 1))
10947         (beg (point)))
10948     (forward-line way)
10949     (while (and (not (eobp))
10950                 (< level (gnus-summary-thread-level)))
10951       (forward-line way))
10952     (if (eobp)
10953         (progn
10954           (goto-char beg)
10955           nil)
10956       (setq beg (point))
10957       (prog1
10958           (gnus-summary-article-number)
10959         (goto-char beg)))))
10960
10961 (defun gnus-summary-next-thread (n &optional silent)
10962   "Go to the same level next N'th thread.
10963 If N is negative, search backward instead.
10964 Returns the difference between N and the number of skips actually
10965 done.
10966
10967 If SILENT, don't output messages."
10968   (interactive "p")
10969   (let ((backward (< n 0))
10970         (n (abs n)))
10971     (while (and (> n 0)
10972                 (gnus-summary-go-to-next-thread backward))
10973       (decf n))
10974     (unless silent
10975       (gnus-summary-position-point))
10976     (when (and (not silent) (/= 0 n))
10977       (gnus-message 7 "No more threads"))
10978     n))
10979
10980 (defun gnus-summary-prev-thread (n)
10981   "Go to the same level previous N'th thread.
10982 Returns the difference between N and the number of skips actually
10983 done."
10984   (interactive "p")
10985   (gnus-summary-next-thread (- n)))
10986
10987 (defun gnus-summary-go-down-thread ()
10988   "Go down one level in the current thread."
10989   (let ((children (gnus-summary-article-children)))
10990     (when children
10991       (gnus-summary-goto-subject (car children)))))
10992
10993 (defun gnus-summary-go-up-thread ()
10994   "Go up one level in the current thread."
10995   (let ((parent (gnus-summary-article-parent)))
10996     (when parent
10997       (gnus-summary-goto-subject parent))))
10998
10999 (defun gnus-summary-down-thread (n)
11000   "Go down thread N steps.
11001 If N is negative, go up instead.
11002 Returns the difference between N and how many steps down that were
11003 taken."
11004   (interactive "p")
11005   (let ((up (< n 0))
11006         (n (abs n)))
11007     (while (and (> n 0)
11008                 (if up (gnus-summary-go-up-thread)
11009                   (gnus-summary-go-down-thread)))
11010       (setq n (1- n)))
11011     (gnus-summary-position-point)
11012     (when (/= 0 n)
11013       (gnus-message 7 "Can't go further"))
11014     n))
11015
11016 (defun gnus-summary-up-thread (n)
11017   "Go up thread N steps.
11018 If N is negative, go down instead.
11019 Returns the difference between N and how many steps down that were
11020 taken."
11021   (interactive "p")
11022   (gnus-summary-down-thread (- n)))
11023
11024 (defun gnus-summary-top-thread ()
11025   "Go to the top of the thread."
11026   (interactive)
11027   (while (gnus-summary-go-up-thread))
11028   (gnus-summary-article-number))
11029
11030 (defun gnus-summary-kill-thread (&optional unmark)
11031   "Mark articles under current thread as read.
11032 If the prefix argument is positive, remove any kinds of marks.
11033 If the prefix argument is negative, tick articles instead."
11034   (interactive "P")
11035   (when unmark
11036     (setq unmark (prefix-numeric-value unmark)))
11037   (let ((articles (gnus-summary-articles-in-thread)))
11038     (save-excursion
11039       ;; Expand the thread.
11040       (gnus-summary-show-thread)
11041       ;; Mark all the articles.
11042       (while articles
11043         (gnus-summary-goto-subject (car articles))
11044         (cond ((null unmark)
11045                (gnus-summary-mark-article-as-read gnus-killed-mark))
11046               ((> unmark 0)
11047                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11048               (t
11049                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11050         (setq articles (cdr articles))))
11051     ;; Hide killed subtrees.
11052     (and (null unmark)
11053          gnus-thread-hide-killed
11054          (gnus-summary-hide-thread))
11055     ;; If marked as read, go to next unread subject.
11056     (when (null unmark)
11057       ;; Go to next unread subject.
11058       (gnus-summary-next-subject 1 t)))
11059   (gnus-set-mode-line 'summary))
11060
11061 ;; Summary sorting commands
11062
11063 (defun gnus-summary-sort-by-number (&optional reverse)
11064   "Sort the summary buffer by article number.
11065 Argument REVERSE means reverse order."
11066   (interactive "P")
11067   (gnus-summary-sort 'number reverse))
11068
11069 (defun gnus-summary-sort-by-random (&optional reverse)
11070   "Randomize the order in the summary buffer.
11071 Argument REVERSE means to randomize in reverse order."
11072   (interactive "P")
11073   (gnus-summary-sort 'random reverse))
11074
11075 (defun gnus-summary-sort-by-author (&optional reverse)
11076   "Sort the summary buffer by author name alphabetically.
11077 If `case-fold-search' is non-nil, case of letters is ignored.
11078 Argument REVERSE means reverse order."
11079   (interactive "P")
11080   (gnus-summary-sort 'author reverse))
11081
11082 (defun gnus-summary-sort-by-recipient (&optional reverse)
11083   "Sort the summary buffer by recipient name alphabetically.
11084 If `case-fold-search' is non-nil, case of letters is ignored.
11085 Argument REVERSE means reverse order."
11086   (interactive "P")
11087   (gnus-summary-sort 'recipient reverse))
11088
11089 (defun gnus-summary-sort-by-subject (&optional reverse)
11090   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11091 If `case-fold-search' is non-nil, case of letters is ignored.
11092 Argument REVERSE means reverse order."
11093   (interactive "P")
11094   (gnus-summary-sort 'subject reverse))
11095
11096 (defun gnus-summary-sort-by-date (&optional reverse)
11097   "Sort the summary buffer by date.
11098 Argument REVERSE means reverse order."
11099   (interactive "P")
11100   (gnus-summary-sort 'date reverse))
11101
11102 (defun gnus-summary-sort-by-score (&optional reverse)
11103   "Sort the summary buffer by score.
11104 Argument REVERSE means reverse order."
11105   (interactive "P")
11106   (gnus-summary-sort 'score reverse))
11107
11108 (defun gnus-summary-sort-by-lines (&optional reverse)
11109   "Sort the summary buffer by the number of lines.
11110 Argument REVERSE means reverse order."
11111   (interactive "P")
11112   (gnus-summary-sort 'lines reverse))
11113
11114 (defun gnus-summary-sort-by-chars (&optional reverse)
11115   "Sort the summary buffer by article length.
11116 Argument REVERSE means reverse order."
11117   (interactive "P")
11118   (gnus-summary-sort 'chars reverse))
11119
11120 (defun gnus-summary-sort-by-original (&optional reverse)
11121   "Sort the summary buffer using the default sorting method.
11122 Argument REVERSE means reverse order."
11123   (interactive "P")
11124   (let* ((buffer-read-only)
11125          (gnus-summary-prepare-hook nil))
11126     ;; We do the sorting by regenerating the threads.
11127     (gnus-summary-prepare)
11128     ;; Hide subthreads if needed.
11129     (gnus-summary-maybe-hide-threads)))
11130
11131 (defun gnus-summary-sort (predicate reverse)
11132   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11133   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11134          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11135          (gnus-thread-sort-functions
11136           (if (not reverse)
11137               thread
11138             `(lambda (t1 t2)
11139                (,thread t2 t1))))
11140          (gnus-sort-gathered-threads-function
11141           gnus-thread-sort-functions)
11142          (gnus-article-sort-functions
11143           (if (not reverse)
11144               article
11145             `(lambda (t1 t2)
11146                (,article t2 t1))))
11147          (buffer-read-only)
11148          (gnus-summary-prepare-hook nil))
11149     ;; We do the sorting by regenerating the threads.
11150     (gnus-summary-prepare)
11151     ;; Hide subthreads if needed.
11152     (gnus-summary-maybe-hide-threads)))
11153
11154 ;; Summary saving commands.
11155
11156 (defun gnus-summary-save-article (&optional n not-saved)
11157   "Save the current article using the default saver function.
11158 If N is a positive number, save the N next articles.
11159 If N is a negative number, save the N previous articles.
11160 If N is nil and any articles have been marked with the process mark,
11161 save those articles instead.
11162 The variable `gnus-default-article-saver' specifies the saver function."
11163   (interactive "P")
11164   (let* ((articles (gnus-summary-work-articles n))
11165          (save-buffer (save-excursion
11166                         (nnheader-set-temp-buffer " *Gnus Save*")))
11167          (num (length articles))
11168          header file)
11169     (dolist (article articles)
11170       (setq header (gnus-summary-article-header article))
11171       (if (not (vectorp header))
11172           ;; This is a pseudo-article.
11173           (if (assq 'name header)
11174               (gnus-copy-file (cdr (assq 'name header)))
11175             (gnus-message 1 "Article %d is unsaveable" article))
11176         ;; This is a real article.
11177         (save-window-excursion
11178           (let ((gnus-display-mime-function nil)
11179                 (gnus-article-prepare-hook nil))
11180             (gnus-summary-select-article t nil nil article)))
11181         (save-excursion
11182           (set-buffer save-buffer)
11183           (erase-buffer)
11184           (insert-buffer-substring gnus-original-article-buffer))
11185         (setq file (gnus-article-save save-buffer file num))
11186         (gnus-summary-remove-process-mark article)
11187         (unless not-saved
11188           (gnus-summary-set-saved-mark article))))
11189     (gnus-kill-buffer save-buffer)
11190     (gnus-summary-position-point)
11191     (gnus-set-mode-line 'summary)
11192     n))
11193
11194 (defun gnus-summary-pipe-output (&optional arg headers)
11195   "Pipe the current article to a subprocess.
11196 If N is a positive number, pipe the N next articles.
11197 If N is a negative number, pipe the N previous articles.
11198 If N is nil and any articles have been marked with the process mark,
11199 pipe those articles instead.
11200 If HEADERS (the symbolic prefix), include the headers, too."
11201   (interactive (gnus-interactive "P\ny"))
11202   (require 'gnus-art)
11203   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11204         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11205     (gnus-summary-save-article arg t))
11206   (let ((buffer (get-buffer "*Shell Command Output*")))
11207     (when (and buffer
11208                (not (zerop (buffer-size buffer))))
11209       (gnus-configure-windows 'pipe))))
11210
11211 (defun gnus-summary-save-article-mail (&optional arg)
11212   "Append the current article to an mail file.
11213 If N is a positive number, save the N next articles.
11214 If N is a negative number, save the N previous articles.
11215 If N is nil and any articles have been marked with the process mark,
11216 save those articles instead."
11217   (interactive "P")
11218   (require 'gnus-art)
11219   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11220     (gnus-summary-save-article arg)))
11221
11222 (defun gnus-summary-save-article-rmail (&optional arg)
11223   "Append the current article to an rmail file.
11224 If N is a positive number, save the N next articles.
11225 If N is a negative number, save the N previous articles.
11226 If N is nil and any articles have been marked with the process mark,
11227 save those articles instead."
11228   (interactive "P")
11229   (require 'gnus-art)
11230   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11231     (gnus-summary-save-article arg)))
11232
11233 (defun gnus-summary-save-article-file (&optional arg)
11234   "Append the current article to a file.
11235 If N is a positive number, save the N next articles.
11236 If N is a negative number, save the N previous articles.
11237 If N is nil and any articles have been marked with the process mark,
11238 save those articles instead."
11239   (interactive "P")
11240   (require 'gnus-art)
11241   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11242     (gnus-summary-save-article arg)))
11243
11244 (defun gnus-summary-write-article-file (&optional arg)
11245   "Write the current article to a file, deleting the previous file.
11246 If N is a positive number, save the N next articles.
11247 If N is a negative number, save the N previous articles.
11248 If N is nil and any articles have been marked with the process mark,
11249 save those articles instead."
11250   (interactive "P")
11251   (require 'gnus-art)
11252   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11253     (gnus-summary-save-article arg)))
11254
11255 (defun gnus-summary-save-article-body-file (&optional arg)
11256   "Append the current article body to a file.
11257 If N is a positive number, save the N next articles.
11258 If N is a negative number, save the N previous articles.
11259 If N is nil and any articles have been marked with the process mark,
11260 save those articles instead."
11261   (interactive "P")
11262   (require 'gnus-art)
11263   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11264     (gnus-summary-save-article arg)))
11265
11266 (defun gnus-summary-muttprint (&optional arg)
11267   "Print the current article using Muttprint.
11268 If N is a positive number, save the N next articles.
11269 If N is a negative number, save the N previous articles.
11270 If N is nil and any articles have been marked with the process mark,
11271 save those articles instead."
11272   (interactive "P")
11273   (require 'gnus-art)
11274   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11275     (gnus-summary-save-article arg t)))
11276
11277 (defun gnus-summary-pipe-message (program)
11278   "Pipe the current article through PROGRAM."
11279   (interactive "sProgram: ")
11280   (gnus-summary-select-article)
11281   (let ((mail-header-separator ""))
11282     (gnus-eval-in-buffer-window gnus-article-buffer
11283       (save-restriction
11284         (widen)
11285         (let ((start (window-start))
11286               buffer-read-only)
11287           (message-pipe-buffer-body program)
11288           (set-window-start (get-buffer-window (current-buffer)) start))))))
11289
11290 (defun gnus-get-split-value (methods)
11291   "Return a value based on the split METHODS."
11292   (let (split-name method result match)
11293     (when methods
11294       (save-excursion
11295         (set-buffer gnus-original-article-buffer)
11296         (save-restriction
11297           (nnheader-narrow-to-headers)
11298           (while (and methods (not split-name))
11299             (goto-char (point-min))
11300             (setq method (pop methods))
11301             (setq match (car method))
11302             (when (cond
11303                    ((stringp match)
11304                     ;; Regular expression.
11305                     (ignore-errors
11306                       (re-search-forward match nil t)))
11307                    ((functionp match)
11308                     ;; Function.
11309                     (save-restriction
11310                       (widen)
11311                       (setq result (funcall match gnus-newsgroup-name))))
11312                    ((consp match)
11313                     ;; Form.
11314                     (save-restriction
11315                       (widen)
11316                       (setq result (eval match)))))
11317               (setq split-name (cdr method))
11318               (cond ((stringp result)
11319                      (push (expand-file-name
11320                             result gnus-article-save-directory)
11321                            split-name))
11322                     ((consp result)
11323                      (setq split-name (append result split-name)))))))))
11324     (nreverse split-name)))
11325
11326 (defun gnus-valid-move-group-p (group)
11327   (and (boundp group)
11328        (symbol-name group)
11329        (symbol-value group)
11330        (gnus-get-function (gnus-find-method-for-group
11331                            (symbol-name group)) 'request-accept-article t)))
11332
11333 (defun gnus-read-move-group-name (prompt default articles prefix)
11334   "Read a group name."
11335   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11336          (minibuffer-confirm-incomplete nil) ; XEmacs
11337          (prom
11338           (format "%s %s to"
11339                   prompt
11340                   (if (> (length articles) 1)
11341                       (format "these %d articles" (length articles))
11342                     "this article")))
11343          (to-newsgroup
11344           (cond
11345            ((null split-name)
11346             (gnus-completing-read-with-default
11347              default prom
11348              gnus-active-hashtb
11349              'gnus-valid-move-group-p
11350              nil prefix
11351              'gnus-group-history))
11352            ((= 1 (length split-name))
11353             (gnus-completing-read-with-default
11354              (car split-name) prom
11355              gnus-active-hashtb
11356              'gnus-valid-move-group-p
11357              nil nil
11358              'gnus-group-history))
11359            (t
11360             (gnus-completing-read-with-default
11361              nil prom
11362              (mapcar 'list (nreverse split-name))
11363              nil nil nil
11364              'gnus-group-history))))
11365          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11366     (when to-newsgroup
11367       (if (or (string= to-newsgroup "")
11368               (string= to-newsgroup prefix))
11369           (setq to-newsgroup default))
11370       (unless to-newsgroup
11371         (error "No group name entered"))
11372       (or (gnus-active to-newsgroup)
11373           (gnus-activate-group to-newsgroup nil nil to-method)
11374           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11375                                      to-newsgroup))
11376               (or (and (gnus-request-create-group to-newsgroup to-method)
11377                        (gnus-activate-group
11378                         to-newsgroup nil nil to-method)
11379                        (gnus-subscribe-group to-newsgroup))
11380                   (error "Couldn't create group %s" to-newsgroup)))
11381           (error "No such group: %s" to-newsgroup)))
11382     to-newsgroup))
11383
11384 (defun gnus-summary-save-parts (type dir n &optional reverse)
11385   "Save parts matching TYPE to DIR.
11386 If REVERSE, save parts that do not match TYPE."
11387   (interactive
11388    (list (read-string "Save parts of type: "
11389                       (or (car gnus-summary-save-parts-type-history)
11390                           gnus-summary-save-parts-default-mime)
11391                       'gnus-summary-save-parts-type-history)
11392          (setq gnus-summary-save-parts-last-directory
11393                (read-file-name "Save to directory: "
11394                                gnus-summary-save-parts-last-directory
11395                                nil t))
11396          current-prefix-arg))
11397   (gnus-summary-iterate n
11398     (let ((gnus-display-mime-function nil)
11399           (gnus-inhibit-treatment t))
11400       (gnus-summary-select-article))
11401     (save-excursion
11402       (set-buffer gnus-article-buffer)
11403       (let ((handles (or gnus-article-mime-handles
11404                          (mm-dissect-buffer nil gnus-article-loose-mime)
11405                          (and gnus-article-emulate-mime
11406                               (mm-uu-dissect)))))
11407         (when handles
11408           (gnus-summary-save-parts-1 type dir handles reverse)
11409           (unless gnus-article-mime-handles ;; Don't destroy this case.
11410             (mm-destroy-parts handles)))))))
11411
11412 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11413   (if (stringp (car handle))
11414       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11415               (cdr handle))
11416     (when (if reverse
11417               (not (string-match type (mm-handle-media-type handle)))
11418             (string-match type (mm-handle-media-type handle)))
11419       (let ((file (expand-file-name
11420                    (gnus-map-function
11421                     mm-file-name-rewrite-functions
11422                     (file-name-nondirectory
11423                      (or
11424                       (mail-content-type-get
11425                        (mm-handle-disposition handle) 'filename)
11426                       (mail-content-type-get
11427                        (mm-handle-type handle) 'name)
11428                       (concat gnus-newsgroup-name
11429                               "." (number-to-string
11430                                    (cdr gnus-article-current))))))
11431                    dir)))
11432         (unless (file-exists-p file)
11433           (mm-save-part-to-file handle file))))))
11434
11435 ;; Summary extract commands
11436
11437 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11438   (let ((buffer-read-only nil)
11439         (article (gnus-summary-article-number))
11440         after-article b e)
11441     (unless (gnus-summary-goto-subject article)
11442       (error "No such article: %d" article))
11443     (gnus-summary-position-point)
11444     ;; If all commands are to be bunched up on one line, we collect
11445     ;; them here.
11446     (unless gnus-view-pseudos-separately
11447       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11448             files action)
11449         (while ps
11450           (setq action (cdr (assq 'action (car ps))))
11451           (setq files (list (cdr (assq 'name (car ps)))))
11452           (while (and ps (cdr ps)
11453                       (string= (or action "1")
11454                                (or (cdr (assq 'action (cadr ps))) "2")))
11455             (push (cdr (assq 'name (cadr ps))) files)
11456             (setcdr ps (cddr ps)))
11457           (when files
11458             (when (not (string-match "%s" action))
11459               (push " " files))
11460             (push " " files)
11461             (when (assq 'execute (car ps))
11462               (setcdr (assq 'execute (car ps))
11463                       (funcall (if (string-match "%s" action)
11464                                    'format 'concat)
11465                                action
11466                                (mapconcat
11467                                 (lambda (f)
11468                                   (if (equal f " ")
11469                                       f
11470                                     (shell-quote-argument f)))
11471                                 files " ")))))
11472           (setq ps (cdr ps)))))
11473     (if (and gnus-view-pseudos (not not-view))
11474         (while pslist
11475           (when (assq 'execute (car pslist))
11476             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11477                                   (eq gnus-view-pseudos 'not-confirm)))
11478           (setq pslist (cdr pslist)))
11479       (save-excursion
11480         (while pslist
11481           (setq after-article (or (cdr (assq 'article (car pslist)))
11482                                   (gnus-summary-article-number)))
11483           (gnus-summary-goto-subject after-article)
11484           (forward-line 1)
11485           (setq b (point))
11486           (insert "    " (file-name-nondirectory
11487                           (cdr (assq 'name (car pslist))))
11488                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11489           (setq e (point))
11490           (forward-line -1)             ; back to `b'
11491           (gnus-add-text-properties
11492            b (1- e) (list 'gnus-number gnus-reffed-article-number
11493                           gnus-mouse-face-prop gnus-mouse-face))
11494           (gnus-data-enter
11495            after-article gnus-reffed-article-number
11496            gnus-unread-mark b (car pslist) 0 (- e b))
11497           (setq gnus-newsgroup-unreads
11498                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11499                                          gnus-reffed-article-number))
11500           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11501           (setq pslist (cdr pslist)))))))
11502
11503 (defun gnus-pseudos< (p1 p2)
11504   (let ((c1 (cdr (assq 'action p1)))
11505         (c2 (cdr (assq 'action p2))))
11506     (and c1 c2 (string< c1 c2))))
11507
11508 (defun gnus-request-pseudo-article (props)
11509   (cond ((assq 'execute props)
11510          (gnus-execute-command (cdr (assq 'execute props)))))
11511   (let ((gnus-current-article (gnus-summary-article-number)))
11512     (gnus-run-hooks 'gnus-mark-article-hook)))
11513
11514 (defun gnus-execute-command (command &optional automatic)
11515   (save-excursion
11516     (gnus-article-setup-buffer)
11517     (set-buffer gnus-article-buffer)
11518     (setq buffer-read-only nil)
11519     (let ((command (if automatic command
11520                      (read-string "Command: " (cons command 0)))))
11521       (erase-buffer)
11522       (insert "$ " command "\n\n")
11523       (if gnus-view-pseudo-asynchronously
11524           (start-process "gnus-execute" (current-buffer) shell-file-name
11525                          shell-command-switch command)
11526         (call-process shell-file-name nil t nil
11527                       shell-command-switch command)))))
11528
11529 ;; Summary kill commands.
11530
11531 (defun gnus-summary-edit-global-kill (article)
11532   "Edit the \"global\" kill file."
11533   (interactive (list (gnus-summary-article-number)))
11534   (gnus-group-edit-global-kill article))
11535
11536 (defun gnus-summary-edit-local-kill ()
11537   "Edit a local kill file applied to the current newsgroup."
11538   (interactive)
11539   (setq gnus-current-headers (gnus-summary-article-header))
11540   (gnus-group-edit-local-kill
11541    (gnus-summary-article-number) gnus-newsgroup-name))
11542
11543 ;;; Header reading.
11544
11545 (defun gnus-read-header (id &optional header)
11546   "Read the headers of article ID and enter them into the Gnus system."
11547   (let ((group gnus-newsgroup-name)
11548         (gnus-override-method
11549          (or
11550           gnus-override-method
11551           (and (gnus-news-group-p gnus-newsgroup-name)
11552                (car (gnus-refer-article-methods)))))
11553         where)
11554     ;; First we check to see whether the header in question is already
11555     ;; fetched.
11556     (if (stringp id)
11557         ;; This is a Message-ID.
11558         (setq header (or header (gnus-id-to-header id)))
11559       ;; This is an article number.
11560       (setq header (or header (gnus-summary-article-header id))))
11561     (if (and header
11562              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11563         ;; We have found the header.
11564         header
11565       ;; We have to really fetch the header to this article.
11566       (save-excursion
11567         (set-buffer nntp-server-buffer)
11568         (when (setq where (gnus-request-head id group))
11569           (nnheader-fold-continuation-lines)
11570           (goto-char (point-max))
11571           (insert ".\n")
11572           (goto-char (point-min))
11573           (insert "211 ")
11574           (princ (cond
11575                   ((numberp id) id)
11576                   ((cdr where) (cdr where))
11577                   (header (mail-header-number header))
11578                   (t gnus-reffed-article-number))
11579                  (current-buffer))
11580           (insert " Article retrieved.\n"))
11581         (if (or (not where)
11582                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11583             ()                          ; Malformed head.
11584           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11585             (when (and (stringp id)
11586                        (not (string= (gnus-group-real-name group)
11587                                      (car where))))
11588               ;; If we fetched by Message-ID and the article came
11589               ;; from a different group, we fudge some bogus article
11590               ;; numbers for this article.
11591               (mail-header-set-number header gnus-reffed-article-number))
11592             (save-excursion
11593               (set-buffer gnus-summary-buffer)
11594               (decf gnus-reffed-article-number)
11595               (gnus-remove-header (mail-header-number header))
11596               (push header gnus-newsgroup-headers)
11597               (setq gnus-current-headers header)
11598               (push (mail-header-number header) gnus-newsgroup-limit)))
11599           header)))))
11600
11601 (defun gnus-remove-header (number)
11602   "Remove header NUMBER from `gnus-newsgroup-headers'."
11603   (if (and gnus-newsgroup-headers
11604            (= number (mail-header-number (car gnus-newsgroup-headers))))
11605       (pop gnus-newsgroup-headers)
11606     (let ((headers gnus-newsgroup-headers))
11607       (while (and (cdr headers)
11608                   (not (= number (mail-header-number (cadr headers)))))
11609         (pop headers))
11610       (when (cdr headers)
11611         (setcdr headers (cddr headers))))))
11612
11613 ;;;
11614 ;;; summary highlights
11615 ;;;
11616
11617 (defun gnus-highlight-selected-summary ()
11618   "Highlight selected article in summary buffer."
11619   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11620   (when gnus-summary-selected-face
11621     (save-excursion
11622       (let* ((beg (point-at-bol))
11623              (end (point-at-eol))
11624              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11625              (from (if (get-text-property beg gnus-mouse-face-prop)
11626                        beg
11627                      (or (next-single-property-change
11628                           beg gnus-mouse-face-prop nil end)
11629                          beg)))
11630              (to
11631               (if (= from end)
11632                   (- from 2)
11633                 (or (next-single-property-change
11634                      from gnus-mouse-face-prop nil end)
11635                     end))))
11636         ;; If no mouse-face prop on line we will have to = from = end,
11637         ;; so we highlight the entire line instead.
11638         (when (= (+ to 2) from)
11639           (setq from beg)
11640           (setq to end))
11641         (if gnus-newsgroup-selected-overlay
11642             ;; Move old overlay.
11643             (gnus-move-overlay
11644              gnus-newsgroup-selected-overlay from to (current-buffer))
11645           ;; Create new overlay.
11646           (gnus-overlay-put
11647            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11648            'face gnus-summary-selected-face))))))
11649
11650 (defvar gnus-summary-highlight-line-cached nil)
11651 (defvar gnus-summary-highlight-line-trigger nil)
11652
11653 (defun gnus-summary-highlight-line-0 ()
11654   (if (and (eq gnus-summary-highlight-line-trigger
11655                gnus-summary-highlight)
11656            gnus-summary-highlight-line-cached)
11657       gnus-summary-highlight-line-cached
11658     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11659           gnus-summary-highlight-line-cached
11660           (let* ((cond (list 'cond))
11661                  (c cond)
11662                  (list gnus-summary-highlight))
11663             (while list
11664               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11665                               nil))
11666               (setq c (cdr c)
11667                     list (cdr list)))
11668             (gnus-byte-compile (list 'lambda nil cond))))))
11669
11670 (defun gnus-summary-highlight-line ()
11671   "Highlight current line according to `gnus-summary-highlight'."
11672   (let* ((beg (point-at-bol))
11673          (article (or (gnus-summary-article-number) gnus-current-article))
11674          (score (or (cdr (assq article
11675                                gnus-newsgroup-scored))
11676                     gnus-summary-default-score 0))
11677          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11678          (inhibit-read-only t)
11679          (default gnus-summary-default-score)
11680          (default-high gnus-summary-default-high-score)
11681          (default-low gnus-summary-default-low-score)
11682          (uncached (and gnus-summary-use-undownloaded-faces
11683                         (memq article gnus-newsgroup-undownloaded)
11684                         (not (memq article gnus-newsgroup-cached)))))
11685     (let ((face (funcall (gnus-summary-highlight-line-0))))
11686       (unless (eq face (get-text-property beg 'face))
11687         (gnus-put-text-property-excluding-characters-with-faces
11688          beg (point-at-eol) 'face
11689          (setq face (if (boundp face) (symbol-value face) face)))
11690         (when gnus-summary-highlight-line-function
11691           (funcall gnus-summary-highlight-line-function article face))))))
11692
11693 (defun gnus-update-read-articles (group unread &optional compute)
11694   "Update the list of read articles in GROUP.
11695 UNREAD is a sorted list."
11696   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11697         (info (gnus-get-info group))
11698         (prev 1)
11699         read)
11700     (if (or (not info) (not active))
11701         ;; There is no info on this group if it was, in fact,
11702         ;; killed.  Gnus stores no information on killed groups, so
11703         ;; there's nothing to be done.
11704         ;; One could store the information somewhere temporarily,
11705         ;; perhaps...  Hmmm...
11706         ()
11707       ;; Remove any negative articles numbers.
11708       (while (and unread (< (car unread) 0))
11709         (setq unread (cdr unread)))
11710       ;; Remove any expired article numbers
11711       (while (and unread (< (car unread) (car active)))
11712         (setq unread (cdr unread)))
11713       ;; Compute the ranges of read articles by looking at the list of
11714       ;; unread articles.
11715       (while unread
11716         (when (/= (car unread) prev)
11717           (push (if (= prev (1- (car unread))) prev
11718                   (cons prev (1- (car unread))))
11719                 read))
11720         (setq prev (1+ (car unread)))
11721         (setq unread (cdr unread)))
11722       (when (<= prev (cdr active))
11723         (push (cons prev (cdr active)) read))
11724       (setq read (if (> (length read) 1) (nreverse read) read))
11725       (if compute
11726           read
11727         (save-excursion
11728           (let (setmarkundo)
11729             ;; Propagate the read marks to the backend.
11730             (when (gnus-check-backend-function 'request-set-mark group)
11731               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11732                     (add (gnus-remove-from-range read (gnus-info-read info))))
11733                 (when (or add del)
11734                   (unless (gnus-check-group group)
11735                     (error "Can't open server for %s" group))
11736                   (gnus-request-set-mark
11737                    group (delq nil (list (if add (list add 'add '(read)))
11738                                          (if del (list del 'del '(read))))))
11739                   (setq setmarkundo
11740                         `(gnus-request-set-mark
11741                           ,group
11742                           ',(delq nil (list
11743                                        (if del (list del 'add '(read)))
11744                                        (if add (list add 'del '(read))))))))))
11745             (set-buffer gnus-group-buffer)
11746             (gnus-undo-register
11747               `(progn
11748                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11749                  (gnus-info-set-read ',info ',(gnus-info-read info))
11750                  (gnus-get-unread-articles-in-group ',info
11751                                                     (gnus-active ,group))
11752                  (gnus-group-update-group ,group t)
11753                  ,setmarkundo))))
11754         ;; Enter this list into the group info.
11755         (gnus-info-set-read info read)
11756         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11757         (gnus-get-unread-articles-in-group info (gnus-active group))
11758         t))))
11759
11760 (defun gnus-offer-save-summaries ()
11761   "Offer to save all active summary buffers."
11762   (let (buffers)
11763     ;; Go through all buffers and find all summaries.
11764     (dolist (buffer (buffer-list))
11765       (when (and (setq buffer (buffer-name buffer))
11766                  (string-match "Summary" buffer)
11767                  (with-current-buffer buffer
11768                    ;; We check that this is, indeed, a summary buffer.
11769                    (and (eq major-mode 'gnus-summary-mode)
11770                         ;; Also make sure this isn't bogus.
11771                         gnus-newsgroup-prepared
11772                         ;; Also make sure that this isn't a
11773                         ;; dead summary buffer.
11774                         (not gnus-dead-summary-mode))))
11775         (push buffer buffers)))
11776     ;; Go through all these summary buffers and offer to save them.
11777     (when buffers
11778       (save-excursion
11779         (map-y-or-n-p
11780          "Update summary buffer %s? "
11781          (lambda (buf)
11782            (switch-to-buffer buf)
11783            (gnus-summary-exit))
11784          buffers)))))
11785
11786 (defun gnus-summary-setup-default-charset ()
11787   "Setup newsgroup default charset."
11788   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11789       (setq gnus-newsgroup-charset nil)
11790     (let* ((ignored-charsets
11791             (or gnus-newsgroup-ephemeral-ignored-charsets
11792                 (append
11793                  (and gnus-newsgroup-name
11794                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11795                  gnus-newsgroup-ignored-charsets))))
11796       (setq gnus-newsgroup-charset
11797             (or gnus-newsgroup-ephemeral-charset
11798                 (and gnus-newsgroup-name
11799                      (gnus-parameter-charset gnus-newsgroup-name))
11800                 gnus-default-charset))
11801       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11802            ignored-charsets))))
11803
11804 ;;;
11805 ;;; Mime Commands
11806 ;;;
11807
11808 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11809   "Display the current article buffer fully MIME-buttonized.
11810 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11811 treated as multipart/mixed."
11812   (interactive "P")
11813   (require 'gnus-art)
11814   (let ((gnus-unbuttonized-mime-types nil)
11815         (gnus-mime-display-multipart-as-mixed show-all-parts))
11816     (gnus-summary-show-article)))
11817
11818 (defun gnus-summary-repair-multipart (article)
11819   "Add a Content-Type header to a multipart article without one."
11820   (interactive (list (gnus-summary-article-number)))
11821   (gnus-with-article article
11822     (message-narrow-to-head)
11823     (message-remove-header "Mime-Version")
11824     (goto-char (point-max))
11825     (insert "Mime-Version: 1.0\n")
11826     (widen)
11827     (when (search-forward "\n--" nil t)
11828       (let ((separator (buffer-substring (point) (point-at-eol))))
11829         (message-narrow-to-head)
11830         (message-remove-header "Content-Type")
11831         (goto-char (point-max))
11832         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11833                         separator))
11834         (widen))))
11835   (let (gnus-mark-article-hook)
11836     (gnus-summary-select-article t t nil article)))
11837
11838 (defun gnus-summary-toggle-display-buttonized ()
11839   "Toggle the buttonizing of the article buffer."
11840   (interactive)
11841   (require 'gnus-art)
11842   (if (setq gnus-inhibit-mime-unbuttonizing
11843             (not gnus-inhibit-mime-unbuttonizing))
11844       (let ((gnus-unbuttonized-mime-types nil))
11845         (gnus-summary-show-article))
11846     (gnus-summary-show-article)))
11847
11848 ;;;
11849 ;;; Generic summary marking commands
11850 ;;;
11851
11852 (defvar gnus-summary-marking-alist
11853   '((read gnus-del-mark "d")
11854     (unread gnus-unread-mark "u")
11855     (ticked gnus-ticked-mark "!")
11856     (dormant gnus-dormant-mark "?")
11857     (expirable gnus-expirable-mark "e"))
11858   "An alist of names/marks/keystrokes.")
11859
11860 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11861 (defvar gnus-summary-mark-map)
11862
11863 (defun gnus-summary-make-all-marking-commands ()
11864   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11865   (dolist (elem gnus-summary-marking-alist)
11866     (apply 'gnus-summary-make-marking-command elem)))
11867
11868 (defun gnus-summary-make-marking-command (name mark keystroke)
11869   (let ((map (make-sparse-keymap)))
11870     (define-key gnus-summary-generic-mark-map keystroke map)
11871     (dolist (lway `((next "next" next nil "n")
11872                     (next-unread "next unread" next t "N")
11873                     (prev "previous" prev nil "p")
11874                     (prev-unread "previous unread" prev t "P")
11875                     (nomove "" nil nil ,keystroke)))
11876       (let ((func (gnus-summary-make-marking-command-1
11877                    mark (car lway) lway name)))
11878         (setq func (eval func))
11879         (define-key map (nth 4 lway) func)))))
11880
11881 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11882   `(defun ,(intern
11883             (format "gnus-summary-put-mark-as-%s%s"
11884                     name (if (eq way 'nomove)
11885                              ""
11886                            (concat "-" (symbol-name way)))))
11887      (n)
11888      ,(format
11889        "Mark the current article as %s%s.
11890 If N, the prefix, then repeat N times.
11891 If N is negative, move in reverse order.
11892 The difference between N and the actual number of articles marked is
11893 returned."
11894        name (cadr lway))
11895      (interactive "p")
11896      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11897
11898 (defun gnus-summary-generic-mark (n mark move unread)
11899   "Mark N articles with MARK."
11900   (unless (eq major-mode 'gnus-summary-mode)
11901     (error "This command can only be used in the summary buffer"))
11902   (gnus-summary-show-thread)
11903   (let ((nummove
11904          (cond
11905           ((eq move 'next) 1)
11906           ((eq move 'prev) -1)
11907           (t 0))))
11908     (if (zerop nummove)
11909         (setq n 1)
11910       (when (< n 0)
11911         (setq n (abs n)
11912               nummove (* -1 nummove))))
11913     (while (and (> n 0)
11914                 (gnus-summary-mark-article nil mark)
11915                 (zerop (gnus-summary-next-subject nummove unread t)))
11916       (setq n (1- n)))
11917     (when (/= 0 n)
11918       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11919     (gnus-summary-recenter)
11920     (gnus-summary-position-point)
11921     (gnus-set-mode-line 'summary)
11922     n))
11923
11924 (defun gnus-summary-insert-articles (articles)
11925   (when (setq articles
11926               (gnus-sorted-difference articles
11927                                       (mapcar (lambda (h)
11928                                                 (mail-header-number h))
11929                                               gnus-newsgroup-headers)))
11930     (setq gnus-newsgroup-headers
11931           (gnus-merge 'list
11932                       gnus-newsgroup-headers
11933                       (gnus-fetch-headers articles)
11934                       'gnus-article-sort-by-number))
11935     ;; Suppress duplicates?
11936     (when gnus-suppress-duplicates
11937       (gnus-dup-suppress-articles))
11938
11939     ;; We might want to build some more threads first.
11940     (when (and gnus-fetch-old-headers
11941                (eq gnus-headers-retrieved-by 'nov))
11942       (if (eq gnus-fetch-old-headers 'invisible)
11943           (gnus-build-all-threads)
11944         (gnus-build-old-threads)))
11945     ;; Let the Gnus agent mark articles as read.
11946     (when gnus-agent
11947       (gnus-agent-get-undownloaded-list))
11948     ;; Remove list identifiers from subject
11949     (when gnus-list-identifiers
11950       (gnus-summary-remove-list-identifiers))
11951     ;; First and last article in this newsgroup.
11952     (when gnus-newsgroup-headers
11953       (setq gnus-newsgroup-begin
11954             (mail-header-number (car gnus-newsgroup-headers))
11955             gnus-newsgroup-end
11956             (mail-header-number
11957              (gnus-last-element gnus-newsgroup-headers))))
11958     (when gnus-use-scoring
11959       (gnus-possibly-score-headers))))
11960
11961 (defun gnus-summary-insert-old-articles (&optional all)
11962   "Insert all old articles in this group.
11963 If ALL is non-nil, already read articles become readable.
11964 If ALL is a number, fetch this number of articles."
11965   (interactive "P")
11966   (prog1
11967       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11968             older len)
11969         (setq older
11970               ;; Some nntp servers lie about their active range.  When
11971               ;; this happens, the active range can be in the millions.
11972               ;; Use a compressed range to avoid creating a huge list.
11973               (gnus-range-difference (list gnus-newsgroup-active) old))
11974         (setq len (gnus-range-length older))
11975         (cond
11976          ((null older) nil)
11977          ((numberp all)
11978           (if (< all len)
11979               (let ((older-range (nreverse older)))
11980                 (setq older nil)
11981
11982                 (while (> all 0)
11983                   (let* ((r (pop older-range))
11984                          (min (if (numberp r) r (car r)))
11985                          (max (if (numberp r) r (cdr r))))
11986                     (while (and (<= min max)
11987                                 (> all 0))
11988                       (push max older)
11989                       (setq all (1- all)
11990                             max (1- max))))))
11991             (setq older (gnus-uncompress-range older))))
11992          (all
11993           (setq older (gnus-uncompress-range older)))
11994          (t
11995           (when (and (numberp gnus-large-newsgroup)
11996                    (> len gnus-large-newsgroup))
11997               (let* ((cursor-in-echo-area nil)
11998                      (initial (gnus-parameter-large-newsgroup-initial
11999                                gnus-newsgroup-name))
12000                      (input
12001                       (read-string
12002                        (format
12003                         "How many articles from %s (%s %d): "
12004                         (gnus-limit-string
12005                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12006                         (if initial "max" "default")
12007                         len)
12008                        (if initial
12009                            (cons (number-to-string initial)
12010                                  0)))))
12011                 (unless (string-match "^[ \t]*$" input)
12012                   (setq all (string-to-number input))
12013                   (if (< all len)
12014                       (let ((older-range (nreverse older)))
12015                         (setq older nil)
12016
12017                         (while (> all 0)
12018                           (let* ((r (pop older-range))
12019                                  (min (if (numberp r) r (car r)))
12020                                  (max (if (numberp r) r (cdr r))))
12021                             (while (and (<= min max)
12022                                         (> all 0))
12023                               (push max older)
12024                               (setq all (1- all)
12025                                     max (1- max))))))))))
12026           (setq older (gnus-uncompress-range older))))
12027         (if (not older)
12028             (message "No old news.")
12029           (gnus-summary-insert-articles older)
12030           (gnus-summary-limit (gnus-sorted-nunion old older))))
12031     (gnus-summary-position-point)))
12032
12033 (defun gnus-summary-insert-new-articles ()
12034   "Insert all new articles in this group."
12035   (interactive)
12036   (prog1
12037       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12038             (old-active gnus-newsgroup-active)
12039             (nnmail-fetched-sources (list t))
12040             i new)
12041         (setq gnus-newsgroup-active
12042               (gnus-activate-group gnus-newsgroup-name 'scan))
12043         (setq i (cdr gnus-newsgroup-active))
12044         (while (> i (cdr old-active))
12045           (push i new)
12046           (decf i))
12047         (if (not new)
12048             (message "No gnus is bad news")
12049           (gnus-summary-insert-articles new)
12050           (setq gnus-newsgroup-unreads
12051                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12052           (gnus-summary-limit (gnus-sorted-nunion old new))))
12053     (gnus-summary-position-point)))
12054
12055 (gnus-summary-make-all-marking-commands)
12056
12057 (gnus-ems-redefine)
12058
12059 (provide 'gnus-sum)
12060
12061 (run-hooks 'gnus-sum-load-hook)
12062
12063 ;; Local Variables:
12064 ;; coding: iso-8859-1
12065 ;; End:
12066
12067 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12068 ;;; gnus-sum.el ends here