(gnus-summary-wash-map): Bind "W i" to
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
48 (autoload 'mm-uu-dissect "mm-uu")
49 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
50   "Deuglify broken Outlook (Express) articles and redisplay."
51   t)
52 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
53 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
54 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
55
56 (defcustom gnus-kill-summary-on-exit t
57   "*If non-nil, kill the summary buffer when you exit from it.
58 If nil, the summary will become a \"*Dead Summary*\" buffer, and
59 it will be killed sometime later."
60   :group 'gnus-summary-exit
61   :type 'boolean)
62
63 (defcustom gnus-fetch-old-headers nil
64   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
65 If an unread article in the group refers to an older, already read (or
66 just marked as read) article, the old article will not normally be
67 displayed in the Summary buffer.  If this variable is t, Gnus
68 will attempt to grab the headers to the old articles, and thereby
69 build complete threads.  If it has the value `some', only enough
70 headers to connect otherwise loose threads will be displayed.  This
71 variable can also be a number.  In that case, no more than that number
72 of old headers will be fetched.  If it has the value `invisible', all
73 old headers will be fetched, but none will be displayed.
74
75 The server has to support NOV for any of this to work."
76   :group 'gnus-thread
77   :type '(choice (const :tag "off" nil)
78                  (const :tag "on" t)
79                  (const some)
80                  (const invisible)
81                  number
82                  (sexp :menu-tag "other" t)))
83
84 (defcustom gnus-refer-thread-limit 200
85   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
86 If t, fetch all the available old headers."
87   :group 'gnus-thread
88   :type '(choice number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-summary-make-false-root 'adopt
92   "*nil means that Gnus won't gather loose threads.
93 If the root of a thread has expired or been read in a previous
94 session, the information necessary to build a complete thread has been
95 lost.  Instead of having many small sub-threads from this original thread
96 scattered all over the summary buffer, Gnus can gather them.
97
98 If non-nil, Gnus will try to gather all loose sub-threads from an
99 original thread into one large thread.
100
101 If this variable is non-nil, it should be one of `none', `adopt',
102 `dummy' or `empty'.
103
104 If this variable is `none', Gnus will not make a false root, but just
105 present the sub-threads after another.
106 If this variable is `dummy', Gnus will create a dummy root that will
107 have all the sub-threads as children.
108 If this variable is `adopt', Gnus will make one of the \"children\"
109 the parent and mark all the step-children as such.
110 If this variable is `empty', the \"children\" are printed with empty
111 subject fields.  (Or rather, they will be printed with a string
112 given by the `gnus-summary-same-subject' variable.)"
113   :group 'gnus-thread
114   :type '(choice (const :tag "off" nil)
115                  (const none)
116                  (const dummy)
117                  (const adopt)
118                  (const empty)))
119
120 (defcustom gnus-summary-make-false-root-always nil
121   "Always make a false dummy root."
122   :version "21.4"
123   :group 'gnus-thread
124   :type 'boolean)
125
126 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
127   "*A regexp to match subjects to be excluded from loose thread gathering.
128 As loose thread gathering is done on subjects only, that means that
129 there can be many false gatherings performed.  By rooting out certain
130 common subjects, gathering might become saner."
131   :group 'gnus-thread
132   :type 'regexp)
133
134 (defcustom gnus-summary-gather-subject-limit nil
135   "*Maximum length of subject comparisons when gathering loose threads.
136 Use nil to compare full subjects.  Setting this variable to a low
137 number will help gather threads that have been corrupted by
138 newsreaders chopping off subject lines, but it might also mean that
139 unrelated articles that have subject that happen to begin with the
140 same few characters will be incorrectly gathered.
141
142 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
143 comparing subjects."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  (const fuzzy)
147                  (sexp :menu-tag "on" t)))
148
149 (defcustom gnus-simplify-subject-functions nil
150   "List of functions taking a string argument that simplify subjects.
151 The functions are applied recursively.
152
153 Useful functions to put in this list include:
154 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
155 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
156   :group 'gnus-thread
157   :type '(repeat function))
158
159 (defcustom gnus-simplify-ignored-prefixes nil
160   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
161   :group 'gnus-thread
162   :type '(choice (const :tag "off" nil)
163                  regexp))
164
165 (defcustom gnus-build-sparse-threads nil
166   "*If non-nil, fill in the gaps in threads.
167 If `some', only fill in the gaps that are needed to tie loose threads
168 together.  If `more', fill in all leaf nodes that Gnus can find.  If
169 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  (const some)
173                  (const more)
174                  (sexp :menu-tag "all" t)))
175
176 (defcustom gnus-summary-thread-gathering-function
177   'gnus-gather-threads-by-subject
178   "*Function used for gathering loose threads.
179 There are two pre-defined functions: `gnus-gather-threads-by-subject',
180 which only takes Subjects into consideration; and
181 `gnus-gather-threads-by-references', which compared the References
182 headers of the articles to find matches."
183   :group 'gnus-thread
184   :type '(radio (function-item gnus-gather-threads-by-subject)
185                 (function-item gnus-gather-threads-by-references)
186                 (function :tag "other")))
187
188 (defcustom gnus-summary-same-subject ""
189   "*String indicating that the current article has the same subject as the previous.
190 This variable will only be used if the value of
191 `gnus-summary-make-false-root' is `empty'."
192   :group 'gnus-summary-format
193   :type 'string)
194
195 (defcustom gnus-summary-goto-unread t
196   "*If t, many commands will go to the next unread article.
197 This applies to marking commands as well as other commands that
198 \"naturally\" select the next article, like, for instance, `SPC' at
199 the end of an article.
200
201 If nil, the marking commands do NOT go to the next unread article
202 \(they go to the next article instead).  If `never', commands that
203 usually go to the next unread article, will go to the next article,
204 whether it is read or not."
205   :group 'gnus-summary-marks
206   :link '(custom-manual "(gnus)Setting Marks")
207   :type '(choice (const :tag "off" nil)
208                  (const never)
209                  (sexp :menu-tag "on" t)))
210
211 (defcustom gnus-summary-default-score 0
212   "*Default article score level.
213 All scores generated by the score files will be added to this score.
214 If this variable is nil, scoring will be disabled."
215   :group 'gnus-score-default
216   :type '(choice (const :tag "disable")
217                  integer))
218
219 (defcustom gnus-summary-default-high-score 0
220   "*Default threshold for a high scored article.
221 An article will be highlighted as high scored if its score is greater
222 than this score."
223   :version "21.4"
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-default-low-score 0
228   "*Default threshold for a low scored article.
229 An article will be highlighted as low scored if its score is smaller
230 than this score."
231   :version "21.4"
232   :group 'gnus-score-default
233   :type 'integer)
234
235 (defcustom gnus-summary-zcore-fuzz 0
236   "*Fuzziness factor for the zcore in the summary buffer.
237 Articles with scores closer than this to `gnus-summary-default-score'
238 will not be marked."
239   :group 'gnus-summary-format
240   :type 'integer)
241
242 (defcustom gnus-simplify-subject-fuzzy-regexp nil
243   "*Strings to be removed when doing fuzzy matches.
244 This can either be a regular expression or list of regular expressions
245 that will be removed from subject strings if fuzzy subject
246 simplification is selected."
247   :group 'gnus-thread
248   :type '(repeat regexp))
249
250 (defcustom gnus-show-threads t
251   "*If non-nil, display threads in summary mode."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-subtree nil
256   "*If non-nil, hide all threads initially.
257 This can be a predicate specifier which says which threads to hide.
258 If threads are hidden, you have to run the command
259 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
260 to expose hidden threads."
261   :group 'gnus-thread
262   :type '(radio (sexp :format "Non-nil\n"
263                       :match (lambda (widget value)
264                                (not (or (consp value) (functionp value))))
265                       :value t)
266                 (const nil)
267                 (sexp :tag "Predicate specifier")))
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :version "21.4"
328   :group 'gnus-group-select
329   :type '(choice (const best)
330                  (const unread)
331                  (const first)
332                  (const unseen)
333                  (const unseen-or-unread)))
334
335 (defcustom gnus-auto-select-next t
336   "*If non-nil, offer to go to the next group from the end of the previous.
337 If the value is t and the next newsgroup is empty, Gnus will exit
338 summary mode and go back to group mode.  If the value is neither nil
339 nor t, Gnus will select the following unread newsgroup.  In
340 particular, if the value is the symbol `quietly', the next unread
341 newsgroup will be selected without any confirmation, and if it is
342 `almost-quietly', the next group will be selected without any
343 confirmation if you are located on the last article in the group.
344 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
345 will go to the next group without confirmation."
346   :group 'gnus-summary-maneuvering
347   :type '(choice (const :tag "off" nil)
348                  (const quietly)
349                  (const almost-quietly)
350                  (const slightly-quietly)
351                  (sexp :menu-tag "on" t)))
352
353 (defcustom gnus-auto-select-same nil
354   "*If non-nil, select the next article with the same subject.
355 If there are no more articles with the same subject, go to
356 the first unread article."
357   :group 'gnus-summary-maneuvering
358   :type 'boolean)
359
360 (defcustom gnus-auto-goto-ignores 'unfetched
361   "*Says how to handle unfetched articles when maneuvering.
362
363 This variable can either be the symbols nil (maneuver to any
364 article), `undownloaded' (maneuvering while unplugged ignores articles
365 that have not been fetched), `always-undownloaded' (maneuvering always
366 ignores articles that have not been fetched), `unfetched' (maneuvering
367 ignores articles whose headers have not been fetched).
368
369 NOTE: The list of unfetched articles will always be nil when plugged
370 and, when unplugged, a subset of the undownloaded article list."
371   :version "21.4"
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "None" nil)
374                  (const :tag "Undownloaded when unplugged" undownloaded)
375                  (const :tag "Undownloaded" always-undownloaded)
376                  (const :tag "Unfetched" unfetched)))
377
378 (defcustom gnus-summary-check-current nil
379   "*If non-nil, consider the current article when moving.
380 The \"unread\" movement commands will stay on the same line if the
381 current article is unread."
382   :group 'gnus-summary-maneuvering
383   :type 'boolean)
384
385 (defcustom gnus-auto-center-summary 2
386   "*If non-nil, always center the current summary buffer.
387 In particular, if `vertical' do only vertical recentering.  If non-nil
388 and non-`vertical', do both horizontal and vertical recentering."
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "none" nil)
391                  (const vertical)
392                  (integer :tag "height")
393                  (sexp :menu-tag "both" t)))
394
395 (defvar gnus-auto-center-group t
396   "*If non-nil, always center the group buffer.")
397
398 (defcustom gnus-show-all-headers nil
399   "*If non-nil, don't hide any headers."
400   :group 'gnus-article-hiding
401   :group 'gnus-article-headers
402   :type 'boolean)
403
404 (defcustom gnus-summary-ignore-duplicates nil
405   "*If non-nil, ignore articles with identical Message-ID headers."
406   :group 'gnus-summary
407   :type 'boolean)
408
409 (defcustom gnus-single-article-buffer t
410   "*If non-nil, display all articles in the same buffer.
411 If nil, each group will get its own article buffer."
412   :group 'gnus-article-various
413   :type 'boolean)
414
415 (defcustom gnus-break-pages t
416   "*If non-nil, do page breaking on articles.
417 The page delimiter is specified by the `gnus-page-delimiter'
418 variable."
419   :group 'gnus-article-various
420   :type 'boolean)
421
422 (defcustom gnus-move-split-methods nil
423   "*Variable used to suggest where articles are to be moved to.
424 It uses the same syntax as the `gnus-split-methods' variable.
425 However, whereas `gnus-split-methods' specifies file names as targets,
426 this variable specifies group names."
427   :group 'gnus-summary-mail
428   :type '(repeat (choice (list :value (fun) function)
429                          (cons :value ("" "") regexp (repeat string))
430                          (sexp :value nil))))
431
432 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
433   "Function used to compute default prefix for article move/copy/etc prompts.
434 The function should take one argument, a group name, and return a
435 string with the suggested prefix."
436   :group 'gnus-summary-mail
437   :type 'function)
438
439 ;; FIXME: Although the custom type is `character' for the following variables,
440 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
441
442 (defcustom gnus-unread-mark ?           ;Whitespace
443   "*Mark used for unread articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-ticked-mark ?!
448   "*Mark used for ticked articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-dormant-mark ??
453   "*Mark used for dormant articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-del-mark ?r
458   "*Mark used for del'd articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-read-mark ?R
463   "*Mark used for read articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-expirable-mark ?E
468   "*Mark used for expirable articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-killed-mark ?K
473   "*Mark used for killed articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-spam-mark ?$
478   "*Mark used for spam articles."
479   :version "21.4"
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-souped-mark ?F
484   "*Mark used for souped articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-kill-file-mark ?X
489   "*Mark used for articles killed by kill files."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-low-score-mark ?Y
494   "*Mark used for articles with a low score."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-catchup-mark ?C
499   "*Mark used for articles that are caught up."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-replied-mark ?A
504   "*Mark used for articles that have been replied to."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-forwarded-mark ?F
509   "*Mark used for articles that have been forwarded."
510   :version "21.4"
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-recent-mark ?N
515   "*Mark used for articles that are recent."
516   :version "21.4"
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :version "21.4"
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-no-mark ?               ;Whitespace
537   "*Mark used for articles that have no other secondary mark."
538   :version "21.4"
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-ancient-mark ?O
543   "*Mark used for ancient articles."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-sparse-mark ?Q
548   "*Mark used for sparsely reffed articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-canceled-mark ?G
553   "*Mark used for canceled articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-duplicate-mark ?M
558   "*Mark used for duplicate articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-undownloaded-mark ?-
563   "*Mark used for articles that weren't downloaded."
564   :version "21.4"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloaded-mark ?+
569   "*Mark used for articles that were downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloadable-mark ?%
574   "*Mark used for articles that are to be downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unsendable-mark ?=
579   "*Mark used for articles that won't be sent."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-over-mark ?+
584   "*Score mark used for articles with high scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-below-mark ?-
589   "*Score mark used for articles with low scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-empty-thread-mark ?     ;Whitespace
594   "*There is no thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-not-empty-thread-mark ?=
599   "*There is a thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-view-pseudo-asynchronously nil
604   "*If non-nil, Gnus will view pseudo-articles asynchronously."
605   :group 'gnus-extract-view
606   :type 'boolean)
607
608 (defcustom gnus-auto-expirable-marks
609   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
610         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
611         gnus-souped-mark gnus-duplicate-mark)
612   "*The list of marks converted into expiration if a group is auto-expirable."
613   :version "21.1"
614   :group 'gnus-summary
615   :type '(repeat character))
616
617 (defcustom gnus-inhibit-user-auto-expire t
618   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
619   :version "21.1"
620   :group 'gnus-summary
621   :type 'boolean)
622
623 (defcustom gnus-view-pseudos nil
624   "*If `automatic', pseudo-articles will be viewed automatically.
625 If `not-confirm', pseudos will be viewed automatically, and the user
626 will not be asked to confirm the command."
627   :group 'gnus-extract-view
628   :type '(choice (const :tag "off" nil)
629                  (const automatic)
630                  (const not-confirm)))
631
632 (defcustom gnus-view-pseudos-separately t
633   "*If non-nil, one pseudo-article will be created for each file to be viewed.
634 If nil, all files that use the same viewing command will be given as a
635 list of parameters to that command."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-insert-pseudo-articles t
640   "*If non-nil, insert pseudo-articles when decoding articles."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-summary-dummy-line-format
645   "   %(:                             :%) %S\n"
646   "*The format specification for the dummy roots in the summary buffer.
647 It works along the same lines as a normal formatting string,
648 with some simple extensions.
649
650 %S  The subject
651
652 General format specifiers can also be used.
653 See `(gnus)Formatting Variables'."
654   :link '(custom-manual "(gnus)Formatting Variables")
655   :group 'gnus-threading
656   :type 'string)
657
658 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
659   "*The format specification for the summary mode line.
660 It works along the same lines as a normal formatting string,
661 with some simple extensions:
662
663 %G  Group name
664 %p  Unprefixed group name
665 %A  Current article number
666 %z  Current article score
667 %V  Gnus version
668 %U  Number of unread articles in the group
669 %e  Number of unselected articles in the group
670 %Z  A string with unread/unselected article counts
671 %g  Shortish group name
672 %S  Subject of the current article
673 %u  User-defined spec
674 %s  Current score file name
675 %d  Number of dormant articles
676 %r  Number of articles that have been marked as read in this session
677 %E  Number of articles expunged by the score files"
678   :group 'gnus-summary-format
679   :type 'string)
680
681 (defcustom gnus-list-identifiers nil
682   "Regexp that matches list identifiers to be removed from subject.
683 This can also be a list of regexps."
684   :version "21.1"
685   :group 'gnus-summary-format
686   :group 'gnus-article-hiding
687   :type '(choice (const :tag "none" nil)
688                  (regexp :value ".*")
689                  (repeat :value (".*") regexp)))
690
691 (defcustom gnus-summary-mark-below 0
692   "*Mark all articles with a score below this variable as read.
693 This variable is local to each summary buffer and usually set by the
694 score file."
695   :group 'gnus-score-default
696   :type 'integer)
697
698 (defun gnus-widget-reversible-match (widget value)
699   "Ignoring WIDGET, convert VALUE to internal form.
700 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
701   ;; (debug value)
702   (or (symbolp value)
703       (and (listp value)
704            (eq (length value) 2)
705            (eq (nth 0 value) 'not)
706            (symbolp (nth 1 value)))))
707
708 (defun gnus-widget-reversible-to-internal (widget value)
709   "Ignoring WIDGET, convert VALUE to internal form.
710 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
711 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
712   ;; (debug value)
713   (if (atom value)
714       (list value nil)
715     (list (nth 1 value) t)))
716
717 (defun gnus-widget-reversible-to-external (widget value)
718   "Ignoring WIDGET, convert VALUE to external form.
719 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
720 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
721   ;; (debug value)
722   (if (nth 1 value)
723       (list 'not (nth 0 value))
724     (nth 0 value)))
725
726 (define-widget 'gnus-widget-reversible 'group
727   "A `group' that convert values."
728   :match 'gnus-widget-reversible-match
729   :value-to-internal 'gnus-widget-reversible-to-internal
730   :value-to-external 'gnus-widget-reversible-to-external)
731
732 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
733   "*List of functions used for sorting articles in the summary buffer.
734
735 Each function takes two articles and returns non-nil if the first
736 article should be sorted before the other.  If you use more than one
737 function, the primary sort function should be the last.  You should
738 probably always include `gnus-article-sort-by-number' in the list of
739 sorting functions -- preferably first.  Also note that sorting by date
740 is often much slower than sorting by number, and the sorting order is
741 very similar.  (Sorting by date means sorting by the time the message
742 was sent, sorting by number means sorting by arrival time.)
743
744 Each item can also be a list `(not F)' where F is a function;
745 this reverses the sort order.
746
747 Ready-made functions include `gnus-article-sort-by-number',
748 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
749 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
750 and `gnus-article-sort-by-score'.
751
752 When threading is turned on, the variable `gnus-thread-sort-functions'
753 controls how articles are sorted."
754   :group 'gnus-summary-sort
755   :type '(repeat (gnus-widget-reversible
756                   (choice (function-item gnus-article-sort-by-number)
757                           (function-item gnus-article-sort-by-author)
758                           (function-item gnus-article-sort-by-subject)
759                           (function-item gnus-article-sort-by-date)
760                           (function-item gnus-article-sort-by-score)
761                           (function-item gnus-article-sort-by-random)
762                           (function :tag "other"))
763                   (boolean :tag "Reverse order"))))
764
765
766 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
767   "*List of functions used for sorting threads in the summary buffer.
768 By default, threads are sorted by article number.
769
770 Each function takes two threads and returns non-nil if the first
771 thread should be sorted before the other.  If you use more than one
772 function, the primary sort function should be the last.  You should
773 probably always include `gnus-thread-sort-by-number' in the list of
774 sorting functions -- preferably first.  Also note that sorting by date
775 is often much slower than sorting by number, and the sorting order is
776 very similar.  (Sorting by date means sorting by the time the message
777 was sent, sorting by number means sorting by arrival time.)
778
779 Each list item can also be a list `(not F)' where F is a
780 function; this specifies reversed sort order.
781
782 Ready-made functions include `gnus-thread-sort-by-number',
783 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
784 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
785 `gnus-thread-sort-by-most-recent-number',
786 `gnus-thread-sort-by-most-recent-date',
787 `gnus-thread-sort-by-random', and
788 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
789
790 When threading is turned off, the variable
791 `gnus-article-sort-functions' controls how articles are sorted."
792   :group 'gnus-summary-sort
793   :type '(repeat 
794           (gnus-widget-reversible
795            (choice (function-item gnus-thread-sort-by-number)
796                    (function-item gnus-thread-sort-by-author)
797                    (function-item gnus-thread-sort-by-subject)
798                    (function-item gnus-thread-sort-by-date)
799                    (function-item gnus-thread-sort-by-score)
800                    (function-item gnus-thread-sort-by-most-recent-number)
801                    (function-item gnus-thread-sort-by-most-recent-date)
802                    (function-item gnus-thread-sort-by-random)
803                    (function-item gnus-thread-sort-by-total-score)
804                    (function :tag "other"))
805            (boolean :tag "Reverse order"))))
806
807 (defcustom gnus-thread-score-function '+
808   "*Function used for calculating the total score of a thread.
809
810 The function is called with the scores of the article and each
811 subthread and should then return the score of the thread.
812
813 Some functions you can use are `+', `max', or `min'."
814   :group 'gnus-summary-sort
815   :type 'function)
816
817 (defcustom gnus-summary-expunge-below nil
818   "All articles that have a score less than this variable will be expunged.
819 This variable is local to the summary buffers."
820   :group 'gnus-score-default
821   :type '(choice (const :tag "off" nil)
822                  integer))
823
824 (defcustom gnus-thread-expunge-below nil
825   "All threads that have a total score less than this variable will be expunged.
826 See `gnus-thread-score-function' for en explanation of what a
827 \"thread score\" is.
828
829 This variable is local to the summary buffers."
830   :group 'gnus-threading
831   :group 'gnus-score-default
832   :type '(choice (const :tag "off" nil)
833                  integer))
834
835 (defcustom gnus-summary-mode-hook nil
836   "*A hook for Gnus summary mode.
837 This hook is run before any variables are set in the summary buffer."
838   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
839   :group 'gnus-summary-various
840   :type 'hook)
841
842 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
843 (when (featurep 'xemacs)
844   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
845   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
846   (add-hook 'gnus-summary-mode-hook
847             'gnus-xmas-switch-horizontal-scrollbar-off))
848
849 (defcustom gnus-summary-menu-hook nil
850   "*Hook run after the creation of the summary mode menu."
851   :group 'gnus-summary-visual
852   :type 'hook)
853
854 (defcustom gnus-summary-exit-hook nil
855   "*A hook called on exit from the summary buffer.
856 It will be called with point in the group buffer."
857   :group 'gnus-summary-exit
858   :type 'hook)
859
860 (defcustom gnus-summary-prepare-hook nil
861   "*A hook called after the summary buffer has been generated.
862 If you want to modify the summary buffer, you can use this hook."
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 (defcustom gnus-summary-prepared-hook nil
867   "*A hook called as the last thing after the summary buffer has been generated."
868   :group 'gnus-summary-various
869   :type 'hook)
870
871 (defcustom gnus-summary-generate-hook nil
872   "*A hook run just before generating the summary buffer.
873 This hook is commonly used to customize threading variables and the
874 like."
875   :group 'gnus-summary-various
876   :type 'hook)
877
878 (defcustom gnus-select-group-hook nil
879   "*A hook called when a newsgroup is selected.
880
881 If you'd like to simplify subjects like the
882 `gnus-summary-next-same-subject' command does, you can use the
883 following hook:
884
885  (add-hook gnus-select-group-hook
886            (lambda ()
887              (mapcar (lambda (header)
888                        (mail-header-set-subject
889                         header
890                         (gnus-simplify-subject
891                          (mail-header-subject header) 're-only)))
892                      gnus-newsgroup-headers)))"
893   :group 'gnus-group-select
894   :type 'hook)
895
896 (defcustom gnus-select-article-hook nil
897   "*A hook called when an article is selected."
898   :group 'gnus-summary-choose
899   :options '(gnus-agent-fetch-selected-article)
900   :type 'hook)
901
902 (defcustom gnus-visual-mark-article-hook
903   (list 'gnus-highlight-selected-summary)
904   "*Hook run after selecting an article in the summary buffer.
905 It is meant to be used for highlighting the article in some way.  It
906 is not run if `gnus-visual' is nil."
907   :group 'gnus-summary-visual
908   :type 'hook)
909
910 (defcustom gnus-parse-headers-hook nil
911   "*A hook called before parsing the headers."
912   :group 'gnus-various
913   :type 'hook)
914
915 (defcustom gnus-exit-group-hook nil
916   "*A hook called when exiting summary mode.
917 This hook is not called from the non-updating exit commands like `Q'."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-summary-update-hook
922   (list 'gnus-summary-highlight-line)
923   "*A hook called when a summary line is changed.
924 The hook will not be called if `gnus-visual' is nil.
925
926 The default function `gnus-summary-highlight-line' will
927 highlight the line according to the `gnus-summary-highlight'
928 variable."
929   :group 'gnus-summary-visual
930   :type 'hook)
931
932 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
933   "*A hook called when an article is selected for the first time.
934 The hook is intended to mark an article as read (or unread)
935 automatically when it is selected."
936   :group 'gnus-summary-choose
937   :type 'hook)
938
939 (defcustom gnus-group-no-more-groups-hook nil
940   "*A hook run when returning to group mode having no more (unread) groups."
941   :group 'gnus-group-select
942   :type 'hook)
943
944 (defcustom gnus-ps-print-hook nil
945   "*A hook run before ps-printing something from Gnus."
946   :group 'gnus-summary
947   :type 'hook)
948
949 (defcustom gnus-summary-article-move-hook nil
950   "*A hook called after an article is moved, copied, respooled, or crossposted."
951   :version "21.4"
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-delete-hook nil
956   "*A hook called after an article is deleted."
957   :version "21.4"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-expire-hook nil
962   "*A hook called after an article is expired."
963   :version "21.4"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-display-arrow
968   (and (fboundp 'display-graphic-p)
969        (display-graphic-p))
970   "*If non-nil, display an arrow highlighting the current article."
971   :version "21.4"
972   :group 'gnus-summary
973   :type 'boolean)
974
975 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
976   "Face used for highlighting the current article in the summary buffer."
977   :group 'gnus-summary-visual
978   :type 'face)
979
980 (defvar gnus-tmp-downloaded nil)
981
982 (defcustom gnus-summary-highlight
983   '(((eq mark gnus-canceled-mark)
984      . gnus-summary-cancelled-face)
985     ((and uncached (> score default-high))
986      . gnus-summary-high-undownloaded-face)
987     ((and uncached (< score default-low))
988      . gnus-summary-low-undownloaded-face)
989     (uncached
990      . gnus-summary-normal-undownloaded-face)
991     ((and (> score default-high)
992           (or (eq mark gnus-dormant-mark)
993               (eq mark gnus-ticked-mark)))
994      . gnus-summary-high-ticked-face)
995     ((and (< score default-low)
996           (or (eq mark gnus-dormant-mark)
997               (eq mark gnus-ticked-mark)))
998      . gnus-summary-low-ticked-face)
999     ((or (eq mark gnus-dormant-mark)
1000          (eq mark gnus-ticked-mark))
1001      . gnus-summary-normal-ticked-face)
1002     ((and (> score default-high) (eq mark gnus-ancient-mark))
1003      . gnus-summary-high-ancient-face)
1004     ((and (< score default-low) (eq mark gnus-ancient-mark))
1005      . gnus-summary-low-ancient-face)
1006     ((eq mark gnus-ancient-mark)
1007      . gnus-summary-normal-ancient-face)
1008     ((and (> score default-high) (eq mark gnus-unread-mark))
1009      . gnus-summary-high-unread-face)
1010     ((and (< score default-low) (eq mark gnus-unread-mark))
1011      . gnus-summary-low-unread-face)
1012     ((eq mark gnus-unread-mark)
1013      . gnus-summary-normal-unread-face)
1014     ((> score default-high)
1015      . gnus-summary-high-read-face)
1016     ((< score default-low)
1017      . gnus-summary-low-read-face)
1018     (t
1019      . gnus-summary-normal-read-face))
1020   "*Controls the highlighting of summary buffer lines.
1021
1022 A list of (FORM . FACE) pairs.  When deciding how a a particular
1023 summary line should be displayed, each form is evaluated.  The content
1024 of the face field after the first true form is used.  You can change
1025 how those summary lines are displayed, by editing the face field.
1026
1027 You can use the following variables in the FORM field.
1028
1029 score:        The article's score
1030 default:      The default article score.
1031 default-high: The default score for high scored articles.
1032 default-low:  The default score for low scored articles.
1033 below:        The score below which articles are automatically marked as read.
1034 mark:         The article's mark.
1035 uncached:     Non-nil if the article is uncached."
1036   :group 'gnus-summary-visual
1037   :type '(repeat (cons (sexp :tag "Form" nil)
1038                        face)))
1039
1040 (defcustom gnus-alter-header-function nil
1041   "Function called to allow alteration of article header structures.
1042 The function is called with one parameter, the article header vector,
1043 which it may alter in any way."
1044   :type '(choice (const :tag "None" nil)
1045                  function)
1046   :group 'gnus-summary)
1047
1048 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1049   "Variable that says which function should be used to decode a string with encoded words.")
1050
1051 (defcustom gnus-extra-headers '(To Newsgroups)
1052   "*Extra headers to parse."
1053   :version "21.1"
1054   :group 'gnus-summary
1055   :type '(repeat symbol))
1056
1057 (defcustom gnus-ignored-from-addresses
1058   (and user-mail-address (regexp-quote user-mail-address))
1059   "*Regexp of From headers that may be suppressed in favor of To headers."
1060   :version "21.1"
1061   :group 'gnus-summary
1062   :type 'regexp)
1063
1064 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1065   "List of charsets that should be ignored.
1066 When these charsets are used in the \"charset\" parameter, the
1067 default charset will be used instead."
1068   :version "21.1"
1069   :type '(repeat symbol)
1070   :group 'gnus-charset)
1071
1072 (gnus-define-group-parameter
1073  ignored-charsets
1074  :type list
1075  :function-document
1076  "Return the ignored charsets of GROUP."
1077  :variable gnus-group-ignored-charsets-alist
1078  :variable-default
1079  '(("alt\\.chinese\\.text" iso-8859-1))
1080  :variable-document
1081  "Alist of regexps (to match group names) and charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084  :variable-group gnus-charset
1085  :variable-type '(repeat (cons (regexp :tag "Group")
1086                                (repeat symbol)))
1087  :parameter-type '(choice :tag "Ignored charsets"
1088                           :value nil
1089                           (repeat (symbol)))
1090  :parameter-document       "\
1091 List of charsets that should be ignored.
1092
1093 When these charsets are used in the \"charset\" parameter, the
1094 default charset will be used instead.")
1095
1096 (defcustom gnus-group-highlight-words-alist nil
1097   "Alist of group regexps and highlight regexps.
1098 This variable uses the same syntax as `gnus-emphasis-alist'."
1099   :version "21.1"
1100   :type '(repeat (cons (regexp :tag "Group")
1101                        (repeat (list (regexp :tag "Highlight regexp")
1102                                      (number :tag "Group for entire word" 0)
1103                                      (number :tag "Group for displayed part" 0)
1104                                      (symbol :tag "Face"
1105                                              gnus-emphasis-highlight-words)))))
1106   :group 'gnus-summary-visual)
1107
1108 (defcustom gnus-summary-show-article-charset-alist
1109   nil
1110   "Alist of number and charset.
1111 The article will be shown with the charset corresponding to the
1112 numbered argument.
1113 For example: ((1 . cn-gb-2312) (2 . big5))."
1114   :version "21.1"
1115   :type '(repeat (cons (number :tag "Argument" 1)
1116                        (symbol :tag "Charset")))
1117   :group 'gnus-charset)
1118
1119 (defcustom gnus-preserve-marks t
1120   "Whether marks are preserved when moving, copying and respooling messages."
1121   :version "21.1"
1122   :type 'boolean
1123   :group 'gnus-summary-marks)
1124
1125 (defcustom gnus-alter-articles-to-read-function nil
1126   "Function to be called to alter the list of articles to be selected."
1127   :type '(choice (const nil) function)
1128   :group 'gnus-summary)
1129
1130 (defcustom gnus-orphan-score nil
1131   "*All orphans get this score added.  Set in the score file."
1132   :group 'gnus-score-default
1133   :type '(choice (const nil)
1134                  integer))
1135
1136 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1137   "*A regexp to match MIME parts when saving multiple parts of a
1138 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1139 This regexp will be used by default when prompting the user for which
1140 type of files to save."
1141   :group 'gnus-summary
1142   :type 'regexp)
1143
1144 (defcustom gnus-read-all-available-headers nil
1145   "Whether Gnus should parse all headers made available to it.
1146 This is mostly relevant for slow back ends where the user may
1147 wish to widen the summary buffer to include all headers
1148 that were fetched.  Say, for nnultimate groups."
1149   :version "21.4"
1150   :group 'gnus-summary
1151   :type '(choice boolean regexp))
1152
1153 (defcustom gnus-summary-muttprint-program "muttprint"
1154   "Command (and optional arguments) used to run Muttprint."
1155   :version "21.4"
1156   :group 'gnus-summary
1157   :type 'string)
1158
1159 (defcustom gnus-article-loose-mime t
1160   "If non-nil, don't require MIME-Version header.
1161 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1162 supply the MIME-Version header or deliberately strip it from the mail.
1163 If non-nil (the default), Gnus will treat some articles as MIME
1164 even if the MIME-Version header is missing."
1165   :version "21.4"
1166   :type 'boolean
1167   :group 'gnus-article-mime)
1168
1169 (defcustom gnus-article-emulate-mime t
1170   "If non-nil, use MIME emulation for uuencode and the like.
1171 This means that Gnus will search message bodies for text that look
1172 like uuencoded bits, yEncoded bits, and so on, and present that using
1173 the normal Gnus MIME machinery."
1174   :version "21.4"
1175   :type 'boolean
1176   :group 'gnus-article-mime)
1177
1178 ;;; Internal variables
1179
1180 (defvar gnus-summary-display-cache nil)
1181 (defvar gnus-article-mime-handles nil)
1182 (defvar gnus-article-decoded-p nil)
1183 (defvar gnus-article-charset nil)
1184 (defvar gnus-article-ignored-charsets nil)
1185 (defvar gnus-scores-exclude-files nil)
1186 (defvar gnus-page-broken nil)
1187
1188 (defvar gnus-original-article nil)
1189 (defvar gnus-article-internal-prepare-hook nil)
1190 (defvar gnus-newsgroup-process-stack nil)
1191
1192 (defvar gnus-thread-indent-array nil)
1193 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1194 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1195   "Function called to sort the articles within a thread after it has been gathered together.")
1196
1197 (defvar gnus-summary-save-parts-type-history nil)
1198 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1199
1200 ;; Avoid highlighting in kill files.
1201 (defvar gnus-summary-inhibit-highlight nil)
1202 (defvar gnus-newsgroup-selected-overlay nil)
1203 (defvar gnus-inhibit-limiting nil)
1204 (defvar gnus-newsgroup-adaptive-score-file nil)
1205 (defvar gnus-current-score-file nil)
1206 (defvar gnus-current-move-group nil)
1207 (defvar gnus-current-copy-group nil)
1208 (defvar gnus-current-crosspost-group nil)
1209 (defvar gnus-newsgroup-display nil)
1210
1211 (defvar gnus-newsgroup-dependencies nil)
1212 (defvar gnus-newsgroup-adaptive nil)
1213 (defvar gnus-summary-display-article-function nil)
1214 (defvar gnus-summary-highlight-line-function nil
1215   "Function called after highlighting a summary line.")
1216
1217 (defvar gnus-summary-line-format-alist
1218   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1219     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1220     (?s gnus-tmp-subject-or-nil ?s)
1221     (?n gnus-tmp-name ?s)
1222     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1223         ?s)
1224     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1225             gnus-tmp-from) ?s)
1226     (?F gnus-tmp-from ?s)
1227     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1228     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1229     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1230     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1231     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1232     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1233     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1234     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1235     (?L gnus-tmp-lines ?s)
1236     (?O gnus-tmp-downloaded ?c)
1237     (?I gnus-tmp-indentation ?s)
1238     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1239     (?R gnus-tmp-replied ?c)
1240     (?\[ gnus-tmp-opening-bracket ?c)
1241     (?\] gnus-tmp-closing-bracket ?c)
1242     (?\> (make-string gnus-tmp-level ? ) ?s)
1243     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1244     (?i gnus-tmp-score ?d)
1245     (?z gnus-tmp-score-char ?c)
1246     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1247     (?U gnus-tmp-unread ?c)
1248     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1249         ?s)
1250     (?t (gnus-summary-number-of-articles-in-thread
1251          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1252         ?d)
1253     (?e (gnus-summary-number-of-articles-in-thread
1254          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1255         ?c)
1256     (?u gnus-tmp-user-defined ?s)
1257     (?P (gnus-pick-line-number) ?d)
1258     (?B gnus-tmp-thread-tree-header-string ?s)
1259     (user-date (gnus-user-date
1260                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1261   "An alist of format specifications that can appear in summary lines.
1262 These are paired with what variables they correspond with, along with
1263 the type of the variable (string, integer, character, etc).")
1264
1265 (defvar gnus-summary-dummy-line-format-alist
1266   `((?S gnus-tmp-subject ?s)
1267     (?N gnus-tmp-number ?d)
1268     (?u gnus-tmp-user-defined ?s)))
1269
1270 (defvar gnus-summary-mode-line-format-alist
1271   `((?G gnus-tmp-group-name ?s)
1272     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1273     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1274     (?A gnus-tmp-article-number ?d)
1275     (?Z gnus-tmp-unread-and-unselected ?s)
1276     (?V gnus-version ?s)
1277     (?U gnus-tmp-unread-and-unticked ?d)
1278     (?S gnus-tmp-subject ?s)
1279     (?e gnus-tmp-unselected ?d)
1280     (?u gnus-tmp-user-defined ?s)
1281     (?d (length gnus-newsgroup-dormant) ?d)
1282     (?t (length gnus-newsgroup-marked) ?d)
1283     (?h (length gnus-newsgroup-spam-marked) ?d)
1284     (?r (length gnus-newsgroup-reads) ?d)
1285     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1286     (?E gnus-newsgroup-expunged-tally ?d)
1287     (?s (gnus-current-score-file-nondirectory) ?s)))
1288
1289 (defvar gnus-last-search-regexp nil
1290   "Default regexp for article search command.")
1291
1292 (defvar gnus-last-shell-command nil
1293   "Default shell command on article.")
1294
1295 (defvar gnus-newsgroup-agentized nil
1296   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1297 (defvar gnus-newsgroup-begin nil)
1298 (defvar gnus-newsgroup-end nil)
1299 (defvar gnus-newsgroup-last-rmail nil)
1300 (defvar gnus-newsgroup-last-mail nil)
1301 (defvar gnus-newsgroup-last-folder nil)
1302 (defvar gnus-newsgroup-last-file nil)
1303 (defvar gnus-newsgroup-auto-expire nil)
1304 (defvar gnus-newsgroup-active nil)
1305
1306 (defvar gnus-newsgroup-data nil)
1307 (defvar gnus-newsgroup-data-reverse nil)
1308 (defvar gnus-newsgroup-limit nil)
1309 (defvar gnus-newsgroup-limits nil)
1310 (defvar gnus-summary-use-undownloaded-faces nil)
1311
1312 (defvar gnus-newsgroup-unreads nil
1313   "Sorted list of unread articles in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-unselected nil
1316   "Sorted list of unselected unread articles in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-reads nil
1319   "Alist of read articles and article marks in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-expunged-tally nil)
1322
1323 (defvar gnus-newsgroup-marked nil
1324   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1325
1326 (defvar gnus-newsgroup-spam-marked nil
1327   "List of ranges of articles that have been marked as spam.")
1328
1329 (defvar gnus-newsgroup-killed nil
1330   "List of ranges of articles that have been through the scoring process.")
1331
1332 (defvar gnus-newsgroup-cached nil
1333   "Sorted list of articles that come from the article cache.")
1334
1335 (defvar gnus-newsgroup-saved nil
1336   "List of articles that have been saved.")
1337
1338 (defvar gnus-newsgroup-kill-headers nil)
1339
1340 (defvar gnus-newsgroup-replied nil
1341   "List of articles that have been replied to in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-forwarded nil
1344   "List of articles that have been forwarded in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-recent nil
1347   "List of articles that have are recent in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-expirable nil
1350   "Sorted list of articles in the current newsgroup that can be expired.")
1351
1352 (defvar gnus-newsgroup-processable nil
1353   "List of articles in the current newsgroup that can be processed.")
1354
1355 (defvar gnus-newsgroup-downloadable nil
1356   "Sorted list of articles in the current newsgroup that can be processed.")
1357
1358 (defvar gnus-newsgroup-unfetched nil
1359   "Sorted list of articles in the current newsgroup whose headers have
1360 not been fetched into the agent.
1361
1362 This list will always be a subset of gnus-newsgroup-undownloaded.")
1363
1364 (defvar gnus-newsgroup-undownloaded nil
1365   "List of articles in the current newsgroup that haven't been downloaded.")
1366
1367 (defvar gnus-newsgroup-unsendable nil
1368   "List of articles in the current newsgroup that won't be sent.")
1369
1370 (defvar gnus-newsgroup-bookmarks nil
1371   "List of articles in the current newsgroup that have bookmarks.")
1372
1373 (defvar gnus-newsgroup-dormant nil
1374   "Sorted list of dormant articles in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-unseen nil
1377   "List of unseen articles in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-seen nil
1380   "Range of seen articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-articles nil
1383   "List of articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-scored nil
1386   "List of scored articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-headers nil
1389   "List of article headers in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-threads nil)
1392
1393 (defvar gnus-newsgroup-prepared nil
1394   "Whether the current group has been prepared properly.")
1395
1396 (defvar gnus-newsgroup-ancient nil
1397   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-sparse nil)
1400
1401 (defvar gnus-current-article nil)
1402 (defvar gnus-article-current nil)
1403 (defvar gnus-current-headers nil)
1404 (defvar gnus-have-all-headers nil)
1405 (defvar gnus-last-article nil)
1406 (defvar gnus-newsgroup-history nil)
1407 (defvar gnus-newsgroup-charset nil)
1408 (defvar gnus-newsgroup-ephemeral-charset nil)
1409 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1410
1411 (defvar gnus-article-before-search nil)
1412
1413 (defvar gnus-summary-local-variables
1414   '(gnus-newsgroup-name
1415     gnus-newsgroup-begin gnus-newsgroup-end
1416     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1417     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1418     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1419     gnus-newsgroup-unselected gnus-newsgroup-marked
1420     gnus-newsgroup-spam-marked
1421     gnus-newsgroup-reads gnus-newsgroup-saved
1422     gnus-newsgroup-replied gnus-newsgroup-forwarded
1423     gnus-newsgroup-recent
1424     gnus-newsgroup-expirable
1425     gnus-newsgroup-processable gnus-newsgroup-killed
1426     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1427     gnus-newsgroup-unfetched
1428     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1429     gnus-newsgroup-seen gnus-newsgroup-articles
1430     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1431     gnus-newsgroup-headers gnus-newsgroup-threads
1432     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1433     gnus-current-article gnus-current-headers gnus-have-all-headers
1434     gnus-last-article gnus-article-internal-prepare-hook
1435     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1436     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1437     gnus-thread-expunge-below
1438     gnus-score-alist gnus-current-score-file
1439     (gnus-summary-expunge-below . global)
1440     (gnus-summary-mark-below . global)
1441     (gnus-orphan-score . global)
1442     gnus-newsgroup-active gnus-scores-exclude-files
1443     gnus-newsgroup-history gnus-newsgroup-ancient
1444     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1445     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1446     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1447     (gnus-newsgroup-expunged-tally . 0)
1448     gnus-cache-removable-articles gnus-newsgroup-cached
1449     gnus-newsgroup-data gnus-newsgroup-data-reverse
1450     gnus-newsgroup-limit gnus-newsgroup-limits
1451     gnus-newsgroup-charset gnus-newsgroup-display
1452     gnus-summary-use-undownloaded-faces)
1453   "Variables that are buffer-local to the summary buffers.")
1454
1455 (defvar gnus-newsgroup-variables nil
1456   "A list of variables that have separate values in different newsgroups.
1457 A list of newsgroup (summary buffer) local variables, or cons of
1458 variables and their default expressions to be evalled (when the default
1459 values are not nil), that should be made global while the summary buffer
1460 is active.
1461
1462 Note: The default expressions will be evaluated (using function `eval')
1463 before assignment to the local variable rather than just assigned to it.
1464 If the default expression is the symbol `global', that symbol will not
1465 be evaluated but the global value of the local variable will be used
1466 instead.
1467
1468 These variables can be used to set variables in the group parameters
1469 while still allowing them to affect operations done in other buffers.
1470 For example:
1471
1472 \(setq gnus-newsgroup-variables
1473      '(message-use-followup-to
1474        (gnus-visible-headers .
1475          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1476 ")
1477
1478 ;; Byte-compiler warning.
1479 (eval-when-compile
1480   ;; Bind features so that require will believe that gnus-sum has
1481   ;; already been loaded (avoids infinite recursion)
1482   (let ((features (cons 'gnus-sum features)))
1483     ;; Several of the declarations in gnus-sum are needed to load the
1484     ;; following files. Right now, these definitions have been
1485     ;; compiled but not defined (evaluated).  We could either do a
1486     ;; eval-and-compile about all of the declarations or evaluate the
1487     ;; source file.
1488     (if (boundp 'gnus-newsgroup-variables)
1489         nil
1490       (load "gnus-sum.el" t t t))
1491     (require 'gnus)
1492     (require 'gnus-art)))
1493
1494 ;; MIME stuff.
1495
1496 (defvar gnus-decode-encoded-word-methods
1497   '(mail-decode-encoded-word-string)
1498   "List of methods used to decode encoded words.
1499
1500 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1501 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1502 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1503 whose names match REGEXP.
1504
1505 For example:
1506 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1507  mail-decode-encoded-word-string
1508  (\"chinese\" . rfc1843-decode-string))")
1509
1510 (defvar gnus-decode-encoded-word-methods-cache nil)
1511
1512 (defun gnus-multi-decode-encoded-word-string (string)
1513   "Apply the functions from `gnus-encoded-word-methods' that match."
1514   (unless (and gnus-decode-encoded-word-methods-cache
1515                (eq gnus-newsgroup-name
1516                    (car gnus-decode-encoded-word-methods-cache)))
1517     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1518     (mapcar (lambda (x)
1519               (if (symbolp x)
1520                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1521                 (if (and gnus-newsgroup-name
1522                          (string-match (car x) gnus-newsgroup-name))
1523                     (nconc gnus-decode-encoded-word-methods-cache
1524                            (list (cdr x))))))
1525             gnus-decode-encoded-word-methods))
1526   (let ((xlist gnus-decode-encoded-word-methods-cache))
1527     (pop xlist)
1528     (while xlist
1529       (setq string (funcall (pop xlist) string))))
1530   string)
1531
1532 ;; Subject simplification.
1533
1534 (defun gnus-simplify-whitespace (str)
1535   "Remove excessive whitespace from STR."
1536   ;; Multiple spaces.
1537   (while (string-match "[ \t][ \t]+" str)
1538     (setq str (concat (substring str 0 (match-beginning 0))
1539                         " "
1540                         (substring str (match-end 0)))))
1541   ;; Leading spaces.
1542   (when (string-match "^[ \t]+" str)
1543     (setq str (substring str (match-end 0))))
1544   ;; Trailing spaces.
1545   (when (string-match "[ \t]+$" str)
1546     (setq str (substring str 0 (match-beginning 0))))
1547   str)
1548
1549 (defun gnus-simplify-all-whitespace (str)
1550   "Remove all whitespace from STR."
1551   (while (string-match "[ \t\n]+" str)
1552     (setq str (replace-match "" nil nil str)))
1553   str)
1554
1555 (defsubst gnus-simplify-subject-re (subject)
1556   "Remove \"Re:\" from subject lines."
1557   (if (string-match message-subject-re-regexp subject)
1558       (substring subject (match-end 0))
1559     subject))
1560
1561 (defun gnus-simplify-subject (subject &optional re-only)
1562   "Remove `Re:' and words in parentheses.
1563 If RE-ONLY is non-nil, strip leading `Re:'s only."
1564   (let ((case-fold-search t))           ;Ignore case.
1565     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1566     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1567       (setq subject (substring subject (match-end 0))))
1568     ;; Remove uninteresting prefixes.
1569     (when (and (not re-only)
1570                gnus-simplify-ignored-prefixes
1571                (string-match gnus-simplify-ignored-prefixes subject))
1572       (setq subject (substring subject (match-end 0))))
1573     ;; Remove words in parentheses from end.
1574     (unless re-only
1575       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1576         (setq subject (substring subject 0 (match-beginning 0)))))
1577     ;; Return subject string.
1578     subject))
1579
1580 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1581 ;; all whitespace.
1582 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1583   (goto-char (point-min))
1584   (while (re-search-forward regexp nil t)
1585     (replace-match (or newtext ""))))
1586
1587 (defun gnus-simplify-buffer-fuzzy ()
1588   "Simplify string in the buffer fuzzily.
1589 The string in the accessible portion of the current buffer is simplified.
1590 It is assumed to be a single-line subject.
1591 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1592 matter is removed.  Additional things can be deleted by setting
1593 `gnus-simplify-subject-fuzzy-regexp'."
1594   (let ((case-fold-search t)
1595         (modified-tick))
1596     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1597
1598     (while (not (eq modified-tick (buffer-modified-tick)))
1599       (setq modified-tick (buffer-modified-tick))
1600       (cond
1601        ((listp gnus-simplify-subject-fuzzy-regexp)
1602         (mapcar 'gnus-simplify-buffer-fuzzy-step
1603                 gnus-simplify-subject-fuzzy-regexp))
1604        (gnus-simplify-subject-fuzzy-regexp
1605         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1606       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1607       (gnus-simplify-buffer-fuzzy-step
1608        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1609       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1610
1611     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1612     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1613     (gnus-simplify-buffer-fuzzy-step " $")
1614     (gnus-simplify-buffer-fuzzy-step "^ +")))
1615
1616 (defun gnus-simplify-subject-fuzzy (subject)
1617   "Simplify a subject string fuzzily.
1618 See `gnus-simplify-buffer-fuzzy' for details."
1619   (save-excursion
1620     (gnus-set-work-buffer)
1621     (let ((case-fold-search t))
1622       ;; Remove uninteresting prefixes.
1623       (when (and gnus-simplify-ignored-prefixes
1624                  (string-match gnus-simplify-ignored-prefixes subject))
1625         (setq subject (substring subject (match-end 0))))
1626       (insert subject)
1627       (inline (gnus-simplify-buffer-fuzzy))
1628       (buffer-string))))
1629
1630 (defsubst gnus-simplify-subject-fully (subject)
1631   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1632   (cond
1633    (gnus-simplify-subject-functions
1634     (gnus-map-function gnus-simplify-subject-functions subject))
1635    ((null gnus-summary-gather-subject-limit)
1636     (gnus-simplify-subject-re subject))
1637    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1638     (gnus-simplify-subject-fuzzy subject))
1639    ((numberp gnus-summary-gather-subject-limit)
1640     (gnus-limit-string (gnus-simplify-subject-re subject)
1641                        gnus-summary-gather-subject-limit))
1642    (t
1643     subject)))
1644
1645 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1646   "Check whether two subjects are equal.
1647 If optional argument SIMPLE-FIRST is t, first argument is already
1648 simplified."
1649   (cond
1650    ((null simple-first)
1651     (equal (gnus-simplify-subject-fully s1)
1652            (gnus-simplify-subject-fully s2)))
1653    (t
1654     (equal s1
1655            (gnus-simplify-subject-fully s2)))))
1656
1657 (defun gnus-summary-bubble-group ()
1658   "Increase the score of the current group.
1659 This is a handy function to add to `gnus-summary-exit-hook' to
1660 increase the score of each group you read."
1661   (gnus-group-add-score gnus-newsgroup-name))
1662
1663 \f
1664 ;;;
1665 ;;; Gnus summary mode
1666 ;;;
1667
1668 (put 'gnus-summary-mode 'mode-class 'special)
1669
1670 (defvar gnus-article-commands-menu)
1671
1672 ;; Non-orthogonal keys
1673
1674 (gnus-define-keys gnus-summary-mode-map
1675   " " gnus-summary-next-page
1676   "\177" gnus-summary-prev-page
1677   [delete] gnus-summary-prev-page
1678   [backspace] gnus-summary-prev-page
1679   "\r" gnus-summary-scroll-up
1680   "\M-\r" gnus-summary-scroll-down
1681   "n" gnus-summary-next-unread-article
1682   "p" gnus-summary-prev-unread-article
1683   "N" gnus-summary-next-article
1684   "P" gnus-summary-prev-article
1685   "\M-\C-n" gnus-summary-next-same-subject
1686   "\M-\C-p" gnus-summary-prev-same-subject
1687   "\M-n" gnus-summary-next-unread-subject
1688   "\M-p" gnus-summary-prev-unread-subject
1689   "." gnus-summary-first-unread-article
1690   "," gnus-summary-best-unread-article
1691   "\M-s" gnus-summary-search-article-forward
1692   "\M-r" gnus-summary-search-article-backward
1693   "<" gnus-summary-beginning-of-article
1694   ">" gnus-summary-end-of-article
1695   "j" gnus-summary-goto-article
1696   "^" gnus-summary-refer-parent-article
1697   "\M-^" gnus-summary-refer-article
1698   "u" gnus-summary-tick-article-forward
1699   "!" gnus-summary-tick-article-forward
1700   "U" gnus-summary-tick-article-backward
1701   "d" gnus-summary-mark-as-read-forward
1702   "D" gnus-summary-mark-as-read-backward
1703   "E" gnus-summary-mark-as-expirable
1704   "\M-u" gnus-summary-clear-mark-forward
1705   "\M-U" gnus-summary-clear-mark-backward
1706   "k" gnus-summary-kill-same-subject-and-select
1707   "\C-k" gnus-summary-kill-same-subject
1708   "\M-\C-k" gnus-summary-kill-thread
1709   "\M-\C-l" gnus-summary-lower-thread
1710   "e" gnus-summary-edit-article
1711   "#" gnus-summary-mark-as-processable
1712   "\M-#" gnus-summary-unmark-as-processable
1713   "\M-\C-t" gnus-summary-toggle-threads
1714   "\M-\C-s" gnus-summary-show-thread
1715   "\M-\C-h" gnus-summary-hide-thread
1716   "\M-\C-f" gnus-summary-next-thread
1717   "\M-\C-b" gnus-summary-prev-thread
1718   [(meta down)] gnus-summary-next-thread
1719   [(meta up)] gnus-summary-prev-thread
1720   "\M-\C-u" gnus-summary-up-thread
1721   "\M-\C-d" gnus-summary-down-thread
1722   "&" gnus-summary-execute-command
1723   "c" gnus-summary-catchup-and-exit
1724   "\C-w" gnus-summary-mark-region-as-read
1725   "\C-t" gnus-summary-toggle-truncation
1726   "?" gnus-summary-mark-as-dormant
1727   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1728   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1729   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1730   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1731   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1732   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1733   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1734   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1735   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1736   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1737   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1738   "=" gnus-summary-expand-window
1739   "\C-x\C-s" gnus-summary-reselect-current-group
1740   "\M-g" gnus-summary-rescan-group
1741   "w" gnus-summary-stop-page-breaking
1742   "\C-c\C-r" gnus-summary-caesar-message
1743   "f" gnus-summary-followup
1744   "F" gnus-summary-followup-with-original
1745   "C" gnus-summary-cancel-article
1746   "r" gnus-summary-reply
1747   "R" gnus-summary-reply-with-original
1748   "\C-c\C-f" gnus-summary-mail-forward
1749   "o" gnus-summary-save-article
1750   "\C-o" gnus-summary-save-article-mail
1751   "|" gnus-summary-pipe-output
1752   "\M-k" gnus-summary-edit-local-kill
1753   "\M-K" gnus-summary-edit-global-kill
1754   ;; "V" gnus-version
1755   "\C-c\C-d" gnus-summary-describe-group
1756   "q" gnus-summary-exit
1757   "Q" gnus-summary-exit-no-update
1758   "\C-c\C-i" gnus-info-find-node
1759   gnus-mouse-2 gnus-mouse-pick-article
1760   [follow-link] mouse-face
1761   "m" gnus-summary-mail-other-window
1762   "a" gnus-summary-post-news
1763   "i" gnus-summary-news-other-window
1764   "x" gnus-summary-limit-to-unread
1765   "s" gnus-summary-isearch-article
1766   "t" gnus-summary-toggle-header
1767   "g" gnus-summary-show-article
1768   "l" gnus-summary-goto-last-article
1769   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1770   "\C-d" gnus-summary-enter-digest-group
1771   "\M-\C-d" gnus-summary-read-document
1772   "\M-\C-e" gnus-summary-edit-parameters
1773   "\M-\C-a" gnus-summary-customize-parameters
1774   "\C-c\C-b" gnus-bug
1775   "*" gnus-cache-enter-article
1776   "\M-*" gnus-cache-remove-article
1777   "\M-&" gnus-summary-universal-argument
1778   "\C-l" gnus-recenter
1779   "I" gnus-summary-increase-score
1780   "L" gnus-summary-lower-score
1781   "\M-i" gnus-symbolic-argument
1782   "h" gnus-summary-select-article-buffer
1783
1784   "b" gnus-article-view-part
1785   "\M-t" gnus-summary-toggle-display-buttonized
1786
1787   "V" gnus-summary-score-map
1788   "X" gnus-uu-extract-map
1789   "S" gnus-summary-send-map)
1790
1791 ;; Sort of orthogonal keymap
1792 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1793   "t" gnus-summary-tick-article-forward
1794   "!" gnus-summary-tick-article-forward
1795   "d" gnus-summary-mark-as-read-forward
1796   "r" gnus-summary-mark-as-read-forward
1797   "c" gnus-summary-clear-mark-forward
1798   " " gnus-summary-clear-mark-forward
1799   "e" gnus-summary-mark-as-expirable
1800   "x" gnus-summary-mark-as-expirable
1801   "?" gnus-summary-mark-as-dormant
1802   "b" gnus-summary-set-bookmark
1803   "B" gnus-summary-remove-bookmark
1804   "#" gnus-summary-mark-as-processable
1805   "\M-#" gnus-summary-unmark-as-processable
1806   "S" gnus-summary-limit-include-expunged
1807   "C" gnus-summary-catchup
1808   "H" gnus-summary-catchup-to-here
1809   "h" gnus-summary-catchup-from-here
1810   "\C-c" gnus-summary-catchup-all
1811   "k" gnus-summary-kill-same-subject-and-select
1812   "K" gnus-summary-kill-same-subject
1813   "P" gnus-uu-mark-map)
1814
1815 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1816   "c" gnus-summary-clear-above
1817   "u" gnus-summary-tick-above
1818   "m" gnus-summary-mark-above
1819   "k" gnus-summary-kill-below)
1820
1821 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1822   "/" gnus-summary-limit-to-subject
1823   "n" gnus-summary-limit-to-articles
1824   "w" gnus-summary-pop-limit
1825   "s" gnus-summary-limit-to-subject
1826   "a" gnus-summary-limit-to-author
1827   "u" gnus-summary-limit-to-unread
1828   "m" gnus-summary-limit-to-marks
1829   "M" gnus-summary-limit-exclude-marks
1830   "v" gnus-summary-limit-to-score
1831   "*" gnus-summary-limit-include-cached
1832   "D" gnus-summary-limit-include-dormant
1833   "T" gnus-summary-limit-include-thread
1834   "d" gnus-summary-limit-exclude-dormant
1835   "t" gnus-summary-limit-to-age
1836   "." gnus-summary-limit-to-unseen
1837   "x" gnus-summary-limit-to-extra
1838   "p" gnus-summary-limit-to-display-predicate
1839   "E" gnus-summary-limit-include-expunged
1840   "c" gnus-summary-limit-exclude-childless-dormant
1841   "C" gnus-summary-limit-mark-excluded-as-read
1842   "o" gnus-summary-insert-old-articles
1843   "N" gnus-summary-insert-new-articles
1844   "r" gnus-summary-limit-to-replied
1845   "R" gnus-summary-limit-to-recipient)
1846
1847 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1848   "n" gnus-summary-next-unread-article
1849   "p" gnus-summary-prev-unread-article
1850   "N" gnus-summary-next-article
1851   "P" gnus-summary-prev-article
1852   "\C-n" gnus-summary-next-same-subject
1853   "\C-p" gnus-summary-prev-same-subject
1854   "\M-n" gnus-summary-next-unread-subject
1855   "\M-p" gnus-summary-prev-unread-subject
1856   "f" gnus-summary-first-unread-article
1857   "b" gnus-summary-best-unread-article
1858   "j" gnus-summary-goto-article
1859   "g" gnus-summary-goto-subject
1860   "l" gnus-summary-goto-last-article
1861   "o" gnus-summary-pop-article)
1862
1863 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1864   "k" gnus-summary-kill-thread
1865   "l" gnus-summary-lower-thread
1866   "i" gnus-summary-raise-thread
1867   "T" gnus-summary-toggle-threads
1868   "t" gnus-summary-rethread-current
1869   "^" gnus-summary-reparent-thread
1870   "s" gnus-summary-show-thread
1871   "S" gnus-summary-show-all-threads
1872   "h" gnus-summary-hide-thread
1873   "H" gnus-summary-hide-all-threads
1874   "n" gnus-summary-next-thread
1875   "p" gnus-summary-prev-thread
1876   "u" gnus-summary-up-thread
1877   "o" gnus-summary-top-thread
1878   "d" gnus-summary-down-thread
1879   "#" gnus-uu-mark-thread
1880   "\M-#" gnus-uu-unmark-thread)
1881
1882 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1883   "g" gnus-summary-prepare
1884   "c" gnus-summary-insert-cached-articles
1885   "d" gnus-summary-insert-dormant-articles)
1886
1887 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1888   "c" gnus-summary-catchup-and-exit
1889   "C" gnus-summary-catchup-all-and-exit
1890   "E" gnus-summary-exit-no-update
1891   "Q" gnus-summary-exit
1892   "Z" gnus-summary-exit
1893   "n" gnus-summary-catchup-and-goto-next-group
1894   "R" gnus-summary-reselect-current-group
1895   "G" gnus-summary-rescan-group
1896   "N" gnus-summary-next-group
1897   "s" gnus-summary-save-newsrc
1898   "P" gnus-summary-prev-group)
1899
1900 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1901   " " gnus-summary-next-page
1902   "n" gnus-summary-next-page
1903   "\177" gnus-summary-prev-page
1904   [delete] gnus-summary-prev-page
1905   "p" gnus-summary-prev-page
1906   "\r" gnus-summary-scroll-up
1907   "\M-\r" gnus-summary-scroll-down
1908   "<" gnus-summary-beginning-of-article
1909   ">" gnus-summary-end-of-article
1910   "b" gnus-summary-beginning-of-article
1911   "e" gnus-summary-end-of-article
1912   "^" gnus-summary-refer-parent-article
1913   "r" gnus-summary-refer-parent-article
1914   "D" gnus-summary-enter-digest-group
1915   "R" gnus-summary-refer-references
1916   "T" gnus-summary-refer-thread
1917   "g" gnus-summary-show-article
1918   "s" gnus-summary-isearch-article
1919   "P" gnus-summary-print-article
1920   "M" gnus-mailing-list-insinuate
1921   "t" gnus-article-babel)
1922
1923 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1924   "b" gnus-article-add-buttons
1925   "B" gnus-article-add-buttons-to-head
1926   "o" gnus-article-treat-overstrike
1927   "e" gnus-article-emphasize
1928   "w" gnus-article-fill-cited-article
1929   "Q" gnus-article-fill-long-lines
1930   "C" gnus-article-capitalize-sentences
1931   "c" gnus-article-remove-cr
1932   "q" gnus-article-de-quoted-unreadable
1933   "6" gnus-article-de-base64-unreadable
1934   "Z" gnus-article-decode-HZ
1935   "A" gnus-article-treat-ansi-sequences
1936   "h" gnus-article-wash-html
1937   "u" gnus-article-unsplit-urls
1938   "s" gnus-summary-force-verify-and-decrypt
1939   "f" gnus-article-display-x-face
1940   "l" gnus-summary-stop-page-breaking
1941   "r" gnus-summary-caesar-message
1942   "m" gnus-summary-morse-message
1943   "t" gnus-summary-toggle-header
1944   "g" gnus-treat-smiley
1945   "v" gnus-summary-verbose-headers
1946   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1947   "p" gnus-article-verify-x-pgp-sig
1948   "d" gnus-article-treat-dumbquotes
1949   "i" gnus-summary-idna-message)
1950
1951 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1952   ;; mnemonic: deuglif*Y*
1953   "u" gnus-article-outlook-unwrap-lines
1954   "a" gnus-article-outlook-repair-attribution
1955   "c" gnus-article-outlook-rearrange-citation
1956   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1957
1958 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1959   "a" gnus-article-hide
1960   "h" gnus-article-hide-headers
1961   "b" gnus-article-hide-boring-headers
1962   "s" gnus-article-hide-signature
1963   "c" gnus-article-hide-citation
1964   "C" gnus-article-hide-citation-in-followups
1965   "l" gnus-article-hide-list-identifiers
1966   "B" gnus-article-strip-banner
1967   "P" gnus-article-hide-pem
1968   "\C-c" gnus-article-hide-citation-maybe)
1969
1970 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1971   "a" gnus-article-highlight
1972   "h" gnus-article-highlight-headers
1973   "c" gnus-article-highlight-citation
1974   "s" gnus-article-highlight-signature)
1975
1976 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1977   "f" gnus-article-treat-fold-headers
1978   "u" gnus-article-treat-unfold-headers
1979   "n" gnus-article-treat-fold-newsgroups)
1980
1981 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1982   "x" gnus-article-display-x-face
1983   "d" gnus-article-display-face
1984   "s" gnus-treat-smiley
1985   "D" gnus-article-remove-images
1986   "f" gnus-treat-from-picon
1987   "m" gnus-treat-mail-picon
1988   "n" gnus-treat-newsgroups-picon)
1989
1990 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1991   "w" gnus-article-decode-mime-words
1992   "c" gnus-article-decode-charset
1993   "v" gnus-mime-view-all-parts
1994   "b" gnus-article-view-part)
1995
1996 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1997   "z" gnus-article-date-ut
1998   "u" gnus-article-date-ut
1999   "l" gnus-article-date-local
2000   "p" gnus-article-date-english
2001   "e" gnus-article-date-lapsed
2002   "o" gnus-article-date-original
2003   "i" gnus-article-date-iso8601
2004   "s" gnus-article-date-user)
2005
2006 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2007   "t" gnus-article-remove-trailing-blank-lines
2008   "l" gnus-article-strip-leading-blank-lines
2009   "m" gnus-article-strip-multiple-blank-lines
2010   "a" gnus-article-strip-blank-lines
2011   "A" gnus-article-strip-all-blank-lines
2012   "s" gnus-article-strip-leading-space
2013   "e" gnus-article-strip-trailing-space
2014   "w" gnus-article-remove-leading-whitespace)
2015
2016 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2017   "v" gnus-version
2018   "f" gnus-summary-fetch-faq
2019   "d" gnus-summary-describe-group
2020   "h" gnus-summary-describe-briefly
2021   "i" gnus-info-find-node
2022   "c" gnus-group-fetch-charter
2023   "C" gnus-group-fetch-control)
2024
2025 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2026   "e" gnus-summary-expire-articles
2027   "\M-\C-e" gnus-summary-expire-articles-now
2028   "\177" gnus-summary-delete-article
2029   [delete] gnus-summary-delete-article
2030   [backspace] gnus-summary-delete-article
2031   "m" gnus-summary-move-article
2032   "r" gnus-summary-respool-article
2033   "w" gnus-summary-edit-article
2034   "c" gnus-summary-copy-article
2035   "B" gnus-summary-crosspost-article
2036   "q" gnus-summary-respool-query
2037   "t" gnus-summary-respool-trace
2038   "i" gnus-summary-import-article
2039   "I" gnus-summary-create-article
2040   "p" gnus-summary-article-posted-p)
2041
2042 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2043   "o" gnus-summary-save-article
2044   "m" gnus-summary-save-article-mail
2045   "F" gnus-summary-write-article-file
2046   "r" gnus-summary-save-article-rmail
2047   "f" gnus-summary-save-article-file
2048   "b" gnus-summary-save-article-body-file
2049   "h" gnus-summary-save-article-folder
2050   "v" gnus-summary-save-article-vm
2051   "p" gnus-summary-pipe-output
2052   "P" gnus-summary-muttprint
2053   "s" gnus-soup-add-article)
2054
2055 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2056   "b" gnus-summary-display-buttonized
2057   "m" gnus-summary-repair-multipart
2058   "v" gnus-article-view-part
2059   "o" gnus-article-save-part
2060   "c" gnus-article-copy-part
2061   "C" gnus-article-view-part-as-charset
2062   "e" gnus-article-view-part-externally
2063   "E" gnus-article-encrypt-body
2064   "i" gnus-article-inline-part
2065   "|" gnus-article-pipe-part)
2066
2067 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2068   "p" gnus-summary-mark-as-processable
2069   "u" gnus-summary-unmark-as-processable
2070   "U" gnus-summary-unmark-all-processable
2071   "v" gnus-uu-mark-over
2072   "s" gnus-uu-mark-series
2073   "r" gnus-uu-mark-region
2074   "g" gnus-uu-unmark-region
2075   "R" gnus-uu-mark-by-regexp
2076   "G" gnus-uu-unmark-by-regexp
2077   "t" gnus-uu-mark-thread
2078   "T" gnus-uu-unmark-thread
2079   "a" gnus-uu-mark-all
2080   "b" gnus-uu-mark-buffer
2081   "S" gnus-uu-mark-sparse
2082   "k" gnus-summary-kill-process-mark
2083   "y" gnus-summary-yank-process-mark
2084   "w" gnus-summary-save-process-mark
2085   "i" gnus-uu-invert-processable)
2086
2087 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2088   ;;"x" gnus-uu-extract-any
2089   "m" gnus-summary-save-parts
2090   "u" gnus-uu-decode-uu
2091   "U" gnus-uu-decode-uu-and-save
2092   "s" gnus-uu-decode-unshar
2093   "S" gnus-uu-decode-unshar-and-save
2094   "o" gnus-uu-decode-save
2095   "O" gnus-uu-decode-save
2096   "b" gnus-uu-decode-binhex
2097   "B" gnus-uu-decode-binhex
2098   "p" gnus-uu-decode-postscript
2099   "P" gnus-uu-decode-postscript-and-save)
2100
2101 (gnus-define-keys
2102     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2103   "u" gnus-uu-decode-uu-view
2104   "U" gnus-uu-decode-uu-and-save-view
2105   "s" gnus-uu-decode-unshar-view
2106   "S" gnus-uu-decode-unshar-and-save-view
2107   "o" gnus-uu-decode-save-view
2108   "O" gnus-uu-decode-save-view
2109   "b" gnus-uu-decode-binhex-view
2110   "B" gnus-uu-decode-binhex-view
2111   "p" gnus-uu-decode-postscript-view
2112   "P" gnus-uu-decode-postscript-and-save-view)
2113
2114 (defvar gnus-article-post-menu nil)
2115
2116 (defconst gnus-summary-menu-maxlen 20)
2117
2118 (defun gnus-summary-menu-split (menu)
2119   ;; If we have lots of elements, divide them into groups of 20
2120   ;; and make a pane (or submenu) for each one.
2121   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2122       (let ((menu menu) sublists next
2123             (i 1))
2124         (while menu
2125           ;; Pull off the next gnus-summary-menu-maxlen elements
2126           ;; and make them the next element of sublist.
2127           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2128           (if next
2129               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2130                       nil))
2131           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2132                                              (aref (car (last menu)) 0)) menu)
2133                                sublists))
2134           (setq i (1+ i))
2135           (setq menu next))
2136         (nreverse sublists))
2137     ;; Few elements--put them all in one pane.
2138     menu))
2139
2140 (defun gnus-summary-make-menu-bar ()
2141   (gnus-turn-off-edit-menu 'summary)
2142
2143   (unless (boundp 'gnus-summary-misc-menu)
2144
2145     (easy-menu-define
2146       gnus-summary-kill-menu gnus-summary-mode-map ""
2147       (cons
2148        "Score"
2149        (nconc
2150         (list
2151          ["Customize" gnus-score-customize t])
2152         (gnus-make-score-map 'increase)
2153         (gnus-make-score-map 'lower)
2154         '(("Mark"
2155            ["Kill below" gnus-summary-kill-below t]
2156            ["Mark above" gnus-summary-mark-above t]
2157            ["Tick above" gnus-summary-tick-above t]
2158            ["Clear above" gnus-summary-clear-above t])
2159           ["Current score" gnus-summary-current-score t]
2160           ["Set score" gnus-summary-set-score t]
2161           ["Switch current score file..." gnus-score-change-score-file t]
2162           ["Set mark below..." gnus-score-set-mark-below t]
2163           ["Set expunge below..." gnus-score-set-expunge-below t]
2164           ["Edit current score file" gnus-score-edit-current-scores t]
2165           ["Edit score file" gnus-score-edit-file t]
2166           ["Trace score" gnus-score-find-trace t]
2167           ["Find words" gnus-score-find-favourite-words t]
2168           ["Rescore buffer" gnus-summary-rescore t]
2169           ["Increase score..." gnus-summary-increase-score t]
2170           ["Lower score..." gnus-summary-lower-score t]))))
2171
2172     ;; Define both the Article menu in the summary buffer and the
2173     ;; equivalent Commands menu in the article buffer here for
2174     ;; consistency.
2175     (let ((innards
2176            `(("Hide"
2177               ["All" gnus-article-hide t]
2178               ["Headers" gnus-article-hide-headers t]
2179               ["Signature" gnus-article-hide-signature t]
2180               ["Citation" gnus-article-hide-citation t]
2181               ["List identifiers" gnus-article-hide-list-identifiers t]
2182               ["Banner" gnus-article-strip-banner t]
2183               ["Boring headers" gnus-article-hide-boring-headers t])
2184              ("Highlight"
2185               ["All" gnus-article-highlight t]
2186               ["Headers" gnus-article-highlight-headers t]
2187               ["Signature" gnus-article-highlight-signature t]
2188               ["Citation" gnus-article-highlight-citation t])
2189              ("MIME"
2190               ["Words" gnus-article-decode-mime-words t]
2191               ["Charset" gnus-article-decode-charset t]
2192               ["QP" gnus-article-de-quoted-unreadable t]
2193               ["Base64" gnus-article-de-base64-unreadable t]
2194               ["View MIME buttons" gnus-summary-display-buttonized t]
2195               ["View all" gnus-mime-view-all-parts t]
2196               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2197               ["Encrypt body" gnus-article-encrypt-body
2198                :active (not (gnus-group-read-only-p))
2199                ,@(if (featurep 'xemacs) nil
2200                    '(:help "Encrypt the message body on disk"))]
2201               ["Extract all parts..." gnus-summary-save-parts t]
2202               ("Multipart"
2203                ["Repair multipart" gnus-summary-repair-multipart t]
2204                ["Pipe part..." gnus-article-pipe-part t]
2205                ["Inline part" gnus-article-inline-part t]
2206                ["Encrypt body" gnus-article-encrypt-body
2207                 :active (not (gnus-group-read-only-p))
2208                ,@(if (featurep 'xemacs) nil
2209                    '(:help "Encrypt the message body on disk"))]
2210                ["View part externally" gnus-article-view-part-externally t]
2211                ["View part with charset..." gnus-article-view-part-as-charset t]
2212                ["Copy part" gnus-article-copy-part t]
2213                ["Save part..." gnus-article-save-part t]
2214                ["View part" gnus-article-view-part t]))
2215              ("Date"
2216               ["Local" gnus-article-date-local t]
2217               ["ISO8601" gnus-article-date-iso8601 t]
2218               ["UT" gnus-article-date-ut t]
2219               ["Original" gnus-article-date-original t]
2220               ["Lapsed" gnus-article-date-lapsed t]
2221               ["User-defined" gnus-article-date-user t])
2222              ("Display"
2223               ["Remove images" gnus-article-remove-images t]
2224               ["Toggle smiley" gnus-treat-smiley t]
2225               ["Show X-Face" gnus-article-display-x-face t]
2226               ["Show picons in From" gnus-treat-from-picon t]
2227               ["Show picons in mail headers" gnus-treat-mail-picon t]
2228               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2229               ("View as different encoding"
2230                ,@(gnus-summary-menu-split
2231                   (mapcar
2232                    (lambda (cs)
2233                      ;; Since easymenu under Emacs doesn't allow
2234                      ;; lambda forms for menu commands, we should
2235                      ;; provide intern'ed function symbols.
2236                      (let ((command (intern (format "\
2237 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2238                        (fset command
2239                              `(lambda ()
2240                                 (interactive)
2241                                 (let ((gnus-summary-show-article-charset-alist
2242                                        '((1 . ,cs))))
2243                                   (gnus-summary-show-article 1))))
2244                        `[,(symbol-name cs) ,command t]))
2245                    (sort (if (fboundp 'coding-system-list)
2246                              (coding-system-list)
2247                            (mapcar 'car mm-mime-mule-charset-alist))
2248                          'string<)))))
2249              ("Washing"
2250               ("Remove Blanks"
2251                ["Leading" gnus-article-strip-leading-blank-lines t]
2252                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2253                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2254                ["All of the above" gnus-article-strip-blank-lines t]
2255                ["All" gnus-article-strip-all-blank-lines t]
2256                ["Leading space" gnus-article-strip-leading-space t]
2257                ["Trailing space" gnus-article-strip-trailing-space t]
2258                ["Leading space in headers"
2259                 gnus-article-remove-leading-whitespace t])
2260               ["Overstrike" gnus-article-treat-overstrike t]
2261               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2262               ["Emphasis" gnus-article-emphasize t]
2263               ["Word wrap" gnus-article-fill-cited-article t]
2264               ["Fill long lines" gnus-article-fill-long-lines t]
2265               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2266               ["Remove CR" gnus-article-remove-cr t]
2267               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2268               ["Base64" gnus-article-de-base64-unreadable t]
2269               ["Rot 13" gnus-summary-caesar-message
2270                ,@(if (featurep 'xemacs) '(t)
2271                    '(:help "\"Caesar rotate\" article by 13"))]
2272               ["De-IDNA" gnus-summary-idna-message t]
2273               ["Morse decode" gnus-summary-morse-message t]
2274               ["Unix pipe..." gnus-summary-pipe-message t]
2275               ["Add buttons" gnus-article-add-buttons t]
2276               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2277               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2278               ["Verbose header" gnus-summary-verbose-headers t]
2279               ["Toggle header" gnus-summary-toggle-header t]
2280               ["Unfold headers" gnus-article-treat-unfold-headers t]
2281               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2282               ["Html" gnus-article-wash-html t]
2283               ["Unsplit URLs" gnus-article-unsplit-urls t]
2284               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2285               ["Decode HZ" gnus-article-decode-HZ t]
2286               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2287               ("(Outlook) Deuglify"
2288                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2289                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2290                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2291                ["Full (Outlook) deuglify"
2292                 gnus-article-outlook-deuglify-article t])
2293               )
2294              ("Output"
2295               ["Save in default format..." gnus-summary-save-article
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Save article using default method"))]
2298               ["Save in file..." gnus-summary-save-article-file
2299                ,@(if (featurep 'xemacs) '(t)
2300                    '(:help "Save article in file"))]
2301               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2302               ["Save in MH folder..." gnus-summary-save-article-folder t]
2303               ["Save in VM folder..." gnus-summary-save-article-vm t]
2304               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2305               ["Save body in file..." gnus-summary-save-article-body-file t]
2306               ["Pipe through a filter..." gnus-summary-pipe-output t]
2307               ["Add to SOUP packet" gnus-soup-add-article t]
2308               ["Print with Muttprint..." gnus-summary-muttprint t]
2309               ["Print" gnus-summary-print-article
2310                ,@(if (featurep 'xemacs) '(t)
2311                    '(:help "Generate and print a PostScript image"))])
2312              ("Copy, move,... (Backend)"
2313               ,@(if (featurep 'xemacs) nil
2314                   '(:help "Copying, moving, expiring articles..."))
2315               ["Respool article..." gnus-summary-respool-article t]
2316               ["Move article..." gnus-summary-move-article
2317                (gnus-check-backend-function
2318                 'request-move-article gnus-newsgroup-name)]
2319               ["Copy article..." gnus-summary-copy-article t]
2320               ["Crosspost article..." gnus-summary-crosspost-article
2321                (gnus-check-backend-function
2322                 'request-replace-article gnus-newsgroup-name)]
2323               ["Import file..." gnus-summary-import-article
2324                (gnus-check-backend-function
2325                 'request-accept-article gnus-newsgroup-name)]
2326               ["Create article..." gnus-summary-create-article
2327                (gnus-check-backend-function
2328                 'request-accept-article gnus-newsgroup-name)]
2329               ["Check if posted" gnus-summary-article-posted-p t]
2330               ["Edit article" gnus-summary-edit-article
2331                (not (gnus-group-read-only-p))]
2332               ["Delete article" gnus-summary-delete-article
2333                (gnus-check-backend-function
2334                 'request-expire-articles gnus-newsgroup-name)]
2335               ["Query respool" gnus-summary-respool-query t]
2336               ["Trace respool" gnus-summary-respool-trace t]
2337               ["Delete expirable articles" gnus-summary-expire-articles-now
2338                (gnus-check-backend-function
2339                 'request-expire-articles gnus-newsgroup-name)])
2340              ("Extract"
2341               ["Uudecode" gnus-uu-decode-uu
2342                ,@(if (featurep 'xemacs) '(t)
2343                    '(:help "Decode uuencoded article(s)"))]
2344               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2345               ["Unshar" gnus-uu-decode-unshar t]
2346               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2347               ["Save" gnus-uu-decode-save t]
2348               ["Binhex" gnus-uu-decode-binhex t]
2349               ["Postscript" gnus-uu-decode-postscript t]
2350               ["All MIME parts" gnus-summary-save-parts t])
2351              ("Cache"
2352               ["Enter article" gnus-cache-enter-article t]
2353               ["Remove article" gnus-cache-remove-article t])
2354              ["Translate" gnus-article-babel t]
2355              ["Select article buffer" gnus-summary-select-article-buffer t]
2356              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2357              ["Isearch article..." gnus-summary-isearch-article t]
2358              ["Beginning of the article" gnus-summary-beginning-of-article t]
2359              ["End of the article" gnus-summary-end-of-article t]
2360              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2361              ["Fetch referenced articles" gnus-summary-refer-references t]
2362              ["Fetch current thread" gnus-summary-refer-thread t]
2363              ["Fetch article with id..." gnus-summary-refer-article t]
2364              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2365              ["Redisplay" gnus-summary-show-article t]
2366              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2367       (easy-menu-define
2368         gnus-summary-article-menu gnus-summary-mode-map ""
2369         (cons "Article" innards))
2370
2371       (if (not (keymapp gnus-summary-article-menu))
2372           (easy-menu-define
2373             gnus-article-commands-menu gnus-article-mode-map ""
2374             (cons "Commands" innards))
2375         ;; in Emacs, don't share menu.
2376         (setq gnus-article-commands-menu
2377               (copy-keymap gnus-summary-article-menu))
2378         (define-key gnus-article-mode-map [menu-bar commands]
2379           (cons "Commands" gnus-article-commands-menu))))
2380
2381     (easy-menu-define
2382       gnus-summary-thread-menu gnus-summary-mode-map ""
2383       '("Threads"
2384         ["Find all messages in thread" gnus-summary-refer-thread t]
2385         ["Toggle threading" gnus-summary-toggle-threads t]
2386         ["Hide threads" gnus-summary-hide-all-threads t]
2387         ["Show threads" gnus-summary-show-all-threads t]
2388         ["Hide thread" gnus-summary-hide-thread t]
2389         ["Show thread" gnus-summary-show-thread t]
2390         ["Go to next thread" gnus-summary-next-thread t]
2391         ["Go to previous thread" gnus-summary-prev-thread t]
2392         ["Go down thread" gnus-summary-down-thread t]
2393         ["Go up thread" gnus-summary-up-thread t]
2394         ["Top of thread" gnus-summary-top-thread t]
2395         ["Mark thread as read" gnus-summary-kill-thread t]
2396         ["Lower thread score" gnus-summary-lower-thread t]
2397         ["Raise thread score" gnus-summary-raise-thread t]
2398         ["Rethread current" gnus-summary-rethread-current t]))
2399
2400     (easy-menu-define
2401       gnus-summary-post-menu gnus-summary-mode-map ""
2402       `("Post"
2403         ["Send a message (mail or news)" gnus-summary-post-news
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Compose a new message (mail or news)"))]
2406         ["Followup" gnus-summary-followup
2407          ,@(if (featurep 'xemacs) '(t)
2408              '(:help "Post followup to this article"))]
2409         ["Followup and yank" gnus-summary-followup-with-original
2410          ,@(if (featurep 'xemacs) '(t)
2411              '(:help "Post followup to this article, quoting its contents"))]
2412         ["Supersede article" gnus-summary-supersede-article t]
2413         ["Cancel article" gnus-summary-cancel-article
2414          ,@(if (featurep 'xemacs) '(t)
2415              '(:help "Cancel an article you posted"))]
2416         ["Reply" gnus-summary-reply t]
2417         ["Reply and yank" gnus-summary-reply-with-original t]
2418         ["Wide reply" gnus-summary-wide-reply t]
2419         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2420          ,@(if (featurep 'xemacs) '(t)
2421              '(:help "Mail a reply, quoting this article"))]
2422         ["Very wide reply" gnus-summary-very-wide-reply t]
2423         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2424          ,@(if (featurep 'xemacs) '(t)
2425              '(:help "Mail a very wide reply, quoting this article"))]
2426         ["Mail forward" gnus-summary-mail-forward t]
2427         ["Post forward" gnus-summary-post-forward t]
2428         ["Digest and mail" gnus-uu-digest-mail-forward t]
2429         ["Digest and post" gnus-uu-digest-post-forward t]
2430         ["Resend message" gnus-summary-resend-message t]
2431         ["Resend message edit" gnus-summary-resend-message-edit t]
2432         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2433         ["Send a mail" gnus-summary-mail-other-window t]
2434         ["Create a local message" gnus-summary-news-other-window t]
2435         ["Uuencode and post" gnus-uu-post-news
2436          ,@(if (featurep 'xemacs) '(t)
2437              '(:help "Post a uuencoded article"))]
2438         ["Followup via news" gnus-summary-followup-to-mail t]
2439         ["Followup via news and yank"
2440          gnus-summary-followup-to-mail-with-original t]
2441         ;;("Draft"
2442         ;;["Send" gnus-summary-send-draft t]
2443         ;;["Send bounced" gnus-resend-bounced-mail t])
2444         ))
2445
2446     (cond
2447      ((not (keymapp gnus-summary-post-menu))
2448       (setq gnus-article-post-menu gnus-summary-post-menu))
2449      ((not gnus-article-post-menu)
2450       ;; Don't share post menu.
2451       (setq gnus-article-post-menu
2452             (copy-keymap gnus-summary-post-menu))))
2453     (define-key gnus-article-mode-map [menu-bar post]
2454       (cons "Post" gnus-article-post-menu))
2455
2456     (easy-menu-define
2457       gnus-summary-misc-menu gnus-summary-mode-map ""
2458       `("Gnus"
2459         ("Mark Read"
2460          ["Mark as read" gnus-summary-mark-as-read-forward t]
2461          ["Mark same subject and select"
2462           gnus-summary-kill-same-subject-and-select t]
2463          ["Mark same subject" gnus-summary-kill-same-subject t]
2464          ["Catchup" gnus-summary-catchup
2465           ,@(if (featurep 'xemacs) '(t)
2466               '(:help "Mark unread articles in this group as read"))]
2467          ["Catchup all" gnus-summary-catchup-all t]
2468          ["Catchup to here" gnus-summary-catchup-to-here t]
2469          ["Catchup from here" gnus-summary-catchup-from-here t]
2470          ["Catchup region" gnus-summary-mark-region-as-read
2471           (gnus-mark-active-p)]
2472          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2473         ("Mark Various"
2474          ["Tick" gnus-summary-tick-article-forward t]
2475          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2476          ["Remove marks" gnus-summary-clear-mark-forward t]
2477          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2478          ["Set bookmark" gnus-summary-set-bookmark t]
2479          ["Remove bookmark" gnus-summary-remove-bookmark t])
2480         ("Limit to"
2481          ["Marks..." gnus-summary-limit-to-marks t]
2482          ["Subject..." gnus-summary-limit-to-subject t]
2483          ["Author..." gnus-summary-limit-to-author t]
2484          ["Recipient..." gnus-summary-limit-to-recipient t]
2485          ["Age..." gnus-summary-limit-to-age t]
2486          ["Extra..." gnus-summary-limit-to-extra t]
2487          ["Score..." gnus-summary-limit-to-score t]
2488          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2489          ["Unread" gnus-summary-limit-to-unread t]
2490          ["Unseen" gnus-summary-limit-to-unseen t]
2491          ["Replied" gnus-summary-limit-to-replied t]
2492          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2493          ["Next articles" gnus-summary-limit-to-articles t]
2494          ["Pop limit" gnus-summary-pop-limit t]
2495          ["Show dormant" gnus-summary-limit-include-dormant t]
2496          ["Hide childless dormant"
2497           gnus-summary-limit-exclude-childless-dormant t]
2498          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2499          ["Hide marked" gnus-summary-limit-exclude-marks t]
2500          ["Show expunged" gnus-summary-limit-include-expunged t])
2501         ("Process Mark"
2502          ["Set mark" gnus-summary-mark-as-processable t]
2503          ["Remove mark" gnus-summary-unmark-as-processable t]
2504          ["Remove all marks" gnus-summary-unmark-all-processable t]
2505          ["Invert marks" gnus-uu-invert-processable t]
2506          ["Mark above" gnus-uu-mark-over t]
2507          ["Mark series" gnus-uu-mark-series t]
2508          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2509          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2510          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2511          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2512          ["Mark all" gnus-uu-mark-all t]
2513          ["Mark buffer" gnus-uu-mark-buffer t]
2514          ["Mark sparse" gnus-uu-mark-sparse t]
2515          ["Mark thread" gnus-uu-mark-thread t]
2516          ["Unmark thread" gnus-uu-unmark-thread t]
2517          ("Process Mark Sets"
2518           ["Kill" gnus-summary-kill-process-mark t]
2519           ["Yank" gnus-summary-yank-process-mark
2520            gnus-newsgroup-process-stack]
2521           ["Save" gnus-summary-save-process-mark t]
2522           ["Run command on marked..." gnus-summary-universal-argument t]))
2523         ("Scroll article"
2524          ["Page forward" gnus-summary-next-page
2525           ,@(if (featurep 'xemacs) '(t)
2526               '(:help "Show next page of article"))]
2527          ["Page backward" gnus-summary-prev-page
2528           ,@(if (featurep 'xemacs) '(t)
2529               '(:help "Show previous page of article"))]
2530          ["Line forward" gnus-summary-scroll-up t])
2531         ("Move"
2532          ["Next unread article" gnus-summary-next-unread-article t]
2533          ["Previous unread article" gnus-summary-prev-unread-article t]
2534          ["Next article" gnus-summary-next-article t]
2535          ["Previous article" gnus-summary-prev-article t]
2536          ["Next unread subject" gnus-summary-next-unread-subject t]
2537          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2538          ["Next article same subject" gnus-summary-next-same-subject t]
2539          ["Previous article same subject" gnus-summary-prev-same-subject t]
2540          ["First unread article" gnus-summary-first-unread-article t]
2541          ["Best unread article" gnus-summary-best-unread-article t]
2542          ["Go to subject number..." gnus-summary-goto-subject t]
2543          ["Go to article number..." gnus-summary-goto-article t]
2544          ["Go to the last article" gnus-summary-goto-last-article t]
2545          ["Pop article off history" gnus-summary-pop-article t])
2546         ("Sort"
2547          ["Sort by number" gnus-summary-sort-by-number t]
2548          ["Sort by author" gnus-summary-sort-by-author t]
2549          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2550          ["Sort by subject" gnus-summary-sort-by-subject t]
2551          ["Sort by date" gnus-summary-sort-by-date t]
2552          ["Sort by score" gnus-summary-sort-by-score t]
2553          ["Sort by lines" gnus-summary-sort-by-lines t]
2554          ["Sort by characters" gnus-summary-sort-by-chars t]
2555          ["Randomize" gnus-summary-sort-by-random t]
2556          ["Original sort" gnus-summary-sort-by-original t])
2557         ("Help"
2558          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2559          ["Describe group" gnus-summary-describe-group t]
2560          ["Fetch charter" gnus-group-fetch-charter
2561           ,@(if (featurep 'xemacs) nil
2562               '(:help "Display the charter of the current group"))]
2563          ["Fetch control message" gnus-group-fetch-control
2564           ,@(if (featurep 'xemacs) nil
2565               '(:help "Display the archived control message for the current group"))]
2566          ["Read manual" gnus-info-find-node t])
2567         ("Modes"
2568          ["Pick and read" gnus-pick-mode t]
2569          ["Binary" gnus-binary-mode t])
2570         ("Regeneration"
2571          ["Regenerate" gnus-summary-prepare t]
2572          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2573          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2574          ["Toggle threading" gnus-summary-toggle-threads t])
2575         ["See old articles" gnus-summary-insert-old-articles t]
2576         ["See new articles" gnus-summary-insert-new-articles t]
2577         ["Filter articles..." gnus-summary-execute-command t]
2578         ["Run command on articles..." gnus-summary-universal-argument t]
2579         ["Search articles forward..." gnus-summary-search-article-forward t]
2580         ["Search articles backward..." gnus-summary-search-article-backward t]
2581         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2582         ["Expand window" gnus-summary-expand-window t]
2583         ["Expire expirable articles" gnus-summary-expire-articles
2584          (gnus-check-backend-function
2585           'request-expire-articles gnus-newsgroup-name)]
2586         ["Edit local kill file" gnus-summary-edit-local-kill t]
2587         ["Edit main kill file" gnus-summary-edit-global-kill t]
2588         ["Edit group parameters" gnus-summary-edit-parameters t]
2589         ["Customize group parameters" gnus-summary-customize-parameters t]
2590         ["Send a bug report" gnus-bug t]
2591         ("Exit"
2592          ["Catchup and exit" gnus-summary-catchup-and-exit
2593           ,@(if (featurep 'xemacs) '(t)
2594               '(:help "Mark unread articles in this group as read, then exit"))]
2595          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2596          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2597          ["Exit group" gnus-summary-exit
2598           ,@(if (featurep 'xemacs) '(t)
2599               '(:help "Exit current group, return to group selection mode"))]
2600          ["Exit group without updating" gnus-summary-exit-no-update t]
2601          ["Exit and goto next group" gnus-summary-next-group t]
2602          ["Exit and goto prev group" gnus-summary-prev-group t]
2603          ["Reselect group" gnus-summary-reselect-current-group t]
2604          ["Rescan group" gnus-summary-rescan-group t]
2605          ["Update dribble" gnus-summary-save-newsrc t])))
2606
2607     (gnus-run-hooks 'gnus-summary-menu-hook)))
2608
2609 (defvar gnus-summary-tool-bar-map nil)
2610
2611 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2612 (defun gnus-summary-make-tool-bar ()
2613   (if (and (fboundp 'tool-bar-add-item-from-menu)
2614            (default-value 'tool-bar-mode)
2615            (not gnus-summary-tool-bar-map))
2616       (setq gnus-summary-tool-bar-map
2617             (let ((tool-bar-map (make-sparse-keymap))
2618                   (load-path (mm-image-load-path)))
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-post-news "post" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-followup "followup" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-reply "reply" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2651               tool-bar-map)))
2652   (if gnus-summary-tool-bar-map
2653       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2654
2655 (defun gnus-score-set-default (var value)
2656   "A version of set that updates the GNU Emacs menu-bar."
2657   (set var value)
2658   ;; It is the message that forces the active status to be updated.
2659   (message ""))
2660
2661 (defun gnus-make-score-map (type)
2662   "Make a summary score map of type TYPE."
2663   (if t
2664       nil
2665     (let ((headers '(("author" "from" string)
2666                      ("subject" "subject" string)
2667                      ("article body" "body" string)
2668                      ("article head" "head" string)
2669                      ("xref" "xref" string)
2670                      ("extra header" "extra" string)
2671                      ("lines" "lines" number)
2672                      ("followups to author" "followup" string)))
2673           (types '((number ("less than" <)
2674                            ("greater than" >)
2675                            ("equal" =))
2676                    (string ("substring" s)
2677                            ("exact string" e)
2678                            ("fuzzy string" f)
2679                            ("regexp" r))))
2680           (perms '(("temporary" (current-time-string))
2681                    ("permanent" nil)
2682                    ("immediate" now)))
2683           header)
2684       (list
2685        (apply
2686         'nconc
2687         (list
2688          (if (eq type 'lower)
2689              "Lower score"
2690            "Increase score"))
2691         (let (outh)
2692           (while headers
2693             (setq header (car headers))
2694             (setq outh
2695                   (cons
2696                    (apply
2697                     'nconc
2698                     (list (car header))
2699                     (let ((ts (cdr (assoc (nth 2 header) types)))
2700                           outt)
2701                       (while ts
2702                         (setq outt
2703                               (cons
2704                                (apply
2705                                 'nconc
2706                                 (list (caar ts))
2707                                 (let ((ps perms)
2708                                       outp)
2709                                   (while ps
2710                                     (setq outp
2711                                           (cons
2712                                            (vector
2713                                             (caar ps)
2714                                             (list
2715                                              'gnus-summary-score-entry
2716                                              (nth 1 header)
2717                                              (if (or (string= (nth 1 header)
2718                                                               "head")
2719                                                      (string= (nth 1 header)
2720                                                               "body"))
2721                                                  ""
2722                                                (list 'gnus-summary-header
2723                                                      (nth 1 header)))
2724                                              (list 'quote (nth 1 (car ts)))
2725                                              (list 'gnus-score-delta-default
2726                                                    nil)
2727                                              (nth 1 (car ps))
2728                                              t)
2729                                             t)
2730                                            outp))
2731                                     (setq ps (cdr ps)))
2732                                   (list (nreverse outp))))
2733                                outt))
2734                         (setq ts (cdr ts)))
2735                       (list (nreverse outt))))
2736                    outh))
2737             (setq headers (cdr headers)))
2738           (list (nreverse outh))))))))
2739
2740 \f
2741
2742 (defun gnus-summary-mode (&optional group)
2743   "Major mode for reading articles.
2744
2745 All normal editing commands are switched off.
2746 \\<gnus-summary-mode-map>
2747 Each line in this buffer represents one article.  To read an
2748 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2749 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2750 respectively.
2751
2752 You can also post articles and send mail from this buffer.  To
2753 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2754 of an article, type `\\[gnus-summary-reply]'.
2755
2756 There are approx. one gazillion commands you can execute in this
2757 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2758
2759 The following commands are available:
2760
2761 \\{gnus-summary-mode-map}"
2762   (interactive)
2763   (kill-all-local-variables)
2764   (when (gnus-visual-p 'summary-menu 'menu)
2765     (gnus-summary-make-menu-bar)
2766     (gnus-summary-make-tool-bar))
2767   (gnus-summary-make-local-variables)
2768   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2769     (gnus-summary-make-local-variables))
2770   (gnus-make-thread-indent-array)
2771   (gnus-simplify-mode-line)
2772   (setq major-mode 'gnus-summary-mode)
2773   (setq mode-name "Summary")
2774   (make-local-variable 'minor-mode-alist)
2775   (use-local-map gnus-summary-mode-map)
2776   (buffer-disable-undo)
2777   (setq buffer-read-only t              ;Disable modification
2778         show-trailing-whitespace nil)
2779   (setq truncate-lines t)
2780   (setq selective-display t)
2781   (setq selective-display-ellipses t)   ;Display `...'
2782   (gnus-summary-set-display-table)
2783   (gnus-set-default-directory)
2784   (setq gnus-newsgroup-name group)
2785   (make-local-variable 'gnus-summary-line-format)
2786   (make-local-variable 'gnus-summary-line-format-spec)
2787   (make-local-variable 'gnus-summary-dummy-line-format)
2788   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2789   (make-local-variable 'gnus-summary-mark-positions)
2790   (gnus-make-local-hook 'pre-command-hook)
2791   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2792   (gnus-run-hooks 'gnus-summary-mode-hook)
2793   (turn-on-gnus-mailing-list-mode)
2794   (mm-enable-multibyte)
2795   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2796   (gnus-update-summary-mark-positions))
2797
2798 (defun gnus-summary-make-local-variables ()
2799   "Make all the local summary buffer variables."
2800   (let (global)
2801     (dolist (local gnus-summary-local-variables)
2802       (if (consp local)
2803           (progn
2804             (if (eq (cdr local) 'global)
2805                 ;; Copy the global value of the variable.
2806                 (setq global (symbol-value (car local)))
2807               ;; Use the value from the list.
2808               (setq global (eval (cdr local))))
2809             (set (make-local-variable (car local)) global))
2810         ;; Simple nil-valued local variable.
2811         (set (make-local-variable local) nil)))))
2812
2813 (defun gnus-summary-clear-local-variables ()
2814   (let ((locals gnus-summary-local-variables))
2815     (while locals
2816       (if (consp (car locals))
2817           (and (symbolp (caar locals))
2818                (set (caar locals) nil))
2819         (and (symbolp (car locals))
2820              (set (car locals) nil)))
2821       (setq locals (cdr locals)))))
2822
2823 ;; Summary data functions.
2824
2825 (defmacro gnus-data-number (data)
2826   `(car ,data))
2827
2828 (defmacro gnus-data-set-number (data number)
2829   `(setcar ,data ,number))
2830
2831 (defmacro gnus-data-mark (data)
2832   `(nth 1 ,data))
2833
2834 (defmacro gnus-data-set-mark (data mark)
2835   `(setcar (nthcdr 1 ,data) ,mark))
2836
2837 (defmacro gnus-data-pos (data)
2838   `(nth 2 ,data))
2839
2840 (defmacro gnus-data-set-pos (data pos)
2841   `(setcar (nthcdr 2 ,data) ,pos))
2842
2843 (defmacro gnus-data-header (data)
2844   `(nth 3 ,data))
2845
2846 (defmacro gnus-data-set-header (data header)
2847   `(setf (nth 3 ,data) ,header))
2848
2849 (defmacro gnus-data-level (data)
2850   `(nth 4 ,data))
2851
2852 (defmacro gnus-data-unread-p (data)
2853   `(= (nth 1 ,data) gnus-unread-mark))
2854
2855 (defmacro gnus-data-read-p (data)
2856   `(/= (nth 1 ,data) gnus-unread-mark))
2857
2858 (defmacro gnus-data-pseudo-p (data)
2859   `(consp (nth 3 ,data)))
2860
2861 (defmacro gnus-data-find (number)
2862   `(assq ,number gnus-newsgroup-data))
2863
2864 (defmacro gnus-data-find-list (number &optional data)
2865   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2866      (memq (assq ,number bdata)
2867            bdata)))
2868
2869 (defmacro gnus-data-make (number mark pos header level)
2870   `(list ,number ,mark ,pos ,header ,level))
2871
2872 (defun gnus-data-enter (after-article number mark pos header level offset)
2873   (let ((data (gnus-data-find-list after-article)))
2874     (unless data
2875       (error "No such article: %d" after-article))
2876     (setcdr data (cons (gnus-data-make number mark pos header level)
2877                        (cdr data)))
2878     (setq gnus-newsgroup-data-reverse nil)
2879     (gnus-data-update-list (cddr data) offset)))
2880
2881 (defun gnus-data-enter-list (after-article list &optional offset)
2882   (when list
2883     (let ((data (and after-article (gnus-data-find-list after-article)))
2884           (ilist list))
2885       (if (not (or data
2886                    after-article))
2887           (let ((odata gnus-newsgroup-data))
2888             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2889             (when offset
2890               (gnus-data-update-list odata offset)))
2891         ;; Find the last element in the list to be spliced into the main
2892         ;; list.
2893         (setq list (last list))
2894         (if (not data)
2895             (progn
2896               (setcdr list gnus-newsgroup-data)
2897               (setq gnus-newsgroup-data ilist)
2898               (when offset
2899                 (gnus-data-update-list (cdr list) offset)))
2900           (setcdr list (cdr data))
2901           (setcdr data ilist)
2902           (when offset
2903             (gnus-data-update-list (cdr list) offset))))
2904       (setq gnus-newsgroup-data-reverse nil))))
2905
2906 (defun gnus-data-remove (article &optional offset)
2907   (let ((data gnus-newsgroup-data))
2908     (if (= (gnus-data-number (car data)) article)
2909         (progn
2910           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2911                 gnus-newsgroup-data-reverse nil)
2912           (when offset
2913             (gnus-data-update-list gnus-newsgroup-data offset)))
2914       (while (cdr data)
2915         (when (= (gnus-data-number (cadr data)) article)
2916           (setcdr data (cddr data))
2917           (when offset
2918             (gnus-data-update-list (cdr data) offset))
2919           (setq data nil
2920                 gnus-newsgroup-data-reverse nil))
2921         (setq data (cdr data))))))
2922
2923 (defmacro gnus-data-list (backward)
2924   `(if ,backward
2925        (or gnus-newsgroup-data-reverse
2926            (setq gnus-newsgroup-data-reverse
2927                  (reverse gnus-newsgroup-data)))
2928      gnus-newsgroup-data))
2929
2930 (defun gnus-data-update-list (data offset)
2931   "Add OFFSET to the POS of all data entries in DATA."
2932   (setq gnus-newsgroup-data-reverse nil)
2933   (while data
2934     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2935     (setq data (cdr data))))
2936
2937 (defun gnus-summary-article-pseudo-p (article)
2938   "Say whether this article is a pseudo article or not."
2939   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2940
2941 (defmacro gnus-summary-article-sparse-p (article)
2942   "Say whether this article is a sparse article or not."
2943   `(memq ,article gnus-newsgroup-sparse))
2944
2945 (defmacro gnus-summary-article-ancient-p (article)
2946   "Say whether this article is a sparse article or not."
2947   `(memq ,article gnus-newsgroup-ancient))
2948
2949 (defun gnus-article-parent-p (number)
2950   "Say whether this article is a parent or not."
2951   (let ((data (gnus-data-find-list number)))
2952     (and (cdr data)              ; There has to be an article after...
2953          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2954             (gnus-data-level (nth 1 data))))))
2955
2956 (defun gnus-article-children (number)
2957   "Return a list of all children to NUMBER."
2958   (let* ((data (gnus-data-find-list number))
2959          (level (gnus-data-level (car data)))
2960          children)
2961     (setq data (cdr data))
2962     (while (and data
2963                 (= (gnus-data-level (car data)) (1+ level)))
2964       (push (gnus-data-number (car data)) children)
2965       (setq data (cdr data)))
2966     children))
2967
2968 (defmacro gnus-summary-skip-intangible ()
2969   "If the current article is intangible, then jump to a different article."
2970   '(let ((to (get-text-property (point) 'gnus-intangible)))
2971      (and to (gnus-summary-goto-subject to))))
2972
2973 (defmacro gnus-summary-article-intangible-p ()
2974   "Say whether this article is intangible or not."
2975   '(get-text-property (point) 'gnus-intangible))
2976
2977 (defun gnus-article-read-p (article)
2978   "Say whether ARTICLE is read or not."
2979   (not (or (memq article gnus-newsgroup-marked)
2980            (memq article gnus-newsgroup-spam-marked)
2981            (memq article gnus-newsgroup-unreads)
2982            (memq article gnus-newsgroup-unselected)
2983            (memq article gnus-newsgroup-dormant))))
2984
2985 ;; Some summary mode macros.
2986
2987 (defmacro gnus-summary-article-number ()
2988   "The article number of the article on the current line.
2989 If there isn't an article number here, then we return the current
2990 article number."
2991   '(progn
2992      (gnus-summary-skip-intangible)
2993      (or (get-text-property (point) 'gnus-number)
2994          (gnus-summary-last-subject))))
2995
2996 (defmacro gnus-summary-article-header (&optional number)
2997   "Return the header of article NUMBER."
2998   `(gnus-data-header (gnus-data-find
2999                       ,(or number '(gnus-summary-article-number)))))
3000
3001 (defmacro gnus-summary-thread-level (&optional number)
3002   "Return the level of thread that starts with article NUMBER."
3003   `(if (and (eq gnus-summary-make-false-root 'dummy)
3004             (get-text-property (point) 'gnus-intangible))
3005        0
3006      (gnus-data-level (gnus-data-find
3007                        ,(or number '(gnus-summary-article-number))))))
3008
3009 (defmacro gnus-summary-article-mark (&optional number)
3010   "Return the mark of article NUMBER."
3011   `(gnus-data-mark (gnus-data-find
3012                     ,(or number '(gnus-summary-article-number)))))
3013
3014 (defmacro gnus-summary-article-pos (&optional number)
3015   "Return the position of the line of article NUMBER."
3016   `(gnus-data-pos (gnus-data-find
3017                    ,(or number '(gnus-summary-article-number)))))
3018
3019 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3020 (defmacro gnus-summary-article-subject (&optional number)
3021   "Return current subject string or nil if nothing."
3022   `(let ((headers
3023           ,(if number
3024                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3025              '(gnus-data-header (assq (gnus-summary-article-number)
3026                                       gnus-newsgroup-data)))))
3027      (and headers
3028           (vectorp headers)
3029           (mail-header-subject headers))))
3030
3031 (defmacro gnus-summary-article-score (&optional number)
3032   "Return current article score."
3033   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3034                   gnus-newsgroup-scored))
3035        gnus-summary-default-score 0))
3036
3037 (defun gnus-summary-article-children (&optional number)
3038   "Return a list of article numbers that are children of article NUMBER."
3039   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3040          (level (gnus-data-level (car data)))
3041          l children)
3042     (while (and (setq data (cdr data))
3043                 (> (setq l (gnus-data-level (car data))) level))
3044       (and (= (1+ level) l)
3045            (push (gnus-data-number (car data))
3046                  children)))
3047     (nreverse children)))
3048
3049 (defun gnus-summary-article-parent (&optional number)
3050   "Return the article number of the parent of article NUMBER."
3051   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3052                                     (gnus-data-list t)))
3053          (level (gnus-data-level (car data))))
3054     (if (zerop level)
3055         ()                              ; This is a root.
3056       ;; We search until we find an article with a level less than
3057       ;; this one.  That function has to be the parent.
3058       (while (and (setq data (cdr data))
3059                   (not (< (gnus-data-level (car data)) level))))
3060       (and data (gnus-data-number (car data))))))
3061
3062 (defun gnus-unread-mark-p (mark)
3063   "Say whether MARK is the unread mark."
3064   (= mark gnus-unread-mark))
3065
3066 (defun gnus-read-mark-p (mark)
3067   "Say whether MARK is one of the marks that mark as read.
3068 This is all marks except unread, ticked, dormant, and expirable."
3069   (not (or (= mark gnus-unread-mark)
3070            (= mark gnus-ticked-mark)
3071            (= mark gnus-spam-mark)
3072            (= mark gnus-dormant-mark)
3073            (= mark gnus-expirable-mark))))
3074
3075 (defmacro gnus-article-mark (number)
3076   "Return the MARK of article NUMBER.
3077 This macro should only be used when computing the mark the \"first\"
3078 time; i.e., when generating the summary lines.  After that,
3079 `gnus-summary-article-mark' should be used to examine the
3080 marks of articles."
3081   `(cond
3082     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3083     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3084     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3085     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3086     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3087     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3088     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3089     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3090            gnus-ancient-mark))))
3091
3092 ;; Saving hidden threads.
3093
3094 (defmacro gnus-save-hidden-threads (&rest forms)
3095   "Save hidden threads, eval FORMS, and restore the hidden threads."
3096   (let ((config (make-symbol "config")))
3097     `(let ((,config (gnus-hidden-threads-configuration)))
3098        (unwind-protect
3099            (save-excursion
3100              ,@forms)
3101          (gnus-restore-hidden-threads-configuration ,config)))))
3102 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3103 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3104
3105 (defun gnus-data-compute-positions ()
3106   "Compute the positions of all articles."
3107   (setq gnus-newsgroup-data-reverse nil)
3108   (let ((data gnus-newsgroup-data))
3109     (save-excursion
3110       (gnus-save-hidden-threads
3111         (gnus-summary-show-all-threads)
3112         (goto-char (point-min))
3113         (while data
3114           (while (get-text-property (point) 'gnus-intangible)
3115             (forward-line 1))
3116           (gnus-data-set-pos (car data) (+ (point) 3))
3117           (setq data (cdr data))
3118           (forward-line 1))))))
3119
3120 (defun gnus-hidden-threads-configuration ()
3121   "Return the current hidden threads configuration."
3122   (save-excursion
3123     (let (config)
3124       (goto-char (point-min))
3125       (while (search-forward "\r" nil t)
3126         (push (1- (point)) config))
3127       config)))
3128
3129 (defun gnus-restore-hidden-threads-configuration (config)
3130   "Restore hidden threads configuration from CONFIG."
3131   (save-excursion
3132     (let (point buffer-read-only)
3133       (while (setq point (pop config))
3134         (when (and (< point (point-max))
3135                    (goto-char point)
3136                    (eq (char-after) ?\n))
3137           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3138
3139 ;; Various summary mode internalish functions.
3140
3141 (defun gnus-mouse-pick-article (e)
3142   (interactive "e")
3143   (mouse-set-point e)
3144   (gnus-summary-next-page nil t))
3145
3146 (defun gnus-summary-set-display-table ()
3147   "Change the display table.
3148 Odd characters have a tendency to mess
3149 up nicely formatted displays - we make all possible glyphs
3150 display only a single character."
3151
3152   ;; We start from the standard display table, if any.
3153   (let ((table (or (copy-sequence standard-display-table)
3154                    (make-display-table)))
3155         (i 32))
3156     ;; Nix out all the control chars...
3157     (while (>= (setq i (1- i)) 0)
3158       (aset table i [??]))
3159    ;; ... but not newline and cr, of course.  (cr is necessary for the
3160     ;; selective display).
3161     (aset table ?\n nil)
3162     (aset table ?\r nil)
3163     ;; We keep TAB as well.
3164     (aset table ?\t nil)
3165     ;; We nix out any glyphs over 126 that are not set already.
3166     (let ((i 256))
3167       (while (>= (setq i (1- i)) 127)
3168         ;; Only modify if the entry is nil.
3169         (unless (aref table i)
3170           (aset table i [??]))))
3171     (setq buffer-display-table table)))
3172
3173 (defun gnus-summary-set-article-display-arrow (pos)
3174   "Update the overlay arrow to point to line at position POS."
3175   (when (and gnus-summary-display-arrow
3176              (boundp 'overlay-arrow-position)
3177              (boundp 'overlay-arrow-string))
3178     (save-excursion
3179       (goto-char pos)
3180       (beginning-of-line)
3181       (unless overlay-arrow-position
3182         (setq overlay-arrow-position (make-marker)))
3183       (setq overlay-arrow-string "=>"
3184             overlay-arrow-position (set-marker overlay-arrow-position
3185                                                (point)
3186                                                (current-buffer))))))
3187
3188 (defun gnus-summary-setup-buffer (group)
3189   "Initialize summary buffer."
3190   (let ((buffer (gnus-summary-buffer-name group))
3191         (dead-name (concat "*Dead Summary "
3192                            (gnus-group-decoded-name group) "*")))
3193     ;; If a dead summary buffer exists, we kill it.
3194     (when (gnus-buffer-live-p dead-name)
3195       (gnus-kill-buffer dead-name))
3196     (if (get-buffer buffer)
3197         (progn
3198           (set-buffer buffer)
3199           (setq gnus-summary-buffer (current-buffer))
3200           (not gnus-newsgroup-prepared))
3201       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3202       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3203       (gnus-summary-mode group)
3204       (when gnus-carpal
3205         (gnus-carpal-setup-buffer 'summary))
3206       (unless gnus-single-article-buffer
3207         (make-local-variable 'gnus-article-buffer)
3208         (make-local-variable 'gnus-article-current)
3209         (make-local-variable 'gnus-original-article-buffer))
3210       (setq gnus-newsgroup-name group)
3211       ;; Set any local variables in the group parameters.
3212       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3213       t)))
3214
3215 (defun gnus-set-global-variables ()
3216   "Set the global equivalents of the buffer-local variables.
3217 They are set to the latest values they had.  These reflect the summary
3218 buffer that was in action when the last article was fetched."
3219   (when (eq major-mode 'gnus-summary-mode)
3220     (setq gnus-summary-buffer (current-buffer))
3221     (let ((name gnus-newsgroup-name)
3222           (marked gnus-newsgroup-marked)
3223           (spam gnus-newsgroup-spam-marked)
3224           (unread gnus-newsgroup-unreads)
3225           (headers gnus-current-headers)
3226           (data gnus-newsgroup-data)
3227           (summary gnus-summary-buffer)
3228           (article-buffer gnus-article-buffer)
3229           (original gnus-original-article-buffer)
3230           (gac gnus-article-current)
3231           (reffed gnus-reffed-article-number)
3232           (score-file gnus-current-score-file)
3233           (default-charset gnus-newsgroup-charset)
3234           vlist)
3235       (let ((locals gnus-newsgroup-variables))
3236         (while locals
3237           (if (consp (car locals))
3238               (push (eval (caar locals)) vlist)
3239             (push (eval (car locals)) vlist))
3240           (setq locals (cdr locals)))
3241         (setq vlist (nreverse vlist)))
3242       (with-current-buffer gnus-group-buffer
3243         (setq gnus-newsgroup-name name
3244               gnus-newsgroup-marked marked
3245               gnus-newsgroup-spam-marked spam
3246               gnus-newsgroup-unreads unread
3247               gnus-current-headers headers
3248               gnus-newsgroup-data data
3249               gnus-article-current gac
3250               gnus-summary-buffer summary
3251               gnus-article-buffer article-buffer
3252               gnus-original-article-buffer original
3253               gnus-reffed-article-number reffed
3254               gnus-current-score-file score-file
3255               gnus-newsgroup-charset default-charset)
3256         (let ((locals gnus-newsgroup-variables))
3257           (while locals
3258             (if (consp (car locals))
3259                 (set (caar locals) (pop vlist))
3260               (set (car locals) (pop vlist)))
3261             (setq locals (cdr locals))))
3262         ;; The article buffer also has local variables.
3263         (when (gnus-buffer-live-p gnus-article-buffer)
3264           (set-buffer gnus-article-buffer)
3265           (setq gnus-summary-buffer summary))))))
3266
3267 (defun gnus-summary-article-unread-p (article)
3268   "Say whether ARTICLE is unread or not."
3269   (memq article gnus-newsgroup-unreads))
3270
3271 (defun gnus-summary-first-article-p (&optional article)
3272   "Return whether ARTICLE is the first article in the buffer."
3273   (if (not (setq article (or article (gnus-summary-article-number))))
3274       nil
3275     (eq article (caar gnus-newsgroup-data))))
3276
3277 (defun gnus-summary-last-article-p (&optional article)
3278   "Return whether ARTICLE is the last article in the buffer."
3279   (if (not (setq article (or article (gnus-summary-article-number))))
3280       ;; All non-existent numbers are the last article.  :-)
3281       t
3282     (not (cdr (gnus-data-find-list article)))))
3283
3284 (defun gnus-make-thread-indent-array ()
3285   (let ((n 200))
3286     (unless (and gnus-thread-indent-array
3287                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3288       (setq gnus-thread-indent-array (make-vector 201 "")
3289             gnus-thread-indent-array-level gnus-thread-indent-level)
3290       (while (>= n 0)
3291         (aset gnus-thread-indent-array n
3292               (make-string (* n gnus-thread-indent-level) ? ))
3293         (setq n (1- n))))))
3294
3295 (defun gnus-update-summary-mark-positions ()
3296   "Compute where the summary marks are to go."
3297   (save-excursion
3298     (when (gnus-buffer-exists-p gnus-summary-buffer)
3299       (set-buffer gnus-summary-buffer))
3300     (let ((spec gnus-summary-line-format-spec)
3301           pos)
3302       (save-excursion
3303         (gnus-set-work-buffer)
3304         (let ((gnus-tmp-unread ?Z)
3305               (gnus-replied-mark ?Z)
3306               (gnus-score-below-mark ?Z)
3307               (gnus-score-over-mark ?Z)
3308               (gnus-undownloaded-mark ?Z)
3309               (gnus-summary-line-format-spec spec)
3310               (gnus-newsgroup-downloadable '(0))
3311               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3312               case-fold-search ignores)
3313           ;; Here, all marks are bound to Z.
3314           (gnus-summary-insert-line header
3315                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3316           (goto-char (point-min))
3317           ;; Memorize the positions of the same characters as dummy marks.
3318           (while (re-search-forward "[A-D]" nil t)
3319             (push (point) ignores))
3320           (erase-buffer)
3321           ;; We use A-D as dummy marks in order to know column positions
3322           ;; where marks should be inserted.
3323           (setq gnus-tmp-unread ?A
3324                 gnus-replied-mark ?B
3325                 gnus-score-below-mark ?C
3326                 gnus-score-over-mark ?C
3327                 gnus-undownloaded-mark ?D)
3328           (gnus-summary-insert-line header
3329                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3330           ;; Ignore characters which aren't dummy marks.
3331           (dolist (p ignores)
3332             (delete-region (goto-char (1- p)) p)
3333             (insert ?Z))
3334           (goto-char (point-min))
3335           (setq pos (list (cons 'unread
3336                                 (and (search-forward "A" nil t)
3337                                      (- (point) (point-min) 1)))))
3338           (goto-char (point-min))
3339           (push (cons 'replied (and (search-forward "B" nil t)
3340                                     (- (point) (point-min) 1)))
3341                 pos)
3342           (goto-char (point-min))
3343           (push (cons 'score (and (search-forward "C" nil t)
3344                                   (- (point) (point-min) 1)))
3345                 pos)
3346           (goto-char (point-min))
3347           (push (cons 'download (and (search-forward "D" nil t)
3348                                      (- (point) (point-min) 1)))
3349                 pos)))
3350       (setq gnus-summary-mark-positions pos))))
3351
3352 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3353   "Insert a dummy root in the summary buffer."
3354   (beginning-of-line)
3355   (gnus-add-text-properties
3356    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3357    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3358
3359 (defun gnus-summary-extract-address-component (from)
3360   (or (car (funcall gnus-extract-address-components from))
3361       from))
3362
3363 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3364   (let ((mail-parse-charset gnus-newsgroup-charset)
3365         ; Is it really necessary to do this next part for each summary line?
3366         ; Luckily, doesn't seem to slow things down much.
3367         (mail-parse-ignored-charsets
3368          (with-current-buffer gnus-summary-buffer
3369            gnus-newsgroup-ignored-charsets)))
3370     (or
3371      (and gnus-ignored-from-addresses
3372           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3373           (let ((extra-headers (mail-header-extra header))
3374                 to
3375                 newsgroups)
3376             (cond
3377              ((setq to (cdr (assq 'To extra-headers)))
3378               (concat "-> "
3379                       (inline
3380                         (gnus-summary-extract-address-component
3381                          (funcall gnus-decode-encoded-word-function to)))))
3382              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3383               (concat "=> " newsgroups)))))
3384      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3385
3386 (defun gnus-summary-insert-line (gnus-tmp-header
3387                                  gnus-tmp-level gnus-tmp-current
3388                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3389                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3390                                  &optional gnus-tmp-dummy gnus-tmp-score
3391                                  gnus-tmp-process)
3392   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3393          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3394          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3395          (gnus-tmp-score-char
3396           (if (or (null gnus-summary-default-score)
3397                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3398                       gnus-summary-zcore-fuzz))
3399               ?                         ;Whitespace
3400             (if (< gnus-tmp-score gnus-summary-default-score)
3401                 gnus-score-below-mark gnus-score-over-mark)))
3402          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3403          (gnus-tmp-replied
3404           (cond (gnus-tmp-process gnus-process-mark)
3405                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3406                  gnus-cached-mark)
3407                 (gnus-tmp-replied gnus-replied-mark)
3408                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3409                  gnus-forwarded-mark)
3410                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3411                  gnus-saved-mark)
3412                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3413                  gnus-recent-mark)
3414                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3415                  gnus-unseen-mark)
3416                 (t gnus-no-mark)))
3417          (gnus-tmp-downloaded
3418           (cond (undownloaded
3419                  gnus-undownloaded-mark)
3420                 (gnus-newsgroup-agentized
3421                  gnus-downloaded-mark)
3422                 (t
3423                  gnus-no-mark)))
3424          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3425          (gnus-tmp-name
3426           (cond
3427            ((string-match "<[^>]+> *$" gnus-tmp-from)
3428             (let ((beg (match-beginning 0)))
3429               (or (and (string-match "^\".+\"" gnus-tmp-from)
3430                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3431                   (substring gnus-tmp-from 0 beg))))
3432            ((string-match "(.+)" gnus-tmp-from)
3433             (substring gnus-tmp-from
3434                        (1+ (match-beginning 0)) (1- (match-end 0))))
3435            (t gnus-tmp-from)))
3436          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3437          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3438          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3439          (buffer-read-only nil))
3440     (when (string= gnus-tmp-name "")
3441       (setq gnus-tmp-name gnus-tmp-from))
3442     (unless (numberp gnus-tmp-lines)
3443       (setq gnus-tmp-lines -1))
3444     (if (= gnus-tmp-lines -1)
3445         (setq gnus-tmp-lines "?")
3446       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3447       (gnus-put-text-property
3448      (point)
3449      (progn (eval gnus-summary-line-format-spec) (point))
3450        'gnus-number gnus-tmp-number)
3451     (when (gnus-visual-p 'summary-highlight 'highlight)
3452       (forward-line -1)
3453       (gnus-run-hooks 'gnus-summary-update-hook)
3454       (forward-line 1))))
3455
3456 (defun gnus-summary-update-line (&optional dont-update)
3457   "Update summary line after change."
3458   (when (and gnus-summary-default-score
3459              (not gnus-summary-inhibit-highlight))
3460     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3461            (article (gnus-summary-article-number))
3462            (score (gnus-summary-article-score article)))
3463       (unless dont-update
3464         (if (and gnus-summary-mark-below
3465                  (< (gnus-summary-article-score)
3466                     gnus-summary-mark-below))
3467             ;; This article has a low score, so we mark it as read.
3468             (when (memq article gnus-newsgroup-unreads)
3469               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3470           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3471             ;; This article was previously marked as read on account
3472             ;; of a low score, but now it has risen, so we mark it as
3473             ;; unread.
3474             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3475         (gnus-summary-update-mark
3476          (if (or (null gnus-summary-default-score)
3477                  (<= (abs (- score gnus-summary-default-score))
3478                      gnus-summary-zcore-fuzz))
3479              ?                          ;Whitespace
3480            (if (< score gnus-summary-default-score)
3481                gnus-score-below-mark gnus-score-over-mark))
3482          'score))
3483       ;; Do visual highlighting.
3484       (when (gnus-visual-p 'summary-highlight 'highlight)
3485         (gnus-run-hooks 'gnus-summary-update-hook)))))
3486
3487 (defvar gnus-tmp-new-adopts nil)
3488
3489 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3490   "Return the number of articles in THREAD.
3491 This may be 0 in some cases -- if none of the articles in
3492 the thread are to be displayed."
3493   (let* ((number
3494          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3495           (cond
3496            ((not (listp thread))
3497             1)
3498            ((and (consp thread) (cdr thread))
3499             (apply
3500              '+ 1 (mapcar
3501                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3502            ((null thread)
3503             1)
3504            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3505             1)
3506            (t 0))))
3507     (when (and level (zerop level) gnus-tmp-new-adopts)
3508       (incf number
3509             (apply '+ (mapcar
3510                        'gnus-summary-number-of-articles-in-thread
3511                        gnus-tmp-new-adopts))))
3512     (if char
3513         (if (> number 1) gnus-not-empty-thread-mark
3514           gnus-empty-thread-mark)
3515       number)))
3516
3517 (defsubst gnus-summary-line-message-size (head)
3518   "Return pretty-printed version of message size.
3519 This function is intended to be used in
3520 `gnus-summary-line-format-alist'."
3521   (let ((c (or (mail-header-chars head) -1)))
3522     (cond ((< c 0) "n/a")               ; chars not available
3523           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3524           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3525           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3526           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3527
3528
3529 (defun gnus-summary-set-local-parameters (group)
3530   "Go through the local params of GROUP and set all variable specs in that list."
3531   (let ((vars '(quit-config)))          ; Ignore quit-config.
3532     (dolist (elem (gnus-group-find-parameter group))
3533       (and (consp elem)                 ; Has to be a cons.
3534            (consp (cdr elem))           ; The cdr has to be a list.
3535            (symbolp (car elem))         ; Has to be a symbol in there.
3536            (not (memq (car elem) vars))
3537            (ignore-errors               ; So we set it.
3538              (push (car elem) vars)
3539              (make-local-variable (car elem))
3540              (set (car elem) (eval (nth 1 elem))))))))
3541
3542 (defun gnus-summary-read-group (group &optional show-all no-article
3543                                       kill-buffer no-display backward
3544                                       select-articles)
3545   "Start reading news in newsgroup GROUP.
3546 If SHOW-ALL is non-nil, already read articles are also listed.
3547 If NO-ARTICLE is non-nil, no article is selected initially.
3548 If NO-DISPLAY, don't generate a summary buffer."
3549   (let (result)
3550     (while (and group
3551                 (null (setq result
3552                             (let ((gnus-auto-select-next nil))
3553                               (or (gnus-summary-read-group-1
3554                                    group show-all no-article
3555                                    kill-buffer no-display
3556                                    select-articles)
3557                                   (setq show-all nil
3558                                         select-articles nil)))))
3559                 (eq gnus-auto-select-next 'quietly))
3560       (set-buffer gnus-group-buffer)
3561       ;; The entry function called above goes to the next
3562       ;; group automatically, so we go two groups back
3563       ;; if we are searching for the previous group.
3564       (when backward
3565         (gnus-group-prev-unread-group 2))
3566       (if (not (equal group (gnus-group-group-name)))
3567           (setq group (gnus-group-group-name))
3568         (setq group nil)))
3569     result))
3570
3571 (defun gnus-summary-read-group-1 (group show-all no-article
3572                                         kill-buffer no-display
3573                                         &optional select-articles)
3574   ;; Killed foreign groups can't be entered.
3575   ;;  (when (and (not (gnus-group-native-p group))
3576   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3577   ;;    (error "Dead non-native groups can't be entered"))
3578   (gnus-message 5 "Retrieving newsgroup: %s..."
3579                 (gnus-group-decoded-name group))
3580   (let* ((new-group (gnus-summary-setup-buffer group))
3581          (quit-config (gnus-group-quit-config group))
3582          (did-select (and new-group (gnus-select-newsgroup
3583                                      group show-all select-articles))))
3584     (cond
3585      ;; This summary buffer exists already, so we just select it.
3586      ((not new-group)
3587       (gnus-set-global-variables)
3588       (when kill-buffer
3589         (gnus-kill-or-deaden-summary kill-buffer))
3590       (gnus-configure-windows 'summary 'force)
3591       (gnus-set-mode-line 'summary)
3592       (gnus-summary-position-point)
3593       (message "")
3594       t)
3595      ;; We couldn't select this group.
3596      ((null did-select)
3597       (when (and (eq major-mode 'gnus-summary-mode)
3598                  (not (equal (current-buffer) kill-buffer)))
3599         (kill-buffer (current-buffer))
3600         (if (not quit-config)
3601             (progn
3602               ;; Update the info -- marks might need to be removed,
3603               ;; for instance.
3604               (gnus-summary-update-info)
3605               (set-buffer gnus-group-buffer)
3606               (gnus-group-jump-to-group group)
3607               (gnus-group-next-unread-group 1))
3608           (gnus-handle-ephemeral-exit quit-config)))
3609       (let ((grpinfo (gnus-get-info group)))
3610         (if (null (gnus-info-read grpinfo))
3611             (gnus-message 3 "Group %s contains no messages"
3612                           (gnus-group-decoded-name group))
3613           (gnus-message 3 "Can't select group")))
3614       nil)
3615      ;; The user did a `C-g' while prompting for number of articles,
3616      ;; so we exit this group.
3617      ((eq did-select 'quit)
3618       (and (eq major-mode 'gnus-summary-mode)
3619            (not (equal (current-buffer) kill-buffer))
3620            (kill-buffer (current-buffer)))
3621       (when kill-buffer
3622         (gnus-kill-or-deaden-summary kill-buffer))
3623       (if (not quit-config)
3624           (progn
3625             (set-buffer gnus-group-buffer)
3626             (gnus-group-jump-to-group group)
3627             (gnus-group-next-unread-group 1)
3628             (gnus-configure-windows 'group 'force))
3629         (gnus-handle-ephemeral-exit quit-config))
3630       ;; Finally signal the quit.
3631       (signal 'quit nil))
3632      ;; The group was successfully selected.
3633      (t
3634       (gnus-set-global-variables)
3635       ;; Save the active value in effect when the group was entered.
3636       (setq gnus-newsgroup-active
3637             (gnus-copy-sequence
3638              (gnus-active gnus-newsgroup-name)))
3639       ;; You can change the summary buffer in some way with this hook.
3640       (gnus-run-hooks 'gnus-select-group-hook)
3641       (when (memq 'summary (gnus-update-format-specifications
3642                             nil 'summary 'summary-mode 'summary-dummy))
3643         ;; The format specification for the summary line was updated,
3644         ;; so we need to update the mark positions as well.
3645         (gnus-update-summary-mark-positions))
3646       ;; Do score processing.
3647       (when gnus-use-scoring
3648         (gnus-possibly-score-headers))
3649       ;; Check whether to fill in the gaps in the threads.
3650       (when gnus-build-sparse-threads
3651         (gnus-build-sparse-threads))
3652       ;; Find the initial limit.
3653       (if show-all
3654           (let ((gnus-newsgroup-dormant nil))
3655             (gnus-summary-initial-limit show-all))
3656         (gnus-summary-initial-limit show-all))
3657       ;; Generate the summary buffer.
3658       (unless no-display
3659         (gnus-summary-prepare))
3660       (when gnus-use-trees
3661         (gnus-tree-open group)
3662         (setq gnus-summary-highlight-line-function
3663               'gnus-tree-highlight-article))
3664       ;; If the summary buffer is empty, but there are some low-scored
3665       ;; articles or some excluded dormants, we include these in the
3666       ;; buffer.
3667       (when (and (zerop (buffer-size))
3668                  (not no-display))
3669         (cond (gnus-newsgroup-dormant
3670                (gnus-summary-limit-include-dormant))
3671               ((and gnus-newsgroup-scored show-all)
3672                (gnus-summary-limit-include-expunged t))))
3673       ;; Function `gnus-apply-kill-file' must be called in this hook.
3674       (gnus-run-hooks 'gnus-apply-kill-hook)
3675       (if (and (zerop (buffer-size))
3676                (not no-display))
3677           (progn
3678             ;; This newsgroup is empty.
3679             (gnus-summary-catchup-and-exit nil t)
3680             (gnus-message 6 "No unread news")
3681             (when kill-buffer
3682               (gnus-kill-or-deaden-summary kill-buffer))
3683             ;; Return nil from this function.
3684             nil)
3685         ;; Hide conversation thread subtrees.  We cannot do this in
3686         ;; gnus-summary-prepare-hook since kill processing may not
3687         ;; work with hidden articles.
3688         (gnus-summary-maybe-hide-threads)
3689         (when kill-buffer
3690           (gnus-kill-or-deaden-summary kill-buffer))
3691         (gnus-summary-auto-select-subject)
3692         ;; Show first unread article if requested.
3693         (if (and (not no-article)
3694                  (not no-display)
3695                  gnus-newsgroup-unreads
3696                  gnus-auto-select-first)
3697             (progn
3698               (gnus-configure-windows 'summary)
3699               (let ((art (gnus-summary-article-number)))
3700                 (unless (and (not gnus-plugged)
3701                              (or (memq art gnus-newsgroup-undownloaded)
3702                                  (memq art gnus-newsgroup-downloadable)))
3703                   (gnus-summary-goto-article art))))
3704           ;; Don't select any articles.
3705           (gnus-summary-position-point)
3706           (gnus-configure-windows 'summary 'force)
3707           (gnus-set-mode-line 'summary))
3708         (when (and gnus-auto-center-group
3709                    (get-buffer-window gnus-group-buffer t))
3710           ;; Gotta use windows, because recenter does weird stuff if
3711           ;; the current buffer ain't the displayed window.
3712           (let ((owin (selected-window)))
3713             (select-window (get-buffer-window gnus-group-buffer t))
3714             (when (gnus-group-goto-group group)
3715               (recenter))
3716             (select-window owin)))
3717         ;; Mark this buffer as "prepared".
3718         (setq gnus-newsgroup-prepared t)
3719         (gnus-run-hooks 'gnus-summary-prepared-hook)
3720         (unless (gnus-ephemeral-group-p group)
3721           (gnus-group-update-group group))
3722         t)))))
3723
3724 (defun gnus-summary-auto-select-subject ()
3725   "Select the subject line on initial group entry."
3726   (goto-char (point-min))
3727   (cond
3728    ((eq gnus-auto-select-subject 'best)
3729     (gnus-summary-best-unread-subject))
3730    ((eq gnus-auto-select-subject 'unread)
3731     (gnus-summary-first-unread-subject))
3732    ((eq gnus-auto-select-subject 'unseen)
3733     (gnus-summary-first-unseen-subject))
3734    ((eq gnus-auto-select-subject 'unseen-or-unread)
3735     (gnus-summary-first-unseen-or-unread-subject))
3736    ((eq gnus-auto-select-subject 'first)
3737     ;; Do nothing.
3738     )
3739    ((functionp gnus-auto-select-subject)
3740     (funcall gnus-auto-select-subject))))
3741
3742 (defun gnus-summary-prepare ()
3743   "Generate the summary buffer."
3744   (interactive)
3745   (let ((buffer-read-only nil))
3746     (erase-buffer)
3747     (setq gnus-newsgroup-data nil
3748           gnus-newsgroup-data-reverse nil)
3749     (gnus-run-hooks 'gnus-summary-generate-hook)
3750     ;; Generate the buffer, either with threads or without.
3751     (when gnus-newsgroup-headers
3752       (gnus-summary-prepare-threads
3753        (if gnus-show-threads
3754            (gnus-sort-gathered-threads
3755             (funcall gnus-summary-thread-gathering-function
3756                      (gnus-sort-threads
3757                       (gnus-cut-threads (gnus-make-threads)))))
3758          ;; Unthreaded display.
3759          (gnus-sort-articles gnus-newsgroup-headers))))
3760     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3761     ;; Call hooks for modifying summary buffer.
3762     (goto-char (point-min))
3763     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3764
3765 (defsubst gnus-general-simplify-subject (subject)
3766   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3767   (setq subject
3768         (cond
3769          ;; Truncate the subject.
3770          (gnus-simplify-subject-functions
3771           (gnus-map-function gnus-simplify-subject-functions subject))
3772          ((numberp gnus-summary-gather-subject-limit)
3773           (setq subject (gnus-simplify-subject-re subject))
3774           (if (> (length subject) gnus-summary-gather-subject-limit)
3775               (substring subject 0 gnus-summary-gather-subject-limit)
3776             subject))
3777          ;; Fuzzily simplify it.
3778          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3779           (gnus-simplify-subject-fuzzy subject))
3780          ;; Just remove the leading "Re:".
3781          (t
3782           (gnus-simplify-subject-re subject))))
3783
3784   (if (and gnus-summary-gather-exclude-subject
3785            (string-match gnus-summary-gather-exclude-subject subject))
3786       nil                         ; This article shouldn't be gathered
3787     subject))
3788
3789 (defun gnus-summary-simplify-subject-query ()
3790   "Query where the respool algorithm would put this article."
3791   (interactive)
3792   (gnus-summary-select-article)
3793   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3794
3795 (defun gnus-gather-threads-by-subject (threads)
3796   "Gather threads by looking at Subject headers."
3797   (if (not gnus-summary-make-false-root)
3798       threads
3799     (let ((hashtb (gnus-make-hashtable 1024))
3800           (prev threads)
3801           (result threads)
3802           subject hthread whole-subject)
3803       (while threads
3804         (setq subject (gnus-general-simplify-subject
3805                        (setq whole-subject (mail-header-subject
3806                                             (caar threads)))))
3807         (when subject
3808           (if (setq hthread (gnus-gethash subject hashtb))
3809               (progn
3810                 ;; We enter a dummy root into the thread, if we
3811                 ;; haven't done that already.
3812                 (unless (stringp (caar hthread))
3813                   (setcar hthread (list whole-subject (car hthread))))
3814                 ;; We add this new gathered thread to this gathered
3815                 ;; thread.
3816                 (setcdr (car hthread)
3817                         (nconc (cdar hthread) (list (car threads))))
3818                 ;; Remove it from the list of threads.
3819                 (setcdr prev (cdr threads))
3820                 (setq threads prev))
3821             ;; Enter this thread into the hash table.
3822             (gnus-sethash subject
3823                           (if gnus-summary-make-false-root-always
3824                               (progn
3825                                 ;; If you want a dummy root above all
3826                                 ;; threads...
3827                                 (setcar threads (list whole-subject
3828                                                       (car threads)))
3829                                 threads)
3830                             threads)
3831                           hashtb)))
3832         (setq prev threads)
3833         (setq threads (cdr threads)))
3834       result)))
3835
3836 (defun gnus-gather-threads-by-references (threads)
3837   "Gather threads by looking at References headers."
3838   (let ((idhashtb (gnus-make-hashtable 1024))
3839         (thhashtb (gnus-make-hashtable 1024))
3840         (prev threads)
3841         (result threads)
3842         ids references id gthread gid entered ref)
3843     (while threads
3844       (when (setq references (mail-header-references (caar threads)))
3845         (setq id (mail-header-id (caar threads))
3846               ids (inline (gnus-split-references references))
3847               entered nil)
3848         (while (setq ref (pop ids))
3849           (setq ids (delete ref ids))
3850           (if (not (setq gid (gnus-gethash ref idhashtb)))
3851               (progn
3852                 (gnus-sethash ref id idhashtb)
3853                 (gnus-sethash id threads thhashtb))
3854             (setq gthread (gnus-gethash gid thhashtb))
3855             (unless entered
3856               ;; We enter a dummy root into the thread, if we
3857               ;; haven't done that already.
3858               (unless (stringp (caar gthread))
3859                 (setcar gthread (list (mail-header-subject (caar gthread))
3860                                       (car gthread))))
3861               ;; We add this new gathered thread to this gathered
3862               ;; thread.
3863               (setcdr (car gthread)
3864                       (nconc (cdar gthread) (list (car threads)))))
3865             ;; Add it into the thread hash table.
3866             (gnus-sethash id gthread thhashtb)
3867             (setq entered t)
3868             ;; Remove it from the list of threads.
3869             (setcdr prev (cdr threads))
3870             (setq threads prev))))
3871       (setq prev threads)
3872       (setq threads (cdr threads)))
3873     result))
3874
3875 (defun gnus-sort-gathered-threads (threads)
3876   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3877   (let ((result threads))
3878     (while threads
3879       (when (stringp (caar threads))
3880         (setcdr (car threads)
3881                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3882       (setq threads (cdr threads)))
3883     result))
3884
3885 (defun gnus-thread-loop-p (root thread)
3886   "Say whether ROOT is in THREAD."
3887   (let ((stack (list thread))
3888         (infloop 0)
3889         th)
3890     (while (setq thread (pop stack))
3891       (setq th (cdr thread))
3892       (while (and th
3893                   (not (eq (caar th) root)))
3894         (pop th))
3895       (if th
3896           ;; We have found a loop.
3897           (let (ref-dep)
3898             (setcdr thread (delq (car th) (cdr thread)))
3899             (if (boundp (setq ref-dep (intern "none"
3900                                               gnus-newsgroup-dependencies)))
3901                 (setcdr (symbol-value ref-dep)
3902                         (nconc (cdr (symbol-value ref-dep))
3903                                (list (car th))))
3904               (set ref-dep (list nil (car th))))
3905             (setq infloop 1
3906                   stack nil))
3907         ;; Push all the subthreads onto the stack.
3908         (push (cdr thread) stack)))
3909     infloop))
3910
3911 (defun gnus-make-threads ()
3912   "Go through the dependency hashtb and find the roots.  Return all threads."
3913   (let (threads)
3914     (while (catch 'infloop
3915              (mapatoms
3916               (lambda (refs)
3917                 ;; Deal with self-referencing References loops.
3918                 (when (and (car (symbol-value refs))
3919                            (not (zerop
3920                                  (apply
3921                                   '+
3922                                   (mapcar
3923                                    (lambda (thread)
3924                                      (gnus-thread-loop-p
3925                                       (car (symbol-value refs)) thread))
3926                                    (cdr (symbol-value refs)))))))
3927                   (setq threads nil)
3928                   (throw 'infloop t))
3929                 (unless (car (symbol-value refs))
3930                   ;; These threads do not refer back to any other
3931                   ;; articles, so they're roots.
3932                   (setq threads (append (cdr (symbol-value refs)) threads))))
3933               gnus-newsgroup-dependencies)))
3934     threads))
3935
3936 ;; Build the thread tree.
3937 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3938   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3939
3940 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3941 if it was already present.
3942
3943 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3944 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3945 Message-IDs will be renamed to a unique Message-ID before being
3946 entered.
3947
3948 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3949   (let* ((id (mail-header-id header))
3950          (id-dep (and id (intern id dependencies)))
3951          parent-id ref ref-dep ref-header replaced)
3952     ;; Enter this `header' in the `dependencies' table.
3953     (cond
3954      ((not id-dep)
3955       (setq header nil))
3956      ;; The first two cases do the normal part: enter a new `header'
3957      ;; in the `dependencies' table.
3958      ((not (boundp id-dep))
3959       (set id-dep (list header)))
3960      ((null (car (symbol-value id-dep)))
3961       (setcar (symbol-value id-dep) header))
3962
3963      ;; From here the `header' was already present in the
3964      ;; `dependencies' table.
3965      (force-new
3966       ;; Overrides an existing entry;
3967       ;; just set the header part of the entry.
3968       (setcar (symbol-value id-dep) header)
3969       (setq replaced t))
3970
3971      ;; Renames the existing `header' to a unique Message-ID.
3972      ((not gnus-summary-ignore-duplicates)
3973       ;; An article with this Message-ID has already been seen.
3974       ;; We rename the Message-ID.
3975       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3976            (list header))
3977       (mail-header-set-id header id))
3978
3979      ;; The last case ignores an existing entry, except it adds any
3980      ;; additional Xrefs (in case the two articles came from different
3981      ;; servers.
3982      ;; Also sets `header' to `nil' meaning that the `dependencies'
3983      ;; table was *not* modified.
3984      (t
3985       (mail-header-set-xref
3986        (car (symbol-value id-dep))
3987        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3988                    "")
3989                (or (mail-header-xref header) "")))
3990       (setq header nil)))
3991
3992     (when (and header (not replaced))
3993       ;; First check that we are not creating a References loop.
3994       (setq parent-id (gnus-parent-id (mail-header-references header)))
3995       (setq ref parent-id)
3996       (while (and ref
3997                   (setq ref-dep (intern-soft ref dependencies))
3998                   (boundp ref-dep)
3999                   (setq ref-header (car (symbol-value ref-dep))))
4000         (if (string= id ref)
4001             ;; Yuk!  This is a reference loop.  Make the article be a
4002             ;; root article.
4003             (progn
4004               (mail-header-set-references (car (symbol-value id-dep)) "none")
4005               (setq ref nil)
4006               (setq parent-id nil))
4007           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4008       (setq ref-dep (intern (or parent-id "none") dependencies))
4009       (if (boundp ref-dep)
4010           (setcdr (symbol-value ref-dep)
4011                   (nconc (cdr (symbol-value ref-dep))
4012                          (list (symbol-value id-dep))))
4013         (set ref-dep (list nil (symbol-value id-dep)))))
4014     header))
4015
4016 (defun gnus-extract-message-id-from-in-reply-to (string)
4017   (if (string-match "<[^>]+>" string)
4018       (substring string (match-beginning 0) (match-end 0))
4019     nil))
4020
4021 (defun gnus-build-sparse-threads ()
4022   (let ((headers gnus-newsgroup-headers)
4023         (mail-parse-charset gnus-newsgroup-charset)
4024         (gnus-summary-ignore-duplicates t)
4025         header references generation relations
4026         subject child end new-child date)
4027     ;; First we create an alist of generations/relations, where
4028     ;; generations is how much we trust the relation, and the relation
4029     ;; is parent/child.
4030     (gnus-message 7 "Making sparse threads...")
4031     (save-excursion
4032       (nnheader-set-temp-buffer " *gnus sparse threads*")
4033       (while (setq header (pop headers))
4034         (when (and (setq references (mail-header-references header))
4035                    (not (string= references "")))
4036           (insert references)
4037           (setq child (mail-header-id header)
4038                 subject (mail-header-subject header)
4039                 date (mail-header-date header)
4040                 generation 0)
4041           (while (search-backward ">" nil t)
4042             (setq end (1+ (point)))
4043             (when (search-backward "<" nil t)
4044               (setq new-child (buffer-substring (point) end))
4045               (push (list (incf generation)
4046                           child (setq child new-child)
4047                           subject date)
4048                     relations)))
4049           (when child
4050             (push (list (1+ generation) child nil subject) relations))
4051           (erase-buffer)))
4052       (kill-buffer (current-buffer)))
4053     ;; Sort over trustworthiness.
4054     (mapcar
4055      (lambda (relation)
4056        (when (gnus-dependencies-add-header
4057               (make-full-mail-header
4058                gnus-reffed-article-number
4059                (nth 3 relation) "" (or (nth 4 relation) "")
4060                (nth 1 relation)
4061                (or (nth 2 relation) "") 0 0 "")
4062               gnus-newsgroup-dependencies nil)
4063          (push gnus-reffed-article-number gnus-newsgroup-limit)
4064          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4065          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4066                gnus-newsgroup-reads)
4067          (decf gnus-reffed-article-number)))
4068      (sort relations 'car-less-than-car))
4069     (gnus-message 7 "Making sparse threads...done")))
4070
4071 (defun gnus-build-old-threads ()
4072   ;; Look at all the articles that refer back to old articles, and
4073   ;; fetch the headers for the articles that aren't there.  This will
4074   ;; build complete threads - if the roots haven't been expired by the
4075   ;; server, that is.
4076   (let ((mail-parse-charset gnus-newsgroup-charset)
4077         id heads)
4078     (mapatoms
4079      (lambda (refs)
4080        (when (not (car (symbol-value refs)))
4081          (setq heads (cdr (symbol-value refs)))
4082          (while heads
4083            (if (memq (mail-header-number (caar heads))
4084                      gnus-newsgroup-dormant)
4085                (setq heads (cdr heads))
4086              (setq id (symbol-name refs))
4087              (while (and (setq id (gnus-build-get-header id))
4088                          (not (car (gnus-id-to-thread id)))))
4089              (setq heads nil)))))
4090      gnus-newsgroup-dependencies)))
4091
4092 (defsubst gnus-remove-odd-characters (string)
4093   "Translate STRING into something that doesn't contain weird characters."
4094   (mm-subst-char-in-string
4095    ?\r ?\-
4096    (mm-subst-char-in-string ?\n ?\- string t) t))
4097
4098 ;; This function has to be called with point after the article number
4099 ;; on the beginning of the line.
4100 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4101   (let ((eol (point-at-eol))
4102         (buffer (current-buffer))
4103         header references in-reply-to)
4104
4105     ;; overview: [num subject from date id refs chars lines misc]
4106     (unwind-protect
4107         (let (x)
4108           (narrow-to-region (point) eol)
4109           (unless (eobp)
4110             (forward-char))
4111
4112           (setq header
4113                 (make-full-mail-header
4114                  number                 ; number
4115                  (condition-case ()     ; subject
4116                      (gnus-remove-odd-characters
4117                       (funcall gnus-decode-encoded-word-function
4118                                (setq x (nnheader-nov-field))))
4119                    (error x))
4120                  (condition-case ()     ; from
4121                      (gnus-remove-odd-characters
4122                       (funcall gnus-decode-encoded-word-function
4123                                (setq x (nnheader-nov-field))))
4124                    (error x))
4125                  (nnheader-nov-field)   ; date
4126                  (nnheader-nov-read-message-id number)  ; id
4127                  (setq references (nnheader-nov-field)) ; refs
4128                  (nnheader-nov-read-integer) ; chars
4129                  (nnheader-nov-read-integer) ; lines
4130                  (unless (eobp)
4131                    (if (looking-at "Xref: ")
4132                        (goto-char (match-end 0)))
4133                    (nnheader-nov-field)) ; Xref
4134                  (nnheader-nov-parse-extra)))) ; extra
4135
4136       (widen))
4137
4138     (when (and (string= references "")
4139                (setq in-reply-to (mail-header-extra header))
4140                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4141       (mail-header-set-references
4142        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4143
4144     (when gnus-alter-header-function
4145       (funcall gnus-alter-header-function header))
4146     (gnus-dependencies-add-header header dependencies force-new)))
4147
4148 (defun gnus-build-get-header (id)
4149   "Look through the buffer of NOV lines and find the header to ID.
4150 Enter this line into the dependencies hash table, and return
4151 the id of the parent article (if any)."
4152   (let ((deps gnus-newsgroup-dependencies)
4153         found header)
4154     (prog1
4155         (save-excursion
4156           (set-buffer nntp-server-buffer)
4157           (let ((case-fold-search nil))
4158             (goto-char (point-min))
4159             (while (and (not found)
4160                         (search-forward id nil t))
4161               (beginning-of-line)
4162               (setq found (looking-at
4163                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4164                                    (regexp-quote id))))
4165               (or found (beginning-of-line 2)))
4166             (when found
4167               (beginning-of-line)
4168               (and
4169                (setq header (gnus-nov-parse-line
4170                              (read (current-buffer)) deps))
4171                (gnus-parent-id (mail-header-references header))))))
4172       (when header
4173         (let ((number (mail-header-number header)))
4174           (push number gnus-newsgroup-limit)
4175           (push header gnus-newsgroup-headers)
4176           (if (memq number gnus-newsgroup-unselected)
4177               (progn
4178                 (setq gnus-newsgroup-unreads
4179                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4180                                                number))
4181                 (setq gnus-newsgroup-unselected
4182                       (delq number gnus-newsgroup-unselected)))
4183             (push number gnus-newsgroup-ancient)))))))
4184
4185 (defun gnus-build-all-threads ()
4186   "Read all the headers."
4187   (let ((gnus-summary-ignore-duplicates t)
4188         (mail-parse-charset gnus-newsgroup-charset)
4189         (dependencies gnus-newsgroup-dependencies)
4190         header article)
4191     (save-excursion
4192       (set-buffer nntp-server-buffer)
4193       (let ((case-fold-search nil))
4194         (goto-char (point-min))
4195         (while (not (eobp))
4196           (ignore-errors
4197             (setq article (read (current-buffer))
4198                   header (gnus-nov-parse-line article dependencies)))
4199           (when header
4200             (with-current-buffer gnus-summary-buffer
4201               (push header gnus-newsgroup-headers)
4202               (if (memq (setq article (mail-header-number header))
4203                         gnus-newsgroup-unselected)
4204                   (progn
4205                     (setq gnus-newsgroup-unreads
4206                           (gnus-add-to-sorted-list
4207                            gnus-newsgroup-unreads article))
4208                     (setq gnus-newsgroup-unselected
4209                           (delq article gnus-newsgroup-unselected)))
4210                 (push article gnus-newsgroup-ancient)))
4211             (forward-line 1)))))))
4212
4213 (defun gnus-summary-update-article-line (article header)
4214   "Update the line for ARTICLE using HEADER."
4215   (let* ((id (mail-header-id header))
4216          (thread (gnus-id-to-thread id)))
4217     (unless thread
4218       (error "Article in no thread"))
4219     ;; Update the thread.
4220     (setcar thread header)
4221     (gnus-summary-goto-subject article)
4222     (let* ((datal (gnus-data-find-list article))
4223            (data (car datal))
4224            (buffer-read-only nil)
4225            (level (gnus-summary-thread-level)))
4226       (gnus-delete-line)
4227       (let ((inserted (- (point)
4228                          (progn
4229                            (gnus-summary-insert-line
4230                             header level nil
4231                             (memq article gnus-newsgroup-undownloaded)
4232                             (gnus-article-mark article)
4233                             (memq article gnus-newsgroup-replied)
4234                             (memq article gnus-newsgroup-expirable)
4235                             ;; Only insert the Subject string when it's different
4236                             ;; from the previous Subject string.
4237                             (if (and
4238                                  gnus-show-threads
4239                                  (gnus-subject-equal
4240                                   (condition-case ()
4241                                       (mail-header-subject
4242                                        (gnus-data-header
4243                                         (cadr
4244                                          (gnus-data-find-list
4245                                           article
4246                                           (gnus-data-list t)))))
4247                                     ;; Error on the side of excessive subjects.
4248                                     (error ""))
4249                                   (mail-header-subject header)))
4250                                 ""
4251                               (mail-header-subject header))
4252                             nil (cdr (assq article gnus-newsgroup-scored))
4253                             (memq article gnus-newsgroup-processable))
4254                            (point)))))
4255         (when (cdr datal)
4256           (gnus-data-update-list
4257            (cdr datal)
4258            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4259
4260 (defun gnus-summary-update-article (article &optional iheader)
4261   "Update ARTICLE in the summary buffer."
4262   (set-buffer gnus-summary-buffer)
4263   (let* ((header (gnus-summary-article-header article))
4264          (id (mail-header-id header))
4265          (data (gnus-data-find article))
4266          (thread (gnus-id-to-thread id))
4267          (references (mail-header-references header))
4268          (parent
4269           (gnus-id-to-thread
4270            (or (gnus-parent-id
4271                 (when (and references
4272                            (not (equal "" references)))
4273                   references))
4274                "none")))
4275          (buffer-read-only nil)
4276          (old (car thread)))
4277     (when thread
4278       (unless iheader
4279         (setcar thread nil)
4280         (when parent
4281           (delq thread parent)))
4282       (if (gnus-summary-insert-subject id header)
4283           ;; Set the (possibly) new article number in the data structure.
4284           (gnus-data-set-number data (gnus-id-to-article id))
4285         (setcar thread old)
4286         nil))))
4287
4288 (defun gnus-rebuild-thread (id &optional line)
4289   "Rebuild the thread containing ID.
4290 If LINE, insert the rebuilt thread starting on line LINE."
4291   (let ((buffer-read-only nil)
4292         old-pos current thread data)
4293     (if (not gnus-show-threads)
4294         (setq thread (list (car (gnus-id-to-thread id))))
4295       ;; Get the thread this article is part of.
4296       (setq thread (gnus-remove-thread id)))
4297     (setq old-pos (point-at-bol))
4298     (setq current (save-excursion
4299                     (and (re-search-backward "[\r\n]" nil t)
4300                          (gnus-summary-article-number))))
4301     ;; If this is a gathered thread, we have to go some re-gathering.
4302     (when (stringp (car thread))
4303       (let ((subject (car thread))
4304             roots thr)
4305         (setq thread (cdr thread))
4306         (while thread
4307           (unless (memq (setq thr (gnus-id-to-thread
4308                                    (gnus-root-id
4309                                     (mail-header-id (caar thread)))))
4310                         roots)
4311             (push thr roots))
4312           (setq thread (cdr thread)))
4313         ;; We now have all (unique) roots.
4314         (if (= (length roots) 1)
4315             ;; All the loose roots are now one solid root.
4316             (setq thread (car roots))
4317           (setq thread (cons subject (gnus-sort-threads roots))))))
4318     (let (threads)
4319       ;; We then insert this thread into the summary buffer.
4320       (when line
4321         (goto-char (point-min))
4322         (forward-line (1- line)))
4323       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4324         (if gnus-show-threads
4325             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4326           (gnus-summary-prepare-unthreaded thread))
4327         (setq data (nreverse gnus-newsgroup-data))
4328         (setq threads gnus-newsgroup-threads))
4329       ;; We splice the new data into the data structure.
4330       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4331       ;;!!! then we want to insert at the beginning of the buffer.
4332       ;;!!! That happens to be true with Gnus now, but that may
4333       ;;!!! change in the future.  Perhaps.
4334       (gnus-data-enter-list
4335        (if line nil current) data (- (point) old-pos))
4336       (setq gnus-newsgroup-threads
4337             (nconc threads gnus-newsgroup-threads))
4338       (gnus-data-compute-positions))))
4339
4340 (defun gnus-number-to-header (number)
4341   "Return the header for article NUMBER."
4342   (let ((headers gnus-newsgroup-headers))
4343     (while (and headers
4344                 (not (= number (mail-header-number (car headers)))))
4345       (pop headers))
4346     (when headers
4347       (car headers))))
4348
4349 (defun gnus-parent-headers (in-headers &optional generation)
4350   "Return the headers of the GENERATIONeth parent of HEADERS."
4351   (unless generation
4352     (setq generation 1))
4353   (let ((parent t)
4354         (headers in-headers)
4355         references)
4356     (while (and parent
4357                 (not (zerop generation))
4358                 (setq references (mail-header-references headers)))
4359       (setq headers (if (and references
4360                              (setq parent (gnus-parent-id references)))
4361                         (car (gnus-id-to-thread parent))
4362                       nil))
4363       (decf generation))
4364     (and (not (eq headers in-headers))
4365          headers)))
4366
4367 (defun gnus-id-to-thread (id)
4368   "Return the (sub-)thread where ID appears."
4369   (gnus-gethash id gnus-newsgroup-dependencies))
4370
4371 (defun gnus-id-to-article (id)
4372   "Return the article number of ID."
4373   (let ((thread (gnus-id-to-thread id)))
4374     (when (and thread
4375                (car thread))
4376       (mail-header-number (car thread)))))
4377
4378 (defun gnus-id-to-header (id)
4379   "Return the article headers of ID."
4380   (car (gnus-id-to-thread id)))
4381
4382 (defun gnus-article-displayed-root-p (article)
4383   "Say whether ARTICLE is a root(ish) article."
4384   (let ((level (gnus-summary-thread-level article))
4385         (refs (mail-header-references  (gnus-summary-article-header article)))
4386         particle)
4387     (cond
4388      ((null level) nil)
4389      ((zerop level) t)
4390      ((null refs) t)
4391      ((null (gnus-parent-id refs)) t)
4392      ((and (= 1 level)
4393            (null (setq particle (gnus-id-to-article
4394                                  (gnus-parent-id refs))))
4395            (null (gnus-summary-thread-level particle)))))))
4396
4397 (defun gnus-root-id (id)
4398   "Return the id of the root of the thread where ID appears."
4399   (let (last-id prev)
4400     (while (and id (setq prev (car (gnus-id-to-thread id))))
4401       (setq last-id id
4402             id (gnus-parent-id (mail-header-references prev))))
4403     last-id))
4404
4405 (defun gnus-articles-in-thread (thread)
4406   "Return the list of articles in THREAD."
4407   (cons (mail-header-number (car thread))
4408         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4409
4410 (defun gnus-remove-thread (id &optional dont-remove)
4411   "Remove the thread that has ID in it."
4412   (let (headers thread last-id)
4413     ;; First go up in this thread until we find the root.
4414     (setq last-id (gnus-root-id id)
4415           headers (message-flatten-list (gnus-id-to-thread last-id)))
4416     ;; We have now found the real root of this thread.  It might have
4417     ;; been gathered into some loose thread, so we have to search
4418     ;; through the threads to find the thread we wanted.
4419     (let ((threads gnus-newsgroup-threads)
4420           sub)
4421       (while threads
4422         (setq sub (car threads))
4423         (if (stringp (car sub))
4424             ;; This is a gathered thread, so we look at the roots
4425             ;; below it to find whether this article is in this
4426             ;; gathered root.
4427             (progn
4428               (setq sub (cdr sub))
4429               (while sub
4430                 (when (member (caar sub) headers)
4431                   (setq thread (car threads)
4432                         threads nil
4433                         sub nil))
4434                 (setq sub (cdr sub))))
4435           ;; It's an ordinary thread, so we check it.
4436           (when (eq (car sub) (car headers))
4437             (setq thread sub
4438                   threads nil)))
4439         (setq threads (cdr threads)))
4440       ;; If this article is in no thread, then it's a root.
4441       (if thread
4442           (unless dont-remove
4443             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4444         (setq thread (gnus-id-to-thread last-id)))
4445       (when thread
4446         (prog1
4447             thread                      ; We return this thread.
4448           (unless dont-remove
4449             (if (stringp (car thread))
4450                 (progn
4451                   ;; If we use dummy roots, then we have to remove the
4452                   ;; dummy root as well.
4453                   (when (eq gnus-summary-make-false-root 'dummy)
4454                     ;; We go to the dummy root by going to
4455                     ;; the first sub-"thread", and then one line up.
4456                     (gnus-summary-goto-article
4457                      (mail-header-number (caadr thread)))
4458                     (forward-line -1)
4459                     (gnus-delete-line)
4460                     (gnus-data-compute-positions))
4461                   (setq thread (cdr thread))
4462                   (while thread
4463                     (gnus-remove-thread-1 (car thread))
4464                     (setq thread (cdr thread))))
4465               (gnus-remove-thread-1 thread))))))))
4466
4467 (defun gnus-remove-thread-1 (thread)
4468   "Remove the thread THREAD recursively."
4469   (let ((number (mail-header-number (pop thread)))
4470         d)
4471     (setq thread (reverse thread))
4472     (while thread
4473       (gnus-remove-thread-1 (pop thread)))
4474     (when (setq d (gnus-data-find number))
4475       (goto-char (gnus-data-pos d))
4476       (gnus-summary-show-thread)
4477       (gnus-data-remove
4478        number
4479        (- (point-at-bol)
4480           (prog1
4481               (1+ (point-at-eol))
4482             (gnus-delete-line)))))))
4483
4484 (defun gnus-sort-threads-1 (threads func)
4485   (sort (mapcar (lambda (thread)
4486                   (cons (car thread)
4487                         (and (cdr thread)
4488                              (gnus-sort-threads-1 (cdr thread) func))))
4489                 threads) func))
4490
4491 (defun gnus-sort-threads (threads)
4492   "Sort THREADS."
4493   (if (not gnus-thread-sort-functions)
4494       threads
4495     (gnus-message 8 "Sorting threads...")
4496     (let ((max-lisp-eval-depth 5000))
4497       (prog1 (gnus-sort-threads-1
4498          threads
4499          (gnus-make-sort-function gnus-thread-sort-functions))
4500         (gnus-message 8 "Sorting threads...done")))))
4501
4502 (defun gnus-sort-articles (articles)
4503   "Sort ARTICLES."
4504   (when gnus-article-sort-functions
4505     (gnus-message 7 "Sorting articles...")
4506     (prog1
4507         (setq gnus-newsgroup-headers
4508               (sort articles (gnus-make-sort-function
4509                               gnus-article-sort-functions)))
4510       (gnus-message 7 "Sorting articles...done"))))
4511
4512 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4513 (defmacro gnus-thread-header (thread)
4514   "Return header of first article in THREAD.
4515 Note that THREAD must never, ever be anything else than a variable -
4516 using some other form will lead to serious barfage."
4517   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4518   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4519   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4520         (vector thread) 2))
4521
4522 (defsubst gnus-article-sort-by-number (h1 h2)
4523   "Sort articles by article number."
4524   (< (mail-header-number h1)
4525      (mail-header-number h2)))
4526
4527 (defun gnus-thread-sort-by-number (h1 h2)
4528   "Sort threads by root article number."
4529   (gnus-article-sort-by-number
4530    (gnus-thread-header h1) (gnus-thread-header h2)))
4531
4532 (defsubst gnus-article-sort-by-random (h1 h2)
4533   "Sort articles by article number."
4534   (zerop (random 2)))
4535
4536 (defun gnus-thread-sort-by-random (h1 h2)
4537   "Sort threads by root article number."
4538   (gnus-article-sort-by-random
4539    (gnus-thread-header h1) (gnus-thread-header h2)))
4540
4541 (defsubst gnus-article-sort-by-lines (h1 h2)
4542   "Sort articles by article Lines header."
4543   (< (mail-header-lines h1)
4544      (mail-header-lines h2)))
4545
4546 (defun gnus-thread-sort-by-lines (h1 h2)
4547   "Sort threads by root article Lines header."
4548   (gnus-article-sort-by-lines
4549    (gnus-thread-header h1) (gnus-thread-header h2)))
4550
4551 (defsubst gnus-article-sort-by-chars (h1 h2)
4552   "Sort articles by octet length."
4553   (< (mail-header-chars h1)
4554      (mail-header-chars h2)))
4555
4556 (defun gnus-thread-sort-by-chars (h1 h2)
4557   "Sort threads by root article octet length."
4558   (gnus-article-sort-by-chars
4559    (gnus-thread-header h1) (gnus-thread-header h2)))
4560
4561 (defsubst gnus-article-sort-by-author (h1 h2)
4562   "Sort articles by root author."
4563   (string-lessp
4564    (let ((extract (funcall
4565                    gnus-extract-address-components
4566                    (mail-header-from h1))))
4567      (or (car extract) (cadr extract) ""))
4568    (let ((extract (funcall
4569                    gnus-extract-address-components
4570                    (mail-header-from h2))))
4571      (or (car extract) (cadr extract) ""))))
4572
4573 (defun gnus-thread-sort-by-author (h1 h2)
4574   "Sort threads by root author."
4575   (gnus-article-sort-by-author
4576    (gnus-thread-header h1)  (gnus-thread-header h2)))
4577
4578 (defsubst gnus-article-sort-by-recipient (h1 h2)
4579   "Sort articles by recipient."
4580   (string-lessp
4581    (let ((extract (funcall
4582                    gnus-extract-address-components
4583                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4584      (or (car extract) (cadr extract)))
4585    (let ((extract (funcall
4586                    gnus-extract-address-components
4587                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4588      (or (car extract) (cadr extract)))))
4589
4590 (defsubst gnus-article-sort-by-subject (h1 h2)
4591   "Sort articles by root subject."
4592   (string-lessp
4593    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4594    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4595
4596 (defun gnus-thread-sort-by-subject (h1 h2)
4597   "Sort threads by root subject."
4598   (gnus-article-sort-by-subject
4599    (gnus-thread-header h1) (gnus-thread-header h2)))
4600
4601 (defsubst gnus-article-sort-by-date (h1 h2)
4602   "Sort articles by root article date."
4603   (time-less-p
4604    (gnus-date-get-time (mail-header-date h1))
4605    (gnus-date-get-time (mail-header-date h2))))
4606
4607 (defun gnus-thread-sort-by-date (h1 h2)
4608   "Sort threads by root article date."
4609   (gnus-article-sort-by-date
4610    (gnus-thread-header h1) (gnus-thread-header h2)))
4611
4612 (defsubst gnus-article-sort-by-score (h1 h2)
4613   "Sort articles by root article score.
4614 Unscored articles will be counted as having a score of zero."
4615   (> (or (cdr (assq (mail-header-number h1)
4616                     gnus-newsgroup-scored))
4617          gnus-summary-default-score 0)
4618      (or (cdr (assq (mail-header-number h2)
4619                     gnus-newsgroup-scored))
4620          gnus-summary-default-score 0)))
4621
4622 (defun gnus-thread-sort-by-score (h1 h2)
4623   "Sort threads by root article score."
4624   (gnus-article-sort-by-score
4625    (gnus-thread-header h1) (gnus-thread-header h2)))
4626
4627 (defun gnus-thread-sort-by-total-score (h1 h2)
4628   "Sort threads by the sum of all scores in the thread.
4629 Unscored articles will be counted as having a score of zero."
4630   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4631
4632 (defun gnus-thread-total-score (thread)
4633   ;; This function find the total score of THREAD.
4634   (cond
4635    ((null thread)
4636     0)
4637    ((consp thread)
4638     (if (stringp (car thread))
4639         (apply gnus-thread-score-function 0
4640                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4641       (gnus-thread-total-score-1 thread)))
4642    (t
4643     (gnus-thread-total-score-1 (list thread)))))
4644
4645 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4646   "Sort threads such that the thread with the most recently arrived article comes first."
4647   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4648
4649 (defun gnus-thread-highest-number (thread)
4650   "Return the highest article number in THREAD."
4651   (apply 'max (mapcar (lambda (header)
4652                         (mail-header-number header))
4653                       (message-flatten-list thread))))
4654
4655 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4656   "Sort threads such that the thread with the most recently dated article comes first."
4657   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4658
4659 (defun gnus-thread-latest-date (thread)
4660   "Return the highest article date in THREAD."
4661   (let ((previous-time 0))
4662     (apply 'max
4663            (mapcar
4664             (lambda (header)
4665               (setq previous-time
4666                     (condition-case ()
4667                         (time-to-seconds (mail-header-parse-date
4668                                           (mail-header-date header)))
4669                       (error previous-time))))
4670             (sort
4671              (message-flatten-list thread)
4672              (lambda (h1 h2)
4673                (< (mail-header-number h1)
4674                   (mail-header-number h2))))))))
4675
4676 (defun gnus-thread-total-score-1 (root)
4677   ;; This function find the total score of the thread below ROOT.
4678   (setq root (car root))
4679   (apply gnus-thread-score-function
4680          (or (append
4681               (mapcar 'gnus-thread-total-score
4682                       (cdr (gnus-id-to-thread (mail-header-id root))))
4683               (when (> (mail-header-number root) 0)
4684                 (list (or (cdr (assq (mail-header-number root)
4685                                      gnus-newsgroup-scored))
4686                           gnus-summary-default-score 0))))
4687              (list gnus-summary-default-score)
4688              '(0))))
4689
4690 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4691 (defvar gnus-tmp-prev-subject nil)
4692 (defvar gnus-tmp-false-parent nil)
4693 (defvar gnus-tmp-root-expunged nil)
4694 (defvar gnus-tmp-dummy-line nil)
4695
4696 (eval-when-compile (defvar gnus-tmp-header))
4697 (defun gnus-extra-header (type &optional header)
4698   "Return the extra header of TYPE."
4699   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4700       ""))
4701
4702 (defvar gnus-tmp-thread-tree-header-string "")
4703
4704 (defcustom gnus-sum-thread-tree-root "> "
4705   "With %B spec, used for the root of a thread.
4706 If nil, use subject instead."
4707   :version "21.4"
4708   :type '(radio (const :format "%v  " nil) string)
4709   :group 'gnus-thread)
4710 (defcustom gnus-sum-thread-tree-false-root "> "
4711   "With %B spec, used for a false root of a thread.
4712 If nil, use subject instead."
4713   :version "21.4"
4714   :type '(radio (const :format "%v  " nil) string)
4715   :group 'gnus-thread)
4716 (defcustom gnus-sum-thread-tree-single-indent ""
4717   "With %B spec, used for a thread with just one message.
4718 If nil, use subject instead."
4719   :version "21.4"
4720   :type '(radio (const :format "%v  " nil) string)
4721   :group 'gnus-thread)
4722 (defcustom gnus-sum-thread-tree-vertical "| "
4723   "With %B spec, used for drawing a vertical line."
4724   :version "21.4"
4725   :type 'string
4726   :group 'gnus-thread)
4727 (defcustom gnus-sum-thread-tree-indent "  "
4728   "With %B spec, used for indenting."
4729   :version "21.4"
4730   :type 'string
4731   :group 'gnus-thread)
4732 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4733   "With %B spec, used for a leaf with brothers."
4734   :version "21.4"
4735   :type 'string
4736   :group 'gnus-thread)
4737 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4738   "With %B spec, used for a leaf without brothers."
4739   :version "21.4"
4740   :type 'string
4741   :group 'gnus-thread)
4742
4743 (defun gnus-summary-prepare-threads (threads)
4744   "Prepare summary buffer from THREADS and indentation LEVEL.
4745 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4746 or a straight list of headers."
4747   (gnus-message 7 "Generating summary...")
4748
4749   (setq gnus-newsgroup-threads threads)
4750   (beginning-of-line)
4751
4752   (let ((gnus-tmp-level 0)
4753         (default-score (or gnus-summary-default-score 0))
4754         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4755         (building-line-count gnus-summary-display-while-building)
4756         (building-count (integerp gnus-summary-display-while-building))
4757         thread number subject stack state gnus-tmp-gathered beg-match
4758         new-roots gnus-tmp-new-adopts thread-end simp-subject
4759         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4760         gnus-tmp-replied gnus-tmp-subject-or-nil
4761         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4762         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4763         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4764         tree-stack)
4765
4766     (setq gnus-tmp-prev-subject nil
4767           gnus-tmp-thread-tree-header-string "")
4768
4769     (if (vectorp (car threads))
4770         ;; If this is a straight (sic) list of headers, then a
4771         ;; threaded summary display isn't required, so we just create
4772         ;; an unthreaded one.
4773         (gnus-summary-prepare-unthreaded threads)
4774
4775       ;; Do the threaded display.
4776
4777       (if gnus-summary-display-while-building
4778           (switch-to-buffer (buffer-name)))
4779       (while (or threads stack gnus-tmp-new-adopts new-roots)
4780
4781         (if (and (= gnus-tmp-level 0)
4782                  (or (not stack)
4783                      (= (caar stack) 0))
4784                  (not gnus-tmp-false-parent)
4785                  (or gnus-tmp-new-adopts new-roots))
4786             (if gnus-tmp-new-adopts
4787                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4788                       thread (list (car gnus-tmp-new-adopts))
4789                       gnus-tmp-header (caar thread)
4790                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4791               (when new-roots
4792                 (setq thread (list (car new-roots))
4793                       gnus-tmp-header (caar thread)
4794                       new-roots (cdr new-roots))))
4795
4796           (if threads
4797               ;; If there are some threads, we do them before the
4798               ;; threads on the stack.
4799               (setq thread threads
4800                     gnus-tmp-header (caar thread))
4801             ;; There were no current threads, so we pop something off
4802             ;; the stack.
4803             (setq state (car stack)
4804                   gnus-tmp-level (car state)
4805                   tree-stack (cadr state)
4806                   thread (caddr state)
4807                   stack (cdr stack)
4808                   gnus-tmp-header (caar thread))))
4809
4810         (setq gnus-tmp-false-parent nil)
4811         (setq gnus-tmp-root-expunged nil)
4812         (setq thread-end nil)
4813
4814         (if (stringp gnus-tmp-header)
4815             ;; The header is a dummy root.
4816             (cond
4817              ((eq gnus-summary-make-false-root 'adopt)
4818               ;; We let the first article adopt the rest.
4819               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4820                                                (cddar thread)))
4821               (setq gnus-tmp-gathered
4822                     (nconc (mapcar
4823                             (lambda (h) (mail-header-number (car h)))
4824                             (cddar thread))
4825                            gnus-tmp-gathered))
4826               (setq thread (cons (list (caar thread)
4827                                        (cadar thread))
4828                                  (cdr thread)))
4829               (setq gnus-tmp-level -1
4830                     gnus-tmp-false-parent t))
4831              ((eq gnus-summary-make-false-root 'empty)
4832               ;; We print adopted articles with empty subject fields.
4833               (setq gnus-tmp-gathered
4834                     (nconc (mapcar
4835                             (lambda (h) (mail-header-number (car h)))
4836                             (cddar thread))
4837                            gnus-tmp-gathered))
4838               (setq gnus-tmp-level -1))
4839              ((eq gnus-summary-make-false-root 'dummy)
4840               ;; We remember that we probably want to output a dummy
4841               ;; root.
4842               (setq gnus-tmp-dummy-line gnus-tmp-header)
4843               (setq gnus-tmp-prev-subject gnus-tmp-header))
4844              (t
4845               ;; We do not make a root for the gathered
4846               ;; sub-threads at all.
4847               (setq gnus-tmp-level -1)))
4848
4849           (setq number (mail-header-number gnus-tmp-header)
4850                 subject (mail-header-subject gnus-tmp-header)
4851                 simp-subject (gnus-simplify-subject-fully subject))
4852
4853           (cond
4854            ;; If the thread has changed subject, we might want to make
4855            ;; this subthread into a root.
4856            ((and (null gnus-thread-ignore-subject)
4857                  (not (zerop gnus-tmp-level))
4858                  gnus-tmp-prev-subject
4859                  (not (string= gnus-tmp-prev-subject simp-subject)))
4860             (setq new-roots (nconc new-roots (list (car thread)))
4861                   thread-end t
4862                   gnus-tmp-header nil))
4863            ;; If the article lies outside the current limit,
4864            ;; then we do not display it.
4865            ((not (memq number gnus-newsgroup-limit))
4866             (setq gnus-tmp-gathered
4867                   (nconc (mapcar
4868                           (lambda (h) (mail-header-number (car h)))
4869                           (cdar thread))
4870                          gnus-tmp-gathered))
4871             (setq gnus-tmp-new-adopts (if (cdar thread)
4872                                           (append gnus-tmp-new-adopts
4873                                                   (cdar thread))
4874                                         gnus-tmp-new-adopts)
4875                   thread-end t
4876                   gnus-tmp-header nil)
4877             (when (zerop gnus-tmp-level)
4878               (setq gnus-tmp-root-expunged t)))
4879            ;; Perhaps this article is to be marked as read?
4880            ((and gnus-summary-mark-below
4881                  (< (or (cdr (assq number gnus-newsgroup-scored))
4882                         default-score)
4883                     gnus-summary-mark-below)
4884                  ;; Don't touch sparse articles.
4885                  (not (gnus-summary-article-sparse-p number))
4886                  (not (gnus-summary-article-ancient-p number)))
4887             (setq gnus-newsgroup-unreads
4888                   (delq number gnus-newsgroup-unreads))
4889             (if gnus-newsgroup-auto-expire
4890                 (setq gnus-newsgroup-expirable
4891                       (gnus-add-to-sorted-list
4892                        gnus-newsgroup-expirable number))
4893               (push (cons number gnus-low-score-mark)
4894                     gnus-newsgroup-reads))))
4895
4896           (when gnus-tmp-header
4897             ;; We may have an old dummy line to output before this
4898             ;; article.
4899             (when (and gnus-tmp-dummy-line
4900                        (gnus-subject-equal
4901                         gnus-tmp-dummy-line
4902                         (mail-header-subject gnus-tmp-header)))
4903               (gnus-summary-insert-dummy-line
4904                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4905               (setq gnus-tmp-dummy-line nil))
4906
4907             ;; Compute the mark.
4908             (setq gnus-tmp-unread (gnus-article-mark number))
4909
4910             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4911                                   gnus-tmp-header gnus-tmp-level)
4912                   gnus-newsgroup-data)
4913
4914             ;; Actually insert the line.
4915             (setq
4916              gnus-tmp-subject-or-nil
4917              (cond
4918               ((and gnus-thread-ignore-subject
4919                     gnus-tmp-prev-subject
4920                     (not (string= gnus-tmp-prev-subject simp-subject)))
4921                subject)
4922               ((zerop gnus-tmp-level)
4923                (if (and (eq gnus-summary-make-false-root 'empty)
4924                         (memq number gnus-tmp-gathered)
4925                         gnus-tmp-prev-subject
4926                         (string= gnus-tmp-prev-subject simp-subject))
4927                    gnus-summary-same-subject
4928                  subject))
4929               (t gnus-summary-same-subject)))
4930             (if (and (eq gnus-summary-make-false-root 'adopt)
4931                      (= gnus-tmp-level 1)
4932                      (memq number gnus-tmp-gathered))
4933                 (setq gnus-tmp-opening-bracket ?\<
4934                       gnus-tmp-closing-bracket ?\>)
4935               (setq gnus-tmp-opening-bracket ?\[
4936                     gnus-tmp-closing-bracket ?\]))
4937             (setq
4938              gnus-tmp-indentation
4939              (aref gnus-thread-indent-array gnus-tmp-level)
4940              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4941              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4942                                 gnus-summary-default-score 0)
4943              gnus-tmp-score-char
4944              (if (or (null gnus-summary-default-score)
4945                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4946                          gnus-summary-zcore-fuzz))
4947                  ?                      ;Whitespace
4948                (if (< gnus-tmp-score gnus-summary-default-score)
4949                    gnus-score-below-mark gnus-score-over-mark))
4950              gnus-tmp-replied
4951              (cond ((memq number gnus-newsgroup-processable)
4952                     gnus-process-mark)
4953                    ((memq number gnus-newsgroup-cached)
4954                     gnus-cached-mark)
4955                    ((memq number gnus-newsgroup-replied)
4956                     gnus-replied-mark)
4957                    ((memq number gnus-newsgroup-forwarded)
4958                     gnus-forwarded-mark)
4959                    ((memq number gnus-newsgroup-saved)
4960                     gnus-saved-mark)
4961                    ((memq number gnus-newsgroup-recent)
4962                     gnus-recent-mark)
4963                    ((memq number gnus-newsgroup-unseen)
4964                     gnus-unseen-mark)
4965                    (t gnus-no-mark))
4966              gnus-tmp-downloaded
4967              (cond ((memq number gnus-newsgroup-undownloaded)
4968                     gnus-undownloaded-mark)
4969                    (gnus-newsgroup-agentized
4970                     gnus-downloaded-mark)
4971                    (t
4972                     gnus-no-mark))
4973              gnus-tmp-from (mail-header-from gnus-tmp-header)
4974              gnus-tmp-name
4975              (cond
4976               ((string-match "<[^>]+> *$" gnus-tmp-from)
4977                (setq beg-match (match-beginning 0))
4978                (or (and (string-match "^\".+\"" gnus-tmp-from)
4979                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4980                    (substring gnus-tmp-from 0 beg-match)))
4981               ((string-match "(.+)" gnus-tmp-from)
4982                (substring gnus-tmp-from
4983                           (1+ (match-beginning 0)) (1- (match-end 0))))
4984               (t gnus-tmp-from))
4985
4986              ;; Do the %B string
4987              gnus-tmp-thread-tree-header-string
4988              (cond
4989               ((not gnus-show-threads) "")
4990               ((zerop gnus-tmp-level)
4991                (cond ((cdar thread)
4992                       (or gnus-sum-thread-tree-root subject))
4993                      (gnus-tmp-new-adopts
4994                       (or gnus-sum-thread-tree-false-root subject))
4995                      (t
4996                       (or gnus-sum-thread-tree-single-indent subject))))
4997               (t
4998                (concat (apply 'concat
4999                               (mapcar (lambda (item)
5000                                         (if (= item 1)
5001                                             gnus-sum-thread-tree-vertical
5002                                           gnus-sum-thread-tree-indent))
5003                                       (cdr (reverse tree-stack))))
5004                        (if (nth 1 thread)
5005                            gnus-sum-thread-tree-leaf-with-other
5006                          gnus-sum-thread-tree-single-leaf)))))
5007             (when (string= gnus-tmp-name "")
5008               (setq gnus-tmp-name gnus-tmp-from))
5009             (unless (numberp gnus-tmp-lines)
5010               (setq gnus-tmp-lines -1))
5011             (if (= gnus-tmp-lines -1)
5012                 (setq gnus-tmp-lines "?")
5013               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5014               (gnus-put-text-property
5015              (point)
5016              (progn (eval gnus-summary-line-format-spec) (point))
5017                'gnus-number number)
5018             (when gnus-visual-p
5019               (forward-line -1)
5020               (gnus-run-hooks 'gnus-summary-update-hook)
5021               (forward-line 1))
5022
5023             (setq gnus-tmp-prev-subject simp-subject)))
5024
5025         (when (nth 1 thread)
5026           (push (list (max 0 gnus-tmp-level)
5027                       (copy-sequence tree-stack)
5028                       (nthcdr 1 thread))
5029                 stack))
5030         (push (if (nth 1 thread) 1 0) tree-stack)
5031         (incf gnus-tmp-level)
5032         (setq threads (if thread-end nil (cdar thread)))
5033         (if gnus-summary-display-while-building
5034             (if building-count
5035                 (progn
5036                   ;; use a set frequency
5037                   (setq building-line-count (1- building-line-count))
5038                   (when (= building-line-count 0)
5039                     (sit-for 0)
5040                     (setq building-line-count
5041                           gnus-summary-display-while-building)))
5042               ;; always
5043               (sit-for 0)))
5044         (unless threads
5045           (setq gnus-tmp-level 0)))))
5046   (gnus-message 7 "Generating summary...done"))
5047
5048 (defun gnus-summary-prepare-unthreaded (headers)
5049   "Generate an unthreaded summary buffer based on HEADERS."
5050   (let (header number mark)
5051
5052     (beginning-of-line)
5053
5054     (while headers
5055       ;; We may have to root out some bad articles...
5056       (when (memq (setq number (mail-header-number
5057                                 (setq header (pop headers))))
5058                   gnus-newsgroup-limit)
5059         ;; Mark article as read when it has a low score.
5060         (when (and gnus-summary-mark-below
5061                    (< (or (cdr (assq number gnus-newsgroup-scored))
5062                           gnus-summary-default-score 0)
5063                       gnus-summary-mark-below)
5064                    (not (gnus-summary-article-ancient-p number)))
5065           (setq gnus-newsgroup-unreads
5066                 (delq number gnus-newsgroup-unreads))
5067           (if gnus-newsgroup-auto-expire
5068               (push number gnus-newsgroup-expirable)
5069             (push (cons number gnus-low-score-mark)
5070                   gnus-newsgroup-reads)))
5071
5072         (setq mark (gnus-article-mark number))
5073         (push (gnus-data-make number mark (1+ (point)) header 0)
5074               gnus-newsgroup-data)
5075         (gnus-summary-insert-line
5076          header 0 number
5077          (memq number gnus-newsgroup-undownloaded)
5078          mark (memq number gnus-newsgroup-replied)
5079          (memq number gnus-newsgroup-expirable)
5080          (mail-header-subject header) nil
5081          (cdr (assq number gnus-newsgroup-scored))
5082          (memq number gnus-newsgroup-processable))))))
5083
5084 (defun gnus-summary-remove-list-identifiers ()
5085   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5086   (let ((regexp (if (consp gnus-list-identifiers)
5087                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5088                   gnus-list-identifiers))
5089         changed subject)
5090     (when regexp
5091       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5092       (dolist (header gnus-newsgroup-headers)
5093         (setq subject (mail-header-subject header)
5094               changed nil)
5095         (while (string-match regexp subject)
5096           (setq subject
5097                 (concat (substring subject 0 (match-beginning 1))
5098                         (substring subject (match-end 0)))
5099                 changed t))
5100         (when changed
5101           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5102             (setq subject
5103                   (concat (substring subject 0 (match-beginning 1))
5104                           (substring subject (match-end 1)))))
5105           (mail-header-set-subject header subject))))))
5106
5107 (defun gnus-fetch-headers (articles)
5108   "Fetch headers of ARTICLES."
5109   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5110     (gnus-message 5 "Fetching headers for %s..." name)
5111     (prog1
5112         (if (eq 'nov
5113                 (setq gnus-headers-retrieved-by
5114                       (gnus-retrieve-headers
5115                        articles gnus-newsgroup-name
5116                        ;; We might want to fetch old headers, but
5117                        ;; not if there is only 1 article.
5118                        (and (or (and
5119                                  (not (eq gnus-fetch-old-headers 'some))
5120                                  (not (numberp gnus-fetch-old-headers)))
5121                                 (> (length articles) 1))
5122                             gnus-fetch-old-headers))))
5123             (gnus-get-newsgroup-headers-xover
5124              articles nil nil gnus-newsgroup-name t)
5125           (gnus-get-newsgroup-headers))
5126       (gnus-message 5 "Fetching headers for %s...done" name))))
5127
5128 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5129   "Select newsgroup GROUP.
5130 If READ-ALL is non-nil, all articles in the group are selected.
5131 If SELECT-ARTICLES, only select those articles from GROUP."
5132   (let* ((entry (gnus-group-entry group))
5133          ;;!!! Dirty hack; should be removed.
5134          (gnus-summary-ignore-duplicates
5135           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5136               t
5137             gnus-summary-ignore-duplicates))
5138          (info (nth 2 entry))
5139          articles fetched-articles cached)
5140
5141     (unless (gnus-check-server
5142              (set (make-local-variable 'gnus-current-select-method)
5143                   (gnus-find-method-for-group group)))
5144       (error "Couldn't open server"))
5145
5146     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5147         (gnus-activate-group group)     ; Or we can activate it...
5148         (progn                          ; Or we bug out.
5149           (when (equal major-mode 'gnus-summary-mode)
5150             (gnus-kill-buffer (current-buffer)))
5151           (error "Couldn't activate group %s: %s"
5152                  group (gnus-status-message group))))
5153
5154     (unless (gnus-request-group group t)
5155       (when (equal major-mode 'gnus-summary-mode)
5156         (gnus-kill-buffer (current-buffer)))
5157       (error "Couldn't request group %s: %s"
5158              group (gnus-status-message group)))
5159
5160     (when gnus-agent
5161       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5162
5163       (setq gnus-summary-use-undownloaded-faces
5164             (gnus-agent-find-parameter
5165              group
5166              'agent-enable-undownloaded-faces)))
5167
5168     (setq gnus-newsgroup-name group
5169           gnus-newsgroup-unselected nil
5170           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5171
5172     (let ((display (gnus-group-find-parameter group 'display)))
5173       (setq gnus-newsgroup-display
5174             (cond
5175              ((not (zerop (or (car-safe read-all) 0)))
5176               ;; The user entered the group with C-u SPC/RET, let's show
5177               ;; all articles.
5178               'gnus-not-ignore)
5179              ((eq display 'all)
5180               'gnus-not-ignore)
5181              ((arrayp display)
5182               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5183              ((numberp display)
5184               ;; The following is probably the "correct" solution, but
5185               ;; it makes Gnus fetch all headers and then limit the
5186               ;; articles (which is slow), so instead we hack the
5187               ;; select-articles parameter instead. -- Simon Josefsson
5188               ;; <jas@kth.se>
5189               ;;
5190               ;; (gnus-byte-compile
5191               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5192               ;;                         display)))))
5193               (setq select-articles
5194                     (gnus-uncompress-range
5195                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5196                              (if (> tmp 0)
5197                                  tmp
5198                                1))
5199                            (cdr (gnus-active group)))))
5200               nil)
5201              (t
5202               nil))))
5203
5204     (gnus-summary-setup-default-charset)
5205
5206     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5207     (when (gnus-virtual-group-p group)
5208       (setq cached gnus-newsgroup-cached))
5209
5210     (setq gnus-newsgroup-unreads
5211           (gnus-sorted-ndifference
5212            (gnus-sorted-ndifference gnus-newsgroup-unreads
5213                                     gnus-newsgroup-marked)
5214            gnus-newsgroup-dormant))
5215
5216     (setq gnus-newsgroup-processable nil)
5217
5218     (gnus-update-read-articles group gnus-newsgroup-unreads)
5219
5220     ;; Adjust and set lists of article marks.
5221     (when info
5222       (gnus-adjust-marked-articles info))
5223     (if (setq articles select-articles)
5224         (setq gnus-newsgroup-unselected
5225               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5226       (setq articles (gnus-articles-to-read group read-all)))
5227
5228     (cond
5229      ((null articles)
5230       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5231       'quit)
5232      ((eq articles 0) nil)
5233      (t
5234       ;; Init the dependencies hash table.
5235       (setq gnus-newsgroup-dependencies
5236             (gnus-make-hashtable (length articles)))
5237       (gnus-set-global-variables)
5238       ;; Retrieve the headers and read them in.
5239
5240       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5241
5242       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5243       (when cached
5244         (setq gnus-newsgroup-cached cached))
5245
5246       ;; Suppress duplicates?
5247       (when gnus-suppress-duplicates
5248         (gnus-dup-suppress-articles))
5249
5250       ;; Set the initial limit.
5251       (setq gnus-newsgroup-limit (copy-sequence articles))
5252       ;; Remove canceled articles from the list of unread articles.
5253       (setq fetched-articles
5254             (mapcar (lambda (headers) (mail-header-number headers))
5255                     gnus-newsgroup-headers))
5256       (setq gnus-newsgroup-articles fetched-articles)
5257       (setq gnus-newsgroup-unreads
5258             (gnus-sorted-nintersection
5259              gnus-newsgroup-unreads fetched-articles))
5260       (gnus-compute-unseen-list)
5261
5262       ;; Removed marked articles that do not exist.
5263       (gnus-update-missing-marks
5264        (gnus-sorted-difference articles fetched-articles))
5265       ;; We might want to build some more threads first.
5266       (when (and gnus-fetch-old-headers
5267                  (eq gnus-headers-retrieved-by 'nov))
5268         (if (eq gnus-fetch-old-headers 'invisible)
5269             (gnus-build-all-threads)
5270           (gnus-build-old-threads)))
5271       ;; Let the Gnus agent mark articles as read.
5272       (when gnus-agent
5273         (gnus-agent-get-undownloaded-list))
5274       ;; Remove list identifiers from subject
5275       (when gnus-list-identifiers
5276         (gnus-summary-remove-list-identifiers))
5277       ;; Check whether auto-expire is to be done in this group.
5278       (setq gnus-newsgroup-auto-expire
5279             (gnus-group-auto-expirable-p group))
5280       ;; Set up the article buffer now, if necessary.
5281       (unless gnus-single-article-buffer
5282         (gnus-article-setup-buffer))
5283       ;; First and last article in this newsgroup.
5284       (when gnus-newsgroup-headers
5285         (setq gnus-newsgroup-begin
5286               (mail-header-number (car gnus-newsgroup-headers))
5287               gnus-newsgroup-end
5288               (mail-header-number
5289                (gnus-last-element gnus-newsgroup-headers))))
5290       ;; GROUP is successfully selected.
5291       (or gnus-newsgroup-headers t)))))
5292
5293 (defun gnus-compute-unseen-list ()
5294   ;; The `seen' marks are treated specially.
5295   (if (not gnus-newsgroup-seen)
5296       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5297     (setq gnus-newsgroup-unseen
5298           (gnus-inverse-list-range-intersection
5299            gnus-newsgroup-articles gnus-newsgroup-seen))))
5300
5301 (defun gnus-summary-display-make-predicate (display)
5302   (require 'gnus-agent)
5303   (when (= (length display) 1)
5304     (setq display (car display)))
5305   (unless gnus-summary-display-cache
5306     (dolist (elem (append '((unread . unread)
5307                             (read . read)
5308                             (unseen . unseen))
5309                           gnus-article-mark-lists))
5310       (push (cons (cdr elem)
5311                   (gnus-byte-compile
5312                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5313             gnus-summary-display-cache)))
5314   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5315         (gnus-category-predicate-cache gnus-summary-display-cache))
5316     (gnus-get-predicate display)))
5317
5318 ;; Uses the dynamically bound `number' variable.
5319 (eval-when-compile
5320   (defvar number))
5321 (defun gnus-article-marked-p (type &optional article)
5322   (let ((article (or article number)))
5323     (cond
5324      ((eq type 'tick)
5325       (memq article gnus-newsgroup-marked))
5326      ((eq type 'spam)
5327       (memq article gnus-newsgroup-spam-marked))
5328      ((eq type 'unsend)
5329       (memq article gnus-newsgroup-unsendable))
5330      ((eq type 'undownload)
5331       (memq article gnus-newsgroup-undownloaded))
5332      ((eq type 'download)
5333       (memq article gnus-newsgroup-downloadable))
5334      ((eq type 'unread)
5335       (memq article gnus-newsgroup-unreads))
5336      ((eq type 'read)
5337       (memq article gnus-newsgroup-reads))
5338      ((eq type 'dormant)
5339       (memq article gnus-newsgroup-dormant) )
5340      ((eq type 'expire)
5341       (memq article gnus-newsgroup-expirable))
5342      ((eq type 'reply)
5343       (memq article gnus-newsgroup-replied))
5344      ((eq type 'killed)
5345       (memq article gnus-newsgroup-killed))
5346      ((eq type 'bookmark)
5347       (assq article gnus-newsgroup-bookmarks))
5348      ((eq type 'score)
5349       (assq article gnus-newsgroup-scored))
5350      ((eq type 'save)
5351       (memq article gnus-newsgroup-saved))
5352      ((eq type 'cache)
5353       (memq article gnus-newsgroup-cached))
5354      ((eq type 'forward)
5355       (memq article gnus-newsgroup-forwarded))
5356      ((eq type 'seen)
5357       (not (memq article gnus-newsgroup-unseen)))
5358      ((eq type 'recent)
5359       (memq article gnus-newsgroup-recent))
5360      (t t))))
5361
5362 (defun gnus-articles-to-read (group &optional read-all)
5363   "Find out what articles the user wants to read."
5364   (let* ((articles
5365           ;; Select all articles if `read-all' is non-nil, or if there
5366           ;; are no unread articles.
5367           (if (or read-all
5368                   (and (zerop (length gnus-newsgroup-marked))
5369                        (zerop (length gnus-newsgroup-unreads)))
5370                   ;; Fetch all if the predicate is non-nil.
5371                   gnus-newsgroup-display)
5372               ;; We want to select the headers for all the articles in
5373               ;; the group, so we select either all the active
5374               ;; articles in the group, or (if that's nil), the
5375               ;; articles in the cache.
5376               (or
5377                (gnus-uncompress-range (gnus-active group))
5378                (gnus-cache-articles-in-group group))
5379             ;; Select only the "normal" subset of articles.
5380             (gnus-sorted-nunion
5381              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5382              gnus-newsgroup-unreads)))
5383          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5384          (scored (length scored-list))
5385          (number (length articles))
5386          (marked (+ (length gnus-newsgroup-marked)
5387                     (length gnus-newsgroup-dormant)))
5388          (select
5389           (cond
5390            ((numberp read-all)
5391             read-all)
5392            ((numberp gnus-newsgroup-display)
5393             gnus-newsgroup-display)
5394            (t
5395             (condition-case ()
5396                 (cond
5397                  ((and (or (<= scored marked) (= scored number))
5398                        (numberp gnus-large-newsgroup)
5399                        (> number gnus-large-newsgroup))
5400                   (let* ((cursor-in-echo-area nil)
5401                          (initial (gnus-parameter-large-newsgroup-initial
5402                                    gnus-newsgroup-name))
5403                          (input
5404                           (read-string
5405                            (format
5406                             "How many articles from %s (%s %d): "
5407                             (gnus-limit-string
5408                              (gnus-group-decoded-name gnus-newsgroup-name)
5409                              35)
5410                             (if initial "max" "default")
5411                             number)
5412                            (if initial
5413                                (cons (number-to-string initial)
5414                                      0)))))
5415                     (if (string-match "^[ \t]*$" input) number input)))
5416                  ((and (> scored marked) (< scored number)
5417                        (> (- scored number) 20))
5418                   (let ((input
5419                          (read-string
5420                           (format "%s %s (%d scored, %d total): "
5421                                   "How many articles from"
5422                                   (gnus-group-decoded-name group)
5423                                   scored number))))
5424                     (if (string-match "^[ \t]*$" input)
5425                         number input)))
5426                  (t number))
5427               (quit
5428                (message "Quit getting the articles to read")
5429                nil))))))
5430     (setq select (if (stringp select) (string-to-number select) select))
5431     (if (or (null select) (zerop select))
5432         select
5433       (if (and (not (zerop scored)) (<= (abs select) scored))
5434           (progn
5435             (setq articles (sort scored-list '<))
5436             (setq number (length articles)))
5437         (setq articles (copy-sequence articles)))
5438
5439       (when (< (abs select) number)
5440         (if (< select 0)
5441             ;; Select the N oldest articles.
5442             (setcdr (nthcdr (1- (abs select)) articles) nil)
5443           ;; Select the N most recent articles.
5444           (setq articles (nthcdr (- number select) articles))))
5445       (setq gnus-newsgroup-unselected
5446             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5447       (when gnus-alter-articles-to-read-function
5448         (setq articles
5449               (sort
5450                (funcall gnus-alter-articles-to-read-function
5451                         gnus-newsgroup-name articles)
5452                '<)))
5453       articles)))
5454
5455 (defun gnus-killed-articles (killed articles)
5456   (let (out)
5457     (while articles
5458       (when (inline (gnus-member-of-range (car articles) killed))
5459         (push (car articles) out))
5460       (setq articles (cdr articles)))
5461     out))
5462
5463 (defun gnus-uncompress-marks (marks)
5464   "Uncompress the mark ranges in MARKS."
5465   (let ((uncompressed '(score bookmark))
5466         out)
5467     (while marks
5468       (if (memq (caar marks) uncompressed)
5469           (push (car marks) out)
5470         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5471       (setq marks (cdr marks)))
5472     out))
5473
5474 (defun gnus-article-mark-to-type (mark)
5475   "Return the type of MARK."
5476   (or (cadr (assq mark gnus-article-special-mark-lists))
5477       'list))
5478
5479 (defun gnus-article-unpropagatable-p (mark)
5480   "Return whether MARK should be propagated to back end."
5481   (memq mark gnus-article-unpropagated-mark-lists))
5482
5483 (defun gnus-adjust-marked-articles (info)
5484   "Set all article lists and remove all marks that are no longer valid."
5485   (let* ((marked-lists (gnus-info-marks info))
5486          (active (gnus-active (gnus-info-group info)))
5487          (min (car active))
5488          (max (cdr active))
5489          (types gnus-article-mark-lists)
5490          marks var articles article mark mark-type
5491          bgn end)
5492
5493     (dolist (marks marked-lists)
5494       (setq mark (car marks)
5495             mark-type (gnus-article-mark-to-type mark)
5496             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5497
5498       ;; We set the variable according to the type of the marks list,
5499       ;; and then adjust the marks to a subset of the active articles.
5500       (cond
5501        ;; Adjust "simple" lists - compressed yet unsorted
5502        ((eq mark-type 'list)
5503         ;; Simultaneously uncompress and clip to active range
5504         ;; See gnus-uncompress-range for a description of possible marks
5505         (let (l lh)
5506           (if (not (cadr marks))
5507               (set var nil)
5508             (setq articles (if (numberp (cddr marks))
5509                                (list (cdr marks))
5510                              (cdr marks))
5511                   lh (cons nil nil)
5512                   l lh)
5513
5514             (while (setq article (pop articles))
5515               (cond ((consp article)
5516                      (setq bgn (max (car article) min)
5517                            end (min (cdr article) max))
5518                      (while (<= bgn end)
5519                        (setq l (setcdr l (cons bgn nil))
5520                              bgn (1+ bgn))))
5521                     ((and (<= min article)
5522                           (>= max article))
5523                      (setq l (setcdr l (cons article nil))))))
5524             (set var (cdr lh)))))
5525        ;; Adjust assocs.
5526        ((eq mark-type 'tuple)
5527         (set var (setq articles (cdr marks)))
5528         (when (not (listp (cdr (symbol-value var))))
5529           (set var (list (symbol-value var))))
5530         (when (not (listp (cdr articles)))
5531           (setq articles (list articles)))
5532         (while articles
5533           (when (or (not (consp (setq article (pop articles))))
5534                     (< (car article) min)
5535                     (> (car article) max))
5536             (set var (delq article (symbol-value var))))))
5537        ;; Adjust ranges (sloppily).
5538        ((eq mark-type 'range)
5539         (cond
5540          ((eq mark 'seen)
5541           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5542           ;; It should be (seen (NUM1 . NUM2)).
5543           (when (numberp (cddr marks))
5544             (setcdr marks (list (cdr marks))))
5545           (setq articles (cdr marks))
5546           (while (and articles
5547                       (or (and (consp (car articles))
5548                                (> min (cdar articles)))
5549                           (and (numberp (car articles))
5550                                (> min (car articles)))))
5551             (pop articles))
5552           (set var articles))))))))
5553
5554 (defun gnus-update-missing-marks (missing)
5555   "Go through the list of MISSING articles and remove them from the mark lists."
5556   (when missing
5557     (let (var m)
5558       ;; Go through all types.
5559       (dolist (elem gnus-article-mark-lists)
5560         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5561           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5562           (when (symbol-value var)
5563             ;; This list has articles.  So we delete all missing
5564             ;; articles from it.
5565             (setq m missing)
5566             (while m
5567               (set var (delq (pop m) (symbol-value var))))))))))
5568
5569 (defun gnus-update-marks ()
5570   "Enter the various lists of marked articles into the newsgroup info list."
5571   (let ((types gnus-article-mark-lists)
5572         (info (gnus-get-info gnus-newsgroup-name))
5573         type list newmarked symbol delta-marks)
5574     (when info
5575       ;; Add all marks lists to the list of marks lists.
5576       (while (setq type (pop types))
5577         (setq list (symbol-value
5578                     (setq symbol
5579                           (intern (format "gnus-newsgroup-%s" (car type))))))
5580
5581         (when list
5582           ;; Get rid of the entries of the articles that have the
5583           ;; default score.
5584           (when (and (eq (cdr type) 'score)
5585                      gnus-save-score
5586                      list)
5587             (let* ((arts list)
5588                    (prev (cons nil list))
5589                    (all prev))
5590               (while arts
5591                 (if (or (not (consp (car arts)))
5592                         (= (cdar arts) gnus-summary-default-score))
5593                     (setcdr prev (cdr arts))
5594                   (setq prev arts))
5595                 (setq arts (cdr arts)))
5596               (setq list (cdr all)))))
5597
5598         (when (eq (cdr type) 'seen)
5599           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5600
5601         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5602           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5603
5604         (when (and (gnus-check-backend-function
5605                     'request-set-mark gnus-newsgroup-name)
5606                    (not (gnus-article-unpropagatable-p (cdr type))))
5607           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5608                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5609                  (add (gnus-remove-from-range
5610                        (gnus-copy-sequence list) old)))
5611             (when add
5612               (push (list add 'add (list (cdr type))) delta-marks))
5613             (when del
5614               (push (list del 'del (list (cdr type))) delta-marks))))
5615
5616         (when list
5617           (push (cons (cdr type) list) newmarked)))
5618
5619       (when delta-marks
5620         (unless (gnus-check-group gnus-newsgroup-name)
5621           (error "Can't open server for %s" gnus-newsgroup-name))
5622         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5623
5624       ;; Enter these new marks into the info of the group.
5625       (if (nthcdr 3 info)
5626           (setcar (nthcdr 3 info) newmarked)
5627         ;; Add the marks lists to the end of the info.
5628         (when newmarked
5629           (setcdr (nthcdr 2 info) (list newmarked))))
5630
5631       ;; Cut off the end of the info if there's nothing else there.
5632       (let ((i 5))
5633         (while (and (> i 2)
5634                     (not (nth i info)))
5635           (when (nthcdr (decf i) info)
5636             (setcdr (nthcdr i info) nil)))))))
5637
5638 (defun gnus-set-mode-line (where)
5639   "Set the mode line of the article or summary buffers.
5640 If WHERE is `summary', the summary mode line format will be used."
5641   ;; Is this mode line one we keep updated?
5642   (when (and (memq where gnus-updated-mode-lines)
5643              (symbol-value
5644               (intern (format "gnus-%s-mode-line-format-spec" where))))
5645     (let (mode-string)
5646       (save-excursion
5647         ;; We evaluate this in the summary buffer since these
5648         ;; variables are buffer-local to that buffer.
5649         (set-buffer gnus-summary-buffer)
5650        ;; We bind all these variables that are used in the `eval' form
5651         ;; below.
5652         (let* ((mformat (symbol-value
5653                          (intern
5654                           (format "gnus-%s-mode-line-format-spec" where))))
5655                (gnus-tmp-group-name (gnus-group-decoded-name
5656                                      gnus-newsgroup-name))
5657                (gnus-tmp-article-number (or gnus-current-article 0))
5658                (gnus-tmp-unread gnus-newsgroup-unreads)
5659                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5660                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5661                (gnus-tmp-unread-and-unselected
5662                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5663                             (zerop gnus-tmp-unselected))
5664                        "")
5665                       ((zerop gnus-tmp-unselected)
5666                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5667                       (t (format "{%d(+%d) more}"
5668                                  gnus-tmp-unread-and-unticked
5669                                  gnus-tmp-unselected))))
5670                (gnus-tmp-subject
5671                 (if (and gnus-current-headers
5672                          (vectorp gnus-current-headers))
5673                     (gnus-mode-string-quote
5674                      (mail-header-subject gnus-current-headers))
5675                   ""))
5676                bufname-length max-len
5677                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5678           (setq mode-string (eval mformat))
5679           (setq bufname-length (if (string-match "%b" mode-string)
5680                                    (- (length
5681                                        (buffer-name
5682                                         (if (eq where 'summary)
5683                                             nil
5684                                           (get-buffer gnus-article-buffer))))
5685                                       2)
5686                                  0))
5687           (setq max-len (max 4 (if gnus-mode-non-string-length
5688                                    (- (window-width)
5689                                       gnus-mode-non-string-length
5690                                       bufname-length)
5691                                  (length mode-string))))
5692           ;; We might have to chop a bit of the string off...
5693           (when (> (length mode-string) max-len)
5694             (setq mode-string
5695                   (concat (truncate-string-to-width mode-string (- max-len 3))
5696                           "...")))
5697           ;; Pad the mode string a bit.
5698           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5699       ;; Update the mode line.
5700       (setq mode-line-buffer-identification
5701             (gnus-mode-line-buffer-identification (list mode-string)))
5702       (set-buffer-modified-p t))))
5703
5704 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5705   "Go through the HEADERS list and add all Xrefs to a hash table.
5706 The resulting hash table is returned, or nil if no Xrefs were found."
5707   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5708          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5709          (xref-hashtb (gnus-make-hashtable))
5710          start group entry number xrefs header)
5711     (while headers
5712       (setq header (pop headers))
5713       (when (and (setq xrefs (mail-header-xref header))
5714                  (not (memq (setq number (mail-header-number header))
5715                             unreads)))
5716         (setq start 0)
5717         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5718           (setq start (match-end 0))
5719           (setq group (if prefix
5720                           (concat prefix (substring xrefs (match-beginning 1)
5721                                                     (match-end 1)))
5722                         (substring xrefs (match-beginning 1) (match-end 1))))
5723           (setq number
5724                 (string-to-int (substring xrefs (match-beginning 2)
5725                                           (match-end 2))))
5726           (if (setq entry (gnus-gethash group xref-hashtb))
5727               (setcdr entry (cons number (cdr entry)))
5728             (gnus-sethash group (cons number nil) xref-hashtb)))))
5729     (and start xref-hashtb)))
5730
5731 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5732   "Look through all the headers and mark the Xrefs as read."
5733   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5734         name info xref-hashtb idlist method nth4)
5735     (save-excursion
5736       (set-buffer gnus-group-buffer)
5737       (when (setq xref-hashtb
5738                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5739         (mapatoms
5740          (lambda (group)
5741            (unless (string= from-newsgroup (setq name (symbol-name group)))
5742              (setq idlist (symbol-value group))
5743              ;; Dead groups are not updated.
5744              (and (prog1
5745                       (setq info (gnus-get-info name))
5746                     (when (stringp (setq nth4 (gnus-info-method info)))
5747                       (setq nth4 (gnus-server-to-method nth4))))
5748                   ;; Only do the xrefs if the group has the same
5749                   ;; select method as the group we have just read.
5750                   (or (gnus-methods-equal-p
5751                        nth4 (gnus-find-method-for-group from-newsgroup))
5752                       virtual
5753                       (equal nth4 (setq method (gnus-find-method-for-group
5754                                                 from-newsgroup)))
5755                       (and (equal (car nth4) (car method))
5756                            (equal (nth 1 nth4) (nth 1 method))))
5757                   gnus-use-cross-reference
5758                   (or (not (eq gnus-use-cross-reference t))
5759                       virtual
5760                       ;; Only do cross-references on subscribed
5761                       ;; groups, if that is what is wanted.
5762                       (<= (gnus-info-level info) gnus-level-subscribed))
5763                   (gnus-group-make-articles-read name idlist))))
5764          xref-hashtb)))))
5765
5766 (defun gnus-compute-read-articles (group articles)
5767   (let* ((entry (gnus-group-entry group))
5768          (info (nth 2 entry))
5769          (active (gnus-active group))
5770          ninfo)
5771     (when entry
5772       ;; First peel off all invalid article numbers.
5773       (when active
5774         (let ((ids articles)
5775               id first)
5776           (while (setq id (pop ids))
5777             (when (and first (> id (cdr active)))
5778               ;; We'll end up in this situation in one particular
5779               ;; obscure situation.  If you re-scan a group and get
5780               ;; a new article that is cross-posted to a different
5781               ;; group that has not been re-scanned, you might get
5782               ;; crossposted article that has a higher number than
5783               ;; Gnus believes possible.  So we re-activate this
5784               ;; group as well.  This might mean doing the
5785               ;; crossposting thingy will *increase* the number
5786               ;; of articles in some groups.  Tsk, tsk.
5787               (setq active (or (gnus-activate-group group) active)))
5788             (when (or (> id (cdr active))
5789                       (< id (car active)))
5790               (setq articles (delq id articles))))))
5791       ;; If the read list is nil, we init it.
5792       (if (and active
5793                (null (gnus-info-read info))
5794                (> (car active) 1))
5795           (setq ninfo (cons 1 (1- (car active))))
5796         (setq ninfo (gnus-info-read info)))
5797       ;; Then we add the read articles to the range.
5798       (gnus-add-to-range
5799        ninfo (setq articles (sort articles '<))))))
5800
5801 (defun gnus-group-make-articles-read (group articles)
5802   "Update the info of GROUP to say that ARTICLES are read."
5803   (let* ((num 0)
5804          (entry (gnus-group-entry group))
5805          (info (nth 2 entry))
5806          (active (gnus-active group))
5807          range)
5808     (when entry
5809       (setq range (gnus-compute-read-articles group articles))
5810       (with-current-buffer gnus-group-buffer
5811         (gnus-undo-register
5812           `(progn
5813              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5814              (gnus-info-set-read ',info ',(gnus-info-read info))
5815              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5816              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5817              (gnus-group-update-group ,group t))))
5818       ;; Add the read articles to the range.
5819       (gnus-info-set-read info range)
5820       (gnus-request-set-mark group (list (list range 'add '(read))))
5821       ;; Then we have to re-compute how many unread
5822       ;; articles there are in this group.
5823       (when active
5824         (cond
5825          ((not range)
5826           (setq num (- (1+ (cdr active)) (car active))))
5827          ((not (listp (cdr range)))
5828           (setq num (- (cdr active) (- (1+ (cdr range))
5829                                        (car range)))))
5830          (t
5831           (while range
5832             (if (numberp (car range))
5833                 (setq num (1+ num))
5834               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5835             (setq range (cdr range)))
5836           (setq num (- (cdr active) num))))
5837         ;; Update the number of unread articles.
5838         (setcar entry num)
5839         ;; Update the group buffer.
5840         (unless (gnus-ephemeral-group-p group)
5841           (gnus-group-update-group group t))))))
5842
5843 (defvar gnus-newsgroup-none-id 0)
5844
5845 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5846   (let ((cur nntp-server-buffer)
5847         (dependencies
5848          (or dependencies
5849              (with-current-buffer gnus-summary-buffer
5850                gnus-newsgroup-dependencies)))
5851         headers id end ref number
5852         (mail-parse-charset gnus-newsgroup-charset)
5853         (mail-parse-ignored-charsets
5854          (save-excursion (condition-case nil
5855                              (set-buffer gnus-summary-buffer)
5856                            (error))
5857                          gnus-newsgroup-ignored-charsets)))
5858     (save-excursion
5859       (set-buffer nntp-server-buffer)
5860       ;; Translate all TAB characters into SPACE characters.
5861       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5862       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5863       (ietf-drums-unfold-fws)
5864       (gnus-run-hooks 'gnus-parse-headers-hook)
5865       (let ((case-fold-search t)
5866             in-reply-to header p lines chars)
5867         (goto-char (point-min))
5868         ;; Search to the beginning of the next header.  Error messages
5869         ;; do not begin with 2 or 3.
5870         (while (re-search-forward "^[23][0-9]+ " nil t)
5871           (setq id nil
5872                 ref nil)
5873           ;; This implementation of this function, with nine
5874           ;; search-forwards instead of the one re-search-forward and
5875           ;; a case (which basically was the old function) is actually
5876           ;; about twice as fast, even though it looks messier.  You
5877           ;; can't have everything, I guess.  Speed and elegance
5878           ;; doesn't always go hand in hand.
5879           (setq
5880            header
5881            (vector
5882             ;; Number.
5883             (prog1
5884                 (setq number (read cur))
5885               (end-of-line)
5886               (setq p (point))
5887               (narrow-to-region (point)
5888                                 (or (and (search-forward "\n.\n" nil t)
5889                                          (- (point) 2))
5890                                     (point))))
5891             ;; Subject.
5892             (progn
5893               (goto-char p)
5894               (if (search-forward "\nsubject:" nil t)
5895                   (funcall gnus-decode-encoded-word-function
5896                            (nnheader-header-value))
5897                 "(none)"))
5898             ;; From.
5899             (progn
5900               (goto-char p)
5901               (if (search-forward "\nfrom:" nil t)
5902                   (funcall gnus-decode-encoded-word-function
5903                            (nnheader-header-value))
5904                 "(nobody)"))
5905             ;; Date.
5906             (progn
5907               (goto-char p)
5908               (if (search-forward "\ndate:" nil t)
5909                   (nnheader-header-value) ""))
5910             ;; Message-ID.
5911             (progn
5912               (goto-char p)
5913               (setq id (if (re-search-forward
5914                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5915                            ;; We do it this way to make sure the Message-ID
5916                            ;; is (somewhat) syntactically valid.
5917                            (buffer-substring (match-beginning 1)
5918                                              (match-end 1))
5919                          ;; If there was no message-id, we just fake one
5920                          ;; to make subsequent routines simpler.
5921                          (nnheader-generate-fake-message-id number))))
5922             ;; References.
5923             (progn
5924               (goto-char p)
5925               (if (search-forward "\nreferences:" nil t)
5926                   (progn
5927                     (setq end (point))
5928                     (prog1
5929                         (nnheader-header-value)
5930                       (setq ref
5931                             (buffer-substring
5932                              (progn
5933                                (end-of-line)
5934                                (search-backward ">" end t)
5935                                (1+ (point)))
5936                              (progn
5937                                (search-backward "<" end t)
5938                                (point))))))
5939                 ;; Get the references from the in-reply-to header if there
5940                 ;; were no references and the in-reply-to header looks
5941                 ;; promising.
5942                 (if (and (search-forward "\nin-reply-to:" nil t)
5943                          (setq in-reply-to (nnheader-header-value))
5944                          (string-match "<[^>]+>" in-reply-to))
5945                     (let (ref2)
5946                       (setq ref (substring in-reply-to (match-beginning 0)
5947                                            (match-end 0)))
5948                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5949                         (setq ref2 (substring in-reply-to (match-beginning 0)
5950                                               (match-end 0)))
5951                         (when (> (length ref2) (length ref))
5952                           (setq ref ref2)))
5953                       ref)
5954                   (setq ref nil))))
5955             ;; Chars.
5956             (progn
5957               (goto-char p)
5958               (if (search-forward "\nchars: " nil t)
5959                   (if (numberp (setq chars (ignore-errors (read cur))))
5960                       chars -1)
5961                 -1))
5962             ;; Lines.
5963             (progn
5964               (goto-char p)
5965               (if (search-forward "\nlines: " nil t)
5966                   (if (numberp (setq lines (ignore-errors (read cur))))
5967                       lines -1)
5968                 -1))
5969             ;; Xref.
5970             (progn
5971               (goto-char p)
5972               (and (search-forward "\nxref:" nil t)
5973                    (nnheader-header-value)))
5974             ;; Extra.
5975             (when gnus-extra-headers
5976               (let ((extra gnus-extra-headers)
5977                     out)
5978                 (while extra
5979                   (goto-char p)
5980                   (when (search-forward
5981                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5982                     (push (cons (car extra) (nnheader-header-value))
5983                           out))
5984                   (pop extra))
5985                 out))))
5986           (when (equal id ref)
5987             (setq ref nil))
5988
5989           (when gnus-alter-header-function
5990             (funcall gnus-alter-header-function header)
5991             (setq id (mail-header-id header)
5992                   ref (gnus-parent-id (mail-header-references header))))
5993
5994           (when (setq header
5995                       (gnus-dependencies-add-header
5996                        header dependencies force-new))
5997             (push header headers))
5998           (goto-char (point-max))
5999           (widen))
6000         (nreverse headers)))))
6001
6002 ;; Goes through the xover lines and returns a list of vectors
6003 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6004                                                   force-new dependencies
6005                                                   group also-fetch-heads)
6006   "Parse the news overview data in the server buffer.
6007 Return a list of headers that match SEQUENCE (see
6008 `nntp-retrieve-headers')."
6009   ;; Get the Xref when the users reads the articles since most/some
6010   ;; NNTP servers do not include Xrefs when using XOVER.
6011   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6012   (let ((mail-parse-charset gnus-newsgroup-charset)
6013         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6014         (cur nntp-server-buffer)
6015         (dependencies (or dependencies gnus-newsgroup-dependencies))
6016         (allp (cond
6017                ((eq gnus-read-all-available-headers t)
6018                 t)
6019                ((stringp gnus-read-all-available-headers)
6020                 (string-match gnus-read-all-available-headers group))
6021                (t
6022                 nil)))
6023         number headers header)
6024     (save-excursion
6025       (set-buffer nntp-server-buffer)
6026       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6027       ;; Allow the user to mangle the headers before parsing them.
6028       (gnus-run-hooks 'gnus-parse-headers-hook)
6029       (goto-char (point-min))
6030       (gnus-parse-without-error
6031         (while (and (or sequence allp)
6032                     (not (eobp)))
6033           (setq number (read cur))
6034           (when (not allp)
6035             (while (and sequence
6036                         (< (car sequence) number))
6037               (setq sequence (cdr sequence))))
6038           (when (and (or allp
6039                          (and sequence
6040                               (eq number (car sequence))))
6041                      (progn
6042                        (setq sequence (cdr sequence))
6043                        (setq header (inline
6044                                       (gnus-nov-parse-line
6045                                        number dependencies force-new)))))
6046             (push header headers))
6047           (forward-line 1)))
6048       ;; A common bug in inn is that if you have posted an article and
6049       ;; then retrieves the active file, it will answer correctly --
6050       ;; the new article is included.  However, a NOV entry for the
6051       ;; article may not have been generated yet, so this may fail.
6052       ;; We work around this problem by retrieving the last few
6053       ;; headers using HEAD.
6054       (if (or (not also-fetch-heads)
6055               (not sequence))
6056           ;; We (probably) got all the headers.
6057           (nreverse headers)
6058         (let ((gnus-nov-is-evil t))
6059           (nconc
6060            (nreverse headers)
6061            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6062              (gnus-get-newsgroup-headers))))))))
6063
6064 (defun gnus-article-get-xrefs ()
6065   "Fill in the Xref value in `gnus-current-headers', if necessary.
6066 This is meant to be called in `gnus-article-internal-prepare-hook'."
6067   (let ((headers (with-current-buffer gnus-summary-buffer
6068                    gnus-current-headers)))
6069     (or (not gnus-use-cross-reference)
6070         (not headers)
6071         (and (mail-header-xref headers)
6072              (not (string= (mail-header-xref headers) "")))
6073         (let ((case-fold-search t)
6074               xref)
6075           (save-restriction
6076             (nnheader-narrow-to-headers)
6077             (goto-char (point-min))
6078             (when (or (and (not (eobp))
6079                            (eq (downcase (char-after)) ?x)
6080                            (looking-at "Xref:"))
6081                       (search-forward "\nXref:" nil t))
6082               (goto-char (1+ (match-end 0)))
6083               (setq xref (buffer-substring (point) (point-at-eol)))
6084               (mail-header-set-xref headers xref)))))))
6085
6086 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6087   "Find article ID and insert the summary line for that article.
6088 OLD-HEADER can either be a header or a line number to insert
6089 the subject line on."
6090   (let* ((line (and (numberp old-header) old-header))
6091          (old-header (and (vectorp old-header) old-header))
6092          (header (cond ((and old-header use-old-header)
6093                         old-header)
6094                        ((and (numberp id)
6095                              (gnus-number-to-header id))
6096                         (gnus-number-to-header id))
6097                        (t
6098                         (gnus-read-header id))))
6099          (number (and (numberp id) id))
6100          d)
6101     (when header
6102       ;; Rebuild the thread that this article is part of and go to the
6103       ;; article we have fetched.
6104       (when (and (not gnus-show-threads)
6105                  old-header)
6106         (when (and number
6107                    (setq d (gnus-data-find (mail-header-number old-header))))
6108           (goto-char (gnus-data-pos d))
6109           (gnus-data-remove
6110            number
6111            (- (point-at-bol)
6112               (prog1
6113                   (1+ (point-at-eol))
6114                 (gnus-delete-line))))))
6115       ;; Remove list identifiers from subject.
6116       (when gnus-list-identifiers
6117         (let ((gnus-newsgroup-headers (list header)))
6118           (gnus-summary-remove-list-identifiers)))
6119       (when old-header
6120         (mail-header-set-number header (mail-header-number old-header)))
6121       (setq gnus-newsgroup-sparse
6122             (delq (setq number (mail-header-number header))
6123                   gnus-newsgroup-sparse))
6124       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6125       (push number gnus-newsgroup-limit)
6126       (gnus-rebuild-thread (mail-header-id header) line)
6127       (gnus-summary-goto-subject number nil t))
6128     (when (and (numberp number)
6129                (> number 0))
6130       ;; We have to update the boundaries even if we can't fetch the
6131       ;; article if ID is a number -- so that the next `P' or `N'
6132       ;; command will fetch the previous (or next) article even
6133       ;; if the one we tried to fetch this time has been canceled.
6134       (when (> number gnus-newsgroup-end)
6135         (setq gnus-newsgroup-end number))
6136       (when (< number gnus-newsgroup-begin)
6137         (setq gnus-newsgroup-begin number))
6138       (setq gnus-newsgroup-unselected
6139             (delq number gnus-newsgroup-unselected)))
6140     ;; Report back a success?
6141     (and header (mail-header-number header))))
6142
6143 ;;; Process/prefix in the summary buffer
6144
6145 (defun gnus-summary-work-articles (n)
6146   "Return a list of articles to be worked upon.
6147 The prefix argument, the list of process marked articles, and the
6148 current article will be taken into consideration."
6149   (save-excursion
6150     (set-buffer gnus-summary-buffer)
6151     (cond
6152      (n
6153       ;; A numerical prefix has been given.
6154       (setq n (prefix-numeric-value n))
6155       (let ((backward (< n 0))
6156             (n (abs (prefix-numeric-value n)))
6157             articles article)
6158         (save-excursion
6159           (while
6160               (and (> n 0)
6161                    (push (setq article (gnus-summary-article-number))
6162                          articles)
6163                    (if backward
6164                        (gnus-summary-find-prev nil article)
6165                      (gnus-summary-find-next nil article)))
6166             (decf n)))
6167         (nreverse articles)))
6168      ((and (gnus-region-active-p) (mark))
6169       (message "region active")
6170       ;; Work on the region between point and mark.
6171       (let ((max (max (point) (mark)))
6172             articles article)
6173         (save-excursion
6174           (goto-char (min (min (point) (mark))))
6175           (while
6176               (and
6177                (push (setq article (gnus-summary-article-number)) articles)
6178                (gnus-summary-find-next nil article)
6179                (< (point) max)))
6180           (nreverse articles))))
6181      (gnus-newsgroup-processable
6182       ;; There are process-marked articles present.
6183       ;; Save current state.
6184       (gnus-summary-save-process-mark)
6185       ;; Return the list.
6186       (reverse gnus-newsgroup-processable))
6187      (t
6188       ;; Just return the current article.
6189       (list (gnus-summary-article-number))))))
6190
6191 (defmacro gnus-summary-iterate (arg &rest forms)
6192   "Iterate over the process/prefixed articles and do FORMS.
6193 ARG is the interactive prefix given to the command.  FORMS will be
6194 executed with point over the summary line of the articles."
6195   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6196     `(let ((,articles (gnus-summary-work-articles ,arg)))
6197        (while ,articles
6198          (gnus-summary-goto-subject (car ,articles))
6199          ,@forms
6200          (pop ,articles)))))
6201
6202 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6203 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6204
6205 (defun gnus-summary-save-process-mark ()
6206   "Push the current set of process marked articles on the stack."
6207   (interactive)
6208   (push (copy-sequence gnus-newsgroup-processable)
6209         gnus-newsgroup-process-stack))
6210
6211 (defun gnus-summary-kill-process-mark ()
6212   "Push the current set of process marked articles on the stack and unmark."
6213   (interactive)
6214   (gnus-summary-save-process-mark)
6215   (gnus-summary-unmark-all-processable))
6216
6217 (defun gnus-summary-yank-process-mark ()
6218   "Pop the last process mark state off the stack and restore it."
6219   (interactive)
6220   (unless gnus-newsgroup-process-stack
6221     (error "Empty mark stack"))
6222   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6223
6224 (defun gnus-summary-process-mark-set (set)
6225   "Make SET into the current process marked articles."
6226   (gnus-summary-unmark-all-processable)
6227   (mapc 'gnus-summary-set-process-mark set))
6228
6229 ;;; Searching and stuff
6230
6231 (defun gnus-summary-search-group (&optional backward use-level)
6232   "Search for next unread newsgroup.
6233 If optional argument BACKWARD is non-nil, search backward instead."
6234   (save-excursion
6235     (set-buffer gnus-group-buffer)
6236     (when (gnus-group-search-forward
6237            backward nil (if use-level (gnus-group-group-level) nil))
6238       (gnus-group-group-name))))
6239
6240 (defun gnus-summary-best-group (&optional exclude-group)
6241   "Find the name of the best unread group.
6242 If EXCLUDE-GROUP, do not go to this group."
6243   (with-current-buffer gnus-group-buffer
6244     (save-excursion
6245       (gnus-group-best-unread-group exclude-group))))
6246
6247 (defun gnus-summary-find-next (&optional unread article backward)
6248   (if backward
6249       (gnus-summary-find-prev unread article)
6250     (let* ((dummy (gnus-summary-article-intangible-p))
6251            (article (or article (gnus-summary-article-number)))
6252            (data (gnus-data-find-list article))
6253            result)
6254       (when (and (not dummy)
6255                  (or (not gnus-summary-check-current)
6256                      (not unread)
6257                      (not (gnus-data-unread-p (car data)))))
6258         (setq data (cdr data)))
6259       (when (setq result
6260                   (if unread
6261                       (progn
6262                         (while data
6263                           (unless (memq (gnus-data-number (car data))
6264                                         (cond
6265                                          ((eq gnus-auto-goto-ignores
6266                                               'always-undownloaded)
6267                                           gnus-newsgroup-undownloaded)
6268                                          (gnus-plugged
6269                                           nil)
6270                                          ((eq gnus-auto-goto-ignores
6271                                               'unfetched)
6272                                           gnus-newsgroup-unfetched)
6273                                          ((eq gnus-auto-goto-ignores
6274                                               'undownloaded)
6275                                           gnus-newsgroup-undownloaded)))
6276                             (when (gnus-data-unread-p (car data))
6277                               (setq result (car data)
6278                                     data nil)))
6279                           (setq data (cdr data)))
6280                         result)
6281                     (car data)))
6282         (goto-char (gnus-data-pos result))
6283         (gnus-data-number result)))))
6284
6285 (defun gnus-summary-find-prev (&optional unread article)
6286   (let* ((eobp (eobp))
6287          (article (or article (gnus-summary-article-number)))
6288          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6289          result)
6290     (when (and (not eobp)
6291                (or (not gnus-summary-check-current)
6292                    (not unread)
6293                    (not (gnus-data-unread-p (car data)))))
6294       (setq data (cdr data)))
6295     (when (setq result
6296                 (if unread
6297                     (progn
6298                       (while data
6299                         (unless (memq (gnus-data-number (car data))
6300                                       (cond
6301                                        ((eq gnus-auto-goto-ignores
6302                                             'always-undownloaded)
6303                                         gnus-newsgroup-undownloaded)
6304                                        (gnus-plugged
6305                                         nil)
6306                                        ((eq gnus-auto-goto-ignores
6307                                             'unfetched)
6308                                         gnus-newsgroup-unfetched)
6309                                        ((eq gnus-auto-goto-ignores
6310                                             'undownloaded)
6311                                         gnus-newsgroup-undownloaded)))
6312                           (when (gnus-data-unread-p (car data))
6313                             (setq result (car data)
6314                                   data nil)))
6315                         (setq data (cdr data)))
6316                       result)
6317                   (car data)))
6318       (goto-char (gnus-data-pos result))
6319       (gnus-data-number result))))
6320
6321 (defun gnus-summary-find-subject (subject &optional unread backward article)
6322   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6323          (article (or article (gnus-summary-article-number)))
6324          (articles (gnus-data-list backward))
6325          (arts (gnus-data-find-list article articles))
6326          result)
6327     (when (or (not gnus-summary-check-current)
6328               (not unread)
6329               (not (gnus-data-unread-p (car arts))))
6330       (setq arts (cdr arts)))
6331     (while arts
6332       (and (or (not unread)
6333                (gnus-data-unread-p (car arts)))
6334            (vectorp (gnus-data-header (car arts)))
6335            (gnus-subject-equal
6336             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6337            (setq result (car arts)
6338                  arts nil))
6339       (setq arts (cdr arts)))
6340     (and result
6341          (goto-char (gnus-data-pos result))
6342          (gnus-data-number result))))
6343
6344 (defun gnus-summary-search-forward (&optional unread subject backward)
6345   "Search forward for an article.
6346 If UNREAD, look for unread articles.  If SUBJECT, look for
6347 articles with that subject.  If BACKWARD, search backward instead."
6348   (cond (subject (gnus-summary-find-subject subject unread backward))
6349         (backward (gnus-summary-find-prev unread))
6350         (t (gnus-summary-find-next unread))))
6351
6352 (defun gnus-recenter (&optional n)
6353   "Center point in window and redisplay frame.
6354 Also do horizontal recentering."
6355   (interactive "P")
6356   (when (and gnus-auto-center-summary
6357              (not (eq gnus-auto-center-summary 'vertical)))
6358     (gnus-horizontal-recenter))
6359   (recenter n))
6360
6361 (defun gnus-summary-recenter ()
6362   "Center point in the summary window.
6363 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6364 displayed, no centering will be performed."
6365   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6366   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6367   (interactive)
6368   ;; The user has to want it.
6369   (when gnus-auto-center-summary
6370     (let* ((top (cond ((< (window-height) 4) 0)
6371                       ((< (window-height) 7) 1)
6372                       (t (if (numberp gnus-auto-center-summary)
6373                              gnus-auto-center-summary
6374                            (/ (1- (window-height)) 2)))))
6375            (height (1- (window-height)))
6376            (bottom (save-excursion (goto-char (point-max))
6377                                    (forward-line (- height))
6378                                    (point)))
6379            (window (get-buffer-window (current-buffer))))
6380       (when (get-buffer-window gnus-article-buffer)
6381         ;; Only do recentering when the article buffer is displayed,
6382         ;; Set the window start to either `bottom', which is the biggest
6383         ;; possible valid number, or the second line from the top,
6384         ;; whichever is the least.
6385         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6386           (if (> bottom top-pos)
6387               ;; Keep the second line from the top visible
6388               (set-window-start window top-pos t)
6389             ;; Try to keep the bottom line visible; if it's partially
6390             ;; obscured, either scroll one more line to make it fully
6391             ;; visible, or revert to using TOP-POS.
6392             (save-excursion
6393               (goto-char (point-max))
6394               (forward-line -1)
6395               (let ((last-line-start (point)))
6396                 (goto-char bottom)
6397                 (set-window-start window (point) t)
6398                 (when (not (pos-visible-in-window-p last-line-start window))
6399                   (forward-line 1)
6400                   (set-window-start window (min (point) top-pos) t)))))))
6401       ;; Do horizontal recentering while we're at it.
6402       (when (and (get-buffer-window (current-buffer) t)
6403                  (not (eq gnus-auto-center-summary 'vertical)))
6404         (let ((selected (selected-window)))
6405           (select-window (get-buffer-window (current-buffer) t))
6406           (gnus-summary-position-point)
6407           (gnus-horizontal-recenter)
6408           (select-window selected))))))
6409
6410 (defun gnus-summary-jump-to-group (newsgroup)
6411   "Move point to NEWSGROUP in group mode buffer."
6412   ;; Keep update point of group mode buffer if visible.
6413   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6414       (save-window-excursion
6415         ;; Take care of tree window mode.
6416         (when (get-buffer-window gnus-group-buffer)
6417           (pop-to-buffer gnus-group-buffer))
6418         (gnus-group-jump-to-group newsgroup))
6419     (save-excursion
6420       ;; Take care of tree window mode.
6421       (if (get-buffer-window gnus-group-buffer)
6422           (pop-to-buffer gnus-group-buffer)
6423         (set-buffer gnus-group-buffer))
6424       (gnus-group-jump-to-group newsgroup))))
6425
6426 ;; This function returns a list of article numbers based on the
6427 ;; difference between the ranges of read articles in this group and
6428 ;; the range of active articles.
6429 (defun gnus-list-of-unread-articles (group)
6430   (let* ((read (gnus-info-read (gnus-get-info group)))
6431          (active (or (gnus-active group) (gnus-activate-group group)))
6432          (last (cdr active))
6433          first nlast unread)
6434     ;; If none are read, then all are unread.
6435     (if (not read)
6436         (setq first (car active))
6437       ;; If the range of read articles is a single range, then the
6438       ;; first unread article is the article after the last read
6439       ;; article.  Sounds logical, doesn't it?
6440       (if (and (not (listp (cdr read)))
6441                (or (< (car read) (car active))
6442                    (progn (setq read (list read))
6443                           nil)))
6444           (setq first (max (car active) (1+ (cdr read))))
6445         ;; `read' is a list of ranges.
6446         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6447                                   (caar read)))
6448                   1)
6449           (setq first (car active)))
6450         (while read
6451           (when first
6452             (while (< first nlast)
6453               (setq unread (cons first unread)
6454                     first (1+ first))))
6455           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6456           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6457           (setq read (cdr read)))))
6458     ;; And add the last unread articles.
6459     (while (<= first last)
6460       (setq unread (cons first unread)
6461             first (1+ first)))
6462     ;; Return the list of unread articles.
6463     (delq 0 (nreverse unread))))
6464
6465 (defun gnus-list-of-read-articles (group)
6466   "Return a list of unread, unticked and non-dormant articles."
6467   (let* ((info (gnus-get-info group))
6468          (marked (gnus-info-marks info))
6469          (active (gnus-active group)))
6470     (and info active
6471          (gnus-list-range-difference
6472           (gnus-list-range-difference
6473            (gnus-sorted-complement
6474             (gnus-uncompress-range active)
6475             (gnus-list-of-unread-articles group))
6476            (cdr (assq 'dormant marked)))
6477           (cdr (assq 'tick marked))))))
6478
6479 ;; This function returns a sequence of article numbers based on the
6480 ;; difference between the ranges of read articles in this group and
6481 ;; the range of active articles.
6482 (defun gnus-sequence-of-unread-articles (group)
6483   (let* ((read (gnus-info-read (gnus-get-info group)))
6484          (active (or (gnus-active group) (gnus-activate-group group)))
6485          (last (cdr active))
6486          first nlast unread)
6487     ;; If none are read, then all are unread.
6488     (if (not read)
6489         (setq first (car active))
6490       ;; If the range of read articles is a single range, then the
6491       ;; first unread article is the article after the last read
6492       ;; article.  Sounds logical, doesn't it?
6493       (if (and (not (listp (cdr read)))
6494                (or (< (car read) (car active))
6495                    (progn (setq read (list read))
6496                           nil)))
6497           (setq first (max (car active) (1+ (cdr read))))
6498         ;; `read' is a list of ranges.
6499         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6500                                   (caar read)))
6501                   1)
6502           (setq first (car active)))
6503         (while read
6504           (when first
6505             (push (cons first nlast) unread))
6506           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6507           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6508           (setq read (cdr read)))))
6509     ;; And add the last unread articles.
6510     (cond ((< first last)
6511            (push (cons first last) unread))
6512           ((= first last)
6513            (push first unread)))
6514     ;; Return the sequence of unread articles.
6515     (delq 0 (nreverse unread))))
6516
6517 ;; Various summary commands
6518
6519 (defun gnus-summary-select-article-buffer ()
6520   "Reconfigure windows to show article buffer."
6521   (interactive)
6522   (if (not (gnus-buffer-live-p gnus-article-buffer))
6523       (error "There is no article buffer for this summary buffer")
6524     (gnus-configure-windows 'article)
6525     (select-window (get-buffer-window gnus-article-buffer))))
6526
6527 (defun gnus-summary-universal-argument (arg)
6528   "Perform any operation on all articles that are process/prefixed."
6529   (interactive "P")
6530   (let ((articles (gnus-summary-work-articles arg))
6531         func article)
6532     (if (eq
6533          (setq
6534           func
6535           (key-binding
6536            (read-key-sequence
6537             (substitute-command-keys
6538              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6539          'undefined)
6540         (gnus-error 1 "Undefined key")
6541       (save-excursion
6542         (while articles
6543           (gnus-summary-goto-subject (setq article (pop articles)))
6544           (let (gnus-newsgroup-processable)
6545             (command-execute func))
6546           (gnus-summary-remove-process-mark article)))))
6547   (gnus-summary-position-point))
6548
6549 (defun gnus-summary-toggle-truncation (&optional arg)
6550   "Toggle truncation of summary lines.
6551 With ARG, turn line truncation on if ARG is positive."
6552   (interactive "P")
6553   (setq truncate-lines
6554         (if (null arg) (not truncate-lines)
6555           (> (prefix-numeric-value arg) 0)))
6556   (redraw-display))
6557
6558 (defun gnus-summary-find-for-reselect ()
6559   "Return the number of an article to stay on across a reselect.
6560 The current article is considered, then following articles, then previous
6561 articles.  An article is sought which is not cancelled and isn't a temporary
6562 insertion from another group.  If there's no such then return a dummy 0."
6563   (let (found)
6564     (dolist (rev '(nil t))
6565       (unless found      ; don't demand the reverse list if we don't need it
6566         (let ((data (gnus-data-find-list
6567                      (gnus-summary-article-number) (gnus-data-list rev))))
6568           (while (and data (not found))
6569             (if (and (< 0 (gnus-data-number (car data)))
6570                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6571                 (setq found (gnus-data-number (car data))))
6572             (setq data (cdr data))))))
6573     (or found 0)))
6574
6575 (defun gnus-summary-reselect-current-group (&optional all rescan)
6576   "Exit and then reselect the current newsgroup.
6577 The prefix argument ALL means to select all articles."
6578   (interactive "P")
6579   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6580     (error "Ephemeral groups can't be reselected"))
6581   (let ((current-subject (gnus-summary-find-for-reselect))
6582         (group gnus-newsgroup-name))
6583     (setq gnus-newsgroup-begin nil)
6584     (gnus-summary-exit nil 'leave-hidden)
6585     ;; We have to adjust the point of group mode buffer because
6586     ;; point was moved to the next unread newsgroup by exiting.
6587     (gnus-summary-jump-to-group group)
6588     (when rescan
6589       (save-excursion
6590         (gnus-group-get-new-news-this-group 1)))
6591     (gnus-group-read-group all t)
6592     (gnus-summary-goto-subject current-subject nil t)))
6593
6594 (defun gnus-summary-rescan-group (&optional all)
6595   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6596   (interactive "P")
6597   (gnus-summary-reselect-current-group all t))
6598
6599 (defun gnus-summary-update-info (&optional non-destructive)
6600   (save-excursion
6601     (let ((group gnus-newsgroup-name))
6602       (when group
6603         (when gnus-newsgroup-kill-headers
6604           (setq gnus-newsgroup-killed
6605                 (gnus-compress-sequence
6606                  (gnus-sorted-union
6607                   (gnus-list-range-intersection
6608                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6609                   gnus-newsgroup-unreads)
6610                  t)))
6611         (unless (listp (cdr gnus-newsgroup-killed))
6612           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6613         (let ((headers gnus-newsgroup-headers))
6614           ;; Set the new ranges of read articles.
6615           (with-current-buffer gnus-group-buffer
6616             (gnus-undo-force-boundary))
6617           (gnus-update-read-articles
6618            group (gnus-sorted-union
6619                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6620           ;; Set the current article marks.
6621           (let ((gnus-newsgroup-scored
6622                  (if (and (not gnus-save-score)
6623                           (not non-destructive))
6624                      nil
6625                    gnus-newsgroup-scored)))
6626             (save-excursion
6627               (gnus-update-marks)))
6628           ;; Do the cross-ref thing.
6629           (when gnus-use-cross-reference
6630             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6631           ;; Do not switch windows but change the buffer to work.
6632           (set-buffer gnus-group-buffer)
6633           (unless (gnus-ephemeral-group-p group)
6634             (gnus-group-update-group group)))))))
6635
6636 (defun gnus-summary-save-newsrc (&optional force)
6637   "Save the current number of read/marked articles in the dribble buffer.
6638 The dribble buffer will then be saved.
6639 If FORCE (the prefix), also save the .newsrc file(s)."
6640   (interactive "P")
6641   (gnus-summary-update-info t)
6642   (if force
6643       (gnus-save-newsrc-file)
6644     (gnus-dribble-save)))
6645
6646 (defun gnus-summary-exit (&optional temporary leave-hidden)
6647   "Exit reading current newsgroup, and then return to group selection mode.
6648 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6649   (interactive)
6650   (gnus-set-global-variables)
6651   (when (gnus-buffer-live-p gnus-article-buffer)
6652     (save-excursion
6653       (set-buffer gnus-article-buffer)
6654       (mm-destroy-parts gnus-article-mime-handles)
6655       ;; Set it to nil for safety reason.
6656       (setq gnus-article-mime-handle-alist nil)
6657       (setq gnus-article-mime-handles nil)))
6658   (gnus-kill-save-kill-buffer)
6659   (gnus-async-halt-prefetch)
6660   (let* ((group gnus-newsgroup-name)
6661          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6662          (gnus-group-is-exiting-p t)
6663          (mode major-mode)
6664          (group-point nil)
6665          (buf (current-buffer)))
6666     (unless quit-config
6667       ;; Do adaptive scoring, and possibly save score files.
6668       (when gnus-newsgroup-adaptive
6669         (gnus-score-adaptive))
6670       (when gnus-use-scoring
6671         (gnus-score-save)))
6672     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6673     ;; If we have several article buffers, we kill them at exit.
6674     (unless gnus-single-article-buffer
6675       (gnus-kill-buffer gnus-original-article-buffer)
6676       (setq gnus-article-current nil))
6677     (when gnus-use-cache
6678       (gnus-cache-possibly-remove-articles)
6679       (gnus-cache-save-buffers))
6680     (gnus-async-prefetch-remove-group group)
6681     (when gnus-suppress-duplicates
6682       (gnus-dup-enter-articles))
6683     (when gnus-use-trees
6684       (gnus-tree-close group))
6685     (when gnus-use-cache
6686       (gnus-cache-write-active))
6687     ;; Remove entries for this group.
6688     (nnmail-purge-split-history (gnus-group-real-name group))
6689     ;; Make all changes in this group permanent.
6690     (unless quit-config
6691       (gnus-run-hooks 'gnus-exit-group-hook)
6692       (gnus-summary-update-info))
6693     (gnus-close-group group)
6694     ;; Make sure where we were, and go to next newsgroup.
6695     (set-buffer gnus-group-buffer)
6696     (unless quit-config
6697       (gnus-group-jump-to-group group))
6698     (gnus-run-hooks 'gnus-summary-exit-hook)
6699     (unless (or quit-config
6700                 ;; If this group has disappeared from the summary
6701                 ;; buffer, don't skip forwards.
6702                 (not (string= group (gnus-group-group-name))))
6703       (gnus-group-next-unread-group 1))
6704     (setq group-point (point))
6705     (if temporary
6706         nil                             ;Nothing to do.
6707       ;; If we have several article buffers, we kill them at exit.
6708       (unless gnus-single-article-buffer
6709         (gnus-kill-buffer gnus-article-buffer)
6710         (gnus-kill-buffer gnus-original-article-buffer)
6711         (setq gnus-article-current nil))
6712       (set-buffer buf)
6713       (if (not gnus-kill-summary-on-exit)
6714           (progn
6715             (gnus-deaden-summary)
6716             (setq mode nil))
6717         ;; We set all buffer-local variables to nil.  It is unclear why
6718         ;; this is needed, but if we don't, buffer-local variables are
6719         ;; not garbage-collected, it seems.  This would the lead to en
6720         ;; ever-growing Emacs.
6721         (gnus-summary-clear-local-variables)
6722         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6723           (gnus-summary-clear-local-variables))
6724         (when (get-buffer gnus-article-buffer)
6725           (bury-buffer gnus-article-buffer))
6726         ;; Return to group mode buffer.
6727         (when (eq mode 'gnus-summary-mode)
6728           (gnus-kill-buffer buf)))
6729       (setq gnus-current-select-method gnus-select-method)
6730       (set-buffer gnus-group-buffer)
6731       (if quit-config
6732           (gnus-handle-ephemeral-exit quit-config)
6733         (goto-char group-point)
6734         (unless leave-hidden
6735           (gnus-configure-windows 'group 'force)))
6736       ;; Clear the current group name.
6737       (unless quit-config
6738         (setq gnus-newsgroup-name nil)))))
6739
6740 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6741 (defun gnus-summary-exit-no-update (&optional no-questions)
6742   "Quit reading current newsgroup without updating read article info."
6743   (interactive)
6744   (let* ((group gnus-newsgroup-name)
6745          (gnus-group-is-exiting-p t)
6746          (gnus-group-is-exiting-without-update-p t)
6747          (quit-config (gnus-group-quit-config group)))
6748     (when (or no-questions
6749               gnus-expert-user
6750               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6751       (gnus-async-halt-prefetch)
6752       (run-hooks 'gnus-summary-prepare-exit-hook)
6753       (when (gnus-buffer-live-p gnus-article-buffer)
6754         (save-excursion
6755           (set-buffer gnus-article-buffer)
6756           (mm-destroy-parts gnus-article-mime-handles)
6757           ;; Set it to nil for safety reason.
6758           (setq gnus-article-mime-handle-alist nil)
6759           (setq gnus-article-mime-handles nil)))
6760       ;; If we have several article buffers, we kill them at exit.
6761       (unless gnus-single-article-buffer
6762         (gnus-kill-buffer gnus-article-buffer)
6763         (gnus-kill-buffer gnus-original-article-buffer)
6764         (setq gnus-article-current nil))
6765       (if (not gnus-kill-summary-on-exit)
6766           (gnus-deaden-summary)
6767         (gnus-close-group group)
6768         (gnus-summary-clear-local-variables)
6769         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6770           (gnus-summary-clear-local-variables))
6771         (gnus-kill-buffer gnus-summary-buffer))
6772       (unless gnus-single-article-buffer
6773         (setq gnus-article-current nil))
6774       (when gnus-use-trees
6775         (gnus-tree-close group))
6776       (gnus-async-prefetch-remove-group group)
6777       (when (get-buffer gnus-article-buffer)
6778         (bury-buffer gnus-article-buffer))
6779       ;; Return to the group buffer.
6780       (gnus-configure-windows 'group 'force)
6781       ;; Clear the current group name.
6782       (setq gnus-newsgroup-name nil)
6783       (unless (gnus-ephemeral-group-p group)
6784         (gnus-group-update-group group))
6785       (when (equal (gnus-group-group-name) group)
6786         (gnus-group-next-unread-group 1))
6787       (when quit-config
6788         (gnus-handle-ephemeral-exit quit-config)))))
6789
6790 (defun gnus-handle-ephemeral-exit (quit-config)
6791   "Handle movement when leaving an ephemeral group.
6792 The state which existed when entering the ephemeral is reset."
6793   (if (not (buffer-name (car quit-config)))
6794       (gnus-configure-windows 'group 'force)
6795     (set-buffer (car quit-config))
6796     (cond ((eq major-mode 'gnus-summary-mode)
6797            (gnus-set-global-variables))
6798           ((eq major-mode 'gnus-article-mode)
6799            (save-excursion
6800              ;; The `gnus-summary-buffer' variable may point
6801              ;; to the old summary buffer when using a single
6802              ;; article buffer.
6803              (unless (gnus-buffer-live-p gnus-summary-buffer)
6804                (set-buffer gnus-group-buffer))
6805              (set-buffer gnus-summary-buffer)
6806              (gnus-set-global-variables))))
6807     (if (or (eq (cdr quit-config) 'article)
6808             (eq (cdr quit-config) 'pick))
6809         (progn
6810           ;; The current article may be from the ephemeral group
6811           ;; thus it is best that we reload this article
6812           ;;
6813           ;; If we're exiting from a large digest, this can be
6814           ;; extremely slow.  So, it's better not to reload it. -- jh.
6815           ;;(gnus-summary-show-article)
6816           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6817               (gnus-configure-windows 'pick 'force)
6818             (gnus-configure-windows (cdr quit-config) 'force)))
6819       (gnus-configure-windows (cdr quit-config) 'force))
6820     (when (eq major-mode 'gnus-summary-mode)
6821       (gnus-summary-next-subject 1 nil t)
6822       (gnus-summary-recenter)
6823       (gnus-summary-position-point))))
6824
6825 ;;; Dead summaries.
6826
6827 (defvar gnus-dead-summary-mode-map nil)
6828
6829 (unless gnus-dead-summary-mode-map
6830   (setq gnus-dead-summary-mode-map (make-keymap))
6831   (suppress-keymap gnus-dead-summary-mode-map)
6832   (substitute-key-definition
6833    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6834   (dolist (key '("\C-d" "\r" "\177" [delete]))
6835     (define-key gnus-dead-summary-mode-map
6836       key 'gnus-summary-wake-up-the-dead))
6837   (dolist (key '("q" "Q"))
6838     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6839
6840 (defvar gnus-dead-summary-mode nil
6841   "Minor mode for Gnus summary buffers.")
6842
6843 (defun gnus-dead-summary-mode (&optional arg)
6844   "Minor mode for Gnus summary buffers."
6845   (interactive "P")
6846   (when (eq major-mode 'gnus-summary-mode)
6847     (make-local-variable 'gnus-dead-summary-mode)
6848     (setq gnus-dead-summary-mode
6849           (if (null arg) (not gnus-dead-summary-mode)
6850             (> (prefix-numeric-value arg) 0)))
6851     (when gnus-dead-summary-mode
6852       (add-minor-mode
6853        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6854
6855 (defun gnus-deaden-summary ()
6856   "Make the current summary buffer into a dead summary buffer."
6857   ;; Kill any previous dead summary buffer.
6858   (when (and gnus-dead-summary
6859              (buffer-name gnus-dead-summary))
6860     (with-current-buffer gnus-dead-summary
6861       (when gnus-dead-summary-mode
6862         (kill-buffer (current-buffer)))))
6863   ;; Make this the current dead summary.
6864   (setq gnus-dead-summary (current-buffer))
6865   (gnus-dead-summary-mode 1)
6866   (let ((name (buffer-name)))
6867     (when (string-match "Summary" name)
6868       (rename-buffer
6869        (concat (substring name 0 (match-beginning 0)) "Dead "
6870                (substring name (match-beginning 0)))
6871        t)
6872       (bury-buffer))))
6873
6874 (defun gnus-kill-or-deaden-summary (buffer)
6875   "Kill or deaden the summary BUFFER."
6876   (save-excursion
6877     (when (and (buffer-name buffer)
6878                (not gnus-single-article-buffer))
6879       (with-current-buffer buffer
6880         (gnus-kill-buffer gnus-article-buffer)
6881         (gnus-kill-buffer gnus-original-article-buffer)))
6882     (cond
6883      ;; Kill the buffer.
6884      (gnus-kill-summary-on-exit
6885       (when (and gnus-use-trees
6886                  (gnus-buffer-exists-p buffer))
6887         (save-excursion
6888           (set-buffer buffer)
6889           (gnus-tree-close gnus-newsgroup-name)))
6890       (gnus-kill-buffer buffer))
6891      ;; Deaden the buffer.
6892      ((gnus-buffer-exists-p buffer)
6893       (save-excursion
6894         (set-buffer buffer)
6895         (gnus-deaden-summary))))))
6896
6897 (defun gnus-summary-wake-up-the-dead (&rest args)
6898   "Wake up the dead summary buffer."
6899   (interactive)
6900   (gnus-dead-summary-mode -1)
6901   (let ((name (buffer-name)))
6902     (when (string-match "Dead " name)
6903       (rename-buffer
6904        (concat (substring name 0 (match-beginning 0))
6905                (substring name (match-end 0)))
6906        t)))
6907   (gnus-message 3 "This dead summary is now alive again"))
6908
6909 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6910 (defun gnus-summary-fetch-faq (&optional faq-dir)
6911   "Fetch the FAQ for the current group.
6912 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6913 in."
6914   (interactive
6915    (list
6916     (when current-prefix-arg
6917       (completing-read
6918        "FAQ dir: " (and (listp gnus-group-faq-directory)
6919                         (mapcar 'list
6920                                 gnus-group-faq-directory))))))
6921   (let (gnus-faq-buffer)
6922     (when (setq gnus-faq-buffer
6923                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6924       (gnus-configure-windows 'summary-faq))))
6925
6926 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6927 (defun gnus-summary-describe-group (&optional force)
6928   "Describe the current newsgroup."
6929   (interactive "P")
6930   (gnus-group-describe-group force gnus-newsgroup-name))
6931
6932 (defun gnus-summary-describe-briefly ()
6933   "Describe summary mode commands briefly."
6934   (interactive)
6935   (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")))
6936
6937 ;; Walking around group mode buffer from summary mode.
6938
6939 (defun gnus-summary-next-group (&optional no-article target-group backward)
6940   "Exit current newsgroup and then select next unread newsgroup.
6941 If prefix argument NO-ARTICLE is non-nil, no article is selected
6942 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6943 previous group instead."
6944   (interactive "P")
6945   ;; Stop pre-fetching.
6946   (gnus-async-halt-prefetch)
6947   (let ((current-group gnus-newsgroup-name)
6948         (current-buffer (current-buffer))
6949         entered)
6950     ;; First we semi-exit this group to update Xrefs and all variables.
6951     ;; We can't do a real exit, because the window conf must remain
6952     ;; the same in case the user is prompted for info, and we don't
6953     ;; want the window conf to change before that...
6954     (gnus-summary-exit t)
6955     (while (not entered)
6956       ;; Then we find what group we are supposed to enter.
6957       (set-buffer gnus-group-buffer)
6958       (gnus-group-jump-to-group current-group)
6959       (setq target-group
6960             (or target-group
6961                 (if (eq gnus-keep-same-level 'best)
6962                     (gnus-summary-best-group gnus-newsgroup-name)
6963                   (gnus-summary-search-group backward gnus-keep-same-level))))
6964       (if (not target-group)
6965           ;; There are no further groups, so we return to the group
6966           ;; buffer.
6967           (progn
6968             (gnus-message 5 "Returning to the group buffer")
6969             (setq entered t)
6970             (when (gnus-buffer-live-p current-buffer)
6971               (set-buffer current-buffer)
6972               (gnus-summary-exit))
6973             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6974         ;; We try to enter the target group.
6975         (gnus-group-jump-to-group target-group)
6976         (let ((unreads (gnus-group-group-unread)))
6977           (if (and (or (eq t unreads)
6978                        (and unreads (not (zerop unreads))))
6979                    (gnus-summary-read-group
6980                     target-group nil no-article
6981                     (and (buffer-name current-buffer) current-buffer)
6982                     nil backward))
6983               (setq entered t)
6984             (setq current-group target-group
6985                   target-group nil)))))))
6986
6987 (defun gnus-summary-prev-group (&optional no-article)
6988   "Exit current newsgroup and then select previous unread newsgroup.
6989 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6990   (interactive "P")
6991   (gnus-summary-next-group no-article nil t))
6992
6993 ;; Walking around summary lines.
6994
6995 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6996   "Go to the first subject satisfying any non-nil constraint.
6997 If UNREAD is non-nil, the article should be unread.
6998 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6999 If UNSEEN is non-nil, the article should be unseen.
7000 Returns the article selected or nil if there are no matching articles."
7001   (interactive "P")
7002   (cond
7003    ;; Empty summary.
7004    ((null gnus-newsgroup-data)
7005     (gnus-message 3 "No articles in the group")
7006     nil)
7007    ;; Pick the first article.
7008    ((not (or unread undownloaded unseen))
7009     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7010     (gnus-data-number (car gnus-newsgroup-data)))
7011    ;; Find the first unread article.
7012    (t
7013     (let ((data gnus-newsgroup-data))
7014       (while (and data
7015                   (let ((num (gnus-data-number (car data))))
7016                     (or (memq num gnus-newsgroup-unfetched)
7017                         (not (or (and unread
7018                                       (memq num gnus-newsgroup-unreads))
7019                                  (and undownloaded
7020                                       (memq num gnus-newsgroup-undownloaded))
7021                                  (and unseen
7022                                       (memq num gnus-newsgroup-unseen)))))))
7023         (setq data (cdr data)))
7024       (prog1
7025           (if data
7026               (progn
7027                 (goto-char (gnus-data-pos (car data)))
7028                 (gnus-data-number (car data)))
7029             (gnus-message 3 "No more%s articles"
7030                           (let* ((r (when unread " unread"))
7031                                  (d (when undownloaded " undownloaded"))
7032                                  (s (when unseen " unseen"))
7033                                  (l (delq nil (list r d s))))
7034                             (cond ((= 3 (length l))
7035                                    (concat r "," d ", or" s))
7036                                   ((= 2 (length l))
7037                                    (concat (car l) ", or" (cadr l)))
7038                                   ((= 1 (length l))
7039                                    (car l))
7040                                   (t
7041                                    ""))))
7042             nil
7043             )
7044         (gnus-summary-position-point))))))
7045
7046 (defun gnus-summary-next-subject (n &optional unread dont-display)
7047   "Go to next N'th summary line.
7048 If N is negative, go to the previous N'th subject line.
7049 If UNREAD is non-nil, only unread articles are selected.
7050 The difference between N and the actual number of steps taken is
7051 returned."
7052   (interactive "p")
7053   (let ((backward (< n 0))
7054         (n (abs n)))
7055     (while (and (> n 0)
7056                 (if backward
7057                     (gnus-summary-find-prev unread)
7058                   (gnus-summary-find-next unread)))
7059       (unless (zerop (setq n (1- n)))
7060         (gnus-summary-show-thread)))
7061     (when (/= 0 n)
7062       (gnus-message 7 "No more%s articles"
7063                     (if unread " unread" "")))
7064     (unless dont-display
7065       (gnus-summary-recenter)
7066       (gnus-summary-position-point))
7067     n))
7068
7069 (defun gnus-summary-next-unread-subject (n)
7070   "Go to next N'th unread summary line."
7071   (interactive "p")
7072   (gnus-summary-next-subject n t))
7073
7074 (defun gnus-summary-prev-subject (n &optional unread)
7075   "Go to previous N'th summary line.
7076 If optional argument UNREAD is non-nil, only unread article is selected."
7077   (interactive "p")
7078   (gnus-summary-next-subject (- n) unread))
7079
7080 (defun gnus-summary-prev-unread-subject (n)
7081   "Go to previous N'th unread summary line."
7082   (interactive "p")
7083   (gnus-summary-next-subject (- n) t))
7084
7085 (defun gnus-summary-goto-subjects (articles)
7086   "Insert the subject header for ARTICLES in the current buffer."
7087   (save-excursion
7088     (dolist (article articles)
7089       (gnus-summary-goto-subject article t)))
7090   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7091   (gnus-summary-position-point))
7092
7093 (defun gnus-summary-goto-subject (article &optional force silent)
7094   "Go the subject line of ARTICLE.
7095 If FORCE, also allow jumping to articles not currently shown."
7096   (interactive "nArticle number: ")
7097   (unless (numberp article)
7098     (error "Article %s is not a number" article))
7099   (let ((b (point))
7100         (data (gnus-data-find article)))
7101     ;; We read in the article if we have to.
7102     (and (not data)
7103          force
7104          (gnus-summary-insert-subject
7105           article
7106           (if (or (numberp force) (vectorp force)) force)
7107           t)
7108          (setq data (gnus-data-find article)))
7109     (goto-char b)
7110     (if (not data)
7111         (progn
7112           (unless silent
7113             (gnus-message 3 "Can't find article %d" article))
7114           nil)
7115       (let ((pt (gnus-data-pos data)))
7116         (goto-char pt)
7117         (gnus-summary-set-article-display-arrow pt))
7118       (gnus-summary-position-point)
7119       article)))
7120
7121 ;; Walking around summary lines with displaying articles.
7122
7123 (defun gnus-summary-expand-window (&optional arg)
7124   "Make the summary buffer take up the entire Emacs frame.
7125 Given a prefix, will force an `article' buffer configuration."
7126   (interactive "P")
7127   (if arg
7128       (gnus-configure-windows 'article 'force)
7129     (gnus-configure-windows 'summary 'force)))
7130
7131 (defun gnus-summary-display-article (article &optional all-header)
7132   "Display ARTICLE in article buffer."
7133   (when (gnus-buffer-live-p gnus-article-buffer)
7134     (with-current-buffer gnus-article-buffer
7135       (mm-enable-multibyte)))
7136   (gnus-set-global-variables)
7137   (when (gnus-buffer-live-p gnus-article-buffer)
7138     (with-current-buffer gnus-article-buffer
7139       (setq gnus-article-charset gnus-newsgroup-charset)
7140       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7141       (mm-enable-multibyte)))
7142   (if (null article)
7143       nil
7144     (prog1
7145         (if gnus-summary-display-article-function
7146             (funcall gnus-summary-display-article-function article all-header)
7147           (gnus-article-prepare article all-header))
7148       (gnus-run-hooks 'gnus-select-article-hook)
7149       (when (and gnus-current-article
7150                  (not (zerop gnus-current-article)))
7151         (gnus-summary-goto-subject gnus-current-article))
7152       (gnus-summary-recenter)
7153       (when (and gnus-use-trees gnus-show-threads)
7154         (gnus-possibly-generate-tree article)
7155         (gnus-highlight-selected-tree article))
7156       ;; Successfully display article.
7157       (gnus-article-set-window-start
7158        (cdr (assq article gnus-newsgroup-bookmarks))))))
7159
7160 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7161   "Select the current article.
7162 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7163 non-nil, the article will be re-fetched even if it already present in
7164 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7165 be displayed."
7166   ;; Make sure we are in the summary buffer to work around bbdb bug.
7167   (unless (eq major-mode 'gnus-summary-mode)
7168     (set-buffer gnus-summary-buffer))
7169   (let ((article (or article (gnus-summary-article-number)))
7170         (all-headers (not (not all-headers))) ;Must be t or nil.
7171         gnus-summary-display-article-function)
7172     (and (not pseudo)
7173          (gnus-summary-article-pseudo-p article)
7174          (error "This is a pseudo-article"))
7175     (save-excursion
7176       (set-buffer gnus-summary-buffer)
7177       (if (or (and gnus-single-article-buffer
7178                    (or (null gnus-current-article)
7179                        (null gnus-article-current)
7180                        (null (get-buffer gnus-article-buffer))
7181                        (not (eq article (cdr gnus-article-current)))
7182                        (not (equal (car gnus-article-current)
7183                                    gnus-newsgroup-name))))
7184               (and (not gnus-single-article-buffer)
7185                    (or (null gnus-current-article)
7186                        (not (eq gnus-current-article article))))
7187               force)
7188           ;; The requested article is different from the current article.
7189           (progn
7190             (gnus-summary-display-article article all-headers)
7191             (when (gnus-buffer-live-p gnus-article-buffer)
7192               (with-current-buffer gnus-article-buffer
7193                 (if (not gnus-article-decoded-p) ;; a local variable
7194                     (mm-disable-multibyte))))
7195             (gnus-article-set-window-start
7196              (cdr (assq article gnus-newsgroup-bookmarks)))
7197             article)
7198         'old))))
7199
7200 (defun gnus-summary-force-verify-and-decrypt ()
7201   "Display buttons for signed/encrypted parts and verify/decrypt them."
7202   (interactive)
7203   (let ((mm-verify-option 'known)
7204         (mm-decrypt-option 'known)
7205         (gnus-article-emulate-mime t)
7206         (gnus-buttonized-mime-types (append (list "multipart/signed"
7207                                                   "multipart/encrypted")
7208                                             gnus-buttonized-mime-types)))
7209     (gnus-summary-select-article nil 'force)))
7210
7211 (defun gnus-summary-set-current-mark (&optional current-mark)
7212   "Obsolete function."
7213   nil)
7214
7215 (defun gnus-summary-next-article (&optional unread subject backward push)
7216   "Select the next article.
7217 If UNREAD, only unread articles are selected.
7218 If SUBJECT, only articles with SUBJECT are selected.
7219 If BACKWARD, the previous article is selected instead of the next."
7220   (interactive "P")
7221   (cond
7222    ;; Is there such an article?
7223    ((and (gnus-summary-search-forward unread subject backward)
7224          (or (gnus-summary-display-article (gnus-summary-article-number))
7225              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7226     (gnus-summary-position-point))
7227    ;; If not, we try the first unread, if that is wanted.
7228    ((and subject
7229          gnus-auto-select-same
7230          (gnus-summary-first-unread-article))
7231     (gnus-summary-position-point)
7232     (gnus-message 6 "Wrapped"))
7233    ;; Try to get next/previous article not displayed in this group.
7234    ((and gnus-auto-extend-newsgroup
7235          (not unread) (not subject))
7236     (gnus-summary-goto-article
7237      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7238      nil (count-lines (point-min) (point))))
7239    ;; Go to next/previous group.
7240    (t
7241     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7242       (gnus-summary-jump-to-group gnus-newsgroup-name))
7243     (let ((cmd last-command-char)
7244           (point
7245            (with-current-buffer gnus-group-buffer
7246              (point)))
7247           (group
7248            (if (eq gnus-keep-same-level 'best)
7249                (gnus-summary-best-group gnus-newsgroup-name)
7250              (gnus-summary-search-group backward gnus-keep-same-level))))
7251       ;; For some reason, the group window gets selected.  We change
7252       ;; it back.
7253       (select-window (get-buffer-window (current-buffer)))
7254       ;; Select next unread newsgroup automagically.
7255       (cond
7256        ((or (not gnus-auto-select-next)
7257             (not cmd))
7258         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7259        ((or (eq gnus-auto-select-next 'quietly)
7260             (and (eq gnus-auto-select-next 'slightly-quietly)
7261                  push)
7262             (and (eq gnus-auto-select-next 'almost-quietly)
7263                  (gnus-summary-last-article-p)))
7264         ;; Select quietly.
7265         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7266             (gnus-summary-exit)
7267           (gnus-message 7 "No more%s articles (%s)..."
7268                         (if unread " unread" "")
7269                         (if group (concat "selecting " group)
7270                           "exiting"))
7271           (gnus-summary-next-group nil group backward)))
7272        (t
7273         (when (gnus-key-press-event-p last-input-event)
7274           (gnus-summary-walk-group-buffer
7275            gnus-newsgroup-name cmd unread backward point))))))))
7276
7277 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7278   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7279                       (?\C-p (gnus-group-prev-unread-group 1))))
7280         (cursor-in-echo-area t)
7281         keve key group ended prompt)
7282     (save-excursion
7283       (set-buffer gnus-group-buffer)
7284       (goto-char start)
7285       (setq group
7286             (if (eq gnus-keep-same-level 'best)
7287                 (gnus-summary-best-group gnus-newsgroup-name)
7288               (gnus-summary-search-group backward gnus-keep-same-level))))
7289     (while (not ended)
7290       (setq prompt
7291             (format
7292              "No more%s articles%s " (if unread " unread" "")
7293              (if (and group
7294                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7295                  (format " (Type %s for %s [%s])"
7296                          (single-key-description cmd)
7297                          (gnus-group-decoded-name group)
7298                          (gnus-group-unread group))
7299                (format " (Type %s to exit %s)"
7300                        (single-key-description cmd)
7301                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7302       ;; Confirm auto selection.
7303       (setq key (car (setq keve (gnus-read-event-char prompt)))
7304             ended t)
7305       (cond
7306        ((assq key keystrokes)
7307         (let ((obuf (current-buffer)))
7308           (switch-to-buffer gnus-group-buffer)
7309           (when group
7310             (gnus-group-jump-to-group group))
7311           (eval (cadr (assq key keystrokes)))
7312           (setq group (gnus-group-group-name))
7313           (switch-to-buffer obuf))
7314         (setq ended nil))
7315        ((equal key cmd)
7316         (if (or (not group)
7317                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7318             (gnus-summary-exit)
7319           (gnus-summary-next-group nil group backward)))
7320        (t
7321         (push (cdr keve) unread-command-events))))))
7322
7323 (defun gnus-summary-next-unread-article ()
7324   "Select unread article after current one."
7325   (interactive)
7326   (gnus-summary-next-article
7327    (or (not (eq gnus-summary-goto-unread 'never))
7328        (gnus-summary-last-article-p (gnus-summary-article-number)))
7329    (and gnus-auto-select-same
7330         (gnus-summary-article-subject))))
7331
7332 (defun gnus-summary-prev-article (&optional unread subject)
7333   "Select the article after the current one.
7334 If UNREAD is non-nil, only unread articles are selected."
7335   (interactive "P")
7336   (gnus-summary-next-article unread subject t))
7337
7338 (defun gnus-summary-prev-unread-article ()
7339   "Select unread article before current one."
7340   (interactive)
7341   (gnus-summary-prev-article
7342    (or (not (eq gnus-summary-goto-unread 'never))
7343        (gnus-summary-first-article-p (gnus-summary-article-number)))
7344    (and gnus-auto-select-same
7345         (gnus-summary-article-subject))))
7346
7347 (defun gnus-summary-next-page (&optional lines circular stop)
7348   "Show next page of the selected article.
7349 If at the end of the current article, select the next article.
7350 LINES says how many lines should be scrolled up.
7351
7352 If CIRCULAR is non-nil, go to the start of the article instead of
7353 selecting the next article when reaching the end of the current
7354 article.
7355
7356 If STOP is non-nil, just stop when reaching the end of the message.
7357
7358 Also see the variable `gnus-article-skip-boring'."
7359   (interactive "P")
7360   (setq gnus-summary-buffer (current-buffer))
7361   (gnus-set-global-variables)
7362   (let ((article (gnus-summary-article-number))
7363         (article-window (get-buffer-window gnus-article-buffer t))
7364         endp)
7365     ;; If the buffer is empty, we have no article.
7366     (unless article
7367       (error "No article to select"))
7368     (gnus-configure-windows 'article)
7369     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7370         (if (and (eq gnus-summary-goto-unread 'never)
7371                  (not (gnus-summary-last-article-p article)))
7372             (gnus-summary-next-article)
7373           (gnus-summary-next-unread-article))
7374       (if (or (null gnus-current-article)
7375               (null gnus-article-current)
7376               (/= article (cdr gnus-article-current))
7377               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7378           ;; Selected subject is different from current article's.
7379           (gnus-summary-display-article article)
7380         (when article-window
7381           (gnus-eval-in-buffer-window gnus-article-buffer
7382             (setq endp (or (gnus-article-next-page lines)
7383                            (gnus-article-only-boring-p))))
7384           (when endp
7385             (cond (stop
7386                    (gnus-message 3 "End of message"))
7387                   (circular
7388                    (gnus-summary-beginning-of-article))
7389                   (lines
7390                    (gnus-message 3 "End of message"))
7391                   ((null lines)
7392                    (if (and (eq gnus-summary-goto-unread 'never)
7393                             (not (gnus-summary-last-article-p article)))
7394                        (gnus-summary-next-article)
7395                      (gnus-summary-next-unread-article))))))))
7396     (gnus-summary-recenter)
7397     (gnus-summary-position-point)))
7398
7399 (defun gnus-summary-prev-page (&optional lines move)
7400   "Show previous page of selected article.
7401 Argument LINES specifies lines to be scrolled down.
7402 If MOVE, move to the previous unread article if point is at
7403 the beginning of the buffer."
7404   (interactive "P")
7405   (let ((article (gnus-summary-article-number))
7406         (article-window (get-buffer-window gnus-article-buffer t))
7407         endp)
7408     (gnus-configure-windows 'article)
7409     (if (or (null gnus-current-article)
7410             (null gnus-article-current)
7411             (/= article (cdr gnus-article-current))
7412             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7413         ;; Selected subject is different from current article's.
7414         (gnus-summary-display-article article)
7415       (gnus-summary-recenter)
7416       (when article-window
7417         (gnus-eval-in-buffer-window gnus-article-buffer
7418           (setq endp (gnus-article-prev-page lines)))
7419         (when (and move endp)
7420           (cond (lines
7421                  (gnus-message 3 "Beginning of message"))
7422                 ((null lines)
7423                  (if (and (eq gnus-summary-goto-unread 'never)
7424                           (not (gnus-summary-first-article-p article)))
7425                      (gnus-summary-prev-article)
7426                    (gnus-summary-prev-unread-article))))))))
7427   (gnus-summary-position-point))
7428
7429 (defun gnus-summary-prev-page-or-article (&optional lines)
7430   "Show previous page of selected article.
7431 Argument LINES specifies lines to be scrolled down.
7432 If at the beginning of the article, go to the next article."
7433   (interactive "P")
7434   (gnus-summary-prev-page lines t))
7435
7436 (defun gnus-summary-scroll-up (lines)
7437   "Scroll up (or down) one line current article.
7438 Argument LINES specifies lines to be scrolled up (or down if negative)."
7439   (interactive "p")
7440   (gnus-configure-windows 'article)
7441   (gnus-summary-show-thread)
7442   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7443     (gnus-eval-in-buffer-window gnus-article-buffer
7444       (cond ((> lines 0)
7445              (when (gnus-article-next-page lines)
7446                (gnus-message 3 "End of message")))
7447             ((< lines 0)
7448              (gnus-article-prev-page (- lines))))))
7449   (gnus-summary-recenter)
7450   (gnus-summary-position-point))
7451
7452 (defun gnus-summary-scroll-down (lines)
7453   "Scroll down (or up) one line current article.
7454 Argument LINES specifies lines to be scrolled down (or up if negative)."
7455   (interactive "p")
7456   (gnus-summary-scroll-up (- lines)))
7457
7458 (defun gnus-summary-next-same-subject ()
7459   "Select next article which has the same subject as current one."
7460   (interactive)
7461   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7462
7463 (defun gnus-summary-prev-same-subject ()
7464   "Select previous article which has the same subject as current one."
7465   (interactive)
7466   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7467
7468 (defun gnus-summary-next-unread-same-subject ()
7469   "Select next unread article which has the same subject as current one."
7470   (interactive)
7471   (gnus-summary-next-article t (gnus-summary-article-subject)))
7472
7473 (defun gnus-summary-prev-unread-same-subject ()
7474   "Select previous unread article which has the same subject as current one."
7475   (interactive)
7476   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7477
7478 (defun gnus-summary-first-unread-article ()
7479   "Select the first unread article.
7480 Return nil if there are no unread articles."
7481   (interactive)
7482   (prog1
7483       (when (gnus-summary-first-subject t)
7484         (gnus-summary-show-thread)
7485         (gnus-summary-first-subject t)
7486         (gnus-summary-display-article (gnus-summary-article-number)))
7487     (gnus-summary-position-point)))
7488
7489 (defun gnus-summary-first-unread-subject ()
7490   "Place the point on the subject line of the first unread article.
7491 Return nil if there are no unread articles."
7492   (interactive)
7493   (prog1
7494       (when (gnus-summary-first-subject t)
7495         (gnus-summary-show-thread)
7496         (gnus-summary-first-subject t))
7497     (gnus-summary-position-point)))
7498
7499 (defun gnus-summary-first-unseen-subject ()
7500   "Place the point on the subject line of the first unseen article.
7501 Return nil if there are no unseen articles."
7502   (interactive)
7503   (prog1
7504       (when (gnus-summary-first-subject nil nil t)
7505         (gnus-summary-show-thread)
7506         (gnus-summary-first-subject nil nil t))
7507     (gnus-summary-position-point)))
7508
7509 (defun gnus-summary-first-unseen-or-unread-subject ()
7510   "Place the point on the subject line of the first unseen article or,
7511 if all article have been seen, on the subject line of the first unread
7512 article."
7513   (interactive)
7514   (prog1
7515       (unless (when (gnus-summary-first-subject nil nil t)
7516                 (gnus-summary-show-thread)
7517                 (gnus-summary-first-subject nil nil t))
7518         (when (gnus-summary-first-subject t)
7519           (gnus-summary-show-thread)
7520           (gnus-summary-first-subject t)))
7521     (gnus-summary-position-point)))
7522
7523 (defun gnus-summary-first-article ()
7524   "Select the first article.
7525 Return nil if there are no articles."
7526   (interactive)
7527   (prog1
7528       (when (gnus-summary-first-subject)
7529         (gnus-summary-show-thread)
7530         (gnus-summary-first-subject)
7531         (gnus-summary-display-article (gnus-summary-article-number)))
7532     (gnus-summary-position-point)))
7533
7534 (defun gnus-summary-best-unread-article (&optional arg)
7535   "Select the unread article with the highest score.
7536 If given a prefix argument, select the next unread article that has a
7537 score higher than the default score."
7538   (interactive "P")
7539   (let ((article (if arg
7540                      (gnus-summary-better-unread-subject)
7541                    (gnus-summary-best-unread-subject))))
7542     (if article
7543         (gnus-summary-goto-article article)
7544       (error "No unread articles"))))
7545
7546 (defun gnus-summary-best-unread-subject ()
7547   "Select the unread subject with the highest score."
7548   (interactive)
7549   (let ((best -1000000)
7550         (data gnus-newsgroup-data)
7551         article score)
7552     (while data
7553       (and (gnus-data-unread-p (car data))
7554            (> (setq score
7555                     (gnus-summary-article-score (gnus-data-number (car data))))
7556               best)
7557            (setq best score
7558                  article (gnus-data-number (car data))))
7559       (setq data (cdr data)))
7560     (when article
7561       (gnus-summary-goto-subject article))
7562     (gnus-summary-position-point)
7563     article))
7564
7565 (defun gnus-summary-better-unread-subject ()
7566   "Select the first unread subject that has a score over the default score."
7567   (interactive)
7568   (let ((data gnus-newsgroup-data)
7569         article score)
7570     (while (and (setq article (gnus-data-number (car data)))
7571                 (or (gnus-data-read-p (car data))
7572                     (not (> (gnus-summary-article-score article)
7573                             gnus-summary-default-score))))
7574       (setq data (cdr data)))
7575     (when article
7576       (gnus-summary-goto-subject article))
7577     (gnus-summary-position-point)
7578     article))
7579
7580 (defun gnus-summary-last-subject ()
7581   "Go to the last displayed subject line in the group."
7582   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7583     (when article
7584       (gnus-summary-goto-subject article))))
7585
7586 (defun gnus-summary-goto-article (article &optional all-headers force)
7587   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7588 If ALL-HEADERS is non-nil, no header lines are hidden.
7589 If FORCE, go to the article even if it isn't displayed.  If FORCE
7590 is a number, it is the line the article is to be displayed on."
7591   (interactive
7592    (list
7593     (completing-read
7594      "Article number or Message-ID: "
7595      (mapcar (lambda (number) (list (int-to-string number)))
7596              gnus-newsgroup-limit))
7597     current-prefix-arg
7598     t))
7599   (prog1
7600       (if (and (stringp article)
7601                (string-match "@\\|%40" article))
7602           (gnus-summary-refer-article article)
7603         (when (stringp article)
7604           (setq article (string-to-number article)))
7605         (if (gnus-summary-goto-subject article force)
7606             (gnus-summary-display-article article all-headers)
7607           (gnus-message 4 "Couldn't go to article %s" article) nil))
7608     (gnus-summary-position-point)))
7609
7610 (defun gnus-summary-goto-last-article ()
7611   "Go to the previously read article."
7612   (interactive)
7613   (prog1
7614       (when gnus-last-article
7615         (gnus-summary-goto-article gnus-last-article nil t))
7616     (gnus-summary-position-point)))
7617
7618 (defun gnus-summary-pop-article (number)
7619   "Pop one article off the history and go to the previous.
7620 NUMBER articles will be popped off."
7621   (interactive "p")
7622   (let (to)
7623     (setq gnus-newsgroup-history
7624           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7625     (if to
7626         (gnus-summary-goto-article (car to) nil t)
7627       (error "Article history empty")))
7628   (gnus-summary-position-point))
7629
7630 ;; Summary commands and functions for limiting the summary buffer.
7631
7632 (defun gnus-summary-limit-to-articles (n)
7633   "Limit the summary buffer to the next N articles.
7634 If not given a prefix, use the process marked articles instead."
7635   (interactive "P")
7636   (prog1
7637       (let ((articles (gnus-summary-work-articles n)))
7638         (setq gnus-newsgroup-processable nil)
7639         (gnus-summary-limit articles))
7640     (gnus-summary-position-point)))
7641
7642 (defun gnus-summary-pop-limit (&optional total)
7643   "Restore the previous limit.
7644 If given a prefix, remove all limits."
7645   (interactive "P")
7646   (when total
7647     (setq gnus-newsgroup-limits
7648           (list (mapcar (lambda (h) (mail-header-number h))
7649                         gnus-newsgroup-headers))))
7650   (unless gnus-newsgroup-limits
7651     (error "No limit to pop"))
7652   (prog1
7653       (gnus-summary-limit nil 'pop)
7654     (gnus-summary-position-point)))
7655
7656 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7657   "Limit the summary buffer to articles that have subjects that match a regexp.
7658 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7659   (interactive
7660    (list (read-string (if current-prefix-arg
7661                           "Exclude subject (regexp): "
7662                         "Limit to subject (regexp): "))
7663          nil current-prefix-arg))
7664   (unless header
7665     (setq header "subject"))
7666   (when (not (equal "" subject))
7667     (prog1
7668         (let ((articles (gnus-summary-find-matching
7669                          (or header "subject") subject 'all nil nil
7670                          not-matching)))
7671           (unless articles
7672             (error "Found no matches for \"%s\"" subject))
7673           (gnus-summary-limit articles))
7674       (gnus-summary-position-point))))
7675
7676 (defun gnus-summary-limit-to-author (from &optional not-matching)
7677   "Limit the summary buffer to articles that have authors that match a regexp.
7678 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7679   (interactive
7680    (list (read-string (if current-prefix-arg
7681                           "Exclude author (regexp): "
7682                         "Limit to author (regexp): "))
7683          current-prefix-arg))
7684   (gnus-summary-limit-to-subject from "from" not-matching))
7685
7686 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7687   "Limit the summary buffer to articles with the given RECIPIENT.
7688
7689 If NOT-MATCHING, exclude RECIPIENT.
7690
7691 To and Cc headers are checked.  You need to include them in
7692 `nnmail-extra-headers'."
7693   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7694   (interactive
7695    (list (read-string (format "%s recipient (regexp): "
7696                               (if current-prefix-arg "Exclude" "Limit to")))
7697          current-prefix-arg))
7698   (when (not (equal "" recipient))
7699     (prog1 (let* ((to
7700                    (if (memq 'To nnmail-extra-headers)
7701                        (gnus-summary-find-matching
7702                         (cons 'extra 'To) recipient 'all nil nil
7703                         not-matching)
7704                      (gnus-message
7705                       1 "`To' isn't present in `nnmail-extra-headers'")
7706                      (sit-for 1)
7707                      nil))
7708                   (cc
7709                    (if (memq 'Cc nnmail-extra-headers)
7710                        (gnus-summary-find-matching
7711                         (cons 'extra 'Cc) recipient 'all nil nil
7712                         not-matching)
7713                      (gnus-message
7714                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7715                      (sit-for 1)
7716                      nil))
7717                   (articles
7718                    (if not-matching
7719                        ;; We need the numbers that are in both lists:
7720                        (mapcar (lambda (a)
7721                                  (and (memq a to) a))
7722                                cc)
7723                      (nconc to cc))))
7724              (unless articles
7725                (error "Found no matches for \"%s\"" recipient))
7726              (gnus-summary-limit articles))
7727       (gnus-summary-position-point))))
7728
7729 (defun gnus-summary-limit-to-age (age &optional younger-p)
7730   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7731 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7732 articles that are younger than AGE days."
7733   (interactive
7734    (let ((younger current-prefix-arg)
7735          (days-got nil)
7736          days)
7737      (while (not days-got)
7738        (setq days (if younger
7739                       (read-string "Limit to articles younger than (in days, older when negative): ")
7740                     (read-string
7741                      "Limit to articles older than (in days, younger when negative): ")))
7742        (when (> (length days) 0)
7743          (setq days (read days)))
7744        (if (numberp days)
7745            (progn
7746              (setq days-got t)
7747              (when (< days 0)
7748                (setq younger (not younger))
7749                (setq days (* days -1))))
7750          (message "Please enter a number.")
7751          (sleep-for 1)))
7752      (list days younger)))
7753   (prog1
7754       (let ((data gnus-newsgroup-data)
7755             (cutoff (days-to-time age))
7756             articles d date is-younger)
7757         (while (setq d (pop data))
7758           (when (and (vectorp (gnus-data-header d))
7759                      (setq date (mail-header-date (gnus-data-header d))))
7760             (setq is-younger (time-less-p
7761                               (time-since (condition-case ()
7762                                               (date-to-time date)
7763                                             (error '(0 0))))
7764                               cutoff))
7765             (when (if younger-p
7766                       is-younger
7767                     (not is-younger))
7768               (push (gnus-data-number d) articles))))
7769         (gnus-summary-limit (nreverse articles)))
7770     (gnus-summary-position-point)))
7771
7772 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7773   "Limit the summary buffer to articles that match an 'extra' header."
7774   (interactive
7775    (let ((header
7776           (intern
7777            (gnus-completing-read-with-default
7778             (symbol-name (car gnus-extra-headers))
7779             (if current-prefix-arg
7780                 "Exclude extra header:"
7781               "Limit extra header:")
7782             (mapcar (lambda (x)
7783                       (cons (symbol-name x) x))
7784                     gnus-extra-headers)
7785             nil
7786             t))))
7787      (list header
7788            (read-string (format "%s header %s (regexp): "
7789                                 (if current-prefix-arg "Exclude" "Limit to")
7790                                 header))
7791            current-prefix-arg)))
7792   (when (not (equal "" regexp))
7793     (prog1
7794         (let ((articles (gnus-summary-find-matching
7795                          (cons 'extra header) regexp 'all nil nil
7796                          not-matching)))
7797           (unless articles
7798             (error "Found no matches for \"%s\"" regexp))
7799           (gnus-summary-limit articles))
7800       (gnus-summary-position-point))))
7801
7802 (defun gnus-summary-limit-to-display-predicate ()
7803   "Limit the summary buffer to the predicated in the `display' group parameter."
7804   (interactive)
7805   (unless gnus-newsgroup-display
7806     (error "There is no `display' group parameter"))
7807   (let (articles)
7808     (dolist (number gnus-newsgroup-articles)
7809       (when (funcall gnus-newsgroup-display)
7810         (push number articles)))
7811     (gnus-summary-limit articles))
7812   (gnus-summary-position-point))
7813
7814 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7815 (make-obsolete
7816  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7817
7818 (defun gnus-summary-limit-to-unread (&optional all)
7819   "Limit the summary buffer to articles that are not marked as read.
7820 If ALL is non-nil, limit strictly to unread articles."
7821   (interactive "P")
7822   (if all
7823       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7824     (gnus-summary-limit-to-marks
7825      ;; Concat all the marks that say that an article is read and have
7826      ;; those removed.
7827      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7828            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7829            gnus-low-score-mark gnus-expirable-mark
7830            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7831            gnus-duplicate-mark gnus-souped-mark)
7832      'reverse)))
7833
7834 (defun gnus-summary-limit-to-replied (&optional unreplied)
7835   "Limit the summary buffer to replied articles.
7836 If UNREPLIED (the prefix), limit to unreplied articles."
7837   (interactive "P")
7838   (if unreplied
7839       (gnus-summary-limit
7840        (gnus-set-difference gnus-newsgroup-articles
7841         gnus-newsgroup-replied))
7842     (gnus-summary-limit gnus-newsgroup-replied))
7843   (gnus-summary-position-point))
7844
7845 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7846 (make-obsolete 'gnus-summary-delete-marked-with
7847                'gnus-summary-limit-exclude-marks)
7848
7849 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7850   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7851 If REVERSE, limit the summary buffer to articles that are marked
7852 with MARKS.  MARKS can either be a string of marks or a list of marks.
7853 Returns how many articles were removed."
7854   (interactive "sMarks: ")
7855   (gnus-summary-limit-to-marks marks t))
7856
7857 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7858   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7859 If REVERSE (the prefix), limit the summary buffer to articles that are
7860 not marked with MARKS.  MARKS can either be a string of marks or a
7861 list of marks.
7862 Returns how many articles were removed."
7863   (interactive "sMarks: \nP")
7864   (prog1
7865       (let ((data gnus-newsgroup-data)
7866             (marks (if (listp marks) marks
7867                      (append marks nil))) ; Transform to list.
7868             articles)
7869         (while data
7870           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7871                   (memq (gnus-data-mark (car data)) marks))
7872             (push (gnus-data-number (car data)) articles))
7873           (setq data (cdr data)))
7874         (gnus-summary-limit articles))
7875     (gnus-summary-position-point)))
7876
7877 (defun gnus-summary-limit-to-score (score)
7878   "Limit to articles with score at or above SCORE."
7879   (interactive "NLimit to articles with score of at least: ")
7880   (let ((data gnus-newsgroup-data)
7881         articles)
7882     (while data
7883       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7884                 score)
7885         (push (gnus-data-number (car data)) articles))
7886       (setq data (cdr data)))
7887     (prog1
7888         (gnus-summary-limit articles)
7889       (gnus-summary-position-point))))
7890
7891 (defun gnus-summary-limit-to-unseen ()
7892   "Limit to unseen articles."
7893   (interactive)
7894   (prog1
7895       (gnus-summary-limit gnus-newsgroup-unseen)
7896     (gnus-summary-position-point)))
7897
7898 (defun gnus-summary-limit-include-thread (id)
7899   "Display all the hidden articles that is in the thread with ID in it.
7900 When called interactively, ID is the Message-ID of the current
7901 article."
7902   (interactive (list (mail-header-id (gnus-summary-article-header))))
7903   (let ((articles (gnus-articles-in-thread
7904                    (gnus-id-to-thread (gnus-root-id id)))))
7905     (prog1
7906         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7907       (gnus-summary-limit-include-matching-articles
7908        "subject"
7909        (regexp-quote (gnus-simplify-subject-re
7910                       (mail-header-subject (gnus-id-to-header id)))))
7911       (gnus-summary-position-point))))
7912
7913 (defun gnus-summary-limit-include-matching-articles (header regexp)
7914   "Display all the hidden articles that have HEADERs that match REGEXP."
7915   (interactive (list (read-string "Match on header: ")
7916                      (read-string "Regexp: ")))
7917   (let ((articles (gnus-find-matching-articles header regexp)))
7918     (prog1
7919         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7920       (gnus-summary-position-point))))
7921
7922 (defun gnus-summary-insert-dormant-articles ()
7923   "Insert all the dormant articles for this group into the current buffer."
7924   (interactive)
7925   (let ((gnus-verbose (max 6 gnus-verbose)))
7926     (if (not gnus-newsgroup-dormant)
7927         (gnus-message 3 "No cached articles for this group")
7928       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7929
7930 (defun gnus-summary-limit-include-dormant ()
7931   "Display all the hidden articles that are marked as dormant.
7932 Note that this command only works on a subset of the articles currently
7933 fetched for this group."
7934   (interactive)
7935   (unless gnus-newsgroup-dormant
7936     (error "There are no dormant articles in this group"))
7937   (prog1
7938       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7939     (gnus-summary-position-point)))
7940
7941 (defun gnus-summary-limit-exclude-dormant ()
7942   "Hide all dormant articles."
7943   (interactive)
7944   (prog1
7945       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7946     (gnus-summary-position-point)))
7947
7948 (defun gnus-summary-limit-exclude-childless-dormant ()
7949   "Hide all dormant articles that have no children."
7950   (interactive)
7951   (let ((data (gnus-data-list t))
7952         articles d children)
7953     ;; Find all articles that are either not dormant or have
7954     ;; children.
7955     (while (setq d (pop data))
7956       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7957                 (and (setq children
7958                            (gnus-article-children (gnus-data-number d)))
7959                      (let (found)
7960                        (while children
7961                          (when (memq (car children) articles)
7962                            (setq children nil
7963                                  found t))
7964                          (pop children))
7965                        found)))
7966         (push (gnus-data-number d) articles)))
7967     ;; Do the limiting.
7968     (prog1
7969         (gnus-summary-limit articles)
7970       (gnus-summary-position-point))))
7971
7972 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7973   "Mark all unread excluded articles as read.
7974 If ALL, mark even excluded ticked and dormants as read."
7975   (interactive "P")
7976   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7977   (let ((articles (gnus-sorted-ndifference
7978                    (sort
7979                     (mapcar (lambda (h) (mail-header-number h))
7980                             gnus-newsgroup-headers)
7981                     '<)
7982                    gnus-newsgroup-limit))
7983         article)
7984     (setq gnus-newsgroup-unreads
7985           (gnus-sorted-intersection gnus-newsgroup-unreads
7986                                     gnus-newsgroup-limit))
7987     (if all
7988         (setq gnus-newsgroup-dormant nil
7989               gnus-newsgroup-marked nil
7990               gnus-newsgroup-reads
7991               (nconc
7992                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7993                gnus-newsgroup-reads))
7994       (while (setq article (pop articles))
7995         (unless (or (memq article gnus-newsgroup-dormant)
7996                     (memq article gnus-newsgroup-marked))
7997           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7998
7999 (defun gnus-summary-limit (articles &optional pop)
8000   (if pop
8001       ;; We pop the previous limit off the stack and use that.
8002       (setq articles (car gnus-newsgroup-limits)
8003             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8004     ;; We use the new limit, so we push the old limit on the stack.
8005     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8006   ;; Set the limit.
8007   (setq gnus-newsgroup-limit articles)
8008   (let ((total (length gnus-newsgroup-data))
8009         (data (gnus-data-find-list (gnus-summary-article-number)))
8010         (gnus-summary-mark-below nil)   ; Inhibit this.
8011         found)
8012     ;; This will do all the work of generating the new summary buffer
8013     ;; according to the new limit.
8014     (gnus-summary-prepare)
8015     ;; Hide any threads, possibly.
8016     (gnus-summary-maybe-hide-threads)
8017     ;; Try to return to the article you were at, or one in the
8018     ;; neighborhood.
8019     (when data
8020       ;; We try to find some article after the current one.
8021       (while data
8022         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8023           (setq data nil
8024                 found t))
8025         (setq data (cdr data))))
8026     (unless found
8027       ;; If there is no data, that means that we were after the last
8028       ;; article.  The same goes when we can't find any articles
8029       ;; after the current one.
8030       (goto-char (point-max))
8031       (gnus-summary-find-prev))
8032     (gnus-set-mode-line 'summary)
8033     ;; We return how many articles were removed from the summary
8034     ;; buffer as a result of the new limit.
8035     (- total (length gnus-newsgroup-data))))
8036
8037 (defsubst gnus-invisible-cut-children (threads)
8038   (let ((num 0))
8039     (while threads
8040       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8041         (incf num))
8042       (pop threads))
8043     (< num 2)))
8044
8045 (defsubst gnus-cut-thread (thread)
8046   "Go forwards in the thread until we find an article that we want to display."
8047   (when (or (eq gnus-fetch-old-headers 'some)
8048             (eq gnus-fetch-old-headers 'invisible)
8049             (numberp gnus-fetch-old-headers)
8050             (eq gnus-build-sparse-threads 'some)
8051             (eq gnus-build-sparse-threads 'more))
8052     ;; Deal with old-fetched headers and sparse threads.
8053     (while (and
8054             thread
8055             (or
8056              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8057              (gnus-summary-article-ancient-p
8058               (mail-header-number (car thread))))
8059             (if (or (<= (length (cdr thread)) 1)
8060                     (eq gnus-fetch-old-headers 'invisible))
8061                 (setq gnus-newsgroup-limit
8062                       (delq (mail-header-number (car thread))
8063                             gnus-newsgroup-limit)
8064                       thread (cadr thread))
8065               (when (gnus-invisible-cut-children (cdr thread))
8066                 (let ((th (cdr thread)))
8067                   (while th
8068                     (if (memq (mail-header-number (caar th))
8069                               gnus-newsgroup-limit)
8070                         (setq thread (car th)
8071                               th nil)
8072                       (setq th (cdr th))))))))))
8073   thread)
8074
8075 (defun gnus-cut-threads (threads)
8076   "Cut off all uninteresting articles from the beginning of THREADS."
8077   (when (or (eq gnus-fetch-old-headers 'some)
8078             (eq gnus-fetch-old-headers 'invisible)
8079             (numberp gnus-fetch-old-headers)
8080             (eq gnus-build-sparse-threads 'some)
8081             (eq gnus-build-sparse-threads 'more))
8082     (let ((th threads))
8083       (while th
8084         (setcar th (gnus-cut-thread (car th)))
8085         (setq th (cdr th)))))
8086   ;; Remove nixed out threads.
8087   (delq nil threads))
8088
8089 (defun gnus-summary-initial-limit (&optional show-if-empty)
8090   "Figure out what the initial limit is supposed to be on group entry.
8091 This entails weeding out unwanted dormants, low-scored articles,
8092 fetch-old-headers verbiage, and so on."
8093   ;; Most groups have nothing to remove.
8094   (if (or gnus-inhibit-limiting
8095           (and (null gnus-newsgroup-dormant)
8096                (eq gnus-newsgroup-display 'gnus-not-ignore)
8097                (not (eq gnus-fetch-old-headers 'some))
8098                (not (numberp gnus-fetch-old-headers))
8099                (not (eq gnus-fetch-old-headers 'invisible))
8100                (null gnus-summary-expunge-below)
8101                (not (eq gnus-build-sparse-threads 'some))
8102                (not (eq gnus-build-sparse-threads 'more))
8103                (null gnus-thread-expunge-below)
8104                (not gnus-use-nocem)))
8105       ()                                ; Do nothing.
8106     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8107     (setq gnus-newsgroup-limit nil)
8108     (mapatoms
8109      (lambda (node)
8110        (unless (car (symbol-value node))
8111          ;; These threads have no parents -- they are roots.
8112          (let ((nodes (cdr (symbol-value node)))
8113                thread)
8114            (while nodes
8115              (if (and gnus-thread-expunge-below
8116                       (< (gnus-thread-total-score (car nodes))
8117                          gnus-thread-expunge-below))
8118                  (gnus-expunge-thread (pop nodes))
8119                (setq thread (pop nodes))
8120                (gnus-summary-limit-children thread))))))
8121      gnus-newsgroup-dependencies)
8122     ;; If this limitation resulted in an empty group, we might
8123     ;; pop the previous limit and use it instead.
8124     (when (and (not gnus-newsgroup-limit)
8125                show-if-empty)
8126       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8127     gnus-newsgroup-limit))
8128
8129 (defun gnus-summary-limit-children (thread)
8130   "Return 1 if this subthread is visible and 0 if it is not."
8131   ;; First we get the number of visible children to this thread.  This
8132   ;; is done by recursing down the thread using this function, so this
8133   ;; will really go down to a leaf article first, before slowly
8134   ;; working its way up towards the root.
8135   (when thread
8136     (let* ((max-lisp-eval-depth 5000)
8137            (children
8138            (if (cdr thread)
8139                (apply '+ (mapcar 'gnus-summary-limit-children
8140                                  (cdr thread)))
8141              0))
8142           (number (mail-header-number (car thread)))
8143           score)
8144       (if (and
8145            (not (memq number gnus-newsgroup-marked))
8146            (or
8147             ;; If this article is dormant and has absolutely no visible
8148             ;; children, then this article isn't visible.
8149             (and (memq number gnus-newsgroup-dormant)
8150                  (zerop children))
8151             ;; If this is "fetch-old-headered" and there is no
8152             ;; visible children, then we don't want this article.
8153             (and (or (eq gnus-fetch-old-headers 'some)
8154                      (numberp gnus-fetch-old-headers))
8155                  (gnus-summary-article-ancient-p number)
8156                  (zerop children))
8157             ;; If this is "fetch-old-headered" and `invisible', then
8158             ;; we don't want this article.
8159             (and (eq gnus-fetch-old-headers 'invisible)
8160                  (gnus-summary-article-ancient-p number))
8161             ;; If this is a sparsely inserted article with no children,
8162             ;; we don't want it.
8163             (and (eq gnus-build-sparse-threads 'some)
8164                  (gnus-summary-article-sparse-p number)
8165                  (zerop children))
8166             ;; If we use expunging, and this article is really
8167             ;; low-scored, then we don't want this article.
8168             (when (and gnus-summary-expunge-below
8169                        (< (setq score
8170                                 (or (cdr (assq number gnus-newsgroup-scored))
8171                                     gnus-summary-default-score))
8172                           gnus-summary-expunge-below))
8173               ;; We increase the expunge-tally here, but that has
8174               ;; nothing to do with the limits, really.
8175               (incf gnus-newsgroup-expunged-tally)
8176               ;; We also mark as read here, if that's wanted.
8177               (when (and gnus-summary-mark-below
8178                          (< score gnus-summary-mark-below))
8179                 (setq gnus-newsgroup-unreads
8180                       (delq number gnus-newsgroup-unreads))
8181                 (if gnus-newsgroup-auto-expire
8182                     (push number gnus-newsgroup-expirable)
8183                   (push (cons number gnus-low-score-mark)
8184                         gnus-newsgroup-reads)))
8185               t)
8186             ;; Do the `display' group parameter.
8187             (and gnus-newsgroup-display
8188                  (not (funcall gnus-newsgroup-display)))
8189             ;; Check NoCeM things.
8190             (when (and gnus-use-nocem
8191                        (gnus-nocem-unwanted-article-p
8192                         (mail-header-id (car thread))))
8193               (setq gnus-newsgroup-unreads
8194                     (delq number gnus-newsgroup-unreads))
8195               t)))
8196           ;; Nope, invisible article.
8197           0
8198         ;; Ok, this article is to be visible, so we add it to the limit
8199         ;; and return 1.
8200         (push number gnus-newsgroup-limit)
8201         1))))
8202
8203 (defun gnus-expunge-thread (thread)
8204   "Mark all articles in THREAD as read."
8205   (let* ((number (mail-header-number (car thread))))
8206     (incf gnus-newsgroup-expunged-tally)
8207     ;; We also mark as read here, if that's wanted.
8208     (setq gnus-newsgroup-unreads
8209           (delq number gnus-newsgroup-unreads))
8210     (if gnus-newsgroup-auto-expire
8211         (push number gnus-newsgroup-expirable)
8212       (push (cons number gnus-low-score-mark)
8213             gnus-newsgroup-reads)))
8214   ;; Go recursively through all subthreads.
8215   (mapcar 'gnus-expunge-thread (cdr thread)))
8216
8217 ;; Summary article oriented commands
8218
8219 (defun gnus-summary-refer-parent-article (n)
8220   "Refer parent article N times.
8221 If N is negative, go to ancestor -N instead.
8222 The difference between N and the number of articles fetched is returned."
8223   (interactive "p")
8224   (let ((skip 1)
8225         error header ref)
8226     (when (not (natnump n))
8227       (setq skip (abs n)
8228             n 1))
8229     (while (and (> n 0)
8230                 (not error))
8231       (setq header (gnus-summary-article-header))
8232       (if (and (eq (mail-header-number header)
8233                    (cdr gnus-article-current))
8234                (equal gnus-newsgroup-name
8235                       (car gnus-article-current)))
8236           ;; If we try to find the parent of the currently
8237           ;; displayed article, then we take a look at the actual
8238           ;; References header, since this is slightly more
8239           ;; reliable than the References field we got from the
8240           ;; server.
8241           (save-excursion
8242             (set-buffer gnus-original-article-buffer)
8243             (nnheader-narrow-to-headers)
8244             (unless (setq ref (message-fetch-field "references"))
8245               (when (setq ref (message-fetch-field "in-reply-to"))
8246                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8247             (widen))
8248         (setq ref
8249               ;; It's not the current article, so we take a bet on
8250               ;; the value we got from the server.
8251               (mail-header-references header)))
8252       (if (and ref
8253                (not (equal ref "")))
8254           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8255             (gnus-message 1 "Couldn't find parent"))
8256         (gnus-message 1 "No references in article %d"
8257                       (gnus-summary-article-number))
8258         (setq error t))
8259       (decf n))
8260     (gnus-summary-position-point)
8261     n))
8262
8263 (defun gnus-summary-refer-references ()
8264   "Fetch all articles mentioned in the References header.
8265 Return the number of articles fetched."
8266   (interactive)
8267   (let ((ref (mail-header-references (gnus-summary-article-header)))
8268         (current (gnus-summary-article-number))
8269         (n 0))
8270     (if (or (not ref)
8271             (equal ref ""))
8272         (error "No References in the current article")
8273       ;; For each Message-ID in the References header...
8274       (while (string-match "<[^>]*>" ref)
8275         (incf n)
8276         ;; ... fetch that article.
8277         (gnus-summary-refer-article
8278          (prog1 (match-string 0 ref)
8279            (setq ref (substring ref (match-end 0))))))
8280       (gnus-summary-goto-subject current)
8281       (gnus-summary-position-point)
8282       n)))
8283
8284 (defun gnus-summary-refer-thread (&optional limit)
8285   "Fetch all articles in the current thread.
8286 If LIMIT (the numerical prefix), fetch that many old headers instead
8287 of what's specified by the `gnus-refer-thread-limit' variable."
8288   (interactive "P")
8289   (let ((id (mail-header-id (gnus-summary-article-header)))
8290         (limit (if limit (prefix-numeric-value limit)
8291                  gnus-refer-thread-limit)))
8292     (unless (eq gnus-fetch-old-headers 'invisible)
8293       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8294       ;; Retrieve the headers and read them in.
8295       (if (eq (if (numberp limit)
8296                   (gnus-retrieve-headers
8297                    (list (min
8298                           (+ (mail-header-number
8299                               (gnus-summary-article-header))
8300                              limit)
8301                           gnus-newsgroup-end))
8302                    gnus-newsgroup-name (* limit 2))
8303                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8304                 ;; headers.
8305                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8306                                        gnus-newsgroup-name limit))
8307               'nov)
8308           (gnus-build-all-threads)
8309         (error "Can't fetch thread from back ends that don't support NOV"))
8310       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8311     (gnus-summary-limit-include-thread id)))
8312
8313 (defun gnus-summary-refer-article (message-id)
8314   "Fetch an article specified by MESSAGE-ID."
8315   (interactive "sMessage-ID: ")
8316   (when (and (stringp message-id)
8317              (not (zerop (length message-id))))
8318     (setq message-id (gnus-replace-in-string message-id " " ""))
8319     ;; Construct the correct Message-ID if necessary.
8320     ;; Suggested by tale@pawl.rpi.edu.
8321     (unless (string-match "^<" message-id)
8322       (setq message-id (concat "<" message-id)))
8323     (unless (string-match ">$" message-id)
8324       (setq message-id (concat message-id ">")))
8325     ;; People often post MIDs from URLs, so unhex it:
8326     (unless (string-match "@" message-id)
8327       (setq message-id (gnus-url-unhex-string message-id)))
8328     (let* ((header (gnus-id-to-header message-id))
8329            (sparse (and header
8330                         (gnus-summary-article-sparse-p
8331                          (mail-header-number header))
8332                         (memq (mail-header-number header)
8333                               gnus-newsgroup-limit)))
8334            number)
8335       (cond
8336        ;; If the article is present in the buffer we just go to it.
8337        ((and header
8338              (or (not (gnus-summary-article-sparse-p
8339                        (mail-header-number header)))
8340                  sparse))
8341         (prog1
8342             (gnus-summary-goto-article
8343              (mail-header-number header) nil t)
8344           (when sparse
8345             (gnus-summary-update-article (mail-header-number header)))))
8346        (t
8347         ;; We fetch the article.
8348         (catch 'found
8349           (dolist (gnus-override-method (gnus-refer-article-methods))
8350             (when (and (gnus-check-server gnus-override-method)
8351                        ;; Fetch the header,
8352                        (setq number (gnus-summary-insert-subject message-id)))
8353               ;; and display the article.
8354               (gnus-summary-select-article nil nil nil number)
8355               (throw 'found t)))
8356           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8357
8358 (defun gnus-refer-article-methods ()
8359   "Return a list of referable methods."
8360   (cond
8361    ;; No method, so we default to current and native.
8362    ((null gnus-refer-article-method)
8363     (list gnus-current-select-method gnus-select-method))
8364    ;; Current.
8365    ((eq 'current gnus-refer-article-method)
8366     (list gnus-current-select-method))
8367    ;; List of select methods.
8368    ((not (and (symbolp (car gnus-refer-article-method))
8369               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8370     (let (out)
8371       (dolist (method gnus-refer-article-method)
8372         (push (if (eq 'current method)
8373                   gnus-current-select-method
8374                 method)
8375               out))
8376       (nreverse out)))
8377    ;; One single select method.
8378    (t
8379     (list gnus-refer-article-method))))
8380
8381 (defun gnus-summary-edit-parameters ()
8382   "Edit the group parameters of the current group."
8383   (interactive)
8384   (gnus-group-edit-group gnus-newsgroup-name 'params))
8385
8386 (defun gnus-summary-customize-parameters ()
8387   "Customize the group parameters of the current group."
8388   (interactive)
8389   (gnus-group-customize gnus-newsgroup-name))
8390
8391 (defun gnus-summary-enter-digest-group (&optional force)
8392   "Enter an nndoc group based on the current article.
8393 If FORCE, force a digest interpretation.  If not, try
8394 to guess what the document format is."
8395   (interactive "P")
8396   (let ((conf gnus-current-window-configuration))
8397     (save-window-excursion
8398       (save-excursion
8399         (let (gnus-article-prepare-hook
8400               gnus-display-mime-function
8401               gnus-break-pages)
8402           (gnus-summary-select-article))))
8403     (setq gnus-current-window-configuration conf)
8404     (let* ((name (format "%s-%d"
8405                          (gnus-group-prefixed-name
8406                           gnus-newsgroup-name (list 'nndoc ""))
8407                          (with-current-buffer gnus-summary-buffer
8408                            gnus-current-article)))
8409            (ogroup gnus-newsgroup-name)
8410            (params (append (gnus-info-params (gnus-get-info ogroup))
8411                            (list (cons 'to-group ogroup))
8412                            (list (cons 'parent-group ogroup))
8413                            (list (cons 'save-article-group ogroup))))
8414            (case-fold-search t)
8415            (buf (current-buffer))
8416            dig to-address)
8417       (save-excursion
8418         (set-buffer gnus-original-article-buffer)
8419         ;; Have the digest group inherit the main mail address of
8420         ;; the parent article.
8421         (when (setq to-address (or (gnus-fetch-field "reply-to")
8422                                    (gnus-fetch-field "from")))
8423           (setq params (append
8424                         (list (cons 'to-address
8425                                     (funcall gnus-decode-encoded-word-function
8426                                              to-address))))))
8427         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8428         (insert-buffer-substring gnus-original-article-buffer)
8429         ;; Remove lines that may lead nndoc to misinterpret the
8430         ;; document type.
8431         (narrow-to-region
8432          (goto-char (point-min))
8433          (or (search-forward "\n\n" nil t) (point)))
8434         (goto-char (point-min))
8435         (delete-matching-lines "^Path:\\|^From ")
8436         (widen))
8437       (unwind-protect
8438           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8439                     (gnus-newsgroup-ephemeral-ignored-charsets
8440                      gnus-newsgroup-ignored-charsets))
8441                 (gnus-group-read-ephemeral-group
8442                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8443                               (nndoc-article-type
8444                                ,(if force 'mbox 'guess)))
8445                  t nil nil nil
8446                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8447                                                         "ADAPT")))))
8448               ;; Make all postings to this group go to the parent group.
8449               (nconc (gnus-info-params (gnus-get-info name))
8450                      params)
8451             ;; Couldn't select this doc group.
8452             (switch-to-buffer buf)
8453             (gnus-set-global-variables)
8454             (gnus-configure-windows 'summary)
8455             (gnus-message 3 "Article couldn't be entered?"))
8456         (kill-buffer dig)))))
8457
8458 (defun gnus-summary-read-document (n)
8459   "Open a new group based on the current article(s).
8460 This will allow you to read digests and other similar
8461 documents as newsgroups.
8462 Obeys the standard process/prefix convention."
8463   (interactive "P")
8464   (let* ((ogroup gnus-newsgroup-name)
8465          (params (append (gnus-info-params (gnus-get-info ogroup))
8466                          (list (cons 'to-group ogroup))))
8467          group egroup groups vgroup)
8468     (dolist (article (gnus-summary-work-articles n))
8469       (setq group (format "%s-%d" gnus-newsgroup-name article))
8470       (gnus-summary-remove-process-mark article)
8471       (when (gnus-summary-display-article article)
8472         (save-excursion
8473           (with-temp-buffer
8474             (insert-buffer-substring gnus-original-article-buffer)
8475             ;; Remove some headers that may lead nndoc to make
8476             ;; the wrong guess.
8477             (message-narrow-to-head)
8478             (goto-char (point-min))
8479             (delete-matching-lines "^Path:\\|^From ")
8480             (widen)
8481             (if (setq egroup
8482                       (gnus-group-read-ephemeral-group
8483                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8484                                      (nndoc-article-type guess))
8485                        t nil t))
8486                 (progn
8487             ;; Make all postings to this group go to the parent group.
8488                   (nconc (gnus-info-params (gnus-get-info egroup))
8489                          params)
8490                   (push egroup groups))
8491               ;; Couldn't select this doc group.
8492               (gnus-error 3 "Article couldn't be entered"))))))
8493     ;; Now we have selected all the documents.
8494     (cond
8495      ((not groups)
8496       (error "None of the articles could be interpreted as documents"))
8497      ((gnus-group-read-ephemeral-group
8498        (setq vgroup (format
8499                      "nnvirtual:%s-%s" gnus-newsgroup-name
8500                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8501        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8502        t
8503        (cons (current-buffer) 'summary)))
8504      (t
8505       (error "Couldn't select virtual nndoc group")))))
8506
8507 (defun gnus-summary-isearch-article (&optional regexp-p)
8508   "Do incremental search forward on the current article.
8509 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8510   (interactive "P")
8511   (gnus-summary-select-article)
8512   (gnus-configure-windows 'article)
8513   (gnus-eval-in-buffer-window gnus-article-buffer
8514     (save-restriction
8515       (widen)
8516       (isearch-forward regexp-p))))
8517
8518 (defun gnus-summary-search-article-forward (regexp &optional backward)
8519   "Search for an article containing REGEXP forward.
8520 If BACKWARD, search backward instead."
8521   (interactive
8522    (list (read-string
8523           (format "Search article %s (regexp%s): "
8524                   (if current-prefix-arg "backward" "forward")
8525                   (if gnus-last-search-regexp
8526                       (concat ", default " gnus-last-search-regexp)
8527                     "")))
8528          current-prefix-arg))
8529   (if (string-equal regexp "")
8530       (setq regexp (or gnus-last-search-regexp ""))
8531     (setq gnus-last-search-regexp regexp)
8532     (setq gnus-article-before-search gnus-current-article))
8533   ;; Intentionally set gnus-last-article.
8534   (setq gnus-last-article gnus-article-before-search)
8535   (let ((gnus-last-article gnus-last-article))
8536     (if (gnus-summary-search-article regexp backward)
8537         (gnus-summary-show-thread)
8538       (signal 'search-failed (list regexp)))))
8539
8540 (defun gnus-summary-search-article-backward (regexp)
8541   "Search for an article containing REGEXP backward."
8542   (interactive
8543    (list (read-string
8544           (format "Search article backward (regexp%s): "
8545                   (if gnus-last-search-regexp
8546                       (concat ", default " gnus-last-search-regexp)
8547                     "")))))
8548   (gnus-summary-search-article-forward regexp 'backward))
8549
8550 (defun gnus-summary-search-article (regexp &optional backward)
8551   "Search for an article containing REGEXP.
8552 Optional argument BACKWARD means do search for backward.
8553 `gnus-select-article-hook' is not called during the search."
8554   ;; We have to require this here to make sure that the following
8555   ;; dynamic binding isn't shadowed by autoloading.
8556   (require 'gnus-async)
8557   (require 'gnus-art)
8558   (let ((gnus-select-article-hook nil)  ;Disable hook.
8559         (gnus-article-prepare-hook nil)
8560         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8561         (gnus-use-article-prefetch nil)
8562         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8563         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8564         (gnus-visual nil)
8565         (gnus-keep-backlog nil)
8566         (gnus-break-pages nil)
8567         (gnus-summary-display-arrow nil)
8568         (gnus-updated-mode-lines nil)
8569         (gnus-auto-center-summary nil)
8570         (sum (current-buffer))
8571         (gnus-display-mime-function nil)
8572         (found nil)
8573         point)
8574     (gnus-save-hidden-threads
8575       (gnus-summary-select-article)
8576       (set-buffer gnus-article-buffer)
8577       (goto-char (window-point (get-buffer-window (current-buffer))))
8578       (when backward
8579         (forward-line -1))
8580       (while (not found)
8581         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8582         (if (if backward
8583                 (re-search-backward regexp nil t)
8584               (re-search-forward regexp nil t))
8585             ;; We found the regexp.
8586             (progn
8587               (setq found 'found)
8588               (beginning-of-line)
8589               (set-window-start
8590                (get-buffer-window (current-buffer))
8591                (point))
8592               (forward-line 1)
8593               (set-window-point
8594                (get-buffer-window (current-buffer))
8595                (point))
8596               (set-buffer sum)
8597               (setq point (point)))
8598           ;; We didn't find it, so we go to the next article.
8599           (set-buffer sum)
8600           (setq found 'not)
8601           (while (eq found 'not)
8602             (if (not (if backward (gnus-summary-find-prev)
8603                        (gnus-summary-find-next)))
8604                 ;; No more articles.
8605                 (setq found t)
8606               ;; Select the next article and adjust point.
8607               (unless (gnus-summary-article-sparse-p
8608                        (gnus-summary-article-number))
8609                 (setq found nil)
8610                 (gnus-summary-select-article)
8611                 (set-buffer gnus-article-buffer)
8612                 (widen)
8613                 (goto-char (if backward (point-max) (point-min))))))))
8614       (gnus-message 7 ""))
8615     ;; Return whether we found the regexp.
8616     (when (eq found 'found)
8617       (goto-char point)
8618       (gnus-summary-show-thread)
8619       (gnus-summary-goto-subject gnus-current-article)
8620       (gnus-summary-position-point)
8621       t)))
8622
8623 (defun gnus-find-matching-articles (header regexp)
8624   "Return a list of all articles that match REGEXP on HEADER.
8625 This search includes all articles in the current group that Gnus has
8626 fetched headers for, whether they are displayed or not."
8627   (let ((articles nil)
8628         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8629         (case-fold-search t))
8630     (dolist (header gnus-newsgroup-headers)
8631       (when (string-match regexp (funcall func header))
8632         (push (mail-header-number header) articles)))
8633     (nreverse articles)))
8634
8635 (defun gnus-summary-find-matching (header regexp &optional backward unread
8636                                           not-case-fold not-matching)
8637   "Return a list of all articles that match REGEXP on HEADER.
8638 The search stars on the current article and goes forwards unless
8639 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8640 If UNREAD is non-nil, only unread articles will
8641 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8642 in the comparisons. If NOT-MATCHING, return a list of all articles that
8643 not match REGEXP on HEADER."
8644   (let ((case-fold-search (not not-case-fold))
8645         articles d func)
8646     (if (consp header)
8647         (if (eq (car header) 'extra)
8648             (setq func
8649                   `(lambda (h)
8650                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8651                          "")))
8652           (error "%s is an invalid header" header))
8653       (unless (fboundp (intern (concat "mail-header-" header)))
8654         (error "%s is not a valid header" header))
8655       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8656     (dolist (d (if (eq backward 'all)
8657                    gnus-newsgroup-data
8658                  (gnus-data-find-list
8659                   (gnus-summary-article-number)
8660                   (gnus-data-list backward))))
8661       (when (and (or (not unread)       ; We want all articles...
8662                      (gnus-data-unread-p d)) ; Or just unreads.
8663                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8664                  (if not-matching
8665                      (not (string-match
8666                            regexp
8667                            (funcall func (gnus-data-header d))))
8668                    (string-match regexp
8669                                  (funcall func (gnus-data-header d)))))
8670         (push (gnus-data-number d) articles))) ; Success!
8671     (nreverse articles)))
8672
8673 (defun gnus-summary-execute-command (header regexp command &optional backward)
8674   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8675 If HEADER is an empty string (or nil), the match is done on the entire
8676 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8677   (interactive
8678    (list (let ((completion-ignore-case t))
8679            (completing-read
8680             "Header name: "
8681             (mapcar (lambda (header) (list (format "%s" header)))
8682                     (append
8683                      '("Number" "Subject" "From" "Lines" "Date"
8684                        "Message-ID" "Xref" "References" "Body")
8685                      gnus-extra-headers))
8686             nil 'require-match))
8687          (read-string "Regexp: ")
8688          (read-key-sequence "Command: ")
8689          current-prefix-arg))
8690   (when (equal header "Body")
8691     (setq header ""))
8692   ;; Hidden thread subtrees must be searched as well.
8693   (gnus-summary-show-all-threads)
8694   ;; We don't want to change current point nor window configuration.
8695   (save-excursion
8696     (save-window-excursion
8697       (let (gnus-visual
8698             gnus-treat-strip-trailing-blank-lines
8699             gnus-treat-strip-leading-blank-lines
8700             gnus-treat-strip-multiple-blank-lines
8701             gnus-treat-hide-boring-headers
8702             gnus-treat-fold-newsgroups
8703             gnus-article-prepare-hook)
8704         (gnus-message 6 "Executing %s..." (key-description command))
8705         ;; We'd like to execute COMMAND interactively so as to give arguments.
8706         (gnus-execute header regexp
8707                       `(call-interactively ',(key-binding command))
8708                       backward)
8709         (gnus-message 6 "Executing %s...done" (key-description command))))))
8710
8711 (defun gnus-summary-beginning-of-article ()
8712   "Scroll the article back to the beginning."
8713   (interactive)
8714   (gnus-summary-select-article)
8715   (gnus-configure-windows 'article)
8716   (gnus-eval-in-buffer-window gnus-article-buffer
8717     (widen)
8718     (goto-char (point-min))
8719     (when gnus-break-pages
8720       (gnus-narrow-to-page))))
8721
8722 (defun gnus-summary-end-of-article ()
8723   "Scroll to the end of the article."
8724   (interactive)
8725   (gnus-summary-select-article)
8726   (gnus-configure-windows 'article)
8727   (gnus-eval-in-buffer-window gnus-article-buffer
8728     (widen)
8729     (goto-char (point-max))
8730     (recenter -3)
8731     (when gnus-break-pages
8732       (when (re-search-backward page-delimiter nil t)
8733         (narrow-to-region (match-end 0) (point-max)))
8734       (gnus-narrow-to-page))))
8735
8736 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8737   "Truncate to LEN and quote all \"(\"'s in STRING."
8738   (gnus-replace-in-string (if (and len (> (length string) len))
8739                               (substring string 0 len)
8740                             string)
8741                           "[()]" "\\\\\\&"))
8742
8743 (defun gnus-summary-print-article (&optional filename n)
8744   "Generate and print a PostScript image of the process-marked (mail) articles.
8745
8746 If used interactively, print the current article if none are
8747 process-marked.  With prefix arg, prompt the user for the name of the
8748 file to save in.
8749
8750 When used from Lisp, accept two optional args FILENAME and N.  N means
8751 to print the next N articles.  If N is negative, print the N previous
8752 articles.  If N is nil and articles have been marked with the process
8753 mark, print these instead.
8754
8755 If the optional first argument FILENAME is nil, send the image to the
8756 printer.  If FILENAME is a string, save the PostScript image in a file with
8757 that name.  If FILENAME is a number, prompt the user for the name of the file
8758 to save in."
8759   (interactive (list (ps-print-preprint current-prefix-arg)))
8760   (dolist (article (gnus-summary-work-articles n))
8761     (gnus-summary-select-article nil nil 'pseudo article)
8762     (gnus-eval-in-buffer-window gnus-article-buffer
8763       (gnus-print-buffer))
8764     (gnus-summary-remove-process-mark article))
8765   (ps-despool filename))
8766
8767 (defun gnus-print-buffer ()
8768   (let ((buffer (generate-new-buffer " *print*")))
8769     (unwind-protect
8770         (progn
8771           (copy-to-buffer buffer (point-min) (point-max))
8772           (set-buffer buffer)
8773           (gnus-remove-text-with-property 'gnus-decoration)
8774           (when (gnus-visual-p 'article-highlight 'highlight)
8775             ;; Copy-to-buffer doesn't copy overlay.  So redo
8776             ;; highlight.
8777             (let ((gnus-article-buffer buffer))
8778               (gnus-article-highlight-citation t)
8779               (gnus-article-highlight-signature)
8780               (gnus-article-emphasize)
8781               (gnus-article-delete-invisible-text)))
8782           (let ((ps-left-header
8783                  (list
8784                   (concat "("
8785                           (gnus-summary-print-truncate-and-quote
8786                            (mail-header-subject gnus-current-headers)
8787                            66) ")")
8788                   (concat "("
8789                           (gnus-summary-print-truncate-and-quote
8790                            (mail-header-from gnus-current-headers)
8791                            45) ")")))
8792                 (ps-right-header
8793                  (list
8794                   "/pagenumberstring load"
8795                   (concat "("
8796                           (mail-header-date gnus-current-headers) ")"))))
8797             (gnus-run-hooks 'gnus-ps-print-hook)
8798             (save-excursion
8799               (if window-system
8800                   (ps-spool-buffer-with-faces)
8801                 (ps-spool-buffer)))))
8802       (kill-buffer buffer))))
8803
8804 (defun gnus-summary-show-article (&optional arg)
8805   "Force redisplaying of the current article.
8806 If ARG (the prefix) is a number, show the article with the charset
8807 defined in `gnus-summary-show-article-charset-alist', or the charset
8808 input.
8809 If ARG (the prefix) is non-nil and not a number, show the raw article
8810 without any article massaging functions being run.  Normally, the key
8811 strokes are `C-u g'."
8812   (interactive "P")
8813   (cond
8814    ((numberp arg)
8815     (gnus-summary-show-article t)
8816     (let ((gnus-newsgroup-charset
8817            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8818                (mm-read-coding-system
8819                 "View as charset: " ;; actually it is coding system.
8820                 (with-current-buffer gnus-article-buffer
8821                   (mm-detect-coding-region (point) (point-max))))))
8822           (gnus-newsgroup-ignored-charsets 'gnus-all))
8823       (gnus-summary-select-article nil 'force)
8824       (let ((deps gnus-newsgroup-dependencies)
8825             head header lines)
8826         (save-excursion
8827           (set-buffer gnus-original-article-buffer)
8828           (save-restriction
8829             (message-narrow-to-head)
8830             (setq head (buffer-string))
8831             (goto-char (point-min))
8832             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8833               (goto-char (point-max))
8834               (widen)
8835               (setq lines (1- (count-lines (point) (point-max))))))
8836           (with-temp-buffer
8837             (insert (format "211 %d Article retrieved.\n"
8838                             (cdr gnus-article-current)))
8839             (insert head)
8840             (if lines (insert (format "Lines: %d\n" lines)))
8841             (insert ".\n")
8842             (let ((nntp-server-buffer (current-buffer)))
8843               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8844         (gnus-data-set-header
8845          (gnus-data-find (cdr gnus-article-current))
8846          header)
8847         (gnus-summary-update-article-line
8848          (cdr gnus-article-current) header)
8849         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8850           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8851    ((not arg)
8852     ;; Select the article the normal way.
8853     (gnus-summary-select-article nil 'force))
8854    (t
8855     ;; We have to require this here to make sure that the following
8856     ;; dynamic binding isn't shadowed by autoloading.
8857     (require 'gnus-async)
8858     (require 'gnus-art)
8859     ;; Bind the article treatment functions to nil.
8860     (let ((gnus-have-all-headers t)
8861           gnus-article-prepare-hook
8862           gnus-article-decode-hook
8863           gnus-display-mime-function
8864           gnus-break-pages)
8865       ;; Destroy any MIME parts.
8866       (when (gnus-buffer-live-p gnus-article-buffer)
8867         (save-excursion
8868           (set-buffer gnus-article-buffer)
8869           (mm-destroy-parts gnus-article-mime-handles)
8870           ;; Set it to nil for safety reason.
8871           (setq gnus-article-mime-handle-alist nil)
8872           (setq gnus-article-mime-handles nil)))
8873       (gnus-summary-select-article nil 'force))))
8874   (gnus-summary-goto-subject gnus-current-article)
8875   (gnus-summary-position-point))
8876
8877 (defun gnus-summary-show-raw-article ()
8878   "Show the raw article without any article massaging functions being run."
8879   (interactive)
8880   (gnus-summary-show-article t))
8881
8882 (defun gnus-summary-verbose-headers (&optional arg)
8883   "Toggle permanent full header display.
8884 If ARG is a positive number, turn header display on.
8885 If ARG is a negative number, turn header display off."
8886   (interactive "P")
8887   (setq gnus-show-all-headers
8888         (cond ((or (not (numberp arg))
8889                    (zerop arg))
8890                (not gnus-show-all-headers))
8891               ((natnump arg)
8892                t)))
8893   (gnus-summary-show-article))
8894
8895 (defun gnus-summary-toggle-header (&optional arg)
8896   "Show the headers if they are hidden, or hide them if they are shown.
8897 If ARG is a positive number, show the entire header.
8898 If ARG is a negative number, hide the unwanted header lines."
8899   (interactive "P")
8900   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8901                      (get-buffer-window gnus-article-buffer t))))
8902     (with-current-buffer gnus-article-buffer
8903       (widen)
8904       (article-narrow-to-head)
8905       (let* ((buffer-read-only nil)
8906              (inhibit-point-motion-hooks t)
8907              (hidden (if (numberp arg)
8908                          (>= arg 0)
8909                        (or (not (looking-at "[^ \t\n]+:"))
8910                            (gnus-article-hidden-text-p 'headers))))
8911              s e)
8912         (delete-region (point-min) (point-max))
8913         (with-current-buffer gnus-original-article-buffer
8914           (goto-char (setq s (point-min)))
8915           (setq e (if (search-forward "\n\n" nil t)
8916                       (1- (point))
8917                     (point-max))))
8918         (insert-buffer-substring gnus-original-article-buffer s e)
8919         (run-hooks 'gnus-article-decode-hook)
8920         (if hidden
8921             (let ((gnus-treat-hide-headers nil)
8922                   (gnus-treat-hide-boring-headers nil))
8923               (gnus-delete-wash-type 'headers)
8924               (gnus-treat-article 'head))
8925           (gnus-treat-article 'head))
8926         (widen)
8927         (if window
8928             (set-window-start window (goto-char (point-min))))
8929         (if gnus-break-pages
8930             (gnus-narrow-to-page)
8931           (when (gnus-visual-p 'page-marker)
8932             (let ((buffer-read-only nil))
8933               (gnus-remove-text-with-property 'gnus-prev)
8934               (gnus-remove-text-with-property 'gnus-next))))
8935         (gnus-set-mode-line 'article)))))
8936
8937 (defun gnus-summary-show-all-headers ()
8938   "Make all header lines visible."
8939   (interactive)
8940   (gnus-summary-toggle-header 1))
8941
8942 (defun gnus-summary-caesar-message (&optional arg)
8943   "Caesar rotate the current article by 13.
8944 The numerical prefix specifies how many places to rotate each letter
8945 forward."
8946   (interactive "P")
8947   (gnus-summary-select-article)
8948   (let ((mail-header-separator ""))
8949     (gnus-eval-in-buffer-window gnus-article-buffer
8950       (save-restriction
8951         (widen)
8952         (let ((start (window-start))
8953               buffer-read-only)
8954           (message-caesar-buffer-body arg)
8955           (set-window-start (get-buffer-window (current-buffer)) start))))))
8956
8957 (defun gnus-summary-idna-message (&optional arg)
8958   "Decode IDNA encoded domain names in the current articles.
8959 IDNA encoded domain names looks like `xn--bar'.  If a string
8960 remain unencoded after running this function, it is likely an
8961 invalid IDNA string (`xn--bar' is invalid)."
8962   (interactive "P")
8963   (gnus-summary-select-article)
8964   (let ((mail-header-separator ""))
8965     (gnus-eval-in-buffer-window gnus-article-buffer
8966       (save-restriction
8967         (widen)
8968         (let ((start (window-start))
8969               buffer-read-only)
8970           (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
8971             (replace-match (idna-to-unicode (match-string 1))))
8972           (set-window-start (get-buffer-window (current-buffer)) start))))))
8973
8974 (autoload 'unmorse-region "morse"
8975   "Convert morse coded text in region to ordinary ASCII text."
8976   t)
8977
8978 (defun gnus-summary-morse-message (&optional arg)
8979   "Morse decode the current article."
8980   (interactive "P")
8981   (gnus-summary-select-article)
8982   (let ((mail-header-separator ""))
8983     (gnus-eval-in-buffer-window gnus-article-buffer
8984       (save-excursion
8985         (save-restriction
8986           (widen)
8987           (let ((pos (window-start))
8988                 buffer-read-only)
8989             (goto-char (point-min))
8990             (when (message-goto-body)
8991               (gnus-narrow-to-body))
8992             (goto-char (point-min))
8993             (while (search-forward "·" (point-max) t)
8994               (replace-match "."))
8995             (unmorse-region (point-min) (point-max))
8996             (widen)
8997             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8998
8999 (defun gnus-summary-stop-page-breaking ()
9000   "Stop page breaking in the current article."
9001   (interactive)
9002   (gnus-summary-select-article)
9003   (gnus-eval-in-buffer-window gnus-article-buffer
9004     (widen)
9005     (when (gnus-visual-p 'page-marker)
9006       (let ((buffer-read-only nil))
9007         (gnus-remove-text-with-property 'gnus-prev)
9008         (gnus-remove-text-with-property 'gnus-next))
9009       (setq gnus-page-broken nil))))
9010
9011 (defun gnus-summary-move-article (&optional n to-newsgroup
9012                                             select-method action)
9013   "Move the current article to a different newsgroup.
9014 If N is a positive number, move the N next articles.
9015 If N is a negative number, move the N previous articles.
9016 If N is nil and any articles have been marked with the process mark,
9017 move those articles instead.
9018 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9019 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9020 re-spool using this method.
9021
9022 When called interactively with TO-NEWSGROUP being nil, the value of
9023 the variable `gnus-move-split-methods' is used for finding a default
9024 for the target newsgroup.
9025
9026 For this function to work, both the current newsgroup and the
9027 newsgroup that you want to move to have to support the `request-move'
9028 and `request-accept' functions.
9029
9030 ACTION can be either `move' (the default), `crosspost' or `copy'."
9031   (interactive "P")
9032   (unless action
9033     (setq action 'move))
9034   ;; Check whether the source group supports the required functions.
9035   (cond ((and (eq action 'move)
9036               (not (gnus-check-backend-function
9037                     'request-move-article gnus-newsgroup-name)))
9038          (error "The current group does not support article moving"))
9039         ((and (eq action 'crosspost)
9040               (not (gnus-check-backend-function
9041                     'request-replace-article gnus-newsgroup-name)))
9042          (error "The current group does not support article editing")))
9043   (let ((articles (gnus-summary-work-articles n))
9044         (prefix (if (gnus-check-backend-function
9045                      'request-move-article gnus-newsgroup-name)
9046                     (funcall gnus-move-group-prefix-function
9047                              gnus-newsgroup-name)
9048                   ""))
9049         (names '((move "Move" "Moving")
9050                  (copy "Copy" "Copying")
9051                  (crosspost "Crosspost" "Crossposting")))
9052         (copy-buf (save-excursion
9053                     (nnheader-set-temp-buffer " *copy article*")))
9054         art-group to-method new-xref article to-groups)
9055     (unless (assq action names)
9056       (error "Unknown action %s" action))
9057     ;; Read the newsgroup name.
9058     (when (and (not to-newsgroup)
9059                (not select-method))
9060       (if (and gnus-move-split-methods
9061                (not
9062                 (and (memq gnus-current-article articles)
9063                      (gnus-buffer-live-p gnus-original-article-buffer))))
9064           ;; When `gnus-move-split-methods' is non-nil, we have to
9065           ;; select an article to give `gnus-read-move-group-name' an
9066           ;; opportunity to suggest an appropriate default.  However,
9067           ;; we needn't render or mark the article.
9068           (let ((gnus-display-mime-function nil)
9069                 (gnus-article-prepare-hook nil)
9070                 (gnus-mark-article-hook nil))
9071             (gnus-summary-select-article nil nil nil (car articles))))
9072       (setq to-newsgroup
9073             (gnus-read-move-group-name
9074              (cadr (assq action names))
9075              (symbol-value (intern (format "gnus-current-%s-group" action)))
9076              articles prefix))
9077       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9078     (setq to-method (or select-method
9079                         (gnus-server-to-method
9080                          (gnus-group-method to-newsgroup))))
9081     ;; Check the method we are to move this article to...
9082     (unless (gnus-check-backend-function
9083              'request-accept-article (car to-method))
9084       (error "%s does not support article copying" (car to-method)))
9085     (unless (gnus-check-server to-method)
9086       (error "Can't open server %s" (car to-method)))
9087     (gnus-message 6 "%s to %s: %s..."
9088                   (caddr (assq action names))
9089                   (or (car select-method) to-newsgroup) articles)
9090     (while articles
9091       (setq article (pop articles))
9092       (setq
9093        art-group
9094        (cond
9095         ;; Move the article.
9096         ((eq action 'move)
9097          ;; Remove this article from future suppression.
9098          (gnus-dup-unsuppress-article article)
9099          (gnus-request-move-article
9100           article                       ; Article to move
9101           gnus-newsgroup-name           ; From newsgroup
9102           (nth 1 (gnus-find-method-for-group
9103                   gnus-newsgroup-name)) ; Server
9104           (list 'gnus-request-accept-article
9105                 to-newsgroup (list 'quote select-method)
9106                 (not articles) t)       ; Accept form
9107           (not articles)))              ; Only save nov last time
9108         ;; Copy the article.
9109         ((eq action 'copy)
9110          (save-excursion
9111            (set-buffer copy-buf)
9112            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9113              (save-restriction
9114                (nnheader-narrow-to-headers)
9115                (dolist (hdr gnus-copy-article-ignored-headers)
9116                  (message-remove-header hdr t)))
9117              (gnus-request-accept-article
9118               to-newsgroup select-method (not articles) t))))
9119         ;; Crosspost the article.
9120         ((eq action 'crosspost)
9121          (let ((xref (message-tokenize-header
9122                       (mail-header-xref (gnus-summary-article-header article))
9123                       " ")))
9124            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9125                                   ":" (number-to-string article)))
9126            (unless xref
9127              (setq xref (list (system-name))))
9128            (setq new-xref
9129                  (concat
9130                   (mapconcat 'identity
9131                              (delete "Xref:" (delete new-xref xref))
9132                              " ")
9133                   " " new-xref))
9134            (save-excursion
9135              (set-buffer copy-buf)
9136              ;; First put the article in the destination group.
9137              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9138              (when (consp (setq art-group
9139                                 (gnus-request-accept-article
9140                                  to-newsgroup select-method (not articles))))
9141                (setq new-xref (concat new-xref " " (car art-group)
9142                                       ":"
9143                                       (number-to-string (cdr art-group))))
9144                ;; Now we have the new Xrefs header, so we insert
9145                ;; it and replace the new article.
9146                (nnheader-replace-header "Xref" new-xref)
9147                (gnus-request-replace-article
9148                 (cdr art-group) to-newsgroup (current-buffer))
9149                art-group))))))
9150       (cond
9151        ((not art-group)
9152         (gnus-message 1 "Couldn't %s article %s: %s"
9153                       (cadr (assq action names)) article
9154                       (nnheader-get-report (car to-method))))
9155        ((eq art-group 'junk)
9156         (when (eq action 'move)
9157           (gnus-summary-mark-article article gnus-canceled-mark)
9158           (gnus-message 4 "Deleted article %s" article)
9159           ;; run the delete hook
9160           (run-hook-with-args 'gnus-summary-article-delete-hook
9161                               action
9162                               (gnus-data-header
9163                                (assoc article (gnus-data-list nil)))
9164                               gnus-newsgroup-name nil
9165                               select-method)))
9166        (t
9167         (let* ((pto-group (gnus-group-prefixed-name
9168                            (car art-group) to-method))
9169                (info (gnus-get-info pto-group))
9170                (to-group (gnus-info-group info))
9171                to-marks)
9172           ;; Update the group that has been moved to.
9173           (when (and info
9174                      (memq action '(move copy)))
9175             (unless (member to-group to-groups)
9176               (push to-group to-groups))
9177
9178             (unless (memq article gnus-newsgroup-unreads)
9179               (push 'read to-marks)
9180               (gnus-info-set-read
9181                info (gnus-add-to-range (gnus-info-read info)
9182                                        (list (cdr art-group)))))
9183
9184             ;; See whether the article is to be put in the cache.
9185             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9186                              gnus-article-mark-lists
9187                            (delete '(expirable . expire)
9188                                    (copy-sequence gnus-article-mark-lists))))
9189                   (to-article (cdr art-group)))
9190
9191               ;; Enter the article into the cache in the new group,
9192               ;; if that is required.
9193               (when gnus-use-cache
9194                 (gnus-cache-possibly-enter-article
9195                  to-group to-article
9196                  (memq article gnus-newsgroup-marked)
9197                  (memq article gnus-newsgroup-dormant)
9198                  (memq article gnus-newsgroup-unreads)))
9199
9200               (when gnus-preserve-marks
9201                 ;; Copy any marks over to the new group.
9202                 (when (and (equal to-group gnus-newsgroup-name)
9203                            (not (memq article gnus-newsgroup-unreads)))
9204                   ;; Mark this article as read in this group.
9205                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9206                   (setcdr (gnus-active to-group) to-article)
9207                   (setcdr gnus-newsgroup-active to-article))
9208
9209                 (while marks
9210                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9211                     (when (memq article (symbol-value
9212                                          (intern (format "gnus-newsgroup-%s"
9213                                                          (caar marks)))))
9214                       (push (cdar marks) to-marks)
9215                       ;; If the other group is the same as this group,
9216                       ;; then we have to add the mark to the list.
9217                       (when (equal to-group gnus-newsgroup-name)
9218                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9219                              (cons to-article
9220                                    (symbol-value
9221                                     (intern (format "gnus-newsgroup-%s"
9222                                                     (caar marks)))))))
9223                       ;; Copy the marks to other group.
9224                       (gnus-add-marked-articles
9225                        to-group (cdar marks) (list to-article) info)))
9226                   (setq marks (cdr marks)))
9227
9228                 (gnus-request-set-mark
9229                  to-group (list (list (list to-article) 'add to-marks))))
9230
9231               (gnus-dribble-enter
9232                (concat "(gnus-group-set-info '"
9233                        (gnus-prin1-to-string (gnus-get-info to-group))
9234                        ")"))))
9235
9236           ;; Update the Xref header in this article to point to
9237           ;; the new crossposted article we have just created.
9238           (when (eq action 'crosspost)
9239             (save-excursion
9240               (set-buffer copy-buf)
9241               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9242               (nnheader-replace-header "Xref" new-xref)
9243               (gnus-request-replace-article
9244                article gnus-newsgroup-name (current-buffer))))
9245
9246           ;; run the move/copy/crosspost/respool hook
9247           (run-hook-with-args 'gnus-summary-article-move-hook
9248                               action
9249                               (gnus-data-header
9250                                (assoc article (gnus-data-list nil)))
9251                               gnus-newsgroup-name
9252                               to-newsgroup
9253                               select-method))
9254
9255         ;;;!!!Why is this necessary?
9256         (set-buffer gnus-summary-buffer)
9257
9258         (gnus-summary-goto-subject article)
9259         (when (eq action 'move)
9260           (gnus-summary-mark-article article gnus-canceled-mark))))
9261       (gnus-summary-remove-process-mark article))
9262     ;; Re-activate all groups that have been moved to.
9263     (save-excursion
9264       (set-buffer gnus-group-buffer)
9265       (let ((gnus-group-marked to-groups))
9266         (gnus-group-get-new-news-this-group nil t)))
9267
9268     (gnus-kill-buffer copy-buf)
9269     (gnus-summary-position-point)
9270     (gnus-set-mode-line 'summary)))
9271
9272 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9273   "Copy the current article to some other group.
9274 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9275 When called interactively, if TO-NEWSGROUP is nil, use the value of
9276 the variable `gnus-move-split-methods' for finding a default target
9277 newsgroup.
9278 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9279 re-spool using this method."
9280   (interactive "P")
9281   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9282
9283 (defun gnus-summary-crosspost-article (&optional n)
9284   "Crosspost the current article to some other group."
9285   (interactive "P")
9286   (gnus-summary-move-article n nil nil 'crosspost))
9287
9288 (defcustom gnus-summary-respool-default-method nil
9289   "Default method type for respooling an article.
9290 If nil, use to the current newsgroup method."
9291   :type 'symbol
9292   :group 'gnus-summary-mail)
9293
9294 (defcustom gnus-summary-display-while-building nil
9295   "If non-nil, show and update the summary buffer as it's being built.
9296 If the value is t, update the buffer after every line is inserted.  If
9297 the value is an integer (N), update the display every N lines."
9298   :version "21.4"
9299   :group 'gnus-thread
9300   :type '(choice (const :tag "off" nil)
9301                  number
9302                  (const :tag "frequently" t)))
9303
9304 (defun gnus-summary-respool-article (&optional n method)
9305   "Respool the current article.
9306 The article will be squeezed through the mail spooling process again,
9307 which means that it will be put in some mail newsgroup or other
9308 depending on `nnmail-split-methods'.
9309 If N is a positive number, respool the N next articles.
9310 If N is a negative number, respool the N previous articles.
9311 If N is nil and any articles have been marked with the process mark,
9312 respool those articles instead.
9313
9314 Respooling can be done both from mail groups and \"real\" newsgroups.
9315 In the former case, the articles in question will be moved from the
9316 current group into whatever groups they are destined to.  In the
9317 latter case, they will be copied into the relevant groups."
9318   (interactive
9319    (list current-prefix-arg
9320          (let* ((methods (gnus-methods-using 'respool))
9321                 (methname
9322                  (symbol-name (or gnus-summary-respool-default-method
9323                                   (car (gnus-find-method-for-group
9324                                         gnus-newsgroup-name)))))
9325                 (method
9326                  (gnus-completing-read-with-default
9327                   methname "What backend do you want to use when respooling?"
9328                   methods nil t nil 'gnus-mail-method-history))
9329                 ms)
9330            (cond
9331             ((zerop (length (setq ms (gnus-servers-using-backend
9332                                       (intern method)))))
9333              (list (intern method) ""))
9334             ((= 1 (length ms))
9335              (car ms))
9336             (t
9337              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9338                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9339                            ms-alist))))))))
9340   (unless method
9341     (error "No method given for respooling"))
9342   (if (assoc (symbol-name
9343               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9344              (gnus-methods-using 'respool))
9345       (gnus-summary-move-article n nil method)
9346     (gnus-summary-copy-article n nil method)))
9347
9348 (defun gnus-summary-import-article (file &optional edit)
9349   "Import an arbitrary file into a mail newsgroup."
9350   (interactive "fImport file: \nP")
9351   (let ((group gnus-newsgroup-name)
9352         (now (current-time))
9353         atts lines group-art)
9354     (unless (gnus-check-backend-function 'request-accept-article group)
9355       (error "%s does not support article importing" group))
9356     (or (file-readable-p file)
9357         (not (file-regular-p file))
9358         (error "Can't read %s" file))
9359     (save-excursion
9360       (set-buffer (gnus-get-buffer-create " *import file*"))
9361       (erase-buffer)
9362       (nnheader-insert-file-contents file)
9363       (goto-char (point-min))
9364       (if (nnheader-article-p)
9365           (save-restriction
9366             (goto-char (point-min))
9367             (search-forward "\n\n" nil t)
9368             (narrow-to-region (point-min) (1- (point)))
9369             (goto-char (point-min))
9370             (unless (re-search-forward "^date:" nil t)
9371               (goto-char (point-max))
9372               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9373        ;; This doesn't look like an article, so we fudge some headers.
9374         (setq atts (file-attributes file)
9375               lines (count-lines (point-min) (point-max)))
9376         (insert "From: " (read-string "From: ") "\n"
9377                 "Subject: " (read-string "Subject: ") "\n"
9378                 "Date: " (message-make-date (nth 5 atts)) "\n"
9379                 "Message-ID: " (message-make-message-id) "\n"
9380                 "Lines: " (int-to-string lines) "\n"
9381                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9382       (setq group-art (gnus-request-accept-article group nil t))
9383       (kill-buffer (current-buffer)))
9384     (setq gnus-newsgroup-active (gnus-activate-group group))
9385     (forward-line 1)
9386     (gnus-summary-goto-article (cdr group-art) nil t)
9387     (when edit
9388       (gnus-summary-edit-article))))
9389
9390 (defun gnus-summary-create-article ()
9391   "Create an article in a mail newsgroup."
9392   (interactive)
9393   (let ((group gnus-newsgroup-name)
9394         (now (current-time))
9395         group-art)
9396     (unless (gnus-check-backend-function 'request-accept-article group)
9397       (error "%s does not support article importing" group))
9398     (save-excursion
9399       (set-buffer (gnus-get-buffer-create " *import file*"))
9400       (erase-buffer)
9401       (goto-char (point-min))
9402       ;; This doesn't look like an article, so we fudge some headers.
9403       (insert "From: " (read-string "From: ") "\n"
9404               "Subject: " (read-string "Subject: ") "\n"
9405               "Date: " (message-make-date now) "\n"
9406               "Message-ID: " (message-make-message-id) "\n")
9407       (setq group-art (gnus-request-accept-article group nil t))
9408       (kill-buffer (current-buffer)))
9409     (setq gnus-newsgroup-active (gnus-activate-group group))
9410     (forward-line 1)
9411     (gnus-summary-goto-article (cdr group-art) nil t)
9412     (gnus-summary-edit-article)))
9413
9414 (defun gnus-summary-article-posted-p ()
9415   "Say whether the current (mail) article is available from news as well.
9416 This will be the case if the article has both been mailed and posted."
9417   (interactive)
9418   (let ((id (mail-header-references (gnus-summary-article-header)))
9419         (gnus-override-method (car (gnus-refer-article-methods))))
9420     (if (gnus-request-head id "")
9421         (gnus-message 2 "The current message was found on %s"
9422                       gnus-override-method)
9423       (gnus-message 2 "The current message couldn't be found on %s"
9424                     gnus-override-method)
9425       nil)))
9426
9427 (defun gnus-summary-expire-articles (&optional now)
9428   "Expire all articles that are marked as expirable in the current group."
9429   (interactive)
9430   (when (and (not gnus-group-is-exiting-without-update-p)
9431              (gnus-check-backend-function
9432               'request-expire-articles gnus-newsgroup-name))
9433     ;; This backend supports expiry.
9434     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9435            (expirable (if total
9436                           (progn
9437                             ;; We need to update the info for
9438                             ;; this group for `gnus-list-of-read-articles'
9439                             ;; to give us the right answer.
9440                             (gnus-run-hooks 'gnus-exit-group-hook)
9441                             (gnus-summary-update-info)
9442                             (gnus-list-of-read-articles gnus-newsgroup-name))
9443                         (setq gnus-newsgroup-expirable
9444                               (sort gnus-newsgroup-expirable '<))))
9445            (expiry-wait (if now 'immediate
9446                           (gnus-group-find-parameter
9447                            gnus-newsgroup-name 'expiry-wait)))
9448            (nnmail-expiry-target
9449             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9450                 nnmail-expiry-target))
9451            es)
9452       (when expirable
9453         ;; There are expirable articles in this group, so we run them
9454         ;; through the expiry process.
9455         (gnus-message 6 "Expiring articles...")
9456         (unless (gnus-check-group gnus-newsgroup-name)
9457           (error "Can't open server for %s" gnus-newsgroup-name))
9458         ;; The list of articles that weren't expired is returned.
9459         (save-excursion
9460           (if expiry-wait
9461               (let ((nnmail-expiry-wait-function nil)
9462                     (nnmail-expiry-wait expiry-wait))
9463                 (setq es (gnus-request-expire-articles
9464                           expirable gnus-newsgroup-name)))
9465             (setq es (gnus-request-expire-articles
9466                       expirable gnus-newsgroup-name)))
9467           (unless total
9468             (setq gnus-newsgroup-expirable es))
9469           ;; We go through the old list of expirable, and mark all
9470           ;; really expired articles as nonexistent.
9471           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9472             (let ((gnus-use-cache nil))
9473               (dolist (article expirable)
9474                 (when (and (not (memq article es))
9475                            (gnus-data-find article))
9476                   (gnus-summary-mark-article article gnus-canceled-mark)
9477                   (run-hook-with-args 'gnus-summary-article-expire-hook
9478                                       'delete
9479                                       (gnus-data-header
9480                                        (assoc article (gnus-data-list nil)))
9481                                       gnus-newsgroup-name
9482                                       nil
9483                                       nil))))))
9484         (gnus-message 6 "Expiring articles...done")))))
9485
9486 (defun gnus-summary-expire-articles-now ()
9487   "Expunge all expirable articles in the current group.
9488 This means that *all* articles that are marked as expirable will be
9489 deleted forever, right now."
9490   (interactive)
9491   (or gnus-expert-user
9492       (gnus-yes-or-no-p
9493        "Are you really, really, really sure you want to delete all these messages? ")
9494       (error "Phew!"))
9495   (gnus-summary-expire-articles t))
9496
9497 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9498 (defun gnus-summary-delete-article (&optional n)
9499   "Delete the N next (mail) articles.
9500 This command actually deletes articles.  This is not a marking
9501 command.  The article will disappear forever from your life, never to
9502 return.
9503
9504 If N is negative, delete backwards.
9505 If N is nil and articles have been marked with the process mark,
9506 delete these instead.
9507
9508 If `gnus-novice-user' is non-nil you will be asked for
9509 confirmation before the articles are deleted."
9510   (interactive "P")
9511   (unless (gnus-check-backend-function 'request-expire-articles
9512                                        gnus-newsgroup-name)
9513     (error "The current newsgroup does not support article deletion"))
9514   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9515     (error "Couldn't open server"))
9516   ;; Compute the list of articles to delete.
9517   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9518         (nnmail-expiry-target 'delete)
9519         not-deleted)
9520     (if (and gnus-novice-user
9521              (not (gnus-yes-or-no-p
9522                    (format "Do you really want to delete %s forever? "
9523                            (if (> (length articles) 1)
9524                                (format "these %s articles" (length articles))
9525                              "this article")))))
9526         ()
9527       ;; Delete the articles.
9528       (setq not-deleted (gnus-request-expire-articles
9529                          articles gnus-newsgroup-name 'force))
9530       (while articles
9531         (gnus-summary-remove-process-mark (car articles))
9532         ;; The backend might not have been able to delete the article
9533         ;; after all.
9534         (unless (memq (car articles) not-deleted)
9535           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9536         (let* ((article (car articles))
9537                (ghead  (gnus-data-header
9538                                     (assoc article (gnus-data-list nil)))))
9539           (run-hook-with-args 'gnus-summary-article-delete-hook
9540                               'delete ghead gnus-newsgroup-name nil
9541                               nil))
9542         (setq articles (cdr articles)))
9543       (when not-deleted
9544         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9545     (gnus-summary-position-point)
9546     (gnus-set-mode-line 'summary)
9547     not-deleted))
9548
9549 (defun gnus-summary-edit-article (&optional arg)
9550   "Edit the current article.
9551 This will have permanent effect only in mail groups.
9552 If ARG is nil, edit the decoded articles.
9553 If ARG is 1, edit the raw articles.
9554 If ARG is 2, edit the raw articles even in read-only groups.
9555 If ARG is 3, edit the articles with the current handles.
9556 Otherwise, allow editing of articles even in read-only
9557 groups."
9558   (interactive "P")
9559   (let (force raw current-handles)
9560     (cond
9561      ((null arg))
9562      ((eq arg 1)
9563       (setq raw t))
9564      ((eq arg 2)
9565       (setq raw t
9566             force t))
9567      ((eq arg 3)
9568       (setq current-handles
9569             (and (gnus-buffer-live-p gnus-article-buffer)
9570                  (with-current-buffer gnus-article-buffer
9571                    (prog1
9572                        gnus-article-mime-handles
9573                      (setq gnus-article-mime-handles nil))))))
9574      (t
9575       (setq force t)))
9576     (when (and raw (not force)
9577                (member gnus-newsgroup-name '("nndraft:delayed"
9578                                              "nndraft:drafts"
9579                                              "nndraft:queue")))
9580       (error "Can't edit the raw article in group %s"
9581              gnus-newsgroup-name))
9582     (save-excursion
9583       (set-buffer gnus-summary-buffer)
9584       (let ((mail-parse-charset gnus-newsgroup-charset)
9585             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9586         (gnus-set-global-variables)
9587         (when (and (not force)
9588                    (gnus-group-read-only-p))
9589           (error "The current newsgroup does not support article editing"))
9590         (gnus-summary-show-article t)
9591         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9592           (with-current-buffer gnus-article-buffer
9593             (mm-enable-multibyte)))
9594         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9595             (setq raw t))
9596         (gnus-article-edit-article
9597          (if raw 'ignore
9598            `(lambda ()
9599               (let ((mbl mml-buffer-list))
9600                 (setq mml-buffer-list nil)
9601                 (mime-to-mml ,'current-handles)
9602                 (let ((mbl1 mml-buffer-list))
9603                   (setq mml-buffer-list mbl)
9604                   (set (make-local-variable 'mml-buffer-list) mbl1))
9605                 (gnus-make-local-hook 'kill-buffer-hook)
9606                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9607          `(lambda (no-highlight)
9608             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9609                   (message-options message-options)
9610                   (message-options-set-recipient)
9611                   (mail-parse-ignored-charsets
9612                    ',gnus-newsgroup-ignored-charsets))
9613               ,(if (not raw) '(progn
9614                                 (mml-to-mime)
9615                                 (mml-destroy-buffers)
9616                                 (remove-hook 'kill-buffer-hook
9617                                              'mml-destroy-buffers t)
9618                                 (kill-local-variable 'mml-buffer-list)))
9619               (gnus-summary-edit-article-done
9620                ,(or (mail-header-references gnus-current-headers) "")
9621                ,(gnus-group-read-only-p)
9622                ,gnus-summary-buffer no-highlight))))))))
9623
9624 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9625
9626 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9627                                                  no-highlight)
9628   "Make edits to the current article permanent."
9629   (interactive)
9630   (save-excursion
9631    ;; The buffer restriction contains the entire article if it exists.
9632     (when (article-goto-body)
9633       (let ((lines (count-lines (point) (point-max)))
9634             (length (- (point-max) (point)))
9635             (case-fold-search t)
9636             (body (copy-marker (point))))
9637         (goto-char (point-min))
9638         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9639           (delete-region (match-beginning 1) (match-end 1))
9640           (insert (number-to-string length)))
9641         (goto-char (point-min))
9642         (when (re-search-forward
9643                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9644           (delete-region (match-beginning 1) (match-end 1))
9645           (insert (number-to-string length)))
9646         (goto-char (point-min))
9647         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9648           (delete-region (match-beginning 1) (match-end 1))
9649           (insert (number-to-string lines))))))
9650   ;; Replace the article.
9651   (let ((buf (current-buffer)))
9652     (with-temp-buffer
9653       (insert-buffer-substring buf)
9654
9655       (if (and (not read-only)
9656                (not (gnus-request-replace-article
9657                      (cdr gnus-article-current) (car gnus-article-current)
9658                      (current-buffer) t)))
9659           (error "Couldn't replace article")
9660         ;; Update the summary buffer.
9661         (if (and references
9662                  (equal (message-tokenize-header references " ")
9663                         (message-tokenize-header
9664                          (or (message-fetch-field "references") "") " ")))
9665             ;; We only have to update this line.
9666             (save-excursion
9667               (save-restriction
9668                 (message-narrow-to-head)
9669                 (let ((head (buffer-string))
9670                       header)
9671                   (with-temp-buffer
9672                     (insert (format "211 %d Article retrieved.\n"
9673                                     (cdr gnus-article-current)))
9674                     (insert head)
9675                     (insert ".\n")
9676                     (let ((nntp-server-buffer (current-buffer)))
9677                       (setq header (car (gnus-get-newsgroup-headers
9678                                          nil t))))
9679                     (save-excursion
9680                       (set-buffer gnus-summary-buffer)
9681                       (gnus-data-set-header
9682                        (gnus-data-find (cdr gnus-article-current))
9683                        header)
9684                       (gnus-summary-update-article-line
9685                        (cdr gnus-article-current) header)
9686                       (if (gnus-summary-goto-subject
9687                            (cdr gnus-article-current) nil t)
9688                           (gnus-summary-update-secondary-mark
9689                            (cdr gnus-article-current))))))))
9690           ;; Update threads.
9691           (set-buffer (or buffer gnus-summary-buffer))
9692           (gnus-summary-update-article (cdr gnus-article-current))
9693           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9694               (gnus-summary-update-secondary-mark
9695                (cdr gnus-article-current))))
9696         ;; Prettify the article buffer again.
9697         (unless no-highlight
9698           (save-excursion
9699             (set-buffer gnus-article-buffer)
9700             ;;;!!! Fix this -- article should be rehighlighted.
9701             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9702             (set-buffer gnus-original-article-buffer)
9703             (gnus-request-article
9704              (cdr gnus-article-current)
9705              (car gnus-article-current) (current-buffer))))
9706         ;; Prettify the summary buffer line.
9707         (when (gnus-visual-p 'summary-highlight 'highlight)
9708           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9709
9710 (defun gnus-summary-edit-wash (key)
9711   "Perform editing command KEY in the article buffer."
9712   (interactive
9713    (list
9714     (progn
9715       (message "%s" (concat (this-command-keys) "- "))
9716       (read-char))))
9717   (message "")
9718   (gnus-summary-edit-article)
9719   (execute-kbd-macro (concat (this-command-keys) key))
9720   (gnus-article-edit-done))
9721
9722 ;;; Respooling
9723
9724 (defun gnus-summary-respool-query (&optional silent trace)
9725   "Query where the respool algorithm would put this article."
9726   (interactive)
9727   (let (gnus-mark-article-hook)
9728     (gnus-summary-select-article)
9729     (save-excursion
9730       (set-buffer gnus-original-article-buffer)
9731       (let ((groups (nnmail-article-group 'identity trace)))
9732         (unless silent
9733           (if groups
9734               (message "This message would go to %s"
9735                        (mapconcat 'car groups ", "))
9736             (message "This message would go to no groups"))
9737           groups)))))
9738
9739 (defun gnus-summary-respool-trace ()
9740   "Trace where the respool algorithm would put this article.
9741 Display a buffer showing all fancy splitting patterns which matched."
9742   (interactive)
9743   (gnus-summary-respool-query nil t))
9744
9745 ;; Summary marking commands.
9746
9747 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9748   "Mark articles which has the same subject as read, and then select the next.
9749 If UNMARK is positive, remove any kind of mark.
9750 If UNMARK is negative, tick articles."
9751   (interactive "P")
9752   (when unmark
9753     (setq unmark (prefix-numeric-value unmark)))
9754   (let ((count
9755          (gnus-summary-mark-same-subject
9756           (gnus-summary-article-subject) unmark)))
9757     ;; Select next unread article.  If auto-select-same mode, should
9758     ;; select the first unread article.
9759     (gnus-summary-next-article t (and gnus-auto-select-same
9760                                       (gnus-summary-article-subject)))
9761     (gnus-message 7 "%d article%s marked as %s"
9762                   count (if (= count 1) " is" "s are")
9763                   (if unmark "unread" "read"))))
9764
9765 (defun gnus-summary-kill-same-subject (&optional unmark)
9766   "Mark articles which has the same subject as read.
9767 If UNMARK is positive, remove any kind of mark.
9768 If UNMARK is negative, tick articles."
9769   (interactive "P")
9770   (when unmark
9771     (setq unmark (prefix-numeric-value unmark)))
9772   (let ((count
9773          (gnus-summary-mark-same-subject
9774           (gnus-summary-article-subject) unmark)))
9775     ;; If marked as read, go to next unread subject.
9776     (when (null unmark)
9777       ;; Go to next unread subject.
9778       (gnus-summary-next-subject 1 t))
9779     (gnus-message 7 "%d articles are marked as %s"
9780                   count (if unmark "unread" "read"))))
9781
9782 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9783   "Mark articles with same SUBJECT as read, and return marked number.
9784 If optional argument UNMARK is positive, remove any kinds of marks.
9785 If optional argument UNMARK is negative, mark articles as unread instead."
9786   (let ((count 1))
9787     (save-excursion
9788       (cond
9789        ((null unmark)                   ; Mark as read.
9790         (while (and
9791                 (progn
9792                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9793                   (gnus-summary-show-thread) t)
9794                 (gnus-summary-find-subject subject))
9795           (setq count (1+ count))))
9796        ((> unmark 0)                    ; Tick.
9797         (while (and
9798                 (progn
9799                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9800                   (gnus-summary-show-thread) t)
9801                 (gnus-summary-find-subject subject))
9802           (setq count (1+ count))))
9803        (t                               ; Mark as unread.
9804         (while (and
9805                 (progn
9806                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9807                   (gnus-summary-show-thread) t)
9808                 (gnus-summary-find-subject subject))
9809           (setq count (1+ count)))))
9810       (gnus-set-mode-line 'summary)
9811       ;; Return the number of marked articles.
9812       count)))
9813
9814 (defun gnus-summary-mark-as-processable (n &optional unmark)
9815   "Set the process mark on the next N articles.
9816 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9817 the process mark instead.  The difference between N and the actual
9818 number of articles marked is returned."
9819   (interactive "P")
9820   (if (and (null n) (gnus-region-active-p))
9821       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9822     (setq n (prefix-numeric-value n))
9823     (let ((backward (< n 0))
9824           (n (abs n)))
9825       (while (and
9826               (> n 0)
9827               (if unmark
9828                   (gnus-summary-remove-process-mark
9829                    (gnus-summary-article-number))
9830                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9831               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9832         (setq n (1- n)))
9833       (when (/= 0 n)
9834         (gnus-message 7 "No more articles"))
9835       (gnus-summary-recenter)
9836       (gnus-summary-position-point)
9837       n)))
9838
9839 (defun gnus-summary-unmark-as-processable (n)
9840   "Remove the process mark from the next N articles.
9841 If N is negative, unmark backward instead.  The difference between N and
9842 the actual number of articles unmarked is returned."
9843   (interactive "P")
9844   (gnus-summary-mark-as-processable n t))
9845
9846 (defun gnus-summary-unmark-all-processable ()
9847   "Remove the process mark from all articles."
9848   (interactive)
9849   (save-excursion
9850     (while gnus-newsgroup-processable
9851       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9852   (gnus-summary-position-point))
9853
9854 (defun gnus-summary-add-mark (article type)
9855   "Mark ARTICLE with a mark of TYPE."
9856   (let ((vtype (car (assq type gnus-article-mark-lists)))
9857         var)
9858     (if (not vtype)
9859         (error "No such mark type: %s" type)
9860       (setq var (intern (format "gnus-newsgroup-%s" type)))
9861       (set var (cons article (symbol-value var)))
9862       (if (memq type '(processable cached replied forwarded recent saved))
9863           (gnus-summary-update-secondary-mark article)
9864         ;;; !!! This is bogus.  We should find out what primary
9865         ;;; !!! mark we want to set.
9866         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9867
9868 (defun gnus-summary-mark-as-expirable (n)
9869   "Mark N articles forward as expirable.
9870 If N is negative, mark backward instead.  The difference between N and
9871 the actual number of articles marked is returned."
9872   (interactive "p")
9873   (gnus-summary-mark-forward n gnus-expirable-mark))
9874
9875 (defun gnus-summary-mark-as-spam (n)
9876   "Mark N articles forward as spam.
9877 If N is negative, mark backward instead.  The difference between N and
9878 the actual number of articles marked is returned."
9879   (interactive "p")
9880   (gnus-summary-mark-forward n gnus-spam-mark))
9881
9882 (defun gnus-summary-mark-article-as-replied (article)
9883   "Mark ARTICLE as replied to and update the summary line.
9884 ARTICLE can also be a list of articles."
9885   (interactive (list (gnus-summary-article-number)))
9886   (let ((articles (if (listp article) article (list article))))
9887     (dolist (article articles)
9888       (unless (numberp article)
9889         (error "%s is not a number" article))
9890       (push article gnus-newsgroup-replied)
9891       (let ((buffer-read-only nil))
9892         (when (gnus-summary-goto-subject article nil t)
9893           (gnus-summary-update-secondary-mark article))))))
9894
9895 (defun gnus-summary-mark-article-as-forwarded (article)
9896   "Mark ARTICLE as forwarded and update the summary line.
9897 ARTICLE can also be a list of articles."
9898   (let ((articles (if (listp article) article (list article))))
9899     (dolist (article articles)
9900       (push article gnus-newsgroup-forwarded)
9901       (let ((buffer-read-only nil))
9902         (when (gnus-summary-goto-subject article nil t)
9903           (gnus-summary-update-secondary-mark article))))))
9904
9905 (defun gnus-summary-set-bookmark (article)
9906   "Set a bookmark in current article."
9907   (interactive (list (gnus-summary-article-number)))
9908   (when (or (not (get-buffer gnus-article-buffer))
9909             (not gnus-current-article)
9910             (not gnus-article-current)
9911             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9912     (error "No current article selected"))
9913   ;; Remove old bookmark, if one exists.
9914   (gnus-pull article gnus-newsgroup-bookmarks)
9915   ;; Set the new bookmark, which is on the form
9916   ;; (article-number . line-number-in-body).
9917   (push
9918    (cons article
9919          (with-current-buffer gnus-article-buffer
9920            (count-lines
9921             (min (point)
9922                  (save-excursion
9923                    (article-goto-body)
9924                    (point)))
9925             (point))))
9926    gnus-newsgroup-bookmarks)
9927   (gnus-message 6 "A bookmark has been added to the current article."))
9928
9929 (defun gnus-summary-remove-bookmark (article)
9930   "Remove the bookmark from the current article."
9931   (interactive (list (gnus-summary-article-number)))
9932   ;; Remove old bookmark, if one exists.
9933   (if (not (assq article gnus-newsgroup-bookmarks))
9934       (gnus-message 6 "No bookmark in current article.")
9935     (gnus-pull article gnus-newsgroup-bookmarks)
9936     (gnus-message 6 "Removed bookmark.")))
9937
9938 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9939 (defun gnus-summary-mark-as-dormant (n)
9940   "Mark N articles forward as dormant.
9941 If N is negative, mark backward instead.  The difference between N and
9942 the actual number of articles marked is returned."
9943   (interactive "p")
9944   (gnus-summary-mark-forward n gnus-dormant-mark))
9945
9946 (defun gnus-summary-set-process-mark (article)
9947   "Set the process mark on ARTICLE and update the summary line."
9948   (setq gnus-newsgroup-processable
9949         (cons article
9950               (delq article gnus-newsgroup-processable)))
9951   (when (gnus-summary-goto-subject article)
9952     (gnus-summary-show-thread)
9953     (gnus-summary-goto-subject article)
9954     (gnus-summary-update-secondary-mark article)))
9955
9956 (defun gnus-summary-remove-process-mark (article)
9957   "Remove the process mark from ARTICLE and update the summary line."
9958   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9959   (when (gnus-summary-goto-subject article)
9960     (gnus-summary-show-thread)
9961     (gnus-summary-goto-subject article)
9962     (gnus-summary-update-secondary-mark article)))
9963
9964 (defun gnus-summary-set-saved-mark (article)
9965   "Set the process mark on ARTICLE and update the summary line."
9966   (push article gnus-newsgroup-saved)
9967   (when (gnus-summary-goto-subject article)
9968     (gnus-summary-update-secondary-mark article)))
9969
9970 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9971   "Mark N articles as read forwards.
9972 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9973 The difference between N and the actual number of articles marked is
9974 returned.
9975 If NO-EXPIRE, auto-expiry will be inhibited."
9976   (interactive "p")
9977   (gnus-summary-show-thread)
9978   (let ((backward (< n 0))
9979         (gnus-summary-goto-unread
9980          (and gnus-summary-goto-unread
9981               (not (eq gnus-summary-goto-unread 'never))
9982               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9983                                     gnus-ticked-mark gnus-dormant-mark)))))
9984         (n (abs n))
9985         (mark (or mark gnus-del-mark)))
9986     (while (and (> n 0)
9987                 (gnus-summary-mark-article nil mark no-expire)
9988                 (zerop (gnus-summary-next-subject
9989                         (if backward -1 1)
9990                         (and gnus-summary-goto-unread
9991                              (not (eq gnus-summary-goto-unread 'never)))
9992                         t)))
9993       (setq n (1- n)))
9994     (when (/= 0 n)
9995       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9996     (gnus-summary-recenter)
9997     (gnus-summary-position-point)
9998     (gnus-set-mode-line 'summary)
9999     n))
10000
10001 (defun gnus-summary-mark-article-as-read (mark)
10002   "Mark the current article quickly as read with MARK."
10003   (let ((article (gnus-summary-article-number)))
10004     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10005     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10006     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10007     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10008     (push (cons article mark) gnus-newsgroup-reads)
10009     ;; Possibly remove from cache, if that is used.
10010     (when gnus-use-cache
10011       (gnus-cache-enter-remove-article article))
10012     ;; Allow the backend to change the mark.
10013     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10014     ;; Check for auto-expiry.
10015     (when (and gnus-newsgroup-auto-expire
10016                (memq mark gnus-auto-expirable-marks))
10017       (setq mark gnus-expirable-mark)
10018       ;; Let the backend know about the mark change.
10019       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10020       (push article gnus-newsgroup-expirable))
10021     ;; Set the mark in the buffer.
10022     (gnus-summary-update-mark mark 'unread)
10023     t))
10024
10025 (defun gnus-summary-mark-article-as-unread (mark)
10026   "Mark the current article quickly as unread with MARK."
10027   (let* ((article (gnus-summary-article-number))
10028          (old-mark (gnus-summary-article-mark article)))
10029     ;; Allow the backend to change the mark.
10030     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10031     (if (eq mark old-mark)
10032         t
10033       (if (<= article 0)
10034           (progn
10035             (gnus-error 1 "Can't mark negative article numbers")
10036             nil)
10037         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10038         (setq gnus-newsgroup-spam-marked
10039               (delq article gnus-newsgroup-spam-marked))
10040         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10041         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10042         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10043         (cond ((= mark gnus-ticked-mark)
10044                (setq gnus-newsgroup-marked
10045                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10046                                               article)))
10047               ((= mark gnus-spam-mark)
10048                (setq gnus-newsgroup-spam-marked
10049                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10050                                               article)))
10051               ((= mark gnus-dormant-mark)
10052                (setq gnus-newsgroup-dormant
10053                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10054                                               article)))
10055               (t
10056                (setq gnus-newsgroup-unreads
10057                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10058                                               article))))
10059         (gnus-pull article gnus-newsgroup-reads)
10060
10061         ;; See whether the article is to be put in the cache.
10062         (and gnus-use-cache
10063              (vectorp (gnus-summary-article-header article))
10064              (save-excursion
10065                (gnus-cache-possibly-enter-article
10066                 gnus-newsgroup-name article
10067                 (= mark gnus-ticked-mark)
10068                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10069
10070         ;; Fix the mark.
10071         (gnus-summary-update-mark mark 'unread)
10072         t))))
10073
10074 (defun gnus-summary-mark-article (&optional article mark no-expire)
10075   "Mark ARTICLE with MARK.  MARK can be any character.
10076 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10077 `??' (dormant) and `?E' (expirable).
10078 If MARK is nil, then the default character `?r' is used.
10079 If ARTICLE is nil, then the article on the current line will be
10080 marked.
10081 If NO-EXPIRE, auto-expiry will be inhibited."
10082   ;; The mark might be a string.
10083   (when (stringp mark)
10084     (setq mark (aref mark 0)))
10085   ;; If no mark is given, then we check auto-expiring.
10086   (when (null mark)
10087     (setq mark gnus-del-mark))
10088   (when (and (not no-expire)
10089              gnus-newsgroup-auto-expire
10090              (memq mark gnus-auto-expirable-marks))
10091     (setq mark gnus-expirable-mark))
10092   (let ((article (or article (gnus-summary-article-number)))
10093         (old-mark (gnus-summary-article-mark article)))
10094     ;; Allow the backend to change the mark.
10095     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10096     (if (eq mark old-mark)
10097         t
10098       (unless article
10099         (error "No article on current line"))
10100       (if (not (if (or (= mark gnus-unread-mark)
10101                        (= mark gnus-ticked-mark)
10102                        (= mark gnus-spam-mark)
10103                        (= mark gnus-dormant-mark))
10104                    (gnus-mark-article-as-unread article mark)
10105                  (gnus-mark-article-as-read article mark)))
10106           t
10107         ;; See whether the article is to be put in the cache.
10108         (and gnus-use-cache
10109              (not (= mark gnus-canceled-mark))
10110              (vectorp (gnus-summary-article-header article))
10111              (save-excursion
10112                (gnus-cache-possibly-enter-article
10113                 gnus-newsgroup-name article
10114                 (= mark gnus-ticked-mark)
10115                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10116
10117         (when (gnus-summary-goto-subject article nil t)
10118           (let ((buffer-read-only nil))
10119             (gnus-summary-show-thread)
10120             ;; Fix the mark.
10121             (gnus-summary-update-mark mark 'unread)
10122             t))))))
10123
10124 (defun gnus-summary-update-secondary-mark (article)
10125   "Update the secondary (read, process, cache) mark."
10126   (gnus-summary-update-mark
10127    (cond ((memq article gnus-newsgroup-processable)
10128           gnus-process-mark)
10129          ((memq article gnus-newsgroup-cached)
10130           gnus-cached-mark)
10131          ((memq article gnus-newsgroup-replied)
10132           gnus-replied-mark)
10133          ((memq article gnus-newsgroup-forwarded)
10134           gnus-forwarded-mark)
10135          ((memq article gnus-newsgroup-saved)
10136           gnus-saved-mark)
10137          ((memq article gnus-newsgroup-recent)
10138           gnus-recent-mark)
10139          ((memq article gnus-newsgroup-unseen)
10140           gnus-unseen-mark)
10141          (t gnus-no-mark))
10142    'replied)
10143   (when (gnus-visual-p 'summary-highlight 'highlight)
10144     (gnus-run-hooks 'gnus-summary-update-hook))
10145   t)
10146
10147 (defun gnus-summary-update-download-mark (article)
10148   "Update the download mark."
10149   (gnus-summary-update-mark
10150    (cond ((memq article gnus-newsgroup-undownloaded)
10151           gnus-undownloaded-mark)
10152          (gnus-newsgroup-agentized
10153           gnus-downloaded-mark)
10154          (t
10155           gnus-no-mark))
10156    'download)
10157   (gnus-summary-update-line t)
10158   t)
10159
10160 (defun gnus-summary-update-mark (mark type)
10161   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10162         (buffer-read-only nil))
10163     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10164     (when forward
10165       (when (looking-at "\r")
10166         (incf forward))
10167       (when (<= (+ forward (point)) (point-max))
10168         ;; Go to the right position on the line.
10169         (goto-char (+ forward (point)))
10170         ;; Replace the old mark with the new mark.
10171         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10172         ;; Optionally update the marks by some user rule.
10173         (when (eq type 'unread)
10174           (gnus-data-set-mark
10175            (gnus-data-find (gnus-summary-article-number)) mark)
10176           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10177
10178 (defun gnus-mark-article-as-read (article &optional mark)
10179   "Enter ARTICLE in the pertinent lists and remove it from others."
10180   ;; Make the article expirable.
10181   (let ((mark (or mark gnus-del-mark)))
10182     (setq gnus-newsgroup-expirable
10183           (if (= mark gnus-expirable-mark)
10184               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10185             (delq article gnus-newsgroup-expirable)))
10186     ;; Remove from unread and marked lists.
10187     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10188     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10189     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10190     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10191     (push (cons article mark) gnus-newsgroup-reads)
10192     ;; Possibly remove from cache, if that is used.
10193     (when gnus-use-cache
10194       (gnus-cache-enter-remove-article article))
10195     t))
10196
10197 (defun gnus-mark-article-as-unread (article &optional mark)
10198   "Enter ARTICLE in the pertinent lists and remove it from others."
10199   (let ((mark (or mark gnus-ticked-mark)))
10200     (if (<= article 0)
10201         (progn
10202           (gnus-error 1 "Can't mark negative article numbers")
10203           nil)
10204       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10205             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10206             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10207             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10208             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10209
10210       ;; Unsuppress duplicates?
10211       (when gnus-suppress-duplicates
10212         (gnus-dup-unsuppress-article article))
10213
10214       (cond ((= mark gnus-ticked-mark)
10215              (setq gnus-newsgroup-marked
10216                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10217             ((= mark gnus-spam-mark)
10218              (setq gnus-newsgroup-spam-marked
10219                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10220                                             article)))
10221             ((= mark gnus-dormant-mark)
10222              (setq gnus-newsgroup-dormant
10223                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10224             (t
10225              (setq gnus-newsgroup-unreads
10226                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10227       (gnus-pull article gnus-newsgroup-reads)
10228       t)))
10229
10230 (defalias 'gnus-summary-mark-as-unread-forward
10231   'gnus-summary-tick-article-forward)
10232 (make-obsolete 'gnus-summary-mark-as-unread-forward
10233                'gnus-summary-tick-article-forward)
10234 (defun gnus-summary-tick-article-forward (n)
10235   "Tick N articles forwards.
10236 If N is negative, tick backwards instead.
10237 The difference between N and the number of articles ticked is returned."
10238   (interactive "p")
10239   (gnus-summary-mark-forward n gnus-ticked-mark))
10240
10241 (defalias 'gnus-summary-mark-as-unread-backward
10242   'gnus-summary-tick-article-backward)
10243 (make-obsolete 'gnus-summary-mark-as-unread-backward
10244                'gnus-summary-tick-article-backward)
10245 (defun gnus-summary-tick-article-backward (n)
10246   "Tick N articles backwards.
10247 The difference between N and the number of articles ticked is returned."
10248   (interactive "p")
10249   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10250
10251 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10252 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10253 (defun gnus-summary-tick-article (&optional article clear-mark)
10254   "Mark current article as unread.
10255 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10256 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10257   (interactive)
10258   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10259                                        gnus-ticked-mark)))
10260
10261 (defun gnus-summary-mark-as-read-forward (n)
10262   "Mark N articles as read forwards.
10263 If N is negative, mark backwards instead.
10264 The difference between N and the actual number of articles marked is
10265 returned."
10266   (interactive "p")
10267   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10268
10269 (defun gnus-summary-mark-as-read-backward (n)
10270   "Mark the N articles as read backwards.
10271 The difference between N and the actual number of articles marked is
10272 returned."
10273   (interactive "p")
10274   (gnus-summary-mark-forward
10275    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10276
10277 (defun gnus-summary-mark-as-read (&optional article mark)
10278   "Mark current article as read.
10279 ARTICLE specifies the article to be marked as read.
10280 MARK specifies a string to be inserted at the beginning of the line."
10281   (gnus-summary-mark-article article mark))
10282
10283 (defun gnus-summary-clear-mark-forward (n)
10284   "Clear marks from N articles forward.
10285 If N is negative, clear backward instead.
10286 The difference between N and the number of marks cleared is returned."
10287   (interactive "p")
10288   (gnus-summary-mark-forward n gnus-unread-mark))
10289
10290 (defun gnus-summary-clear-mark-backward (n)
10291   "Clear marks from N articles backward.
10292 The difference between N and the number of marks cleared is returned."
10293   (interactive "p")
10294   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10295
10296 (defun gnus-summary-mark-unread-as-read ()
10297   "Intended to be used by `gnus-summary-mark-article-hook'."
10298   (when (memq gnus-current-article gnus-newsgroup-unreads)
10299     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10300
10301 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10302   "Intended to be used by `gnus-summary-mark-article-hook'."
10303   (let ((mark (gnus-summary-article-mark)))
10304     (when (or (gnus-unread-mark-p mark)
10305               (gnus-read-mark-p mark))
10306       (gnus-summary-mark-article gnus-current-article
10307                                  (or new-mark gnus-read-mark)))))
10308
10309 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10310   "Intended to be used by `gnus-summary-mark-article-hook'."
10311   (let ((mark (gnus-summary-article-mark)))
10312     (when (or (gnus-unread-mark-p mark)
10313               (gnus-read-mark-p mark))
10314       (gnus-summary-mark-article (gnus-summary-article-number)
10315                                  (or new-mark gnus-read-mark)))))
10316
10317 (defun gnus-summary-mark-unread-as-ticked ()
10318   "Intended to be used by `gnus-summary-mark-article-hook'."
10319   (when (memq gnus-current-article gnus-newsgroup-unreads)
10320     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10321
10322 (defun gnus-summary-mark-region-as-read (point mark all)
10323   "Mark all unread articles between point and mark as read.
10324 If given a prefix, mark all articles between point and mark as read,
10325 even ticked and dormant ones."
10326   (interactive "r\nP")
10327   (save-excursion
10328     (let (article)
10329       (goto-char point)
10330       (beginning-of-line)
10331       (while (and
10332               (< (point) mark)
10333               (progn
10334                 (when (or all
10335                           (memq (setq article (gnus-summary-article-number))
10336                                 gnus-newsgroup-unreads))
10337                   (gnus-summary-mark-article article gnus-del-mark))
10338                 t)
10339               (gnus-summary-find-next))))))
10340
10341 (defun gnus-summary-mark-below (score mark)
10342   "Mark articles with score less than SCORE with MARK."
10343   (interactive "P\ncMark: ")
10344   (setq score (if score
10345                   (prefix-numeric-value score)
10346                 (or gnus-summary-default-score 0)))
10347   (save-excursion
10348     (set-buffer gnus-summary-buffer)
10349     (goto-char (point-min))
10350     (while
10351         (progn
10352           (and (< (gnus-summary-article-score) score)
10353                (gnus-summary-mark-article nil mark))
10354           (gnus-summary-find-next)))))
10355
10356 (defun gnus-summary-kill-below (&optional score)
10357   "Mark articles with score below SCORE as read."
10358   (interactive "P")
10359   (gnus-summary-mark-below score gnus-killed-mark))
10360
10361 (defun gnus-summary-clear-above (&optional score)
10362   "Clear all marks from articles with score above SCORE."
10363   (interactive "P")
10364   (gnus-summary-mark-above score gnus-unread-mark))
10365
10366 (defun gnus-summary-tick-above (&optional score)
10367   "Tick all articles with score above SCORE."
10368   (interactive "P")
10369   (gnus-summary-mark-above score gnus-ticked-mark))
10370
10371 (defun gnus-summary-mark-above (score mark)
10372   "Mark articles with score over SCORE with MARK."
10373   (interactive "P\ncMark: ")
10374   (setq score (if score
10375                   (prefix-numeric-value score)
10376                 (or gnus-summary-default-score 0)))
10377   (save-excursion
10378     (set-buffer gnus-summary-buffer)
10379     (goto-char (point-min))
10380     (while (and (progn
10381                   (when (> (gnus-summary-article-score) score)
10382                     (gnus-summary-mark-article nil mark))
10383                   t)
10384                 (gnus-summary-find-next)))))
10385
10386 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10387 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10388 (defun gnus-summary-limit-include-expunged (&optional no-error)
10389   "Display all the hidden articles that were expunged for low scores."
10390   (interactive)
10391   (let ((buffer-read-only nil))
10392     (let ((scored gnus-newsgroup-scored)
10393           headers h)
10394       (while scored
10395         (unless (gnus-summary-article-header (caar scored))
10396           (and (setq h (gnus-number-to-header (caar scored)))
10397                (< (cdar scored) gnus-summary-expunge-below)
10398                (push h headers)))
10399         (setq scored (cdr scored)))
10400       (if (not headers)
10401           (when (not no-error)
10402             (error "No expunged articles hidden"))
10403         (goto-char (point-min))
10404         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10405         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10406         (mapcar (lambda (x) (push (mail-header-number x)
10407                                   gnus-newsgroup-limit))
10408                 headers)
10409         (gnus-summary-prepare-unthreaded (nreverse headers))
10410         (goto-char (point-min))
10411         (gnus-summary-position-point)
10412         t))))
10413
10414 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10415   "Mark all unread articles in this newsgroup as read.
10416 If prefix argument ALL is non-nil, ticked and dormant articles will
10417 also be marked as read.
10418 If QUIETLY is non-nil, no questions will be asked.
10419
10420 If TO-HERE is non-nil, it should be a point in the buffer.  All
10421 articles before (after, if REVERSE is set) this point will be marked
10422 as read.
10423
10424 Note that this function will only catch up the unread article
10425 in the current summary buffer limitation.
10426
10427 The number of articles marked as read is returned."
10428   (interactive "P")
10429   (prog1
10430       (save-excursion
10431         (when (or quietly
10432                   (not gnus-interactive-catchup) ;Without confirmation?
10433                   gnus-expert-user
10434                   (gnus-y-or-n-p
10435                    (if all
10436                        "Mark absolutely all articles as read? "
10437                      "Mark all unread articles as read? ")))
10438           (if (and not-mark
10439                    (not gnus-newsgroup-adaptive)
10440                    (not gnus-newsgroup-auto-expire)
10441                    (not gnus-suppress-duplicates)
10442                    (or (not gnus-use-cache)
10443                        (eq gnus-use-cache 'passive)))
10444               (progn
10445                 (when all
10446                   (setq gnus-newsgroup-marked nil
10447                         gnus-newsgroup-spam-marked nil
10448                         gnus-newsgroup-dormant nil))
10449                 (setq gnus-newsgroup-unreads
10450                       (gnus-sorted-nunion
10451                        (gnus-intersection gnus-newsgroup-unreads
10452                                           gnus-newsgroup-downloadable)
10453                        gnus-newsgroup-unfetched)))
10454             ;; We actually mark all articles as canceled, which we
10455             ;; have to do when using auto-expiry or adaptive scoring.
10456             (gnus-summary-show-all-threads)
10457             (if (and to-here reverse)
10458                 (progn
10459                   (goto-char to-here)
10460                   (gnus-summary-mark-current-read-and-unread-as-read
10461                    gnus-catchup-mark)
10462                   (while (gnus-summary-find-next (not all))
10463                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10464               (when (gnus-summary-first-subject (not all))
10465                 (while (and
10466                         (if to-here (< (point) to-here) t)
10467                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10468                         (gnus-summary-find-next (not all))))))
10469             (gnus-set-mode-line 'summary))
10470           t))
10471     (gnus-summary-position-point)))
10472
10473 (defun gnus-summary-catchup-to-here (&optional all)
10474   "Mark all unticked articles before the current one as read.
10475 If ALL is non-nil, also mark ticked and dormant articles as read."
10476   (interactive "P")
10477   (save-excursion
10478     (gnus-save-hidden-threads
10479       (let ((beg (point)))
10480         ;; We check that there are unread articles.
10481         (when (or all (gnus-summary-find-prev))
10482           (gnus-summary-catchup all t beg)))))
10483   (gnus-summary-position-point))
10484
10485 (defun gnus-summary-catchup-from-here (&optional all)
10486   "Mark all unticked articles after (and including) the current one as read.
10487 If ALL is non-nil, also mark ticked and dormant articles as read."
10488   (interactive "P")
10489   (save-excursion
10490     (gnus-save-hidden-threads
10491       (let ((beg (point)))
10492         ;; We check that there are unread articles.
10493         (when (or all (gnus-summary-find-next))
10494           (gnus-summary-catchup all t beg nil t)))))
10495   (gnus-summary-position-point))
10496
10497 (defun gnus-summary-catchup-all (&optional quietly)
10498   "Mark all articles in this newsgroup as read.
10499 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10500 instead, which marks only unread articles as read."
10501   (interactive "P")
10502   (gnus-summary-catchup t quietly))
10503
10504 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10505   "Mark all unread articles in this group as read, then exit.
10506 If prefix argument ALL is non-nil, all articles are marked as read.
10507 If QUIETLY is non-nil, no questions will be asked."
10508   (interactive "P")
10509   (when (gnus-summary-catchup all quietly nil 'fast)
10510     ;; Select next newsgroup or exit.
10511     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10512              (eq gnus-auto-select-next 'quietly))
10513         (gnus-summary-next-group nil)
10514       (gnus-summary-exit))))
10515
10516 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10517   "Mark all articles in this newsgroup as read, and then exit.
10518 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10519 instead, which marks only unread articles as read."
10520   (interactive "P")
10521   (gnus-summary-catchup-and-exit t quietly))
10522
10523 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10524   "Mark all articles in this group as read and select the next group.
10525 If given a prefix, mark all articles, unread as well as ticked, as
10526 read."
10527   (interactive "P")
10528   (save-excursion
10529     (gnus-summary-catchup all))
10530   (gnus-summary-next-group))
10531
10532 ;;;
10533 ;;; with article
10534 ;;;
10535
10536 (defmacro gnus-with-article (article &rest forms)
10537   "Select ARTICLE and perform FORMS in the original article buffer.
10538 Then replace the article with the result."
10539   `(progn
10540      ;; We don't want the article to be marked as read.
10541      (let (gnus-mark-article-hook)
10542        (gnus-summary-select-article t t nil ,article))
10543      (set-buffer gnus-original-article-buffer)
10544      ,@forms
10545      (if (not (gnus-check-backend-function
10546                'request-replace-article (car gnus-article-current)))
10547          (gnus-message 5 "Read-only group; not replacing")
10548        (unless (gnus-request-replace-article
10549                 ,article (car gnus-article-current)
10550                 (current-buffer) t)
10551          (error "Couldn't replace article")))
10552      ;; The cache and backlog have to be flushed somewhat.
10553      (when gnus-keep-backlog
10554        (gnus-backlog-remove-article
10555         (car gnus-article-current) (cdr gnus-article-current)))
10556      (when gnus-use-cache
10557        (gnus-cache-update-article
10558         (car gnus-article-current) (cdr gnus-article-current)))))
10559
10560 (put 'gnus-with-article 'lisp-indent-function 1)
10561 (put 'gnus-with-article 'edebug-form-spec '(form body))
10562
10563 ;; Thread-based commands.
10564
10565 (defun gnus-summary-articles-in-thread (&optional article)
10566   "Return a list of all articles in the current thread.
10567 If ARTICLE is non-nil, return all articles in the thread that starts
10568 with that article."
10569   (let* ((article (or article (gnus-summary-article-number)))
10570          (data (gnus-data-find-list article))
10571          (top-level (gnus-data-level (car data)))
10572          (top-subject
10573           (cond ((null gnus-thread-operation-ignore-subject)
10574                  (gnus-simplify-subject-re
10575                   (mail-header-subject (gnus-data-header (car data)))))
10576                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10577                  (gnus-simplify-subject-fuzzy
10578                   (mail-header-subject (gnus-data-header (car data)))))
10579                 (t nil)))
10580          (end-point (save-excursion
10581                       (if (gnus-summary-go-to-next-thread)
10582                           (point) (point-max))))
10583          articles)
10584     (while (and data
10585                 (< (gnus-data-pos (car data)) end-point))
10586       (when (or (not top-subject)
10587                 (string= top-subject
10588                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10589                              (gnus-simplify-subject-fuzzy
10590                               (mail-header-subject
10591                                (gnus-data-header (car data))))
10592                            (gnus-simplify-subject-re
10593                             (mail-header-subject
10594                              (gnus-data-header (car data)))))))
10595         (push (gnus-data-number (car data)) articles))
10596       (unless (and (setq data (cdr data))
10597                    (> (gnus-data-level (car data)) top-level))
10598         (setq data nil)))
10599     ;; Return the list of articles.
10600     (nreverse articles)))
10601
10602 (defun gnus-summary-rethread-current ()
10603   "Rethread the thread the current article is part of."
10604   (interactive)
10605   (let* ((gnus-show-threads t)
10606          (article (gnus-summary-article-number))
10607          (id (mail-header-id (gnus-summary-article-header)))
10608          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10609     (unless id
10610       (error "No article on the current line"))
10611     (gnus-rebuild-thread id)
10612     (gnus-summary-goto-subject article)))
10613
10614 (defun gnus-summary-reparent-thread ()
10615   "Make the current article child of the marked (or previous) article.
10616
10617 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10618 is non-nil or the Subject: of both articles are the same."
10619   (interactive)
10620   (unless (not (gnus-group-read-only-p))
10621     (error "The current newsgroup does not support article editing"))
10622   (unless (<= (length gnus-newsgroup-processable) 1)
10623     (error "No more than one article may be marked"))
10624   (save-window-excursion
10625     (let ((gnus-article-buffer " *reparent*")
10626           (current-article (gnus-summary-article-number))
10627           ;; First grab the marked article, otherwise one line up.
10628           (parent-article (if (not (null gnus-newsgroup-processable))
10629                               (car gnus-newsgroup-processable)
10630                             (save-excursion
10631                               (if (eq (forward-line -1) 0)
10632                                   (gnus-summary-article-number)
10633                                 (error "Beginning of summary buffer"))))))
10634       (unless (not (eq current-article parent-article))
10635         (error "An article may not be self-referential"))
10636       (let ((message-id (mail-header-id
10637                          (gnus-summary-article-header parent-article))))
10638         (unless (and message-id (not (equal message-id "")))
10639           (error "No message-id in desired parent"))
10640         (gnus-with-article current-article
10641           (save-restriction
10642             (goto-char (point-min))
10643             (message-narrow-to-head)
10644             (if (re-search-forward "^References: " nil t)
10645                 (progn
10646                   (re-search-forward "^[^ \t]" nil t)
10647                   (forward-line -1)
10648                   (end-of-line)
10649                   (insert " " message-id))
10650               (insert "References: " message-id "\n"))))
10651         (set-buffer gnus-summary-buffer)
10652         (gnus-summary-unmark-all-processable)
10653         (gnus-summary-update-article current-article)
10654         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10655             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10656         (gnus-summary-rethread-current)
10657         (gnus-message 3 "Article %d is now the child of article %d"
10658                       current-article parent-article)))))
10659
10660 (defun gnus-summary-toggle-threads (&optional arg)
10661   "Toggle showing conversation threads.
10662 If ARG is positive number, turn showing conversation threads on."
10663   (interactive "P")
10664   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10665     (setq gnus-show-threads
10666           (if (null arg) (not gnus-show-threads)
10667             (> (prefix-numeric-value arg) 0)))
10668     (gnus-summary-prepare)
10669     (gnus-summary-goto-subject current)
10670     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10671     (gnus-summary-position-point)))
10672
10673 (defun gnus-summary-show-all-threads ()
10674   "Show all threads."
10675   (interactive)
10676   (save-excursion
10677     (let ((buffer-read-only nil))
10678       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10679   (gnus-summary-position-point))
10680
10681 (defun gnus-summary-show-thread ()
10682   "Show thread subtrees.
10683 Returns nil if no thread was there to be shown."
10684   (interactive)
10685   (let ((buffer-read-only nil)
10686         (orig (point))
10687         (end (point-at-eol))
10688         ;; Leave point at bol
10689         (beg (progn (beginning-of-line) (point))))
10690     (prog1
10691         ;; Any hidden lines here?
10692         (search-forward "\r" end t)
10693       (subst-char-in-region beg end ?\^M ?\n t)
10694       (goto-char orig)
10695       (gnus-summary-position-point))))
10696
10697 (defun gnus-summary-maybe-hide-threads ()
10698   "If requested, hide the threads that should be hidden."
10699   (when (and gnus-show-threads
10700              gnus-thread-hide-subtree)
10701     (gnus-summary-hide-all-threads
10702      (if (or (consp gnus-thread-hide-subtree)
10703              (functionp gnus-thread-hide-subtree))
10704          (gnus-make-predicate gnus-thread-hide-subtree)
10705        nil))))
10706
10707 ;;; Hiding predicates.
10708
10709 (defun gnus-article-unread-p (header)
10710   (memq (mail-header-number header) gnus-newsgroup-unreads))
10711
10712 (defun gnus-article-unseen-p (header)
10713   (memq (mail-header-number header) gnus-newsgroup-unseen))
10714
10715 (defun gnus-map-articles (predicate articles)
10716   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10717   (apply 'gnus-or (mapcar predicate
10718                           (mapcar 'gnus-summary-article-header articles))))
10719
10720 (defun gnus-summary-hide-all-threads (&optional predicate)
10721   "Hide all thread subtrees.
10722 If PREDICATE is supplied, threads that satisfy this predicate
10723 will not be hidden."
10724   (interactive)
10725   (save-excursion
10726     (goto-char (point-min))
10727     (let ((end nil))
10728       (while (not end)
10729         (when (or (not predicate)
10730                   (gnus-map-articles
10731                    predicate (gnus-summary-article-children)))
10732             (gnus-summary-hide-thread))
10733         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10734   (gnus-summary-position-point))
10735
10736 (defun gnus-summary-hide-thread ()
10737   "Hide thread subtrees.
10738 If PREDICATE is supplied, threads that satisfy this predicate
10739 will not be hidden.
10740 Returns nil if no threads were there to be hidden."
10741   (interactive)
10742   (let ((buffer-read-only nil)
10743         (start (point))
10744         (article (gnus-summary-article-number)))
10745     (goto-char start)
10746     ;; Go forward until either the buffer ends or the subthread
10747     ;; ends.
10748     (when (and (not (eobp))
10749                (or (zerop (gnus-summary-next-thread 1 t))
10750                    (goto-char (point-max))))
10751       (prog1
10752           (if (and (> (point) start)
10753                    (search-backward "\n" start t))
10754               (progn
10755                 (subst-char-in-region start (point) ?\n ?\^M)
10756                 (gnus-summary-goto-subject article))
10757             (goto-char start)
10758             nil)))))
10759
10760 (defun gnus-summary-go-to-next-thread (&optional previous)
10761   "Go to the same level (or less) next thread.
10762 If PREVIOUS is non-nil, go to previous thread instead.
10763 Return the article number moved to, or nil if moving was impossible."
10764   (let ((level (gnus-summary-thread-level))
10765         (way (if previous -1 1))
10766         (beg (point)))
10767     (forward-line way)
10768     (while (and (not (eobp))
10769                 (< level (gnus-summary-thread-level)))
10770       (forward-line way))
10771     (if (eobp)
10772         (progn
10773           (goto-char beg)
10774           nil)
10775       (setq beg (point))
10776       (prog1
10777           (gnus-summary-article-number)
10778         (goto-char beg)))))
10779
10780 (defun gnus-summary-next-thread (n &optional silent)
10781   "Go to the same level next N'th thread.
10782 If N is negative, search backward instead.
10783 Returns the difference between N and the number of skips actually
10784 done.
10785
10786 If SILENT, don't output messages."
10787   (interactive "p")
10788   (let ((backward (< n 0))
10789         (n (abs n)))
10790     (while (and (> n 0)
10791                 (gnus-summary-go-to-next-thread backward))
10792       (decf n))
10793     (unless silent
10794       (gnus-summary-position-point))
10795     (when (and (not silent) (/= 0 n))
10796       (gnus-message 7 "No more threads"))
10797     n))
10798
10799 (defun gnus-summary-prev-thread (n)
10800   "Go to the same level previous N'th thread.
10801 Returns the difference between N and the number of skips actually
10802 done."
10803   (interactive "p")
10804   (gnus-summary-next-thread (- n)))
10805
10806 (defun gnus-summary-go-down-thread ()
10807   "Go down one level in the current thread."
10808   (let ((children (gnus-summary-article-children)))
10809     (when children
10810       (gnus-summary-goto-subject (car children)))))
10811
10812 (defun gnus-summary-go-up-thread ()
10813   "Go up one level in the current thread."
10814   (let ((parent (gnus-summary-article-parent)))
10815     (when parent
10816       (gnus-summary-goto-subject parent))))
10817
10818 (defun gnus-summary-down-thread (n)
10819   "Go down thread N steps.
10820 If N is negative, go up instead.
10821 Returns the difference between N and how many steps down that were
10822 taken."
10823   (interactive "p")
10824   (let ((up (< n 0))
10825         (n (abs n)))
10826     (while (and (> n 0)
10827                 (if up (gnus-summary-go-up-thread)
10828                   (gnus-summary-go-down-thread)))
10829       (setq n (1- n)))
10830     (gnus-summary-position-point)
10831     (when (/= 0 n)
10832       (gnus-message 7 "Can't go further"))
10833     n))
10834
10835 (defun gnus-summary-up-thread (n)
10836   "Go up thread N steps.
10837 If N is negative, go down instead.
10838 Returns the difference between N and how many steps down that were
10839 taken."
10840   (interactive "p")
10841   (gnus-summary-down-thread (- n)))
10842
10843 (defun gnus-summary-top-thread ()
10844   "Go to the top of the thread."
10845   (interactive)
10846   (while (gnus-summary-go-up-thread))
10847   (gnus-summary-article-number))
10848
10849 (defun gnus-summary-kill-thread (&optional unmark)
10850   "Mark articles under current thread as read.
10851 If the prefix argument is positive, remove any kinds of marks.
10852 If the prefix argument is negative, tick articles instead."
10853   (interactive "P")
10854   (when unmark
10855     (setq unmark (prefix-numeric-value unmark)))
10856   (let ((articles (gnus-summary-articles-in-thread)))
10857     (save-excursion
10858       ;; Expand the thread.
10859       (gnus-summary-show-thread)
10860       ;; Mark all the articles.
10861       (while articles
10862         (gnus-summary-goto-subject (car articles))
10863         (cond ((null unmark)
10864                (gnus-summary-mark-article-as-read gnus-killed-mark))
10865               ((> unmark 0)
10866                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10867               (t
10868                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10869         (setq articles (cdr articles))))
10870     ;; Hide killed subtrees.
10871     (and (null unmark)
10872          gnus-thread-hide-killed
10873          (gnus-summary-hide-thread))
10874     ;; If marked as read, go to next unread subject.
10875     (when (null unmark)
10876       ;; Go to next unread subject.
10877       (gnus-summary-next-subject 1 t)))
10878   (gnus-set-mode-line 'summary))
10879
10880 ;; Summary sorting commands
10881
10882 (defun gnus-summary-sort-by-number (&optional reverse)
10883   "Sort the summary buffer by article number.
10884 Argument REVERSE means reverse order."
10885   (interactive "P")
10886   (gnus-summary-sort 'number reverse))
10887
10888 (defun gnus-summary-sort-by-random (&optional reverse)
10889   "Randomize the order in the summary buffer.
10890 Argument REVERSE means to randomize in reverse order."
10891   (interactive "P")
10892   (gnus-summary-sort 'random reverse))
10893
10894 (defun gnus-summary-sort-by-author (&optional reverse)
10895   "Sort the summary buffer by author name alphabetically.
10896 If `case-fold-search' is non-nil, case of letters is ignored.
10897 Argument REVERSE means reverse order."
10898   (interactive "P")
10899   (gnus-summary-sort 'author reverse))
10900
10901 (defun gnus-summary-sort-by-recipient (&optional reverse)
10902   "Sort the summary buffer by recipient name alphabetically.
10903 If `case-fold-search' is non-nil, case of letters is ignored.
10904 Argument REVERSE means reverse order."
10905   (interactive "P")
10906   (gnus-summary-sort 'recipient reverse))
10907
10908 (defun gnus-summary-sort-by-subject (&optional reverse)
10909   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10910 If `case-fold-search' is non-nil, case of letters is ignored.
10911 Argument REVERSE means reverse order."
10912   (interactive "P")
10913   (gnus-summary-sort 'subject reverse))
10914
10915 (defun gnus-summary-sort-by-date (&optional reverse)
10916   "Sort the summary buffer by date.
10917 Argument REVERSE means reverse order."
10918   (interactive "P")
10919   (gnus-summary-sort 'date reverse))
10920
10921 (defun gnus-summary-sort-by-score (&optional reverse)
10922   "Sort the summary buffer by score.
10923 Argument REVERSE means reverse order."
10924   (interactive "P")
10925   (gnus-summary-sort 'score reverse))
10926
10927 (defun gnus-summary-sort-by-lines (&optional reverse)
10928   "Sort the summary buffer by the number of lines.
10929 Argument REVERSE means reverse order."
10930   (interactive "P")
10931   (gnus-summary-sort 'lines reverse))
10932
10933 (defun gnus-summary-sort-by-chars (&optional reverse)
10934   "Sort the summary buffer by article length.
10935 Argument REVERSE means reverse order."
10936   (interactive "P")
10937   (gnus-summary-sort 'chars reverse))
10938
10939 (defun gnus-summary-sort-by-original (&optional reverse)
10940   "Sort the summary buffer using the default sorting method.
10941 Argument REVERSE means reverse order."
10942   (interactive "P")
10943   (let* ((buffer-read-only)
10944          (gnus-summary-prepare-hook nil))
10945     ;; We do the sorting by regenerating the threads.
10946     (gnus-summary-prepare)
10947     ;; Hide subthreads if needed.
10948     (gnus-summary-maybe-hide-threads)))
10949
10950 (defun gnus-summary-sort (predicate reverse)
10951   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10952   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10953          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10954          (gnus-thread-sort-functions
10955           (if (not reverse)
10956               thread
10957             `(lambda (t1 t2)
10958                (,thread t2 t1))))
10959          (gnus-sort-gathered-threads-function
10960           gnus-thread-sort-functions)
10961          (gnus-article-sort-functions
10962           (if (not reverse)
10963               article
10964             `(lambda (t1 t2)
10965                (,article t2 t1))))
10966          (buffer-read-only)
10967          (gnus-summary-prepare-hook nil))
10968     ;; We do the sorting by regenerating the threads.
10969     (gnus-summary-prepare)
10970     ;; Hide subthreads if needed.
10971     (gnus-summary-maybe-hide-threads)))
10972
10973 ;; Summary saving commands.
10974
10975 (defun gnus-summary-save-article (&optional n not-saved)
10976   "Save the current article using the default saver function.
10977 If N is a positive number, save the N next articles.
10978 If N is a negative number, save the N previous articles.
10979 If N is nil and any articles have been marked with the process mark,
10980 save those articles instead.
10981 The variable `gnus-default-article-saver' specifies the saver function."
10982   (interactive "P")
10983   (let* ((articles (gnus-summary-work-articles n))
10984          (save-buffer (save-excursion
10985                         (nnheader-set-temp-buffer " *Gnus Save*")))
10986          (num (length articles))
10987          header file)
10988     (dolist (article articles)
10989       (setq header (gnus-summary-article-header article))
10990       (if (not (vectorp header))
10991           ;; This is a pseudo-article.
10992           (if (assq 'name header)
10993               (gnus-copy-file (cdr (assq 'name header)))
10994             (gnus-message 1 "Article %d is unsaveable" article))
10995         ;; This is a real article.
10996         (save-window-excursion
10997           (let ((gnus-display-mime-function nil)
10998                 (gnus-article-prepare-hook nil))
10999             (gnus-summary-select-article t nil nil article)))
11000         (save-excursion
11001           (set-buffer save-buffer)
11002           (erase-buffer)
11003           (insert-buffer-substring gnus-original-article-buffer))
11004         (setq file (gnus-article-save save-buffer file num))
11005         (gnus-summary-remove-process-mark article)
11006         (unless not-saved
11007           (gnus-summary-set-saved-mark article))))
11008     (gnus-kill-buffer save-buffer)
11009     (gnus-summary-position-point)
11010     (gnus-set-mode-line 'summary)
11011     n))
11012
11013 (defun gnus-summary-pipe-output (&optional arg headers)
11014   "Pipe the current article to a subprocess.
11015 If N is a positive number, pipe the N next articles.
11016 If N is a negative number, pipe the N previous articles.
11017 If N is nil and any articles have been marked with the process mark,
11018 pipe those articles instead.
11019 If HEADERS (the symbolic prefix), include the headers, too."
11020   (interactive (gnus-interactive "P\ny"))
11021   (require 'gnus-art)
11022   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11023         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11024     (gnus-summary-save-article arg t))
11025   (let ((buffer (get-buffer "*Shell Command Output*")))
11026     (when (and buffer
11027                (not (zerop (buffer-size buffer))))
11028       (gnus-configure-windows 'pipe))))
11029
11030 (defun gnus-summary-save-article-mail (&optional arg)
11031   "Append the current article to an mail file.
11032 If N is a positive number, save the N next articles.
11033 If N is a negative number, save the N previous articles.
11034 If N is nil and any articles have been marked with the process mark,
11035 save those articles instead."
11036   (interactive "P")
11037   (require 'gnus-art)
11038   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11039     (gnus-summary-save-article arg)))
11040
11041 (defun gnus-summary-save-article-rmail (&optional arg)
11042   "Append the current article to an rmail file.
11043 If N is a positive number, save the N next articles.
11044 If N is a negative number, save the N previous articles.
11045 If N is nil and any articles have been marked with the process mark,
11046 save those articles instead."
11047   (interactive "P")
11048   (require 'gnus-art)
11049   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11050     (gnus-summary-save-article arg)))
11051
11052 (defun gnus-summary-save-article-file (&optional arg)
11053   "Append the current article to a file.
11054 If N is a positive number, save the N next articles.
11055 If N is a negative number, save the N previous articles.
11056 If N is nil and any articles have been marked with the process mark,
11057 save those articles instead."
11058   (interactive "P")
11059   (require 'gnus-art)
11060   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11061     (gnus-summary-save-article arg)))
11062
11063 (defun gnus-summary-write-article-file (&optional arg)
11064   "Write the current article to a file, deleting the previous file.
11065 If N is a positive number, save the N next articles.
11066 If N is a negative number, save the N previous articles.
11067 If N is nil and any articles have been marked with the process mark,
11068 save those articles instead."
11069   (interactive "P")
11070   (require 'gnus-art)
11071   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11072     (gnus-summary-save-article arg)))
11073
11074 (defun gnus-summary-save-article-body-file (&optional arg)
11075   "Append the current article body to a file.
11076 If N is a positive number, save the N next articles.
11077 If N is a negative number, save the N previous articles.
11078 If N is nil and any articles have been marked with the process mark,
11079 save those articles instead."
11080   (interactive "P")
11081   (require 'gnus-art)
11082   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11083     (gnus-summary-save-article arg)))
11084
11085 (defun gnus-summary-muttprint (&optional arg)
11086   "Print the current article using Muttprint.
11087 If N is a positive number, save the N next articles.
11088 If N is a negative number, save the N previous articles.
11089 If N is nil and any articles have been marked with the process mark,
11090 save those articles instead."
11091   (interactive "P")
11092   (require 'gnus-art)
11093   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11094     (gnus-summary-save-article arg t)))
11095
11096 (defun gnus-summary-pipe-message (program)
11097   "Pipe the current article through PROGRAM."
11098   (interactive "sProgram: ")
11099   (gnus-summary-select-article)
11100   (let ((mail-header-separator ""))
11101     (gnus-eval-in-buffer-window gnus-article-buffer
11102       (save-restriction
11103         (widen)
11104         (let ((start (window-start))
11105               buffer-read-only)
11106           (message-pipe-buffer-body program)
11107           (set-window-start (get-buffer-window (current-buffer)) start))))))
11108
11109 (defun gnus-get-split-value (methods)
11110   "Return a value based on the split METHODS."
11111   (let (split-name method result match)
11112     (when methods
11113       (save-excursion
11114         (set-buffer gnus-original-article-buffer)
11115         (save-restriction
11116           (nnheader-narrow-to-headers)
11117           (while (and methods (not split-name))
11118             (goto-char (point-min))
11119             (setq method (pop methods))
11120             (setq match (car method))
11121             (when (cond
11122                    ((stringp match)
11123                     ;; Regular expression.
11124                     (ignore-errors
11125                       (re-search-forward match nil t)))
11126                    ((functionp match)
11127                     ;; Function.
11128                     (save-restriction
11129                       (widen)
11130                       (setq result (funcall match gnus-newsgroup-name))))
11131                    ((consp match)
11132                     ;; Form.
11133                     (save-restriction
11134                       (widen)
11135                       (setq result (eval match)))))
11136               (setq split-name (cdr method))
11137               (cond ((stringp result)
11138                      (push (expand-file-name
11139                             result gnus-article-save-directory)
11140                            split-name))
11141                     ((consp result)
11142                      (setq split-name (append result split-name)))))))))
11143     (nreverse split-name)))
11144
11145 (defun gnus-valid-move-group-p (group)
11146   (and (boundp group)
11147        (symbol-name group)
11148        (symbol-value group)
11149        (gnus-get-function (gnus-find-method-for-group
11150                            (symbol-name group)) 'request-accept-article t)))
11151
11152 (defun gnus-read-move-group-name (prompt default articles prefix)
11153   "Read a group name."
11154   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11155          (minibuffer-confirm-incomplete nil) ; XEmacs
11156          (prom
11157           (format "%s %s to:"
11158                   prompt
11159                   (if (> (length articles) 1)
11160                       (format "these %d articles" (length articles))
11161                     "this article")))
11162          (to-newsgroup
11163           (cond
11164            ((null split-name)
11165             (gnus-completing-read-with-default
11166              default prom
11167              gnus-active-hashtb
11168              'gnus-valid-move-group-p
11169              nil prefix
11170              'gnus-group-history))
11171            ((= 1 (length split-name))
11172             (gnus-completing-read-with-default
11173              (car split-name) prom
11174              gnus-active-hashtb
11175              'gnus-valid-move-group-p
11176              nil nil
11177              'gnus-group-history))
11178            (t
11179             (gnus-completing-read-with-default
11180              nil prom
11181              (mapcar 'list (nreverse split-name))
11182              nil nil nil
11183              'gnus-group-history))))
11184          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11185     (when to-newsgroup
11186       (if (or (string= to-newsgroup "")
11187               (string= to-newsgroup prefix))
11188           (setq to-newsgroup default))
11189       (unless to-newsgroup
11190         (error "No group name entered"))
11191       (or (gnus-active to-newsgroup)
11192           (gnus-activate-group to-newsgroup nil nil to-method)
11193           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11194                                      to-newsgroup))
11195               (or (and (gnus-request-create-group to-newsgroup to-method)
11196                        (gnus-activate-group
11197                         to-newsgroup nil nil to-method)
11198                        (gnus-subscribe-group to-newsgroup))
11199                   (error "Couldn't create group %s" to-newsgroup)))
11200           (error "No such group: %s" to-newsgroup)))
11201     to-newsgroup))
11202
11203 (defun gnus-summary-save-parts (type dir n &optional reverse)
11204   "Save parts matching TYPE to DIR.
11205 If REVERSE, save parts that do not match TYPE."
11206   (interactive
11207    (list (read-string "Save parts of type: "
11208                       (or (car gnus-summary-save-parts-type-history)
11209                           gnus-summary-save-parts-default-mime)
11210                       'gnus-summary-save-parts-type-history)
11211          (setq gnus-summary-save-parts-last-directory
11212                (read-file-name "Save to directory: "
11213                                gnus-summary-save-parts-last-directory
11214                                nil t))
11215          current-prefix-arg))
11216   (gnus-summary-iterate n
11217     (let ((gnus-display-mime-function nil)
11218           (gnus-inhibit-treatment t))
11219       (gnus-summary-select-article))
11220     (save-excursion
11221       (set-buffer gnus-article-buffer)
11222       (let ((handles (or gnus-article-mime-handles
11223                          (mm-dissect-buffer nil gnus-article-loose-mime)
11224                          (and gnus-article-emulate-mime
11225                               (mm-uu-dissect)))))
11226         (when handles
11227           (gnus-summary-save-parts-1 type dir handles reverse)
11228           (unless gnus-article-mime-handles ;; Don't destroy this case.
11229             (mm-destroy-parts handles)))))))
11230
11231 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11232   (if (stringp (car handle))
11233       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11234               (cdr handle))
11235     (when (if reverse
11236               (not (string-match type (mm-handle-media-type handle)))
11237             (string-match type (mm-handle-media-type handle)))
11238       (let ((file (expand-file-name
11239                    (gnus-map-function
11240                     mm-file-name-rewrite-functions
11241                     (file-name-nondirectory
11242                      (or
11243                       (mail-content-type-get
11244                        (mm-handle-disposition handle) 'filename)
11245                       (mail-content-type-get
11246                        (mm-handle-type handle) 'name)
11247                       (concat gnus-newsgroup-name
11248                               "." (number-to-string
11249                                    (cdr gnus-article-current))))))
11250                    dir)))
11251         (unless (file-exists-p file)
11252           (mm-save-part-to-file handle file))))))
11253
11254 ;; Summary extract commands
11255
11256 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11257   (let ((buffer-read-only nil)
11258         (article (gnus-summary-article-number))
11259         after-article b e)
11260     (unless (gnus-summary-goto-subject article)
11261       (error "No such article: %d" article))
11262     (gnus-summary-position-point)
11263     ;; If all commands are to be bunched up on one line, we collect
11264     ;; them here.
11265     (unless gnus-view-pseudos-separately
11266       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11267             files action)
11268         (while ps
11269           (setq action (cdr (assq 'action (car ps))))
11270           (setq files (list (cdr (assq 'name (car ps)))))
11271           (while (and ps (cdr ps)
11272                       (string= (or action "1")
11273                                (or (cdr (assq 'action (cadr ps))) "2")))
11274             (push (cdr (assq 'name (cadr ps))) files)
11275             (setcdr ps (cddr ps)))
11276           (when files
11277             (when (not (string-match "%s" action))
11278               (push " " files))
11279             (push " " files)
11280             (when (assq 'execute (car ps))
11281               (setcdr (assq 'execute (car ps))
11282                       (funcall (if (string-match "%s" action)
11283                                    'format 'concat)
11284                                action
11285                                (mapconcat
11286                                 (lambda (f)
11287                                   (if (equal f " ")
11288                                       f
11289                                     (shell-quote-argument f)))
11290                                 files " ")))))
11291           (setq ps (cdr ps)))))
11292     (if (and gnus-view-pseudos (not not-view))
11293         (while pslist
11294           (when (assq 'execute (car pslist))
11295             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11296                                   (eq gnus-view-pseudos 'not-confirm)))
11297           (setq pslist (cdr pslist)))
11298       (save-excursion
11299         (while pslist
11300           (setq after-article (or (cdr (assq 'article (car pslist)))
11301                                   (gnus-summary-article-number)))
11302           (gnus-summary-goto-subject after-article)
11303           (forward-line 1)
11304           (setq b (point))
11305           (insert "    " (file-name-nondirectory
11306                           (cdr (assq 'name (car pslist))))
11307                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11308           (setq e (point))
11309           (forward-line -1)             ; back to `b'
11310           (gnus-add-text-properties
11311            b (1- e) (list 'gnus-number gnus-reffed-article-number
11312                           gnus-mouse-face-prop gnus-mouse-face))
11313           (gnus-data-enter
11314            after-article gnus-reffed-article-number
11315            gnus-unread-mark b (car pslist) 0 (- e b))
11316           (setq gnus-newsgroup-unreads
11317                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11318                                          gnus-reffed-article-number))
11319           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11320           (setq pslist (cdr pslist)))))))
11321
11322 (defun gnus-pseudos< (p1 p2)
11323   (let ((c1 (cdr (assq 'action p1)))
11324         (c2 (cdr (assq 'action p2))))
11325     (and c1 c2 (string< c1 c2))))
11326
11327 (defun gnus-request-pseudo-article (props)
11328   (cond ((assq 'execute props)
11329          (gnus-execute-command (cdr (assq 'execute props)))))
11330   (let ((gnus-current-article (gnus-summary-article-number)))
11331     (gnus-run-hooks 'gnus-mark-article-hook)))
11332
11333 (defun gnus-execute-command (command &optional automatic)
11334   (save-excursion
11335     (gnus-article-setup-buffer)
11336     (set-buffer gnus-article-buffer)
11337     (setq buffer-read-only nil)
11338     (let ((command (if automatic command
11339                      (read-string "Command: " (cons command 0)))))
11340       (erase-buffer)
11341       (insert "$ " command "\n\n")
11342       (if gnus-view-pseudo-asynchronously
11343           (start-process "gnus-execute" (current-buffer) shell-file-name
11344                          shell-command-switch command)
11345         (call-process shell-file-name nil t nil
11346                       shell-command-switch command)))))
11347
11348 ;; Summary kill commands.
11349
11350 (defun gnus-summary-edit-global-kill (article)
11351   "Edit the \"global\" kill file."
11352   (interactive (list (gnus-summary-article-number)))
11353   (gnus-group-edit-global-kill article))
11354
11355 (defun gnus-summary-edit-local-kill ()
11356   "Edit a local kill file applied to the current newsgroup."
11357   (interactive)
11358   (setq gnus-current-headers (gnus-summary-article-header))
11359   (gnus-group-edit-local-kill
11360    (gnus-summary-article-number) gnus-newsgroup-name))
11361
11362 ;;; Header reading.
11363
11364 (defun gnus-read-header (id &optional header)
11365   "Read the headers of article ID and enter them into the Gnus system."
11366   (let ((group gnus-newsgroup-name)
11367         (gnus-override-method
11368          (or
11369           gnus-override-method
11370           (and (gnus-news-group-p gnus-newsgroup-name)
11371                (car (gnus-refer-article-methods)))))
11372         where)
11373     ;; First we check to see whether the header in question is already
11374     ;; fetched.
11375     (if (stringp id)
11376         ;; This is a Message-ID.
11377         (setq header (or header (gnus-id-to-header id)))
11378       ;; This is an article number.
11379       (setq header (or header (gnus-summary-article-header id))))
11380     (if (and header
11381              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11382         ;; We have found the header.
11383         header
11384       ;; We have to really fetch the header to this article.
11385       (save-excursion
11386         (set-buffer nntp-server-buffer)
11387         (when (setq where (gnus-request-head id group))
11388           (nnheader-fold-continuation-lines)
11389           (goto-char (point-max))
11390           (insert ".\n")
11391           (goto-char (point-min))
11392           (insert "211 ")
11393           (princ (cond
11394                   ((numberp id) id)
11395                   ((cdr where) (cdr where))
11396                   (header (mail-header-number header))
11397                   (t gnus-reffed-article-number))
11398                  (current-buffer))
11399           (insert " Article retrieved.\n"))
11400         (if (or (not where)
11401                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11402             ()                          ; Malformed head.
11403           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11404             (when (and (stringp id)
11405                        (not (string= (gnus-group-real-name group)
11406                                      (car where))))
11407               ;; If we fetched by Message-ID and the article came
11408               ;; from a different group, we fudge some bogus article
11409               ;; numbers for this article.
11410               (mail-header-set-number header gnus-reffed-article-number))
11411             (save-excursion
11412               (set-buffer gnus-summary-buffer)
11413               (decf gnus-reffed-article-number)
11414               (gnus-remove-header (mail-header-number header))
11415               (push header gnus-newsgroup-headers)
11416               (setq gnus-current-headers header)
11417               (push (mail-header-number header) gnus-newsgroup-limit)))
11418           header)))))
11419
11420 (defun gnus-remove-header (number)
11421   "Remove header NUMBER from `gnus-newsgroup-headers'."
11422   (if (and gnus-newsgroup-headers
11423            (= number (mail-header-number (car gnus-newsgroup-headers))))
11424       (pop gnus-newsgroup-headers)
11425     (let ((headers gnus-newsgroup-headers))
11426       (while (and (cdr headers)
11427                   (not (= number (mail-header-number (cadr headers)))))
11428         (pop headers))
11429       (when (cdr headers)
11430         (setcdr headers (cddr headers))))))
11431
11432 ;;;
11433 ;;; summary highlights
11434 ;;;
11435
11436 (defun gnus-highlight-selected-summary ()
11437   "Highlight selected article in summary buffer."
11438   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11439   (when gnus-summary-selected-face
11440     (save-excursion
11441       (let* ((beg (point-at-bol))
11442              (end (point-at-eol))
11443              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11444              (from (if (get-text-property beg gnus-mouse-face-prop)
11445                        beg
11446                      (or (next-single-property-change
11447                           beg gnus-mouse-face-prop nil end)
11448                          beg)))
11449              (to
11450               (if (= from end)
11451                   (- from 2)
11452                 (or (next-single-property-change
11453                      from gnus-mouse-face-prop nil end)
11454                     end))))
11455         ;; If no mouse-face prop on line we will have to = from = end,
11456         ;; so we highlight the entire line instead.
11457         (when (= (+ to 2) from)
11458           (setq from beg)
11459           (setq to end))
11460         (if gnus-newsgroup-selected-overlay
11461             ;; Move old overlay.
11462             (gnus-move-overlay
11463              gnus-newsgroup-selected-overlay from to (current-buffer))
11464           ;; Create new overlay.
11465           (gnus-overlay-put
11466            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11467            'face gnus-summary-selected-face))))))
11468
11469 (defvar gnus-summary-highlight-line-cached nil)
11470 (defvar gnus-summary-highlight-line-trigger nil)
11471
11472 (defun gnus-summary-highlight-line-0 ()
11473   (if (and (eq gnus-summary-highlight-line-trigger
11474                gnus-summary-highlight)
11475            gnus-summary-highlight-line-cached)
11476       gnus-summary-highlight-line-cached
11477     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11478           gnus-summary-highlight-line-cached
11479           (let* ((cond (list 'cond))
11480                  (c cond)
11481                  (list gnus-summary-highlight))
11482             (while list
11483               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11484                               nil))
11485               (setq c (cdr c)
11486                     list (cdr list)))
11487             (gnus-byte-compile (list 'lambda nil cond))))))
11488
11489 (defun gnus-summary-highlight-line ()
11490   "Highlight current line according to `gnus-summary-highlight'."
11491   (let* ((beg (point-at-bol))
11492          (article (or (gnus-summary-article-number) gnus-current-article))
11493          (score (or (cdr (assq article
11494                                gnus-newsgroup-scored))
11495                     gnus-summary-default-score 0))
11496          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11497          (inhibit-read-only t)
11498          (default gnus-summary-default-score)
11499          (default-high gnus-summary-default-high-score)
11500          (default-low gnus-summary-default-low-score)
11501          (uncached (and gnus-summary-use-undownloaded-faces
11502                         (memq article gnus-newsgroup-undownloaded)
11503                         (not (memq article gnus-newsgroup-cached)))))
11504     (let ((face (funcall (gnus-summary-highlight-line-0))))
11505       (unless (eq face (get-text-property beg 'face))
11506         (gnus-put-text-property-excluding-characters-with-faces
11507          beg (point-at-eol) 'face
11508          (setq face (if (boundp face) (symbol-value face) face)))
11509         (when gnus-summary-highlight-line-function
11510           (funcall gnus-summary-highlight-line-function article face))))))
11511
11512 (defun gnus-update-read-articles (group unread &optional compute)
11513   "Update the list of read articles in GROUP.
11514 UNREAD is a sorted list."
11515   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11516         (info (gnus-get-info group))
11517         (prev 1)
11518         read)
11519     (if (or (not info) (not active))
11520         ;; There is no info on this group if it was, in fact,
11521         ;; killed.  Gnus stores no information on killed groups, so
11522         ;; there's nothing to be done.
11523         ;; One could store the information somewhere temporarily,
11524         ;; perhaps...  Hmmm...
11525         ()
11526       ;; Remove any negative articles numbers.
11527       (while (and unread (< (car unread) 0))
11528         (setq unread (cdr unread)))
11529       ;; Remove any expired article numbers
11530       (while (and unread (< (car unread) (car active)))
11531         (setq unread (cdr unread)))
11532       ;; Compute the ranges of read articles by looking at the list of
11533       ;; unread articles.
11534       (while unread
11535         (when (/= (car unread) prev)
11536           (push (if (= prev (1- (car unread))) prev
11537                   (cons prev (1- (car unread))))
11538                 read))
11539         (setq prev (1+ (car unread)))
11540         (setq unread (cdr unread)))
11541       (when (<= prev (cdr active))
11542         (push (cons prev (cdr active)) read))
11543       (setq read (if (> (length read) 1) (nreverse read) read))
11544       (if compute
11545           read
11546         (save-excursion
11547           (let (setmarkundo)
11548             ;; Propagate the read marks to the backend.
11549             (when (gnus-check-backend-function 'request-set-mark group)
11550               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11551                     (add (gnus-remove-from-range read (gnus-info-read info))))
11552                 (when (or add del)
11553                   (unless (gnus-check-group group)
11554                     (error "Can't open server for %s" group))
11555                   (gnus-request-set-mark
11556                    group (delq nil (list (if add (list add 'add '(read)))
11557                                          (if del (list del 'del '(read))))))
11558                   (setq setmarkundo
11559                         `(gnus-request-set-mark
11560                           ,group
11561                           ',(delq nil (list
11562                                        (if del (list del 'add '(read)))
11563                                        (if add (list add 'del '(read))))))))))
11564             (set-buffer gnus-group-buffer)
11565             (gnus-undo-register
11566               `(progn
11567                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11568                  (gnus-info-set-read ',info ',(gnus-info-read info))
11569                  (gnus-get-unread-articles-in-group ',info
11570                                                     (gnus-active ,group))
11571                  (gnus-group-update-group ,group t)
11572                  ,setmarkundo))))
11573         ;; Enter this list into the group info.
11574         (gnus-info-set-read info read)
11575         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11576         (gnus-get-unread-articles-in-group info (gnus-active group))
11577         t))))
11578
11579 (defun gnus-offer-save-summaries ()
11580   "Offer to save all active summary buffers."
11581   (let (buffers)
11582     ;; Go through all buffers and find all summaries.
11583     (dolist (buffer (buffer-list))
11584       (when (and (setq buffer (buffer-name buffer))
11585                  (string-match "Summary" buffer)
11586                  (with-current-buffer buffer
11587                    ;; We check that this is, indeed, a summary buffer.
11588                    (and (eq major-mode 'gnus-summary-mode)
11589                         ;; Also make sure this isn't bogus.
11590                         gnus-newsgroup-prepared
11591                         ;; Also make sure that this isn't a
11592                         ;; dead summary buffer.
11593                         (not gnus-dead-summary-mode))))
11594         (push buffer buffers)))
11595     ;; Go through all these summary buffers and offer to save them.
11596     (when buffers
11597       (save-excursion
11598         (map-y-or-n-p
11599          "Update summary buffer %s? "
11600          (lambda (buf)
11601            (switch-to-buffer buf)
11602            (gnus-summary-exit))
11603          buffers)))))
11604
11605 (defun gnus-summary-setup-default-charset ()
11606   "Setup newsgroup default charset."
11607   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11608       (setq gnus-newsgroup-charset nil)
11609     (let* ((ignored-charsets
11610             (or gnus-newsgroup-ephemeral-ignored-charsets
11611                 (append
11612                  (and gnus-newsgroup-name
11613                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11614                  gnus-newsgroup-ignored-charsets))))
11615       (setq gnus-newsgroup-charset
11616             (or gnus-newsgroup-ephemeral-charset
11617                 (and gnus-newsgroup-name
11618                      (gnus-parameter-charset gnus-newsgroup-name))
11619                 gnus-default-charset))
11620       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11621            ignored-charsets))))
11622
11623 ;;;
11624 ;;; Mime Commands
11625 ;;;
11626
11627 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11628   "Display the current article buffer fully MIME-buttonized.
11629 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11630 treated as multipart/mixed."
11631   (interactive "P")
11632   (require 'gnus-art)
11633   (let ((gnus-unbuttonized-mime-types nil)
11634         (gnus-mime-display-multipart-as-mixed show-all-parts))
11635     (gnus-summary-show-article)))
11636
11637 (defun gnus-summary-repair-multipart (article)
11638   "Add a Content-Type header to a multipart article without one."
11639   (interactive (list (gnus-summary-article-number)))
11640   (gnus-with-article article
11641     (message-narrow-to-head)
11642     (message-remove-header "Mime-Version")
11643     (goto-char (point-max))
11644     (insert "Mime-Version: 1.0\n")
11645     (widen)
11646     (when (search-forward "\n--" nil t)
11647       (let ((separator (buffer-substring (point) (point-at-eol))))
11648         (message-narrow-to-head)
11649         (message-remove-header "Content-Type")
11650         (goto-char (point-max))
11651         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11652                         separator))
11653         (widen))))
11654   (let (gnus-mark-article-hook)
11655     (gnus-summary-select-article t t nil article)))
11656
11657 (defun gnus-summary-toggle-display-buttonized ()
11658   "Toggle the buttonizing of the article buffer."
11659   (interactive)
11660   (require 'gnus-art)
11661   (if (setq gnus-inhibit-mime-unbuttonizing
11662             (not gnus-inhibit-mime-unbuttonizing))
11663       (let ((gnus-unbuttonized-mime-types nil))
11664         (gnus-summary-show-article))
11665     (gnus-summary-show-article)))
11666
11667 ;;;
11668 ;;; Generic summary marking commands
11669 ;;;
11670
11671 (defvar gnus-summary-marking-alist
11672   '((read gnus-del-mark "d")
11673     (unread gnus-unread-mark "u")
11674     (ticked gnus-ticked-mark "!")
11675     (dormant gnus-dormant-mark "?")
11676     (expirable gnus-expirable-mark "e"))
11677   "An alist of names/marks/keystrokes.")
11678
11679 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11680 (defvar gnus-summary-mark-map)
11681
11682 (defun gnus-summary-make-all-marking-commands ()
11683   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11684   (dolist (elem gnus-summary-marking-alist)
11685     (apply 'gnus-summary-make-marking-command elem)))
11686
11687 (defun gnus-summary-make-marking-command (name mark keystroke)
11688   (let ((map (make-sparse-keymap)))
11689     (define-key gnus-summary-generic-mark-map keystroke map)
11690     (dolist (lway `((next "next" next nil "n")
11691                     (next-unread "next unread" next t "N")
11692                     (prev "previous" prev nil "p")
11693                     (prev-unread "previous unread" prev t "P")
11694                     (nomove "" nil nil ,keystroke)))
11695       (let ((func (gnus-summary-make-marking-command-1
11696                    mark (car lway) lway name)))
11697         (setq func (eval func))
11698         (define-key map (nth 4 lway) func)))))
11699
11700 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11701   `(defun ,(intern
11702             (format "gnus-summary-put-mark-as-%s%s"
11703                     name (if (eq way 'nomove)
11704                              ""
11705                            (concat "-" (symbol-name way)))))
11706      (n)
11707      ,(format
11708        "Mark the current article as %s%s.
11709 If N, the prefix, then repeat N times.
11710 If N is negative, move in reverse order.
11711 The difference between N and the actual number of articles marked is
11712 returned."
11713        name (cadr lway))
11714      (interactive "p")
11715      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11716
11717 (defun gnus-summary-generic-mark (n mark move unread)
11718   "Mark N articles with MARK."
11719   (unless (eq major-mode 'gnus-summary-mode)
11720     (error "This command can only be used in the summary buffer"))
11721   (gnus-summary-show-thread)
11722   (let ((nummove
11723          (cond
11724           ((eq move 'next) 1)
11725           ((eq move 'prev) -1)
11726           (t 0))))
11727     (if (zerop nummove)
11728         (setq n 1)
11729       (when (< n 0)
11730         (setq n (abs n)
11731               nummove (* -1 nummove))))
11732     (while (and (> n 0)
11733                 (gnus-summary-mark-article nil mark)
11734                 (zerop (gnus-summary-next-subject nummove unread t)))
11735       (setq n (1- n)))
11736     (when (/= 0 n)
11737       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11738     (gnus-summary-recenter)
11739     (gnus-summary-position-point)
11740     (gnus-set-mode-line 'summary)
11741     n))
11742
11743 (defun gnus-summary-insert-articles (articles)
11744   (when (setq articles
11745               (gnus-sorted-difference articles
11746                                       (mapcar (lambda (h)
11747                                                 (mail-header-number h))
11748                                               gnus-newsgroup-headers)))
11749     (setq gnus-newsgroup-headers
11750           (gnus-merge 'list
11751                       gnus-newsgroup-headers
11752                       (gnus-fetch-headers articles)
11753                       'gnus-article-sort-by-number))
11754     ;; Suppress duplicates?
11755     (when gnus-suppress-duplicates
11756       (gnus-dup-suppress-articles))
11757
11758     ;; We might want to build some more threads first.
11759     (when (and gnus-fetch-old-headers
11760                (eq gnus-headers-retrieved-by 'nov))
11761       (if (eq gnus-fetch-old-headers 'invisible)
11762           (gnus-build-all-threads)
11763         (gnus-build-old-threads)))
11764     ;; Let the Gnus agent mark articles as read.
11765     (when gnus-agent
11766       (gnus-agent-get-undownloaded-list))
11767     ;; Remove list identifiers from subject
11768     (when gnus-list-identifiers
11769       (gnus-summary-remove-list-identifiers))
11770     ;; First and last article in this newsgroup.
11771     (when gnus-newsgroup-headers
11772       (setq gnus-newsgroup-begin
11773             (mail-header-number (car gnus-newsgroup-headers))
11774             gnus-newsgroup-end
11775             (mail-header-number
11776              (gnus-last-element gnus-newsgroup-headers))))
11777     (when gnus-use-scoring
11778       (gnus-possibly-score-headers))))
11779
11780 (defun gnus-summary-insert-old-articles (&optional all)
11781   "Insert all old articles in this group.
11782 If ALL is non-nil, already read articles become readable.
11783 If ALL is a number, fetch this number of articles."
11784   (interactive "P")
11785   (prog1
11786       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11787             older len)
11788         (setq older
11789               ;; Some nntp servers lie about their active range.  When
11790               ;; this happens, the active range can be in the millions.
11791               ;; Use a compressed range to avoid creating a huge list.
11792               (gnus-range-difference (list gnus-newsgroup-active) old))
11793         (setq len (gnus-range-length older))
11794         (cond
11795          ((null older) nil)
11796          ((numberp all)
11797           (if (< all len)
11798               (let ((older-range (nreverse older)))
11799                 (setq older nil)
11800
11801                 (while (> all 0)
11802                   (let* ((r (pop older-range))
11803                          (min (if (numberp r) r (car r)))
11804                          (max (if (numberp r) r (cdr r))))
11805                     (while (and (<= min max)
11806                                 (> all 0))
11807                       (push max older)
11808                       (setq all (1- all)
11809                             max (1- max))))))
11810             (setq older (gnus-uncompress-range older))))
11811          (all
11812           (setq older (gnus-uncompress-range older)))
11813          (t
11814           (when (and (numberp gnus-large-newsgroup)
11815                    (> len gnus-large-newsgroup))
11816               (let* ((cursor-in-echo-area nil)
11817                      (initial (gnus-parameter-large-newsgroup-initial
11818                                gnus-newsgroup-name))
11819                      (input
11820                       (read-string
11821                        (format
11822                         "How many articles from %s (%s %d): "
11823                         (gnus-limit-string
11824                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11825                         (if initial "max" "default")
11826                         len)
11827                        (if initial
11828                            (cons (number-to-string initial)
11829                                  0)))))
11830                 (unless (string-match "^[ \t]*$" input)
11831                   (setq all (string-to-number input))
11832                   (if (< all len)
11833                       (let ((older-range (nreverse older)))
11834                         (setq older nil)
11835
11836                         (while (> all 0)
11837                           (let* ((r (pop older-range))
11838                                  (min (if (numberp r) r (car r)))
11839                                  (max (if (numberp r) r (cdr r))))
11840                             (while (and (<= min max)
11841                                         (> all 0))
11842                               (push max older)
11843                               (setq all (1- all)
11844                                     max (1- max))))))))))
11845           (setq older (gnus-uncompress-range older))))
11846         (if (not older)
11847             (message "No old news.")
11848           (gnus-summary-insert-articles older)
11849           (gnus-summary-limit (gnus-sorted-nunion old older))))
11850     (gnus-summary-position-point)))
11851
11852 (defun gnus-summary-insert-new-articles ()
11853   "Insert all new articles in this group."
11854   (interactive)
11855   (prog1
11856       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11857             (old-active gnus-newsgroup-active)
11858             (nnmail-fetched-sources (list t))
11859             i new)
11860         (setq gnus-newsgroup-active
11861               (gnus-activate-group gnus-newsgroup-name 'scan))
11862         (setq i (cdr gnus-newsgroup-active))
11863         (while (> i (cdr old-active))
11864           (push i new)
11865           (decf i))
11866         (if (not new)
11867             (message "No gnus is bad news")
11868           (gnus-summary-insert-articles new)
11869           (setq gnus-newsgroup-unreads
11870                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11871           (gnus-summary-limit (gnus-sorted-nunion old new))))
11872     (gnus-summary-position-point)))
11873
11874 (gnus-summary-make-all-marking-commands)
11875
11876 (gnus-ems-redefine)
11877
11878 (provide 'gnus-sum)
11879
11880 (run-hooks 'gnus-sum-load-hook)
11881
11882 ;; Local Variables:
11883 ;; coding: iso-8859-1
11884 ;; End:
11885
11886 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11887 ;;; gnus-sum.el ends here