* ecomplete.el (ecomplete-add-item): Chop off decimals.
[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
2704      :visible (and (fboundp 'spam-group-ham-contents-p)
2705                    (spam-group-ham-contents-p gnus-newsgroup-name))
2706      :help "Mark as spam")
2707     (gnus-summary-mark-as-read-forward
2708      "mail/not-spam" nil
2709      :visible (and (fboundp 'spam-group-spam-contents-p)
2710                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2711     ;;
2712     (gnus-summary-exit "exit")
2713     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2714     (gnus-info-find-node "help"))
2715   "List of functions for the summary tool bar (GNOME style).
2716
2717 See `gmm-tool-bar-from-list' for the format of the list."
2718   :type '(repeat gmm-tool-bar-item)
2719   :version "23.0" ;; No Gnus
2720   :initialize 'custom-initialize-default
2721   :set 'gnus-summary-tool-bar-update
2722   :group 'gnus-summary)
2723
2724 (defcustom gnus-summary-tool-bar-retro
2725   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2726     (gnus-summary-next-unread-article "gnus/next-ur")
2727     (gnus-summary-post-news "gnus/post")
2728     (gnus-summary-followup-with-original "gnus/fuwo")
2729     (gnus-summary-followup "gnus/followup")
2730     (gnus-summary-reply-with-original "gnus/reply-wo")
2731     (gnus-summary-reply "gnus/reply")
2732     (gnus-summary-caesar-message "gnus/rot13")
2733     (gnus-uu-decode-uu "gnus/uu-decode")
2734     (gnus-summary-save-article-file "gnus/save-aif")
2735     (gnus-summary-save-article "gnus/save-art")
2736     (gnus-uu-post-news "gnus/uu-post")
2737     (gnus-summary-catchup "gnus/catchup")
2738     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2739     (gnus-summary-exit "gnus/exit-summ")
2740     ;; Some new command that may need more suitable icons:
2741     (gnus-summary-print-article "gnus/print" nil :visible nil)
2742     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2743     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2744     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2745     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2746     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2747     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2748     ;;
2749     (gnus-info-find-node "gnus/help" nil :visible nil))
2750   "List of functions for the summary tool bar (retro look).
2751
2752 See `gmm-tool-bar-from-list' for the format of the list."
2753   :type '(repeat gmm-tool-bar-item)
2754   :version "23.0" ;; No Gnus
2755   :initialize 'custom-initialize-default
2756   :set 'gnus-summary-tool-bar-update
2757   :group 'gnus-summary)
2758
2759 (defcustom gnus-summary-tool-bar-zap-list t
2760   "List of icon items from the global tool bar.
2761 These items are not displayed in the Gnus summary mode tool bar.
2762
2763 See `gmm-tool-bar-from-list' for the format of the list."
2764   :type 'gmm-tool-bar-zap-list
2765   :version "23.0" ;; No Gnus
2766   :initialize 'custom-initialize-default
2767   :set 'gnus-summary-tool-bar-update
2768   :group 'gnus-summary)
2769
2770 (defvar image-load-path)
2771
2772 (defun gnus-summary-make-tool-bar (&optional force)
2773   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2774 When FORCE, rebuild the tool bar."
2775   (when (and (not (featurep 'xemacs))
2776              (boundp 'tool-bar-mode)
2777              tool-bar-mode
2778              (or (not gnus-summary-tool-bar-map) force))
2779     (let* ((load-path
2780             (gmm-image-load-path-for-library "gnus"
2781                                              "mail/save.xpm"
2782                                              nil t))
2783            (image-load-path (cons (car load-path)
2784                                   (when (boundp 'image-load-path)
2785                                     image-load-path)))
2786            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2787                                         gnus-summary-tool-bar-zap-list
2788                                         'gnus-summary-mode-map)))
2789       (when map
2790         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2791         ;; uses it's value.
2792         (setq gnus-summary-tool-bar-map map))))
2793   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2794
2795 (defun gnus-score-set-default (var value)
2796   "A version of set that updates the GNU Emacs menu-bar."
2797   (set var value)
2798   ;; It is the message that forces the active status to be updated.
2799   (message ""))
2800
2801 (defun gnus-make-score-map (type)
2802   "Make a summary score map of type TYPE."
2803   (if t
2804       nil
2805     (let ((headers '(("author" "from" string)
2806                      ("subject" "subject" string)
2807                      ("article body" "body" string)
2808                      ("article head" "head" string)
2809                      ("xref" "xref" string)
2810                      ("extra header" "extra" string)
2811                      ("lines" "lines" number)
2812                      ("followups to author" "followup" string)))
2813           (types '((number ("less than" <)
2814                            ("greater than" >)
2815                            ("equal" =))
2816                    (string ("substring" s)
2817                            ("exact string" e)
2818                            ("fuzzy string" f)
2819                            ("regexp" r))))
2820           (perms '(("temporary" (current-time-string))
2821                    ("permanent" nil)
2822                    ("immediate" now)))
2823           header)
2824       (list
2825        (apply
2826         'nconc
2827         (list
2828          (if (eq type 'lower)
2829              "Lower score"
2830            "Increase score"))
2831         (let (outh)
2832           (while headers
2833             (setq header (car headers))
2834             (setq outh
2835                   (cons
2836                    (apply
2837                     'nconc
2838                     (list (car header))
2839                     (let ((ts (cdr (assoc (nth 2 header) types)))
2840                           outt)
2841                       (while ts
2842                         (setq outt
2843                               (cons
2844                                (apply
2845                                 'nconc
2846                                 (list (caar ts))
2847                                 (let ((ps perms)
2848                                       outp)
2849                                   (while ps
2850                                     (setq outp
2851                                           (cons
2852                                            (vector
2853                                             (caar ps)
2854                                             (list
2855                                              'gnus-summary-score-entry
2856                                              (nth 1 header)
2857                                              (if (or (string= (nth 1 header)
2858                                                               "head")
2859                                                      (string= (nth 1 header)
2860                                                               "body"))
2861                                                  ""
2862                                                (list 'gnus-summary-header
2863                                                      (nth 1 header)))
2864                                              (list 'quote (nth 1 (car ts)))
2865                                              (list 'gnus-score-delta-default
2866                                                    nil)
2867                                              (nth 1 (car ps))
2868                                              t)
2869                                             t)
2870                                            outp))
2871                                     (setq ps (cdr ps)))
2872                                   (list (nreverse outp))))
2873                                outt))
2874                         (setq ts (cdr ts)))
2875                       (list (nreverse outt))))
2876                    outh))
2877             (setq headers (cdr headers)))
2878           (list (nreverse outh))))))))
2879
2880 \f
2881
2882 (defun gnus-summary-mode (&optional group)
2883   "Major mode for reading articles.
2884
2885 All normal editing commands are switched off.
2886 \\<gnus-summary-mode-map>
2887 Each line in this buffer represents one article.  To read an
2888 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2889 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2890 respectively.
2891
2892 You can also post articles and send mail from this buffer.  To
2893 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2894 of an article, type `\\[gnus-summary-reply]'.
2895
2896 There are approx. one gazillion commands you can execute in this
2897 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2898
2899 The following commands are available:
2900
2901 \\{gnus-summary-mode-map}"
2902   (interactive)
2903   (kill-all-local-variables)
2904   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2905     (gnus-summary-make-local-variables))
2906   (gnus-summary-make-local-variables)
2907   (setq gnus-newsgroup-name group)
2908   (when (gnus-visual-p 'summary-menu 'menu)
2909     (gnus-summary-make-menu-bar)
2910     (gnus-summary-make-tool-bar))
2911   (gnus-make-thread-indent-array)
2912   (gnus-simplify-mode-line)
2913   (setq major-mode 'gnus-summary-mode)
2914   (setq mode-name "Summary")
2915   (make-local-variable 'minor-mode-alist)
2916   (use-local-map gnus-summary-mode-map)
2917   (buffer-disable-undo)
2918   (setq buffer-read-only t              ;Disable modification
2919         show-trailing-whitespace nil)
2920   (setq truncate-lines t)
2921   (setq selective-display t)
2922   (setq selective-display-ellipses t)   ;Display `...'
2923   (gnus-summary-set-display-table)
2924   (gnus-set-default-directory)
2925   (make-local-variable 'gnus-summary-line-format)
2926   (make-local-variable 'gnus-summary-line-format-spec)
2927   (make-local-variable 'gnus-summary-dummy-line-format)
2928   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2929   (make-local-variable 'gnus-summary-mark-positions)
2930   (gnus-make-local-hook 'pre-command-hook)
2931   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2932   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2933   (turn-on-gnus-mailing-list-mode)
2934   (mm-enable-multibyte)
2935   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2936   (gnus-update-summary-mark-positions))
2937
2938 (defun gnus-summary-make-local-variables ()
2939   "Make all the local summary buffer variables."
2940   (let (global)
2941     (dolist (local gnus-summary-local-variables)
2942       (if (consp local)
2943           (progn
2944             (if (eq (cdr local) 'global)
2945                 ;; Copy the global value of the variable.
2946                 (setq global (symbol-value (car local)))
2947               ;; Use the value from the list.
2948               (setq global (eval (cdr local))))
2949             (set (make-local-variable (car local)) global))
2950         ;; Simple nil-valued local variable.
2951         (set (make-local-variable local) nil)))))
2952
2953 (defun gnus-summary-clear-local-variables ()
2954   (let ((locals gnus-summary-local-variables))
2955     (while locals
2956       (if (consp (car locals))
2957           (and (symbolp (caar locals))
2958                (set (caar locals) nil))
2959         (and (symbolp (car locals))
2960              (set (car locals) nil)))
2961       (setq locals (cdr locals)))))
2962
2963 ;; Summary data functions.
2964
2965 (defmacro gnus-data-number (data)
2966   `(car ,data))
2967
2968 (defmacro gnus-data-set-number (data number)
2969   `(setcar ,data ,number))
2970
2971 (defmacro gnus-data-mark (data)
2972   `(nth 1 ,data))
2973
2974 (defmacro gnus-data-set-mark (data mark)
2975   `(setcar (nthcdr 1 ,data) ,mark))
2976
2977 (defmacro gnus-data-pos (data)
2978   `(nth 2 ,data))
2979
2980 (defmacro gnus-data-set-pos (data pos)
2981   `(setcar (nthcdr 2 ,data) ,pos))
2982
2983 (defmacro gnus-data-header (data)
2984   `(nth 3 ,data))
2985
2986 (defmacro gnus-data-set-header (data header)
2987   `(setf (nth 3 ,data) ,header))
2988
2989 (defmacro gnus-data-level (data)
2990   `(nth 4 ,data))
2991
2992 (defmacro gnus-data-unread-p (data)
2993   `(= (nth 1 ,data) gnus-unread-mark))
2994
2995 (defmacro gnus-data-read-p (data)
2996   `(/= (nth 1 ,data) gnus-unread-mark))
2997
2998 (defmacro gnus-data-pseudo-p (data)
2999   `(consp (nth 3 ,data)))
3000
3001 (defmacro gnus-data-find (number)
3002   `(assq ,number gnus-newsgroup-data))
3003
3004 (defmacro gnus-data-find-list (number &optional data)
3005   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3006      (memq (assq ,number bdata)
3007            bdata)))
3008
3009 (defmacro gnus-data-make (number mark pos header level)
3010   `(list ,number ,mark ,pos ,header ,level))
3011
3012 (defun gnus-data-enter (after-article number mark pos header level offset)
3013   (let ((data (gnus-data-find-list after-article)))
3014     (unless data
3015       (error "No such article: %d" after-article))
3016     (setcdr data (cons (gnus-data-make number mark pos header level)
3017                        (cdr data)))
3018     (setq gnus-newsgroup-data-reverse nil)
3019     (gnus-data-update-list (cddr data) offset)))
3020
3021 (defun gnus-data-enter-list (after-article list &optional offset)
3022   (when list
3023     (let ((data (and after-article (gnus-data-find-list after-article)))
3024           (ilist list))
3025       (if (not (or data
3026                    after-article))
3027           (let ((odata gnus-newsgroup-data))
3028             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3029             (when offset
3030               (gnus-data-update-list odata offset)))
3031         ;; Find the last element in the list to be spliced into the main
3032         ;; list.
3033         (setq list (last list))
3034         (if (not data)
3035             (progn
3036               (setcdr list gnus-newsgroup-data)
3037               (setq gnus-newsgroup-data ilist)
3038               (when offset
3039                 (gnus-data-update-list (cdr list) offset)))
3040           (setcdr list (cdr data))
3041           (setcdr data ilist)
3042           (when offset
3043             (gnus-data-update-list (cdr list) offset))))
3044       (setq gnus-newsgroup-data-reverse nil))))
3045
3046 (defun gnus-data-remove (article &optional offset)
3047   (let ((data gnus-newsgroup-data))
3048     (if (= (gnus-data-number (car data)) article)
3049         (progn
3050           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3051                 gnus-newsgroup-data-reverse nil)
3052           (when offset
3053             (gnus-data-update-list gnus-newsgroup-data offset)))
3054       (while (cdr data)
3055         (when (= (gnus-data-number (cadr data)) article)
3056           (setcdr data (cddr data))
3057           (when offset
3058             (gnus-data-update-list (cdr data) offset))
3059           (setq data nil
3060                 gnus-newsgroup-data-reverse nil))
3061         (setq data (cdr data))))))
3062
3063 (defmacro gnus-data-list (backward)
3064   `(if ,backward
3065        (or gnus-newsgroup-data-reverse
3066            (setq gnus-newsgroup-data-reverse
3067                  (reverse gnus-newsgroup-data)))
3068      gnus-newsgroup-data))
3069
3070 (defun gnus-data-update-list (data offset)
3071   "Add OFFSET to the POS of all data entries in DATA."
3072   (setq gnus-newsgroup-data-reverse nil)
3073   (while data
3074     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3075     (setq data (cdr data))))
3076
3077 (defun gnus-summary-article-pseudo-p (article)
3078   "Say whether this article is a pseudo article or not."
3079   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3080
3081 (defmacro gnus-summary-article-sparse-p (article)
3082   "Say whether this article is a sparse article or not."
3083   `(memq ,article gnus-newsgroup-sparse))
3084
3085 (defmacro gnus-summary-article-ancient-p (article)
3086   "Say whether this article is a sparse article or not."
3087   `(memq ,article gnus-newsgroup-ancient))
3088
3089 (defun gnus-article-parent-p (number)
3090   "Say whether this article is a parent or not."
3091   (let ((data (gnus-data-find-list number)))
3092     (and (cdr data)              ; There has to be an article after...
3093          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3094             (gnus-data-level (nth 1 data))))))
3095
3096 (defun gnus-article-children (number)
3097   "Return a list of all children to NUMBER."
3098   (let* ((data (gnus-data-find-list number))
3099          (level (gnus-data-level (car data)))
3100          children)
3101     (setq data (cdr data))
3102     (while (and data
3103                 (= (gnus-data-level (car data)) (1+ level)))
3104       (push (gnus-data-number (car data)) children)
3105       (setq data (cdr data)))
3106     children))
3107
3108 (defmacro gnus-summary-skip-intangible ()
3109   "If the current article is intangible, then jump to a different article."
3110   '(let ((to (get-text-property (point) 'gnus-intangible)))
3111      (and to (gnus-summary-goto-subject to))))
3112
3113 (defmacro gnus-summary-article-intangible-p ()
3114   "Say whether this article is intangible or not."
3115   '(get-text-property (point) 'gnus-intangible))
3116
3117 (defun gnus-article-read-p (article)
3118   "Say whether ARTICLE is read or not."
3119   (not (or (memq article gnus-newsgroup-marked)
3120            (memq article gnus-newsgroup-spam-marked)
3121            (memq article gnus-newsgroup-unreads)
3122            (memq article gnus-newsgroup-unselected)
3123            (memq article gnus-newsgroup-dormant))))
3124
3125 ;; Some summary mode macros.
3126
3127 (defmacro gnus-summary-article-number ()
3128   "The article number of the article on the current line.
3129 If there isn't an article number here, then we return the current
3130 article number."
3131   '(progn
3132      (gnus-summary-skip-intangible)
3133      (or (get-text-property (point) 'gnus-number)
3134          (gnus-summary-last-subject))))
3135
3136 (defmacro gnus-summary-article-header (&optional number)
3137   "Return the header of article NUMBER."
3138   `(gnus-data-header (gnus-data-find
3139                       ,(or number '(gnus-summary-article-number)))))
3140
3141 (defmacro gnus-summary-thread-level (&optional number)
3142   "Return the level of thread that starts with article NUMBER."
3143   `(if (and (eq gnus-summary-make-false-root 'dummy)
3144             (get-text-property (point) 'gnus-intangible))
3145        0
3146      (gnus-data-level (gnus-data-find
3147                        ,(or number '(gnus-summary-article-number))))))
3148
3149 (defmacro gnus-summary-article-mark (&optional number)
3150   "Return the mark of article NUMBER."
3151   `(gnus-data-mark (gnus-data-find
3152                     ,(or number '(gnus-summary-article-number)))))
3153
3154 (defmacro gnus-summary-article-pos (&optional number)
3155   "Return the position of the line of article NUMBER."
3156   `(gnus-data-pos (gnus-data-find
3157                    ,(or number '(gnus-summary-article-number)))))
3158
3159 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3160 (defmacro gnus-summary-article-subject (&optional number)
3161   "Return current subject string or nil if nothing."
3162   `(let ((headers
3163           ,(if number
3164                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3165              '(gnus-data-header (assq (gnus-summary-article-number)
3166                                       gnus-newsgroup-data)))))
3167      (and headers
3168           (vectorp headers)
3169           (mail-header-subject headers))))
3170
3171 (defmacro gnus-summary-article-score (&optional number)
3172   "Return current article score."
3173   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3174                   gnus-newsgroup-scored))
3175        gnus-summary-default-score 0))
3176
3177 (defun gnus-summary-article-children (&optional number)
3178   "Return a list of article numbers that are children of article NUMBER."
3179   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3180          (level (gnus-data-level (car data)))
3181          l children)
3182     (while (and (setq data (cdr data))
3183                 (> (setq l (gnus-data-level (car data))) level))
3184       (and (= (1+ level) l)
3185            (push (gnus-data-number (car data))
3186                  children)))
3187     (nreverse children)))
3188
3189 (defun gnus-summary-article-parent (&optional number)
3190   "Return the article number of the parent of article NUMBER."
3191   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3192                                     (gnus-data-list t)))
3193          (level (gnus-data-level (car data))))
3194     (if (zerop level)
3195         ()                              ; This is a root.
3196       ;; We search until we find an article with a level less than
3197       ;; this one.  That function has to be the parent.
3198       (while (and (setq data (cdr data))
3199                   (not (< (gnus-data-level (car data)) level))))
3200       (and data (gnus-data-number (car data))))))
3201
3202 (defun gnus-unread-mark-p (mark)
3203   "Say whether MARK is the unread mark."
3204   (= mark gnus-unread-mark))
3205
3206 (defun gnus-read-mark-p (mark)
3207   "Say whether MARK is one of the marks that mark as read.
3208 This is all marks except unread, ticked, dormant, and expirable."
3209   (not (or (= mark gnus-unread-mark)
3210            (= mark gnus-ticked-mark)
3211            (= mark gnus-spam-mark)
3212            (= mark gnus-dormant-mark)
3213            (= mark gnus-expirable-mark))))
3214
3215 (defmacro gnus-article-mark (number)
3216   "Return the MARK of article NUMBER.
3217 This macro should only be used when computing the mark the \"first\"
3218 time; i.e., when generating the summary lines.  After that,
3219 `gnus-summary-article-mark' should be used to examine the
3220 marks of articles."
3221   `(cond
3222     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3223     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3224     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3225     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3226     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3227     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3228     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3229     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3230            gnus-ancient-mark))))
3231
3232 ;; Saving hidden threads.
3233
3234 (defmacro gnus-save-hidden-threads (&rest forms)
3235   "Save hidden threads, eval FORMS, and restore the hidden threads."
3236   (let ((config (make-symbol "config")))
3237     `(let ((,config (gnus-hidden-threads-configuration)))
3238        (unwind-protect
3239            (save-excursion
3240              ,@forms)
3241          (gnus-restore-hidden-threads-configuration ,config)))))
3242 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3243 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3244
3245 (defun gnus-data-compute-positions ()
3246   "Compute the positions of all articles."
3247   (setq gnus-newsgroup-data-reverse nil)
3248   (let ((data gnus-newsgroup-data))
3249     (save-excursion
3250       (gnus-save-hidden-threads
3251         (gnus-summary-show-all-threads)
3252         (goto-char (point-min))
3253         (while data
3254           (while (get-text-property (point) 'gnus-intangible)
3255             (forward-line 1))
3256           (gnus-data-set-pos (car data) (+ (point) 3))
3257           (setq data (cdr data))
3258           (forward-line 1))))))
3259
3260 (defun gnus-hidden-threads-configuration ()
3261   "Return the current hidden threads configuration."
3262   (save-excursion
3263     (let (config)
3264       (goto-char (point-min))
3265       (while (search-forward "\r" nil t)
3266         (push (1- (point)) config))
3267       config)))
3268
3269 (defun gnus-restore-hidden-threads-configuration (config)
3270   "Restore hidden threads configuration from CONFIG."
3271   (save-excursion
3272     (let (point buffer-read-only)
3273       (while (setq point (pop config))
3274         (when (and (< point (point-max))
3275                    (goto-char point)
3276                    (eq (char-after) ?\n))
3277           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3278
3279 ;; Various summary mode internalish functions.
3280
3281 (defun gnus-mouse-pick-article (e)
3282   (interactive "e")
3283   (mouse-set-point e)
3284   (gnus-summary-next-page nil t))
3285
3286 (defun gnus-summary-set-display-table ()
3287   "Change the display table.
3288 Odd characters have a tendency to mess
3289 up nicely formatted displays - we make all possible glyphs
3290 display only a single character."
3291
3292   ;; We start from the standard display table, if any.
3293   (let ((table (or (copy-sequence standard-display-table)
3294                    (make-display-table)))
3295         (i 32))
3296     ;; Nix out all the control chars...
3297     (while (>= (setq i (1- i)) 0)
3298       (aset table i [??]))
3299    ;; ... but not newline and cr, of course.  (cr is necessary for the
3300     ;; selective display).
3301     (aset table ?\n nil)
3302     (aset table ?\r nil)
3303     ;; We keep TAB as well.
3304     (aset table ?\t nil)
3305     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3306     ;; Emacs 23 (unicode), that are not set already.
3307     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3308                  160
3309                256)))
3310       (while (>= (setq i (1- i)) 127)
3311         ;; Only modify if the entry is nil.
3312         (unless (aref table i)
3313           (aset table i [??]))))
3314     (setq buffer-display-table table)))
3315
3316 (defun gnus-summary-set-article-display-arrow (pos)
3317   "Update the overlay arrow to point to line at position POS."
3318   (when (and gnus-summary-display-arrow
3319              (boundp 'overlay-arrow-position)
3320              (boundp 'overlay-arrow-string))
3321     (save-excursion
3322       (goto-char pos)
3323       (beginning-of-line)
3324       (unless overlay-arrow-position
3325         (setq overlay-arrow-position (make-marker)))
3326       (setq overlay-arrow-string "=>"
3327             overlay-arrow-position (set-marker overlay-arrow-position
3328                                                (point)
3329                                                (current-buffer))))))
3330
3331 (defun gnus-summary-setup-buffer (group)
3332   "Initialize summary buffer."
3333   (let ((buffer (gnus-summary-buffer-name group))
3334         (dead-name (concat "*Dead Summary "
3335                            (gnus-group-decoded-name group) "*")))
3336     ;; If a dead summary buffer exists, we kill it.
3337     (when (gnus-buffer-live-p dead-name)
3338       (gnus-kill-buffer dead-name))
3339     (if (get-buffer buffer)
3340         (progn
3341           (set-buffer buffer)
3342           (setq gnus-summary-buffer (current-buffer))
3343           (not gnus-newsgroup-prepared))
3344       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3345       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3346       (gnus-summary-mode group)
3347       (when gnus-carpal
3348         (gnus-carpal-setup-buffer 'summary))
3349       (unless gnus-single-article-buffer
3350         (make-local-variable 'gnus-article-buffer)
3351         (make-local-variable 'gnus-article-current)
3352         (make-local-variable 'gnus-original-article-buffer))
3353       (setq gnus-newsgroup-name group)
3354       ;; Set any local variables in the group parameters.
3355       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3356       t)))
3357
3358 (defun gnus-set-global-variables ()
3359   "Set the global equivalents of the buffer-local variables.
3360 They are set to the latest values they had.  These reflect the summary
3361 buffer that was in action when the last article was fetched."
3362   (when (eq major-mode 'gnus-summary-mode)
3363     (setq gnus-summary-buffer (current-buffer))
3364     (let ((name gnus-newsgroup-name)
3365           (marked gnus-newsgroup-marked)
3366           (spam gnus-newsgroup-spam-marked)
3367           (unread gnus-newsgroup-unreads)
3368           (headers gnus-current-headers)
3369           (data gnus-newsgroup-data)
3370           (summary gnus-summary-buffer)
3371           (article-buffer gnus-article-buffer)
3372           (original gnus-original-article-buffer)
3373           (gac gnus-article-current)
3374           (reffed gnus-reffed-article-number)
3375           (score-file gnus-current-score-file)
3376           (default-charset gnus-newsgroup-charset)
3377           vlist)
3378       (let ((locals gnus-newsgroup-variables))
3379         (while locals
3380           (if (consp (car locals))
3381               (push (eval (caar locals)) vlist)
3382             (push (eval (car locals)) vlist))
3383           (setq locals (cdr locals)))
3384         (setq vlist (nreverse vlist)))
3385       (with-current-buffer gnus-group-buffer
3386         (setq gnus-newsgroup-name name
3387               gnus-newsgroup-marked marked
3388               gnus-newsgroup-spam-marked spam
3389               gnus-newsgroup-unreads unread
3390               gnus-current-headers headers
3391               gnus-newsgroup-data data
3392               gnus-article-current gac
3393               gnus-summary-buffer summary
3394               gnus-article-buffer article-buffer
3395               gnus-original-article-buffer original
3396               gnus-reffed-article-number reffed
3397               gnus-current-score-file score-file
3398               gnus-newsgroup-charset default-charset)
3399         (let ((locals gnus-newsgroup-variables))
3400           (while locals
3401             (if (consp (car locals))
3402                 (set (caar locals) (pop vlist))
3403               (set (car locals) (pop vlist)))
3404             (setq locals (cdr locals))))
3405         ;; The article buffer also has local variables.
3406         (when (gnus-buffer-live-p gnus-article-buffer)
3407           (set-buffer gnus-article-buffer)
3408           (setq gnus-summary-buffer summary))))))
3409
3410 (defun gnus-summary-article-unread-p (article)
3411   "Say whether ARTICLE is unread or not."
3412   (memq article gnus-newsgroup-unreads))
3413
3414 (defun gnus-summary-first-article-p (&optional article)
3415   "Return whether ARTICLE is the first article in the buffer."
3416   (if (not (setq article (or article (gnus-summary-article-number))))
3417       nil
3418     (eq article (caar gnus-newsgroup-data))))
3419
3420 (defun gnus-summary-last-article-p (&optional article)
3421   "Return whether ARTICLE is the last article in the buffer."
3422   (if (not (setq article (or article (gnus-summary-article-number))))
3423       ;; All non-existent numbers are the last article.  :-)
3424       t
3425     (not (cdr (gnus-data-find-list article)))))
3426
3427 (defun gnus-make-thread-indent-array ()
3428   (let ((n 200))
3429     (unless (and gnus-thread-indent-array
3430                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3431       (setq gnus-thread-indent-array (make-vector 201 "")
3432             gnus-thread-indent-array-level gnus-thread-indent-level)
3433       (while (>= n 0)
3434         (aset gnus-thread-indent-array n
3435               (make-string (* n gnus-thread-indent-level) ? ))
3436         (setq n (1- n))))))
3437
3438 (defun gnus-update-summary-mark-positions ()
3439   "Compute where the summary marks are to go."
3440   (save-excursion
3441     (when (gnus-buffer-exists-p gnus-summary-buffer)
3442       (set-buffer gnus-summary-buffer))
3443     (let ((spec gnus-summary-line-format-spec)
3444           pos)
3445       (save-excursion
3446         (gnus-set-work-buffer)
3447         (let ((gnus-tmp-unread ?Z)
3448               (gnus-replied-mark ?Z)
3449               (gnus-score-below-mark ?Z)
3450               (gnus-score-over-mark ?Z)
3451               (gnus-undownloaded-mark ?Z)
3452               (gnus-summary-line-format-spec spec)
3453               (gnus-newsgroup-downloadable '(0))
3454               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3455               case-fold-search ignores)
3456           ;; Here, all marks are bound to Z.
3457           (gnus-summary-insert-line header
3458                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3459           (goto-char (point-min))
3460           ;; Memorize the positions of the same characters as dummy marks.
3461           (while (re-search-forward "[A-D]" nil t)
3462             (push (point) ignores))
3463           (erase-buffer)
3464           ;; We use A-D as dummy marks in order to know column positions
3465           ;; where marks should be inserted.
3466           (setq gnus-tmp-unread ?A
3467                 gnus-replied-mark ?B
3468                 gnus-score-below-mark ?C
3469                 gnus-score-over-mark ?C
3470                 gnus-undownloaded-mark ?D)
3471           (gnus-summary-insert-line header
3472                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3473           ;; Ignore characters which aren't dummy marks.
3474           (dolist (p ignores)
3475             (delete-region (goto-char (1- p)) p)
3476             (insert ?Z))
3477           (goto-char (point-min))
3478           (setq pos (list (cons 'unread
3479                                 (and (search-forward "A" nil t)
3480                                      (- (point) (point-min) 1)))))
3481           (goto-char (point-min))
3482           (push (cons 'replied (and (search-forward "B" nil t)
3483                                     (- (point) (point-min) 1)))
3484                 pos)
3485           (goto-char (point-min))
3486           (push (cons 'score (and (search-forward "C" nil t)
3487                                   (- (point) (point-min) 1)))
3488                 pos)
3489           (goto-char (point-min))
3490           (push (cons 'download (and (search-forward "D" nil t)
3491                                      (- (point) (point-min) 1)))
3492                 pos)))
3493       (setq gnus-summary-mark-positions pos))))
3494
3495 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3496   "Insert a dummy root in the summary buffer."
3497   (beginning-of-line)
3498   (gnus-add-text-properties
3499    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3500    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3501
3502 (defun gnus-summary-extract-address-component (from)
3503   (or (car (funcall gnus-extract-address-components from))
3504       from))
3505
3506 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3507   (let ((mail-parse-charset gnus-newsgroup-charset)
3508         ; Is it really necessary to do this next part for each summary line?
3509         ; Luckily, doesn't seem to slow things down much.
3510         (mail-parse-ignored-charsets
3511          (with-current-buffer gnus-summary-buffer
3512            gnus-newsgroup-ignored-charsets)))
3513     (or
3514      (and gnus-ignored-from-addresses
3515           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3516           (let ((extra-headers (mail-header-extra header))
3517                 to
3518                 newsgroups)
3519             (cond
3520              ((setq to (cdr (assq 'To extra-headers)))
3521               (concat gnus-summary-to-prefix
3522                       (inline
3523                         (gnus-summary-extract-address-component
3524                          (funcall gnus-decode-encoded-word-function to)))))
3525              ((setq newsgroups
3526                     (or
3527                      (cdr (assq 'Newsgroups extra-headers))
3528                      (and
3529                       (memq 'Newsgroups gnus-extra-headers)
3530                       (eq (car (gnus-find-method-for-group
3531                                 gnus-newsgroup-name)) 'nntp)
3532                       (gnus-group-real-name gnus-newsgroup-name))))
3533               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3534      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3535
3536 (defun gnus-summary-insert-line (gnus-tmp-header
3537                                  gnus-tmp-level gnus-tmp-current
3538                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3539                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3540                                  &optional gnus-tmp-dummy gnus-tmp-score
3541                                  gnus-tmp-process)
3542   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3543          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3544          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3545          (gnus-tmp-score-char
3546           (if (or (null gnus-summary-default-score)
3547                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3548                       gnus-summary-zcore-fuzz))
3549               ?                         ;Whitespace
3550             (if (< gnus-tmp-score gnus-summary-default-score)
3551                 gnus-score-below-mark gnus-score-over-mark)))
3552          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3553          (gnus-tmp-replied
3554           (cond (gnus-tmp-process gnus-process-mark)
3555                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3556                  gnus-cached-mark)
3557                 (gnus-tmp-replied gnus-replied-mark)
3558                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3559                  gnus-forwarded-mark)
3560                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3561                  gnus-saved-mark)
3562                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3563                  gnus-recent-mark)
3564                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3565                  gnus-unseen-mark)
3566                 (t gnus-no-mark)))
3567          (gnus-tmp-downloaded
3568           (cond (undownloaded
3569                  gnus-undownloaded-mark)
3570                 (gnus-newsgroup-agentized
3571                  gnus-downloaded-mark)
3572                 (t
3573                  gnus-no-mark)))
3574          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3575          (gnus-tmp-name
3576           (cond
3577            ((string-match "<[^>]+> *$" gnus-tmp-from)
3578             (let ((beg (match-beginning 0)))
3579               (or (and (string-match "^\".+\"" gnus-tmp-from)
3580                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3581                   (substring gnus-tmp-from 0 beg))))
3582            ((string-match "(.+)" gnus-tmp-from)
3583             (substring gnus-tmp-from
3584                        (1+ (match-beginning 0)) (1- (match-end 0))))
3585            (t gnus-tmp-from)))
3586          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3587          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3588          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3589          (buffer-read-only nil))
3590     (when (string= gnus-tmp-name "")
3591       (setq gnus-tmp-name gnus-tmp-from))
3592     (unless (numberp gnus-tmp-lines)
3593       (setq gnus-tmp-lines -1))
3594     (if (= gnus-tmp-lines -1)
3595         (setq gnus-tmp-lines "?")
3596       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3597       (gnus-put-text-property
3598      (point)
3599      (progn (eval gnus-summary-line-format-spec) (point))
3600        'gnus-number gnus-tmp-number)
3601     (when (gnus-visual-p 'summary-highlight 'highlight)
3602       (forward-line -1)
3603       (gnus-run-hooks 'gnus-summary-update-hook)
3604       (forward-line 1))))
3605
3606 (defun gnus-summary-update-line (&optional dont-update)
3607   "Update summary line after change."
3608   (when (and gnus-summary-default-score
3609              (not gnus-summary-inhibit-highlight))
3610     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3611            (article (gnus-summary-article-number))
3612            (score (gnus-summary-article-score article)))
3613       (unless dont-update
3614         (if (and gnus-summary-mark-below
3615                  (< (gnus-summary-article-score)
3616                     gnus-summary-mark-below))
3617             ;; This article has a low score, so we mark it as read.
3618             (when (memq article gnus-newsgroup-unreads)
3619               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3620           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3621             ;; This article was previously marked as read on account
3622             ;; of a low score, but now it has risen, so we mark it as
3623             ;; unread.
3624             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3625         (gnus-summary-update-mark
3626          (if (or (null gnus-summary-default-score)
3627                  (<= (abs (- score gnus-summary-default-score))
3628                      gnus-summary-zcore-fuzz))
3629              ?                          ;Whitespace
3630            (if (< score gnus-summary-default-score)
3631                gnus-score-below-mark gnus-score-over-mark))
3632          'score))
3633       ;; Do visual highlighting.
3634       (when (gnus-visual-p 'summary-highlight 'highlight)
3635         (gnus-run-hooks 'gnus-summary-update-hook)))))
3636
3637 (defvar gnus-tmp-new-adopts nil)
3638
3639 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3640   "Return the number of articles in THREAD.
3641 This may be 0 in some cases -- if none of the articles in
3642 the thread are to be displayed."
3643   (let* ((number
3644          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3645           (cond
3646            ((not (listp thread))
3647             1)
3648            ((and (consp thread) (cdr thread))
3649             (apply
3650              '+ 1 (mapcar
3651                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3652            ((null thread)
3653             1)
3654            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3655             1)
3656            (t 0))))
3657     (when (and level (zerop level) gnus-tmp-new-adopts)
3658       (incf number
3659             (apply '+ (mapcar
3660                        'gnus-summary-number-of-articles-in-thread
3661                        gnus-tmp-new-adopts))))
3662     (if char
3663         (if (> number 1) gnus-not-empty-thread-mark
3664           gnus-empty-thread-mark)
3665       number)))
3666
3667 (defsubst gnus-summary-line-message-size (head)
3668   "Return pretty-printed version of message size.
3669 This function is intended to be used in
3670 `gnus-summary-line-format-alist'."
3671   (let ((c (or (mail-header-chars head) -1)))
3672     (cond ((< c 0) "n/a")               ; chars not available
3673           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3674           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3675           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3676           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3677
3678
3679 (defun gnus-summary-set-local-parameters (group)
3680   "Go through the local params of GROUP and set all variable specs in that list."
3681   (let ((vars '(quit-config)))          ; Ignore quit-config.
3682     (dolist (elem (gnus-group-find-parameter group))
3683       (and (consp elem)                 ; Has to be a cons.
3684            (consp (cdr elem))           ; The cdr has to be a list.
3685            (symbolp (car elem))         ; Has to be a symbol in there.
3686            (not (memq (car elem) vars))
3687            (ignore-errors               ; So we set it.
3688              (push (car elem) vars)
3689              (make-local-variable (car elem))
3690              (set (car elem) (eval (nth 1 elem))))))))
3691
3692 (defun gnus-summary-read-group (group &optional show-all no-article
3693                                       kill-buffer no-display backward
3694                                       select-articles)
3695   "Start reading news in newsgroup GROUP.
3696 If SHOW-ALL is non-nil, already read articles are also listed.
3697 If NO-ARTICLE is non-nil, no article is selected initially.
3698 If NO-DISPLAY, don't generate a summary buffer."
3699   (let (result)
3700     (while (and group
3701                 (null (setq result
3702                             (let ((gnus-auto-select-next nil))
3703                               (or (gnus-summary-read-group-1
3704                                    group show-all no-article
3705                                    kill-buffer no-display
3706                                    select-articles)
3707                                   (setq show-all nil
3708                                         select-articles nil)))))
3709                 (eq gnus-auto-select-next 'quietly))
3710       (set-buffer gnus-group-buffer)
3711       ;; The entry function called above goes to the next
3712       ;; group automatically, so we go two groups back
3713       ;; if we are searching for the previous group.
3714       (when backward
3715         (gnus-group-prev-unread-group 2))
3716       (if (not (equal group (gnus-group-group-name)))
3717           (setq group (gnus-group-group-name))
3718         (setq group nil)))
3719     result))
3720
3721 (defun gnus-summary-read-group-1 (group show-all no-article
3722                                         kill-buffer no-display
3723                                         &optional select-articles)
3724   ;; Killed foreign groups can't be entered.
3725   ;;  (when (and (not (gnus-group-native-p group))
3726   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3727   ;;    (error "Dead non-native groups can't be entered"))
3728   (gnus-message 5 "Retrieving newsgroup: %s..."
3729                 (gnus-group-decoded-name group))
3730   (let* ((new-group (gnus-summary-setup-buffer group))
3731          (quit-config (gnus-group-quit-config group))
3732          (did-select (and new-group (gnus-select-newsgroup
3733                                      group show-all select-articles))))
3734     (cond
3735      ;; This summary buffer exists already, so we just select it.
3736      ((not new-group)
3737       (gnus-set-global-variables)
3738       (when kill-buffer
3739         (gnus-kill-or-deaden-summary kill-buffer))
3740       (gnus-configure-windows 'summary 'force)
3741       (gnus-set-mode-line 'summary)
3742       (gnus-summary-position-point)
3743       (message "")
3744       t)
3745      ;; We couldn't select this group.
3746      ((null did-select)
3747       (when (and (eq major-mode 'gnus-summary-mode)
3748                  (not (equal (current-buffer) kill-buffer)))
3749         (kill-buffer (current-buffer))
3750         (if (not quit-config)
3751             (progn
3752               ;; Update the info -- marks might need to be removed,
3753               ;; for instance.
3754               (gnus-summary-update-info)
3755               (set-buffer gnus-group-buffer)
3756               (gnus-group-jump-to-group group)
3757               (gnus-group-next-unread-group 1))
3758           (gnus-handle-ephemeral-exit quit-config)))
3759       (let ((grpinfo (gnus-get-info group)))
3760         (if (null (gnus-info-read grpinfo))
3761             (gnus-message 3 "Group %s contains no messages"
3762                           (gnus-group-decoded-name group))
3763           (gnus-message 3 "Can't select group")))
3764       nil)
3765      ;; The user did a `C-g' while prompting for number of articles,
3766      ;; so we exit this group.
3767      ((eq did-select 'quit)
3768       (and (eq major-mode 'gnus-summary-mode)
3769            (not (equal (current-buffer) kill-buffer))
3770            (kill-buffer (current-buffer)))
3771       (when kill-buffer
3772         (gnus-kill-or-deaden-summary kill-buffer))
3773       (if (not quit-config)
3774           (progn
3775             (set-buffer gnus-group-buffer)
3776             (gnus-group-jump-to-group group)
3777             (gnus-group-next-unread-group 1)
3778             (gnus-configure-windows 'group 'force))
3779         (gnus-handle-ephemeral-exit quit-config))
3780       ;; Finally signal the quit.
3781       (signal 'quit nil))
3782      ;; The group was successfully selected.
3783      (t
3784       (gnus-set-global-variables)
3785       ;; Save the active value in effect when the group was entered.
3786       (setq gnus-newsgroup-active
3787             (gnus-copy-sequence
3788              (gnus-active gnus-newsgroup-name)))
3789       ;; You can change the summary buffer in some way with this hook.
3790       (gnus-run-hooks 'gnus-select-group-hook)
3791       (when (memq 'summary (gnus-update-format-specifications
3792                             nil 'summary 'summary-mode 'summary-dummy))
3793         ;; The format specification for the summary line was updated,
3794         ;; so we need to update the mark positions as well.
3795         (gnus-update-summary-mark-positions))
3796       ;; Do score processing.
3797       (when gnus-use-scoring
3798         (gnus-possibly-score-headers))
3799       ;; Check whether to fill in the gaps in the threads.
3800       (when gnus-build-sparse-threads
3801         (gnus-build-sparse-threads))
3802       ;; Find the initial limit.
3803       (if show-all
3804           (let ((gnus-newsgroup-dormant nil))
3805             (gnus-summary-initial-limit show-all))
3806         (gnus-summary-initial-limit show-all))
3807       ;; Generate the summary buffer.
3808       (unless no-display
3809         (gnus-summary-prepare))
3810       (when gnus-use-trees
3811         (gnus-tree-open group)
3812         (setq gnus-summary-highlight-line-function
3813               'gnus-tree-highlight-article))
3814       ;; If the summary buffer is empty, but there are some low-scored
3815       ;; articles or some excluded dormants, we include these in the
3816       ;; buffer.
3817       (when (and (zerop (buffer-size))
3818                  (not no-display))
3819         (cond (gnus-newsgroup-dormant
3820                (gnus-summary-limit-include-dormant))
3821               ((and gnus-newsgroup-scored show-all)
3822                (gnus-summary-limit-include-expunged t))))
3823       ;; Function `gnus-apply-kill-file' must be called in this hook.
3824       (gnus-run-hooks 'gnus-apply-kill-hook)
3825       (if (and (zerop (buffer-size))
3826                (not no-display))
3827           (progn
3828             ;; This newsgroup is empty.
3829             (gnus-summary-catchup-and-exit nil t)
3830             (gnus-message 6 "No unread news")
3831             (when kill-buffer
3832               (gnus-kill-or-deaden-summary kill-buffer))
3833             ;; Return nil from this function.
3834             nil)
3835         ;; Hide conversation thread subtrees.  We cannot do this in
3836         ;; gnus-summary-prepare-hook since kill processing may not
3837         ;; work with hidden articles.
3838         (gnus-summary-maybe-hide-threads)
3839         (when kill-buffer
3840           (gnus-kill-or-deaden-summary kill-buffer))
3841         (gnus-summary-auto-select-subject)
3842         ;; Show first unread article if requested.
3843         (if (and (not no-article)
3844                  (not no-display)
3845                  gnus-newsgroup-unreads
3846                  gnus-auto-select-first)
3847             (progn
3848               (gnus-configure-windows 'summary)
3849               (let ((art (gnus-summary-article-number)))
3850                 (unless (and (not gnus-plugged)
3851                              (or (memq art gnus-newsgroup-undownloaded)
3852                                  (memq art gnus-newsgroup-downloadable)))
3853                   (gnus-summary-goto-article art))))
3854           ;; Don't select any articles.
3855           (gnus-summary-position-point)
3856           (gnus-configure-windows 'summary 'force)
3857           (gnus-set-mode-line 'summary))
3858         (when (and gnus-auto-center-group
3859                    (get-buffer-window gnus-group-buffer t))
3860           ;; Gotta use windows, because recenter does weird stuff if
3861           ;; the current buffer ain't the displayed window.
3862           (let ((owin (selected-window)))
3863             (select-window (get-buffer-window gnus-group-buffer t))
3864             (when (gnus-group-goto-group group)
3865               (recenter))
3866             (select-window owin)))
3867         ;; Mark this buffer as "prepared".
3868         (setq gnus-newsgroup-prepared t)
3869         (gnus-run-hooks 'gnus-summary-prepared-hook)
3870         (unless (gnus-ephemeral-group-p group)
3871           (gnus-group-update-group group))
3872         t)))))
3873
3874 (defun gnus-summary-auto-select-subject ()
3875   "Select the subject line on initial group entry."
3876   (goto-char (point-min))
3877   (cond
3878    ((eq gnus-auto-select-subject 'best)
3879     (gnus-summary-best-unread-subject))
3880    ((eq gnus-auto-select-subject 'unread)
3881     (gnus-summary-first-unread-subject))
3882    ((eq gnus-auto-select-subject 'unseen)
3883     (gnus-summary-first-unseen-subject))
3884    ((eq gnus-auto-select-subject 'unseen-or-unread)
3885     (gnus-summary-first-unseen-or-unread-subject))
3886    ((eq gnus-auto-select-subject 'first)
3887     ;; Do nothing.
3888     )
3889    ((functionp gnus-auto-select-subject)
3890     (funcall gnus-auto-select-subject))))
3891
3892 (defun gnus-summary-prepare ()
3893   "Generate the summary buffer."
3894   (interactive)
3895   (let ((buffer-read-only nil))
3896     (erase-buffer)
3897     (setq gnus-newsgroup-data nil
3898           gnus-newsgroup-data-reverse nil)
3899     (gnus-run-hooks 'gnus-summary-generate-hook)
3900     ;; Generate the buffer, either with threads or without.
3901     (when gnus-newsgroup-headers
3902       (gnus-summary-prepare-threads
3903        (if gnus-show-threads
3904            (gnus-sort-gathered-threads
3905             (funcall gnus-summary-thread-gathering-function
3906                      (gnus-sort-threads
3907                       (gnus-cut-threads (gnus-make-threads)))))
3908          ;; Unthreaded display.
3909          (gnus-sort-articles gnus-newsgroup-headers))))
3910     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3911     ;; Call hooks for modifying summary buffer.
3912     (goto-char (point-min))
3913     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3914
3915 (defsubst gnus-general-simplify-subject (subject)
3916   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3917   (setq subject
3918         (cond
3919          ;; Truncate the subject.
3920          (gnus-simplify-subject-functions
3921           (gnus-map-function gnus-simplify-subject-functions subject))
3922          ((numberp gnus-summary-gather-subject-limit)
3923           (setq subject (gnus-simplify-subject-re subject))
3924           (if (> (length subject) gnus-summary-gather-subject-limit)
3925               (substring subject 0 gnus-summary-gather-subject-limit)
3926             subject))
3927          ;; Fuzzily simplify it.
3928          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3929           (gnus-simplify-subject-fuzzy subject))
3930          ;; Just remove the leading "Re:".
3931          (t
3932           (gnus-simplify-subject-re subject))))
3933
3934   (if (and gnus-summary-gather-exclude-subject
3935            (string-match gnus-summary-gather-exclude-subject subject))
3936       nil                         ; This article shouldn't be gathered
3937     subject))
3938
3939 (defun gnus-summary-simplify-subject-query ()
3940   "Query where the respool algorithm would put this article."
3941   (interactive)
3942   (gnus-summary-select-article)
3943   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3944
3945 (defun gnus-gather-threads-by-subject (threads)
3946   "Gather threads by looking at Subject headers."
3947   (if (not gnus-summary-make-false-root)
3948       threads
3949     (let ((hashtb (gnus-make-hashtable 1024))
3950           (prev threads)
3951           (result threads)
3952           subject hthread whole-subject)
3953       (while threads
3954         (setq subject (gnus-general-simplify-subject
3955                        (setq whole-subject (mail-header-subject
3956                                             (caar threads)))))
3957         (when subject
3958           (if (setq hthread (gnus-gethash subject hashtb))
3959               (progn
3960                 ;; We enter a dummy root into the thread, if we
3961                 ;; haven't done that already.
3962                 (unless (stringp (caar hthread))
3963                   (setcar hthread (list whole-subject (car hthread))))
3964                 ;; We add this new gathered thread to this gathered
3965                 ;; thread.
3966                 (setcdr (car hthread)
3967                         (nconc (cdar hthread) (list (car threads))))
3968                 ;; Remove it from the list of threads.
3969                 (setcdr prev (cdr threads))
3970                 (setq threads prev))
3971             ;; Enter this thread into the hash table.
3972             (gnus-sethash subject
3973                           (if gnus-summary-make-false-root-always
3974                               (progn
3975                                 ;; If you want a dummy root above all
3976                                 ;; threads...
3977                                 (setcar threads (list whole-subject
3978                                                       (car threads)))
3979                                 threads)
3980                             threads)
3981                           hashtb)))
3982         (setq prev threads)
3983         (setq threads (cdr threads)))
3984       result)))
3985
3986 (defun gnus-gather-threads-by-references (threads)
3987   "Gather threads by looking at References headers."
3988   (let ((idhashtb (gnus-make-hashtable 1024))
3989         (thhashtb (gnus-make-hashtable 1024))
3990         (prev threads)
3991         (result threads)
3992         ids references id gthread gid entered ref)
3993     (while threads
3994       (when (setq references (mail-header-references (caar threads)))
3995         (setq id (mail-header-id (caar threads))
3996               ids (inline (gnus-split-references references))
3997               entered nil)
3998         (while (setq ref (pop ids))
3999           (setq ids (delete ref ids))
4000           (if (not (setq gid (gnus-gethash ref idhashtb)))
4001               (progn
4002                 (gnus-sethash ref id idhashtb)
4003                 (gnus-sethash id threads thhashtb))
4004             (setq gthread (gnus-gethash gid thhashtb))
4005             (unless entered
4006               ;; We enter a dummy root into the thread, if we
4007               ;; haven't done that already.
4008               (unless (stringp (caar gthread))
4009                 (setcar gthread (list (mail-header-subject (caar gthread))
4010                                       (car gthread))))
4011               ;; We add this new gathered thread to this gathered
4012               ;; thread.
4013               (setcdr (car gthread)
4014                       (nconc (cdar gthread) (list (car threads)))))
4015             ;; Add it into the thread hash table.
4016             (gnus-sethash id gthread thhashtb)
4017             (setq entered t)
4018             ;; Remove it from the list of threads.
4019             (setcdr prev (cdr threads))
4020             (setq threads prev))))
4021       (setq prev threads)
4022       (setq threads (cdr threads)))
4023     result))
4024
4025 (defun gnus-sort-gathered-threads (threads)
4026   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4027   (let ((result threads))
4028     (while threads
4029       (when (stringp (caar threads))
4030         (setcdr (car threads)
4031                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4032       (setq threads (cdr threads)))
4033     result))
4034
4035 (defun gnus-thread-loop-p (root thread)
4036   "Say whether ROOT is in THREAD."
4037   (let ((stack (list thread))
4038         (infloop 0)
4039         th)
4040     (while (setq thread (pop stack))
4041       (setq th (cdr thread))
4042       (while (and th
4043                   (not (eq (caar th) root)))
4044         (pop th))
4045       (if th
4046           ;; We have found a loop.
4047           (let (ref-dep)
4048             (setcdr thread (delq (car th) (cdr thread)))
4049             (if (boundp (setq ref-dep (intern "none"
4050                                               gnus-newsgroup-dependencies)))
4051                 (setcdr (symbol-value ref-dep)
4052                         (nconc (cdr (symbol-value ref-dep))
4053                                (list (car th))))
4054               (set ref-dep (list nil (car th))))
4055             (setq infloop 1
4056                   stack nil))
4057         ;; Push all the subthreads onto the stack.
4058         (push (cdr thread) stack)))
4059     infloop))
4060
4061 (defun gnus-make-threads ()
4062   "Go through the dependency hashtb and find the roots.  Return all threads."
4063   (let (threads)
4064     (while (catch 'infloop
4065              (mapatoms
4066               (lambda (refs)
4067                 ;; Deal with self-referencing References loops.
4068                 (when (and (car (symbol-value refs))
4069                            (not (zerop
4070                                  (apply
4071                                   '+
4072                                   (mapcar
4073                                    (lambda (thread)
4074                                      (gnus-thread-loop-p
4075                                       (car (symbol-value refs)) thread))
4076                                    (cdr (symbol-value refs)))))))
4077                   (setq threads nil)
4078                   (throw 'infloop t))
4079                 (unless (car (symbol-value refs))
4080                   ;; These threads do not refer back to any other
4081                   ;; articles, so they're roots.
4082                   (setq threads (append (cdr (symbol-value refs)) threads))))
4083               gnus-newsgroup-dependencies)))
4084     threads))
4085
4086 ;; Build the thread tree.
4087 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4088   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4089
4090 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4091 if it was already present.
4092
4093 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4094 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4095 Message-IDs will be renamed to a unique Message-ID before being
4096 entered.
4097
4098 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4099   (let* ((id (mail-header-id header))
4100          (id-dep (and id (intern id dependencies)))
4101          parent-id ref ref-dep ref-header replaced)
4102     ;; Enter this `header' in the `dependencies' table.
4103     (cond
4104      ((not id-dep)
4105       (setq header nil))
4106      ;; The first two cases do the normal part: enter a new `header'
4107      ;; in the `dependencies' table.
4108      ((not (boundp id-dep))
4109       (set id-dep (list header)))
4110      ((null (car (symbol-value id-dep)))
4111       (setcar (symbol-value id-dep) header))
4112
4113      ;; From here the `header' was already present in the
4114      ;; `dependencies' table.
4115      (force-new
4116       ;; Overrides an existing entry;
4117       ;; just set the header part of the entry.
4118       (setcar (symbol-value id-dep) header)
4119       (setq replaced t))
4120
4121      ;; Renames the existing `header' to a unique Message-ID.
4122      ((not gnus-summary-ignore-duplicates)
4123       ;; An article with this Message-ID has already been seen.
4124       ;; We rename the Message-ID.
4125       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4126            (list header))
4127       (mail-header-set-id header id))
4128
4129      ;; The last case ignores an existing entry, except it adds any
4130      ;; additional Xrefs (in case the two articles came from different
4131      ;; servers.
4132      ;; Also sets `header' to `nil' meaning that the `dependencies'
4133      ;; table was *not* modified.
4134      (t
4135       (mail-header-set-xref
4136        (car (symbol-value id-dep))
4137        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4138                    "")
4139                (or (mail-header-xref header) "")))
4140       (setq header nil)))
4141
4142     (when (and header (not replaced))
4143       ;; First check that we are not creating a References loop.
4144       (setq parent-id (gnus-parent-id (mail-header-references header)))
4145       (setq ref parent-id)
4146       (while (and ref
4147                   (setq ref-dep (intern-soft ref dependencies))
4148                   (boundp ref-dep)
4149                   (setq ref-header (car (symbol-value ref-dep))))
4150         (if (string= id ref)
4151             ;; Yuk!  This is a reference loop.  Make the article be a
4152             ;; root article.
4153             (progn
4154               (mail-header-set-references (car (symbol-value id-dep)) "none")
4155               (setq ref nil)
4156               (setq parent-id nil))
4157           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4158       (setq ref-dep (intern (or parent-id "none") dependencies))
4159       (if (boundp ref-dep)
4160           (setcdr (symbol-value ref-dep)
4161                   (nconc (cdr (symbol-value ref-dep))
4162                          (list (symbol-value id-dep))))
4163         (set ref-dep (list nil (symbol-value id-dep)))))
4164     header))
4165
4166 (defun gnus-extract-message-id-from-in-reply-to (string)
4167   (if (string-match "<[^>]+>" string)
4168       (substring string (match-beginning 0) (match-end 0))
4169     nil))
4170
4171 (defun gnus-build-sparse-threads ()
4172   (let ((headers gnus-newsgroup-headers)
4173         (mail-parse-charset gnus-newsgroup-charset)
4174         (gnus-summary-ignore-duplicates t)
4175         header references generation relations
4176         subject child end new-child date)
4177     ;; First we create an alist of generations/relations, where
4178     ;; generations is how much we trust the relation, and the relation
4179     ;; is parent/child.
4180     (gnus-message 7 "Making sparse threads...")
4181     (save-excursion
4182       (nnheader-set-temp-buffer " *gnus sparse threads*")
4183       (while (setq header (pop headers))
4184         (when (and (setq references (mail-header-references header))
4185                    (not (string= references "")))
4186           (insert references)
4187           (setq child (mail-header-id header)
4188                 subject (mail-header-subject header)
4189                 date (mail-header-date header)
4190                 generation 0)
4191           (while (search-backward ">" nil t)
4192             (setq end (1+ (point)))
4193             (when (search-backward "<" nil t)
4194               (setq new-child (buffer-substring (point) end))
4195               (push (list (incf generation)
4196                           child (setq child new-child)
4197                           subject date)
4198                     relations)))
4199           (when child
4200             (push (list (1+ generation) child nil subject) relations))
4201           (erase-buffer)))
4202       (kill-buffer (current-buffer)))
4203     ;; Sort over trustworthiness.
4204     (mapcar
4205      (lambda (relation)
4206        (when (gnus-dependencies-add-header
4207               (make-full-mail-header
4208                gnus-reffed-article-number
4209                (nth 3 relation) "" (or (nth 4 relation) "")
4210                (nth 1 relation)
4211                (or (nth 2 relation) "") 0 0 "")
4212               gnus-newsgroup-dependencies nil)
4213          (push gnus-reffed-article-number gnus-newsgroup-limit)
4214          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4215          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4216                gnus-newsgroup-reads)
4217          (decf gnus-reffed-article-number)))
4218      (sort relations 'car-less-than-car))
4219     (gnus-message 7 "Making sparse threads...done")))
4220
4221 (defun gnus-build-old-threads ()
4222   ;; Look at all the articles that refer back to old articles, and
4223   ;; fetch the headers for the articles that aren't there.  This will
4224   ;; build complete threads - if the roots haven't been expired by the
4225   ;; server, that is.
4226   (let ((mail-parse-charset gnus-newsgroup-charset)
4227         id heads)
4228     (mapatoms
4229      (lambda (refs)
4230        (when (not (car (symbol-value refs)))
4231          (setq heads (cdr (symbol-value refs)))
4232          (while heads
4233            (if (memq (mail-header-number (caar heads))
4234                      gnus-newsgroup-dormant)
4235                (setq heads (cdr heads))
4236              (setq id (symbol-name refs))
4237              (while (and (setq id (gnus-build-get-header id))
4238                          (not (car (gnus-id-to-thread id)))))
4239              (setq heads nil)))))
4240      gnus-newsgroup-dependencies)))
4241
4242 (defsubst gnus-remove-odd-characters (string)
4243   "Translate STRING into something that doesn't contain weird characters."
4244   (mm-subst-char-in-string
4245    ?\r ?\-
4246    (mm-subst-char-in-string ?\n ?\- string t) t))
4247
4248 ;; This function has to be called with point after the article number
4249 ;; on the beginning of the line.
4250 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4251   (let ((eol (point-at-eol))
4252         (buffer (current-buffer))
4253         header references in-reply-to)
4254
4255     ;; overview: [num subject from date id refs chars lines misc]
4256     (unwind-protect
4257         (let (x)
4258           (narrow-to-region (point) eol)
4259           (unless (eobp)
4260             (forward-char))
4261
4262           (setq header
4263                 (make-full-mail-header
4264                  number                 ; number
4265                  (condition-case ()     ; subject
4266                      (gnus-remove-odd-characters
4267                       (funcall gnus-decode-encoded-word-function
4268                                (setq x (nnheader-nov-field))))
4269                    (error x))
4270                  (condition-case ()     ; from
4271                      (gnus-remove-odd-characters
4272                       (funcall gnus-decode-encoded-word-function
4273                                (setq x (nnheader-nov-field))))
4274                    (error x))
4275                  (nnheader-nov-field)   ; date
4276                  (nnheader-nov-read-message-id number)  ; id
4277                  (setq references (nnheader-nov-field)) ; refs
4278                  (nnheader-nov-read-integer) ; chars
4279                  (nnheader-nov-read-integer) ; lines
4280                  (unless (eobp)
4281                    (if (looking-at "Xref: ")
4282                        (goto-char (match-end 0)))
4283                    (nnheader-nov-field)) ; Xref
4284                  (nnheader-nov-parse-extra)))) ; extra
4285
4286       (widen))
4287
4288     (when (and (string= references "")
4289                (setq in-reply-to (mail-header-extra header))
4290                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4291       (mail-header-set-references
4292        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4293
4294     (when gnus-alter-header-function
4295       (funcall gnus-alter-header-function header))
4296     (gnus-dependencies-add-header header dependencies force-new)))
4297
4298 (defun gnus-build-get-header (id)
4299   "Look through the buffer of NOV lines and find the header to ID.
4300 Enter this line into the dependencies hash table, and return
4301 the id of the parent article (if any)."
4302   (let ((deps gnus-newsgroup-dependencies)
4303         found header)
4304     (prog1
4305         (save-excursion
4306           (set-buffer nntp-server-buffer)
4307           (let ((case-fold-search nil))
4308             (goto-char (point-min))
4309             (while (and (not found)
4310                         (search-forward id nil t))
4311               (beginning-of-line)
4312               (setq found (looking-at
4313                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4314                                    (regexp-quote id))))
4315               (or found (beginning-of-line 2)))
4316             (when found
4317               (beginning-of-line)
4318               (and
4319                (setq header (gnus-nov-parse-line
4320                              (read (current-buffer)) deps))
4321                (gnus-parent-id (mail-header-references header))))))
4322       (when header
4323         (let ((number (mail-header-number header)))
4324           (push number gnus-newsgroup-limit)
4325           (push header gnus-newsgroup-headers)
4326           (if (memq number gnus-newsgroup-unselected)
4327               (progn
4328                 (setq gnus-newsgroup-unreads
4329                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4330                                                number))
4331                 (setq gnus-newsgroup-unselected
4332                       (delq number gnus-newsgroup-unselected)))
4333             (push number gnus-newsgroup-ancient)))))))
4334
4335 (defun gnus-build-all-threads ()
4336   "Read all the headers."
4337   (let ((gnus-summary-ignore-duplicates t)
4338         (mail-parse-charset gnus-newsgroup-charset)
4339         (dependencies gnus-newsgroup-dependencies)
4340         header article)
4341     (save-excursion
4342       (set-buffer nntp-server-buffer)
4343       (let ((case-fold-search nil))
4344         (goto-char (point-min))
4345         (while (not (eobp))
4346           (ignore-errors
4347             (setq article (read (current-buffer))
4348                   header (gnus-nov-parse-line article dependencies)))
4349           (when header
4350             (with-current-buffer gnus-summary-buffer
4351               (push header gnus-newsgroup-headers)
4352               (if (memq (setq article (mail-header-number header))
4353                         gnus-newsgroup-unselected)
4354                   (progn
4355                     (setq gnus-newsgroup-unreads
4356                           (gnus-add-to-sorted-list
4357                            gnus-newsgroup-unreads article))
4358                     (setq gnus-newsgroup-unselected
4359                           (delq article gnus-newsgroup-unselected)))
4360                 (push article gnus-newsgroup-ancient)))
4361             (forward-line 1)))))))
4362
4363 (defun gnus-summary-update-article-line (article header)
4364   "Update the line for ARTICLE using HEADER."
4365   (let* ((id (mail-header-id header))
4366          (thread (gnus-id-to-thread id)))
4367     (unless thread
4368       (error "Article in no thread"))
4369     ;; Update the thread.
4370     (setcar thread header)
4371     (gnus-summary-goto-subject article)
4372     (let* ((datal (gnus-data-find-list article))
4373            (data (car datal))
4374            (buffer-read-only nil)
4375            (level (gnus-summary-thread-level)))
4376       (gnus-delete-line)
4377       (let ((inserted (- (point)
4378                          (progn
4379                            (gnus-summary-insert-line
4380                             header level nil
4381                             (memq article gnus-newsgroup-undownloaded)
4382                             (gnus-article-mark article)
4383                             (memq article gnus-newsgroup-replied)
4384                             (memq article gnus-newsgroup-expirable)
4385                             ;; Only insert the Subject string when it's different
4386                             ;; from the previous Subject string.
4387                             (if (and
4388                                  gnus-show-threads
4389                                  (gnus-subject-equal
4390                                   (condition-case ()
4391                                       (mail-header-subject
4392                                        (gnus-data-header
4393                                         (cadr
4394                                          (gnus-data-find-list
4395                                           article
4396                                           (gnus-data-list t)))))
4397                                     ;; Error on the side of excessive subjects.
4398                                     (error ""))
4399                                   (mail-header-subject header)))
4400                                 ""
4401                               (mail-header-subject header))
4402                             nil (cdr (assq article gnus-newsgroup-scored))
4403                             (memq article gnus-newsgroup-processable))
4404                            (point)))))
4405         (when (cdr datal)
4406           (gnus-data-update-list
4407            (cdr datal)
4408            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4409
4410 (defun gnus-summary-update-article (article &optional iheader)
4411   "Update ARTICLE in the summary buffer."
4412   (set-buffer gnus-summary-buffer)
4413   (let* ((header (gnus-summary-article-header article))
4414          (id (mail-header-id header))
4415          (data (gnus-data-find article))
4416          (thread (gnus-id-to-thread id))
4417          (references (mail-header-references header))
4418          (parent
4419           (gnus-id-to-thread
4420            (or (gnus-parent-id
4421                 (when (and references
4422                            (not (equal "" references)))
4423                   references))
4424                "none")))
4425          (buffer-read-only nil)
4426          (old (car thread)))
4427     (when thread
4428       (unless iheader
4429         (setcar thread nil)
4430         (when parent
4431           (delq thread parent)))
4432       (if (gnus-summary-insert-subject id header)
4433           ;; Set the (possibly) new article number in the data structure.
4434           (gnus-data-set-number data (gnus-id-to-article id))
4435         (setcar thread old)
4436         nil))))
4437
4438 (defun gnus-rebuild-thread (id &optional line)
4439   "Rebuild the thread containing ID.
4440 If LINE, insert the rebuilt thread starting on line LINE."
4441   (let ((buffer-read-only nil)
4442         old-pos current thread data)
4443     (if (not gnus-show-threads)
4444         (setq thread (list (car (gnus-id-to-thread id))))
4445       ;; Get the thread this article is part of.
4446       (setq thread (gnus-remove-thread id)))
4447     (setq old-pos (point-at-bol))
4448     (setq current (save-excursion
4449                     (and (re-search-backward "[\r\n]" nil t)
4450                          (gnus-summary-article-number))))
4451     ;; If this is a gathered thread, we have to go some re-gathering.
4452     (when (stringp (car thread))
4453       (let ((subject (car thread))
4454             roots thr)
4455         (setq thread (cdr thread))
4456         (while thread
4457           (unless (memq (setq thr (gnus-id-to-thread
4458                                    (gnus-root-id
4459                                     (mail-header-id (caar thread)))))
4460                         roots)
4461             (push thr roots))
4462           (setq thread (cdr thread)))
4463         ;; We now have all (unique) roots.
4464         (if (= (length roots) 1)
4465             ;; All the loose roots are now one solid root.
4466             (setq thread (car roots))
4467           (setq thread (cons subject (gnus-sort-threads roots))))))
4468     (let (threads)
4469       ;; We then insert this thread into the summary buffer.
4470       (when line
4471         (goto-char (point-min))
4472         (forward-line (1- line)))
4473       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4474         (if gnus-show-threads
4475             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4476           (gnus-summary-prepare-unthreaded thread))
4477         (setq data (nreverse gnus-newsgroup-data))
4478         (setq threads gnus-newsgroup-threads))
4479       ;; We splice the new data into the data structure.
4480       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4481       ;;!!! then we want to insert at the beginning of the buffer.
4482       ;;!!! That happens to be true with Gnus now, but that may
4483       ;;!!! change in the future.  Perhaps.
4484       (gnus-data-enter-list
4485        (if line nil current) data (- (point) old-pos))
4486       (setq gnus-newsgroup-threads
4487             (nconc threads gnus-newsgroup-threads))
4488       (gnus-data-compute-positions))))
4489
4490 (defun gnus-number-to-header (number)
4491   "Return the header for article NUMBER."
4492   (let ((headers gnus-newsgroup-headers))
4493     (while (and headers
4494                 (not (= number (mail-header-number (car headers)))))
4495       (pop headers))
4496     (when headers
4497       (car headers))))
4498
4499 (defun gnus-parent-headers (in-headers &optional generation)
4500   "Return the headers of the GENERATIONeth parent of HEADERS."
4501   (unless generation
4502     (setq generation 1))
4503   (let ((parent t)
4504         (headers in-headers)
4505         references)
4506     (while (and parent
4507                 (not (zerop generation))
4508                 (setq references (mail-header-references headers)))
4509       (setq headers (if (and references
4510                              (setq parent (gnus-parent-id references)))
4511                         (car (gnus-id-to-thread parent))
4512                       nil))
4513       (decf generation))
4514     (and (not (eq headers in-headers))
4515          headers)))
4516
4517 (defun gnus-id-to-thread (id)
4518   "Return the (sub-)thread where ID appears."
4519   (gnus-gethash id gnus-newsgroup-dependencies))
4520
4521 (defun gnus-id-to-article (id)
4522   "Return the article number of ID."
4523   (let ((thread (gnus-id-to-thread id)))
4524     (when (and thread
4525                (car thread))
4526       (mail-header-number (car thread)))))
4527
4528 (defun gnus-id-to-header (id)
4529   "Return the article headers of ID."
4530   (car (gnus-id-to-thread id)))
4531
4532 (defun gnus-article-displayed-root-p (article)
4533   "Say whether ARTICLE is a root(ish) article."
4534   (let ((level (gnus-summary-thread-level article))
4535         (refs (mail-header-references  (gnus-summary-article-header article)))
4536         particle)
4537     (cond
4538      ((null level) nil)
4539      ((zerop level) t)
4540      ((null refs) t)
4541      ((null (gnus-parent-id refs)) t)
4542      ((and (= 1 level)
4543            (null (setq particle (gnus-id-to-article
4544                                  (gnus-parent-id refs))))
4545            (null (gnus-summary-thread-level particle)))))))
4546
4547 (defun gnus-root-id (id)
4548   "Return the id of the root of the thread where ID appears."
4549   (let (last-id prev)
4550     (while (and id (setq prev (car (gnus-id-to-thread id))))
4551       (setq last-id id
4552             id (gnus-parent-id (mail-header-references prev))))
4553     last-id))
4554
4555 (defun gnus-articles-in-thread (thread)
4556   "Return the list of articles in THREAD."
4557   (cons (mail-header-number (car thread))
4558         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4559
4560 (defun gnus-remove-thread (id &optional dont-remove)
4561   "Remove the thread that has ID in it."
4562   (let (headers thread last-id)
4563     ;; First go up in this thread until we find the root.
4564     (setq last-id (gnus-root-id id)
4565           headers (message-flatten-list (gnus-id-to-thread last-id)))
4566     ;; We have now found the real root of this thread.  It might have
4567     ;; been gathered into some loose thread, so we have to search
4568     ;; through the threads to find the thread we wanted.
4569     (let ((threads gnus-newsgroup-threads)
4570           sub)
4571       (while threads
4572         (setq sub (car threads))
4573         (if (stringp (car sub))
4574             ;; This is a gathered thread, so we look at the roots
4575             ;; below it to find whether this article is in this
4576             ;; gathered root.
4577             (progn
4578               (setq sub (cdr sub))
4579               (while sub
4580                 (when (member (caar sub) headers)
4581                   (setq thread (car threads)
4582                         threads nil
4583                         sub nil))
4584                 (setq sub (cdr sub))))
4585           ;; It's an ordinary thread, so we check it.
4586           (when (eq (car sub) (car headers))
4587             (setq thread sub
4588                   threads nil)))
4589         (setq threads (cdr threads)))
4590       ;; If this article is in no thread, then it's a root.
4591       (if thread
4592           (unless dont-remove
4593             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4594         (setq thread (gnus-id-to-thread last-id)))
4595       (when thread
4596         (prog1
4597             thread                      ; We return this thread.
4598           (unless dont-remove
4599             (if (stringp (car thread))
4600                 (progn
4601                   ;; If we use dummy roots, then we have to remove the
4602                   ;; dummy root as well.
4603                   (when (eq gnus-summary-make-false-root 'dummy)
4604                     ;; We go to the dummy root by going to
4605                     ;; the first sub-"thread", and then one line up.
4606                     (gnus-summary-goto-article
4607                      (mail-header-number (caadr thread)))
4608                     (forward-line -1)
4609                     (gnus-delete-line)
4610                     (gnus-data-compute-positions))
4611                   (setq thread (cdr thread))
4612                   (while thread
4613                     (gnus-remove-thread-1 (car thread))
4614                     (setq thread (cdr thread))))
4615               (gnus-remove-thread-1 thread))))))))
4616
4617 (defun gnus-remove-thread-1 (thread)
4618   "Remove the thread THREAD recursively."
4619   (let ((number (mail-header-number (pop thread)))
4620         d)
4621     (setq thread (reverse thread))
4622     (while thread
4623       (gnus-remove-thread-1 (pop thread)))
4624     (when (setq d (gnus-data-find number))
4625       (goto-char (gnus-data-pos d))
4626       (gnus-summary-show-thread)
4627       (gnus-data-remove
4628        number
4629        (- (point-at-bol)
4630           (prog1
4631               (1+ (point-at-eol))
4632             (gnus-delete-line)))))))
4633
4634 (defun gnus-sort-threads-1 (threads func)
4635   (sort (mapcar (lambda (thread)
4636                   (cons (car thread)
4637                         (and (cdr thread)
4638                              (gnus-sort-threads-1 (cdr thread) func))))
4639                 threads) func))
4640
4641 (defun gnus-sort-threads (threads)
4642   "Sort THREADS."
4643   (if (not gnus-thread-sort-functions)
4644       threads
4645     (gnus-message 8 "Sorting threads...")
4646     (let ((max-lisp-eval-depth 5000))
4647       (prog1 (gnus-sort-threads-1
4648          threads
4649          (gnus-make-sort-function gnus-thread-sort-functions))
4650         (gnus-message 8 "Sorting threads...done")))))
4651
4652 (defun gnus-sort-articles (articles)
4653   "Sort ARTICLES."
4654   (when gnus-article-sort-functions
4655     (gnus-message 7 "Sorting articles...")
4656     (prog1
4657         (setq gnus-newsgroup-headers
4658               (sort articles (gnus-make-sort-function
4659                               gnus-article-sort-functions)))
4660       (gnus-message 7 "Sorting articles...done"))))
4661
4662 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4663 (defmacro gnus-thread-header (thread)
4664   "Return header of first article in THREAD.
4665 Note that THREAD must never, ever be anything else than a variable -
4666 using some other form will lead to serious barfage."
4667   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4668   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4669   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4670         (vector thread) 2))
4671
4672 (defsubst gnus-article-sort-by-number (h1 h2)
4673   "Sort articles by article number."
4674   (< (mail-header-number h1)
4675      (mail-header-number h2)))
4676
4677 (defun gnus-thread-sort-by-number (h1 h2)
4678   "Sort threads by root article number."
4679   (gnus-article-sort-by-number
4680    (gnus-thread-header h1) (gnus-thread-header h2)))
4681
4682 (defsubst gnus-article-sort-by-random (h1 h2)
4683   "Sort articles by article number."
4684   (zerop (random 2)))
4685
4686 (defun gnus-thread-sort-by-random (h1 h2)
4687   "Sort threads by root article number."
4688   (gnus-article-sort-by-random
4689    (gnus-thread-header h1) (gnus-thread-header h2)))
4690
4691 (defsubst gnus-article-sort-by-lines (h1 h2)
4692   "Sort articles by article Lines header."
4693   (< (mail-header-lines h1)
4694      (mail-header-lines h2)))
4695
4696 (defun gnus-thread-sort-by-lines (h1 h2)
4697   "Sort threads by root article Lines header."
4698   (gnus-article-sort-by-lines
4699    (gnus-thread-header h1) (gnus-thread-header h2)))
4700
4701 (defsubst gnus-article-sort-by-chars (h1 h2)
4702   "Sort articles by octet length."
4703   (< (mail-header-chars h1)
4704      (mail-header-chars h2)))
4705
4706 (defun gnus-thread-sort-by-chars (h1 h2)
4707   "Sort threads by root article octet length."
4708   (gnus-article-sort-by-chars
4709    (gnus-thread-header h1) (gnus-thread-header h2)))
4710
4711 (defsubst gnus-article-sort-by-author (h1 h2)
4712   "Sort articles by root author."
4713   (string-lessp
4714    (let ((extract (funcall
4715                    gnus-extract-address-components
4716                    (mail-header-from h1))))
4717      (or (car extract) (cadr extract) ""))
4718    (let ((extract (funcall
4719                    gnus-extract-address-components
4720                    (mail-header-from h2))))
4721      (or (car extract) (cadr extract) ""))))
4722
4723 (defun gnus-thread-sort-by-author (h1 h2)
4724   "Sort threads by root author."
4725   (gnus-article-sort-by-author
4726    (gnus-thread-header h1)  (gnus-thread-header h2)))
4727
4728 (defsubst gnus-article-sort-by-recipient (h1 h2)
4729   "Sort articles by recipient."
4730   (string-lessp
4731    (let ((extract (funcall
4732                    gnus-extract-address-components
4733                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4734      (or (car extract) (cadr extract)))
4735    (let ((extract (funcall
4736                    gnus-extract-address-components
4737                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4738      (or (car extract) (cadr extract)))))
4739
4740 (defun gnus-thread-sort-by-recipient (h1 h2)
4741   "Sort threads by root recipient."
4742   (gnus-article-sort-by-recipient
4743    (gnus-thread-header h1) (gnus-thread-header h2)))
4744
4745 (defsubst gnus-article-sort-by-subject (h1 h2)
4746   "Sort articles by root subject."
4747   (string-lessp
4748    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4749    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4750
4751 (defun gnus-thread-sort-by-subject (h1 h2)
4752   "Sort threads by root subject."
4753   (gnus-article-sort-by-subject
4754    (gnus-thread-header h1) (gnus-thread-header h2)))
4755
4756 (defsubst gnus-article-sort-by-date (h1 h2)
4757   "Sort articles by root article date."
4758   (time-less-p
4759    (gnus-date-get-time (mail-header-date h1))
4760    (gnus-date-get-time (mail-header-date h2))))
4761
4762 (defun gnus-thread-sort-by-date (h1 h2)
4763   "Sort threads by root article date."
4764   (gnus-article-sort-by-date
4765    (gnus-thread-header h1) (gnus-thread-header h2)))
4766
4767 (defsubst gnus-article-sort-by-score (h1 h2)
4768   "Sort articles by root article score.
4769 Unscored articles will be counted as having a score of zero."
4770   (> (or (cdr (assq (mail-header-number h1)
4771                     gnus-newsgroup-scored))
4772          gnus-summary-default-score 0)
4773      (or (cdr (assq (mail-header-number h2)
4774                     gnus-newsgroup-scored))
4775          gnus-summary-default-score 0)))
4776
4777 (defun gnus-thread-sort-by-score (h1 h2)
4778   "Sort threads by root article score."
4779   (gnus-article-sort-by-score
4780    (gnus-thread-header h1) (gnus-thread-header h2)))
4781
4782 (defun gnus-thread-sort-by-total-score (h1 h2)
4783   "Sort threads by the sum of all scores in the thread.
4784 Unscored articles will be counted as having a score of zero."
4785   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4786
4787 (defun gnus-thread-total-score (thread)
4788   ;; This function find the total score of THREAD.
4789   (cond
4790    ((null thread)
4791     0)
4792    ((consp thread)
4793     (if (stringp (car thread))
4794         (apply gnus-thread-score-function 0
4795                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4796       (gnus-thread-total-score-1 thread)))
4797    (t
4798     (gnus-thread-total-score-1 (list thread)))))
4799
4800 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4801   "Sort threads such that the thread with the most recently arrived article comes first."
4802   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4803
4804 (defun gnus-thread-highest-number (thread)
4805   "Return the highest article number in THREAD."
4806   (apply 'max (mapcar (lambda (header)
4807                         (mail-header-number header))
4808                       (message-flatten-list thread))))
4809
4810 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4811   "Sort threads such that the thread with the most recently dated article comes first."
4812   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4813
4814 (defun gnus-thread-latest-date (thread)
4815   "Return the highest article date in THREAD."
4816   (let ((previous-time 0))
4817     (apply 'max
4818            (mapcar
4819             (lambda (header)
4820               (setq previous-time
4821                     (condition-case ()
4822                         (time-to-seconds (mail-header-parse-date
4823                                           (mail-header-date header)))
4824                       (error previous-time))))
4825             (sort
4826              (message-flatten-list thread)
4827              (lambda (h1 h2)
4828                (< (mail-header-number h1)
4829                   (mail-header-number h2))))))))
4830
4831 (defun gnus-thread-total-score-1 (root)
4832   ;; This function find the total score of the thread below ROOT.
4833   (setq root (car root))
4834   (apply gnus-thread-score-function
4835          (or (append
4836               (mapcar 'gnus-thread-total-score
4837                       (cdr (gnus-id-to-thread (mail-header-id root))))
4838               (when (> (mail-header-number root) 0)
4839                 (list (or (cdr (assq (mail-header-number root)
4840                                      gnus-newsgroup-scored))
4841                           gnus-summary-default-score 0))))
4842              (list gnus-summary-default-score)
4843              '(0))))
4844
4845 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4846 (defvar gnus-tmp-prev-subject nil)
4847 (defvar gnus-tmp-false-parent nil)
4848 (defvar gnus-tmp-root-expunged nil)
4849 (defvar gnus-tmp-dummy-line nil)
4850
4851 (eval-when-compile (defvar gnus-tmp-header))
4852 (defun gnus-extra-header (type &optional header)
4853   "Return the extra header of TYPE."
4854   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4855       ""))
4856
4857 (defvar gnus-tmp-thread-tree-header-string "")
4858
4859 (defcustom gnus-sum-thread-tree-root "> "
4860   "With %B spec, used for the root of a thread.
4861 If nil, use subject instead."
4862   :version "22.1"
4863   :type '(radio (const :format "%v  " nil) string)
4864   :group 'gnus-thread)
4865
4866 (defcustom gnus-sum-thread-tree-false-root "> "
4867   "With %B spec, used for a false root of a thread.
4868 If nil, use subject instead."
4869   :version "22.1"
4870   :type '(radio (const :format "%v  " nil) string)
4871   :group 'gnus-thread)
4872
4873 (defcustom gnus-sum-thread-tree-single-indent ""
4874   "With %B spec, used for a thread with just one message.
4875 If nil, use subject instead."
4876   :version "22.1"
4877   :type '(radio (const :format "%v  " nil) string)
4878   :group 'gnus-thread)
4879
4880 (defcustom gnus-sum-thread-tree-vertical "| "
4881   "With %B spec, used for drawing a vertical line."
4882   :version "22.1"
4883   :type 'string
4884   :group 'gnus-thread)
4885
4886 (defcustom gnus-sum-thread-tree-indent "  "
4887   "With %B spec, used for indenting."
4888   :version "22.1"
4889   :type 'string
4890   :group 'gnus-thread)
4891
4892 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4893   "With %B spec, used for a leaf with brothers."
4894   :version "22.1"
4895   :type 'string
4896   :group 'gnus-thread)
4897
4898 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4899   "With %B spec, used for a leaf without brothers."
4900   :version "22.1"
4901   :type 'string
4902   :group 'gnus-thread)
4903
4904 (defun gnus-summary-prepare-threads (threads)
4905   "Prepare summary buffer from THREADS and indentation LEVEL.
4906 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4907 or a straight list of headers."
4908   (gnus-message 7 "Generating summary...")
4909
4910   (setq gnus-newsgroup-threads threads)
4911   (beginning-of-line)
4912
4913   (let ((gnus-tmp-level 0)
4914         (default-score (or gnus-summary-default-score 0))
4915         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4916         (building-line-count gnus-summary-display-while-building)
4917         (building-count (integerp gnus-summary-display-while-building))
4918         thread number subject stack state gnus-tmp-gathered beg-match
4919         new-roots gnus-tmp-new-adopts thread-end simp-subject
4920         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4921         gnus-tmp-replied gnus-tmp-subject-or-nil
4922         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4923         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4924         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4925         tree-stack)
4926
4927     (setq gnus-tmp-prev-subject nil
4928           gnus-tmp-thread-tree-header-string "")
4929
4930     (if (vectorp (car threads))
4931         ;; If this is a straight (sic) list of headers, then a
4932         ;; threaded summary display isn't required, so we just create
4933         ;; an unthreaded one.
4934         (gnus-summary-prepare-unthreaded threads)
4935
4936       ;; Do the threaded display.
4937
4938       (if gnus-summary-display-while-building
4939           (switch-to-buffer (buffer-name)))
4940       (while (or threads stack gnus-tmp-new-adopts new-roots)
4941
4942         (if (and (= gnus-tmp-level 0)
4943                  (or (not stack)
4944                      (= (caar stack) 0))
4945                  (not gnus-tmp-false-parent)
4946                  (or gnus-tmp-new-adopts new-roots))
4947             (if gnus-tmp-new-adopts
4948                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4949                       thread (list (car gnus-tmp-new-adopts))
4950                       gnus-tmp-header (caar thread)
4951                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4952               (when new-roots
4953                 (setq thread (list (car new-roots))
4954                       gnus-tmp-header (caar thread)
4955                       new-roots (cdr new-roots))))
4956
4957           (if threads
4958               ;; If there are some threads, we do them before the
4959               ;; threads on the stack.
4960               (setq thread threads
4961                     gnus-tmp-header (caar thread))
4962             ;; There were no current threads, so we pop something off
4963             ;; the stack.
4964             (setq state (car stack)
4965                   gnus-tmp-level (car state)
4966                   tree-stack (cadr state)
4967                   thread (caddr state)
4968                   stack (cdr stack)
4969                   gnus-tmp-header (caar thread))))
4970
4971         (setq gnus-tmp-false-parent nil)
4972         (setq gnus-tmp-root-expunged nil)
4973         (setq thread-end nil)
4974
4975         (if (stringp gnus-tmp-header)
4976             ;; The header is a dummy root.
4977             (cond
4978              ((eq gnus-summary-make-false-root 'adopt)
4979               ;; We let the first article adopt the rest.
4980               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4981                                                (cddar thread)))
4982               (setq gnus-tmp-gathered
4983                     (nconc (mapcar
4984                             (lambda (h) (mail-header-number (car h)))
4985                             (cddar thread))
4986                            gnus-tmp-gathered))
4987               (setq thread (cons (list (caar thread)
4988                                        (cadar thread))
4989                                  (cdr thread)))
4990               (setq gnus-tmp-level -1
4991                     gnus-tmp-false-parent t))
4992              ((eq gnus-summary-make-false-root 'empty)
4993               ;; We print adopted articles with empty subject fields.
4994               (setq gnus-tmp-gathered
4995                     (nconc (mapcar
4996                             (lambda (h) (mail-header-number (car h)))
4997                             (cddar thread))
4998                            gnus-tmp-gathered))
4999               (setq gnus-tmp-level -1))
5000              ((eq gnus-summary-make-false-root 'dummy)
5001               ;; We remember that we probably want to output a dummy
5002               ;; root.
5003               (setq gnus-tmp-dummy-line gnus-tmp-header)
5004               (setq gnus-tmp-prev-subject gnus-tmp-header))
5005              (t
5006               ;; We do not make a root for the gathered
5007               ;; sub-threads at all.
5008               (setq gnus-tmp-level -1)))
5009
5010           (setq number (mail-header-number gnus-tmp-header)
5011                 subject (mail-header-subject gnus-tmp-header)
5012                 simp-subject (gnus-simplify-subject-fully subject))
5013
5014           (cond
5015            ;; If the thread has changed subject, we might want to make
5016            ;; this subthread into a root.
5017            ((and (null gnus-thread-ignore-subject)
5018                  (not (zerop gnus-tmp-level))
5019                  gnus-tmp-prev-subject
5020                  (not (string= gnus-tmp-prev-subject simp-subject)))
5021             (setq new-roots (nconc new-roots (list (car thread)))
5022                   thread-end t
5023                   gnus-tmp-header nil))
5024            ;; If the article lies outside the current limit,
5025            ;; then we do not display it.
5026            ((not (memq number gnus-newsgroup-limit))
5027             (setq gnus-tmp-gathered
5028                   (nconc (mapcar
5029                           (lambda (h) (mail-header-number (car h)))
5030                           (cdar thread))
5031                          gnus-tmp-gathered))
5032             (setq gnus-tmp-new-adopts (if (cdar thread)
5033                                           (append gnus-tmp-new-adopts
5034                                                   (cdar thread))
5035                                         gnus-tmp-new-adopts)
5036                   thread-end t
5037                   gnus-tmp-header nil)
5038             (when (zerop gnus-tmp-level)
5039               (setq gnus-tmp-root-expunged t)))
5040            ;; Perhaps this article is to be marked as read?
5041            ((and gnus-summary-mark-below
5042                  (< (or (cdr (assq number gnus-newsgroup-scored))
5043                         default-score)
5044                     gnus-summary-mark-below)
5045                  ;; Don't touch sparse articles.
5046                  (not (gnus-summary-article-sparse-p number))
5047                  (not (gnus-summary-article-ancient-p number)))
5048             (setq gnus-newsgroup-unreads
5049                   (delq number gnus-newsgroup-unreads))
5050             (if gnus-newsgroup-auto-expire
5051                 (setq gnus-newsgroup-expirable
5052                       (gnus-add-to-sorted-list
5053                        gnus-newsgroup-expirable number))
5054               (push (cons number gnus-low-score-mark)
5055                     gnus-newsgroup-reads))))
5056
5057           (when gnus-tmp-header
5058             ;; We may have an old dummy line to output before this
5059             ;; article.
5060             (when (and gnus-tmp-dummy-line
5061                        (gnus-subject-equal
5062                         gnus-tmp-dummy-line
5063                         (mail-header-subject gnus-tmp-header)))
5064               (gnus-summary-insert-dummy-line
5065                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5066               (setq gnus-tmp-dummy-line nil))
5067
5068             ;; Compute the mark.
5069             (setq gnus-tmp-unread (gnus-article-mark number))
5070
5071             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5072                                   gnus-tmp-header gnus-tmp-level)
5073                   gnus-newsgroup-data)
5074
5075             ;; Actually insert the line.
5076             (setq
5077              gnus-tmp-subject-or-nil
5078              (cond
5079               ((and gnus-thread-ignore-subject
5080                     gnus-tmp-prev-subject
5081                     (not (string= gnus-tmp-prev-subject simp-subject)))
5082                subject)
5083               ((zerop gnus-tmp-level)
5084                (if (and (eq gnus-summary-make-false-root 'empty)
5085                         (memq number gnus-tmp-gathered)
5086                         gnus-tmp-prev-subject
5087                         (string= gnus-tmp-prev-subject simp-subject))
5088                    gnus-summary-same-subject
5089                  subject))
5090               (t gnus-summary-same-subject)))
5091             (if (and (eq gnus-summary-make-false-root 'adopt)
5092                      (= gnus-tmp-level 1)
5093                      (memq number gnus-tmp-gathered))
5094                 (setq gnus-tmp-opening-bracket ?\<
5095                       gnus-tmp-closing-bracket ?\>)
5096               (setq gnus-tmp-opening-bracket ?\[
5097                     gnus-tmp-closing-bracket ?\]))
5098             (setq
5099              gnus-tmp-indentation
5100              (aref gnus-thread-indent-array gnus-tmp-level)
5101              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5102              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5103                                 gnus-summary-default-score 0)
5104              gnus-tmp-score-char
5105              (if (or (null gnus-summary-default-score)
5106                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5107                          gnus-summary-zcore-fuzz))
5108                  ?                      ;Whitespace
5109                (if (< gnus-tmp-score gnus-summary-default-score)
5110                    gnus-score-below-mark gnus-score-over-mark))
5111              gnus-tmp-replied
5112              (cond ((memq number gnus-newsgroup-processable)
5113                     gnus-process-mark)
5114                    ((memq number gnus-newsgroup-cached)
5115                     gnus-cached-mark)
5116                    ((memq number gnus-newsgroup-replied)
5117                     gnus-replied-mark)
5118                    ((memq number gnus-newsgroup-forwarded)
5119                     gnus-forwarded-mark)
5120                    ((memq number gnus-newsgroup-saved)
5121                     gnus-saved-mark)
5122                    ((memq number gnus-newsgroup-recent)
5123                     gnus-recent-mark)
5124                    ((memq number gnus-newsgroup-unseen)
5125                     gnus-unseen-mark)
5126                    (t gnus-no-mark))
5127              gnus-tmp-downloaded
5128              (cond ((memq number gnus-newsgroup-undownloaded)
5129                     gnus-undownloaded-mark)
5130                    (gnus-newsgroup-agentized
5131                     gnus-downloaded-mark)
5132                    (t
5133                     gnus-no-mark))
5134              gnus-tmp-from (mail-header-from gnus-tmp-header)
5135              gnus-tmp-name
5136              (cond
5137               ((string-match "<[^>]+> *$" gnus-tmp-from)
5138                (setq beg-match (match-beginning 0))
5139                (or (and (string-match "^\".+\"" gnus-tmp-from)
5140                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5141                    (substring gnus-tmp-from 0 beg-match)))
5142               ((string-match "(.+)" gnus-tmp-from)
5143                (substring gnus-tmp-from
5144                           (1+ (match-beginning 0)) (1- (match-end 0))))
5145               (t gnus-tmp-from))
5146
5147              ;; Do the %B string
5148              gnus-tmp-thread-tree-header-string
5149              (cond
5150               ((not gnus-show-threads) "")
5151               ((zerop gnus-tmp-level)
5152                (cond ((cdar thread)
5153                       (or gnus-sum-thread-tree-root subject))
5154                      (gnus-tmp-new-adopts
5155                       (or gnus-sum-thread-tree-false-root subject))
5156                      (t
5157                       (or gnus-sum-thread-tree-single-indent subject))))
5158               (t
5159                (concat (apply 'concat
5160                               (mapcar (lambda (item)
5161                                         (if (= item 1)
5162                                             gnus-sum-thread-tree-vertical
5163                                           gnus-sum-thread-tree-indent))
5164                                       (cdr (reverse tree-stack))))
5165                        (if (nth 1 thread)
5166                            gnus-sum-thread-tree-leaf-with-other
5167                          gnus-sum-thread-tree-single-leaf)))))
5168             (when (string= gnus-tmp-name "")
5169               (setq gnus-tmp-name gnus-tmp-from))
5170             (unless (numberp gnus-tmp-lines)
5171               (setq gnus-tmp-lines -1))
5172             (if (= gnus-tmp-lines -1)
5173                 (setq gnus-tmp-lines "?")
5174               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5175               (gnus-put-text-property
5176              (point)
5177              (progn (eval gnus-summary-line-format-spec) (point))
5178                'gnus-number number)
5179             (when gnus-visual-p
5180               (forward-line -1)
5181               (gnus-run-hooks 'gnus-summary-update-hook)
5182               (forward-line 1))
5183
5184             (setq gnus-tmp-prev-subject simp-subject)))
5185
5186         (when (nth 1 thread)
5187           (push (list (max 0 gnus-tmp-level)
5188                       (copy-sequence tree-stack)
5189                       (nthcdr 1 thread))
5190                 stack))
5191         (push (if (nth 1 thread) 1 0) tree-stack)
5192         (incf gnus-tmp-level)
5193         (setq threads (if thread-end nil (cdar thread)))
5194         (if gnus-summary-display-while-building
5195             (if building-count
5196                 (progn
5197                   ;; use a set frequency
5198                   (setq building-line-count (1- building-line-count))
5199                   (when (= building-line-count 0)
5200                     (sit-for 0)
5201                     (setq building-line-count
5202                           gnus-summary-display-while-building)))
5203               ;; always
5204               (sit-for 0)))
5205         (unless threads
5206           (setq gnus-tmp-level 0)))))
5207   (gnus-message 7 "Generating summary...done"))
5208
5209 (defun gnus-summary-prepare-unthreaded (headers)
5210   "Generate an unthreaded summary buffer based on HEADERS."
5211   (let (header number mark)
5212
5213     (beginning-of-line)
5214
5215     (while headers
5216       ;; We may have to root out some bad articles...
5217       (when (memq (setq number (mail-header-number
5218                                 (setq header (pop headers))))
5219                   gnus-newsgroup-limit)
5220         ;; Mark article as read when it has a low score.
5221         (when (and gnus-summary-mark-below
5222                    (< (or (cdr (assq number gnus-newsgroup-scored))
5223                           gnus-summary-default-score 0)
5224                       gnus-summary-mark-below)
5225                    (not (gnus-summary-article-ancient-p number)))
5226           (setq gnus-newsgroup-unreads
5227                 (delq number gnus-newsgroup-unreads))
5228           (if gnus-newsgroup-auto-expire
5229               (push number gnus-newsgroup-expirable)
5230             (push (cons number gnus-low-score-mark)
5231                   gnus-newsgroup-reads)))
5232
5233         (setq mark (gnus-article-mark number))
5234         (push (gnus-data-make number mark (1+ (point)) header 0)
5235               gnus-newsgroup-data)
5236         (gnus-summary-insert-line
5237          header 0 number
5238          (memq number gnus-newsgroup-undownloaded)
5239          mark (memq number gnus-newsgroup-replied)
5240          (memq number gnus-newsgroup-expirable)
5241          (mail-header-subject header) nil
5242          (cdr (assq number gnus-newsgroup-scored))
5243          (memq number gnus-newsgroup-processable))))))
5244
5245 (defun gnus-summary-remove-list-identifiers ()
5246   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5247   (let ((regexp (if (consp gnus-list-identifiers)
5248                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5249                   gnus-list-identifiers))
5250         changed subject)
5251     (when regexp
5252       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5253       (dolist (header gnus-newsgroup-headers)
5254         (setq subject (mail-header-subject header)
5255               changed nil)
5256         (while (string-match regexp subject)
5257           (setq subject
5258                 (concat (substring subject 0 (match-beginning 1))
5259                         (substring subject (match-end 0)))
5260                 changed t))
5261         (when changed
5262           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5263             (setq subject
5264                   (concat (substring subject 0 (match-beginning 1))
5265                           (substring subject (match-end 1)))))
5266           (mail-header-set-subject header subject))))))
5267
5268 (defun gnus-fetch-headers (articles)
5269   "Fetch headers of ARTICLES."
5270   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5271     (gnus-message 5 "Fetching headers for %s..." name)
5272     (prog1
5273         (if (eq 'nov
5274                 (setq gnus-headers-retrieved-by
5275                       (gnus-retrieve-headers
5276                        articles gnus-newsgroup-name
5277                        ;; We might want to fetch old headers, but
5278                        ;; not if there is only 1 article.
5279                        (and (or (and
5280                                  (not (eq gnus-fetch-old-headers 'some))
5281                                  (not (numberp gnus-fetch-old-headers)))
5282                                 (> (length articles) 1))
5283                             gnus-fetch-old-headers))))
5284             (gnus-get-newsgroup-headers-xover
5285              articles nil nil gnus-newsgroup-name t)
5286           (gnus-get-newsgroup-headers))
5287       (gnus-message 5 "Fetching headers for %s...done" name))))
5288
5289 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5290   "Select newsgroup GROUP.
5291 If READ-ALL is non-nil, all articles in the group are selected.
5292 If SELECT-ARTICLES, only select those articles from GROUP."
5293   (let* ((entry (gnus-group-entry group))
5294          ;;!!! Dirty hack; should be removed.
5295          (gnus-summary-ignore-duplicates
5296           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5297               t
5298             gnus-summary-ignore-duplicates))
5299          (info (nth 2 entry))
5300          articles fetched-articles cached)
5301
5302     (unless (gnus-check-server
5303              (set (make-local-variable 'gnus-current-select-method)
5304                   (gnus-find-method-for-group group)))
5305       (error "Couldn't open server"))
5306
5307     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5308         (gnus-activate-group group)     ; Or we can activate it...
5309         (progn                          ; Or we bug out.
5310           (when (equal major-mode 'gnus-summary-mode)
5311             (gnus-kill-buffer (current-buffer)))
5312           (error "Couldn't activate group %s: %s"
5313                  group (gnus-status-message group))))
5314
5315     (unless (gnus-request-group group t)
5316       (when (equal major-mode 'gnus-summary-mode)
5317         (gnus-kill-buffer (current-buffer)))
5318       (error "Couldn't request group %s: %s"
5319              group (gnus-status-message group)))
5320
5321     (when gnus-agent
5322       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5323
5324       (setq gnus-summary-use-undownloaded-faces
5325             (gnus-agent-find-parameter
5326              group
5327              'agent-enable-undownloaded-faces)))
5328
5329     (setq gnus-newsgroup-name group
5330           gnus-newsgroup-unselected nil
5331           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5332
5333     (let ((display (gnus-group-find-parameter group 'display)))
5334       (setq gnus-newsgroup-display
5335             (cond
5336              ((not (zerop (or (car-safe read-all) 0)))
5337               ;; The user entered the group with C-u SPC/RET, let's show
5338               ;; all articles.
5339               'gnus-not-ignore)
5340              ((eq display 'all)
5341               'gnus-not-ignore)
5342              ((arrayp display)
5343               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5344              ((numberp display)
5345               ;; The following is probably the "correct" solution, but
5346               ;; it makes Gnus fetch all headers and then limit the
5347               ;; articles (which is slow), so instead we hack the
5348               ;; select-articles parameter instead. -- Simon Josefsson
5349               ;; <jas@kth.se>
5350               ;;
5351               ;; (gnus-byte-compile
5352               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5353               ;;                         display)))))
5354               (setq select-articles
5355                     (gnus-uncompress-range
5356                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5357                              (if (> tmp 0)
5358                                  tmp
5359                                1))
5360                            (cdr (gnus-active group)))))
5361               nil)
5362              (t
5363               nil))))
5364
5365     (gnus-summary-setup-default-charset)
5366
5367     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5368     (when (gnus-virtual-group-p group)
5369       (setq cached gnus-newsgroup-cached))
5370
5371     (setq gnus-newsgroup-unreads
5372           (gnus-sorted-ndifference
5373            (gnus-sorted-ndifference gnus-newsgroup-unreads
5374                                     gnus-newsgroup-marked)
5375            gnus-newsgroup-dormant))
5376
5377     (setq gnus-newsgroup-processable nil)
5378
5379     (gnus-update-read-articles group gnus-newsgroup-unreads)
5380
5381     ;; Adjust and set lists of article marks.
5382     (when info
5383       (gnus-adjust-marked-articles info))
5384     (if (setq articles select-articles)
5385         (setq gnus-newsgroup-unselected
5386               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5387       (setq articles (gnus-articles-to-read group read-all)))
5388
5389     (cond
5390      ((null articles)
5391       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5392       'quit)
5393      ((eq articles 0) nil)
5394      (t
5395       ;; Init the dependencies hash table.
5396       (setq gnus-newsgroup-dependencies
5397             (gnus-make-hashtable (length articles)))
5398       (gnus-set-global-variables)
5399       ;; Retrieve the headers and read them in.
5400
5401       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5402
5403       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5404       (when cached
5405         (setq gnus-newsgroup-cached cached))
5406
5407       ;; Suppress duplicates?
5408       (when gnus-suppress-duplicates
5409         (gnus-dup-suppress-articles))
5410
5411       ;; Set the initial limit.
5412       (setq gnus-newsgroup-limit (copy-sequence articles))
5413       ;; Remove canceled articles from the list of unread articles.
5414       (setq fetched-articles
5415             (mapcar (lambda (headers) (mail-header-number headers))
5416                     gnus-newsgroup-headers))
5417       (setq gnus-newsgroup-articles fetched-articles)
5418       (setq gnus-newsgroup-unreads
5419             (gnus-sorted-nintersection
5420              gnus-newsgroup-unreads fetched-articles))
5421       (gnus-compute-unseen-list)
5422
5423       ;; Removed marked articles that do not exist.
5424       (gnus-update-missing-marks
5425        (gnus-sorted-difference articles fetched-articles))
5426       ;; We might want to build some more threads first.
5427       (when (and gnus-fetch-old-headers
5428                  (eq gnus-headers-retrieved-by 'nov))
5429         (if (eq gnus-fetch-old-headers 'invisible)
5430             (gnus-build-all-threads)
5431           (gnus-build-old-threads)))
5432       ;; Let the Gnus agent mark articles as read.
5433       (when gnus-agent
5434         (gnus-agent-get-undownloaded-list))
5435       ;; Remove list identifiers from subject
5436       (when gnus-list-identifiers
5437         (gnus-summary-remove-list-identifiers))
5438       ;; Check whether auto-expire is to be done in this group.
5439       (setq gnus-newsgroup-auto-expire
5440             (gnus-group-auto-expirable-p group))
5441       ;; Set up the article buffer now, if necessary.
5442       (unless gnus-single-article-buffer
5443         (gnus-article-setup-buffer))
5444       ;; First and last article in this newsgroup.
5445       (when gnus-newsgroup-headers
5446         (setq gnus-newsgroup-begin
5447               (mail-header-number (car gnus-newsgroup-headers))
5448               gnus-newsgroup-end
5449               (mail-header-number
5450                (gnus-last-element gnus-newsgroup-headers))))
5451       ;; GROUP is successfully selected.
5452       (or gnus-newsgroup-headers t)))))
5453
5454 (defun gnus-compute-unseen-list ()
5455   ;; The `seen' marks are treated specially.
5456   (if (not gnus-newsgroup-seen)
5457       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5458     (setq gnus-newsgroup-unseen
5459           (gnus-inverse-list-range-intersection
5460            gnus-newsgroup-articles gnus-newsgroup-seen))))
5461
5462 (defun gnus-summary-display-make-predicate (display)
5463   (require 'gnus-agent)
5464   (when (= (length display) 1)
5465     (setq display (car display)))
5466   (unless gnus-summary-display-cache
5467     (dolist (elem (append '((unread . unread)
5468                             (read . read)
5469                             (unseen . unseen))
5470                           gnus-article-mark-lists))
5471       (push (cons (cdr elem)
5472                   (gnus-byte-compile
5473                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5474             gnus-summary-display-cache)))
5475   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5476         (gnus-category-predicate-cache gnus-summary-display-cache))
5477     (gnus-get-predicate display)))
5478
5479 ;; Uses the dynamically bound `number' variable.
5480 (eval-when-compile
5481   (defvar number))
5482 (defun gnus-article-marked-p (type &optional article)
5483   (let ((article (or article number)))
5484     (cond
5485      ((eq type 'tick)
5486       (memq article gnus-newsgroup-marked))
5487      ((eq type 'spam)
5488       (memq article gnus-newsgroup-spam-marked))
5489      ((eq type 'unsend)
5490       (memq article gnus-newsgroup-unsendable))
5491      ((eq type 'undownload)
5492       (memq article gnus-newsgroup-undownloaded))
5493      ((eq type 'download)
5494       (memq article gnus-newsgroup-downloadable))
5495      ((eq type 'unread)
5496       (memq article gnus-newsgroup-unreads))
5497      ((eq type 'read)
5498       (memq article gnus-newsgroup-reads))
5499      ((eq type 'dormant)
5500       (memq article gnus-newsgroup-dormant) )
5501      ((eq type 'expire)
5502       (memq article gnus-newsgroup-expirable))
5503      ((eq type 'reply)
5504       (memq article gnus-newsgroup-replied))
5505      ((eq type 'killed)
5506       (memq article gnus-newsgroup-killed))
5507      ((eq type 'bookmark)
5508       (assq article gnus-newsgroup-bookmarks))
5509      ((eq type 'score)
5510       (assq article gnus-newsgroup-scored))
5511      ((eq type 'save)
5512       (memq article gnus-newsgroup-saved))
5513      ((eq type 'cache)
5514       (memq article gnus-newsgroup-cached))
5515      ((eq type 'forward)
5516       (memq article gnus-newsgroup-forwarded))
5517      ((eq type 'seen)
5518       (not (memq article gnus-newsgroup-unseen)))
5519      ((eq type 'recent)
5520       (memq article gnus-newsgroup-recent))
5521      (t t))))
5522
5523 (defun gnus-articles-to-read (group &optional read-all)
5524   "Find out what articles the user wants to read."
5525   (let* ((articles
5526           ;; Select all articles if `read-all' is non-nil, or if there
5527           ;; are no unread articles.
5528           (if (or read-all
5529                   (and (zerop (length gnus-newsgroup-marked))
5530                        (zerop (length gnus-newsgroup-unreads)))
5531                   ;; Fetch all if the predicate is non-nil.
5532                   gnus-newsgroup-display)
5533               ;; We want to select the headers for all the articles in
5534               ;; the group, so we select either all the active
5535               ;; articles in the group, or (if that's nil), the
5536               ;; articles in the cache.
5537               (or
5538                (gnus-uncompress-range (gnus-active group))
5539                (gnus-cache-articles-in-group group))
5540             ;; Select only the "normal" subset of articles.
5541             (gnus-sorted-nunion
5542              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5543              gnus-newsgroup-unreads)))
5544          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5545          (scored (length scored-list))
5546          (number (length articles))
5547          (marked (+ (length gnus-newsgroup-marked)
5548                     (length gnus-newsgroup-dormant)))
5549          (select
5550           (cond
5551            ((numberp read-all)
5552             read-all)
5553            ((numberp gnus-newsgroup-display)
5554             gnus-newsgroup-display)
5555            (t
5556             (condition-case ()
5557                 (cond
5558                  ((and (or (<= scored marked) (= scored number))
5559                        (numberp gnus-large-newsgroup)
5560                        (> number gnus-large-newsgroup))
5561                   (let* ((cursor-in-echo-area nil)
5562                          (initial (gnus-parameter-large-newsgroup-initial
5563                                    gnus-newsgroup-name))
5564                          (input
5565                           (read-string
5566                            (format
5567                             "How many articles from %s (%s %d): "
5568                             (gnus-limit-string
5569                              (gnus-group-decoded-name gnus-newsgroup-name)
5570                              35)
5571                             (if initial "max" "default")
5572                             number)
5573                            (if initial
5574                                (cons (number-to-string initial)
5575                                      0)))))
5576                     (if (string-match "^[ \t]*$" input) number input)))
5577                  ((and (> scored marked) (< scored number)
5578                        (> (- scored number) 20))
5579                   (let ((input
5580                          (read-string
5581                           (format "%s %s (%d scored, %d total): "
5582                                   "How many articles from"
5583                                   (gnus-group-decoded-name group)
5584                                   scored number))))
5585                     (if (string-match "^[ \t]*$" input)
5586                         number input)))
5587                  (t number))
5588               (quit
5589                (message "Quit getting the articles to read")
5590                nil))))))
5591     (setq select (if (stringp select) (string-to-number select) select))
5592     (if (or (null select) (zerop select))
5593         select
5594       (if (and (not (zerop scored)) (<= (abs select) scored))
5595           (progn
5596             (setq articles (sort scored-list '<))
5597             (setq number (length articles)))
5598         (setq articles (copy-sequence articles)))
5599
5600       (when (< (abs select) number)
5601         (if (< select 0)
5602             ;; Select the N oldest articles.
5603             (setcdr (nthcdr (1- (abs select)) articles) nil)
5604           ;; Select the N most recent articles.
5605           (setq articles (nthcdr (- number select) articles))))
5606       (setq gnus-newsgroup-unselected
5607             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5608       (when gnus-alter-articles-to-read-function
5609         (setq articles
5610               (sort
5611                (funcall gnus-alter-articles-to-read-function
5612                         gnus-newsgroup-name articles)
5613                '<)))
5614       articles)))
5615
5616 (defun gnus-killed-articles (killed articles)
5617   (let (out)
5618     (while articles
5619       (when (inline (gnus-member-of-range (car articles) killed))
5620         (push (car articles) out))
5621       (setq articles (cdr articles)))
5622     out))
5623
5624 (defun gnus-uncompress-marks (marks)
5625   "Uncompress the mark ranges in MARKS."
5626   (let ((uncompressed '(score bookmark))
5627         out)
5628     (while marks
5629       (if (memq (caar marks) uncompressed)
5630           (push (car marks) out)
5631         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5632       (setq marks (cdr marks)))
5633     out))
5634
5635 (defun gnus-article-mark-to-type (mark)
5636   "Return the type of MARK."
5637   (or (cadr (assq mark gnus-article-special-mark-lists))
5638       'list))
5639
5640 (defun gnus-article-unpropagatable-p (mark)
5641   "Return whether MARK should be propagated to back end."
5642   (memq mark gnus-article-unpropagated-mark-lists))
5643
5644 (defun gnus-adjust-marked-articles (info)
5645   "Set all article lists and remove all marks that are no longer valid."
5646   (let* ((marked-lists (gnus-info-marks info))
5647          (active (gnus-active (gnus-info-group info)))
5648          (min (car active))
5649          (max (cdr active))
5650          (types gnus-article-mark-lists)
5651          marks var articles article mark mark-type
5652          bgn end)
5653
5654     (dolist (marks marked-lists)
5655       (setq mark (car marks)
5656             mark-type (gnus-article-mark-to-type mark)
5657             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5658
5659       ;; We set the variable according to the type of the marks list,
5660       ;; and then adjust the marks to a subset of the active articles.
5661       (cond
5662        ;; Adjust "simple" lists - compressed yet unsorted
5663        ((eq mark-type 'list)
5664         ;; Simultaneously uncompress and clip to active range
5665         ;; See gnus-uncompress-range for a description of possible marks
5666         (let (l lh)
5667           (if (not (cadr marks))
5668               (set var nil)
5669             (setq articles (if (numberp (cddr marks))
5670                                (list (cdr marks))
5671                              (cdr marks))
5672                   lh (cons nil nil)
5673                   l lh)
5674
5675             (while (setq article (pop articles))
5676               (cond ((consp article)
5677                      (setq bgn (max (car article) min)
5678                            end (min (cdr article) max))
5679                      (while (<= bgn end)
5680                        (setq l (setcdr l (cons bgn nil))
5681                              bgn (1+ bgn))))
5682                     ((and (<= min article)
5683                           (>= max article))
5684                      (setq l (setcdr l (cons article nil))))))
5685             (set var (cdr lh)))))
5686        ;; Adjust assocs.
5687        ((eq mark-type 'tuple)
5688         (set var (setq articles (cdr marks)))
5689         (when (not (listp (cdr (symbol-value var))))
5690           (set var (list (symbol-value var))))
5691         (when (not (listp (cdr articles)))
5692           (setq articles (list articles)))
5693         (while articles
5694           (when (or (not (consp (setq article (pop articles))))
5695                     (< (car article) min)
5696                     (> (car article) max))
5697             (set var (delq article (symbol-value var))))))
5698        ;; Adjust ranges (sloppily).
5699        ((eq mark-type 'range)
5700         (cond
5701          ((eq mark 'seen)
5702           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5703           ;; It should be (seen (NUM1 . NUM2)).
5704           (when (numberp (cddr marks))
5705             (setcdr marks (list (cdr marks))))
5706           (setq articles (cdr marks))
5707           (while (and articles
5708                       (or (and (consp (car articles))
5709                                (> min (cdar articles)))
5710                           (and (numberp (car articles))
5711                                (> min (car articles)))))
5712             (pop articles))
5713           (set var articles))))))))
5714
5715 (defun gnus-update-missing-marks (missing)
5716   "Go through the list of MISSING articles and remove them from the mark lists."
5717   (when missing
5718     (let (var m)
5719       ;; Go through all types.
5720       (dolist (elem gnus-article-mark-lists)
5721         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5722           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5723           (when (symbol-value var)
5724             ;; This list has articles.  So we delete all missing
5725             ;; articles from it.
5726             (setq m missing)
5727             (while m
5728               (set var (delq (pop m) (symbol-value var))))))))))
5729
5730 (defun gnus-update-marks ()
5731   "Enter the various lists of marked articles into the newsgroup info list."
5732   (let ((types gnus-article-mark-lists)
5733         (info (gnus-get-info gnus-newsgroup-name))
5734         type list newmarked symbol delta-marks)
5735     (when info
5736       ;; Add all marks lists to the list of marks lists.
5737       (while (setq type (pop types))
5738         (setq list (symbol-value
5739                     (setq symbol
5740                           (intern (format "gnus-newsgroup-%s" (car type))))))
5741
5742         (when list
5743           ;; Get rid of the entries of the articles that have the
5744           ;; default score.
5745           (when (and (eq (cdr type) 'score)
5746                      gnus-save-score
5747                      list)
5748             (let* ((arts list)
5749                    (prev (cons nil list))
5750                    (all prev))
5751               (while arts
5752                 (if (or (not (consp (car arts)))
5753                         (= (cdar arts) gnus-summary-default-score))
5754                     (setcdr prev (cdr arts))
5755                   (setq prev arts))
5756                 (setq arts (cdr arts)))
5757               (setq list (cdr all)))))
5758
5759         (when (eq (cdr type) 'seen)
5760           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5761
5762         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5763           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5764
5765         (when (and (gnus-check-backend-function
5766                     'request-set-mark gnus-newsgroup-name)
5767                    (not (gnus-article-unpropagatable-p (cdr type))))
5768           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5769                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5770                  (add (gnus-remove-from-range
5771                        (gnus-copy-sequence list) old)))
5772             (when add
5773               (push (list add 'add (list (cdr type))) delta-marks))
5774             (when del
5775               (push (list del 'del (list (cdr type))) delta-marks))))
5776
5777         (when list
5778           (push (cons (cdr type) list) newmarked)))
5779
5780       (when delta-marks
5781         (unless (gnus-check-group gnus-newsgroup-name)
5782           (error "Can't open server for %s" gnus-newsgroup-name))
5783         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5784
5785       ;; Enter these new marks into the info of the group.
5786       (if (nthcdr 3 info)
5787           (setcar (nthcdr 3 info) newmarked)
5788         ;; Add the marks lists to the end of the info.
5789         (when newmarked
5790           (setcdr (nthcdr 2 info) (list newmarked))))
5791
5792       ;; Cut off the end of the info if there's nothing else there.
5793       (let ((i 5))
5794         (while (and (> i 2)
5795                     (not (nth i info)))
5796           (when (nthcdr (decf i) info)
5797             (setcdr (nthcdr i info) nil)))))))
5798
5799 (defun gnus-set-mode-line (where)
5800   "Set the mode line of the article or summary buffers.
5801 If WHERE is `summary', the summary mode line format will be used."
5802   ;; Is this mode line one we keep updated?
5803   (when (and (memq where gnus-updated-mode-lines)
5804              (symbol-value
5805               (intern (format "gnus-%s-mode-line-format-spec" where))))
5806     (let (mode-string)
5807       (save-excursion
5808         ;; We evaluate this in the summary buffer since these
5809         ;; variables are buffer-local to that buffer.
5810         (set-buffer gnus-summary-buffer)
5811        ;; We bind all these variables that are used in the `eval' form
5812         ;; below.
5813         (let* ((mformat (symbol-value
5814                          (intern
5815                           (format "gnus-%s-mode-line-format-spec" where))))
5816                (gnus-tmp-group-name (gnus-group-decoded-name
5817                                      gnus-newsgroup-name))
5818                (gnus-tmp-article-number (or gnus-current-article 0))
5819                (gnus-tmp-unread gnus-newsgroup-unreads)
5820                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5821                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5822                (gnus-tmp-unread-and-unselected
5823                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5824                             (zerop gnus-tmp-unselected))
5825                        "")
5826                       ((zerop gnus-tmp-unselected)
5827                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5828                       (t (format "{%d(+%d) more}"
5829                                  gnus-tmp-unread-and-unticked
5830                                  gnus-tmp-unselected))))
5831                (gnus-tmp-subject
5832                 (if (and gnus-current-headers
5833                          (vectorp gnus-current-headers))
5834                     (gnus-mode-string-quote
5835                      (mail-header-subject gnus-current-headers))
5836                   ""))
5837                bufname-length max-len
5838                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5839           (setq mode-string (eval mformat))
5840           (setq bufname-length (if (string-match "%b" mode-string)
5841                                    (- (length
5842                                        (buffer-name
5843                                         (if (eq where 'summary)
5844                                             nil
5845                                           (get-buffer gnus-article-buffer))))
5846                                       2)
5847                                  0))
5848           (setq max-len (max 4 (if gnus-mode-non-string-length
5849                                    (- (window-width)
5850                                       gnus-mode-non-string-length
5851                                       bufname-length)
5852                                  (length mode-string))))
5853           ;; We might have to chop a bit of the string off...
5854           (when (> (length mode-string) max-len)
5855             (setq mode-string
5856                   (concat (truncate-string-to-width mode-string (- max-len 3))
5857                           "...")))
5858           ;; Pad the mode string a bit.
5859           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5860       ;; Update the mode line.
5861       (setq mode-line-buffer-identification
5862             (gnus-mode-line-buffer-identification (list mode-string)))
5863       (set-buffer-modified-p t))))
5864
5865 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5866   "Go through the HEADERS list and add all Xrefs to a hash table.
5867 The resulting hash table is returned, or nil if no Xrefs were found."
5868   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5869          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5870          (xref-hashtb (gnus-make-hashtable))
5871          start group entry number xrefs header)
5872     (while headers
5873       (setq header (pop headers))
5874       (when (and (setq xrefs (mail-header-xref header))
5875                  (not (memq (setq number (mail-header-number header))
5876                             unreads)))
5877         (setq start 0)
5878         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5879           (setq start (match-end 0))
5880           (setq group (if prefix
5881                           (concat prefix (substring xrefs (match-beginning 1)
5882                                                     (match-end 1)))
5883                         (substring xrefs (match-beginning 1) (match-end 1))))
5884           (setq number
5885                 (string-to-number (substring xrefs (match-beginning 2)
5886                                           (match-end 2))))
5887           (if (setq entry (gnus-gethash group xref-hashtb))
5888               (setcdr entry (cons number (cdr entry)))
5889             (gnus-sethash group (cons number nil) xref-hashtb)))))
5890     (and start xref-hashtb)))
5891
5892 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5893   "Look through all the headers and mark the Xrefs as read."
5894   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5895         name info xref-hashtb idlist method nth4)
5896     (save-excursion
5897       (set-buffer gnus-group-buffer)
5898       (when (setq xref-hashtb
5899                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5900         (mapatoms
5901          (lambda (group)
5902            (unless (string= from-newsgroup (setq name (symbol-name group)))
5903              (setq idlist (symbol-value group))
5904              ;; Dead groups are not updated.
5905              (and (prog1
5906                       (setq info (gnus-get-info name))
5907                     (when (stringp (setq nth4 (gnus-info-method info)))
5908                       (setq nth4 (gnus-server-to-method nth4))))
5909                   ;; Only do the xrefs if the group has the same
5910                   ;; select method as the group we have just read.
5911                   (or (gnus-methods-equal-p
5912                        nth4 (gnus-find-method-for-group from-newsgroup))
5913                       virtual
5914                       (equal nth4 (setq method (gnus-find-method-for-group
5915                                                 from-newsgroup)))
5916                       (and (equal (car nth4) (car method))
5917                            (equal (nth 1 nth4) (nth 1 method))))
5918                   gnus-use-cross-reference
5919                   (or (not (eq gnus-use-cross-reference t))
5920                       virtual
5921                       ;; Only do cross-references on subscribed
5922                       ;; groups, if that is what is wanted.
5923                       (<= (gnus-info-level info) gnus-level-subscribed))
5924                   (gnus-group-make-articles-read name idlist))))
5925          xref-hashtb)))))
5926
5927 (defun gnus-compute-read-articles (group articles)
5928   (let* ((entry (gnus-group-entry group))
5929          (info (nth 2 entry))
5930          (active (gnus-active group))
5931          ninfo)
5932     (when entry
5933       ;; First peel off all invalid article numbers.
5934       (when active
5935         (let ((ids articles)
5936               id first)
5937           (while (setq id (pop ids))
5938             (when (and first (> id (cdr active)))
5939               ;; We'll end up in this situation in one particular
5940               ;; obscure situation.  If you re-scan a group and get
5941               ;; a new article that is cross-posted to a different
5942               ;; group that has not been re-scanned, you might get
5943               ;; crossposted article that has a higher number than
5944               ;; Gnus believes possible.  So we re-activate this
5945               ;; group as well.  This might mean doing the
5946               ;; crossposting thingy will *increase* the number
5947               ;; of articles in some groups.  Tsk, tsk.
5948               (setq active (or (gnus-activate-group group) active)))
5949             (when (or (> id (cdr active))
5950                       (< id (car active)))
5951               (setq articles (delq id articles))))))
5952       ;; If the read list is nil, we init it.
5953       (if (and active
5954                (null (gnus-info-read info))
5955                (> (car active) 1))
5956           (setq ninfo (cons 1 (1- (car active))))
5957         (setq ninfo (gnus-info-read info)))
5958       ;; Then we add the read articles to the range.
5959       (gnus-add-to-range
5960        ninfo (setq articles (sort articles '<))))))
5961
5962 (defun gnus-group-make-articles-read (group articles)
5963   "Update the info of GROUP to say that ARTICLES are read."
5964   (let* ((num 0)
5965          (entry (gnus-group-entry group))
5966          (info (nth 2 entry))
5967          (active (gnus-active group))
5968          range)
5969     (when entry
5970       (setq range (gnus-compute-read-articles group articles))
5971       (with-current-buffer gnus-group-buffer
5972         (gnus-undo-register
5973           `(progn
5974              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5975              (gnus-info-set-read ',info ',(gnus-info-read info))
5976              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5977              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5978              (gnus-group-update-group ,group t))))
5979       ;; Add the read articles to the range.
5980       (gnus-info-set-read info range)
5981       (gnus-request-set-mark group (list (list range 'add '(read))))
5982       ;; Then we have to re-compute how many unread
5983       ;; articles there are in this group.
5984       (when active
5985         (cond
5986          ((not range)
5987           (setq num (- (1+ (cdr active)) (car active))))
5988          ((not (listp (cdr range)))
5989           (setq num (- (cdr active) (- (1+ (cdr range))
5990                                        (car range)))))
5991          (t
5992           (while range
5993             (if (numberp (car range))
5994                 (setq num (1+ num))
5995               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5996             (setq range (cdr range)))
5997           (setq num (- (cdr active) num))))
5998         ;; Update the number of unread articles.
5999         (setcar entry num)
6000         ;; Update the group buffer.
6001         (unless (gnus-ephemeral-group-p group)
6002           (gnus-group-update-group group t))))))
6003
6004 (defvar gnus-newsgroup-none-id 0)
6005
6006 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6007   (let ((cur nntp-server-buffer)
6008         (dependencies
6009          (or dependencies
6010              (with-current-buffer gnus-summary-buffer
6011                gnus-newsgroup-dependencies)))
6012         headers id end ref number
6013         (mail-parse-charset gnus-newsgroup-charset)
6014         (mail-parse-ignored-charsets
6015          (save-excursion (condition-case nil
6016                              (set-buffer gnus-summary-buffer)
6017                            (error))
6018                          gnus-newsgroup-ignored-charsets)))
6019     (save-excursion
6020       (set-buffer nntp-server-buffer)
6021       ;; Translate all TAB characters into SPACE characters.
6022       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6023       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6024       (ietf-drums-unfold-fws)
6025       (gnus-run-hooks 'gnus-parse-headers-hook)
6026       (let ((case-fold-search t)
6027             in-reply-to header p lines chars)
6028         (goto-char (point-min))
6029         ;; Search to the beginning of the next header.  Error messages
6030         ;; do not begin with 2 or 3.
6031         (while (re-search-forward "^[23][0-9]+ " nil t)
6032           (setq id nil
6033                 ref nil)
6034           ;; This implementation of this function, with nine
6035           ;; search-forwards instead of the one re-search-forward and
6036           ;; a case (which basically was the old function) is actually
6037           ;; about twice as fast, even though it looks messier.  You
6038           ;; can't have everything, I guess.  Speed and elegance
6039           ;; doesn't always go hand in hand.
6040           (setq
6041            header
6042            (vector
6043             ;; Number.
6044             (prog1
6045                 (setq number (read cur))
6046               (end-of-line)
6047               (setq p (point))
6048               (narrow-to-region (point)
6049                                 (or (and (search-forward "\n.\n" nil t)
6050                                          (- (point) 2))
6051                                     (point))))
6052             ;; Subject.
6053             (progn
6054               (goto-char p)
6055               (if (search-forward "\nsubject:" nil t)
6056                   (funcall gnus-decode-encoded-word-function
6057                            (nnheader-header-value))
6058                 "(none)"))
6059             ;; From.
6060             (progn
6061               (goto-char p)
6062               (if (search-forward "\nfrom:" nil t)
6063                   (funcall gnus-decode-encoded-word-function
6064                            (nnheader-header-value))
6065                 "(nobody)"))
6066             ;; Date.
6067             (progn
6068               (goto-char p)
6069               (if (search-forward "\ndate:" nil t)
6070                   (nnheader-header-value) ""))
6071             ;; Message-ID.
6072             (progn
6073               (goto-char p)
6074               (setq id (if (re-search-forward
6075                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6076                            ;; We do it this way to make sure the Message-ID
6077                            ;; is (somewhat) syntactically valid.
6078                            (buffer-substring (match-beginning 1)
6079                                              (match-end 1))
6080                          ;; If there was no message-id, we just fake one
6081                          ;; to make subsequent routines simpler.
6082                          (nnheader-generate-fake-message-id number))))
6083             ;; References.
6084             (progn
6085               (goto-char p)
6086               (if (search-forward "\nreferences:" nil t)
6087                   (progn
6088                     (setq end (point))
6089                     (prog1
6090                         (nnheader-header-value)
6091                       (setq ref
6092                             (buffer-substring
6093                              (progn
6094                                (end-of-line)
6095                                (search-backward ">" end t)
6096                                (1+ (point)))
6097                              (progn
6098                                (search-backward "<" end t)
6099                                (point))))))
6100                 ;; Get the references from the in-reply-to header if there
6101                 ;; were no references and the in-reply-to header looks
6102                 ;; promising.
6103                 (if (and (search-forward "\nin-reply-to:" nil t)
6104                          (setq in-reply-to (nnheader-header-value))
6105                          (string-match "<[^>]+>" in-reply-to))
6106                     (let (ref2)
6107                       (setq ref (substring in-reply-to (match-beginning 0)
6108                                            (match-end 0)))
6109                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6110                         (setq ref2 (substring in-reply-to (match-beginning 0)
6111                                               (match-end 0)))
6112                         (when (> (length ref2) (length ref))
6113                           (setq ref ref2)))
6114                       ref)
6115                   (setq ref nil))))
6116             ;; Chars.
6117             (progn
6118               (goto-char p)
6119               (if (search-forward "\nchars: " nil t)
6120                   (if (numberp (setq chars (ignore-errors (read cur))))
6121                       chars -1)
6122                 -1))
6123             ;; Lines.
6124             (progn
6125               (goto-char p)
6126               (if (search-forward "\nlines: " nil t)
6127                   (if (numberp (setq lines (ignore-errors (read cur))))
6128                       lines -1)
6129                 -1))
6130             ;; Xref.
6131             (progn
6132               (goto-char p)
6133               (and (search-forward "\nxref:" nil t)
6134                    (nnheader-header-value)))
6135             ;; Extra.
6136             (when gnus-extra-headers
6137               (let ((extra gnus-extra-headers)
6138                     out)
6139                 (while extra
6140                   (goto-char p)
6141                   (when (search-forward
6142                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6143                     (push (cons (car extra) (nnheader-header-value))
6144                           out))
6145                   (pop extra))
6146                 out))))
6147           (when (equal id ref)
6148             (setq ref nil))
6149
6150           (when gnus-alter-header-function
6151             (funcall gnus-alter-header-function header)
6152             (setq id (mail-header-id header)
6153                   ref (gnus-parent-id (mail-header-references header))))
6154
6155           (when (setq header
6156                       (gnus-dependencies-add-header
6157                        header dependencies force-new))
6158             (push header headers))
6159           (goto-char (point-max))
6160           (widen))
6161         (nreverse headers)))))
6162
6163 ;; Goes through the xover lines and returns a list of vectors
6164 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6165                                                   force-new dependencies
6166                                                   group also-fetch-heads)
6167   "Parse the news overview data in the server buffer.
6168 Return a list of headers that match SEQUENCE (see
6169 `nntp-retrieve-headers')."
6170   ;; Get the Xref when the users reads the articles since most/some
6171   ;; NNTP servers do not include Xrefs when using XOVER.
6172   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6173   (let ((mail-parse-charset gnus-newsgroup-charset)
6174         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6175         (cur nntp-server-buffer)
6176         (dependencies (or dependencies gnus-newsgroup-dependencies))
6177         (allp (cond
6178                ((eq gnus-read-all-available-headers t)
6179                 t)
6180                ((and (stringp gnus-read-all-available-headers)
6181                      group)
6182                 (string-match gnus-read-all-available-headers group))
6183                (t
6184                 nil)))
6185         number headers header)
6186     (save-excursion
6187       (set-buffer nntp-server-buffer)
6188       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6189       ;; Allow the user to mangle the headers before parsing them.
6190       (gnus-run-hooks 'gnus-parse-headers-hook)
6191       (goto-char (point-min))
6192       (gnus-parse-without-error
6193         (while (and (or sequence allp)
6194                     (not (eobp)))
6195           (setq number (read cur))
6196           (when (not allp)
6197             (while (and sequence
6198                         (< (car sequence) number))
6199               (setq sequence (cdr sequence))))
6200           (when (and (or allp
6201                          (and sequence
6202                               (eq number (car sequence))))
6203                      (progn
6204                        (setq sequence (cdr sequence))
6205                        (setq header (inline
6206                                       (gnus-nov-parse-line
6207                                        number dependencies force-new)))))
6208             (push header headers))
6209           (forward-line 1)))
6210       ;; A common bug in inn is that if you have posted an article and
6211       ;; then retrieves the active file, it will answer correctly --
6212       ;; the new article is included.  However, a NOV entry for the
6213       ;; article may not have been generated yet, so this may fail.
6214       ;; We work around this problem by retrieving the last few
6215       ;; headers using HEAD.
6216       (if (or (not also-fetch-heads)
6217               (not sequence))
6218           ;; We (probably) got all the headers.
6219           (nreverse headers)
6220         (let ((gnus-nov-is-evil t))
6221           (nconc
6222            (nreverse headers)
6223            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6224              (gnus-get-newsgroup-headers))))))))
6225
6226 (defun gnus-article-get-xrefs ()
6227   "Fill in the Xref value in `gnus-current-headers', if necessary.
6228 This is meant to be called in `gnus-article-internal-prepare-hook'."
6229   (let ((headers (with-current-buffer gnus-summary-buffer
6230                    gnus-current-headers)))
6231     (or (not gnus-use-cross-reference)
6232         (not headers)
6233         (and (mail-header-xref headers)
6234              (not (string= (mail-header-xref headers) "")))
6235         (let ((case-fold-search t)
6236               xref)
6237           (save-restriction
6238             (nnheader-narrow-to-headers)
6239             (goto-char (point-min))
6240             (when (or (and (not (eobp))
6241                            (eq (downcase (char-after)) ?x)
6242                            (looking-at "Xref:"))
6243                       (search-forward "\nXref:" nil t))
6244               (goto-char (1+ (match-end 0)))
6245               (setq xref (buffer-substring (point) (point-at-eol)))
6246               (mail-header-set-xref headers xref)))))))
6247
6248 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6249   "Find article ID and insert the summary line for that article.
6250 OLD-HEADER can either be a header or a line number to insert
6251 the subject line on."
6252   (let* ((line (and (numberp old-header) old-header))
6253          (old-header (and (vectorp old-header) old-header))
6254          (header (cond ((and old-header use-old-header)
6255                         old-header)
6256                        ((and (numberp id)
6257                              (gnus-number-to-header id))
6258                         (gnus-number-to-header id))
6259                        (t
6260                         (gnus-read-header id))))
6261          (number (and (numberp id) id))
6262          d)
6263     (when header
6264       ;; Rebuild the thread that this article is part of and go to the
6265       ;; article we have fetched.
6266       (when (and (not gnus-show-threads)
6267                  old-header)
6268         (when (and number
6269                    (setq d (gnus-data-find (mail-header-number old-header))))
6270           (goto-char (gnus-data-pos d))
6271           (gnus-data-remove
6272            number
6273            (- (point-at-bol)
6274               (prog1
6275                   (1+ (point-at-eol))
6276                 (gnus-delete-line))))))
6277       ;; Remove list identifiers from subject.
6278       (when gnus-list-identifiers
6279         (let ((gnus-newsgroup-headers (list header)))
6280           (gnus-summary-remove-list-identifiers)))
6281       (when old-header
6282         (mail-header-set-number header (mail-header-number old-header)))
6283       (setq gnus-newsgroup-sparse
6284             (delq (setq number (mail-header-number header))
6285                   gnus-newsgroup-sparse))
6286       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6287       (push number gnus-newsgroup-limit)
6288       (gnus-rebuild-thread (mail-header-id header) line)
6289       (gnus-summary-goto-subject number nil t))
6290     (when (and (numberp number)
6291                (> number 0))
6292       ;; We have to update the boundaries even if we can't fetch the
6293       ;; article if ID is a number -- so that the next `P' or `N'
6294       ;; command will fetch the previous (or next) article even
6295       ;; if the one we tried to fetch this time has been canceled.
6296       (when (> number gnus-newsgroup-end)
6297         (setq gnus-newsgroup-end number))
6298       (when (< number gnus-newsgroup-begin)
6299         (setq gnus-newsgroup-begin number))
6300       (setq gnus-newsgroup-unselected
6301             (delq number gnus-newsgroup-unselected)))
6302     ;; Report back a success?
6303     (and header (mail-header-number header))))
6304
6305 ;;; Process/prefix in the summary buffer
6306
6307 (defun gnus-summary-work-articles (n)
6308   "Return a list of articles to be worked upon.
6309 The prefix argument, the list of process marked articles, and the
6310 current article will be taken into consideration."
6311   (save-excursion
6312     (set-buffer gnus-summary-buffer)
6313     (cond
6314      (n
6315       ;; A numerical prefix has been given.
6316       (setq n (prefix-numeric-value n))
6317       (let ((backward (< n 0))
6318             (n (abs (prefix-numeric-value n)))
6319             articles article)
6320         (save-excursion
6321           (while
6322               (and (> n 0)
6323                    (push (setq article (gnus-summary-article-number))
6324                          articles)
6325                    (if backward
6326                        (gnus-summary-find-prev nil article)
6327                      (gnus-summary-find-next nil article)))
6328             (decf n)))
6329         (nreverse articles)))
6330      ((and (gnus-region-active-p) (mark))
6331       (message "region active")
6332       ;; Work on the region between point and mark.
6333       (let ((max (max (point) (mark)))
6334             articles article)
6335         (save-excursion
6336           (goto-char (min (point) (mark)))
6337           (while
6338               (and
6339                (push (setq article (gnus-summary-article-number)) articles)
6340                (gnus-summary-find-next nil article)
6341                (< (point) max)))
6342           (nreverse articles))))
6343      (gnus-newsgroup-processable
6344       ;; There are process-marked articles present.
6345       ;; Save current state.
6346       (gnus-summary-save-process-mark)
6347       ;; Return the list.
6348       (reverse gnus-newsgroup-processable))
6349      (t
6350       ;; Just return the current article.
6351       (list (gnus-summary-article-number))))))
6352
6353 (defmacro gnus-summary-iterate (arg &rest forms)
6354   "Iterate over the process/prefixed articles and do FORMS.
6355 ARG is the interactive prefix given to the command.  FORMS will be
6356 executed with point over the summary line of the articles."
6357   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6358     `(let ((,articles (gnus-summary-work-articles ,arg)))
6359        (while ,articles
6360          (gnus-summary-goto-subject (car ,articles))
6361          ,@forms
6362          (pop ,articles)))))
6363
6364 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6365 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6366
6367 (defun gnus-summary-save-process-mark ()
6368   "Push the current set of process marked articles on the stack."
6369   (interactive)
6370   (push (copy-sequence gnus-newsgroup-processable)
6371         gnus-newsgroup-process-stack))
6372
6373 (defun gnus-summary-kill-process-mark ()
6374   "Push the current set of process marked articles on the stack and unmark."
6375   (interactive)
6376   (gnus-summary-save-process-mark)
6377   (gnus-summary-unmark-all-processable))
6378
6379 (defun gnus-summary-yank-process-mark ()
6380   "Pop the last process mark state off the stack and restore it."
6381   (interactive)
6382   (unless gnus-newsgroup-process-stack
6383     (error "Empty mark stack"))
6384   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6385
6386 (defun gnus-summary-process-mark-set (set)
6387   "Make SET into the current process marked articles."
6388   (gnus-summary-unmark-all-processable)
6389   (mapc 'gnus-summary-set-process-mark set))
6390
6391 ;;; Searching and stuff
6392
6393 (defun gnus-summary-search-group (&optional backward use-level)
6394   "Search for next unread newsgroup.
6395 If optional argument BACKWARD is non-nil, search backward instead."
6396   (save-excursion
6397     (set-buffer gnus-group-buffer)
6398     (when (gnus-group-search-forward
6399            backward nil (if use-level (gnus-group-group-level) nil))
6400       (gnus-group-group-name))))
6401
6402 (defun gnus-summary-best-group (&optional exclude-group)
6403   "Find the name of the best unread group.
6404 If EXCLUDE-GROUP, do not go to this group."
6405   (with-current-buffer gnus-group-buffer
6406     (save-excursion
6407       (gnus-group-best-unread-group exclude-group))))
6408
6409 (defun gnus-summary-find-next (&optional unread article backward)
6410   (if backward
6411       (gnus-summary-find-prev unread article)
6412     (let* ((dummy (gnus-summary-article-intangible-p))
6413            (article (or article (gnus-summary-article-number)))
6414            (data (gnus-data-find-list article))
6415            result)
6416       (when (and (not dummy)
6417                  (or (not gnus-summary-check-current)
6418                      (not unread)
6419                      (not (gnus-data-unread-p (car data)))))
6420         (setq data (cdr data)))
6421       (when (setq result
6422                   (if unread
6423                       (progn
6424                         (while data
6425                           (unless (memq (gnus-data-number (car data))
6426                                         (cond
6427                                          ((eq gnus-auto-goto-ignores
6428                                               'always-undownloaded)
6429                                           gnus-newsgroup-undownloaded)
6430                                          (gnus-plugged
6431                                           nil)
6432                                          ((eq gnus-auto-goto-ignores
6433                                               'unfetched)
6434                                           gnus-newsgroup-unfetched)
6435                                          ((eq gnus-auto-goto-ignores
6436                                               'undownloaded)
6437                                           gnus-newsgroup-undownloaded)))
6438                             (when (gnus-data-unread-p (car data))
6439                               (setq result (car data)
6440                                     data nil)))
6441                           (setq data (cdr data)))
6442                         result)
6443                     (car data)))
6444         (goto-char (gnus-data-pos result))
6445         (gnus-data-number result)))))
6446
6447 (defun gnus-summary-find-prev (&optional unread article)
6448   (let* ((eobp (eobp))
6449          (article (or article (gnus-summary-article-number)))
6450          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6451          result)
6452     (when (and (not eobp)
6453                (or (not gnus-summary-check-current)
6454                    (not unread)
6455                    (not (gnus-data-unread-p (car data)))))
6456       (setq data (cdr data)))
6457     (when (setq result
6458                 (if unread
6459                     (progn
6460                       (while data
6461                         (unless (memq (gnus-data-number (car data))
6462                                       (cond
6463                                        ((eq gnus-auto-goto-ignores
6464                                             'always-undownloaded)
6465                                         gnus-newsgroup-undownloaded)
6466                                        (gnus-plugged
6467                                         nil)
6468                                        ((eq gnus-auto-goto-ignores
6469                                             'unfetched)
6470                                         gnus-newsgroup-unfetched)
6471                                        ((eq gnus-auto-goto-ignores
6472                                             'undownloaded)
6473                                         gnus-newsgroup-undownloaded)))
6474                           (when (gnus-data-unread-p (car data))
6475                             (setq result (car data)
6476                                   data nil)))
6477                         (setq data (cdr data)))
6478                       result)
6479                   (car data)))
6480       (goto-char (gnus-data-pos result))
6481       (gnus-data-number result))))
6482
6483 (defun gnus-summary-find-subject (subject &optional unread backward article)
6484   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6485          (article (or article (gnus-summary-article-number)))
6486          (articles (gnus-data-list backward))
6487          (arts (gnus-data-find-list article articles))
6488          result)
6489     (when (or (not gnus-summary-check-current)
6490               (not unread)
6491               (not (gnus-data-unread-p (car arts))))
6492       (setq arts (cdr arts)))
6493     (while arts
6494       (and (or (not unread)
6495                (gnus-data-unread-p (car arts)))
6496            (vectorp (gnus-data-header (car arts)))
6497            (gnus-subject-equal
6498             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6499            (setq result (car arts)
6500                  arts nil))
6501       (setq arts (cdr arts)))
6502     (and result
6503          (goto-char (gnus-data-pos result))
6504          (gnus-data-number result))))
6505
6506 (defun gnus-summary-search-forward (&optional unread subject backward)
6507   "Search forward for an article.
6508 If UNREAD, look for unread articles.  If SUBJECT, look for
6509 articles with that subject.  If BACKWARD, search backward instead."
6510   (cond (subject (gnus-summary-find-subject subject unread backward))
6511         (backward (gnus-summary-find-prev unread))
6512         (t (gnus-summary-find-next unread))))
6513
6514 (defun gnus-recenter (&optional n)
6515   "Center point in window and redisplay frame.
6516 Also do horizontal recentering."
6517   (interactive "P")
6518   (when (and gnus-auto-center-summary
6519              (not (eq gnus-auto-center-summary 'vertical)))
6520     (gnus-horizontal-recenter))
6521   (recenter n))
6522
6523 (defun gnus-summary-recenter ()
6524   "Center point in the summary window.
6525 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6526 displayed, no centering will be performed."
6527   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6528   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6529   (interactive)
6530   ;; The user has to want it.
6531   (when gnus-auto-center-summary
6532     (let* ((top (cond ((< (window-height) 4) 0)
6533                       ((< (window-height) 7) 1)
6534                       (t (if (numberp gnus-auto-center-summary)
6535                              gnus-auto-center-summary
6536                            (/ (1- (window-height)) 2)))))
6537            (height (1- (window-height)))
6538            (bottom (save-excursion (goto-char (point-max))
6539                                    (forward-line (- height))
6540                                    (point)))
6541            (window (get-buffer-window (current-buffer))))
6542       (when (get-buffer-window gnus-article-buffer)
6543         ;; Only do recentering when the article buffer is displayed,
6544         ;; Set the window start to either `bottom', which is the biggest
6545         ;; possible valid number, or the second line from the top,
6546         ;; whichever is the least.
6547         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6548           (if (> bottom top-pos)
6549               ;; Keep the second line from the top visible
6550               (set-window-start window top-pos t)
6551             ;; Try to keep the bottom line visible; if it's partially
6552             ;; obscured, either scroll one more line to make it fully
6553             ;; visible, or revert to using TOP-POS.
6554             (save-excursion
6555               (goto-char (point-max))
6556               (forward-line -1)
6557               (let ((last-line-start (point)))
6558                 (goto-char bottom)
6559                 (set-window-start window (point) t)
6560                 (when (not (pos-visible-in-window-p last-line-start window))
6561                   (forward-line 1)
6562                   (set-window-start window (min (point) top-pos) t)))))))
6563       ;; Do horizontal recentering while we're at it.
6564       (when (and (get-buffer-window (current-buffer) t)
6565                  (not (eq gnus-auto-center-summary 'vertical)))
6566         (let ((selected (selected-window)))
6567           (select-window (get-buffer-window (current-buffer) t))
6568           (gnus-summary-position-point)
6569           (gnus-horizontal-recenter)
6570           (select-window selected))))))
6571
6572 (defun gnus-summary-jump-to-group (newsgroup)
6573   "Move point to NEWSGROUP in group mode buffer."
6574   ;; Keep update point of group mode buffer if visible.
6575   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6576       (save-window-excursion
6577         ;; Take care of tree window mode.
6578         (when (get-buffer-window gnus-group-buffer)
6579           (pop-to-buffer gnus-group-buffer))
6580         (gnus-group-jump-to-group newsgroup))
6581     (save-excursion
6582       ;; Take care of tree window mode.
6583       (if (get-buffer-window gnus-group-buffer)
6584           (pop-to-buffer gnus-group-buffer)
6585         (set-buffer gnus-group-buffer))
6586       (gnus-group-jump-to-group newsgroup))))
6587
6588 ;; This function returns a list of article numbers based on the
6589 ;; difference between the ranges of read articles in this group and
6590 ;; the range of active articles.
6591 (defun gnus-list-of-unread-articles (group)
6592   (let* ((read (gnus-info-read (gnus-get-info group)))
6593          (active (or (gnus-active group) (gnus-activate-group group)))
6594          (last (or (cdr active)
6595                    (error "Group %s couldn't be activated " group)))
6596          first nlast unread)
6597     ;; If none are read, then all are unread.
6598     (if (not read)
6599         (setq first (car active))
6600       ;; If the range of read articles is a single range, then the
6601       ;; first unread article is the article after the last read
6602       ;; article.  Sounds logical, doesn't it?
6603       (if (and (not (listp (cdr read)))
6604                (or (< (car read) (car active))
6605                    (progn (setq read (list read))
6606                           nil)))
6607           (setq first (max (car active) (1+ (cdr read))))
6608         ;; `read' is a list of ranges.
6609         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6610                                   (caar read)))
6611                   1)
6612           (setq first (car active)))
6613         (while read
6614           (when first
6615             (while (< first nlast)
6616               (setq unread (cons first unread)
6617                     first (1+ first))))
6618           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6619           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6620           (setq read (cdr read)))))
6621     ;; And add the last unread articles.
6622     (while (<= first last)
6623       (setq unread (cons first unread)
6624             first (1+ first)))
6625     ;; Return the list of unread articles.
6626     (delq 0 (nreverse unread))))
6627
6628 (defun gnus-list-of-read-articles (group)
6629   "Return a list of unread, unticked and non-dormant articles."
6630   (let* ((info (gnus-get-info group))
6631          (marked (gnus-info-marks info))
6632          (active (gnus-active group)))
6633     (and info active
6634          (gnus-list-range-difference
6635           (gnus-list-range-difference
6636            (gnus-sorted-complement
6637             (gnus-uncompress-range active)
6638             (gnus-list-of-unread-articles group))
6639            (cdr (assq 'dormant marked)))
6640           (cdr (assq 'tick marked))))))
6641
6642 ;; This function returns a sequence of article numbers based on the
6643 ;; difference between the ranges of read articles in this group and
6644 ;; the range of active articles.
6645 (defun gnus-sequence-of-unread-articles (group)
6646   (let* ((read (gnus-info-read (gnus-get-info group)))
6647          (active (or (gnus-active group) (gnus-activate-group group)))
6648          (last (cdr active))
6649          first nlast unread)
6650     ;; If none are read, then all are unread.
6651     (if (not read)
6652         (setq first (car active))
6653       ;; If the range of read articles is a single range, then the
6654       ;; first unread article is the article after the last read
6655       ;; article.  Sounds logical, doesn't it?
6656       (if (and (not (listp (cdr read)))
6657                (or (< (car read) (car active))
6658                    (progn (setq read (list read))
6659                           nil)))
6660           (setq first (max (car active) (1+ (cdr read))))
6661         ;; `read' is a list of ranges.
6662         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6663                                   (caar read)))
6664                   1)
6665           (setq first (car active)))
6666         (while read
6667           (when first
6668             (push (cons first nlast) unread))
6669           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6670           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6671           (setq read (cdr read)))))
6672     ;; And add the last unread articles.
6673     (cond ((not (and first last))
6674            nil)
6675           ((< first last)
6676            (push (cons first last) unread))
6677           ((= first last)
6678            (push first unread)))
6679     ;; Return the sequence of unread articles.
6680     (delq 0 (nreverse unread))))
6681
6682 ;; Various summary commands
6683
6684 (defun gnus-summary-select-article-buffer ()
6685   "Reconfigure windows to show article buffer."
6686   (interactive)
6687   (if (not (gnus-buffer-live-p gnus-article-buffer))
6688       (error "There is no article buffer for this summary buffer")
6689     (gnus-configure-windows 'article)
6690     (select-window (get-buffer-window gnus-article-buffer))))
6691
6692 (defun gnus-summary-universal-argument (arg)
6693   "Perform any operation on all articles that are process/prefixed."
6694   (interactive "P")
6695   (let ((articles (gnus-summary-work-articles arg))
6696         func article)
6697     (if (eq
6698          (setq
6699           func
6700           (key-binding
6701            (read-key-sequence
6702             (substitute-command-keys
6703              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6704          'undefined)
6705         (gnus-error 1 "Undefined key")
6706       (save-excursion
6707         (while articles
6708           (gnus-summary-goto-subject (setq article (pop articles)))
6709           (let (gnus-newsgroup-processable)
6710             (command-execute func))
6711           (gnus-summary-remove-process-mark article)))))
6712   (gnus-summary-position-point))
6713
6714 (defun gnus-summary-toggle-truncation (&optional arg)
6715   "Toggle truncation of summary lines.
6716 With ARG, turn line truncation on if ARG is positive."
6717   (interactive "P")
6718   (setq truncate-lines
6719         (if (null arg) (not truncate-lines)
6720           (> (prefix-numeric-value arg) 0)))
6721   (redraw-display))
6722
6723 (defun gnus-summary-find-for-reselect ()
6724   "Return the number of an article to stay on across a reselect.
6725 The current article is considered, then following articles, then previous
6726 articles.  An article is sought which is not cancelled and isn't a temporary
6727 insertion from another group.  If there's no such then return a dummy 0."
6728   (let (found)
6729     (dolist (rev '(nil t))
6730       (unless found      ; don't demand the reverse list if we don't need it
6731         (let ((data (gnus-data-find-list
6732                      (gnus-summary-article-number) (gnus-data-list rev))))
6733           (while (and data (not found))
6734             (if (and (< 0 (gnus-data-number (car data)))
6735                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6736                 (setq found (gnus-data-number (car data))))
6737             (setq data (cdr data))))))
6738     (or found 0)))
6739
6740 (defun gnus-summary-reselect-current-group (&optional all rescan)
6741   "Exit and then reselect the current newsgroup.
6742 The prefix argument ALL means to select all articles."
6743   (interactive "P")
6744   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6745     (error "Ephemeral groups can't be reselected"))
6746   (let ((current-subject (gnus-summary-find-for-reselect))
6747         (group gnus-newsgroup-name))
6748     (setq gnus-newsgroup-begin nil)
6749     (gnus-summary-exit nil 'leave-hidden)
6750     ;; We have to adjust the point of group mode buffer because
6751     ;; point was moved to the next unread newsgroup by exiting.
6752     (gnus-summary-jump-to-group group)
6753     (when rescan
6754       (save-excursion
6755         (gnus-group-get-new-news-this-group 1)))
6756     (gnus-group-read-group all t)
6757     (gnus-summary-goto-subject current-subject nil t)))
6758
6759 (defun gnus-summary-rescan-group (&optional all)
6760   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6761   (interactive "P")
6762   (gnus-summary-reselect-current-group all t))
6763
6764 (defun gnus-summary-update-info (&optional non-destructive)
6765   (save-excursion
6766     (let ((group gnus-newsgroup-name))
6767       (when group
6768         (when gnus-newsgroup-kill-headers
6769           (setq gnus-newsgroup-killed
6770                 (gnus-compress-sequence
6771                  (gnus-sorted-union
6772                   (gnus-list-range-intersection
6773                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6774                   gnus-newsgroup-unreads)
6775                  t)))
6776         (unless (listp (cdr gnus-newsgroup-killed))
6777           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6778         (let ((headers gnus-newsgroup-headers))
6779           ;; Set the new ranges of read articles.
6780           (with-current-buffer gnus-group-buffer
6781             (gnus-undo-force-boundary))
6782           (gnus-update-read-articles
6783            group (gnus-sorted-union
6784                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6785           ;; Set the current article marks.
6786           (let ((gnus-newsgroup-scored
6787                  (if (and (not gnus-save-score)
6788                           (not non-destructive))
6789                      nil
6790                    gnus-newsgroup-scored)))
6791             (save-excursion
6792               (gnus-update-marks)))
6793           ;; Do the cross-ref thing.
6794           (when gnus-use-cross-reference
6795             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6796           ;; Do not switch windows but change the buffer to work.
6797           (set-buffer gnus-group-buffer)
6798           (unless (gnus-ephemeral-group-p group)
6799             (gnus-group-update-group group)))))))
6800
6801 (defun gnus-summary-save-newsrc (&optional force)
6802   "Save the current number of read/marked articles in the dribble buffer.
6803 The dribble buffer will then be saved.
6804 If FORCE (the prefix), also save the .newsrc file(s)."
6805   (interactive "P")
6806   (gnus-summary-update-info t)
6807   (if force
6808       (gnus-save-newsrc-file)
6809     (gnus-dribble-save)))
6810
6811 (defun gnus-summary-exit (&optional temporary leave-hidden)
6812   "Exit reading current newsgroup, and then return to group selection mode.
6813 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6814   (interactive)
6815   (gnus-set-global-variables)
6816   (when (gnus-buffer-live-p gnus-article-buffer)
6817     (save-excursion
6818       (set-buffer gnus-article-buffer)
6819       (mm-destroy-parts gnus-article-mime-handles)
6820       ;; Set it to nil for safety reason.
6821       (setq gnus-article-mime-handle-alist nil)
6822       (setq gnus-article-mime-handles nil)))
6823   (gnus-kill-save-kill-buffer)
6824   (gnus-async-halt-prefetch)
6825   (let* ((group gnus-newsgroup-name)
6826          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6827          (gnus-group-is-exiting-p t)
6828          (mode major-mode)
6829          (group-point nil)
6830          (buf (current-buffer)))
6831     (unless quit-config
6832       ;; Do adaptive scoring, and possibly save score files.
6833       (when gnus-newsgroup-adaptive
6834         (gnus-score-adaptive))
6835       (when gnus-use-scoring
6836         (gnus-score-save)))
6837     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6838     ;; If we have several article buffers, we kill them at exit.
6839     (unless gnus-single-article-buffer
6840       (gnus-kill-buffer gnus-original-article-buffer)
6841       (setq gnus-article-current nil))
6842     (when gnus-use-cache
6843       (gnus-cache-possibly-remove-articles)
6844       (gnus-cache-save-buffers))
6845     (gnus-async-prefetch-remove-group group)
6846     (when gnus-suppress-duplicates
6847       (gnus-dup-enter-articles))
6848     (when gnus-use-trees
6849       (gnus-tree-close group))
6850     (when gnus-use-cache
6851       (gnus-cache-write-active))
6852     ;; Remove entries for this group.
6853     (nnmail-purge-split-history (gnus-group-real-name group))
6854     ;; Make all changes in this group permanent.
6855     (unless quit-config
6856       (gnus-run-hooks 'gnus-exit-group-hook)
6857       (gnus-summary-update-info))
6858     (gnus-close-group group)
6859     ;; Make sure where we were, and go to next newsgroup.
6860     (set-buffer gnus-group-buffer)
6861     (unless quit-config
6862       (gnus-group-jump-to-group group))
6863     (gnus-run-hooks 'gnus-summary-exit-hook)
6864     (unless (or quit-config
6865                 ;; If this group has disappeared from the summary
6866                 ;; buffer, don't skip forwards.
6867                 (not (string= group (gnus-group-group-name))))
6868       (gnus-group-next-unread-group 1))
6869     (setq group-point (point))
6870     (if temporary
6871         nil                             ;Nothing to do.
6872       ;; If we have several article buffers, we kill them at exit.
6873       (unless gnus-single-article-buffer
6874         (gnus-kill-buffer gnus-article-buffer)
6875         (gnus-kill-buffer gnus-original-article-buffer)
6876         (setq gnus-article-current nil))
6877       (set-buffer buf)
6878       (if (not gnus-kill-summary-on-exit)
6879           (progn
6880             (gnus-deaden-summary)
6881             (setq mode nil))
6882         ;; We set all buffer-local variables to nil.  It is unclear why
6883         ;; this is needed, but if we don't, buffer-local variables are
6884         ;; not garbage-collected, it seems.  This would the lead to en
6885         ;; ever-growing Emacs.
6886         (gnus-summary-clear-local-variables)
6887         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6888           (gnus-summary-clear-local-variables))
6889         (when (get-buffer gnus-article-buffer)
6890           (bury-buffer gnus-article-buffer))
6891         ;; Return to group mode buffer.
6892         (when (eq mode 'gnus-summary-mode)
6893           (gnus-kill-buffer buf)))
6894       (setq gnus-current-select-method gnus-select-method)
6895       (set-buffer gnus-group-buffer)
6896       (if quit-config
6897           (gnus-handle-ephemeral-exit quit-config)
6898         (goto-char group-point)
6899         ;; If gnus-group-buffer is already displayed, make sure we also move
6900         ;; the cursor in the window that displays it.
6901         (let ((win (get-buffer-window (current-buffer) 0)))
6902           (if win (set-window-point win (point))))
6903         (unless leave-hidden
6904           (gnus-configure-windows 'group 'force)))
6905       ;; Clear the current group name.
6906       (unless quit-config
6907         (setq gnus-newsgroup-name nil)))))
6908
6909 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6910 (defun gnus-summary-exit-no-update (&optional no-questions)
6911   "Quit reading current newsgroup without updating read article info."
6912   (interactive)
6913   (let* ((group gnus-newsgroup-name)
6914          (gnus-group-is-exiting-p t)
6915          (gnus-group-is-exiting-without-update-p t)
6916          (quit-config (gnus-group-quit-config group)))
6917     (when (or no-questions
6918               gnus-expert-user
6919               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6920       (gnus-async-halt-prefetch)
6921       (run-hooks 'gnus-summary-prepare-exit-hook)
6922       (when (gnus-buffer-live-p gnus-article-buffer)
6923         (save-excursion
6924           (set-buffer gnus-article-buffer)
6925           (mm-destroy-parts gnus-article-mime-handles)
6926           ;; Set it to nil for safety reason.
6927           (setq gnus-article-mime-handle-alist nil)
6928           (setq gnus-article-mime-handles nil)))
6929       ;; If we have several article buffers, we kill them at exit.
6930       (unless gnus-single-article-buffer
6931         (gnus-kill-buffer gnus-article-buffer)
6932         (gnus-kill-buffer gnus-original-article-buffer)
6933         (setq gnus-article-current nil))
6934       (if (not gnus-kill-summary-on-exit)
6935           (gnus-deaden-summary)
6936         (gnus-close-group group)
6937         (gnus-summary-clear-local-variables)
6938         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6939           (gnus-summary-clear-local-variables))
6940         (gnus-kill-buffer gnus-summary-buffer))
6941       (unless gnus-single-article-buffer
6942         (setq gnus-article-current nil))
6943       (when gnus-use-trees
6944         (gnus-tree-close group))
6945       (gnus-async-prefetch-remove-group group)
6946       (when (get-buffer gnus-article-buffer)
6947         (bury-buffer gnus-article-buffer))
6948       ;; Return to the group buffer.
6949       (gnus-configure-windows 'group 'force)
6950       ;; Clear the current group name.
6951       (setq gnus-newsgroup-name nil)
6952       (unless (gnus-ephemeral-group-p group)
6953         (gnus-group-update-group group))
6954       (when (equal (gnus-group-group-name) group)
6955         (gnus-group-next-unread-group 1))
6956       (when quit-config
6957         (gnus-handle-ephemeral-exit quit-config)))))
6958
6959 (defun gnus-handle-ephemeral-exit (quit-config)
6960   "Handle movement when leaving an ephemeral group.
6961 The state which existed when entering the ephemeral is reset."
6962   (if (not (buffer-name (car quit-config)))
6963       (gnus-configure-windows 'group 'force)
6964     (set-buffer (car quit-config))
6965     (cond ((eq major-mode 'gnus-summary-mode)
6966            (gnus-set-global-variables))
6967           ((eq major-mode 'gnus-article-mode)
6968            (save-excursion
6969              ;; The `gnus-summary-buffer' variable may point
6970              ;; to the old summary buffer when using a single
6971              ;; article buffer.
6972              (unless (gnus-buffer-live-p gnus-summary-buffer)
6973                (set-buffer gnus-group-buffer))
6974              (set-buffer gnus-summary-buffer)
6975              (gnus-set-global-variables))))
6976     (if (or (eq (cdr quit-config) 'article)
6977             (eq (cdr quit-config) 'pick))
6978         (progn
6979           ;; The current article may be from the ephemeral group
6980           ;; thus it is best that we reload this article
6981           ;;
6982           ;; If we're exiting from a large digest, this can be
6983           ;; extremely slow.  So, it's better not to reload it. -- jh.
6984           ;;(gnus-summary-show-article)
6985           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6986               (gnus-configure-windows 'pick 'force)
6987             (gnus-configure-windows (cdr quit-config) 'force)))
6988       (gnus-configure-windows (cdr quit-config) 'force))
6989     (when (eq major-mode 'gnus-summary-mode)
6990       (gnus-summary-next-subject 1 nil t)
6991       (gnus-summary-recenter)
6992       (gnus-summary-position-point))))
6993
6994 ;;; Dead summaries.
6995
6996 (defvar gnus-dead-summary-mode-map nil)
6997
6998 (unless gnus-dead-summary-mode-map
6999   (setq gnus-dead-summary-mode-map (make-keymap))
7000   (suppress-keymap gnus-dead-summary-mode-map)
7001   (substitute-key-definition
7002    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7003   (dolist (key '("\C-d" "\r" "\177" [delete]))
7004     (define-key gnus-dead-summary-mode-map
7005       key 'gnus-summary-wake-up-the-dead))
7006   (dolist (key '("q" "Q"))
7007     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7008
7009 (defvar gnus-dead-summary-mode nil
7010   "Minor mode for Gnus summary buffers.")
7011
7012 (defun gnus-dead-summary-mode (&optional arg)
7013   "Minor mode for Gnus summary buffers."
7014   (interactive "P")
7015   (when (eq major-mode 'gnus-summary-mode)
7016     (make-local-variable 'gnus-dead-summary-mode)
7017     (setq gnus-dead-summary-mode
7018           (if (null arg) (not gnus-dead-summary-mode)
7019             (> (prefix-numeric-value arg) 0)))
7020     (when gnus-dead-summary-mode
7021       (add-minor-mode
7022        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7023
7024 (defun gnus-deaden-summary ()
7025   "Make the current summary buffer into a dead summary buffer."
7026   ;; Kill any previous dead summary buffer.
7027   (when (and gnus-dead-summary
7028              (buffer-name gnus-dead-summary))
7029     (with-current-buffer gnus-dead-summary
7030       (when gnus-dead-summary-mode
7031         (kill-buffer (current-buffer)))))
7032   ;; Make this the current dead summary.
7033   (setq gnus-dead-summary (current-buffer))
7034   (gnus-dead-summary-mode 1)
7035   (let ((name (buffer-name)))
7036     (when (string-match "Summary" name)
7037       (rename-buffer
7038        (concat (substring name 0 (match-beginning 0)) "Dead "
7039                (substring name (match-beginning 0)))
7040        t)
7041       (bury-buffer))))
7042
7043 (defun gnus-kill-or-deaden-summary (buffer)
7044   "Kill or deaden the summary BUFFER."
7045   (save-excursion
7046     (when (and (buffer-name buffer)
7047                (not gnus-single-article-buffer))
7048       (with-current-buffer buffer
7049         (gnus-kill-buffer gnus-article-buffer)
7050         (gnus-kill-buffer gnus-original-article-buffer)))
7051     (cond
7052      ;; Kill the buffer.
7053      (gnus-kill-summary-on-exit
7054       (when (and gnus-use-trees
7055                  (gnus-buffer-exists-p buffer))
7056         (save-excursion
7057           (set-buffer buffer)
7058           (gnus-tree-close gnus-newsgroup-name)))
7059       (gnus-kill-buffer buffer))
7060      ;; Deaden the buffer.
7061      ((gnus-buffer-exists-p buffer)
7062       (save-excursion
7063         (set-buffer buffer)
7064         (gnus-deaden-summary))))))
7065
7066 (defun gnus-summary-wake-up-the-dead (&rest args)
7067   "Wake up the dead summary buffer."
7068   (interactive)
7069   (gnus-dead-summary-mode -1)
7070   (let ((name (buffer-name)))
7071     (when (string-match "Dead " name)
7072       (rename-buffer
7073        (concat (substring name 0 (match-beginning 0))
7074                (substring name (match-end 0)))
7075        t)))
7076   (gnus-message 3 "This dead summary is now alive again"))
7077
7078 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7079 (defun gnus-summary-fetch-faq (&optional faq-dir)
7080   "Fetch the FAQ for the current group.
7081 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7082 in."
7083   (interactive
7084    (list
7085     (when current-prefix-arg
7086       (completing-read
7087        "FAQ dir: " (and (listp gnus-group-faq-directory)
7088                         (mapcar 'list
7089                                 gnus-group-faq-directory))))))
7090   (let (gnus-faq-buffer)
7091     (when (setq gnus-faq-buffer
7092                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7093       (gnus-configure-windows 'summary-faq))))
7094
7095 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7096 (defun gnus-summary-describe-group (&optional force)
7097   "Describe the current newsgroup."
7098   (interactive "P")
7099   (gnus-group-describe-group force gnus-newsgroup-name))
7100
7101 (defun gnus-summary-describe-briefly ()
7102   "Describe summary mode commands briefly."
7103   (interactive)
7104   (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")))
7105
7106 ;; Walking around group mode buffer from summary mode.
7107
7108 (defun gnus-summary-next-group (&optional no-article target-group backward)
7109   "Exit current newsgroup and then select next unread newsgroup.
7110 If prefix argument NO-ARTICLE is non-nil, no article is selected
7111 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7112 previous group instead."
7113   (interactive "P")
7114   ;; Stop pre-fetching.
7115   (gnus-async-halt-prefetch)
7116   (let ((current-group gnus-newsgroup-name)
7117         (current-buffer (current-buffer))
7118         entered)
7119     ;; First we semi-exit this group to update Xrefs and all variables.
7120     ;; We can't do a real exit, because the window conf must remain
7121     ;; the same in case the user is prompted for info, and we don't
7122     ;; want the window conf to change before that...
7123     (gnus-summary-exit t)
7124     (while (not entered)
7125       ;; Then we find what group we are supposed to enter.
7126       (set-buffer gnus-group-buffer)
7127       (gnus-group-jump-to-group current-group)
7128       (setq target-group
7129             (or target-group
7130                 (if (eq gnus-keep-same-level 'best)
7131                     (gnus-summary-best-group gnus-newsgroup-name)
7132                   (gnus-summary-search-group backward gnus-keep-same-level))))
7133       (if (not target-group)
7134           ;; There are no further groups, so we return to the group
7135           ;; buffer.
7136           (progn
7137             (gnus-message 5 "Returning to the group buffer")
7138             (setq entered t)
7139             (when (gnus-buffer-live-p current-buffer)
7140               (set-buffer current-buffer)
7141               (gnus-summary-exit))
7142             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7143         ;; We try to enter the target group.
7144         (gnus-group-jump-to-group target-group)
7145         (let ((unreads (gnus-group-group-unread)))
7146           (if (and (or (eq t unreads)
7147                        (and unreads (not (zerop unreads))))
7148                    (gnus-summary-read-group
7149                     target-group nil no-article
7150                     (and (buffer-name current-buffer) current-buffer)
7151                     nil backward))
7152               (setq entered t)
7153             (setq current-group target-group
7154                   target-group nil)))))))
7155
7156 (defun gnus-summary-prev-group (&optional no-article)
7157   "Exit current newsgroup and then select previous unread newsgroup.
7158 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7159   (interactive "P")
7160   (gnus-summary-next-group no-article nil t))
7161
7162 ;; Walking around summary lines.
7163
7164 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7165   "Go to the first subject satisfying any non-nil constraint.
7166 If UNREAD is non-nil, the article should be unread.
7167 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7168 If UNSEEN is non-nil, the article should be unseen.
7169 Returns the article selected or nil if there are no matching articles."
7170   (interactive "P")
7171   (cond
7172    ;; Empty summary.
7173    ((null gnus-newsgroup-data)
7174     (gnus-message 3 "No articles in the group")
7175     nil)
7176    ;; Pick the first article.
7177    ((not (or unread undownloaded unseen))
7178     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7179     (gnus-data-number (car gnus-newsgroup-data)))
7180    ;; Find the first unread article.
7181    (t
7182     (let ((data gnus-newsgroup-data))
7183       (while (and data
7184                   (let ((num (gnus-data-number (car data))))
7185                     (or (memq num gnus-newsgroup-unfetched)
7186                         (not (or (and unread
7187                                       (memq num gnus-newsgroup-unreads))
7188                                  (and undownloaded
7189                                       (memq num gnus-newsgroup-undownloaded))
7190                                  (and unseen
7191                                       (memq num gnus-newsgroup-unseen)))))))
7192         (setq data (cdr data)))
7193       (prog1
7194           (if data
7195               (progn
7196                 (goto-char (gnus-data-pos (car data)))
7197                 (gnus-data-number (car data)))
7198             (gnus-message 3 "No more%s articles"
7199                           (let* ((r (when unread " unread"))
7200                                  (d (when undownloaded " undownloaded"))
7201                                  (s (when unseen " unseen"))
7202                                  (l (delq nil (list r d s))))
7203                             (cond ((= 3 (length l))
7204                                    (concat r "," d ", or" s))
7205                                   ((= 2 (length l))
7206                                    (concat (car l) ", or" (cadr l)))
7207                                   ((= 1 (length l))
7208                                    (car l))
7209                                   (t
7210                                    ""))))
7211             nil
7212             )
7213         (gnus-summary-position-point))))))
7214
7215 (defun gnus-summary-next-subject (n &optional unread dont-display)
7216   "Go to next N'th summary line.
7217 If N is negative, go to the previous N'th subject line.
7218 If UNREAD is non-nil, only unread articles are selected.
7219 The difference between N and the actual number of steps taken is
7220 returned."
7221   (interactive "p")
7222   (let ((backward (< n 0))
7223         (n (abs n)))
7224     (while (and (> n 0)
7225                 (if backward
7226                     (gnus-summary-find-prev unread)
7227                   (gnus-summary-find-next unread)))
7228       (unless (zerop (setq n (1- n)))
7229         (gnus-summary-show-thread)))
7230     (when (/= 0 n)
7231       (gnus-message 7 "No more%s articles"
7232                     (if unread " unread" "")))
7233     (unless dont-display
7234       (gnus-summary-recenter)
7235       (gnus-summary-position-point))
7236     n))
7237
7238 (defun gnus-summary-next-unread-subject (n)
7239   "Go to next N'th unread summary line."
7240   (interactive "p")
7241   (gnus-summary-next-subject n t))
7242
7243 (defun gnus-summary-prev-subject (n &optional unread)
7244   "Go to previous N'th summary line.
7245 If optional argument UNREAD is non-nil, only unread article is selected."
7246   (interactive "p")
7247   (gnus-summary-next-subject (- n) unread))
7248
7249 (defun gnus-summary-prev-unread-subject (n)
7250   "Go to previous N'th unread summary line."
7251   (interactive "p")
7252   (gnus-summary-next-subject (- n) t))
7253
7254 (defun gnus-summary-goto-subjects (articles)
7255   "Insert the subject header for ARTICLES in the current buffer."
7256   (save-excursion
7257     (dolist (article articles)
7258       (gnus-summary-goto-subject article t)))
7259   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7260   (gnus-summary-position-point))
7261
7262 (defun gnus-summary-goto-subject (article &optional force silent)
7263   "Go the subject line of ARTICLE.
7264 If FORCE, also allow jumping to articles not currently shown."
7265   (interactive "nArticle number: ")
7266   (unless (numberp article)
7267     (error "Article %s is not a number" article))
7268   (let ((b (point))
7269         (data (gnus-data-find article)))
7270     ;; We read in the article if we have to.
7271     (and (not data)
7272          force
7273          (gnus-summary-insert-subject
7274           article
7275           (if (or (numberp force) (vectorp force)) force)
7276           t)
7277          (setq data (gnus-data-find article)))
7278     (goto-char b)
7279     (if (not data)
7280         (progn
7281           (unless silent
7282             (gnus-message 3 "Can't find article %d" article))
7283           nil)
7284       (let ((pt (gnus-data-pos data)))
7285         (goto-char pt)
7286         (gnus-summary-set-article-display-arrow pt))
7287       (gnus-summary-position-point)
7288       article)))
7289
7290 ;; Walking around summary lines with displaying articles.
7291
7292 (defun gnus-summary-expand-window (&optional arg)
7293   "Make the summary buffer take up the entire Emacs frame.
7294 Given a prefix, will force an `article' buffer configuration."
7295   (interactive "P")
7296   (if arg
7297       (gnus-configure-windows 'article 'force)
7298     (gnus-configure-windows 'summary 'force)))
7299
7300 (defun gnus-summary-display-article (article &optional all-header)
7301   "Display ARTICLE in article buffer."
7302   (when (gnus-buffer-live-p gnus-article-buffer)
7303     (with-current-buffer gnus-article-buffer
7304       (mm-enable-multibyte)))
7305   (gnus-set-global-variables)
7306   (when (gnus-buffer-live-p gnus-article-buffer)
7307     (with-current-buffer gnus-article-buffer
7308       (setq gnus-article-charset gnus-newsgroup-charset)
7309       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7310       (mm-enable-multibyte)))
7311   (if (null article)
7312       nil
7313     (prog1
7314         (if gnus-summary-display-article-function
7315             (funcall gnus-summary-display-article-function article all-header)
7316           (gnus-article-prepare article all-header))
7317       (gnus-run-hooks 'gnus-select-article-hook)
7318       (when (and gnus-current-article
7319                  (not (zerop gnus-current-article)))
7320         (gnus-summary-goto-subject gnus-current-article))
7321       (gnus-summary-recenter)
7322       (when (and gnus-use-trees gnus-show-threads)
7323         (gnus-possibly-generate-tree article)
7324         (gnus-highlight-selected-tree article))
7325       ;; Successfully display article.
7326       (gnus-article-set-window-start
7327        (cdr (assq article gnus-newsgroup-bookmarks))))))
7328
7329 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7330   "Select the current article.
7331 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7332 non-nil, the article will be re-fetched even if it already present in
7333 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7334 be displayed."
7335   ;; Make sure we are in the summary buffer to work around bbdb bug.
7336   (unless (eq major-mode 'gnus-summary-mode)
7337     (set-buffer gnus-summary-buffer))
7338   (let ((article (or article (gnus-summary-article-number)))
7339         (all-headers (not (not all-headers))) ;Must be t or nil.
7340         gnus-summary-display-article-function)
7341     (and (not pseudo)
7342          (gnus-summary-article-pseudo-p article)
7343          (error "This is a pseudo-article"))
7344     (save-excursion
7345       (set-buffer gnus-summary-buffer)
7346       (if (or (and gnus-single-article-buffer
7347                    (or (null gnus-current-article)
7348                        (null gnus-article-current)
7349                        (null (get-buffer gnus-article-buffer))
7350                        (not (eq article (cdr gnus-article-current)))
7351                        (not (equal (car gnus-article-current)
7352                                    gnus-newsgroup-name))))
7353               (and (not gnus-single-article-buffer)
7354                    (or (null gnus-current-article)
7355                        (not (eq gnus-current-article article))))
7356               force)
7357           ;; The requested article is different from the current article.
7358           (progn
7359             (gnus-summary-display-article article all-headers)
7360             (when (gnus-buffer-live-p gnus-article-buffer)
7361               (with-current-buffer gnus-article-buffer
7362                 (if (not gnus-article-decoded-p) ;; a local variable
7363                     (mm-disable-multibyte))))
7364             (gnus-article-set-window-start
7365              (cdr (assq article gnus-newsgroup-bookmarks)))
7366             article)
7367         'old))))
7368
7369 (defun gnus-summary-force-verify-and-decrypt ()
7370   "Display buttons for signed/encrypted parts and verify/decrypt them."
7371   (interactive)
7372   (let ((mm-verify-option 'known)
7373         (mm-decrypt-option 'known)
7374         (gnus-article-emulate-mime t)
7375         (gnus-buttonized-mime-types (append (list "multipart/signed"
7376                                                   "multipart/encrypted")
7377                                             gnus-buttonized-mime-types)))
7378     (gnus-summary-select-article nil 'force)))
7379
7380 (defun gnus-summary-set-current-mark (&optional current-mark)
7381   "Obsolete function."
7382   nil)
7383
7384 (defun gnus-summary-next-article (&optional unread subject backward push)
7385   "Select the next article.
7386 If UNREAD, only unread articles are selected.
7387 If SUBJECT, only articles with SUBJECT are selected.
7388 If BACKWARD, the previous article is selected instead of the next."
7389   (interactive "P")
7390   (cond
7391    ;; Is there such an article?
7392    ((and (gnus-summary-search-forward unread subject backward)
7393          (or (gnus-summary-display-article (gnus-summary-article-number))
7394              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7395     (gnus-summary-position-point))
7396    ;; If not, we try the first unread, if that is wanted.
7397    ((and subject
7398          gnus-auto-select-same
7399          (gnus-summary-first-unread-article))
7400     (gnus-summary-position-point)
7401     (gnus-message 6 "Wrapped"))
7402    ;; Try to get next/previous article not displayed in this group.
7403    ((and gnus-auto-extend-newsgroup
7404          (not unread) (not subject))
7405     (gnus-summary-goto-article
7406      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7407      nil (count-lines (point-min) (point))))
7408    ;; Go to next/previous group.
7409    (t
7410     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7411       (gnus-summary-jump-to-group gnus-newsgroup-name))
7412     (let ((cmd last-command-char)
7413           (point
7414            (with-current-buffer gnus-group-buffer
7415              (point)))
7416           (group
7417            (if (eq gnus-keep-same-level 'best)
7418                (gnus-summary-best-group gnus-newsgroup-name)
7419              (gnus-summary-search-group backward gnus-keep-same-level))))
7420       ;; For some reason, the group window gets selected.  We change
7421       ;; it back.
7422       (select-window (get-buffer-window (current-buffer)))
7423       ;; Select next unread newsgroup automagically.
7424       (cond
7425        ((or (not gnus-auto-select-next)
7426             (not cmd))
7427         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7428        ((or (eq gnus-auto-select-next 'quietly)
7429             (and (eq gnus-auto-select-next 'slightly-quietly)
7430                  push)
7431             (and (eq gnus-auto-select-next 'almost-quietly)
7432                  (gnus-summary-last-article-p)))
7433         ;; Select quietly.
7434         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7435             (gnus-summary-exit)
7436           (gnus-message 7 "No more%s articles (%s)..."
7437                         (if unread " unread" "")
7438                         (if group (concat "selecting " group)
7439                           "exiting"))
7440           (gnus-summary-next-group nil group backward)))
7441        (t
7442         (when (gnus-key-press-event-p last-input-event)
7443           (gnus-summary-walk-group-buffer
7444            gnus-newsgroup-name cmd unread backward point))))))))
7445
7446 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7447   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7448                       (?\C-p (gnus-group-prev-unread-group 1))))
7449         (cursor-in-echo-area t)
7450         keve key group ended prompt)
7451     (save-excursion
7452       (set-buffer gnus-group-buffer)
7453       (goto-char start)
7454       (setq group
7455             (if (eq gnus-keep-same-level 'best)
7456                 (gnus-summary-best-group gnus-newsgroup-name)
7457               (gnus-summary-search-group backward gnus-keep-same-level))))
7458     (while (not ended)
7459       (setq prompt
7460             (format
7461              "No more%s articles%s " (if unread " unread" "")
7462              (if (and group
7463                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7464                  (format " (Type %s for %s [%s])"
7465                          (single-key-description cmd)
7466                          (gnus-group-decoded-name group)
7467                          (gnus-group-unread group))
7468                (format " (Type %s to exit %s)"
7469                        (single-key-description cmd)
7470                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7471       ;; Confirm auto selection.
7472       (setq key (car (setq keve (gnus-read-event-char prompt)))
7473             ended t)
7474       (cond
7475        ((assq key keystrokes)
7476         (let ((obuf (current-buffer)))
7477           (switch-to-buffer gnus-group-buffer)
7478           (when group
7479             (gnus-group-jump-to-group group))
7480           (eval (cadr (assq key keystrokes)))
7481           (setq group (gnus-group-group-name))
7482           (switch-to-buffer obuf))
7483         (setq ended nil))
7484        ((equal key cmd)
7485         (if (or (not group)
7486                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7487             (gnus-summary-exit)
7488           (gnus-summary-next-group nil group backward)))
7489        (t
7490         (push (cdr keve) unread-command-events))))))
7491
7492 (defun gnus-summary-next-unread-article ()
7493   "Select unread article after current one."
7494   (interactive)
7495   (gnus-summary-next-article
7496    (or (not (eq gnus-summary-goto-unread 'never))
7497        (gnus-summary-last-article-p (gnus-summary-article-number)))
7498    (and gnus-auto-select-same
7499         (gnus-summary-article-subject))))
7500
7501 (defun gnus-summary-prev-article (&optional unread subject)
7502   "Select the article after the current one.
7503 If UNREAD is non-nil, only unread articles are selected."
7504   (interactive "P")
7505   (gnus-summary-next-article unread subject t))
7506
7507 (defun gnus-summary-prev-unread-article ()
7508   "Select unread article before current one."
7509   (interactive)
7510   (gnus-summary-prev-article
7511    (or (not (eq gnus-summary-goto-unread 'never))
7512        (gnus-summary-first-article-p (gnus-summary-article-number)))
7513    (and gnus-auto-select-same
7514         (gnus-summary-article-subject))))
7515
7516 (defun gnus-summary-next-page (&optional lines circular stop)
7517   "Show next page of the selected article.
7518 If at the end of the current article, select the next article.
7519 LINES says how many lines should be scrolled up.
7520
7521 If CIRCULAR is non-nil, go to the start of the article instead of
7522 selecting the next article when reaching the end of the current
7523 article.
7524
7525 If STOP is non-nil, just stop when reaching the end of the message.
7526
7527 Also see the variable `gnus-article-skip-boring'."
7528   (interactive "P")
7529   (setq gnus-summary-buffer (current-buffer))
7530   (gnus-set-global-variables)
7531   (let ((article (gnus-summary-article-number))
7532         (article-window (get-buffer-window gnus-article-buffer t))
7533         endp)
7534     ;; If the buffer is empty, we have no article.
7535     (unless article
7536       (error "No article to select"))
7537     (gnus-configure-windows 'article)
7538     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7539         (if (and (eq gnus-summary-goto-unread 'never)
7540                  (not (gnus-summary-last-article-p article)))
7541             (gnus-summary-next-article)
7542           (gnus-summary-next-unread-article))
7543       (if (or (null gnus-current-article)
7544               (null gnus-article-current)
7545               (/= article (cdr gnus-article-current))
7546               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7547           ;; Selected subject is different from current article's.
7548           (gnus-summary-display-article article)
7549         (when article-window
7550           (gnus-eval-in-buffer-window gnus-article-buffer
7551             (setq endp (or (gnus-article-next-page lines)
7552                            (gnus-article-only-boring-p))))
7553           (when endp
7554             (cond (stop
7555                    (gnus-message 3 "End of message"))
7556                   (circular
7557                    (gnus-summary-beginning-of-article))
7558                   (lines
7559                    (gnus-message 3 "End of message"))
7560                   ((null lines)
7561                    (if (and (eq gnus-summary-goto-unread 'never)
7562                             (not (gnus-summary-last-article-p article)))
7563                        (gnus-summary-next-article)
7564                      (gnus-summary-next-unread-article))))))))
7565     (gnus-summary-recenter)
7566     (gnus-summary-position-point)))
7567
7568 (defun gnus-summary-prev-page (&optional lines move)
7569   "Show previous page of selected article.
7570 Argument LINES specifies lines to be scrolled down.
7571 If MOVE, move to the previous unread article if point is at
7572 the beginning of the buffer."
7573   (interactive "P")
7574   (let ((article (gnus-summary-article-number))
7575         (article-window (get-buffer-window gnus-article-buffer t))
7576         endp)
7577     (gnus-configure-windows 'article)
7578     (if (or (null gnus-current-article)
7579             (null gnus-article-current)
7580             (/= article (cdr gnus-article-current))
7581             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7582         ;; Selected subject is different from current article's.
7583         (gnus-summary-display-article article)
7584       (gnus-summary-recenter)
7585       (when article-window
7586         (gnus-eval-in-buffer-window gnus-article-buffer
7587           (setq endp (gnus-article-prev-page lines)))
7588         (when (and move endp)
7589           (cond (lines
7590                  (gnus-message 3 "Beginning of message"))
7591                 ((null lines)
7592                  (if (and (eq gnus-summary-goto-unread 'never)
7593                           (not (gnus-summary-first-article-p article)))
7594                      (gnus-summary-prev-article)
7595                    (gnus-summary-prev-unread-article))))))))
7596   (gnus-summary-position-point))
7597
7598 (defun gnus-summary-prev-page-or-article (&optional lines)
7599   "Show previous page of selected article.
7600 Argument LINES specifies lines to be scrolled down.
7601 If at the beginning of the article, go to the next article."
7602   (interactive "P")
7603   (gnus-summary-prev-page lines t))
7604
7605 (defun gnus-summary-scroll-up (lines)
7606   "Scroll up (or down) one line current article.
7607 Argument LINES specifies lines to be scrolled up (or down if negative)."
7608   (interactive "p")
7609   (gnus-configure-windows 'article)
7610   (gnus-summary-show-thread)
7611   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7612     (gnus-eval-in-buffer-window gnus-article-buffer
7613       (cond ((> lines 0)
7614              (when (gnus-article-next-page lines)
7615                (gnus-message 3 "End of message")))
7616             ((< lines 0)
7617              (gnus-article-prev-page (- lines))))))
7618   (gnus-summary-recenter)
7619   (gnus-summary-position-point))
7620
7621 (defun gnus-summary-scroll-down (lines)
7622   "Scroll down (or up) one line current article.
7623 Argument LINES specifies lines to be scrolled down (or up if negative)."
7624   (interactive "p")
7625   (gnus-summary-scroll-up (- lines)))
7626
7627 (defun gnus-summary-next-same-subject ()
7628   "Select next article which has the same subject as current one."
7629   (interactive)
7630   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7631
7632 (defun gnus-summary-prev-same-subject ()
7633   "Select previous article which has the same subject as current one."
7634   (interactive)
7635   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7636
7637 (defun gnus-summary-next-unread-same-subject ()
7638   "Select next unread article which has the same subject as current one."
7639   (interactive)
7640   (gnus-summary-next-article t (gnus-summary-article-subject)))
7641
7642 (defun gnus-summary-prev-unread-same-subject ()
7643   "Select previous unread article which has the same subject as current one."
7644   (interactive)
7645   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7646
7647 (defun gnus-summary-first-unread-article ()
7648   "Select the first unread article.
7649 Return nil if there are no unread articles."
7650   (interactive)
7651   (prog1
7652       (when (gnus-summary-first-subject t)
7653         (gnus-summary-show-thread)
7654         (gnus-summary-first-subject t)
7655         (gnus-summary-display-article (gnus-summary-article-number)))
7656     (gnus-summary-position-point)))
7657
7658 (defun gnus-summary-first-unread-subject ()
7659   "Place the point on the subject line of the first unread article.
7660 Return nil if there are no unread articles."
7661   (interactive)
7662   (prog1
7663       (when (gnus-summary-first-subject t)
7664         (gnus-summary-show-thread)
7665         (gnus-summary-first-subject t))
7666     (gnus-summary-position-point)))
7667
7668 (defun gnus-summary-first-unseen-subject ()
7669   "Place the point on the subject line of the first unseen article.
7670 Return nil if there are no unseen articles."
7671   (interactive)
7672   (prog1
7673       (when (gnus-summary-first-subject nil nil t)
7674         (gnus-summary-show-thread)
7675         (gnus-summary-first-subject nil nil t))
7676     (gnus-summary-position-point)))
7677
7678 (defun gnus-summary-first-unseen-or-unread-subject ()
7679   "Place the point on the subject line of the first unseen article or,
7680 if all article have been seen, on the subject line of the first unread
7681 article."
7682   (interactive)
7683   (prog1
7684       (unless (when (gnus-summary-first-subject nil nil t)
7685                 (gnus-summary-show-thread)
7686                 (gnus-summary-first-subject nil nil t))
7687         (when (gnus-summary-first-subject t)
7688           (gnus-summary-show-thread)
7689           (gnus-summary-first-subject t)))
7690     (gnus-summary-position-point)))
7691
7692 (defun gnus-summary-first-article ()
7693   "Select the first article.
7694 Return nil if there are no articles."
7695   (interactive)
7696   (prog1
7697       (when (gnus-summary-first-subject)
7698         (gnus-summary-show-thread)
7699         (gnus-summary-first-subject)
7700         (gnus-summary-display-article (gnus-summary-article-number)))
7701     (gnus-summary-position-point)))
7702
7703 (defun gnus-summary-best-unread-article (&optional arg)
7704   "Select the unread article with the highest score.
7705 If given a prefix argument, select the next unread article that has a
7706 score higher than the default score."
7707   (interactive "P")
7708   (let ((article (if arg
7709                      (gnus-summary-better-unread-subject)
7710                    (gnus-summary-best-unread-subject))))
7711     (if article
7712         (gnus-summary-goto-article article)
7713       (error "No unread articles"))))
7714
7715 (defun gnus-summary-best-unread-subject ()
7716   "Select the unread subject with the highest score."
7717   (interactive)
7718   (let ((best -1000000)
7719         (data gnus-newsgroup-data)
7720         article score)
7721     (while data
7722       (and (gnus-data-unread-p (car data))
7723            (> (setq score
7724                     (gnus-summary-article-score (gnus-data-number (car data))))
7725               best)
7726            (setq best score
7727                  article (gnus-data-number (car data))))
7728       (setq data (cdr data)))
7729     (when article
7730       (gnus-summary-goto-subject article))
7731     (gnus-summary-position-point)
7732     article))
7733
7734 (defun gnus-summary-better-unread-subject ()
7735   "Select the first unread subject that has a score over the default score."
7736   (interactive)
7737   (let ((data gnus-newsgroup-data)
7738         article score)
7739     (while (and (setq article (gnus-data-number (car data)))
7740                 (or (gnus-data-read-p (car data))
7741                     (not (> (gnus-summary-article-score article)
7742                             gnus-summary-default-score))))
7743       (setq data (cdr data)))
7744     (when article
7745       (gnus-summary-goto-subject article))
7746     (gnus-summary-position-point)
7747     article))
7748
7749 (defun gnus-summary-last-subject ()
7750   "Go to the last displayed subject line in the group."
7751   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7752     (when article
7753       (gnus-summary-goto-subject article))))
7754
7755 (defun gnus-summary-goto-article (article &optional all-headers force)
7756   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7757 If ALL-HEADERS is non-nil, no header lines are hidden.
7758 If FORCE, go to the article even if it isn't displayed.  If FORCE
7759 is a number, it is the line the article is to be displayed on."
7760   (interactive
7761    (list
7762     (completing-read
7763      "Article number or Message-ID: "
7764      (mapcar (lambda (number) (list (int-to-string number)))
7765              gnus-newsgroup-limit))
7766     current-prefix-arg
7767     t))
7768   (prog1
7769       (if (and (stringp article)
7770                (string-match "@\\|%40" article))
7771           (gnus-summary-refer-article article)
7772         (when (stringp article)
7773           (setq article (string-to-number article)))
7774         (if (gnus-summary-goto-subject article force)
7775             (gnus-summary-display-article article all-headers)
7776           (gnus-message 4 "Couldn't go to article %s" article) nil))
7777     (gnus-summary-position-point)))
7778
7779 (defun gnus-summary-goto-last-article ()
7780   "Go to the previously read article."
7781   (interactive)
7782   (prog1
7783       (when gnus-last-article
7784         (gnus-summary-goto-article gnus-last-article nil t))
7785     (gnus-summary-position-point)))
7786
7787 (defun gnus-summary-pop-article (number)
7788   "Pop one article off the history and go to the previous.
7789 NUMBER articles will be popped off."
7790   (interactive "p")
7791   (let (to)
7792     (setq gnus-newsgroup-history
7793           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7794     (if to
7795         (gnus-summary-goto-article (car to) nil t)
7796       (error "Article history empty")))
7797   (gnus-summary-position-point))
7798
7799 ;; Summary commands and functions for limiting the summary buffer.
7800
7801 (defun gnus-summary-limit-to-articles (n)
7802   "Limit the summary buffer to the next N articles.
7803 If not given a prefix, use the process marked articles instead."
7804   (interactive "P")
7805   (prog1
7806       (let ((articles (gnus-summary-work-articles n)))
7807         (setq gnus-newsgroup-processable nil)
7808         (gnus-summary-limit articles))
7809     (gnus-summary-position-point)))
7810
7811 (defun gnus-summary-pop-limit (&optional total)
7812   "Restore the previous limit.
7813 If given a prefix, remove all limits."
7814   (interactive "P")
7815   (when total
7816     (setq gnus-newsgroup-limits
7817           (list (mapcar (lambda (h) (mail-header-number h))
7818                         gnus-newsgroup-headers))))
7819   (unless gnus-newsgroup-limits
7820     (error "No limit to pop"))
7821   (prog1
7822       (gnus-summary-limit nil 'pop)
7823     (gnus-summary-position-point)))
7824
7825 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7826   "Limit the summary buffer to articles that have subjects that match a regexp.
7827 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7828   (interactive
7829    (list (read-string (if current-prefix-arg
7830                           "Exclude subject (regexp): "
7831                         "Limit to subject (regexp): "))
7832          nil current-prefix-arg))
7833   (unless header
7834     (setq header "subject"))
7835   (when (not (equal "" subject))
7836     (prog1
7837         (let ((articles (gnus-summary-find-matching
7838                          (or header "subject") subject 'all nil nil
7839                          not-matching)))
7840           (unless articles
7841             (error "Found no matches for \"%s\"" subject))
7842           (gnus-summary-limit articles))
7843       (gnus-summary-position-point))))
7844
7845 (defun gnus-summary-limit-to-author (from &optional not-matching)
7846   "Limit the summary buffer to articles that have authors that match a regexp.
7847 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7848   (interactive
7849    (list (read-string (if current-prefix-arg
7850                           "Exclude author (regexp): "
7851                         "Limit to author (regexp): "))
7852          current-prefix-arg))
7853   (gnus-summary-limit-to-subject from "from" not-matching))
7854
7855 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7856   "Limit the summary buffer to articles with the given RECIPIENT.
7857
7858 If NOT-MATCHING, exclude RECIPIENT.
7859
7860 To and Cc headers are checked.  You need to include them in
7861 `nnmail-extra-headers'."
7862   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7863   (interactive
7864    (list (read-string (format "%s recipient (regexp): "
7865                               (if current-prefix-arg "Exclude" "Limit to")))
7866          current-prefix-arg))
7867   (when (not (equal "" recipient))
7868     (prog1 (let* ((to
7869                    (if (memq 'To nnmail-extra-headers)
7870                        (gnus-summary-find-matching
7871                         (cons 'extra 'To) recipient 'all nil nil
7872                         not-matching)
7873                      (gnus-message
7874                       1 "`To' isn't present in `nnmail-extra-headers'")
7875                      (sit-for 1)
7876                      nil))
7877                   (cc
7878                    (if (memq 'Cc nnmail-extra-headers)
7879                        (gnus-summary-find-matching
7880                         (cons 'extra 'Cc) recipient 'all nil nil
7881                         not-matching)
7882                      (gnus-message
7883                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7884                      (sit-for 1)
7885                      nil))
7886                   (articles
7887                    (if not-matching
7888                        ;; We need the numbers that are in both lists:
7889                        (mapcar (lambda (a)
7890                                  (and (memq a to) a))
7891                                cc)
7892                      (nconc to cc))))
7893              (unless articles
7894                (error "Found no matches for \"%s\"" recipient))
7895              (gnus-summary-limit articles))
7896       (gnus-summary-position-point))))
7897
7898 (defun gnus-summary-limit-to-age (age &optional younger-p)
7899   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7900 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7901 articles that are younger than AGE days."
7902   (interactive
7903    (let ((younger current-prefix-arg)
7904          (days-got nil)
7905          days)
7906      (while (not days-got)
7907        (setq days (if younger
7908                       (read-string "Limit to articles younger than (in days, older when negative): ")
7909                     (read-string
7910                      "Limit to articles older than (in days, younger when negative): ")))
7911        (when (> (length days) 0)
7912          (setq days (read days)))
7913        (if (numberp days)
7914            (progn
7915              (setq days-got t)
7916              (when (< days 0)
7917                (setq younger (not younger))
7918                (setq days (* days -1))))
7919          (message "Please enter a number.")
7920          (sleep-for 1)))
7921      (list days younger)))
7922   (prog1
7923       (let ((data gnus-newsgroup-data)
7924             (cutoff (days-to-time age))
7925             articles d date is-younger)
7926         (while (setq d (pop data))
7927           (when (and (vectorp (gnus-data-header d))
7928                      (setq date (mail-header-date (gnus-data-header d))))
7929             (setq is-younger (time-less-p
7930                               (time-since (condition-case ()
7931                                               (date-to-time date)
7932                                             (error '(0 0))))
7933                               cutoff))
7934             (when (if younger-p
7935                       is-younger
7936                     (not is-younger))
7937               (push (gnus-data-number d) articles))))
7938         (gnus-summary-limit (nreverse articles)))
7939     (gnus-summary-position-point)))
7940
7941 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7942   "Limit the summary buffer to articles that match an 'extra' header."
7943   (interactive
7944    (let ((header
7945           (intern
7946            (gnus-completing-read-with-default
7947             (symbol-name (car gnus-extra-headers))
7948             (if current-prefix-arg
7949                 "Exclude extra header"
7950               "Limit extra header")
7951             (mapcar (lambda (x)
7952                       (cons (symbol-name x) x))
7953                     gnus-extra-headers)
7954             nil
7955             t))))
7956      (list header
7957            (read-string (format "%s header %s (regexp): "
7958                                 (if current-prefix-arg "Exclude" "Limit to")
7959                                 header))
7960            current-prefix-arg)))
7961   (when (not (equal "" regexp))
7962     (prog1
7963         (let ((articles (gnus-summary-find-matching
7964                          (cons 'extra header) regexp 'all nil nil
7965                          not-matching)))
7966           (unless articles
7967             (error "Found no matches for \"%s\"" regexp))
7968           (gnus-summary-limit articles))
7969       (gnus-summary-position-point))))
7970
7971 (defun gnus-summary-limit-to-display-predicate ()
7972   "Limit the summary buffer to the predicated in the `display' group parameter."
7973   (interactive)
7974   (unless gnus-newsgroup-display
7975     (error "There is no `display' group parameter"))
7976   (let (articles)
7977     (dolist (number gnus-newsgroup-articles)
7978       (when (funcall gnus-newsgroup-display)
7979         (push number articles)))
7980     (gnus-summary-limit articles))
7981   (gnus-summary-position-point))
7982
7983 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7984 (make-obsolete
7985  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7986
7987 (defun gnus-summary-limit-to-unread (&optional all)
7988   "Limit the summary buffer to articles that are not marked as read.
7989 If ALL is non-nil, limit strictly to unread articles."
7990   (interactive "P")
7991   (if all
7992       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7993     (gnus-summary-limit-to-marks
7994      ;; Concat all the marks that say that an article is read and have
7995      ;; those removed.
7996      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7997            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7998            gnus-low-score-mark gnus-expirable-mark
7999            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8000            gnus-duplicate-mark gnus-souped-mark)
8001      'reverse)))
8002
8003 (defun gnus-summary-limit-to-replied (&optional unreplied)
8004   "Limit the summary buffer to replied articles.
8005 If UNREPLIED (the prefix), limit to unreplied articles."
8006   (interactive "P")
8007   (if unreplied
8008       (gnus-summary-limit
8009        (gnus-set-difference gnus-newsgroup-articles
8010         gnus-newsgroup-replied))
8011     (gnus-summary-limit gnus-newsgroup-replied))
8012   (gnus-summary-position-point))
8013
8014 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8015 (make-obsolete 'gnus-summary-delete-marked-with
8016                'gnus-summary-limit-exclude-marks)
8017
8018 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8019   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8020 If REVERSE, limit the summary buffer to articles that are marked
8021 with MARKS.  MARKS can either be a string of marks or a list of marks.
8022 Returns how many articles were removed."
8023   (interactive "sMarks: ")
8024   (gnus-summary-limit-to-marks marks t))
8025
8026 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8027   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8028 If REVERSE (the prefix), limit the summary buffer to articles that are
8029 not marked with MARKS.  MARKS can either be a string of marks or a
8030 list of marks.
8031 Returns how many articles were removed."
8032   (interactive "sMarks: \nP")
8033   (prog1
8034       (let ((data gnus-newsgroup-data)
8035             (marks (if (listp marks) marks
8036                      (append marks nil))) ; Transform to list.
8037             articles)
8038         (while data
8039           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8040                   (memq (gnus-data-mark (car data)) marks))
8041             (push (gnus-data-number (car data)) articles))
8042           (setq data (cdr data)))
8043         (gnus-summary-limit articles))
8044     (gnus-summary-position-point)))
8045
8046 (defun gnus-summary-limit-to-score (score)
8047   "Limit to articles with score at or above SCORE."
8048   (interactive "NLimit to articles with score of at least: ")
8049   (let ((data gnus-newsgroup-data)
8050         articles)
8051     (while data
8052       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8053                 score)
8054         (push (gnus-data-number (car data)) articles))
8055       (setq data (cdr data)))
8056     (prog1
8057         (gnus-summary-limit articles)
8058       (gnus-summary-position-point))))
8059
8060 (defun gnus-summary-limit-to-unseen ()
8061   "Limit to unseen articles."
8062   (interactive)
8063   (prog1
8064       (gnus-summary-limit gnus-newsgroup-unseen)
8065     (gnus-summary-position-point)))
8066
8067 (defun gnus-summary-limit-include-thread (id)
8068   "Display all the hidden articles that is in the thread with ID in it.
8069 When called interactively, ID is the Message-ID of the current
8070 article."
8071   (interactive (list (mail-header-id (gnus-summary-article-header))))
8072   (let ((articles (gnus-articles-in-thread
8073                    (gnus-id-to-thread (gnus-root-id id)))))
8074     (prog1
8075         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8076       (gnus-summary-limit-include-matching-articles
8077        "subject"
8078        (regexp-quote (gnus-simplify-subject-re
8079                       (mail-header-subject (gnus-id-to-header id)))))
8080       (gnus-summary-position-point))))
8081
8082 (defun gnus-summary-limit-include-matching-articles (header regexp)
8083   "Display all the hidden articles that have HEADERs that match REGEXP."
8084   (interactive (list (read-string "Match on header: ")
8085                      (read-string "Regexp: ")))
8086   (let ((articles (gnus-find-matching-articles header regexp)))
8087     (prog1
8088         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8089       (gnus-summary-position-point))))
8090
8091 (defun gnus-summary-insert-dormant-articles ()
8092   "Insert all the dormant articles for this group into the current buffer."
8093   (interactive)
8094   (let ((gnus-verbose (max 6 gnus-verbose)))
8095     (if (not gnus-newsgroup-dormant)
8096         (gnus-message 3 "No cached articles for this group")
8097       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8098
8099 (defun gnus-summary-limit-include-dormant ()
8100   "Display all the hidden articles that are marked as dormant.
8101 Note that this command only works on a subset of the articles currently
8102 fetched for this group."
8103   (interactive)
8104   (unless gnus-newsgroup-dormant
8105     (error "There are no dormant articles in this group"))
8106   (prog1
8107       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8108     (gnus-summary-position-point)))
8109
8110 (defun gnus-summary-limit-exclude-dormant ()
8111   "Hide all dormant articles."
8112   (interactive)
8113   (prog1
8114       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8115     (gnus-summary-position-point)))
8116
8117 (defun gnus-summary-limit-exclude-childless-dormant ()
8118   "Hide all dormant articles that have no children."
8119   (interactive)
8120   (let ((data (gnus-data-list t))
8121         articles d children)
8122     ;; Find all articles that are either not dormant or have
8123     ;; children.
8124     (while (setq d (pop data))
8125       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8126                 (and (setq children
8127                            (gnus-article-children (gnus-data-number d)))
8128                      (let (found)
8129                        (while children
8130                          (when (memq (car children) articles)
8131                            (setq children nil
8132                                  found t))
8133                          (pop children))
8134                        found)))
8135         (push (gnus-data-number d) articles)))
8136     ;; Do the limiting.
8137     (prog1
8138         (gnus-summary-limit articles)
8139       (gnus-summary-position-point))))
8140
8141 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8142   "Mark all unread excluded articles as read.
8143 If ALL, mark even excluded ticked and dormants as read."
8144   (interactive "P")
8145   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8146   (let ((articles (gnus-sorted-ndifference
8147                    (sort
8148                     (mapcar (lambda (h) (mail-header-number h))
8149                             gnus-newsgroup-headers)
8150                     '<)
8151                    gnus-newsgroup-limit))
8152         article)
8153     (setq gnus-newsgroup-unreads
8154           (gnus-sorted-intersection gnus-newsgroup-unreads
8155                                     gnus-newsgroup-limit))
8156     (if all
8157         (setq gnus-newsgroup-dormant nil
8158               gnus-newsgroup-marked nil
8159               gnus-newsgroup-reads
8160               (nconc
8161                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8162                gnus-newsgroup-reads))
8163       (while (setq article (pop articles))
8164         (unless (or (memq article gnus-newsgroup-dormant)
8165                     (memq article gnus-newsgroup-marked))
8166           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8167
8168 (defun gnus-summary-limit (articles &optional pop)
8169   (if pop
8170       ;; We pop the previous limit off the stack and use that.
8171       (setq articles (car gnus-newsgroup-limits)
8172             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8173     ;; We use the new limit, so we push the old limit on the stack.
8174     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8175   ;; Set the limit.
8176   (setq gnus-newsgroup-limit articles)
8177   (let ((total (length gnus-newsgroup-data))
8178         (data (gnus-data-find-list (gnus-summary-article-number)))
8179         (gnus-summary-mark-below nil)   ; Inhibit this.
8180         found)
8181     ;; This will do all the work of generating the new summary buffer
8182     ;; according to the new limit.
8183     (gnus-summary-prepare)
8184     ;; Hide any threads, possibly.
8185     (gnus-summary-maybe-hide-threads)
8186     ;; Try to return to the article you were at, or one in the
8187     ;; neighborhood.
8188     (when data
8189       ;; We try to find some article after the current one.
8190       (while data
8191         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8192           (setq data nil
8193                 found t))
8194         (setq data (cdr data))))
8195     (unless found
8196       ;; If there is no data, that means that we were after the last
8197       ;; article.  The same goes when we can't find any articles
8198       ;; after the current one.
8199       (goto-char (point-max))
8200       (gnus-summary-find-prev))
8201     (gnus-set-mode-line 'summary)
8202     ;; We return how many articles were removed from the summary
8203     ;; buffer as a result of the new limit.
8204     (- total (length gnus-newsgroup-data))))
8205
8206 (defsubst gnus-invisible-cut-children (threads)
8207   (let ((num 0))
8208     (while threads
8209       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8210         (incf num))
8211       (pop threads))
8212     (< num 2)))
8213
8214 (defsubst gnus-cut-thread (thread)
8215   "Go forwards in the thread until we find an article that we want to display."
8216   (when (or (eq gnus-fetch-old-headers 'some)
8217             (eq gnus-fetch-old-headers 'invisible)
8218             (numberp gnus-fetch-old-headers)
8219             (eq gnus-build-sparse-threads 'some)
8220             (eq gnus-build-sparse-threads 'more))
8221     ;; Deal with old-fetched headers and sparse threads.
8222     (while (and
8223             thread
8224             (or
8225              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8226              (gnus-summary-article-ancient-p
8227               (mail-header-number (car thread))))
8228             (if (or (<= (length (cdr thread)) 1)
8229                     (eq gnus-fetch-old-headers 'invisible))
8230                 (setq gnus-newsgroup-limit
8231                       (delq (mail-header-number (car thread))
8232                             gnus-newsgroup-limit)
8233                       thread (cadr thread))
8234               (when (gnus-invisible-cut-children (cdr thread))
8235                 (let ((th (cdr thread)))
8236                   (while th
8237                     (if (memq (mail-header-number (caar th))
8238                               gnus-newsgroup-limit)
8239                         (setq thread (car th)
8240                               th nil)
8241                       (setq th (cdr th))))))))))
8242   thread)
8243
8244 (defun gnus-cut-threads (threads)
8245   "Cut off all uninteresting articles from the beginning of THREADS."
8246   (when (or (eq gnus-fetch-old-headers 'some)
8247             (eq gnus-fetch-old-headers 'invisible)
8248             (numberp gnus-fetch-old-headers)
8249             (eq gnus-build-sparse-threads 'some)
8250             (eq gnus-build-sparse-threads 'more))
8251     (let ((th threads))
8252       (while th
8253         (setcar th (gnus-cut-thread (car th)))
8254         (setq th (cdr th)))))
8255   ;; Remove nixed out threads.
8256   (delq nil threads))
8257
8258 (defun gnus-summary-initial-limit (&optional show-if-empty)
8259   "Figure out what the initial limit is supposed to be on group entry.
8260 This entails weeding out unwanted dormants, low-scored articles,
8261 fetch-old-headers verbiage, and so on."
8262   ;; Most groups have nothing to remove.
8263   (if (or gnus-inhibit-limiting
8264           (and (null gnus-newsgroup-dormant)
8265                (eq gnus-newsgroup-display 'gnus-not-ignore)
8266                (not (eq gnus-fetch-old-headers 'some))
8267                (not (numberp gnus-fetch-old-headers))
8268                (not (eq gnus-fetch-old-headers 'invisible))
8269                (null gnus-summary-expunge-below)
8270                (not (eq gnus-build-sparse-threads 'some))
8271                (not (eq gnus-build-sparse-threads 'more))
8272                (null gnus-thread-expunge-below)
8273                (not gnus-use-nocem)))
8274       ()                                ; Do nothing.
8275     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8276     (setq gnus-newsgroup-limit nil)
8277     (mapatoms
8278      (lambda (node)
8279        (unless (car (symbol-value node))
8280          ;; These threads have no parents -- they are roots.
8281          (let ((nodes (cdr (symbol-value node)))
8282                thread)
8283            (while nodes
8284              (if (and gnus-thread-expunge-below
8285                       (< (gnus-thread-total-score (car nodes))
8286                          gnus-thread-expunge-below))
8287                  (gnus-expunge-thread (pop nodes))
8288                (setq thread (pop nodes))
8289                (gnus-summary-limit-children thread))))))
8290      gnus-newsgroup-dependencies)
8291     ;; If this limitation resulted in an empty group, we might
8292     ;; pop the previous limit and use it instead.
8293     (when (and (not gnus-newsgroup-limit)
8294                show-if-empty)
8295       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8296     gnus-newsgroup-limit))
8297
8298 (defun gnus-summary-limit-children (thread)
8299   "Return 1 if this subthread is visible and 0 if it is not."
8300   ;; First we get the number of visible children to this thread.  This
8301   ;; is done by recursing down the thread using this function, so this
8302   ;; will really go down to a leaf article first, before slowly
8303   ;; working its way up towards the root.
8304   (when thread
8305     (let* ((max-lisp-eval-depth 5000)
8306            (children
8307            (if (cdr thread)
8308                (apply '+ (mapcar 'gnus-summary-limit-children
8309                                  (cdr thread)))
8310              0))
8311           (number (mail-header-number (car thread)))
8312           score)
8313       (if (and
8314            (not (memq number gnus-newsgroup-marked))
8315            (or
8316             ;; If this article is dormant and has absolutely no visible
8317             ;; children, then this article isn't visible.
8318             (and (memq number gnus-newsgroup-dormant)
8319                  (zerop children))
8320             ;; If this is "fetch-old-headered" and there is no
8321             ;; visible children, then we don't want this article.
8322             (and (or (eq gnus-fetch-old-headers 'some)
8323                      (numberp gnus-fetch-old-headers))
8324                  (gnus-summary-article-ancient-p number)
8325                  (zerop children))
8326             ;; If this is "fetch-old-headered" and `invisible', then
8327             ;; we don't want this article.
8328             (and (eq gnus-fetch-old-headers 'invisible)
8329                  (gnus-summary-article-ancient-p number))
8330             ;; If this is a sparsely inserted article with no children,
8331             ;; we don't want it.
8332             (and (eq gnus-build-sparse-threads 'some)
8333                  (gnus-summary-article-sparse-p number)
8334                  (zerop children))
8335             ;; If we use expunging, and this article is really
8336             ;; low-scored, then we don't want this article.
8337             (when (and gnus-summary-expunge-below
8338                        (< (setq score
8339                                 (or (cdr (assq number gnus-newsgroup-scored))
8340                                     gnus-summary-default-score))
8341                           gnus-summary-expunge-below))
8342               ;; We increase the expunge-tally here, but that has
8343               ;; nothing to do with the limits, really.
8344               (incf gnus-newsgroup-expunged-tally)
8345               ;; We also mark as read here, if that's wanted.
8346               (when (and gnus-summary-mark-below
8347                          (< score gnus-summary-mark-below))
8348                 (setq gnus-newsgroup-unreads
8349                       (delq number gnus-newsgroup-unreads))
8350                 (if gnus-newsgroup-auto-expire
8351                     (push number gnus-newsgroup-expirable)
8352                   (push (cons number gnus-low-score-mark)
8353                         gnus-newsgroup-reads)))
8354               t)
8355             ;; Do the `display' group parameter.
8356             (and gnus-newsgroup-display
8357                  (not (funcall gnus-newsgroup-display)))
8358             ;; Check NoCeM things.
8359             (when (and gnus-use-nocem
8360                        (gnus-nocem-unwanted-article-p
8361                         (mail-header-id (car thread))))
8362               (setq gnus-newsgroup-unreads
8363                     (delq number gnus-newsgroup-unreads))
8364               t)))
8365           ;; Nope, invisible article.
8366           0
8367         ;; Ok, this article is to be visible, so we add it to the limit
8368         ;; and return 1.
8369         (push number gnus-newsgroup-limit)
8370         1))))
8371
8372 (defun gnus-expunge-thread (thread)
8373   "Mark all articles in THREAD as read."
8374   (let* ((number (mail-header-number (car thread))))
8375     (incf gnus-newsgroup-expunged-tally)
8376     ;; We also mark as read here, if that's wanted.
8377     (setq gnus-newsgroup-unreads
8378           (delq number gnus-newsgroup-unreads))
8379     (if gnus-newsgroup-auto-expire
8380         (push number gnus-newsgroup-expirable)
8381       (push (cons number gnus-low-score-mark)
8382             gnus-newsgroup-reads)))
8383   ;; Go recursively through all subthreads.
8384   (mapcar 'gnus-expunge-thread (cdr thread)))
8385
8386 ;; Summary article oriented commands
8387
8388 (defun gnus-summary-refer-parent-article (n)
8389   "Refer parent article N times.
8390 If N is negative, go to ancestor -N instead.
8391 The difference between N and the number of articles fetched is returned."
8392   (interactive "p")
8393   (let ((skip 1)
8394         error header ref)
8395     (when (not (natnump n))
8396       (setq skip (abs n)
8397             n 1))
8398     (while (and (> n 0)
8399                 (not error))
8400       (setq header (gnus-summary-article-header))
8401       (if (and (eq (mail-header-number header)
8402                    (cdr gnus-article-current))
8403                (equal gnus-newsgroup-name
8404                       (car gnus-article-current)))
8405           ;; If we try to find the parent of the currently
8406           ;; displayed article, then we take a look at the actual
8407           ;; References header, since this is slightly more
8408           ;; reliable than the References field we got from the
8409           ;; server.
8410           (save-excursion
8411             (set-buffer gnus-original-article-buffer)
8412             (nnheader-narrow-to-headers)
8413             (unless (setq ref (message-fetch-field "references"))
8414               (when (setq ref (message-fetch-field "in-reply-to"))
8415                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8416             (widen))
8417         (setq ref
8418               ;; It's not the current article, so we take a bet on
8419               ;; the value we got from the server.
8420               (mail-header-references header)))
8421       (if (and ref
8422                (not (equal ref "")))
8423           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8424             (gnus-message 1 "Couldn't find parent"))
8425         (gnus-message 1 "No references in article %d"
8426                       (gnus-summary-article-number))
8427         (setq error t))
8428       (decf n))
8429     (gnus-summary-position-point)
8430     n))
8431
8432 (defun gnus-summary-refer-references ()
8433   "Fetch all articles mentioned in the References header.
8434 Return the number of articles fetched."
8435   (interactive)
8436   (let ((ref (mail-header-references (gnus-summary-article-header)))
8437         (current (gnus-summary-article-number))
8438         (n 0))
8439     (if (or (not ref)
8440             (equal ref ""))
8441         (error "No References in the current article")
8442       ;; For each Message-ID in the References header...
8443       (while (string-match "<[^>]*>" ref)
8444         (incf n)
8445         ;; ... fetch that article.
8446         (gnus-summary-refer-article
8447          (prog1 (match-string 0 ref)
8448            (setq ref (substring ref (match-end 0))))))
8449       (gnus-summary-goto-subject current)
8450       (gnus-summary-position-point)
8451       n)))
8452
8453 (defun gnus-summary-refer-thread (&optional limit)
8454   "Fetch all articles in the current thread.
8455 If LIMIT (the numerical prefix), fetch that many old headers instead
8456 of what's specified by the `gnus-refer-thread-limit' variable."
8457   (interactive "P")
8458   (let ((id (mail-header-id (gnus-summary-article-header)))
8459         (limit (if limit (prefix-numeric-value limit)
8460                  gnus-refer-thread-limit)))
8461     (unless (eq gnus-fetch-old-headers 'invisible)
8462       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8463       ;; Retrieve the headers and read them in.
8464       (if (eq (if (numberp limit)
8465                   (gnus-retrieve-headers
8466                    (list (min
8467                           (+ (mail-header-number
8468                               (gnus-summary-article-header))
8469                              limit)
8470                           gnus-newsgroup-end))
8471                    gnus-newsgroup-name (* limit 2))
8472                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8473                 ;; headers.
8474                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8475                                        gnus-newsgroup-name limit))
8476               'nov)
8477           (gnus-build-all-threads)
8478         (error "Can't fetch thread from back ends that don't support NOV"))
8479       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8480     (gnus-summary-limit-include-thread id)))
8481
8482 (defun gnus-summary-refer-article (message-id)
8483   "Fetch an article specified by MESSAGE-ID."
8484   (interactive "sMessage-ID: ")
8485   (when (and (stringp message-id)
8486              (not (zerop (length message-id))))
8487     (setq message-id (gnus-replace-in-string message-id " " ""))
8488     ;; Construct the correct Message-ID if necessary.
8489     ;; Suggested by tale@pawl.rpi.edu.
8490     (unless (string-match "^<" message-id)
8491       (setq message-id (concat "<" message-id)))
8492     (unless (string-match ">$" message-id)
8493       (setq message-id (concat message-id ">")))
8494     ;; People often post MIDs from URLs, so unhex it:
8495     (unless (string-match "@" message-id)
8496       (setq message-id (gnus-url-unhex-string message-id)))
8497     (let* ((header (gnus-id-to-header message-id))
8498            (sparse (and header
8499                         (gnus-summary-article-sparse-p
8500                          (mail-header-number header))
8501                         (memq (mail-header-number header)
8502                               gnus-newsgroup-limit)))
8503            number)
8504       (cond
8505        ;; If the article is present in the buffer we just go to it.
8506        ((and header
8507              (or (not (gnus-summary-article-sparse-p
8508                        (mail-header-number header)))
8509                  sparse))
8510         (prog1
8511             (gnus-summary-goto-article
8512              (mail-header-number header) nil t)
8513           (when sparse
8514             (gnus-summary-update-article (mail-header-number header)))))
8515        (t
8516         ;; We fetch the article.
8517         (catch 'found
8518           (dolist (gnus-override-method (gnus-refer-article-methods))
8519             (when (and (gnus-check-server gnus-override-method)
8520                        ;; Fetch the header,
8521                        (setq number (gnus-summary-insert-subject message-id)))
8522               ;; and display the article.
8523               (gnus-summary-select-article nil nil nil number)
8524               (throw 'found t)))
8525           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8526
8527 (defun gnus-refer-article-methods ()
8528   "Return a list of referable methods."
8529   (cond
8530    ;; No method, so we default to current and native.
8531    ((null gnus-refer-article-method)
8532     (list gnus-current-select-method gnus-select-method))
8533    ;; Current.
8534    ((eq 'current gnus-refer-article-method)
8535     (list gnus-current-select-method))
8536    ;; List of select methods.
8537    ((not (and (symbolp (car gnus-refer-article-method))
8538               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8539     (let (out)
8540       (dolist (method gnus-refer-article-method)
8541         (push (if (eq 'current method)
8542                   gnus-current-select-method
8543                 method)
8544               out))
8545       (nreverse out)))
8546    ;; One single select method.
8547    (t
8548     (list gnus-refer-article-method))))
8549
8550 (defun gnus-summary-edit-parameters ()
8551   "Edit the group parameters of the current group."
8552   (interactive)
8553   (gnus-group-edit-group gnus-newsgroup-name 'params))
8554
8555 (defun gnus-summary-customize-parameters ()
8556   "Customize the group parameters of the current group."
8557   (interactive)
8558   (gnus-group-customize gnus-newsgroup-name))
8559
8560 (defun gnus-summary-enter-digest-group (&optional force)
8561   "Enter an nndoc group based on the current article.
8562 If FORCE, force a digest interpretation.  If not, try
8563 to guess what the document format is."
8564   (interactive "P")
8565   (let ((conf gnus-current-window-configuration))
8566     (save-window-excursion
8567       (save-excursion
8568         (let (gnus-article-prepare-hook
8569               gnus-display-mime-function
8570               gnus-break-pages)
8571           (gnus-summary-select-article))))
8572     (setq gnus-current-window-configuration conf)
8573     (let* ((name (format "%s-%d"
8574                          (gnus-group-prefixed-name
8575                           gnus-newsgroup-name (list 'nndoc ""))
8576                          (with-current-buffer gnus-summary-buffer
8577                            gnus-current-article)))
8578            (ogroup gnus-newsgroup-name)
8579            (params (append (gnus-info-params (gnus-get-info ogroup))
8580                            (list (cons 'to-group ogroup))
8581                            (list (cons 'parent-group ogroup))
8582                            (list (cons 'save-article-group ogroup))))
8583            (case-fold-search t)
8584            (buf (current-buffer))
8585            dig to-address)
8586       (save-excursion
8587         (set-buffer gnus-original-article-buffer)
8588         ;; Have the digest group inherit the main mail address of
8589         ;; the parent article.
8590         (when (setq to-address (or (gnus-fetch-field "reply-to")
8591                                    (gnus-fetch-field "from")))
8592           (setq params (append
8593                         (list (cons 'to-address
8594                                     (funcall gnus-decode-encoded-word-function
8595                                              to-address))))))
8596         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8597         (insert-buffer-substring gnus-original-article-buffer)
8598         ;; Remove lines that may lead nndoc to misinterpret the
8599         ;; document type.
8600         (narrow-to-region
8601          (goto-char (point-min))
8602          (or (search-forward "\n\n" nil t) (point)))
8603         (goto-char (point-min))
8604         (delete-matching-lines "^Path:\\|^From ")
8605         (widen))
8606       (unwind-protect
8607           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8608                     (gnus-newsgroup-ephemeral-ignored-charsets
8609                      gnus-newsgroup-ignored-charsets))
8610                 (gnus-group-read-ephemeral-group
8611                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8612                               (nndoc-article-type
8613                                ,(if force 'mbox 'guess)))
8614                  t nil nil nil
8615                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8616                                                         "ADAPT")))))
8617               ;; Make all postings to this group go to the parent group.
8618               (nconc (gnus-info-params (gnus-get-info name))
8619                      params)
8620             ;; Couldn't select this doc group.
8621             (switch-to-buffer buf)
8622             (gnus-set-global-variables)
8623             (gnus-configure-windows 'summary)
8624             (gnus-message 3 "Article couldn't be entered?"))
8625         (kill-buffer dig)))))
8626
8627 (defun gnus-summary-read-document (n)
8628   "Open a new group based on the current article(s).
8629 This will allow you to read digests and other similar
8630 documents as newsgroups.
8631 Obeys the standard process/prefix convention."
8632   (interactive "P")
8633   (let* ((ogroup gnus-newsgroup-name)
8634          (params (append (gnus-info-params (gnus-get-info ogroup))
8635                          (list (cons 'to-group ogroup))))
8636          group egroup groups vgroup)
8637     (dolist (article (gnus-summary-work-articles n))
8638       (setq group (format "%s-%d" gnus-newsgroup-name article))
8639       (gnus-summary-remove-process-mark article)
8640       (when (gnus-summary-display-article article)
8641         (save-excursion
8642           (with-temp-buffer
8643             (insert-buffer-substring gnus-original-article-buffer)
8644             ;; Remove some headers that may lead nndoc to make
8645             ;; the wrong guess.
8646             (message-narrow-to-head)
8647             (goto-char (point-min))
8648             (delete-matching-lines "^Path:\\|^From ")
8649             (widen)
8650             (if (setq egroup
8651                       (gnus-group-read-ephemeral-group
8652                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8653                                      (nndoc-article-type guess))
8654                        t nil t))
8655                 (progn
8656             ;; Make all postings to this group go to the parent group.
8657                   (nconc (gnus-info-params (gnus-get-info egroup))
8658                          params)
8659                   (push egroup groups))
8660               ;; Couldn't select this doc group.
8661               (gnus-error 3 "Article couldn't be entered"))))))
8662     ;; Now we have selected all the documents.
8663     (cond
8664      ((not groups)
8665       (error "None of the articles could be interpreted as documents"))
8666      ((gnus-group-read-ephemeral-group
8667        (setq vgroup (format
8668                      "nnvirtual:%s-%s" gnus-newsgroup-name
8669                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8670        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8671        t
8672        (cons (current-buffer) 'summary)))
8673      (t
8674       (error "Couldn't select virtual nndoc group")))))
8675
8676 (defun gnus-summary-isearch-article (&optional regexp-p)
8677   "Do incremental search forward on the current article.
8678 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8679   (interactive "P")
8680   (gnus-summary-select-article)
8681   (gnus-configure-windows 'article)
8682   (gnus-eval-in-buffer-window gnus-article-buffer
8683     (save-restriction
8684       (widen)
8685       (isearch-forward regexp-p))))
8686
8687 (defun gnus-summary-search-article-forward (regexp &optional backward)
8688   "Search for an article containing REGEXP forward.
8689 If BACKWARD, search backward instead."
8690   (interactive
8691    (list (read-string
8692           (format "Search article %s (regexp%s): "
8693                   (if current-prefix-arg "backward" "forward")
8694                   (if gnus-last-search-regexp
8695                       (concat ", default " gnus-last-search-regexp)
8696                     "")))
8697          current-prefix-arg))
8698   (if (string-equal regexp "")
8699       (setq regexp (or gnus-last-search-regexp ""))
8700     (setq gnus-last-search-regexp regexp)
8701     (setq gnus-article-before-search gnus-current-article))
8702   ;; Intentionally set gnus-last-article.
8703   (setq gnus-last-article gnus-article-before-search)
8704   (let ((gnus-last-article gnus-last-article))
8705     (if (gnus-summary-search-article regexp backward)
8706         (gnus-summary-show-thread)
8707       (signal 'search-failed (list regexp)))))
8708
8709 (defun gnus-summary-search-article-backward (regexp)
8710   "Search for an article containing REGEXP backward."
8711   (interactive
8712    (list (read-string
8713           (format "Search article backward (regexp%s): "
8714                   (if gnus-last-search-regexp
8715                       (concat ", default " gnus-last-search-regexp)
8716                     "")))))
8717   (gnus-summary-search-article-forward regexp 'backward))
8718
8719 (defun gnus-summary-search-article (regexp &optional backward)
8720   "Search for an article containing REGEXP.
8721 Optional argument BACKWARD means do search for backward.
8722 `gnus-select-article-hook' is not called during the search."
8723   ;; We have to require this here to make sure that the following
8724   ;; dynamic binding isn't shadowed by autoloading.
8725   (require 'gnus-async)
8726   (require 'gnus-art)
8727   (let ((gnus-select-article-hook nil)  ;Disable hook.
8728         (gnus-article-prepare-hook nil)
8729         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8730         (gnus-use-article-prefetch nil)
8731         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8732         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8733         (gnus-visual nil)
8734         (gnus-keep-backlog nil)
8735         (gnus-break-pages nil)
8736         (gnus-summary-display-arrow nil)
8737         (gnus-updated-mode-lines nil)
8738         (gnus-auto-center-summary nil)
8739         (sum (current-buffer))
8740         (gnus-display-mime-function nil)
8741         (found nil)
8742         point)
8743     (gnus-save-hidden-threads
8744       (gnus-summary-select-article)
8745       (set-buffer gnus-article-buffer)
8746       (goto-char (window-point (get-buffer-window (current-buffer))))
8747       (when backward
8748         (forward-line -1))
8749       (while (not found)
8750         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8751         (if (if backward
8752                 (re-search-backward regexp nil t)
8753               (re-search-forward regexp nil t))
8754             ;; We found the regexp.
8755             (progn
8756               (setq found 'found)
8757               (beginning-of-line)
8758               (set-window-start
8759                (get-buffer-window (current-buffer))
8760                (point))
8761               (forward-line 1)
8762               (set-window-point
8763                (get-buffer-window (current-buffer))
8764                (point))
8765               (set-buffer sum)
8766               (setq point (point)))
8767           ;; We didn't find it, so we go to the next article.
8768           (set-buffer sum)
8769           (setq found 'not)
8770           (while (eq found 'not)
8771             (if (not (if backward (gnus-summary-find-prev)
8772                        (gnus-summary-find-next)))
8773                 ;; No more articles.
8774                 (setq found t)
8775               ;; Select the next article and adjust point.
8776               (unless (gnus-summary-article-sparse-p
8777                        (gnus-summary-article-number))
8778                 (setq found nil)
8779                 (gnus-summary-select-article)
8780                 (set-buffer gnus-article-buffer)
8781                 (widen)
8782                 (goto-char (if backward (point-max) (point-min))))))))
8783       (gnus-message 7 ""))
8784     ;; Return whether we found the regexp.
8785     (when (eq found 'found)
8786       (goto-char point)
8787       (gnus-summary-show-thread)
8788       (gnus-summary-goto-subject gnus-current-article)
8789       (gnus-summary-position-point)
8790       t)))
8791
8792 (defun gnus-find-matching-articles (header regexp)
8793   "Return a list of all articles that match REGEXP on HEADER.
8794 This search includes all articles in the current group that Gnus has
8795 fetched headers for, whether they are displayed or not."
8796   (let ((articles nil)
8797         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8798         (case-fold-search t))
8799     (dolist (header gnus-newsgroup-headers)
8800       (when (string-match regexp (funcall func header))
8801         (push (mail-header-number header) articles)))
8802     (nreverse articles)))
8803
8804 (defun gnus-summary-find-matching (header regexp &optional backward unread
8805                                           not-case-fold not-matching)
8806   "Return a list of all articles that match REGEXP on HEADER.
8807 The search stars on the current article and goes forwards unless
8808 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8809 If UNREAD is non-nil, only unread articles will
8810 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8811 in the comparisons. If NOT-MATCHING, return a list of all articles that
8812 not match REGEXP on HEADER."
8813   (let ((case-fold-search (not not-case-fold))
8814         articles d func)
8815     (if (consp header)
8816         (if (eq (car header) 'extra)
8817             (setq func
8818                   `(lambda (h)
8819                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8820                          "")))
8821           (error "%s is an invalid header" header))
8822       (unless (fboundp (intern (concat "mail-header-" header)))
8823         (error "%s is not a valid header" header))
8824       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8825     (dolist (d (if (eq backward 'all)
8826                    gnus-newsgroup-data
8827                  (gnus-data-find-list
8828                   (gnus-summary-article-number)
8829                   (gnus-data-list backward))))
8830       (when (and (or (not unread)       ; We want all articles...
8831                      (gnus-data-unread-p d)) ; Or just unreads.
8832                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8833                  (if not-matching
8834                      (not (string-match
8835                            regexp
8836                            (funcall func (gnus-data-header d))))
8837                    (string-match regexp
8838                                  (funcall func (gnus-data-header d)))))
8839         (push (gnus-data-number d) articles))) ; Success!
8840     (nreverse articles)))
8841
8842 (defun gnus-summary-execute-command (header regexp command &optional backward)
8843   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8844 If HEADER is an empty string (or nil), the match is done on the entire
8845 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8846   (interactive
8847    (list (let ((completion-ignore-case t))
8848            (completing-read
8849             "Header name: "
8850             (mapcar (lambda (header) (list (format "%s" header)))
8851                     (append
8852                      '("Number" "Subject" "From" "Lines" "Date"
8853                        "Message-ID" "Xref" "References" "Body")
8854                      gnus-extra-headers))
8855             nil 'require-match))
8856          (read-string "Regexp: ")
8857          (read-key-sequence "Command: ")
8858          current-prefix-arg))
8859   (when (equal header "Body")
8860     (setq header ""))
8861   ;; Hidden thread subtrees must be searched as well.
8862   (gnus-summary-show-all-threads)
8863   ;; We don't want to change current point nor window configuration.
8864   (save-excursion
8865     (save-window-excursion
8866       (let (gnus-visual
8867             gnus-treat-strip-trailing-blank-lines
8868             gnus-treat-strip-leading-blank-lines
8869             gnus-treat-strip-multiple-blank-lines
8870             gnus-treat-hide-boring-headers
8871             gnus-treat-fold-newsgroups
8872             gnus-article-prepare-hook)
8873         (gnus-message 6 "Executing %s..." (key-description command))
8874         ;; We'd like to execute COMMAND interactively so as to give arguments.
8875         (gnus-execute header regexp
8876                       `(call-interactively ',(key-binding command))
8877                       backward)
8878         (gnus-message 6 "Executing %s...done" (key-description command))))))
8879
8880 (defun gnus-summary-beginning-of-article ()
8881   "Scroll the article back to the beginning."
8882   (interactive)
8883   (gnus-summary-select-article)
8884   (gnus-configure-windows 'article)
8885   (gnus-eval-in-buffer-window gnus-article-buffer
8886     (widen)
8887     (goto-char (point-min))
8888     (when gnus-break-pages
8889       (gnus-narrow-to-page))))
8890
8891 (defun gnus-summary-end-of-article ()
8892   "Scroll to the end of the article."
8893   (interactive)
8894   (gnus-summary-select-article)
8895   (gnus-configure-windows 'article)
8896   (gnus-eval-in-buffer-window gnus-article-buffer
8897     (widen)
8898     (goto-char (point-max))
8899     (recenter -3)
8900     (when gnus-break-pages
8901       (when (re-search-backward page-delimiter nil t)
8902         (narrow-to-region (match-end 0) (point-max)))
8903       (gnus-narrow-to-page))))
8904
8905 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8906   "Truncate to LEN and quote all \"(\"'s in STRING."
8907   (gnus-replace-in-string (if (and len (> (length string) len))
8908                               (substring string 0 len)
8909                             string)
8910                           "[()]" "\\\\\\&"))
8911
8912 (defun gnus-summary-print-article (&optional filename n)
8913   "Generate and print a PostScript image of the process-marked (mail) articles.
8914
8915 If used interactively, print the current article if none are
8916 process-marked.  With prefix arg, prompt the user for the name of the
8917 file to save in.
8918
8919 When used from Lisp, accept two optional args FILENAME and N.  N means
8920 to print the next N articles.  If N is negative, print the N previous
8921 articles.  If N is nil and articles have been marked with the process
8922 mark, print these instead.
8923
8924 If the optional first argument FILENAME is nil, send the image to the
8925 printer.  If FILENAME is a string, save the PostScript image in a file with
8926 that name.  If FILENAME is a number, prompt the user for the name of the file
8927 to save in."
8928   (interactive (list (ps-print-preprint current-prefix-arg)))
8929   (dolist (article (gnus-summary-work-articles n))
8930     (gnus-summary-select-article nil nil 'pseudo article)
8931     (gnus-eval-in-buffer-window gnus-article-buffer
8932       (gnus-print-buffer))
8933     (gnus-summary-remove-process-mark article))
8934   (ps-despool filename))
8935
8936 (defun gnus-print-buffer ()
8937   (let ((buffer (generate-new-buffer " *print*")))
8938     (unwind-protect
8939         (progn
8940           (copy-to-buffer buffer (point-min) (point-max))
8941           (set-buffer buffer)
8942           (gnus-remove-text-with-property 'gnus-decoration)
8943           (when (gnus-visual-p 'article-highlight 'highlight)
8944             ;; Copy-to-buffer doesn't copy overlay.  So redo
8945             ;; highlight.
8946             (let ((gnus-article-buffer buffer))
8947               (gnus-article-highlight-citation t)
8948               (gnus-article-highlight-signature)
8949               (gnus-article-emphasize)
8950               (gnus-article-delete-invisible-text)))
8951           (let ((ps-left-header
8952                  (list
8953                   (concat "("
8954                           (gnus-summary-print-truncate-and-quote
8955                            (mail-header-subject gnus-current-headers)
8956                            66) ")")
8957                   (concat "("
8958                           (gnus-summary-print-truncate-and-quote
8959                            (mail-header-from gnus-current-headers)
8960                            45) ")")))
8961                 (ps-right-header
8962                  (list
8963                   "/pagenumberstring load"
8964                   (concat "("
8965                           (mail-header-date gnus-current-headers) ")"))))
8966             (gnus-run-hooks 'gnus-ps-print-hook)
8967             (save-excursion
8968               (if window-system
8969                   (ps-spool-buffer-with-faces)
8970                 (ps-spool-buffer)))))
8971       (kill-buffer buffer))))
8972
8973 (defun gnus-summary-show-article (&optional arg)
8974   "Force redisplaying of the current article.
8975 If ARG (the prefix) is a number, show the article with the charset
8976 defined in `gnus-summary-show-article-charset-alist', or the charset
8977 input.
8978 If ARG (the prefix) is non-nil and not a number, show the raw article
8979 without any article massaging functions being run.  Normally, the key
8980 strokes are `C-u g'."
8981   (interactive "P")
8982   (cond
8983    ((numberp arg)
8984     (gnus-summary-show-article t)
8985     (let ((gnus-newsgroup-charset
8986            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8987                (mm-read-coding-system
8988                 "View as charset: " ;; actually it is coding system.
8989                 (with-current-buffer gnus-article-buffer
8990                   (mm-detect-coding-region (point) (point-max))))))
8991           (gnus-newsgroup-ignored-charsets 'gnus-all))
8992       (gnus-summary-select-article nil 'force)
8993       (let ((deps gnus-newsgroup-dependencies)
8994             head header lines)
8995         (save-excursion
8996           (set-buffer gnus-original-article-buffer)
8997           (save-restriction
8998             (message-narrow-to-head)
8999             (setq head (buffer-string))
9000             (goto-char (point-min))
9001             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9002               (goto-char (point-max))
9003               (widen)
9004               (setq lines (1- (count-lines (point) (point-max))))))
9005           (with-temp-buffer
9006             (insert (format "211 %d Article retrieved.\n"
9007                             (cdr gnus-article-current)))
9008             (insert head)
9009             (if lines (insert (format "Lines: %d\n" lines)))
9010             (insert ".\n")
9011             (let ((nntp-server-buffer (current-buffer)))
9012               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9013         (gnus-data-set-header
9014          (gnus-data-find (cdr gnus-article-current))
9015          header)
9016         (gnus-summary-update-article-line
9017          (cdr gnus-article-current) header)
9018         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9019           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9020    ((not arg)
9021     ;; Select the article the normal way.
9022     (gnus-summary-select-article nil 'force))
9023    (t
9024     ;; We have to require this here to make sure that the following
9025     ;; dynamic binding isn't shadowed by autoloading.
9026     (require 'gnus-async)
9027     (require 'gnus-art)
9028     ;; Bind the article treatment functions to nil.
9029     (let ((gnus-have-all-headers t)
9030           gnus-article-prepare-hook
9031           gnus-article-decode-hook
9032           gnus-display-mime-function
9033           gnus-break-pages)
9034       ;; Destroy any MIME parts.
9035       (when (gnus-buffer-live-p gnus-article-buffer)
9036         (save-excursion
9037           (set-buffer gnus-article-buffer)
9038           (mm-destroy-parts gnus-article-mime-handles)
9039           ;; Set it to nil for safety reason.
9040           (setq gnus-article-mime-handle-alist nil)
9041           (setq gnus-article-mime-handles nil)))
9042       (gnus-summary-select-article nil 'force))))
9043   (gnus-summary-goto-subject gnus-current-article)
9044   (gnus-summary-position-point))
9045
9046 (defun gnus-summary-show-raw-article ()
9047   "Show the raw article without any article massaging functions being run."
9048   (interactive)
9049   (gnus-summary-show-article t))
9050
9051 (defun gnus-summary-verbose-headers (&optional arg)
9052   "Toggle permanent full header display.
9053 If ARG is a positive number, turn header display on.
9054 If ARG is a negative number, turn header display off."
9055   (interactive "P")
9056   (setq gnus-show-all-headers
9057         (cond ((or (not (numberp arg))
9058                    (zerop arg))
9059                (not gnus-show-all-headers))
9060               ((natnump arg)
9061                t)))
9062   (gnus-summary-show-article))
9063
9064 (defun gnus-summary-toggle-header (&optional arg)
9065   "Show the headers if they are hidden, or hide them if they are shown.
9066 If ARG is a positive number, show the entire header.
9067 If ARG is a negative number, hide the unwanted header lines."
9068   (interactive "P")
9069   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9070                      (get-buffer-window gnus-article-buffer t))))
9071     (with-current-buffer gnus-article-buffer
9072       (widen)
9073       (article-narrow-to-head)
9074       (let* ((buffer-read-only nil)
9075              (inhibit-point-motion-hooks t)
9076              (hidden (if (numberp arg)
9077                          (>= arg 0)
9078                        (or (not (looking-at "[^ \t\n]+:"))
9079                            (gnus-article-hidden-text-p 'headers))))
9080              s e)
9081         (delete-region (point-min) (point-max))
9082         (with-current-buffer gnus-original-article-buffer
9083           (goto-char (setq s (point-min)))
9084           (setq e (if (search-forward "\n\n" nil t)
9085                       (1- (point))
9086                     (point-max))))
9087         (insert-buffer-substring gnus-original-article-buffer s e)
9088         (run-hooks 'gnus-article-decode-hook)
9089         (if hidden
9090             (let ((gnus-treat-hide-headers nil)
9091                   (gnus-treat-hide-boring-headers nil))
9092               (gnus-delete-wash-type 'headers)
9093               (gnus-treat-article 'head))
9094           (gnus-treat-article 'head))
9095         (widen)
9096         (if window
9097             (set-window-start window (goto-char (point-min))))
9098         (if gnus-break-pages
9099             (gnus-narrow-to-page)
9100           (when (gnus-visual-p 'page-marker)
9101             (let ((buffer-read-only nil))
9102               (gnus-remove-text-with-property 'gnus-prev)
9103               (gnus-remove-text-with-property 'gnus-next))))
9104         (gnus-set-mode-line 'article)))))
9105
9106 (defun gnus-summary-show-all-headers ()
9107   "Make all header lines visible."
9108   (interactive)
9109   (gnus-summary-toggle-header 1))
9110
9111 (defun gnus-summary-caesar-message (&optional arg)
9112   "Caesar rotate the current article by 13.
9113 The numerical prefix specifies how many places to rotate each letter
9114 forward."
9115   (interactive "P")
9116   (gnus-summary-select-article)
9117   (let ((mail-header-separator ""))
9118     (gnus-eval-in-buffer-window gnus-article-buffer
9119       (save-restriction
9120         (widen)
9121         (let ((start (window-start))
9122               buffer-read-only)
9123           (message-caesar-buffer-body arg)
9124           (set-window-start (get-buffer-window (current-buffer)) start)))))
9125   ;; Create buttons and stuff...
9126   (gnus-treat-article nil))
9127
9128 (defun gnus-summary-idna-message (&optional arg)
9129   "Decode IDNA encoded domain names in the current articles.
9130 IDNA encoded domain names looks like `xn--bar'.  If a string
9131 remain unencoded after running this function, it is likely an
9132 invalid IDNA string (`xn--bar' is invalid).
9133
9134 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9135 installed for this command to work."
9136   (interactive "P")
9137   (if (not (and (condition-case nil (require 'idna)
9138                   (file-error))
9139                 (mm-coding-system-p 'utf-8)
9140                 (executable-find (symbol-value 'idna-program))))
9141       (gnus-message
9142        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9143     (gnus-summary-select-article)
9144     (let ((mail-header-separator ""))
9145       (gnus-eval-in-buffer-window gnus-article-buffer
9146         (save-restriction
9147           (widen)
9148           (let ((start (window-start))
9149                 buffer-read-only)
9150             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9151               (replace-match (idna-to-unicode (match-string 1))))
9152             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9153
9154 (autoload 'unmorse-region "morse"
9155   "Convert morse coded text in region to ordinary ASCII text."
9156   t)
9157
9158 (defun gnus-summary-morse-message (&optional arg)
9159   "Morse decode the current article."
9160   (interactive "P")
9161   (gnus-summary-select-article)
9162   (let ((mail-header-separator ""))
9163     (gnus-eval-in-buffer-window gnus-article-buffer
9164       (save-excursion
9165         (save-restriction
9166           (widen)
9167           (let ((pos (window-start))
9168                 buffer-read-only)
9169             (goto-char (point-min))
9170             (when (message-goto-body)
9171               (gnus-narrow-to-body))
9172             (goto-char (point-min))
9173             (while (search-forward "·" (point-max) t)
9174               (replace-match "."))
9175             (unmorse-region (point-min) (point-max))
9176             (widen)
9177             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9178
9179 (defun gnus-summary-stop-page-breaking ()
9180   "Stop page breaking in the current article."
9181   (interactive)
9182   (gnus-summary-select-article)
9183   (gnus-eval-in-buffer-window gnus-article-buffer
9184     (widen)
9185     (when (gnus-visual-p 'page-marker)
9186       (let ((buffer-read-only nil))
9187         (gnus-remove-text-with-property 'gnus-prev)
9188         (gnus-remove-text-with-property 'gnus-next))
9189       (setq gnus-page-broken nil))))
9190
9191 (defun gnus-summary-move-article (&optional n to-newsgroup
9192                                             select-method action)
9193   "Move the current article to a different newsgroup.
9194 If N is a positive number, move the N next articles.
9195 If N is a negative number, move the N previous articles.
9196 If N is nil and any articles have been marked with the process mark,
9197 move those articles instead.
9198 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9199 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9200 re-spool using this method.
9201
9202 When called interactively with TO-NEWSGROUP being nil, the value of
9203 the variable `gnus-move-split-methods' is used for finding a default
9204 for the target newsgroup.
9205
9206 For this function to work, both the current newsgroup and the
9207 newsgroup that you want to move to have to support the `request-move'
9208 and `request-accept' functions.
9209
9210 ACTION can be either `move' (the default), `crosspost' or `copy'."
9211   (interactive "P")
9212   (unless action
9213     (setq action 'move))
9214   ;; Check whether the source group supports the required functions.
9215   (cond ((and (eq action 'move)
9216               (not (gnus-check-backend-function
9217                     'request-move-article gnus-newsgroup-name)))
9218          (error "The current group does not support article moving"))
9219         ((and (eq action 'crosspost)
9220               (not (gnus-check-backend-function
9221                     'request-replace-article gnus-newsgroup-name)))
9222          (error "The current group does not support article editing")))
9223   (let ((articles (gnus-summary-work-articles n))
9224         (prefix (if (gnus-check-backend-function
9225                      'request-move-article gnus-newsgroup-name)
9226                     (funcall gnus-move-group-prefix-function
9227                              gnus-newsgroup-name)
9228                   ""))
9229         (names '((move "Move" "Moving")
9230                  (copy "Copy" "Copying")
9231                  (crosspost "Crosspost" "Crossposting")))
9232         (copy-buf (save-excursion
9233                     (nnheader-set-temp-buffer " *copy article*")))
9234         art-group to-method new-xref article to-groups articles-to-update-marks)
9235     (unless (assq action names)
9236       (error "Unknown action %s" action))
9237     ;; Read the newsgroup name.
9238     (when (and (not to-newsgroup)
9239                (not select-method))
9240       (if (and gnus-move-split-methods
9241                (not
9242                 (and (memq gnus-current-article articles)
9243                      (gnus-buffer-live-p gnus-original-article-buffer))))
9244           ;; When `gnus-move-split-methods' is non-nil, we have to
9245           ;; select an article to give `gnus-read-move-group-name' an
9246           ;; opportunity to suggest an appropriate default.  However,
9247           ;; we needn't render or mark the article.
9248           (let ((gnus-display-mime-function nil)
9249                 (gnus-article-prepare-hook nil)
9250                 (gnus-mark-article-hook nil))
9251             (gnus-summary-select-article nil nil nil (car articles))))
9252       (setq to-newsgroup
9253             (gnus-read-move-group-name
9254              (cadr (assq action names))
9255              (symbol-value (intern (format "gnus-current-%s-group" action)))
9256              articles prefix))
9257       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9258     (setq to-method (or select-method
9259                         (gnus-server-to-method
9260                          (gnus-group-method to-newsgroup))))
9261     ;; Check the method we are to move this article to...
9262     (unless (gnus-check-backend-function
9263              'request-accept-article (car to-method))
9264       (error "%s does not support article copying" (car to-method)))
9265     (unless (gnus-check-server to-method)
9266       (error "Can't open server %s" (car to-method)))
9267     (gnus-message 6 "%s to %s: %s..."
9268                   (caddr (assq action names))
9269                   (or (car select-method) to-newsgroup) articles)
9270     (while articles
9271       (setq article (pop articles))
9272       (setq
9273        art-group
9274        (cond
9275         ;; Move the article.
9276         ((eq action 'move)
9277          ;; Remove this article from future suppression.
9278          (gnus-dup-unsuppress-article article)
9279          (let* ((from-method (gnus-find-method-for-group
9280                               gnus-newsgroup-name))
9281                 (to-method (gnus-find-method-for-group
9282                             to-newsgroup))
9283                 (move-is-internal (gnus-method-equal from-method to-method)))
9284          (gnus-request-move-article
9285           article                       ; Article to move
9286           gnus-newsgroup-name           ; From newsgroup
9287           (nth 1 (gnus-find-method-for-group
9288                   gnus-newsgroup-name)) ; Server
9289           (list 'gnus-request-accept-article
9290                 to-newsgroup (list 'quote select-method)
9291                 (not articles) t)       ; Accept form
9292           (not articles)                ; Only save nov last time
9293           move-is-internal)))           ; is this move internal?
9294         ;; Copy the article.
9295         ((eq action 'copy)
9296          (save-excursion
9297            (set-buffer copy-buf)
9298            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9299              (save-restriction
9300                (nnheader-narrow-to-headers)
9301                (dolist (hdr gnus-copy-article-ignored-headers)
9302                  (message-remove-header hdr t)))
9303              (gnus-request-accept-article
9304               to-newsgroup select-method (not articles) t))))
9305         ;; Crosspost the article.
9306         ((eq action 'crosspost)
9307          (let ((xref (message-tokenize-header
9308                       (mail-header-xref (gnus-summary-article-header article))
9309                       " ")))
9310            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9311                                   ":" (number-to-string article)))
9312            (unless xref
9313              (setq xref (list (system-name))))
9314            (setq new-xref
9315                  (concat
9316                   (mapconcat 'identity
9317                              (delete "Xref:" (delete new-xref xref))
9318                              " ")
9319                   " " new-xref))
9320            (save-excursion
9321              (set-buffer copy-buf)
9322              ;; First put the article in the destination group.
9323              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9324              (when (consp (setq art-group
9325                                 (gnus-request-accept-article
9326                                  to-newsgroup select-method (not articles))))
9327                (setq new-xref (concat new-xref " " (car art-group)
9328                                       ":"
9329                                       (number-to-string (cdr art-group))))
9330                ;; Now we have the new Xrefs header, so we insert
9331                ;; it and replace the new article.
9332                (nnheader-replace-header "Xref" new-xref)
9333                (gnus-request-replace-article
9334                 (cdr art-group) to-newsgroup (current-buffer))
9335                art-group))))))
9336       (cond
9337        ((not art-group)
9338         (gnus-message 1 "Couldn't %s article %s: %s"
9339                       (cadr (assq action names)) article
9340                       (nnheader-get-report (car to-method))))
9341        ((eq art-group 'junk)
9342         (when (eq action 'move)
9343           (gnus-summary-mark-article article gnus-canceled-mark)
9344           (gnus-message 4 "Deleted article %s" article)
9345           ;; run the delete hook
9346           (run-hook-with-args 'gnus-summary-article-delete-hook
9347                               action
9348                               (gnus-data-header
9349                                (assoc article (gnus-data-list nil)))
9350                               gnus-newsgroup-name nil
9351                               select-method)))
9352        (t
9353         (let* ((pto-group (gnus-group-prefixed-name
9354                            (car art-group) to-method))
9355                (info (gnus-get-info pto-group))
9356                (to-group (gnus-info-group info))
9357                to-marks)
9358           ;; Update the group that has been moved to.
9359           (when (and info
9360                      (memq action '(move copy)))
9361             (unless (member to-group to-groups)
9362               (push to-group to-groups))
9363
9364             (unless (memq article gnus-newsgroup-unreads)
9365               (push 'read to-marks)
9366               (gnus-info-set-read
9367                info (gnus-add-to-range (gnus-info-read info)
9368                                        (list (cdr art-group)))))
9369
9370             ;; See whether the article is to be put in the cache.
9371             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9372                              gnus-article-mark-lists
9373                            (delete '(expirable . expire)
9374                                    (copy-sequence gnus-article-mark-lists))))
9375                   (to-article (cdr art-group)))
9376
9377               ;; Enter the article into the cache in the new group,
9378               ;; if that is required.
9379               (when gnus-use-cache
9380                 (gnus-cache-possibly-enter-article
9381                  to-group to-article
9382                  (memq article gnus-newsgroup-marked)
9383                  (memq article gnus-newsgroup-dormant)
9384                  (memq article gnus-newsgroup-unreads)))
9385
9386               (when gnus-preserve-marks
9387                 ;; Copy any marks over to the new group.
9388                 (when (and (equal to-group gnus-newsgroup-name)
9389                            (not (memq article gnus-newsgroup-unreads)))
9390                   ;; Mark this article as read in this group.
9391                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9392                   (setcdr (gnus-active to-group) to-article)
9393                   (setcdr gnus-newsgroup-active to-article))
9394
9395                 (while marks
9396                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9397                     (when (memq article (symbol-value
9398                                          (intern (format "gnus-newsgroup-%s"
9399                                                          (caar marks)))))
9400                       (push (cdar marks) to-marks)
9401                       ;; If the other group is the same as this group,
9402                       ;; then we have to add the mark to the list.
9403                       (when (equal to-group gnus-newsgroup-name)
9404                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9405                              (cons to-article
9406                                    (symbol-value
9407                                     (intern (format "gnus-newsgroup-%s"
9408                                                     (caar marks)))))))
9409                       ;; Copy the marks to other group.
9410                       (gnus-add-marked-articles
9411                        to-group (cdar marks) (list to-article) info)))
9412                   (setq marks (cdr marks)))
9413
9414                 (gnus-request-set-mark
9415                  to-group (list (list (list to-article) 'add to-marks))))
9416
9417               (gnus-dribble-enter
9418                (concat "(gnus-group-set-info '"
9419                        (gnus-prin1-to-string (gnus-get-info to-group))
9420                        ")"))))
9421
9422           ;; Update the Xref header in this article to point to
9423           ;; the new crossposted article we have just created.
9424           (when (eq action 'crosspost)
9425             (save-excursion
9426               (set-buffer copy-buf)
9427               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9428               (nnheader-replace-header "Xref" new-xref)
9429               (gnus-request-replace-article
9430                article gnus-newsgroup-name (current-buffer))))
9431
9432           ;; run the move/copy/crosspost/respool hook
9433           (run-hook-with-args 'gnus-summary-article-move-hook
9434                               action
9435                               (gnus-data-header
9436                                (assoc article (gnus-data-list nil)))
9437                               gnus-newsgroup-name
9438                               to-newsgroup
9439                               select-method))
9440
9441         ;;;!!!Why is this necessary?
9442         (set-buffer gnus-summary-buffer)
9443         
9444         (gnus-summary-goto-subject article)
9445         (when (eq action 'move)
9446           (gnus-summary-mark-article article gnus-canceled-mark))))
9447       (push article articles-to-update-marks))
9448
9449     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9450     ;; Re-activate all groups that have been moved to.
9451     (save-excursion
9452       (set-buffer gnus-group-buffer)
9453       (let ((gnus-group-marked to-groups))
9454         (gnus-group-get-new-news-this-group nil t)))
9455     
9456     (gnus-kill-buffer copy-buf)
9457     (gnus-summary-position-point)
9458     (gnus-set-mode-line 'summary)))
9459
9460 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9461   "Copy the current article to some other group.
9462 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9463 When called interactively, if TO-NEWSGROUP is nil, use the value of
9464 the variable `gnus-move-split-methods' for finding a default target
9465 newsgroup.
9466 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9467 re-spool using this method."
9468   (interactive "P")
9469   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9470
9471 (defun gnus-summary-crosspost-article (&optional n)
9472   "Crosspost the current article to some other group."
9473   (interactive "P")
9474   (gnus-summary-move-article n nil nil 'crosspost))
9475
9476 (defcustom gnus-summary-respool-default-method nil
9477   "Default method type for respooling an article.
9478 If nil, use to the current newsgroup method."
9479   :type 'symbol
9480   :group 'gnus-summary-mail)
9481
9482 (defcustom gnus-summary-display-while-building nil
9483   "If non-nil, show and update the summary buffer as it's being built.
9484 If the value is t, update the buffer after every line is inserted.  If
9485 the value is an integer (N), update the display every N lines."
9486   :version "22.1"
9487   :group 'gnus-thread
9488   :type '(choice (const :tag "off" nil)
9489                  number
9490                  (const :tag "frequently" t)))
9491
9492 (defun gnus-summary-respool-article (&optional n method)
9493   "Respool the current article.
9494 The article will be squeezed through the mail spooling process again,
9495 which means that it will be put in some mail newsgroup or other
9496 depending on `nnmail-split-methods'.
9497 If N is a positive number, respool the N next articles.
9498 If N is a negative number, respool the N previous articles.
9499 If N is nil and any articles have been marked with the process mark,
9500 respool those articles instead.
9501
9502 Respooling can be done both from mail groups and \"real\" newsgroups.
9503 In the former case, the articles in question will be moved from the
9504 current group into whatever groups they are destined to.  In the
9505 latter case, they will be copied into the relevant groups."
9506   (interactive
9507    (list current-prefix-arg
9508          (let* ((methods (gnus-methods-using 'respool))
9509                 (methname
9510                  (symbol-name (or gnus-summary-respool-default-method
9511                                   (car (gnus-find-method-for-group
9512                                         gnus-newsgroup-name)))))
9513                 (method
9514                  (gnus-completing-read-with-default
9515                   methname "Backend to use when respooling"
9516                   methods nil t nil 'gnus-mail-method-history))
9517                 ms)
9518            (cond
9519             ((zerop (length (setq ms (gnus-servers-using-backend
9520                                       (intern method)))))
9521              (list (intern method) ""))
9522             ((= 1 (length ms))
9523              (car ms))
9524             (t
9525              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9526                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9527                            ms-alist))))))))
9528   (unless method
9529     (error "No method given for respooling"))
9530   (if (assoc (symbol-name
9531               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9532              (gnus-methods-using 'respool))
9533       (gnus-summary-move-article n nil method)
9534     (gnus-summary-copy-article n nil method)))
9535
9536 (defun gnus-summary-import-article (file &optional edit)
9537   "Import an arbitrary file into a mail newsgroup."
9538   (interactive "fImport file: \nP")
9539   (let ((group gnus-newsgroup-name)
9540         (now (current-time))
9541         atts lines group-art)
9542     (unless (gnus-check-backend-function 'request-accept-article group)
9543       (error "%s does not support article importing" group))
9544     (or (file-readable-p file)
9545         (not (file-regular-p file))
9546         (error "Can't read %s" file))
9547     (save-excursion
9548       (set-buffer (gnus-get-buffer-create " *import file*"))
9549       (erase-buffer)
9550       (nnheader-insert-file-contents file)
9551       (goto-char (point-min))
9552       (if (nnheader-article-p)
9553           (save-restriction
9554             (goto-char (point-min))
9555             (search-forward "\n\n" nil t)
9556             (narrow-to-region (point-min) (1- (point)))
9557             (goto-char (point-min))
9558             (unless (re-search-forward "^date:" nil t)
9559               (goto-char (point-max))
9560               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9561        ;; This doesn't look like an article, so we fudge some headers.
9562         (setq atts (file-attributes file)
9563               lines (count-lines (point-min) (point-max)))
9564         (insert "From: " (read-string "From: ") "\n"
9565                 "Subject: " (read-string "Subject: ") "\n"
9566                 "Date: " (message-make-date (nth 5 atts)) "\n"
9567                 "Message-ID: " (message-make-message-id) "\n"
9568                 "Lines: " (int-to-string lines) "\n"
9569                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9570       (setq group-art (gnus-request-accept-article group nil t))
9571       (kill-buffer (current-buffer)))
9572     (setq gnus-newsgroup-active (gnus-activate-group group))
9573     (forward-line 1)
9574     (gnus-summary-goto-article (cdr group-art) nil t)
9575     (when edit
9576       (gnus-summary-edit-article))))
9577
9578 (defun gnus-summary-create-article ()
9579   "Create an article in a mail newsgroup."
9580   (interactive)
9581   (let ((group gnus-newsgroup-name)
9582         (now (current-time))
9583         group-art)
9584     (unless (gnus-check-backend-function 'request-accept-article group)
9585       (error "%s does not support article importing" group))
9586     (save-excursion
9587       (set-buffer (gnus-get-buffer-create " *import file*"))
9588       (erase-buffer)
9589       (goto-char (point-min))
9590       ;; This doesn't look like an article, so we fudge some headers.
9591       (insert "From: " (read-string "From: ") "\n"
9592               "Subject: " (read-string "Subject: ") "\n"
9593               "Date: " (message-make-date now) "\n"
9594               "Message-ID: " (message-make-message-id) "\n")
9595       (setq group-art (gnus-request-accept-article group nil t))
9596       (kill-buffer (current-buffer)))
9597     (setq gnus-newsgroup-active (gnus-activate-group group))
9598     (forward-line 1)
9599     (gnus-summary-goto-article (cdr group-art) nil t)
9600     (gnus-summary-edit-article)))
9601
9602 (defun gnus-summary-article-posted-p ()
9603   "Say whether the current (mail) article is available from news as well.
9604 This will be the case if the article has both been mailed and posted."
9605   (interactive)
9606   (let ((id (mail-header-references (gnus-summary-article-header)))
9607         (gnus-override-method (car (gnus-refer-article-methods))))
9608     (if (gnus-request-head id "")
9609         (gnus-message 2 "The current message was found on %s"
9610                       gnus-override-method)
9611       (gnus-message 2 "The current message couldn't be found on %s"
9612                     gnus-override-method)
9613       nil)))
9614
9615 (defun gnus-summary-expire-articles (&optional now)
9616   "Expire all articles that are marked as expirable in the current group."
9617   (interactive)
9618   (when (and (not gnus-group-is-exiting-without-update-p)
9619              (gnus-check-backend-function
9620               'request-expire-articles gnus-newsgroup-name))
9621     ;; This backend supports expiry.
9622     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9623            (expirable (if total
9624                           (progn
9625                             ;; We need to update the info for
9626                             ;; this group for `gnus-list-of-read-articles'
9627                             ;; to give us the right answer.
9628                             (gnus-run-hooks 'gnus-exit-group-hook)
9629                             (gnus-summary-update-info)
9630                             (gnus-list-of-read-articles gnus-newsgroup-name))
9631                         (setq gnus-newsgroup-expirable
9632                               (sort gnus-newsgroup-expirable '<))))
9633            (expiry-wait (if now 'immediate
9634                           (gnus-group-find-parameter
9635                            gnus-newsgroup-name 'expiry-wait)))
9636            (nnmail-expiry-target
9637             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9638                 nnmail-expiry-target))
9639            es)
9640       (when expirable
9641         ;; There are expirable articles in this group, so we run them
9642         ;; through the expiry process.
9643         (gnus-message 6 "Expiring articles...")
9644         (unless (gnus-check-group gnus-newsgroup-name)
9645           (error "Can't open server for %s" gnus-newsgroup-name))
9646         ;; The list of articles that weren't expired is returned.
9647         (save-excursion
9648           (if expiry-wait
9649               (let ((nnmail-expiry-wait-function nil)
9650                     (nnmail-expiry-wait expiry-wait))
9651                 (setq es (gnus-request-expire-articles
9652                           expirable gnus-newsgroup-name)))
9653             (setq es (gnus-request-expire-articles
9654                       expirable gnus-newsgroup-name)))
9655           (unless total
9656             (setq gnus-newsgroup-expirable es))
9657           ;; We go through the old list of expirable, and mark all
9658           ;; really expired articles as nonexistent.
9659           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9660             (let ((gnus-use-cache nil))
9661               (dolist (article expirable)
9662                 (when (and (not (memq article es))
9663                            (gnus-data-find article))
9664                   (gnus-summary-mark-article article gnus-canceled-mark)
9665                   (run-hook-with-args 'gnus-summary-article-expire-hook
9666                                       'delete
9667                                       (gnus-data-header
9668                                        (assoc article (gnus-data-list nil)))
9669                                       gnus-newsgroup-name
9670                                       nil
9671                                       nil))))))
9672         (gnus-message 6 "Expiring articles...done")))))
9673
9674 (defun gnus-summary-expire-articles-now ()
9675   "Expunge all expirable articles in the current group.
9676 This means that *all* articles that are marked as expirable will be
9677 deleted forever, right now."
9678   (interactive)
9679   (or gnus-expert-user
9680       (gnus-yes-or-no-p
9681        "Are you really, really, really sure you want to delete all these messages? ")
9682       (error "Phew!"))
9683   (gnus-summary-expire-articles t))
9684
9685 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9686 (defun gnus-summary-delete-article (&optional n)
9687   "Delete the N next (mail) articles.
9688 This command actually deletes articles.  This is not a marking
9689 command.  The article will disappear forever from your life, never to
9690 return.
9691
9692 If N is negative, delete backwards.
9693 If N is nil and articles have been marked with the process mark,
9694 delete these instead.
9695
9696 If `gnus-novice-user' is non-nil you will be asked for
9697 confirmation before the articles are deleted."
9698   (interactive "P")
9699   (unless (gnus-check-backend-function 'request-expire-articles
9700                                        gnus-newsgroup-name)
9701     (error "The current newsgroup does not support article deletion"))
9702   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9703     (error "Couldn't open server"))
9704   ;; Compute the list of articles to delete.
9705   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9706         (nnmail-expiry-target 'delete)
9707         not-deleted)
9708     (if (and gnus-novice-user
9709              (not (gnus-yes-or-no-p
9710                    (format "Do you really want to delete %s forever? "
9711                            (if (> (length articles) 1)
9712                                (format "these %s articles" (length articles))
9713                              "this article")))))
9714         ()
9715       ;; Delete the articles.
9716       (setq not-deleted (gnus-request-expire-articles
9717                          articles gnus-newsgroup-name 'force))
9718       (while articles
9719         (gnus-summary-remove-process-mark (car articles))
9720         ;; The backend might not have been able to delete the article
9721         ;; after all.
9722         (unless (memq (car articles) not-deleted)
9723           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9724         (let* ((article (car articles))
9725                (ghead  (gnus-data-header
9726                                     (assoc article (gnus-data-list nil)))))
9727           (run-hook-with-args 'gnus-summary-article-delete-hook
9728                               'delete ghead gnus-newsgroup-name nil
9729                               nil))
9730         (setq articles (cdr articles)))
9731       (when not-deleted
9732         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9733     (gnus-summary-position-point)
9734     (gnus-set-mode-line 'summary)
9735     not-deleted))
9736
9737 (defun gnus-summary-edit-article (&optional arg)
9738   "Edit the current article.
9739 This will have permanent effect only in mail groups.
9740 If ARG is nil, edit the decoded articles.
9741 If ARG is 1, edit the raw articles.
9742 If ARG is 2, edit the raw articles even in read-only groups.
9743 If ARG is 3, edit the articles with the current handles.
9744 Otherwise, allow editing of articles even in read-only
9745 groups."
9746   (interactive "P")
9747   (let (force raw current-handles)
9748     (cond
9749      ((null arg))
9750      ((eq arg 1)
9751       (setq raw t))
9752      ((eq arg 2)
9753       (setq raw t
9754             force t))
9755      ((eq arg 3)
9756       (setq current-handles
9757             (and (gnus-buffer-live-p gnus-article-buffer)
9758                  (with-current-buffer gnus-article-buffer
9759                    (prog1
9760                        gnus-article-mime-handles
9761                      (setq gnus-article-mime-handles nil))))))
9762      (t
9763       (setq force t)))
9764     (when (and raw (not force)
9765                (member gnus-newsgroup-name '("nndraft:delayed"
9766                                              "nndraft:drafts"
9767                                              "nndraft:queue")))
9768       (error "Can't edit the raw article in group %s"
9769              gnus-newsgroup-name))
9770     (save-excursion
9771       (set-buffer gnus-summary-buffer)
9772       (let ((mail-parse-charset gnus-newsgroup-charset)
9773             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9774         (gnus-set-global-variables)
9775         (when (and (not force)
9776                    (gnus-group-read-only-p))
9777           (error "The current newsgroup does not support article editing"))
9778         (gnus-summary-show-article t)
9779         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9780           (with-current-buffer gnus-article-buffer
9781             (mm-enable-multibyte)))
9782         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9783             (setq raw t))
9784         (gnus-article-edit-article
9785          (if raw 'ignore
9786            `(lambda ()
9787               (let ((mbl mml-buffer-list))
9788                 (setq mml-buffer-list nil)
9789                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9790                   (mime-to-mml ,'current-handles))
9791                 (let ((mbl1 mml-buffer-list))
9792                   (setq mml-buffer-list mbl)
9793                   (set (make-local-variable 'mml-buffer-list) mbl1))
9794                 (gnus-make-local-hook 'kill-buffer-hook)
9795                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9796          `(lambda (no-highlight)
9797             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9798                   (message-options message-options)
9799                   (message-options-set-recipient)
9800                   (mail-parse-ignored-charsets
9801                    ',gnus-newsgroup-ignored-charsets))
9802               ,(if (not raw) '(progn
9803                                 (mml-to-mime)
9804                                 (mml-destroy-buffers)
9805                                 (remove-hook 'kill-buffer-hook
9806                                              'mml-destroy-buffers t)
9807                                 (kill-local-variable 'mml-buffer-list)))
9808               (gnus-summary-edit-article-done
9809                ,(or (mail-header-references gnus-current-headers) "")
9810                ,(gnus-group-read-only-p)
9811                ,gnus-summary-buffer no-highlight))))))))
9812
9813 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9814
9815 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9816                                                  no-highlight)
9817   "Make edits to the current article permanent."
9818   (interactive)
9819   (save-excursion
9820    ;; The buffer restriction contains the entire article if it exists.
9821     (when (article-goto-body)
9822       (let ((lines (count-lines (point) (point-max)))
9823             (length (- (point-max) (point)))
9824             (case-fold-search t)
9825             (body (copy-marker (point))))
9826         (goto-char (point-min))
9827         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9828           (delete-region (match-beginning 1) (match-end 1))
9829           (insert (number-to-string length)))
9830         (goto-char (point-min))
9831         (when (re-search-forward
9832                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9833           (delete-region (match-beginning 1) (match-end 1))
9834           (insert (number-to-string length)))
9835         (goto-char (point-min))
9836         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9837           (delete-region (match-beginning 1) (match-end 1))
9838           (insert (number-to-string lines))))))
9839   ;; Replace the article.
9840   (let ((buf (current-buffer)))
9841     (with-temp-buffer
9842       (insert-buffer-substring buf)
9843
9844       (if (and (not read-only)
9845                (not (gnus-request-replace-article
9846                      (cdr gnus-article-current) (car gnus-article-current)
9847                      (current-buffer) t)))
9848           (error "Couldn't replace article")
9849         ;; Update the summary buffer.
9850         (if (and references
9851                  (equal (message-tokenize-header references " ")
9852                         (message-tokenize-header
9853                          (or (message-fetch-field "references") "") " ")))
9854             ;; We only have to update this line.
9855             (save-excursion
9856               (save-restriction
9857                 (message-narrow-to-head)
9858                 (let ((head (buffer-substring-no-properties
9859                              (point-min) (point-max)))
9860                       header)
9861                   (with-temp-buffer
9862                     (insert (format "211 %d Article retrieved.\n"
9863                                     (cdr gnus-article-current)))
9864                     (insert head)
9865                     (insert ".\n")
9866                     (let ((nntp-server-buffer (current-buffer)))
9867                       (setq header (car (gnus-get-newsgroup-headers
9868                                          nil t))))
9869                     (save-excursion
9870                       (set-buffer gnus-summary-buffer)
9871                       (gnus-data-set-header
9872                        (gnus-data-find (cdr gnus-article-current))
9873                        header)
9874                       (gnus-summary-update-article-line
9875                        (cdr gnus-article-current) header)
9876                       (if (gnus-summary-goto-subject
9877                            (cdr gnus-article-current) nil t)
9878                           (gnus-summary-update-secondary-mark
9879                            (cdr gnus-article-current))))))))
9880           ;; Update threads.
9881           (set-buffer (or buffer gnus-summary-buffer))
9882           (gnus-summary-update-article (cdr gnus-article-current))
9883           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9884               (gnus-summary-update-secondary-mark
9885                (cdr gnus-article-current))))
9886         ;; Prettify the article buffer again.
9887         (unless no-highlight
9888           (save-excursion
9889             (set-buffer gnus-article-buffer)
9890             ;;;!!! Fix this -- article should be rehighlighted.
9891             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9892             (set-buffer gnus-original-article-buffer)
9893             (gnus-request-article
9894              (cdr gnus-article-current)
9895              (car gnus-article-current) (current-buffer))))
9896         ;; Prettify the summary buffer line.
9897         (when (gnus-visual-p 'summary-highlight 'highlight)
9898           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9899
9900 (defun gnus-summary-edit-wash (key)
9901   "Perform editing command KEY in the article buffer."
9902   (interactive
9903    (list
9904     (progn
9905       (message "%s" (concat (this-command-keys) "- "))
9906       (read-char))))
9907   (message "")
9908   (gnus-summary-edit-article)
9909   (execute-kbd-macro (concat (this-command-keys) key))
9910   (gnus-article-edit-done))
9911
9912 ;;; Respooling
9913
9914 (defun gnus-summary-respool-query (&optional silent trace)
9915   "Query where the respool algorithm would put this article."
9916   (interactive)
9917   (let (gnus-mark-article-hook)
9918     (gnus-summary-select-article)
9919     (save-excursion
9920       (set-buffer gnus-original-article-buffer)
9921       (let ((groups (nnmail-article-group 'identity trace)))
9922         (unless silent
9923           (if groups
9924               (message "This message would go to %s"
9925                        (mapconcat 'car groups ", "))
9926             (message "This message would go to no groups"))
9927           groups)))))
9928
9929 (defun gnus-summary-respool-trace ()
9930   "Trace where the respool algorithm would put this article.
9931 Display a buffer showing all fancy splitting patterns which matched."
9932   (interactive)
9933   (gnus-summary-respool-query nil t))
9934
9935 ;; Summary marking commands.
9936
9937 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9938   "Mark articles which has the same subject as read, and then select the next.
9939 If UNMARK is positive, remove any kind of mark.
9940 If UNMARK is negative, tick articles."
9941   (interactive "P")
9942   (when unmark
9943     (setq unmark (prefix-numeric-value unmark)))
9944   (let ((count
9945          (gnus-summary-mark-same-subject
9946           (gnus-summary-article-subject) unmark)))
9947     ;; Select next unread article.  If auto-select-same mode, should
9948     ;; select the first unread article.
9949     (gnus-summary-next-article t (and gnus-auto-select-same
9950                                       (gnus-summary-article-subject)))
9951     (gnus-message 7 "%d article%s marked as %s"
9952                   count (if (= count 1) " is" "s are")
9953                   (if unmark "unread" "read"))))
9954
9955 (defun gnus-summary-kill-same-subject (&optional unmark)
9956   "Mark articles which has the same subject as read.
9957 If UNMARK is positive, remove any kind of mark.
9958 If UNMARK is negative, tick articles."
9959   (interactive "P")
9960   (when unmark
9961     (setq unmark (prefix-numeric-value unmark)))
9962   (let ((count
9963          (gnus-summary-mark-same-subject
9964           (gnus-summary-article-subject) unmark)))
9965     ;; If marked as read, go to next unread subject.
9966     (when (null unmark)
9967       ;; Go to next unread subject.
9968       (gnus-summary-next-subject 1 t))
9969     (gnus-message 7 "%d articles are marked as %s"
9970                   count (if unmark "unread" "read"))))
9971
9972 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9973   "Mark articles with same SUBJECT as read, and return marked number.
9974 If optional argument UNMARK is positive, remove any kinds of marks.
9975 If optional argument UNMARK is negative, mark articles as unread instead."
9976   (let ((count 1))
9977     (save-excursion
9978       (cond
9979        ((null unmark)                   ; Mark as read.
9980         (while (and
9981                 (progn
9982                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9983                   (gnus-summary-show-thread) t)
9984                 (gnus-summary-find-subject subject))
9985           (setq count (1+ count))))
9986        ((> unmark 0)                    ; Tick.
9987         (while (and
9988                 (progn
9989                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9990                   (gnus-summary-show-thread) t)
9991                 (gnus-summary-find-subject subject))
9992           (setq count (1+ count))))
9993        (t                               ; Mark as unread.
9994         (while (and
9995                 (progn
9996                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9997                   (gnus-summary-show-thread) t)
9998                 (gnus-summary-find-subject subject))
9999           (setq count (1+ count)))))
10000       (gnus-set-mode-line 'summary)
10001       ;; Return the number of marked articles.
10002       count)))
10003
10004 (defun gnus-summary-mark-as-processable (n &optional unmark)
10005   "Set the process mark on the next N articles.
10006 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10007 the process mark instead.  The difference between N and the actual
10008 number of articles marked is returned."
10009   (interactive "P")
10010   (if (and (null n) (gnus-region-active-p))
10011       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10012     (setq n (prefix-numeric-value n))
10013     (let ((backward (< n 0))
10014           (n (abs n)))
10015       (while (and
10016               (> n 0)
10017               (if unmark
10018                   (gnus-summary-remove-process-mark
10019                    (gnus-summary-article-number))
10020                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10021               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10022         (setq n (1- n)))
10023       (when (/= 0 n)
10024         (gnus-message 7 "No more articles"))
10025       (gnus-summary-recenter)
10026       (gnus-summary-position-point)
10027       n)))
10028
10029 (defun gnus-summary-unmark-as-processable (n)
10030   "Remove the process mark from the next N articles.
10031 If N is negative, unmark backward instead.  The difference between N and
10032 the actual number of articles unmarked is returned."
10033   (interactive "P")
10034   (gnus-summary-mark-as-processable n t))
10035
10036 (defun gnus-summary-unmark-all-processable ()
10037   "Remove the process mark from all articles."
10038   (interactive)
10039   (save-excursion
10040     (while gnus-newsgroup-processable
10041       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10042   (gnus-summary-position-point))
10043
10044 (defun gnus-summary-add-mark (article type)
10045   "Mark ARTICLE with a mark of TYPE."
10046   (let ((vtype (car (assq type gnus-article-mark-lists)))
10047         var)
10048     (if (not vtype)
10049         (error "No such mark type: %s" type)
10050       (setq var (intern (format "gnus-newsgroup-%s" type)))
10051       (set var (cons article (symbol-value var)))
10052       (if (memq type '(processable cached replied forwarded recent saved))
10053           (gnus-summary-update-secondary-mark article)
10054         ;;; !!! This is bogus.  We should find out what primary
10055         ;;; !!! mark we want to set.
10056         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10057
10058 (defun gnus-summary-mark-as-expirable (n)
10059   "Mark N articles forward as expirable.
10060 If N is negative, mark backward instead.  The difference between N and
10061 the actual number of articles marked is returned."
10062   (interactive "p")
10063   (gnus-summary-mark-forward n gnus-expirable-mark))
10064
10065 (defun gnus-summary-mark-as-spam (n)
10066   "Mark N articles forward as spam.
10067 If N is negative, mark backward instead.  The difference between N and
10068 the actual number of articles marked is returned."
10069   (interactive "p")
10070   (gnus-summary-mark-forward n gnus-spam-mark))
10071
10072 (defun gnus-summary-mark-article-as-replied (article)
10073   "Mark ARTICLE as replied to and update the summary line.
10074 ARTICLE can also be a list of articles."
10075   (interactive (list (gnus-summary-article-number)))
10076   (let ((articles (if (listp article) article (list article))))
10077     (dolist (article articles)
10078       (unless (numberp article)
10079         (error "%s is not a number" article))
10080       (push article gnus-newsgroup-replied)
10081       (let ((buffer-read-only nil))
10082         (when (gnus-summary-goto-subject article nil t)
10083           (gnus-summary-update-secondary-mark article))))))
10084
10085 (defun gnus-summary-mark-article-as-forwarded (article)
10086   "Mark ARTICLE as forwarded and update the summary line.
10087 ARTICLE can also be a list of articles."
10088   (let ((articles (if (listp article) article (list article))))
10089     (dolist (article articles)
10090       (push article gnus-newsgroup-forwarded)
10091       (let ((buffer-read-only nil))
10092         (when (gnus-summary-goto-subject article nil t)
10093           (gnus-summary-update-secondary-mark article))))))
10094
10095 (defun gnus-summary-set-bookmark (article)
10096   "Set a bookmark in current article."
10097   (interactive (list (gnus-summary-article-number)))
10098   (when (or (not (get-buffer gnus-article-buffer))
10099             (not gnus-current-article)
10100             (not gnus-article-current)
10101             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10102     (error "No current article selected"))
10103   ;; Remove old bookmark, if one exists.
10104   (gnus-pull article gnus-newsgroup-bookmarks)
10105   ;; Set the new bookmark, which is on the form
10106   ;; (article-number . line-number-in-body).
10107   (push
10108    (cons article
10109          (with-current-buffer gnus-article-buffer
10110            (count-lines
10111             (min (point)
10112                  (save-excursion
10113                    (article-goto-body)
10114                    (point)))
10115             (point))))
10116    gnus-newsgroup-bookmarks)
10117   (gnus-message 6 "A bookmark has been added to the current article."))
10118
10119 (defun gnus-summary-remove-bookmark (article)
10120   "Remove the bookmark from the current article."
10121   (interactive (list (gnus-summary-article-number)))
10122   ;; Remove old bookmark, if one exists.
10123   (if (not (assq article gnus-newsgroup-bookmarks))
10124       (gnus-message 6 "No bookmark in current article.")
10125     (gnus-pull article gnus-newsgroup-bookmarks)
10126     (gnus-message 6 "Removed bookmark.")))
10127
10128 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10129 (defun gnus-summary-mark-as-dormant (n)
10130   "Mark N articles forward as dormant.
10131 If N is negative, mark backward instead.  The difference between N and
10132 the actual number of articles marked is returned."
10133   (interactive "p")
10134   (gnus-summary-mark-forward n gnus-dormant-mark))
10135
10136 (defun gnus-summary-set-process-mark (article)
10137   "Set the process mark on ARTICLE and update the summary line."
10138   (setq gnus-newsgroup-processable
10139         (cons article
10140               (delq article gnus-newsgroup-processable)))
10141   (when (gnus-summary-goto-subject article)
10142     (gnus-summary-show-thread)
10143     (gnus-summary-goto-subject article)
10144     (gnus-summary-update-secondary-mark article)))
10145
10146 (defun gnus-summary-remove-process-mark (&rest articles)
10147   "Remove the process mark from ARTICLES and update the summary line."
10148   (dolist (article articles)
10149     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10150     (when (gnus-summary-goto-subject article)
10151       (gnus-summary-show-thread)
10152       (gnus-summary-goto-subject article)
10153       (gnus-summary-update-secondary-mark article)))
10154   t)
10155
10156 (defun gnus-summary-set-saved-mark (article)
10157   "Set the process mark on ARTICLE and update the summary line."
10158   (push article gnus-newsgroup-saved)
10159   (when (gnus-summary-goto-subject article)
10160     (gnus-summary-update-secondary-mark article)))
10161
10162 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10163   "Mark N articles as read forwards.
10164 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10165 The difference between N and the actual number of articles marked is
10166 returned.
10167 If NO-EXPIRE, auto-expiry will be inhibited."
10168   (interactive "p")
10169   (gnus-summary-show-thread)
10170   (let ((backward (< n 0))
10171         (gnus-summary-goto-unread
10172          (and gnus-summary-goto-unread
10173               (not (eq gnus-summary-goto-unread 'never))
10174               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10175                                     gnus-ticked-mark gnus-dormant-mark)))))
10176         (n (abs n))
10177         (mark (or mark gnus-del-mark)))
10178     (while (and (> n 0)
10179                 (gnus-summary-mark-article nil mark no-expire)
10180                 (zerop (gnus-summary-next-subject
10181                         (if backward -1 1)
10182                         (and gnus-summary-goto-unread
10183                              (not (eq gnus-summary-goto-unread 'never)))
10184                         t)))
10185       (setq n (1- n)))
10186     (when (/= 0 n)
10187       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10188     (gnus-summary-recenter)
10189     (gnus-summary-position-point)
10190     (gnus-set-mode-line 'summary)
10191     n))
10192
10193 (defun gnus-summary-mark-article-as-read (mark)
10194   "Mark the current article quickly as read with MARK."
10195   (let ((article (gnus-summary-article-number)))
10196     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10197     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10198     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10199     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10200     (push (cons article mark) gnus-newsgroup-reads)
10201     ;; Possibly remove from cache, if that is used.
10202     (when gnus-use-cache
10203       (gnus-cache-enter-remove-article article))
10204     ;; Allow the backend to change the mark.
10205     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10206     ;; Check for auto-expiry.
10207     (when (and gnus-newsgroup-auto-expire
10208                (memq mark gnus-auto-expirable-marks))
10209       (setq mark gnus-expirable-mark)
10210       ;; Let the backend know about the mark change.
10211       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10212       (push article gnus-newsgroup-expirable))
10213     ;; Set the mark in the buffer.
10214     (gnus-summary-update-mark mark 'unread)
10215     t))
10216
10217 (defun gnus-summary-mark-article-as-unread (mark)
10218   "Mark the current article quickly as unread with MARK."
10219   (let* ((article (gnus-summary-article-number))
10220          (old-mark (gnus-summary-article-mark article)))
10221     ;; Allow the backend to change the mark.
10222     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10223     (if (eq mark old-mark)
10224         t
10225       (if (<= article 0)
10226           (progn
10227             (gnus-error 1 "Can't mark negative article numbers")
10228             nil)
10229         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10230         (setq gnus-newsgroup-spam-marked
10231               (delq article gnus-newsgroup-spam-marked))
10232         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10233         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10234         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10235         (cond ((= mark gnus-ticked-mark)
10236                (setq gnus-newsgroup-marked
10237                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10238                                               article)))
10239               ((= mark gnus-spam-mark)
10240                (setq gnus-newsgroup-spam-marked
10241                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10242                                               article)))
10243               ((= mark gnus-dormant-mark)
10244                (setq gnus-newsgroup-dormant
10245                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10246                                               article)))
10247               (t
10248                (setq gnus-newsgroup-unreads
10249                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10250                                               article))))
10251         (gnus-pull article gnus-newsgroup-reads)
10252
10253         ;; See whether the article is to be put in the cache.
10254         (and gnus-use-cache
10255              (vectorp (gnus-summary-article-header article))
10256              (save-excursion
10257                (gnus-cache-possibly-enter-article
10258                 gnus-newsgroup-name article
10259                 (= mark gnus-ticked-mark)
10260                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10261
10262         ;; Fix the mark.
10263         (gnus-summary-update-mark mark 'unread)
10264         t))))
10265
10266 (defun gnus-summary-mark-article (&optional article mark no-expire)
10267   "Mark ARTICLE with MARK.  MARK can be any character.
10268 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10269 `??' (dormant) and `?E' (expirable).
10270 If MARK is nil, then the default character `?r' is used.
10271 If ARTICLE is nil, then the article on the current line will be
10272 marked.
10273 If NO-EXPIRE, auto-expiry will be inhibited."
10274   ;; The mark might be a string.
10275   (when (stringp mark)
10276     (setq mark (aref mark 0)))
10277   ;; If no mark is given, then we check auto-expiring.
10278   (when (null mark)
10279     (setq mark gnus-del-mark))
10280   (when (and (not no-expire)
10281              gnus-newsgroup-auto-expire
10282              (memq mark gnus-auto-expirable-marks))
10283     (setq mark gnus-expirable-mark))
10284   (let ((article (or article (gnus-summary-article-number)))
10285         (old-mark (gnus-summary-article-mark article)))
10286     ;; Allow the backend to change the mark.
10287     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10288     (if (eq mark old-mark)
10289         t
10290       (unless article
10291         (error "No article on current line"))
10292       (if (not (if (or (= mark gnus-unread-mark)
10293                        (= mark gnus-ticked-mark)
10294                        (= mark gnus-spam-mark)
10295                        (= mark gnus-dormant-mark))
10296                    (gnus-mark-article-as-unread article mark)
10297                  (gnus-mark-article-as-read article mark)))
10298           t
10299         ;; See whether the article is to be put in the cache.
10300         (and gnus-use-cache
10301              (not (= mark gnus-canceled-mark))
10302              (vectorp (gnus-summary-article-header article))
10303              (save-excursion
10304                (gnus-cache-possibly-enter-article
10305                 gnus-newsgroup-name article
10306                 (= mark gnus-ticked-mark)
10307                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10308
10309         (when (gnus-summary-goto-subject article nil t)
10310           (let ((buffer-read-only nil))
10311             (gnus-summary-show-thread)
10312             ;; Fix the mark.
10313             (gnus-summary-update-mark mark 'unread)
10314             t))))))
10315
10316 (defun gnus-summary-update-secondary-mark (article)
10317   "Update the secondary (read, process, cache) mark."
10318   (gnus-summary-update-mark
10319    (cond ((memq article gnus-newsgroup-processable)
10320           gnus-process-mark)
10321          ((memq article gnus-newsgroup-cached)
10322           gnus-cached-mark)
10323          ((memq article gnus-newsgroup-replied)
10324           gnus-replied-mark)
10325          ((memq article gnus-newsgroup-forwarded)
10326           gnus-forwarded-mark)
10327          ((memq article gnus-newsgroup-saved)
10328           gnus-saved-mark)
10329          ((memq article gnus-newsgroup-recent)
10330           gnus-recent-mark)
10331          ((memq article gnus-newsgroup-unseen)
10332           gnus-unseen-mark)
10333          (t gnus-no-mark))
10334    'replied)
10335   (when (gnus-visual-p 'summary-highlight 'highlight)
10336     (gnus-run-hooks 'gnus-summary-update-hook))
10337   t)
10338
10339 (defun gnus-summary-update-download-mark (article)
10340   "Update the download mark."
10341   (gnus-summary-update-mark
10342    (cond ((memq article gnus-newsgroup-undownloaded)
10343           gnus-undownloaded-mark)
10344          (gnus-newsgroup-agentized
10345           gnus-downloaded-mark)
10346          (t
10347           gnus-no-mark))
10348    'download)
10349   (gnus-summary-update-line t)
10350   t)
10351
10352 (defun gnus-summary-update-mark (mark type)
10353   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10354         (buffer-read-only nil))
10355     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10356     (when forward
10357       (when (looking-at "\r")
10358         (incf forward))
10359       (when (<= (+ forward (point)) (point-max))
10360         ;; Go to the right position on the line.
10361         (goto-char (+ forward (point)))
10362         ;; Replace the old mark with the new mark.
10363         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10364         ;; Optionally update the marks by some user rule.
10365         (when (eq type 'unread)
10366           (gnus-data-set-mark
10367            (gnus-data-find (gnus-summary-article-number)) mark)
10368           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10369
10370 (defun gnus-mark-article-as-read (article &optional mark)
10371   "Enter ARTICLE in the pertinent lists and remove it from others."
10372   ;; Make the article expirable.
10373   (let ((mark (or mark gnus-del-mark)))
10374     (setq gnus-newsgroup-expirable
10375           (if (= mark gnus-expirable-mark)
10376               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10377             (delq article gnus-newsgroup-expirable)))
10378     ;; Remove from unread and marked lists.
10379     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10380     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10381     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10382     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10383     (push (cons article mark) gnus-newsgroup-reads)
10384     ;; Possibly remove from cache, if that is used.
10385     (when gnus-use-cache
10386       (gnus-cache-enter-remove-article article))
10387     t))
10388
10389 (defun gnus-mark-article-as-unread (article &optional mark)
10390   "Enter ARTICLE in the pertinent lists and remove it from others."
10391   (let ((mark (or mark gnus-ticked-mark)))
10392     (if (<= article 0)
10393         (progn
10394           (gnus-error 1 "Can't mark negative article numbers")
10395           nil)
10396       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10397             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10398             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10399             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10400             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10401
10402       ;; Unsuppress duplicates?
10403       (when gnus-suppress-duplicates
10404         (gnus-dup-unsuppress-article article))
10405
10406       (cond ((= mark gnus-ticked-mark)
10407              (setq gnus-newsgroup-marked
10408                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10409             ((= mark gnus-spam-mark)
10410              (setq gnus-newsgroup-spam-marked
10411                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10412                                             article)))
10413             ((= mark gnus-dormant-mark)
10414              (setq gnus-newsgroup-dormant
10415                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10416             (t
10417              (setq gnus-newsgroup-unreads
10418                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10419       (gnus-pull article gnus-newsgroup-reads)
10420       t)))
10421
10422 (defalias 'gnus-summary-mark-as-unread-forward
10423   'gnus-summary-tick-article-forward)
10424 (make-obsolete 'gnus-summary-mark-as-unread-forward
10425                'gnus-summary-tick-article-forward)
10426 (defun gnus-summary-tick-article-forward (n)
10427   "Tick N articles forwards.
10428 If N is negative, tick backwards instead.
10429 The difference between N and the number of articles ticked is returned."
10430   (interactive "p")
10431   (gnus-summary-mark-forward n gnus-ticked-mark))
10432
10433 (defalias 'gnus-summary-mark-as-unread-backward
10434   'gnus-summary-tick-article-backward)
10435 (make-obsolete 'gnus-summary-mark-as-unread-backward
10436                'gnus-summary-tick-article-backward)
10437 (defun gnus-summary-tick-article-backward (n)
10438   "Tick N articles backwards.
10439 The difference between N and the number of articles ticked is returned."
10440   (interactive "p")
10441   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10442
10443 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10444 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10445 (defun gnus-summary-tick-article (&optional article clear-mark)
10446   "Mark current article as unread.
10447 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10448 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10449   (interactive)
10450   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10451                                        gnus-ticked-mark)))
10452
10453 (defun gnus-summary-mark-as-read-forward (n)
10454   "Mark N articles as read forwards.
10455 If N is negative, mark backwards instead.
10456 The difference between N and the actual number of articles marked is
10457 returned."
10458   (interactive "p")
10459   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10460
10461 (defun gnus-summary-mark-as-read-backward (n)
10462   "Mark the N articles as read backwards.
10463 The difference between N and the actual number of articles marked is
10464 returned."
10465   (interactive "p")
10466   (gnus-summary-mark-forward
10467    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10468
10469 (defun gnus-summary-mark-as-read (&optional article mark)
10470   "Mark current article as read.
10471 ARTICLE specifies the article to be marked as read.
10472 MARK specifies a string to be inserted at the beginning of the line."
10473   (gnus-summary-mark-article article mark))
10474
10475 (defun gnus-summary-clear-mark-forward (n)
10476   "Clear marks from N articles forward.
10477 If N is negative, clear backward instead.
10478 The difference between N and the number of marks cleared is returned."
10479   (interactive "p")
10480   (gnus-summary-mark-forward n gnus-unread-mark))
10481
10482 (defun gnus-summary-clear-mark-backward (n)
10483   "Clear marks from N articles backward.
10484 The difference between N and the number of marks cleared is returned."
10485   (interactive "p")
10486   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10487
10488 (defun gnus-summary-mark-unread-as-read ()
10489   "Intended to be used by `gnus-summary-mark-article-hook'."
10490   (when (memq gnus-current-article gnus-newsgroup-unreads)
10491     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10492
10493 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10494   "Intended to be used by `gnus-summary-mark-article-hook'."
10495   (let ((mark (gnus-summary-article-mark)))
10496     (when (or (gnus-unread-mark-p mark)
10497               (gnus-read-mark-p mark))
10498       (gnus-summary-mark-article gnus-current-article
10499                                  (or new-mark gnus-read-mark)))))
10500
10501 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10502   "Intended to be used by `gnus-summary-mark-article-hook'."
10503   (let ((mark (gnus-summary-article-mark)))
10504     (when (or (gnus-unread-mark-p mark)
10505               (gnus-read-mark-p mark))
10506       (gnus-summary-mark-article (gnus-summary-article-number)
10507                                  (or new-mark gnus-read-mark)))))
10508
10509 (defun gnus-summary-mark-unread-as-ticked ()
10510   "Intended to be used by `gnus-summary-mark-article-hook'."
10511   (when (memq gnus-current-article gnus-newsgroup-unreads)
10512     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10513
10514 (defun gnus-summary-mark-region-as-read (point mark all)
10515   "Mark all unread articles between point and mark as read.
10516 If given a prefix, mark all articles between point and mark as read,
10517 even ticked and dormant ones."
10518   (interactive "r\nP")
10519   (save-excursion
10520     (let (article)
10521       (goto-char point)
10522       (beginning-of-line)
10523       (while (and
10524               (< (point) mark)
10525               (progn
10526                 (when (or all
10527                           (memq (setq article (gnus-summary-article-number))
10528                                 gnus-newsgroup-unreads))
10529                   (gnus-summary-mark-article article gnus-del-mark))
10530                 t)
10531               (gnus-summary-find-next))))))
10532
10533 (defun gnus-summary-mark-below (score mark)
10534   "Mark articles with score less than SCORE with MARK."
10535   (interactive "P\ncMark: ")
10536   (setq score (if score
10537                   (prefix-numeric-value score)
10538                 (or gnus-summary-default-score 0)))
10539   (save-excursion
10540     (set-buffer gnus-summary-buffer)
10541     (goto-char (point-min))
10542     (while
10543         (progn
10544           (and (< (gnus-summary-article-score) score)
10545                (gnus-summary-mark-article nil mark))
10546           (gnus-summary-find-next)))))
10547
10548 (defun gnus-summary-kill-below (&optional score)
10549   "Mark articles with score below SCORE as read."
10550   (interactive "P")
10551   (gnus-summary-mark-below score gnus-killed-mark))
10552
10553 (defun gnus-summary-clear-above (&optional score)
10554   "Clear all marks from articles with score above SCORE."
10555   (interactive "P")
10556   (gnus-summary-mark-above score gnus-unread-mark))
10557
10558 (defun gnus-summary-tick-above (&optional score)
10559   "Tick all articles with score above SCORE."
10560   (interactive "P")
10561   (gnus-summary-mark-above score gnus-ticked-mark))
10562
10563 (defun gnus-summary-mark-above (score mark)
10564   "Mark articles with score over SCORE with MARK."
10565   (interactive "P\ncMark: ")
10566   (setq score (if score
10567                   (prefix-numeric-value score)
10568                 (or gnus-summary-default-score 0)))
10569   (save-excursion
10570     (set-buffer gnus-summary-buffer)
10571     (goto-char (point-min))
10572     (while (and (progn
10573                   (when (> (gnus-summary-article-score) score)
10574                     (gnus-summary-mark-article nil mark))
10575                   t)
10576                 (gnus-summary-find-next)))))
10577
10578 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10579 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10580 (defun gnus-summary-limit-include-expunged (&optional no-error)
10581   "Display all the hidden articles that were expunged for low scores."
10582   (interactive)
10583   (let ((buffer-read-only nil))
10584     (let ((scored gnus-newsgroup-scored)
10585           headers h)
10586       (while scored
10587         (unless (gnus-summary-article-header (caar scored))
10588           (and (setq h (gnus-number-to-header (caar scored)))
10589                (< (cdar scored) gnus-summary-expunge-below)
10590                (push h headers)))
10591         (setq scored (cdr scored)))
10592       (if (not headers)
10593           (when (not no-error)
10594             (error "No expunged articles hidden"))
10595         (goto-char (point-min))
10596         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10597         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10598         (mapcar (lambda (x) (push (mail-header-number x)
10599                                   gnus-newsgroup-limit))
10600                 headers)
10601         (gnus-summary-prepare-unthreaded (nreverse headers))
10602         (goto-char (point-min))
10603         (gnus-summary-position-point)
10604         t))))
10605
10606 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10607   "Mark all unread articles in this newsgroup as read.
10608 If prefix argument ALL is non-nil, ticked and dormant articles will
10609 also be marked as read.
10610 If QUIETLY is non-nil, no questions will be asked.
10611
10612 If TO-HERE is non-nil, it should be a point in the buffer.  All
10613 articles before (after, if REVERSE is set) this point will be marked
10614 as read.
10615
10616 Note that this function will only catch up the unread article
10617 in the current summary buffer limitation.
10618
10619 The number of articles marked as read is returned."
10620   (interactive "P")
10621   (prog1
10622       (save-excursion
10623         (when (or quietly
10624                   (not gnus-interactive-catchup) ;Without confirmation?
10625                   gnus-expert-user
10626                   (gnus-y-or-n-p
10627                    (if all
10628                        "Mark absolutely all articles as read? "
10629                      "Mark all unread articles as read? ")))
10630           (if (and not-mark
10631                    (not gnus-newsgroup-adaptive)
10632                    (not gnus-newsgroup-auto-expire)
10633                    (not gnus-suppress-duplicates)
10634                    (or (not gnus-use-cache)
10635                        (eq gnus-use-cache 'passive)))
10636               (progn
10637                 (when all
10638                   (setq gnus-newsgroup-marked nil
10639                         gnus-newsgroup-spam-marked nil
10640                         gnus-newsgroup-dormant nil))
10641                 (setq gnus-newsgroup-unreads
10642                       (gnus-sorted-nunion
10643                        (gnus-intersection gnus-newsgroup-unreads
10644                                           gnus-newsgroup-downloadable)
10645                        gnus-newsgroup-unfetched)))
10646             ;; We actually mark all articles as canceled, which we
10647             ;; have to do when using auto-expiry or adaptive scoring.
10648             (gnus-summary-show-all-threads)
10649             (if (and to-here reverse)
10650                 (progn
10651                   (goto-char to-here)
10652                   (gnus-summary-mark-current-read-and-unread-as-read
10653                    gnus-catchup-mark)
10654                   (while (gnus-summary-find-next (not all))
10655                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10656               (when (gnus-summary-first-subject (not all))
10657                 (while (and
10658                         (if to-here (< (point) to-here) t)
10659                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10660                         (gnus-summary-find-next (not all))))))
10661             (gnus-set-mode-line 'summary))
10662           t))
10663     (gnus-summary-position-point)))
10664
10665 (defun gnus-summary-catchup-to-here (&optional all)
10666   "Mark all unticked articles before the current one as read.
10667 If ALL is non-nil, also mark ticked and dormant articles as read."
10668   (interactive "P")
10669   (save-excursion
10670     (gnus-save-hidden-threads
10671       (let ((beg (point)))
10672         ;; We check that there are unread articles.
10673         (when (or all (gnus-summary-find-prev))
10674           (gnus-summary-catchup all t beg)))))
10675   (gnus-summary-position-point))
10676
10677 (defun gnus-summary-catchup-from-here (&optional all)
10678   "Mark all unticked articles after (and including) the current one as read.
10679 If ALL is non-nil, also mark ticked and dormant articles as read."
10680   (interactive "P")
10681   (save-excursion
10682     (gnus-save-hidden-threads
10683       (let ((beg (point)))
10684         ;; We check that there are unread articles.
10685         (when (or all (gnus-summary-find-next))
10686           (gnus-summary-catchup all t beg nil t)))))
10687   (gnus-summary-position-point))
10688
10689 (defun gnus-summary-catchup-all (&optional quietly)
10690   "Mark all articles in this newsgroup as read.
10691 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10692 instead, which marks only unread articles as read."
10693   (interactive "P")
10694   (gnus-summary-catchup t quietly))
10695
10696 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10697   "Mark all unread articles in this group as read, then exit.
10698 If prefix argument ALL is non-nil, all articles are marked as read.
10699 If QUIETLY is non-nil, no questions will be asked."
10700   (interactive "P")
10701   (when (gnus-summary-catchup all quietly nil 'fast)
10702     ;; Select next newsgroup or exit.
10703     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10704              (eq gnus-auto-select-next 'quietly))
10705         (gnus-summary-next-group nil)
10706       (gnus-summary-exit))))
10707
10708 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10709   "Mark all articles in this newsgroup as read, and then exit.
10710 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10711 instead, which marks only unread articles as read."
10712   (interactive "P")
10713   (gnus-summary-catchup-and-exit t quietly))
10714
10715 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10716   "Mark all articles in this group as read and select the next group.
10717 If given a prefix, mark all articles, unread as well as ticked, as
10718 read."
10719   (interactive "P")
10720   (save-excursion
10721     (gnus-summary-catchup all))
10722   (gnus-summary-next-group))
10723
10724 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10725   "Mark all articles in this group as read and select the previous group.
10726 If given a prefix, mark all articles, unread as well as ticked, as
10727 read."
10728   (interactive "P")
10729   (save-excursion
10730     (gnus-summary-catchup all))
10731   (gnus-summary-next-group nil nil t))
10732
10733 ;;;
10734 ;;; with article
10735 ;;;
10736
10737 (defmacro gnus-with-article (article &rest forms)
10738   "Select ARTICLE and perform FORMS in the original article buffer.
10739 Then replace the article with the result."
10740   `(progn
10741      ;; We don't want the article to be marked as read.
10742      (let (gnus-mark-article-hook)
10743        (gnus-summary-select-article t t nil ,article))
10744      (set-buffer gnus-original-article-buffer)
10745      ,@forms
10746      (if (not (gnus-check-backend-function
10747                'request-replace-article (car gnus-article-current)))
10748          (gnus-message 5 "Read-only group; not replacing")
10749        (unless (gnus-request-replace-article
10750                 ,article (car gnus-article-current)
10751                 (current-buffer) t)
10752          (error "Couldn't replace article")))
10753      ;; The cache and backlog have to be flushed somewhat.
10754      (when gnus-keep-backlog
10755        (gnus-backlog-remove-article
10756         (car gnus-article-current) (cdr gnus-article-current)))
10757      (when gnus-use-cache
10758        (gnus-cache-update-article
10759         (car gnus-article-current) (cdr gnus-article-current)))))
10760
10761 (put 'gnus-with-article 'lisp-indent-function 1)
10762 (put 'gnus-with-article 'edebug-form-spec '(form body))
10763
10764 ;; Thread-based commands.
10765
10766 (defun gnus-summary-articles-in-thread (&optional article)
10767   "Return a list of all articles in the current thread.
10768 If ARTICLE is non-nil, return all articles in the thread that starts
10769 with that article."
10770   (let* ((article (or article (gnus-summary-article-number)))
10771          (data (gnus-data-find-list article))
10772          (top-level (gnus-data-level (car data)))
10773          (top-subject
10774           (cond ((null gnus-thread-operation-ignore-subject)
10775                  (gnus-simplify-subject-re
10776                   (mail-header-subject (gnus-data-header (car data)))))
10777                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10778                  (gnus-simplify-subject-fuzzy
10779                   (mail-header-subject (gnus-data-header (car data)))))
10780                 (t nil)))
10781          (end-point (save-excursion
10782                       (if (gnus-summary-go-to-next-thread)
10783                           (point) (point-max))))
10784          articles)
10785     (while (and data
10786                 (< (gnus-data-pos (car data)) end-point))
10787       (when (or (not top-subject)
10788                 (string= top-subject
10789                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10790                              (gnus-simplify-subject-fuzzy
10791                               (mail-header-subject
10792                                (gnus-data-header (car data))))
10793                            (gnus-simplify-subject-re
10794                             (mail-header-subject
10795                              (gnus-data-header (car data)))))))
10796         (push (gnus-data-number (car data)) articles))
10797       (unless (and (setq data (cdr data))
10798                    (> (gnus-data-level (car data)) top-level))
10799         (setq data nil)))
10800     ;; Return the list of articles.
10801     (nreverse articles)))
10802
10803 (defun gnus-summary-rethread-current ()
10804   "Rethread the thread the current article is part of."
10805   (interactive)
10806   (let* ((gnus-show-threads t)
10807          (article (gnus-summary-article-number))
10808          (id (mail-header-id (gnus-summary-article-header)))
10809          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10810     (unless id
10811       (error "No article on the current line"))
10812     (gnus-rebuild-thread id)
10813     (gnus-summary-goto-subject article)))
10814
10815 (defun gnus-summary-reparent-thread ()
10816   "Make the current article child of the marked (or previous) article.
10817
10818 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10819 is non-nil or the Subject: of both articles are the same."
10820   (interactive)
10821   (unless (not (gnus-group-read-only-p))
10822     (error "The current newsgroup does not support article editing"))
10823   (unless (<= (length gnus-newsgroup-processable) 1)
10824     (error "No more than one article may be marked"))
10825   (save-window-excursion
10826     (let ((gnus-article-buffer " *reparent*")
10827           (current-article (gnus-summary-article-number))
10828           ;; First grab the marked article, otherwise one line up.
10829           (parent-article (if (not (null gnus-newsgroup-processable))
10830                               (car gnus-newsgroup-processable)
10831                             (save-excursion
10832                               (if (eq (forward-line -1) 0)
10833                                   (gnus-summary-article-number)
10834                                 (error "Beginning of summary buffer"))))))
10835       (unless (not (eq current-article parent-article))
10836         (error "An article may not be self-referential"))
10837       (let ((message-id (mail-header-id
10838                          (gnus-summary-article-header parent-article))))
10839         (unless (and message-id (not (equal message-id "")))
10840           (error "No message-id in desired parent"))
10841         (gnus-with-article current-article
10842           (save-restriction
10843             (goto-char (point-min))
10844             (message-narrow-to-head)
10845             (if (re-search-forward "^References: " nil t)
10846                 (progn
10847                   (re-search-forward "^[^ \t]" nil t)
10848                   (forward-line -1)
10849                   (end-of-line)
10850                   (insert " " message-id))
10851               (insert "References: " message-id "\n"))))
10852         (set-buffer gnus-summary-buffer)
10853         (gnus-summary-unmark-all-processable)
10854         (gnus-summary-update-article current-article)
10855         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10856             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10857         (gnus-summary-rethread-current)
10858         (gnus-message 3 "Article %d is now the child of article %d"
10859                       current-article parent-article)))))
10860
10861 (defun gnus-summary-toggle-threads (&optional arg)
10862   "Toggle showing conversation threads.
10863 If ARG is positive number, turn showing conversation threads on."
10864   (interactive "P")
10865   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10866     (setq gnus-show-threads
10867           (if (null arg) (not gnus-show-threads)
10868             (> (prefix-numeric-value arg) 0)))
10869     (gnus-summary-prepare)
10870     (gnus-summary-goto-subject current)
10871     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10872     (gnus-summary-position-point)))
10873
10874 (defun gnus-summary-show-all-threads ()
10875   "Show all threads."
10876   (interactive)
10877   (save-excursion
10878     (let ((buffer-read-only nil))
10879       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10880   (gnus-summary-position-point))
10881
10882 (defun gnus-summary-show-thread ()
10883   "Show thread subtrees.
10884 Returns nil if no thread was there to be shown."
10885   (interactive)
10886   (let ((buffer-read-only nil)
10887         (orig (point))
10888         (end (point-at-eol))
10889         ;; Leave point at bol
10890         (beg (progn (beginning-of-line) (point))))
10891     (prog1
10892         ;; Any hidden lines here?
10893         (search-forward "\r" end t)
10894       (subst-char-in-region beg end ?\^M ?\n t)
10895       (goto-char orig)
10896       (gnus-summary-position-point))))
10897
10898 (defun gnus-summary-maybe-hide-threads ()
10899   "If requested, hide the threads that should be hidden."
10900   (when (and gnus-show-threads
10901              gnus-thread-hide-subtree)
10902     (gnus-summary-hide-all-threads
10903      (if (or (consp gnus-thread-hide-subtree)
10904              (functionp gnus-thread-hide-subtree))
10905          (gnus-make-predicate gnus-thread-hide-subtree)
10906        nil))))
10907
10908 ;;; Hiding predicates.
10909
10910 (defun gnus-article-unread-p (header)
10911   (memq (mail-header-number header) gnus-newsgroup-unreads))
10912
10913 (defun gnus-article-unseen-p (header)
10914   (memq (mail-header-number header) gnus-newsgroup-unseen))
10915
10916 (defun gnus-map-articles (predicate articles)
10917   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10918   (apply 'gnus-or (mapcar predicate
10919                           (mapcar (lambda (number)
10920                                     (gnus-summary-article-header number))
10921                                   articles))))
10922
10923 (defun gnus-summary-hide-all-threads (&optional predicate)
10924   "Hide all thread subtrees.
10925 If PREDICATE is supplied, threads that satisfy this predicate
10926 will not be hidden."
10927   (interactive)
10928   (save-excursion
10929     (goto-char (point-min))
10930     (let ((end nil))
10931       (while (not end)
10932         (when (or (not predicate)
10933                   (gnus-map-articles
10934                    predicate (gnus-summary-article-children)))
10935             (gnus-summary-hide-thread))
10936         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10937   (gnus-summary-position-point))
10938
10939 (defun gnus-summary-hide-thread ()
10940   "Hide thread subtrees.
10941 If PREDICATE is supplied, threads that satisfy this predicate
10942 will not be hidden.
10943 Returns nil if no threads were there to be hidden."
10944   (interactive)
10945   (let ((buffer-read-only nil)
10946         (start (point))
10947         (article (gnus-summary-article-number)))
10948     (goto-char start)
10949     ;; Go forward until either the buffer ends or the subthread
10950     ;; ends.
10951     (when (and (not (eobp))
10952                (or (zerop (gnus-summary-next-thread 1 t))
10953                    (goto-char (point-max))))
10954       (prog1
10955           (if (and (> (point) start)
10956                    (search-backward "\n" start t))
10957               (progn
10958                 (subst-char-in-region start (point) ?\n ?\^M)
10959                 (gnus-summary-goto-subject article))
10960             (goto-char start)
10961             nil)))))
10962
10963 (defun gnus-summary-go-to-next-thread (&optional previous)
10964   "Go to the same level (or less) next thread.
10965 If PREVIOUS is non-nil, go to previous thread instead.
10966 Return the article number moved to, or nil if moving was impossible."
10967   (let ((level (gnus-summary-thread-level))
10968         (way (if previous -1 1))
10969         (beg (point)))
10970     (forward-line way)
10971     (while (and (not (eobp))
10972                 (< level (gnus-summary-thread-level)))
10973       (forward-line way))
10974     (if (eobp)
10975         (progn
10976           (goto-char beg)
10977           nil)
10978       (setq beg (point))
10979       (prog1
10980           (gnus-summary-article-number)
10981         (goto-char beg)))))
10982
10983 (defun gnus-summary-next-thread (n &optional silent)
10984   "Go to the same level next N'th thread.
10985 If N is negative, search backward instead.
10986 Returns the difference between N and the number of skips actually
10987 done.
10988
10989 If SILENT, don't output messages."
10990   (interactive "p")
10991   (let ((backward (< n 0))
10992         (n (abs n)))
10993     (while (and (> n 0)
10994                 (gnus-summary-go-to-next-thread backward))
10995       (decf n))
10996     (unless silent
10997       (gnus-summary-position-point))
10998     (when (and (not silent) (/= 0 n))
10999       (gnus-message 7 "No more threads"))
11000     n))
11001
11002 (defun gnus-summary-prev-thread (n)
11003   "Go to the same level previous N'th thread.
11004 Returns the difference between N and the number of skips actually
11005 done."
11006   (interactive "p")
11007   (gnus-summary-next-thread (- n)))
11008
11009 (defun gnus-summary-go-down-thread ()
11010   "Go down one level in the current thread."
11011   (let ((children (gnus-summary-article-children)))
11012     (when children
11013       (gnus-summary-goto-subject (car children)))))
11014
11015 (defun gnus-summary-go-up-thread ()
11016   "Go up one level in the current thread."
11017   (let ((parent (gnus-summary-article-parent)))
11018     (when parent
11019       (gnus-summary-goto-subject parent))))
11020
11021 (defun gnus-summary-down-thread (n)
11022   "Go down thread N steps.
11023 If N is negative, go up instead.
11024 Returns the difference between N and how many steps down that were
11025 taken."
11026   (interactive "p")
11027   (let ((up (< n 0))
11028         (n (abs n)))
11029     (while (and (> n 0)
11030                 (if up (gnus-summary-go-up-thread)
11031                   (gnus-summary-go-down-thread)))
11032       (setq n (1- n)))
11033     (gnus-summary-position-point)
11034     (when (/= 0 n)
11035       (gnus-message 7 "Can't go further"))
11036     n))
11037
11038 (defun gnus-summary-up-thread (n)
11039   "Go up thread N steps.
11040 If N is negative, go down instead.
11041 Returns the difference between N and how many steps down that were
11042 taken."
11043   (interactive "p")
11044   (gnus-summary-down-thread (- n)))
11045
11046 (defun gnus-summary-top-thread ()
11047   "Go to the top of the thread."
11048   (interactive)
11049   (while (gnus-summary-go-up-thread))
11050   (gnus-summary-article-number))
11051
11052 (defun gnus-summary-kill-thread (&optional unmark)
11053   "Mark articles under current thread as read.
11054 If the prefix argument is positive, remove any kinds of marks.
11055 If the prefix argument is negative, tick articles instead."
11056   (interactive "P")
11057   (when unmark
11058     (setq unmark (prefix-numeric-value unmark)))
11059   (let ((articles (gnus-summary-articles-in-thread)))
11060     (save-excursion
11061       ;; Expand the thread.
11062       (gnus-summary-show-thread)
11063       ;; Mark all the articles.
11064       (while articles
11065         (gnus-summary-goto-subject (car articles))
11066         (cond ((null unmark)
11067                (gnus-summary-mark-article-as-read gnus-killed-mark))
11068               ((> unmark 0)
11069                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11070               (t
11071                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11072         (setq articles (cdr articles))))
11073     ;; Hide killed subtrees.
11074     (and (null unmark)
11075          gnus-thread-hide-killed
11076          (gnus-summary-hide-thread))
11077     ;; If marked as read, go to next unread subject.
11078     (when (null unmark)
11079       ;; Go to next unread subject.
11080       (gnus-summary-next-subject 1 t)))
11081   (gnus-set-mode-line 'summary))
11082
11083 ;; Summary sorting commands
11084
11085 (defun gnus-summary-sort-by-number (&optional reverse)
11086   "Sort the summary buffer by article number.
11087 Argument REVERSE means reverse order."
11088   (interactive "P")
11089   (gnus-summary-sort 'number reverse))
11090
11091 (defun gnus-summary-sort-by-random (&optional reverse)
11092   "Randomize the order in the summary buffer.
11093 Argument REVERSE means to randomize in reverse order."
11094   (interactive "P")
11095   (gnus-summary-sort 'random reverse))
11096
11097 (defun gnus-summary-sort-by-author (&optional reverse)
11098   "Sort the summary buffer by author name alphabetically.
11099 If `case-fold-search' is non-nil, case of letters is ignored.
11100 Argument REVERSE means reverse order."
11101   (interactive "P")
11102   (gnus-summary-sort 'author reverse))
11103
11104 (defun gnus-summary-sort-by-recipient (&optional reverse)
11105   "Sort the summary buffer by recipient name alphabetically.
11106 If `case-fold-search' is non-nil, case of letters is ignored.
11107 Argument REVERSE means reverse order."
11108   (interactive "P")
11109   (gnus-summary-sort 'recipient reverse))
11110
11111 (defun gnus-summary-sort-by-subject (&optional reverse)
11112   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11113 If `case-fold-search' is non-nil, case of letters is ignored.
11114 Argument REVERSE means reverse order."
11115   (interactive "P")
11116   (gnus-summary-sort 'subject reverse))
11117
11118 (defun gnus-summary-sort-by-date (&optional reverse)
11119   "Sort the summary buffer by date.
11120 Argument REVERSE means reverse order."
11121   (interactive "P")
11122   (gnus-summary-sort 'date reverse))
11123
11124 (defun gnus-summary-sort-by-score (&optional reverse)
11125   "Sort the summary buffer by score.
11126 Argument REVERSE means reverse order."
11127   (interactive "P")
11128   (gnus-summary-sort 'score reverse))
11129
11130 (defun gnus-summary-sort-by-lines (&optional reverse)
11131   "Sort the summary buffer by the number of lines.
11132 Argument REVERSE means reverse order."
11133   (interactive "P")
11134   (gnus-summary-sort 'lines reverse))
11135
11136 (defun gnus-summary-sort-by-chars (&optional reverse)
11137   "Sort the summary buffer by article length.
11138 Argument REVERSE means reverse order."
11139   (interactive "P")
11140   (gnus-summary-sort 'chars reverse))
11141
11142 (defun gnus-summary-sort-by-original (&optional reverse)
11143   "Sort the summary buffer using the default sorting method.
11144 Argument REVERSE means reverse order."
11145   (interactive "P")
11146   (let* ((buffer-read-only)
11147          (gnus-summary-prepare-hook nil))
11148     ;; We do the sorting by regenerating the threads.
11149     (gnus-summary-prepare)
11150     ;; Hide subthreads if needed.
11151     (gnus-summary-maybe-hide-threads)))
11152
11153 (defun gnus-summary-sort (predicate reverse)
11154   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11155   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11156          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11157          (gnus-thread-sort-functions
11158           (if (not reverse)
11159               thread
11160             `(lambda (t1 t2)
11161                (,thread t2 t1))))
11162          (gnus-sort-gathered-threads-function
11163           gnus-thread-sort-functions)
11164          (gnus-article-sort-functions
11165           (if (not reverse)
11166               article
11167             `(lambda (t1 t2)
11168                (,article t2 t1))))
11169          (buffer-read-only)
11170          (gnus-summary-prepare-hook nil))
11171     ;; We do the sorting by regenerating the threads.
11172     (gnus-summary-prepare)
11173     ;; Hide subthreads if needed.
11174     (gnus-summary-maybe-hide-threads)))
11175
11176 ;; Summary saving commands.
11177
11178 (defun gnus-summary-save-article (&optional n not-saved)
11179   "Save the current article using the default saver function.
11180 If N is a positive number, save the N next articles.
11181 If N is a negative number, save the N previous articles.
11182 If N is nil and any articles have been marked with the process mark,
11183 save those articles instead.
11184 The variable `gnus-default-article-saver' specifies the saver function."
11185   (interactive "P")
11186   (let* ((articles (gnus-summary-work-articles n))
11187          (save-buffer (save-excursion
11188                         (nnheader-set-temp-buffer " *Gnus Save*")))
11189          (num (length articles))
11190          header file)
11191     (dolist (article articles)
11192       (setq header (gnus-summary-article-header article))
11193       (if (not (vectorp header))
11194           ;; This is a pseudo-article.
11195           (if (assq 'name header)
11196               (gnus-copy-file (cdr (assq 'name header)))
11197             (gnus-message 1 "Article %d is unsaveable" article))
11198         ;; This is a real article.
11199         (save-window-excursion
11200           (let ((gnus-display-mime-function nil)
11201                 (gnus-article-prepare-hook nil))
11202             (gnus-summary-select-article t nil nil article)))
11203         (save-excursion
11204           (set-buffer save-buffer)
11205           (erase-buffer)
11206           (insert-buffer-substring gnus-original-article-buffer))
11207         (setq file (gnus-article-save save-buffer file num))
11208         (gnus-summary-remove-process-mark article)
11209         (unless not-saved
11210           (gnus-summary-set-saved-mark article))))
11211     (gnus-kill-buffer save-buffer)
11212     (gnus-summary-position-point)
11213     (gnus-set-mode-line 'summary)
11214     n))
11215
11216 (defun gnus-summary-pipe-output (&optional arg headers)
11217   "Pipe the current article to a subprocess.
11218 If N is a positive number, pipe the N next articles.
11219 If N is a negative number, pipe the N previous articles.
11220 If N is nil and any articles have been marked with the process mark,
11221 pipe those articles instead.
11222 If HEADERS (the symbolic prefix), include the headers, too."
11223   (interactive (gnus-interactive "P\ny"))
11224   (require 'gnus-art)
11225   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11226         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11227     (gnus-summary-save-article arg t))
11228   (let ((buffer (get-buffer "*Shell Command Output*")))
11229     (when (and buffer
11230                (not (zerop (buffer-size buffer))))
11231       (gnus-configure-windows 'pipe))))
11232
11233 (defun gnus-summary-save-article-mail (&optional arg)
11234   "Append the current article to an mail 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-mail))
11242     (gnus-summary-save-article arg)))
11243
11244 (defun gnus-summary-save-article-rmail (&optional arg)
11245   "Append the current article to an rmail 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-save-in-rmail))
11253     (gnus-summary-save-article arg)))
11254
11255 (defun gnus-summary-save-article-file (&optional arg)
11256   "Append the current article 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-in-file))
11264     (gnus-summary-save-article arg)))
11265
11266 (defun gnus-summary-write-article-file (&optional arg)
11267   "Write the current article to a file, deleting the previous file.
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-write-to-file))
11275     (gnus-summary-save-article arg)))
11276
11277 (defun gnus-summary-save-article-body-file (&optional arg)
11278   "Append the current article body to a file.
11279 If N is a positive number, save the N next articles.
11280 If N is a negative number, save the N previous articles.
11281 If N is nil and any articles have been marked with the process mark,
11282 save those articles instead."
11283   (interactive "P")
11284   (require 'gnus-art)
11285   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11286     (gnus-summary-save-article arg)))
11287
11288 (defun gnus-summary-muttprint (&optional arg)
11289   "Print the current article using Muttprint.
11290 If N is a positive number, save the N next articles.
11291 If N is a negative number, save the N previous articles.
11292 If N is nil and any articles have been marked with the process mark,
11293 save those articles instead."
11294   (interactive "P")
11295   (require 'gnus-art)
11296   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11297     (gnus-summary-save-article arg t)))
11298
11299 (defun gnus-summary-pipe-message (program)
11300   "Pipe the current article through PROGRAM."
11301   (interactive "sProgram: ")
11302   (gnus-summary-select-article)
11303   (let ((mail-header-separator ""))
11304     (gnus-eval-in-buffer-window gnus-article-buffer
11305       (save-restriction
11306         (widen)
11307         (let ((start (window-start))
11308               buffer-read-only)
11309           (message-pipe-buffer-body program)
11310           (set-window-start (get-buffer-window (current-buffer)) start))))))
11311
11312 (defun gnus-get-split-value (methods)
11313   "Return a value based on the split METHODS."
11314   (let (split-name method result match)
11315     (when methods
11316       (save-excursion
11317         (set-buffer gnus-original-article-buffer)
11318         (save-restriction
11319           (nnheader-narrow-to-headers)
11320           (while (and methods (not split-name))
11321             (goto-char (point-min))
11322             (setq method (pop methods))
11323             (setq match (car method))
11324             (when (cond
11325                    ((stringp match)
11326                     ;; Regular expression.
11327                     (ignore-errors
11328                       (re-search-forward match nil t)))
11329                    ((functionp match)
11330                     ;; Function.
11331                     (save-restriction
11332                       (widen)
11333                       (setq result (funcall match gnus-newsgroup-name))))
11334                    ((consp match)
11335                     ;; Form.
11336                     (save-restriction
11337                       (widen)
11338                       (setq result (eval match)))))
11339               (setq split-name (cdr method))
11340               (cond ((stringp result)
11341                      (push (expand-file-name
11342                             result gnus-article-save-directory)
11343                            split-name))
11344                     ((consp result)
11345                      (setq split-name (append result split-name)))))))))
11346     (nreverse split-name)))
11347
11348 (defun gnus-valid-move-group-p (group)
11349   (and (boundp group)
11350        (symbol-name group)
11351        (symbol-value group)
11352        (gnus-get-function (gnus-find-method-for-group
11353                            (symbol-name group)) 'request-accept-article t)))
11354
11355 (defun gnus-read-move-group-name (prompt default articles prefix)
11356   "Read a group name."
11357   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11358          (minibuffer-confirm-incomplete nil) ; XEmacs
11359          (prom
11360           (format "%s %s to"
11361                   prompt
11362                   (if (> (length articles) 1)
11363                       (format "these %d articles" (length articles))
11364                     "this article")))
11365          (to-newsgroup
11366           (cond
11367            ((null split-name)
11368             (gnus-completing-read-with-default
11369              default prom
11370              gnus-active-hashtb
11371              'gnus-valid-move-group-p
11372              nil prefix
11373              'gnus-group-history))
11374            ((= 1 (length split-name))
11375             (gnus-completing-read-with-default
11376              (car split-name) prom
11377              gnus-active-hashtb
11378              'gnus-valid-move-group-p
11379              nil nil
11380              'gnus-group-history))
11381            (t
11382             (gnus-completing-read-with-default
11383              nil prom
11384              (mapcar 'list (nreverse split-name))
11385              nil nil nil
11386              'gnus-group-history))))
11387          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11388     (when to-newsgroup
11389       (if (or (string= to-newsgroup "")
11390               (string= to-newsgroup prefix))
11391           (setq to-newsgroup default))
11392       (unless to-newsgroup
11393         (error "No group name entered"))
11394       (or (gnus-active to-newsgroup)
11395           (gnus-activate-group to-newsgroup nil nil to-method)
11396           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11397                                      to-newsgroup))
11398               (or (and (gnus-request-create-group to-newsgroup to-method)
11399                        (gnus-activate-group
11400                         to-newsgroup nil nil to-method)
11401                        (gnus-subscribe-group to-newsgroup))
11402                   (error "Couldn't create group %s" to-newsgroup)))
11403           (error "No such group: %s" to-newsgroup)))
11404     to-newsgroup))
11405
11406 (defvar gnus-summary-save-parts-counter)
11407
11408 (defun gnus-summary-save-parts (type dir n &optional reverse)
11409   "Save parts matching TYPE to DIR.
11410 If REVERSE, save parts that do not match TYPE."
11411   (interactive
11412    (list (read-string "Save parts of type: "
11413                       (or (car gnus-summary-save-parts-type-history)
11414                           gnus-summary-save-parts-default-mime)
11415                       'gnus-summary-save-parts-type-history)
11416          (setq gnus-summary-save-parts-last-directory
11417                (read-file-name "Save to directory: "
11418                                gnus-summary-save-parts-last-directory
11419                                nil t))
11420          current-prefix-arg))
11421   (gnus-summary-iterate n
11422     (let ((gnus-display-mime-function nil)
11423           (gnus-inhibit-treatment t))
11424       (gnus-summary-select-article))
11425     (save-excursion
11426       (set-buffer gnus-article-buffer)
11427       (let ((handles (or gnus-article-mime-handles
11428                          (mm-dissect-buffer nil gnus-article-loose-mime)
11429                          (and gnus-article-emulate-mime
11430                               (mm-uu-dissect))))
11431             (gnus-summary-save-parts-counter 1))
11432         (when handles
11433           (gnus-summary-save-parts-1 type dir handles reverse)
11434           (unless gnus-article-mime-handles ;; Don't destroy this case.
11435             (mm-destroy-parts handles)))))))
11436
11437 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11438   (if (stringp (car handle))
11439       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11440               (cdr handle))
11441     (when (if reverse
11442               (not (string-match type (mm-handle-media-type handle)))
11443             (string-match type (mm-handle-media-type handle)))
11444       (let ((file (expand-file-name
11445                    (gnus-map-function
11446                     mm-file-name-rewrite-functions
11447                     (file-name-nondirectory
11448                      (or
11449                       (mail-content-type-get
11450                        (mm-handle-disposition handle) 'filename)
11451                       (mail-content-type-get
11452                        (mm-handle-type handle) 'name)
11453                       (format "%s.%d.%d" gnus-newsgroup-name
11454                               (cdr gnus-article-current)
11455                               gnus-summary-save-parts-counter))))
11456                    dir)))
11457         (incf gnus-summary-save-parts-counter)
11458         (unless (file-exists-p file)
11459           (mm-save-part-to-file handle file))))))
11460
11461 ;; Summary extract commands
11462
11463 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11464   (let ((buffer-read-only nil)
11465         (article (gnus-summary-article-number))
11466         after-article b e)
11467     (unless (gnus-summary-goto-subject article)
11468       (error "No such article: %d" article))
11469     (gnus-summary-position-point)
11470     ;; If all commands are to be bunched up on one line, we collect
11471     ;; them here.
11472     (unless gnus-view-pseudos-separately
11473       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11474             files action)
11475         (while ps
11476           (setq action (cdr (assq 'action (car ps))))
11477           (setq files (list (cdr (assq 'name (car ps)))))
11478           (while (and ps (cdr ps)
11479                       (string= (or action "1")
11480                                (or (cdr (assq 'action (cadr ps))) "2")))
11481             (push (cdr (assq 'name (cadr ps))) files)
11482             (setcdr ps (cddr ps)))
11483           (when files
11484             (when (not (string-match "%s" action))
11485               (push " " files))
11486             (push " " files)
11487             (when (assq 'execute (car ps))
11488               (setcdr (assq 'execute (car ps))
11489                       (funcall (if (string-match "%s" action)
11490                                    'format 'concat)
11491                                action
11492                                (mapconcat
11493                                 (lambda (f)
11494                                   (if (equal f " ")
11495                                       f
11496                                     (shell-quote-argument f)))
11497                                 files " ")))))
11498           (setq ps (cdr ps)))))
11499     (if (and gnus-view-pseudos (not not-view))
11500         (while pslist
11501           (when (assq 'execute (car pslist))
11502             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11503                                   (eq gnus-view-pseudos 'not-confirm)))
11504           (setq pslist (cdr pslist)))
11505       (save-excursion
11506         (while pslist
11507           (setq after-article (or (cdr (assq 'article (car pslist)))
11508                                   (gnus-summary-article-number)))
11509           (gnus-summary-goto-subject after-article)
11510           (forward-line 1)
11511           (setq b (point))
11512           (insert "    " (file-name-nondirectory
11513                           (cdr (assq 'name (car pslist))))
11514                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11515           (setq e (point))
11516           (forward-line -1)             ; back to `b'
11517           (gnus-add-text-properties
11518            b (1- e) (list 'gnus-number gnus-reffed-article-number
11519                           gnus-mouse-face-prop gnus-mouse-face))
11520           (gnus-data-enter
11521            after-article gnus-reffed-article-number
11522            gnus-unread-mark b (car pslist) 0 (- e b))
11523           (setq gnus-newsgroup-unreads
11524                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11525                                          gnus-reffed-article-number))
11526           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11527           (setq pslist (cdr pslist)))))))
11528
11529 (defun gnus-pseudos< (p1 p2)
11530   (let ((c1 (cdr (assq 'action p1)))
11531         (c2 (cdr (assq 'action p2))))
11532     (and c1 c2 (string< c1 c2))))
11533
11534 (defun gnus-request-pseudo-article (props)
11535   (cond ((assq 'execute props)
11536          (gnus-execute-command (cdr (assq 'execute props)))))
11537   (let ((gnus-current-article (gnus-summary-article-number)))
11538     (gnus-run-hooks 'gnus-mark-article-hook)))
11539
11540 (defun gnus-execute-command (command &optional automatic)
11541   (save-excursion
11542     (gnus-article-setup-buffer)
11543     (set-buffer gnus-article-buffer)
11544     (setq buffer-read-only nil)
11545     (let ((command (if automatic command
11546                      (read-string "Command: " (cons command 0)))))
11547       (erase-buffer)
11548       (insert "$ " command "\n\n")
11549       (if gnus-view-pseudo-asynchronously
11550           (start-process "gnus-execute" (current-buffer) shell-file-name
11551                          shell-command-switch command)
11552         (call-process shell-file-name nil t nil
11553                       shell-command-switch command)))))
11554
11555 ;; Summary kill commands.
11556
11557 (defun gnus-summary-edit-global-kill (article)
11558   "Edit the \"global\" kill file."
11559   (interactive (list (gnus-summary-article-number)))
11560   (gnus-group-edit-global-kill article))
11561
11562 (defun gnus-summary-edit-local-kill ()
11563   "Edit a local kill file applied to the current newsgroup."
11564   (interactive)
11565   (setq gnus-current-headers (gnus-summary-article-header))
11566   (gnus-group-edit-local-kill
11567    (gnus-summary-article-number) gnus-newsgroup-name))
11568
11569 ;;; Header reading.
11570
11571 (defun gnus-read-header (id &optional header)
11572   "Read the headers of article ID and enter them into the Gnus system."
11573   (let ((group gnus-newsgroup-name)
11574         (gnus-override-method
11575          (or
11576           gnus-override-method
11577           (and (gnus-news-group-p gnus-newsgroup-name)
11578                (car (gnus-refer-article-methods)))))
11579         where)
11580     ;; First we check to see whether the header in question is already
11581     ;; fetched.
11582     (if (stringp id)
11583         ;; This is a Message-ID.
11584         (setq header (or header (gnus-id-to-header id)))
11585       ;; This is an article number.
11586       (setq header (or header (gnus-summary-article-header id))))
11587     (if (and header
11588              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11589         ;; We have found the header.
11590         header
11591       ;; We have to really fetch the header to this article.
11592       (save-excursion
11593         (set-buffer nntp-server-buffer)
11594         (when (setq where (gnus-request-head id group))
11595           (nnheader-fold-continuation-lines)
11596           (goto-char (point-max))
11597           (insert ".\n")
11598           (goto-char (point-min))
11599           (insert "211 ")
11600           (princ (cond
11601                   ((numberp id) id)
11602                   ((cdr where) (cdr where))
11603                   (header (mail-header-number header))
11604                   (t gnus-reffed-article-number))
11605                  (current-buffer))
11606           (insert " Article retrieved.\n"))
11607         (if (or (not where)
11608                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11609             ()                          ; Malformed head.
11610           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11611             (when (and (stringp id)
11612                        (not (string= (gnus-group-real-name group)
11613                                      (car where))))
11614               ;; If we fetched by Message-ID and the article came
11615               ;; from a different group, we fudge some bogus article
11616               ;; numbers for this article.
11617               (mail-header-set-number header gnus-reffed-article-number))
11618             (save-excursion
11619               (set-buffer gnus-summary-buffer)
11620               (decf gnus-reffed-article-number)
11621               (gnus-remove-header (mail-header-number header))
11622               (push header gnus-newsgroup-headers)
11623               (setq gnus-current-headers header)
11624               (push (mail-header-number header) gnus-newsgroup-limit)))
11625           header)))))
11626
11627 (defun gnus-remove-header (number)
11628   "Remove header NUMBER from `gnus-newsgroup-headers'."
11629   (if (and gnus-newsgroup-headers
11630            (= number (mail-header-number (car gnus-newsgroup-headers))))
11631       (pop gnus-newsgroup-headers)
11632     (let ((headers gnus-newsgroup-headers))
11633       (while (and (cdr headers)
11634                   (not (= number (mail-header-number (cadr headers)))))
11635         (pop headers))
11636       (when (cdr headers)
11637         (setcdr headers (cddr headers))))))
11638
11639 ;;;
11640 ;;; summary highlights
11641 ;;;
11642
11643 (defun gnus-highlight-selected-summary ()
11644   "Highlight selected article in summary buffer."
11645   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11646   (when gnus-summary-selected-face
11647     (save-excursion
11648       (let* ((beg (point-at-bol))
11649              (end (point-at-eol))
11650              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11651              (from (if (get-text-property beg gnus-mouse-face-prop)
11652                        beg
11653                      (or (next-single-property-change
11654                           beg gnus-mouse-face-prop nil end)
11655                          beg)))
11656              (to
11657               (if (= from end)
11658                   (- from 2)
11659                 (or (next-single-property-change
11660                      from gnus-mouse-face-prop nil end)
11661                     end))))
11662         ;; If no mouse-face prop on line we will have to = from = end,
11663         ;; so we highlight the entire line instead.
11664         (when (= (+ to 2) from)
11665           (setq from beg)
11666           (setq to end))
11667         (if gnus-newsgroup-selected-overlay
11668             ;; Move old overlay.
11669             (gnus-move-overlay
11670              gnus-newsgroup-selected-overlay from to (current-buffer))
11671           ;; Create new overlay.
11672           (gnus-overlay-put
11673            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11674            'face gnus-summary-selected-face))))))
11675
11676 (defvar gnus-summary-highlight-line-cached nil)
11677 (defvar gnus-summary-highlight-line-trigger nil)
11678
11679 (defun gnus-summary-highlight-line-0 ()
11680   (if (and (eq gnus-summary-highlight-line-trigger
11681                gnus-summary-highlight)
11682            gnus-summary-highlight-line-cached)
11683       gnus-summary-highlight-line-cached
11684     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11685           gnus-summary-highlight-line-cached
11686           (let* ((cond (list 'cond))
11687                  (c cond)
11688                  (list gnus-summary-highlight))
11689             (while list
11690               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11691                               nil))
11692               (setq c (cdr c)
11693                     list (cdr list)))
11694             (gnus-byte-compile (list 'lambda nil cond))))))
11695
11696 (defun gnus-summary-highlight-line ()
11697   "Highlight current line according to `gnus-summary-highlight'."
11698   (let* ((beg (point-at-bol))
11699          (article (or (gnus-summary-article-number) gnus-current-article))
11700          (score (or (cdr (assq article
11701                                gnus-newsgroup-scored))
11702                     gnus-summary-default-score 0))
11703          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11704          (inhibit-read-only t)
11705          (default gnus-summary-default-score)
11706          (default-high gnus-summary-default-high-score)
11707          (default-low gnus-summary-default-low-score)
11708          (uncached (and gnus-summary-use-undownloaded-faces
11709                         (memq article gnus-newsgroup-undownloaded)
11710                         (not (memq article gnus-newsgroup-cached)))))
11711     (let ((face (funcall (gnus-summary-highlight-line-0))))
11712       (unless (eq face (get-text-property beg 'face))
11713         (gnus-put-text-property-excluding-characters-with-faces
11714          beg (point-at-eol) 'face
11715          (setq face (if (boundp face) (symbol-value face) face)))
11716         (when gnus-summary-highlight-line-function
11717           (funcall gnus-summary-highlight-line-function article face))))))
11718
11719 (defun gnus-update-read-articles (group unread &optional compute)
11720   "Update the list of read articles in GROUP.
11721 UNREAD is a sorted list."
11722   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11723         (info (gnus-get-info group))
11724         (prev 1)
11725         read)
11726     (if (or (not info) (not active))
11727         ;; There is no info on this group if it was, in fact,
11728         ;; killed.  Gnus stores no information on killed groups, so
11729         ;; there's nothing to be done.
11730         ;; One could store the information somewhere temporarily,
11731         ;; perhaps...  Hmmm...
11732         ()
11733       ;; Remove any negative articles numbers.
11734       (while (and unread (< (car unread) 0))
11735         (setq unread (cdr unread)))
11736       ;; Remove any expired article numbers
11737       (while (and unread (< (car unread) (car active)))
11738         (setq unread (cdr unread)))
11739       ;; Compute the ranges of read articles by looking at the list of
11740       ;; unread articles.
11741       (while unread
11742         (when (/= (car unread) prev)
11743           (push (if (= prev (1- (car unread))) prev
11744                   (cons prev (1- (car unread))))
11745                 read))
11746         (setq prev (1+ (car unread)))
11747         (setq unread (cdr unread)))
11748       (when (<= prev (cdr active))
11749         (push (cons prev (cdr active)) read))
11750       (setq read (if (> (length read) 1) (nreverse read) read))
11751       (if compute
11752           read
11753         (save-excursion
11754           (let (setmarkundo)
11755             ;; Propagate the read marks to the backend.
11756             (when (gnus-check-backend-function 'request-set-mark group)
11757               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11758                     (add (gnus-remove-from-range read (gnus-info-read info))))
11759                 (when (or add del)
11760                   (unless (gnus-check-group group)
11761                     (error "Can't open server for %s" group))
11762                   (gnus-request-set-mark
11763                    group (delq nil (list (if add (list add 'add '(read)))
11764                                          (if del (list del 'del '(read))))))
11765                   (setq setmarkundo
11766                         `(gnus-request-set-mark
11767                           ,group
11768                           ',(delq nil (list
11769                                        (if del (list del 'add '(read)))
11770                                        (if add (list add 'del '(read))))))))))
11771             (set-buffer gnus-group-buffer)
11772             (gnus-undo-register
11773               `(progn
11774                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11775                  (gnus-info-set-read ',info ',(gnus-info-read info))
11776                  (gnus-get-unread-articles-in-group ',info
11777                                                     (gnus-active ,group))
11778                  (gnus-group-update-group ,group t)
11779                  ,setmarkundo))))
11780         ;; Enter this list into the group info.
11781         (gnus-info-set-read info read)
11782         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11783         (gnus-get-unread-articles-in-group info (gnus-active group))
11784         t))))
11785
11786 (defun gnus-offer-save-summaries ()
11787   "Offer to save all active summary buffers."
11788   (let (buffers)
11789     ;; Go through all buffers and find all summaries.
11790     (dolist (buffer (buffer-list))
11791       (when (and (setq buffer (buffer-name buffer))
11792                  (string-match "Summary" buffer)
11793                  (with-current-buffer buffer
11794                    ;; We check that this is, indeed, a summary buffer.
11795                    (and (eq major-mode 'gnus-summary-mode)
11796                         ;; Also make sure this isn't bogus.
11797                         gnus-newsgroup-prepared
11798                         ;; Also make sure that this isn't a
11799                         ;; dead summary buffer.
11800                         (not gnus-dead-summary-mode))))
11801         (push buffer buffers)))
11802     ;; Go through all these summary buffers and offer to save them.
11803     (when buffers
11804       (save-excursion
11805         (map-y-or-n-p
11806          "Update summary buffer %s? "
11807          (lambda (buf)
11808            (switch-to-buffer buf)
11809            (gnus-summary-exit))
11810          buffers)))))
11811
11812 (defun gnus-summary-setup-default-charset ()
11813   "Setup newsgroup default charset."
11814   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11815       (setq gnus-newsgroup-charset nil)
11816     (let* ((ignored-charsets
11817             (or gnus-newsgroup-ephemeral-ignored-charsets
11818                 (append
11819                  (and gnus-newsgroup-name
11820                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11821                  gnus-newsgroup-ignored-charsets))))
11822       (setq gnus-newsgroup-charset
11823             (or gnus-newsgroup-ephemeral-charset
11824                 (and gnus-newsgroup-name
11825                      (gnus-parameter-charset gnus-newsgroup-name))
11826                 gnus-default-charset))
11827       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11828            ignored-charsets))))
11829
11830 ;;;
11831 ;;; Mime Commands
11832 ;;;
11833
11834 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11835   "Display the current article buffer fully MIME-buttonized.
11836 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11837 treated as multipart/mixed."
11838   (interactive "P")
11839   (require 'gnus-art)
11840   (let ((gnus-unbuttonized-mime-types nil)
11841         (gnus-mime-display-multipart-as-mixed show-all-parts))
11842     (gnus-summary-show-article)))
11843
11844 (defun gnus-summary-repair-multipart (article)
11845   "Add a Content-Type header to a multipart article without one."
11846   (interactive (list (gnus-summary-article-number)))
11847   (gnus-with-article article
11848     (message-narrow-to-head)
11849     (message-remove-header "Mime-Version")
11850     (goto-char (point-max))
11851     (insert "Mime-Version: 1.0\n")
11852     (widen)
11853     (when (search-forward "\n--" nil t)
11854       (let ((separator (buffer-substring (point) (point-at-eol))))
11855         (message-narrow-to-head)
11856         (message-remove-header "Content-Type")
11857         (goto-char (point-max))
11858         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11859                         separator))
11860         (widen))))
11861   (let (gnus-mark-article-hook)
11862     (gnus-summary-select-article t t nil article)))
11863
11864 (defun gnus-summary-toggle-display-buttonized ()
11865   "Toggle the buttonizing of the article buffer."
11866   (interactive)
11867   (require 'gnus-art)
11868   (if (setq gnus-inhibit-mime-unbuttonizing
11869             (not gnus-inhibit-mime-unbuttonizing))
11870       (let ((gnus-unbuttonized-mime-types nil))
11871         (gnus-summary-show-article))
11872     (gnus-summary-show-article)))
11873
11874 ;;;
11875 ;;; Generic summary marking commands
11876 ;;;
11877
11878 (defvar gnus-summary-marking-alist
11879   '((read gnus-del-mark "d")
11880     (unread gnus-unread-mark "u")
11881     (ticked gnus-ticked-mark "!")
11882     (dormant gnus-dormant-mark "?")
11883     (expirable gnus-expirable-mark "e"))
11884   "An alist of names/marks/keystrokes.")
11885
11886 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11887 (defvar gnus-summary-mark-map)
11888
11889 (defun gnus-summary-make-all-marking-commands ()
11890   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11891   (dolist (elem gnus-summary-marking-alist)
11892     (apply 'gnus-summary-make-marking-command elem)))
11893
11894 (defun gnus-summary-make-marking-command (name mark keystroke)
11895   (let ((map (make-sparse-keymap)))
11896     (define-key gnus-summary-generic-mark-map keystroke map)
11897     (dolist (lway `((next "next" next nil "n")
11898                     (next-unread "next unread" next t "N")
11899                     (prev "previous" prev nil "p")
11900                     (prev-unread "previous unread" prev t "P")
11901                     (nomove "" nil nil ,keystroke)))
11902       (let ((func (gnus-summary-make-marking-command-1
11903                    mark (car lway) lway name)))
11904         (setq func (eval func))
11905         (define-key map (nth 4 lway) func)))))
11906
11907 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11908   `(defun ,(intern
11909             (format "gnus-summary-put-mark-as-%s%s"
11910                     name (if (eq way 'nomove)
11911                              ""
11912                            (concat "-" (symbol-name way)))))
11913      (n)
11914      ,(format
11915        "Mark the current article as %s%s.
11916 If N, the prefix, then repeat N times.
11917 If N is negative, move in reverse order.
11918 The difference between N and the actual number of articles marked is
11919 returned."
11920        name (cadr lway))
11921      (interactive "p")
11922      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11923
11924 (defun gnus-summary-generic-mark (n mark move unread)
11925   "Mark N articles with MARK."
11926   (unless (eq major-mode 'gnus-summary-mode)
11927     (error "This command can only be used in the summary buffer"))
11928   (gnus-summary-show-thread)
11929   (let ((nummove
11930          (cond
11931           ((eq move 'next) 1)
11932           ((eq move 'prev) -1)
11933           (t 0))))
11934     (if (zerop nummove)
11935         (setq n 1)
11936       (when (< n 0)
11937         (setq n (abs n)
11938               nummove (* -1 nummove))))
11939     (while (and (> n 0)
11940                 (gnus-summary-mark-article nil mark)
11941                 (zerop (gnus-summary-next-subject nummove unread t)))
11942       (setq n (1- n)))
11943     (when (/= 0 n)
11944       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11945     (gnus-summary-recenter)
11946     (gnus-summary-position-point)
11947     (gnus-set-mode-line 'summary)
11948     n))
11949
11950 (defun gnus-summary-insert-articles (articles)
11951   (when (setq articles
11952               (gnus-sorted-difference articles
11953                                       (mapcar (lambda (h)
11954                                                 (mail-header-number h))
11955                                               gnus-newsgroup-headers)))
11956     (setq gnus-newsgroup-headers
11957           (gnus-merge 'list
11958                       gnus-newsgroup-headers
11959                       (gnus-fetch-headers articles)
11960                       'gnus-article-sort-by-number))
11961     ;; Suppress duplicates?
11962     (when gnus-suppress-duplicates
11963       (gnus-dup-suppress-articles))
11964
11965     ;; We might want to build some more threads first.
11966     (when (and gnus-fetch-old-headers
11967                (eq gnus-headers-retrieved-by 'nov))
11968       (if (eq gnus-fetch-old-headers 'invisible)
11969           (gnus-build-all-threads)
11970         (gnus-build-old-threads)))
11971     ;; Let the Gnus agent mark articles as read.
11972     (when gnus-agent
11973       (gnus-agent-get-undownloaded-list))
11974     ;; Remove list identifiers from subject
11975     (when gnus-list-identifiers
11976       (gnus-summary-remove-list-identifiers))
11977     ;; First and last article in this newsgroup.
11978     (when gnus-newsgroup-headers
11979       (setq gnus-newsgroup-begin
11980             (mail-header-number (car gnus-newsgroup-headers))
11981             gnus-newsgroup-end
11982             (mail-header-number
11983              (gnus-last-element gnus-newsgroup-headers))))
11984     (when gnus-use-scoring
11985       (gnus-possibly-score-headers))))
11986
11987 (defun gnus-summary-insert-old-articles (&optional all)
11988   "Insert all old articles in this group.
11989 If ALL is non-nil, already read articles become readable.
11990 If ALL is a number, fetch this number of articles."
11991   (interactive "P")
11992   (prog1
11993       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11994             older len)
11995         (setq older
11996               ;; Some nntp servers lie about their active range.  When
11997               ;; this happens, the active range can be in the millions.
11998               ;; Use a compressed range to avoid creating a huge list.
11999               (gnus-range-difference (list gnus-newsgroup-active) old))
12000         (setq len (gnus-range-length older))
12001         (cond
12002          ((null older) nil)
12003          ((numberp all)
12004           (if (< all len)
12005               (let ((older-range (nreverse older)))
12006                 (setq older nil)
12007
12008                 (while (> all 0)
12009                   (let* ((r (pop older-range))
12010                          (min (if (numberp r) r (car r)))
12011                          (max (if (numberp r) r (cdr r))))
12012                     (while (and (<= min max)
12013                                 (> all 0))
12014                       (push max older)
12015                       (setq all (1- all)
12016                             max (1- max))))))
12017             (setq older (gnus-uncompress-range older))))
12018          (all
12019           (setq older (gnus-uncompress-range older)))
12020          (t
12021           (when (and (numberp gnus-large-newsgroup)
12022                    (> len gnus-large-newsgroup))
12023               (let* ((cursor-in-echo-area nil)
12024                      (initial (gnus-parameter-large-newsgroup-initial
12025                                gnus-newsgroup-name))
12026                      (input
12027                       (read-string
12028                        (format
12029                         "How many articles from %s (%s %d): "
12030                         (gnus-limit-string
12031                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12032                         (if initial "max" "default")
12033                         len)
12034                        (if initial
12035                            (cons (number-to-string initial)
12036                                  0)))))
12037                 (unless (string-match "^[ \t]*$" input)
12038                   (setq all (string-to-number input))
12039                   (if (< all len)
12040                       (let ((older-range (nreverse older)))
12041                         (setq older nil)
12042
12043                         (while (> all 0)
12044                           (let* ((r (pop older-range))
12045                                  (min (if (numberp r) r (car r)))
12046                                  (max (if (numberp r) r (cdr r))))
12047                             (while (and (<= min max)
12048                                         (> all 0))
12049                               (push max older)
12050                               (setq all (1- all)
12051                                     max (1- max))))))))))
12052           (setq older (gnus-uncompress-range older))))
12053         (if (not older)
12054             (message "No old news.")
12055           (gnus-summary-insert-articles older)
12056           (gnus-summary-limit (gnus-sorted-nunion old older))))
12057     (gnus-summary-position-point)))
12058
12059 (defun gnus-summary-insert-new-articles ()
12060   "Insert all new articles in this group."
12061   (interactive)
12062   (prog1
12063       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12064             (old-active gnus-newsgroup-active)
12065             (nnmail-fetched-sources (list t))
12066             i new)
12067         (setq gnus-newsgroup-active
12068               (gnus-activate-group gnus-newsgroup-name 'scan))
12069         (setq i (cdr gnus-newsgroup-active))
12070         (while (> i (cdr old-active))
12071           (push i new)
12072           (decf i))
12073         (if (not new)
12074             (message "No gnus is bad news")
12075           (gnus-summary-insert-articles new)
12076           (setq gnus-newsgroup-unreads
12077                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12078           (gnus-summary-limit (gnus-sorted-nunion old new))))
12079     (gnus-summary-position-point)))
12080
12081 (gnus-summary-make-all-marking-commands)
12082
12083 (gnus-ems-redefine)
12084
12085 (provide 'gnus-sum)
12086
12087 (run-hooks 'gnus-sum-load-hook)
12088
12089 ;; Local Variables:
12090 ;; coding: iso-8859-1
12091 ;; End:
12092
12093 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12094 ;;; gnus-sum.el ends here