(gnus-summary-to-prefix,
[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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, 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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
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 "22.1"
972   :group 'gnus-summary
973   :type 'boolean)
974
975 (defcustom gnus-summary-selected-face 'gnus-summary-selected
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)
985     ((and uncached (> score default-high))
986      . gnus-summary-high-undownloaded)
987     ((and uncached (< score default-low))
988      . gnus-summary-low-undownloaded)
989     (uncached
990      . gnus-summary-normal-undownloaded)
991     ((and (> score default-high)
992           (or (eq mark gnus-dormant-mark)
993               (eq mark gnus-ticked-mark)))
994      . gnus-summary-high-ticked)
995     ((and (< score default-low)
996           (or (eq mark gnus-dormant-mark)
997               (eq mark gnus-ticked-mark)))
998      . gnus-summary-low-ticked)
999     ((or (eq mark gnus-dormant-mark)
1000          (eq mark gnus-ticked-mark))
1001      . gnus-summary-normal-ticked)
1002     ((and (> score default-high) (eq mark gnus-ancient-mark))
1003      . gnus-summary-high-ancient)
1004     ((and (< score default-low) (eq mark gnus-ancient-mark))
1005      . gnus-summary-low-ancient)
1006     ((eq mark gnus-ancient-mark)
1007      . gnus-summary-normal-ancient)
1008     ((and (> score default-high) (eq mark gnus-unread-mark))
1009      . gnus-summary-high-unread)
1010     ((and (< score default-low) (eq mark gnus-unread-mark))
1011      . gnus-summary-low-unread)
1012     ((eq mark gnus-unread-mark)
1013      . gnus-summary-normal-unread)
1014     ((> score default-high)
1015      . gnus-summary-high-read)
1016     ((< score default-low)
1017      . gnus-summary-low-read)
1018     (t
1019      . gnus-summary-normal-read))
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-summary-to-prefix "-> "
1065   "*String prefixed to the To field in the summary line when
1066 using `gnus-ignored-from-addresses'."
1067   :version "22.1"
1068   :group 'gnus-summary
1069   :type 'string)
1070
1071 (defcustom gnus-summary-newsgroup-prefix "=> "
1072   "*String prefixed to the Newsgroup field in the summary
1073 line when using `gnus-ignored-from-addresses'."
1074   :version "22.1"
1075   :group 'gnus-summary
1076   :type 'string)
1077
1078 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1079   "List of charsets that should be ignored.
1080 When these charsets are used in the \"charset\" parameter, the
1081 default charset will be used instead."
1082   :version "21.1"
1083   :type '(repeat symbol)
1084   :group 'gnus-charset)
1085
1086 (gnus-define-group-parameter
1087  ignored-charsets
1088  :type list
1089  :function-document
1090  "Return the ignored charsets of GROUP."
1091  :variable gnus-group-ignored-charsets-alist
1092  :variable-default
1093  '(("alt\\.chinese\\.text" iso-8859-1))
1094  :variable-document
1095  "Alist of regexps (to match group names) and charsets that should be ignored.
1096 When these charsets are used in the \"charset\" parameter, the
1097 default charset will be used instead."
1098  :variable-group gnus-charset
1099  :variable-type '(repeat (cons (regexp :tag "Group")
1100                                (repeat symbol)))
1101  :parameter-type '(choice :tag "Ignored charsets"
1102                           :value nil
1103                           (repeat (symbol)))
1104  :parameter-document       "\
1105 List of charsets that should be ignored.
1106
1107 When these charsets are used in the \"charset\" parameter, the
1108 default charset will be used instead.")
1109
1110 (defcustom gnus-group-highlight-words-alist nil
1111   "Alist of group regexps and highlight regexps.
1112 This variable uses the same syntax as `gnus-emphasis-alist'."
1113   :version "21.1"
1114   :type '(repeat (cons (regexp :tag "Group")
1115                        (repeat (list (regexp :tag "Highlight regexp")
1116                                      (number :tag "Group for entire word" 0)
1117                                      (number :tag "Group for displayed part" 0)
1118                                      (symbol :tag "Face"
1119                                              gnus-emphasis-highlight-words)))))
1120   :group 'gnus-summary-visual)
1121
1122 (defcustom gnus-summary-show-article-charset-alist
1123   nil
1124   "Alist of number and charset.
1125 The article will be shown with the charset corresponding to the
1126 numbered argument.
1127 For example: ((1 . cn-gb-2312) (2 . big5))."
1128   :version "21.1"
1129   :type '(repeat (cons (number :tag "Argument" 1)
1130                        (symbol :tag "Charset")))
1131   :group 'gnus-charset)
1132
1133 (defcustom gnus-preserve-marks t
1134   "Whether marks are preserved when moving, copying and respooling messages."
1135   :version "21.1"
1136   :type 'boolean
1137   :group 'gnus-summary-marks)
1138
1139 (defcustom gnus-alter-articles-to-read-function nil
1140   "Function to be called to alter the list of articles to be selected."
1141   :type '(choice (const nil) function)
1142   :group 'gnus-summary)
1143
1144 (defcustom gnus-orphan-score nil
1145   "*All orphans get this score added.  Set in the score file."
1146   :group 'gnus-score-default
1147   :type '(choice (const nil)
1148                  integer))
1149
1150 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1151   "*A regexp to match MIME parts when saving multiple parts of a
1152 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1153 This regexp will be used by default when prompting the user for which
1154 type of files to save."
1155   :group 'gnus-summary
1156   :type 'regexp)
1157
1158 (defcustom gnus-read-all-available-headers nil
1159   "Whether Gnus should parse all headers made available to it.
1160 This is mostly relevant for slow back ends where the user may
1161 wish to widen the summary buffer to include all headers
1162 that were fetched.  Say, for nnultimate groups."
1163   :version "22.1"
1164   :group 'gnus-summary
1165   :type '(choice boolean regexp))
1166
1167 (defcustom gnus-summary-muttprint-program "muttprint"
1168   "Command (and optional arguments) used to run Muttprint."
1169   :version "22.1"
1170   :group 'gnus-summary
1171   :type 'string)
1172
1173 (defcustom gnus-article-loose-mime t
1174   "If non-nil, don't require MIME-Version header.
1175 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1176 supply the MIME-Version header or deliberately strip it from the mail.
1177 If non-nil (the default), Gnus will treat some articles as MIME
1178 even if the MIME-Version header is missing."
1179   :version "22.1"
1180   :type 'boolean
1181   :group 'gnus-article-mime)
1182
1183 (defcustom gnus-article-emulate-mime t
1184   "If non-nil, use MIME emulation for uuencode and the like.
1185 This means that Gnus will search message bodies for text that look
1186 like uuencoded bits, yEncoded bits, and so on, and present that using
1187 the normal Gnus MIME machinery."
1188   :version "22.1"
1189   :type 'boolean
1190   :group 'gnus-article-mime)
1191
1192 ;;; Internal variables
1193
1194 (defvar gnus-summary-display-cache nil)
1195 (defvar gnus-article-mime-handles nil)
1196 (defvar gnus-article-decoded-p nil)
1197 (defvar gnus-article-charset nil)
1198 (defvar gnus-article-ignored-charsets nil)
1199 (defvar gnus-scores-exclude-files nil)
1200 (defvar gnus-page-broken nil)
1201
1202 (defvar gnus-original-article nil)
1203 (defvar gnus-article-internal-prepare-hook nil)
1204 (defvar gnus-newsgroup-process-stack nil)
1205
1206 (defvar gnus-thread-indent-array nil)
1207 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1208 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1209   "Function called to sort the articles within a thread after it has been gathered together.")
1210
1211 (defvar gnus-summary-save-parts-type-history nil)
1212 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1213
1214 ;; Avoid highlighting in kill files.
1215 (defvar gnus-summary-inhibit-highlight nil)
1216 (defvar gnus-newsgroup-selected-overlay nil)
1217 (defvar gnus-inhibit-limiting nil)
1218 (defvar gnus-newsgroup-adaptive-score-file nil)
1219 (defvar gnus-current-score-file nil)
1220 (defvar gnus-current-move-group nil)
1221 (defvar gnus-current-copy-group nil)
1222 (defvar gnus-current-crosspost-group nil)
1223 (defvar gnus-newsgroup-display nil)
1224
1225 (defvar gnus-newsgroup-dependencies nil)
1226 (defvar gnus-newsgroup-adaptive nil)
1227 (defvar gnus-summary-display-article-function nil)
1228 (defvar gnus-summary-highlight-line-function nil
1229   "Function called after highlighting a summary line.")
1230
1231 (defvar gnus-summary-line-format-alist
1232   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1233     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1234     (?s gnus-tmp-subject-or-nil ?s)
1235     (?n gnus-tmp-name ?s)
1236     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1237         ?s)
1238     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1239             gnus-tmp-from) ?s)
1240     (?F gnus-tmp-from ?s)
1241     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1242     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1243     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1244     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1245     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1246     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1247     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1248     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1249     (?L gnus-tmp-lines ?s)
1250     (?O gnus-tmp-downloaded ?c)
1251     (?I gnus-tmp-indentation ?s)
1252     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1253     (?R gnus-tmp-replied ?c)
1254     (?\[ gnus-tmp-opening-bracket ?c)
1255     (?\] gnus-tmp-closing-bracket ?c)
1256     (?\> (make-string gnus-tmp-level ? ) ?s)
1257     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1258     (?i gnus-tmp-score ?d)
1259     (?z gnus-tmp-score-char ?c)
1260     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1261     (?U gnus-tmp-unread ?c)
1262     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1263         ?s)
1264     (?t (gnus-summary-number-of-articles-in-thread
1265          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1266         ?d)
1267     (?e (gnus-summary-number-of-articles-in-thread
1268          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1269         ?c)
1270     (?u gnus-tmp-user-defined ?s)
1271     (?P (gnus-pick-line-number) ?d)
1272     (?B gnus-tmp-thread-tree-header-string ?s)
1273     (user-date (gnus-user-date
1274                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1275   "An alist of format specifications that can appear in summary lines.
1276 These are paired with what variables they correspond with, along with
1277 the type of the variable (string, integer, character, etc).")
1278
1279 (defvar gnus-summary-dummy-line-format-alist
1280   `((?S gnus-tmp-subject ?s)
1281     (?N gnus-tmp-number ?d)
1282     (?u gnus-tmp-user-defined ?s)))
1283
1284 (defvar gnus-summary-mode-line-format-alist
1285   `((?G gnus-tmp-group-name ?s)
1286     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1287     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1288     (?A gnus-tmp-article-number ?d)
1289     (?Z gnus-tmp-unread-and-unselected ?s)
1290     (?V gnus-version ?s)
1291     (?U gnus-tmp-unread-and-unticked ?d)
1292     (?S gnus-tmp-subject ?s)
1293     (?e gnus-tmp-unselected ?d)
1294     (?u gnus-tmp-user-defined ?s)
1295     (?d (length gnus-newsgroup-dormant) ?d)
1296     (?t (length gnus-newsgroup-marked) ?d)
1297     (?h (length gnus-newsgroup-spam-marked) ?d)
1298     (?r (length gnus-newsgroup-reads) ?d)
1299     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1300     (?E gnus-newsgroup-expunged-tally ?d)
1301     (?s (gnus-current-score-file-nondirectory) ?s)))
1302
1303 (defvar gnus-last-search-regexp nil
1304   "Default regexp for article search command.")
1305
1306 (defvar gnus-last-shell-command nil
1307   "Default shell command on article.")
1308
1309 (defvar gnus-newsgroup-agentized nil
1310   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1311 (defvar gnus-newsgroup-begin nil)
1312 (defvar gnus-newsgroup-end nil)
1313 (defvar gnus-newsgroup-last-rmail nil)
1314 (defvar gnus-newsgroup-last-mail nil)
1315 (defvar gnus-newsgroup-last-folder nil)
1316 (defvar gnus-newsgroup-last-file nil)
1317 (defvar gnus-newsgroup-auto-expire nil)
1318 (defvar gnus-newsgroup-active nil)
1319
1320 (defvar gnus-newsgroup-data nil)
1321 (defvar gnus-newsgroup-data-reverse nil)
1322 (defvar gnus-newsgroup-limit nil)
1323 (defvar gnus-newsgroup-limits nil)
1324 (defvar gnus-summary-use-undownloaded-faces nil)
1325
1326 (defvar gnus-newsgroup-unreads nil
1327   "Sorted list of unread articles in the current newsgroup.")
1328
1329 (defvar gnus-newsgroup-unselected nil
1330   "Sorted list of unselected unread articles in the current newsgroup.")
1331
1332 (defvar gnus-newsgroup-reads nil
1333   "Alist of read articles and article marks in the current newsgroup.")
1334
1335 (defvar gnus-newsgroup-expunged-tally nil)
1336
1337 (defvar gnus-newsgroup-marked nil
1338   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1339
1340 (defvar gnus-newsgroup-spam-marked nil
1341   "List of ranges of articles that have been marked as spam.")
1342
1343 (defvar gnus-newsgroup-killed nil
1344   "List of ranges of articles that have been through the scoring process.")
1345
1346 (defvar gnus-newsgroup-cached nil
1347   "Sorted list of articles that come from the article cache.")
1348
1349 (defvar gnus-newsgroup-saved nil
1350   "List of articles that have been saved.")
1351
1352 (defvar gnus-newsgroup-kill-headers nil)
1353
1354 (defvar gnus-newsgroup-replied nil
1355   "List of articles that have been replied to in the current newsgroup.")
1356
1357 (defvar gnus-newsgroup-forwarded nil
1358   "List of articles that have been forwarded in the current newsgroup.")
1359
1360 (defvar gnus-newsgroup-recent nil
1361   "List of articles that have are recent in the current newsgroup.")
1362
1363 (defvar gnus-newsgroup-expirable nil
1364   "Sorted list of articles in the current newsgroup that can be expired.")
1365
1366 (defvar gnus-newsgroup-processable nil
1367   "List of articles in the current newsgroup that can be processed.")
1368
1369 (defvar gnus-newsgroup-downloadable nil
1370   "Sorted list of articles in the current newsgroup that can be processed.")
1371
1372 (defvar gnus-newsgroup-unfetched nil
1373   "Sorted list of articles in the current newsgroup whose headers have
1374 not been fetched into the agent.
1375
1376 This list will always be a subset of gnus-newsgroup-undownloaded.")
1377
1378 (defvar gnus-newsgroup-undownloaded nil
1379   "List of articles in the current newsgroup that haven't been downloaded.")
1380
1381 (defvar gnus-newsgroup-unsendable nil
1382   "List of articles in the current newsgroup that won't be sent.")
1383
1384 (defvar gnus-newsgroup-bookmarks nil
1385   "List of articles in the current newsgroup that have bookmarks.")
1386
1387 (defvar gnus-newsgroup-dormant nil
1388   "Sorted list of dormant articles in the current newsgroup.")
1389
1390 (defvar gnus-newsgroup-unseen nil
1391   "List of unseen articles in the current newsgroup.")
1392
1393 (defvar gnus-newsgroup-seen nil
1394   "Range of seen articles in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-articles nil
1397   "List of articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-scored nil
1400   "List of scored articles in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-headers nil
1403   "List of article headers in the current newsgroup.")
1404
1405 (defvar gnus-newsgroup-threads nil)
1406
1407 (defvar gnus-newsgroup-prepared nil
1408   "Whether the current group has been prepared properly.")
1409
1410 (defvar gnus-newsgroup-ancient nil
1411   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-sparse nil)
1414
1415 (defvar gnus-current-article nil)
1416 (defvar gnus-article-current nil)
1417 (defvar gnus-current-headers nil)
1418 (defvar gnus-have-all-headers nil)
1419 (defvar gnus-last-article nil)
1420 (defvar gnus-newsgroup-history nil)
1421 (defvar gnus-newsgroup-charset nil)
1422 (defvar gnus-newsgroup-ephemeral-charset nil)
1423 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1424
1425 (defvar gnus-article-before-search nil)
1426
1427 (defvar gnus-summary-local-variables
1428   '(gnus-newsgroup-name
1429     gnus-newsgroup-begin gnus-newsgroup-end
1430     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1431     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1432     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1433     gnus-newsgroup-unselected gnus-newsgroup-marked
1434     gnus-newsgroup-spam-marked
1435     gnus-newsgroup-reads gnus-newsgroup-saved
1436     gnus-newsgroup-replied gnus-newsgroup-forwarded
1437     gnus-newsgroup-recent
1438     gnus-newsgroup-expirable
1439     gnus-newsgroup-processable gnus-newsgroup-killed
1440     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1441     gnus-newsgroup-unfetched
1442     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1443     gnus-newsgroup-seen gnus-newsgroup-articles
1444     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1445     gnus-newsgroup-headers gnus-newsgroup-threads
1446     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1447     gnus-current-article gnus-current-headers gnus-have-all-headers
1448     gnus-last-article gnus-article-internal-prepare-hook
1449     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1450     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1451     gnus-thread-expunge-below
1452     gnus-score-alist gnus-current-score-file
1453     (gnus-summary-expunge-below . global)
1454     (gnus-summary-mark-below . global)
1455     (gnus-orphan-score . global)
1456     gnus-newsgroup-active gnus-scores-exclude-files
1457     gnus-newsgroup-history gnus-newsgroup-ancient
1458     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1459     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1460     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1461     (gnus-newsgroup-expunged-tally . 0)
1462     gnus-cache-removable-articles gnus-newsgroup-cached
1463     gnus-newsgroup-data gnus-newsgroup-data-reverse
1464     gnus-newsgroup-limit gnus-newsgroup-limits
1465     gnus-newsgroup-charset gnus-newsgroup-display
1466     gnus-summary-use-undownloaded-faces)
1467   "Variables that are buffer-local to the summary buffers.")
1468
1469 (defvar gnus-newsgroup-variables nil
1470   "A list of variables that have separate values in different newsgroups.
1471 A list of newsgroup (summary buffer) local variables, or cons of
1472 variables and their default expressions to be evalled (when the default
1473 values are not nil), that should be made global while the summary buffer
1474 is active.
1475
1476 Note: The default expressions will be evaluated (using function `eval')
1477 before assignment to the local variable rather than just assigned to it.
1478 If the default expression is the symbol `global', that symbol will not
1479 be evaluated but the global value of the local variable will be used
1480 instead.
1481
1482 These variables can be used to set variables in the group parameters
1483 while still allowing them to affect operations done in other buffers.
1484 For example:
1485
1486 \(setq gnus-newsgroup-variables
1487      '(message-use-followup-to
1488        (gnus-visible-headers .
1489          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1490 ")
1491
1492 ;; Byte-compiler warning.
1493 (eval-when-compile
1494   ;; Bind features so that require will believe that gnus-sum has
1495   ;; already been loaded (avoids infinite recursion)
1496   (let ((features (cons 'gnus-sum features)))
1497     ;; Several of the declarations in gnus-sum are needed to load the
1498     ;; following files. Right now, these definitions have been
1499     ;; compiled but not defined (evaluated).  We could either do a
1500     ;; eval-and-compile about all of the declarations or evaluate the
1501     ;; source file.
1502     (if (boundp 'gnus-newsgroup-variables)
1503         nil
1504       (load "gnus-sum.el" t t t))
1505     (require 'gnus)
1506     (require 'gnus-art)))
1507
1508 ;; MIME stuff.
1509
1510 (defvar gnus-decode-encoded-word-methods
1511   '(mail-decode-encoded-word-string)
1512   "List of methods used to decode encoded words.
1513
1514 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1515 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1516 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1517 whose names match REGEXP.
1518
1519 For example:
1520 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1521  mail-decode-encoded-word-string
1522  (\"chinese\" . rfc1843-decode-string))")
1523
1524 (defvar gnus-decode-encoded-word-methods-cache nil)
1525
1526 (defun gnus-multi-decode-encoded-word-string (string)
1527   "Apply the functions from `gnus-encoded-word-methods' that match."
1528   (unless (and gnus-decode-encoded-word-methods-cache
1529                (eq gnus-newsgroup-name
1530                    (car gnus-decode-encoded-word-methods-cache)))
1531     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1532     (mapcar (lambda (x)
1533               (if (symbolp x)
1534                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1535                 (if (and gnus-newsgroup-name
1536                          (string-match (car x) gnus-newsgroup-name))
1537                     (nconc gnus-decode-encoded-word-methods-cache
1538                            (list (cdr x))))))
1539             gnus-decode-encoded-word-methods))
1540   (let ((xlist gnus-decode-encoded-word-methods-cache))
1541     (pop xlist)
1542     (while xlist
1543       (setq string (funcall (pop xlist) string))))
1544   string)
1545
1546 ;; Subject simplification.
1547
1548 (defun gnus-simplify-whitespace (str)
1549   "Remove excessive whitespace from STR."
1550   ;; Multiple spaces.
1551   (while (string-match "[ \t][ \t]+" str)
1552     (setq str (concat (substring str 0 (match-beginning 0))
1553                         " "
1554                         (substring str (match-end 0)))))
1555   ;; Leading spaces.
1556   (when (string-match "^[ \t]+" str)
1557     (setq str (substring str (match-end 0))))
1558   ;; Trailing spaces.
1559   (when (string-match "[ \t]+$" str)
1560     (setq str (substring str 0 (match-beginning 0))))
1561   str)
1562
1563 (defun gnus-simplify-all-whitespace (str)
1564   "Remove all whitespace from STR."
1565   (while (string-match "[ \t\n]+" str)
1566     (setq str (replace-match "" nil nil str)))
1567   str)
1568
1569 (defsubst gnus-simplify-subject-re (subject)
1570   "Remove \"Re:\" from subject lines."
1571   (if (string-match message-subject-re-regexp subject)
1572       (substring subject (match-end 0))
1573     subject))
1574
1575 (defun gnus-simplify-subject (subject &optional re-only)
1576   "Remove `Re:' and words in parentheses.
1577 If RE-ONLY is non-nil, strip leading `Re:'s only."
1578   (let ((case-fold-search t))           ;Ignore case.
1579     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1580     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1581       (setq subject (substring subject (match-end 0))))
1582     ;; Remove uninteresting prefixes.
1583     (when (and (not re-only)
1584                gnus-simplify-ignored-prefixes
1585                (string-match gnus-simplify-ignored-prefixes subject))
1586       (setq subject (substring subject (match-end 0))))
1587     ;; Remove words in parentheses from end.
1588     (unless re-only
1589       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1590         (setq subject (substring subject 0 (match-beginning 0)))))
1591     ;; Return subject string.
1592     subject))
1593
1594 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1595 ;; all whitespace.
1596 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1597   (goto-char (point-min))
1598   (while (re-search-forward regexp nil t)
1599     (replace-match (or newtext ""))))
1600
1601 (defun gnus-simplify-buffer-fuzzy ()
1602   "Simplify string in the buffer fuzzily.
1603 The string in the accessible portion of the current buffer is simplified.
1604 It is assumed to be a single-line subject.
1605 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1606 matter is removed.  Additional things can be deleted by setting
1607 `gnus-simplify-subject-fuzzy-regexp'."
1608   (let ((case-fold-search t)
1609         (modified-tick))
1610     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1611
1612     (while (not (eq modified-tick (buffer-modified-tick)))
1613       (setq modified-tick (buffer-modified-tick))
1614       (cond
1615        ((listp gnus-simplify-subject-fuzzy-regexp)
1616         (mapcar 'gnus-simplify-buffer-fuzzy-step
1617                 gnus-simplify-subject-fuzzy-regexp))
1618        (gnus-simplify-subject-fuzzy-regexp
1619         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1620       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1621       (gnus-simplify-buffer-fuzzy-step
1622        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1623       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1624
1625     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1626     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1627     (gnus-simplify-buffer-fuzzy-step " $")
1628     (gnus-simplify-buffer-fuzzy-step "^ +")))
1629
1630 (defun gnus-simplify-subject-fuzzy (subject)
1631   "Simplify a subject string fuzzily.
1632 See `gnus-simplify-buffer-fuzzy' for details."
1633   (save-excursion
1634     (gnus-set-work-buffer)
1635     (let ((case-fold-search t))
1636       ;; Remove uninteresting prefixes.
1637       (when (and gnus-simplify-ignored-prefixes
1638                  (string-match gnus-simplify-ignored-prefixes subject))
1639         (setq subject (substring subject (match-end 0))))
1640       (insert subject)
1641       (inline (gnus-simplify-buffer-fuzzy))
1642       (buffer-string))))
1643
1644 (defsubst gnus-simplify-subject-fully (subject)
1645   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1646   (cond
1647    (gnus-simplify-subject-functions
1648     (gnus-map-function gnus-simplify-subject-functions subject))
1649    ((null gnus-summary-gather-subject-limit)
1650     (gnus-simplify-subject-re subject))
1651    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1652     (gnus-simplify-subject-fuzzy subject))
1653    ((numberp gnus-summary-gather-subject-limit)
1654     (gnus-limit-string (gnus-simplify-subject-re subject)
1655                        gnus-summary-gather-subject-limit))
1656    (t
1657     subject)))
1658
1659 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1660   "Check whether two subjects are equal.
1661 If optional argument SIMPLE-FIRST is t, first argument is already
1662 simplified."
1663   (cond
1664    ((null simple-first)
1665     (equal (gnus-simplify-subject-fully s1)
1666            (gnus-simplify-subject-fully s2)))
1667    (t
1668     (equal s1
1669            (gnus-simplify-subject-fully s2)))))
1670
1671 (defun gnus-summary-bubble-group ()
1672   "Increase the score of the current group.
1673 This is a handy function to add to `gnus-summary-exit-hook' to
1674 increase the score of each group you read."
1675   (gnus-group-add-score gnus-newsgroup-name))
1676
1677 \f
1678 ;;;
1679 ;;; Gnus summary mode
1680 ;;;
1681
1682 (put 'gnus-summary-mode 'mode-class 'special)
1683
1684 (defvar gnus-article-commands-menu)
1685
1686 ;; Non-orthogonal keys
1687
1688 (gnus-define-keys gnus-summary-mode-map
1689   " " gnus-summary-next-page
1690   "\177" gnus-summary-prev-page
1691   [delete] gnus-summary-prev-page
1692   [backspace] gnus-summary-prev-page
1693   "\r" gnus-summary-scroll-up
1694   "\M-\r" gnus-summary-scroll-down
1695   "n" gnus-summary-next-unread-article
1696   "p" gnus-summary-prev-unread-article
1697   "N" gnus-summary-next-article
1698   "P" gnus-summary-prev-article
1699   "\M-\C-n" gnus-summary-next-same-subject
1700   "\M-\C-p" gnus-summary-prev-same-subject
1701   "\M-n" gnus-summary-next-unread-subject
1702   "\M-p" gnus-summary-prev-unread-subject
1703   "." gnus-summary-first-unread-article
1704   "," gnus-summary-best-unread-article
1705   "\M-s" gnus-summary-search-article-forward
1706   "\M-r" gnus-summary-search-article-backward
1707   "<" gnus-summary-beginning-of-article
1708   ">" gnus-summary-end-of-article
1709   "j" gnus-summary-goto-article
1710   "^" gnus-summary-refer-parent-article
1711   "\M-^" gnus-summary-refer-article
1712   "u" gnus-summary-tick-article-forward
1713   "!" gnus-summary-tick-article-forward
1714   "U" gnus-summary-tick-article-backward
1715   "d" gnus-summary-mark-as-read-forward
1716   "D" gnus-summary-mark-as-read-backward
1717   "E" gnus-summary-mark-as-expirable
1718   "\M-u" gnus-summary-clear-mark-forward
1719   "\M-U" gnus-summary-clear-mark-backward
1720   "k" gnus-summary-kill-same-subject-and-select
1721   "\C-k" gnus-summary-kill-same-subject
1722   "\M-\C-k" gnus-summary-kill-thread
1723   "\M-\C-l" gnus-summary-lower-thread
1724   "e" gnus-summary-edit-article
1725   "#" gnus-summary-mark-as-processable
1726   "\M-#" gnus-summary-unmark-as-processable
1727   "\M-\C-t" gnus-summary-toggle-threads
1728   "\M-\C-s" gnus-summary-show-thread
1729   "\M-\C-h" gnus-summary-hide-thread
1730   "\M-\C-f" gnus-summary-next-thread
1731   "\M-\C-b" gnus-summary-prev-thread
1732   [(meta down)] gnus-summary-next-thread
1733   [(meta up)] gnus-summary-prev-thread
1734   "\M-\C-u" gnus-summary-up-thread
1735   "\M-\C-d" gnus-summary-down-thread
1736   "&" gnus-summary-execute-command
1737   "c" gnus-summary-catchup-and-exit
1738   "\C-w" gnus-summary-mark-region-as-read
1739   "\C-t" gnus-summary-toggle-truncation
1740   "?" gnus-summary-mark-as-dormant
1741   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1742   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1743   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1744   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1745   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1746   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1747   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1748   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1749   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1750   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1751   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1752   "=" gnus-summary-expand-window
1753   "\C-x\C-s" gnus-summary-reselect-current-group
1754   "\M-g" gnus-summary-rescan-group
1755   "w" gnus-summary-stop-page-breaking
1756   "\C-c\C-r" gnus-summary-caesar-message
1757   "f" gnus-summary-followup
1758   "F" gnus-summary-followup-with-original
1759   "C" gnus-summary-cancel-article
1760   "r" gnus-summary-reply
1761   "R" gnus-summary-reply-with-original
1762   "\C-c\C-f" gnus-summary-mail-forward
1763   "o" gnus-summary-save-article
1764   "\C-o" gnus-summary-save-article-mail
1765   "|" gnus-summary-pipe-output
1766   "\M-k" gnus-summary-edit-local-kill
1767   "\M-K" gnus-summary-edit-global-kill
1768   ;; "V" gnus-version
1769   "\C-c\C-d" gnus-summary-describe-group
1770   "q" gnus-summary-exit
1771   "Q" gnus-summary-exit-no-update
1772   "\C-c\C-i" gnus-info-find-node
1773   gnus-mouse-2 gnus-mouse-pick-article
1774   [follow-link] mouse-face
1775   "m" gnus-summary-mail-other-window
1776   "a" gnus-summary-post-news
1777   "i" gnus-summary-news-other-window
1778   "x" gnus-summary-limit-to-unread
1779   "s" gnus-summary-isearch-article
1780   "t" gnus-summary-toggle-header
1781   "g" gnus-summary-show-article
1782   "l" gnus-summary-goto-last-article
1783   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1784   "\C-d" gnus-summary-enter-digest-group
1785   "\M-\C-d" gnus-summary-read-document
1786   "\M-\C-e" gnus-summary-edit-parameters
1787   "\M-\C-a" gnus-summary-customize-parameters
1788   "\C-c\C-b" gnus-bug
1789   "*" gnus-cache-enter-article
1790   "\M-*" gnus-cache-remove-article
1791   "\M-&" gnus-summary-universal-argument
1792   "\C-l" gnus-recenter
1793   "I" gnus-summary-increase-score
1794   "L" gnus-summary-lower-score
1795   "\M-i" gnus-symbolic-argument
1796   "h" gnus-summary-select-article-buffer
1797
1798   "b" gnus-article-view-part
1799   "\M-t" gnus-summary-toggle-display-buttonized
1800
1801   "V" gnus-summary-score-map
1802   "X" gnus-uu-extract-map
1803   "S" gnus-summary-send-map)
1804
1805 ;; Sort of orthogonal keymap
1806 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1807   "t" gnus-summary-tick-article-forward
1808   "!" gnus-summary-tick-article-forward
1809   "d" gnus-summary-mark-as-read-forward
1810   "r" gnus-summary-mark-as-read-forward
1811   "c" gnus-summary-clear-mark-forward
1812   " " gnus-summary-clear-mark-forward
1813   "e" gnus-summary-mark-as-expirable
1814   "x" gnus-summary-mark-as-expirable
1815   "?" gnus-summary-mark-as-dormant
1816   "b" gnus-summary-set-bookmark
1817   "B" gnus-summary-remove-bookmark
1818   "#" gnus-summary-mark-as-processable
1819   "\M-#" gnus-summary-unmark-as-processable
1820   "S" gnus-summary-limit-include-expunged
1821   "C" gnus-summary-catchup
1822   "H" gnus-summary-catchup-to-here
1823   "h" gnus-summary-catchup-from-here
1824   "\C-c" gnus-summary-catchup-all
1825   "k" gnus-summary-kill-same-subject-and-select
1826   "K" gnus-summary-kill-same-subject
1827   "P" gnus-uu-mark-map)
1828
1829 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1830   "c" gnus-summary-clear-above
1831   "u" gnus-summary-tick-above
1832   "m" gnus-summary-mark-above
1833   "k" gnus-summary-kill-below)
1834
1835 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1836   "/" gnus-summary-limit-to-subject
1837   "n" gnus-summary-limit-to-articles
1838   "w" gnus-summary-pop-limit
1839   "s" gnus-summary-limit-to-subject
1840   "a" gnus-summary-limit-to-author
1841   "u" gnus-summary-limit-to-unread
1842   "m" gnus-summary-limit-to-marks
1843   "M" gnus-summary-limit-exclude-marks
1844   "v" gnus-summary-limit-to-score
1845   "*" gnus-summary-limit-include-cached
1846   "D" gnus-summary-limit-include-dormant
1847   "T" gnus-summary-limit-include-thread
1848   "d" gnus-summary-limit-exclude-dormant
1849   "t" gnus-summary-limit-to-age
1850   "." gnus-summary-limit-to-unseen
1851   "x" gnus-summary-limit-to-extra
1852   "p" gnus-summary-limit-to-display-predicate
1853   "E" gnus-summary-limit-include-expunged
1854   "c" gnus-summary-limit-exclude-childless-dormant
1855   "C" gnus-summary-limit-mark-excluded-as-read
1856   "o" gnus-summary-insert-old-articles
1857   "N" gnus-summary-insert-new-articles
1858   "r" gnus-summary-limit-to-replied
1859   "R" gnus-summary-limit-to-recipient)
1860
1861 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1862   "n" gnus-summary-next-unread-article
1863   "p" gnus-summary-prev-unread-article
1864   "N" gnus-summary-next-article
1865   "P" gnus-summary-prev-article
1866   "\C-n" gnus-summary-next-same-subject
1867   "\C-p" gnus-summary-prev-same-subject
1868   "\M-n" gnus-summary-next-unread-subject
1869   "\M-p" gnus-summary-prev-unread-subject
1870   "f" gnus-summary-first-unread-article
1871   "b" gnus-summary-best-unread-article
1872   "j" gnus-summary-goto-article
1873   "g" gnus-summary-goto-subject
1874   "l" gnus-summary-goto-last-article
1875   "o" gnus-summary-pop-article)
1876
1877 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1878   "k" gnus-summary-kill-thread
1879   "l" gnus-summary-lower-thread
1880   "i" gnus-summary-raise-thread
1881   "T" gnus-summary-toggle-threads
1882   "t" gnus-summary-rethread-current
1883   "^" gnus-summary-reparent-thread
1884   "s" gnus-summary-show-thread
1885   "S" gnus-summary-show-all-threads
1886   "h" gnus-summary-hide-thread
1887   "H" gnus-summary-hide-all-threads
1888   "n" gnus-summary-next-thread
1889   "p" gnus-summary-prev-thread
1890   "u" gnus-summary-up-thread
1891   "o" gnus-summary-top-thread
1892   "d" gnus-summary-down-thread
1893   "#" gnus-uu-mark-thread
1894   "\M-#" gnus-uu-unmark-thread)
1895
1896 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1897   "g" gnus-summary-prepare
1898   "c" gnus-summary-insert-cached-articles
1899   "d" gnus-summary-insert-dormant-articles)
1900
1901 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1902   "c" gnus-summary-catchup-and-exit
1903   "C" gnus-summary-catchup-all-and-exit
1904   "E" gnus-summary-exit-no-update
1905   "Q" gnus-summary-exit
1906   "Z" gnus-summary-exit
1907   "n" gnus-summary-catchup-and-goto-next-group
1908   "R" gnus-summary-reselect-current-group
1909   "G" gnus-summary-rescan-group
1910   "N" gnus-summary-next-group
1911   "s" gnus-summary-save-newsrc
1912   "P" gnus-summary-prev-group)
1913
1914 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1915   " " gnus-summary-next-page
1916   "n" gnus-summary-next-page
1917   "\177" gnus-summary-prev-page
1918   [delete] gnus-summary-prev-page
1919   "p" gnus-summary-prev-page
1920   "\r" gnus-summary-scroll-up
1921   "\M-\r" gnus-summary-scroll-down
1922   "<" gnus-summary-beginning-of-article
1923   ">" gnus-summary-end-of-article
1924   "b" gnus-summary-beginning-of-article
1925   "e" gnus-summary-end-of-article
1926   "^" gnus-summary-refer-parent-article
1927   "r" gnus-summary-refer-parent-article
1928   "D" gnus-summary-enter-digest-group
1929   "R" gnus-summary-refer-references
1930   "T" gnus-summary-refer-thread
1931   "g" gnus-summary-show-article
1932   "s" gnus-summary-isearch-article
1933   "P" gnus-summary-print-article
1934   "M" gnus-mailing-list-insinuate
1935   "t" gnus-article-babel)
1936
1937 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1938   "b" gnus-article-add-buttons
1939   "B" gnus-article-add-buttons-to-head
1940   "o" gnus-article-treat-overstrike
1941   "e" gnus-article-emphasize
1942   "w" gnus-article-fill-cited-article
1943   "Q" gnus-article-fill-long-lines
1944   "C" gnus-article-capitalize-sentences
1945   "c" gnus-article-remove-cr
1946   "q" gnus-article-de-quoted-unreadable
1947   "6" gnus-article-de-base64-unreadable
1948   "Z" gnus-article-decode-HZ
1949   "A" gnus-article-treat-ansi-sequences
1950   "h" gnus-article-wash-html
1951   "u" gnus-article-unsplit-urls
1952   "s" gnus-summary-force-verify-and-decrypt
1953   "f" gnus-article-display-x-face
1954   "l" gnus-summary-stop-page-breaking
1955   "r" gnus-summary-caesar-message
1956   "m" gnus-summary-morse-message
1957   "t" gnus-summary-toggle-header
1958   "g" gnus-treat-smiley
1959   "v" gnus-summary-verbose-headers
1960   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1961   "p" gnus-article-verify-x-pgp-sig
1962   "d" gnus-article-treat-dumbquotes
1963   "i" gnus-summary-idna-message)
1964
1965 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1966   ;; mnemonic: deuglif*Y*
1967   "u" gnus-article-outlook-unwrap-lines
1968   "a" gnus-article-outlook-repair-attribution
1969   "c" gnus-article-outlook-rearrange-citation
1970   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1971
1972 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1973   "a" gnus-article-hide
1974   "h" gnus-article-hide-headers
1975   "b" gnus-article-hide-boring-headers
1976   "s" gnus-article-hide-signature
1977   "c" gnus-article-hide-citation
1978   "C" gnus-article-hide-citation-in-followups
1979   "l" gnus-article-hide-list-identifiers
1980   "B" gnus-article-strip-banner
1981   "P" gnus-article-hide-pem
1982   "\C-c" gnus-article-hide-citation-maybe)
1983
1984 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1985   "a" gnus-article-highlight
1986   "h" gnus-article-highlight-headers
1987   "c" gnus-article-highlight-citation
1988   "s" gnus-article-highlight-signature)
1989
1990 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1991   "f" gnus-article-treat-fold-headers
1992   "u" gnus-article-treat-unfold-headers
1993   "n" gnus-article-treat-fold-newsgroups)
1994
1995 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1996   "x" gnus-article-display-x-face
1997   "d" gnus-article-display-face
1998   "s" gnus-treat-smiley
1999   "D" gnus-article-remove-images
2000   "f" gnus-treat-from-picon
2001   "m" gnus-treat-mail-picon
2002   "n" gnus-treat-newsgroups-picon)
2003
2004 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2005   "w" gnus-article-decode-mime-words
2006   "c" gnus-article-decode-charset
2007   "v" gnus-mime-view-all-parts
2008   "b" gnus-article-view-part)
2009
2010 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2011   "z" gnus-article-date-ut
2012   "u" gnus-article-date-ut
2013   "l" gnus-article-date-local
2014   "p" gnus-article-date-english
2015   "e" gnus-article-date-lapsed
2016   "o" gnus-article-date-original
2017   "i" gnus-article-date-iso8601
2018   "s" gnus-article-date-user)
2019
2020 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2021   "t" gnus-article-remove-trailing-blank-lines
2022   "l" gnus-article-strip-leading-blank-lines
2023   "m" gnus-article-strip-multiple-blank-lines
2024   "a" gnus-article-strip-blank-lines
2025   "A" gnus-article-strip-all-blank-lines
2026   "s" gnus-article-strip-leading-space
2027   "e" gnus-article-strip-trailing-space
2028   "w" gnus-article-remove-leading-whitespace)
2029
2030 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2031   "v" gnus-version
2032   "f" gnus-summary-fetch-faq
2033   "d" gnus-summary-describe-group
2034   "h" gnus-summary-describe-briefly
2035   "i" gnus-info-find-node
2036   "c" gnus-group-fetch-charter
2037   "C" gnus-group-fetch-control)
2038
2039 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2040   "e" gnus-summary-expire-articles
2041   "\M-\C-e" gnus-summary-expire-articles-now
2042   "\177" gnus-summary-delete-article
2043   [delete] gnus-summary-delete-article
2044   [backspace] gnus-summary-delete-article
2045   "m" gnus-summary-move-article
2046   "r" gnus-summary-respool-article
2047   "w" gnus-summary-edit-article
2048   "c" gnus-summary-copy-article
2049   "B" gnus-summary-crosspost-article
2050   "q" gnus-summary-respool-query
2051   "t" gnus-summary-respool-trace
2052   "i" gnus-summary-import-article
2053   "I" gnus-summary-create-article
2054   "p" gnus-summary-article-posted-p)
2055
2056 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2057   "o" gnus-summary-save-article
2058   "m" gnus-summary-save-article-mail
2059   "F" gnus-summary-write-article-file
2060   "r" gnus-summary-save-article-rmail
2061   "f" gnus-summary-save-article-file
2062   "b" gnus-summary-save-article-body-file
2063   "h" gnus-summary-save-article-folder
2064   "v" gnus-summary-save-article-vm
2065   "p" gnus-summary-pipe-output
2066   "P" gnus-summary-muttprint
2067   "s" gnus-soup-add-article)
2068
2069 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2070   "b" gnus-summary-display-buttonized
2071   "m" gnus-summary-repair-multipart
2072   "v" gnus-article-view-part
2073   "o" gnus-article-save-part
2074   "c" gnus-article-copy-part
2075   "C" gnus-article-view-part-as-charset
2076   "e" gnus-article-view-part-externally
2077   "E" gnus-article-encrypt-body
2078   "i" gnus-article-inline-part
2079   "|" gnus-article-pipe-part)
2080
2081 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2082   "p" gnus-summary-mark-as-processable
2083   "u" gnus-summary-unmark-as-processable
2084   "U" gnus-summary-unmark-all-processable
2085   "v" gnus-uu-mark-over
2086   "s" gnus-uu-mark-series
2087   "r" gnus-uu-mark-region
2088   "g" gnus-uu-unmark-region
2089   "R" gnus-uu-mark-by-regexp
2090   "G" gnus-uu-unmark-by-regexp
2091   "t" gnus-uu-mark-thread
2092   "T" gnus-uu-unmark-thread
2093   "a" gnus-uu-mark-all
2094   "b" gnus-uu-mark-buffer
2095   "S" gnus-uu-mark-sparse
2096   "k" gnus-summary-kill-process-mark
2097   "y" gnus-summary-yank-process-mark
2098   "w" gnus-summary-save-process-mark
2099   "i" gnus-uu-invert-processable)
2100
2101 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2102   ;;"x" gnus-uu-extract-any
2103   "m" gnus-summary-save-parts
2104   "u" gnus-uu-decode-uu
2105   "U" gnus-uu-decode-uu-and-save
2106   "s" gnus-uu-decode-unshar
2107   "S" gnus-uu-decode-unshar-and-save
2108   "o" gnus-uu-decode-save
2109   "O" gnus-uu-decode-save
2110   "b" gnus-uu-decode-binhex
2111   "B" gnus-uu-decode-binhex
2112   "p" gnus-uu-decode-postscript
2113   "P" gnus-uu-decode-postscript-and-save)
2114
2115 (gnus-define-keys
2116     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2117   "u" gnus-uu-decode-uu-view
2118   "U" gnus-uu-decode-uu-and-save-view
2119   "s" gnus-uu-decode-unshar-view
2120   "S" gnus-uu-decode-unshar-and-save-view
2121   "o" gnus-uu-decode-save-view
2122   "O" gnus-uu-decode-save-view
2123   "b" gnus-uu-decode-binhex-view
2124   "B" gnus-uu-decode-binhex-view
2125   "p" gnus-uu-decode-postscript-view
2126   "P" gnus-uu-decode-postscript-and-save-view)
2127
2128 (defvar gnus-article-post-menu nil)
2129
2130 (defconst gnus-summary-menu-maxlen 20)
2131
2132 (defun gnus-summary-menu-split (menu)
2133   ;; If we have lots of elements, divide them into groups of 20
2134   ;; and make a pane (or submenu) for each one.
2135   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2136       (let ((menu menu) sublists next
2137             (i 1))
2138         (while menu
2139           ;; Pull off the next gnus-summary-menu-maxlen elements
2140           ;; and make them the next element of sublist.
2141           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2142           (if next
2143               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2144                       nil))
2145           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2146                                              (aref (car (last menu)) 0)) menu)
2147                                sublists))
2148           (setq i (1+ i))
2149           (setq menu next))
2150         (nreverse sublists))
2151     ;; Few elements--put them all in one pane.
2152     menu))
2153
2154 (defun gnus-summary-make-menu-bar ()
2155   (gnus-turn-off-edit-menu 'summary)
2156
2157   (unless (boundp 'gnus-summary-misc-menu)
2158
2159     (easy-menu-define
2160       gnus-summary-kill-menu gnus-summary-mode-map ""
2161       (cons
2162        "Score"
2163        (nconc
2164         (list
2165          ["Customize" gnus-score-customize t])
2166         (gnus-make-score-map 'increase)
2167         (gnus-make-score-map 'lower)
2168         '(("Mark"
2169            ["Kill below" gnus-summary-kill-below t]
2170            ["Mark above" gnus-summary-mark-above t]
2171            ["Tick above" gnus-summary-tick-above t]
2172            ["Clear above" gnus-summary-clear-above t])
2173           ["Current score" gnus-summary-current-score t]
2174           ["Set score" gnus-summary-set-score t]
2175           ["Switch current score file..." gnus-score-change-score-file t]
2176           ["Set mark below..." gnus-score-set-mark-below t]
2177           ["Set expunge below..." gnus-score-set-expunge-below t]
2178           ["Edit current score file" gnus-score-edit-current-scores t]
2179           ["Edit score file" gnus-score-edit-file t]
2180           ["Trace score" gnus-score-find-trace t]
2181           ["Find words" gnus-score-find-favourite-words t]
2182           ["Rescore buffer" gnus-summary-rescore t]
2183           ["Increase score..." gnus-summary-increase-score t]
2184           ["Lower score..." gnus-summary-lower-score t]))))
2185
2186     ;; Define both the Article menu in the summary buffer and the
2187     ;; equivalent Commands menu in the article buffer here for
2188     ;; consistency.
2189     (let ((innards
2190            `(("Hide"
2191               ["All" gnus-article-hide t]
2192               ["Headers" gnus-article-hide-headers t]
2193               ["Signature" gnus-article-hide-signature t]
2194               ["Citation" gnus-article-hide-citation t]
2195               ["List identifiers" gnus-article-hide-list-identifiers t]
2196               ["Banner" gnus-article-strip-banner t]
2197               ["Boring headers" gnus-article-hide-boring-headers t])
2198              ("Highlight"
2199               ["All" gnus-article-highlight t]
2200               ["Headers" gnus-article-highlight-headers t]
2201               ["Signature" gnus-article-highlight-signature t]
2202               ["Citation" gnus-article-highlight-citation t])
2203              ("MIME"
2204               ["Words" gnus-article-decode-mime-words t]
2205               ["Charset" gnus-article-decode-charset t]
2206               ["QP" gnus-article-de-quoted-unreadable t]
2207               ["Base64" gnus-article-de-base64-unreadable t]
2208               ["View MIME buttons" gnus-summary-display-buttonized t]
2209               ["View all" gnus-mime-view-all-parts t]
2210               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2211               ["Encrypt body" gnus-article-encrypt-body
2212                :active (not (gnus-group-read-only-p))
2213                ,@(if (featurep 'xemacs) nil
2214                    '(:help "Encrypt the message body on disk"))]
2215               ["Extract all parts..." gnus-summary-save-parts t]
2216               ("Multipart"
2217                ["Repair multipart" gnus-summary-repair-multipart t]
2218                ["Pipe part..." gnus-article-pipe-part t]
2219                ["Inline part" gnus-article-inline-part t]
2220                ["Encrypt body" gnus-article-encrypt-body
2221                 :active (not (gnus-group-read-only-p))
2222                ,@(if (featurep 'xemacs) nil
2223                    '(:help "Encrypt the message body on disk"))]
2224                ["View part externally" gnus-article-view-part-externally t]
2225                ["View part with charset..." gnus-article-view-part-as-charset t]
2226                ["Copy part" gnus-article-copy-part t]
2227                ["Save part..." gnus-article-save-part t]
2228                ["View part" gnus-article-view-part t]))
2229              ("Date"
2230               ["Local" gnus-article-date-local t]
2231               ["ISO8601" gnus-article-date-iso8601 t]
2232               ["UT" gnus-article-date-ut t]
2233               ["Original" gnus-article-date-original t]
2234               ["Lapsed" gnus-article-date-lapsed t]
2235               ["User-defined" gnus-article-date-user t])
2236              ("Display"
2237               ["Remove images" gnus-article-remove-images t]
2238               ["Toggle smiley" gnus-treat-smiley t]
2239               ["Show X-Face" gnus-article-display-x-face t]
2240               ["Show picons in From" gnus-treat-from-picon t]
2241               ["Show picons in mail headers" gnus-treat-mail-picon t]
2242               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2243               ("View as different encoding"
2244                ,@(gnus-summary-menu-split
2245                   (mapcar
2246                    (lambda (cs)
2247                      ;; Since easymenu under Emacs doesn't allow
2248                      ;; lambda forms for menu commands, we should
2249                      ;; provide intern'ed function symbols.
2250                      (let ((command (intern (format "\
2251 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2252                        (fset command
2253                              `(lambda ()
2254                                 (interactive)
2255                                 (let ((gnus-summary-show-article-charset-alist
2256                                        '((1 . ,cs))))
2257                                   (gnus-summary-show-article 1))))
2258                        `[,(symbol-name cs) ,command t]))
2259                    (sort (if (fboundp 'coding-system-list)
2260                              (coding-system-list)
2261                            (mapcar 'car mm-mime-mule-charset-alist))
2262                          'string<)))))
2263              ("Washing"
2264               ("Remove Blanks"
2265                ["Leading" gnus-article-strip-leading-blank-lines t]
2266                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2267                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2268                ["All of the above" gnus-article-strip-blank-lines t]
2269                ["All" gnus-article-strip-all-blank-lines t]
2270                ["Leading space" gnus-article-strip-leading-space t]
2271                ["Trailing space" gnus-article-strip-trailing-space t]
2272                ["Leading space in headers"
2273                 gnus-article-remove-leading-whitespace t])
2274               ["Overstrike" gnus-article-treat-overstrike t]
2275               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2276               ["Emphasis" gnus-article-emphasize t]
2277               ["Word wrap" gnus-article-fill-cited-article t]
2278               ["Fill long lines" gnus-article-fill-long-lines t]
2279               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2280               ["Remove CR" gnus-article-remove-cr t]
2281               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2282               ["Base64" gnus-article-de-base64-unreadable t]
2283               ["Rot 13" gnus-summary-caesar-message
2284                ,@(if (featurep 'xemacs) '(t)
2285                    '(:help "\"Caesar rotate\" article by 13"))]
2286               ["De-IDNA" gnus-summary-idna-message t]
2287               ["Morse decode" gnus-summary-morse-message t]
2288               ["Unix pipe..." gnus-summary-pipe-message t]
2289               ["Add buttons" gnus-article-add-buttons t]
2290               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2291               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2292               ["Verbose header" gnus-summary-verbose-headers t]
2293               ["Toggle header" gnus-summary-toggle-header t]
2294               ["Unfold headers" gnus-article-treat-unfold-headers t]
2295               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2296               ["Html" gnus-article-wash-html t]
2297               ["Unsplit URLs" gnus-article-unsplit-urls t]
2298               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2299               ["Decode HZ" gnus-article-decode-HZ t]
2300               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2301               ("(Outlook) Deuglify"
2302                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2303                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2304                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2305                ["Full (Outlook) deuglify"
2306                 gnus-article-outlook-deuglify-article t])
2307               )
2308              ("Output"
2309               ["Save in default format..." gnus-summary-save-article
2310                ,@(if (featurep 'xemacs) '(t)
2311                    '(:help "Save article using default method"))]
2312               ["Save in file..." gnus-summary-save-article-file
2313                ,@(if (featurep 'xemacs) '(t)
2314                    '(:help "Save article in file"))]
2315               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2316               ["Save in MH folder..." gnus-summary-save-article-folder t]
2317               ["Save in VM folder..." gnus-summary-save-article-vm t]
2318               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2319               ["Save body in file..." gnus-summary-save-article-body-file t]
2320               ["Pipe through a filter..." gnus-summary-pipe-output t]
2321               ["Add to SOUP packet" gnus-soup-add-article t]
2322               ["Print with Muttprint..." gnus-summary-muttprint t]
2323               ["Print" gnus-summary-print-article
2324                ,@(if (featurep 'xemacs) '(t)
2325                    '(:help "Generate and print a PostScript image"))])
2326              ("Copy, move,... (Backend)"
2327               ,@(if (featurep 'xemacs) nil
2328                   '(:help "Copying, moving, expiring articles..."))
2329               ["Respool article..." gnus-summary-respool-article t]
2330               ["Move article..." gnus-summary-move-article
2331                (gnus-check-backend-function
2332                 'request-move-article gnus-newsgroup-name)]
2333               ["Copy article..." gnus-summary-copy-article t]
2334               ["Crosspost article..." gnus-summary-crosspost-article
2335                (gnus-check-backend-function
2336                 'request-replace-article gnus-newsgroup-name)]
2337               ["Import file..." gnus-summary-import-article
2338                (gnus-check-backend-function
2339                 'request-accept-article gnus-newsgroup-name)]
2340               ["Create article..." gnus-summary-create-article
2341                (gnus-check-backend-function
2342                 'request-accept-article gnus-newsgroup-name)]
2343               ["Check if posted" gnus-summary-article-posted-p t]
2344               ["Edit article" gnus-summary-edit-article
2345                (not (gnus-group-read-only-p))]
2346               ["Delete article" gnus-summary-delete-article
2347                (gnus-check-backend-function
2348                 'request-expire-articles gnus-newsgroup-name)]
2349               ["Query respool" gnus-summary-respool-query t]
2350               ["Trace respool" gnus-summary-respool-trace t]
2351               ["Delete expirable articles" gnus-summary-expire-articles-now
2352                (gnus-check-backend-function
2353                 'request-expire-articles gnus-newsgroup-name)])
2354              ("Extract"
2355               ["Uudecode" gnus-uu-decode-uu
2356                ,@(if (featurep 'xemacs) '(t)
2357                    '(:help "Decode uuencoded article(s)"))]
2358               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2359               ["Unshar" gnus-uu-decode-unshar t]
2360               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2361               ["Save" gnus-uu-decode-save t]
2362               ["Binhex" gnus-uu-decode-binhex t]
2363               ["Postscript" gnus-uu-decode-postscript t]
2364               ["All MIME parts" gnus-summary-save-parts t])
2365              ("Cache"
2366               ["Enter article" gnus-cache-enter-article t]
2367               ["Remove article" gnus-cache-remove-article t])
2368              ["Translate" gnus-article-babel t]
2369              ["Select article buffer" gnus-summary-select-article-buffer t]
2370              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2371              ["Isearch article..." gnus-summary-isearch-article t]
2372              ["Beginning of the article" gnus-summary-beginning-of-article t]
2373              ["End of the article" gnus-summary-end-of-article t]
2374              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2375              ["Fetch referenced articles" gnus-summary-refer-references t]
2376              ["Fetch current thread" gnus-summary-refer-thread t]
2377              ["Fetch article with id..." gnus-summary-refer-article t]
2378              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2379              ["Redisplay" gnus-summary-show-article t]
2380              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2381       (easy-menu-define
2382         gnus-summary-article-menu gnus-summary-mode-map ""
2383         (cons "Article" innards))
2384
2385       (if (not (keymapp gnus-summary-article-menu))
2386           (easy-menu-define
2387             gnus-article-commands-menu gnus-article-mode-map ""
2388             (cons "Commands" innards))
2389         ;; in Emacs, don't share menu.
2390         (setq gnus-article-commands-menu
2391               (copy-keymap gnus-summary-article-menu))
2392         (define-key gnus-article-mode-map [menu-bar commands]
2393           (cons "Commands" gnus-article-commands-menu))))
2394
2395     (easy-menu-define
2396       gnus-summary-thread-menu gnus-summary-mode-map ""
2397       '("Threads"
2398         ["Find all messages in thread" gnus-summary-refer-thread t]
2399         ["Toggle threading" gnus-summary-toggle-threads t]
2400         ["Hide threads" gnus-summary-hide-all-threads t]
2401         ["Show threads" gnus-summary-show-all-threads t]
2402         ["Hide thread" gnus-summary-hide-thread t]
2403         ["Show thread" gnus-summary-show-thread t]
2404         ["Go to next thread" gnus-summary-next-thread t]
2405         ["Go to previous thread" gnus-summary-prev-thread t]
2406         ["Go down thread" gnus-summary-down-thread t]
2407         ["Go up thread" gnus-summary-up-thread t]
2408         ["Top of thread" gnus-summary-top-thread t]
2409         ["Mark thread as read" gnus-summary-kill-thread t]
2410         ["Lower thread score" gnus-summary-lower-thread t]
2411         ["Raise thread score" gnus-summary-raise-thread t]
2412         ["Rethread current" gnus-summary-rethread-current t]))
2413
2414     (easy-menu-define
2415       gnus-summary-post-menu gnus-summary-mode-map ""
2416       `("Post"
2417         ["Send a message (mail or news)" gnus-summary-post-news
2418          ,@(if (featurep 'xemacs) '(t)
2419              '(:help "Compose a new message (mail or news)"))]
2420         ["Followup" gnus-summary-followup
2421          ,@(if (featurep 'xemacs) '(t)
2422              '(:help "Post followup to this article"))]
2423         ["Followup and yank" gnus-summary-followup-with-original
2424          ,@(if (featurep 'xemacs) '(t)
2425              '(:help "Post followup to this article, quoting its contents"))]
2426         ["Supersede article" gnus-summary-supersede-article t]
2427         ["Cancel article" gnus-summary-cancel-article
2428          ,@(if (featurep 'xemacs) '(t)
2429              '(:help "Cancel an article you posted"))]
2430         ["Reply" gnus-summary-reply t]
2431         ["Reply and yank" gnus-summary-reply-with-original t]
2432         ["Wide reply" gnus-summary-wide-reply t]
2433         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Mail a reply, quoting this article"))]
2436         ["Very wide reply" gnus-summary-very-wide-reply t]
2437         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2438          ,@(if (featurep 'xemacs) '(t)
2439              '(:help "Mail a very wide reply, quoting this article"))]
2440         ["Mail forward" gnus-summary-mail-forward t]
2441         ["Post forward" gnus-summary-post-forward t]
2442         ["Digest and mail" gnus-uu-digest-mail-forward t]
2443         ["Digest and post" gnus-uu-digest-post-forward t]
2444         ["Resend message" gnus-summary-resend-message t]
2445         ["Resend message edit" gnus-summary-resend-message-edit t]
2446         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2447         ["Send a mail" gnus-summary-mail-other-window t]
2448         ["Create a local message" gnus-summary-news-other-window t]
2449         ["Uuencode and post" gnus-uu-post-news
2450          ,@(if (featurep 'xemacs) '(t)
2451              '(:help "Post a uuencoded article"))]
2452         ["Followup via news" gnus-summary-followup-to-mail t]
2453         ["Followup via news and yank"
2454          gnus-summary-followup-to-mail-with-original t]
2455         ;;("Draft"
2456         ;;["Send" gnus-summary-send-draft t]
2457         ;;["Send bounced" gnus-resend-bounced-mail t])
2458         ))
2459
2460     (cond
2461      ((not (keymapp gnus-summary-post-menu))
2462       (setq gnus-article-post-menu gnus-summary-post-menu))
2463      ((not gnus-article-post-menu)
2464       ;; Don't share post menu.
2465       (setq gnus-article-post-menu
2466             (copy-keymap gnus-summary-post-menu))))
2467     (define-key gnus-article-mode-map [menu-bar post]
2468       (cons "Post" gnus-article-post-menu))
2469
2470     (easy-menu-define
2471       gnus-summary-misc-menu gnus-summary-mode-map ""
2472       `("Gnus"
2473         ("Mark Read"
2474          ["Mark as read" gnus-summary-mark-as-read-forward t]
2475          ["Mark same subject and select"
2476           gnus-summary-kill-same-subject-and-select t]
2477          ["Mark same subject" gnus-summary-kill-same-subject t]
2478          ["Catchup" gnus-summary-catchup
2479           ,@(if (featurep 'xemacs) '(t)
2480               '(:help "Mark unread articles in this group as read"))]
2481          ["Catchup all" gnus-summary-catchup-all t]
2482          ["Catchup to here" gnus-summary-catchup-to-here t]
2483          ["Catchup from here" gnus-summary-catchup-from-here t]
2484          ["Catchup region" gnus-summary-mark-region-as-read
2485           (gnus-mark-active-p)]
2486          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2487         ("Mark Various"
2488          ["Tick" gnus-summary-tick-article-forward t]
2489          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2490          ["Remove marks" gnus-summary-clear-mark-forward t]
2491          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2492          ["Set bookmark" gnus-summary-set-bookmark t]
2493          ["Remove bookmark" gnus-summary-remove-bookmark t])
2494         ("Limit to"
2495          ["Marks..." gnus-summary-limit-to-marks t]
2496          ["Subject..." gnus-summary-limit-to-subject t]
2497          ["Author..." gnus-summary-limit-to-author t]
2498          ["Recipient..." gnus-summary-limit-to-recipient t]
2499          ["Age..." gnus-summary-limit-to-age t]
2500          ["Extra..." gnus-summary-limit-to-extra t]
2501          ["Score..." gnus-summary-limit-to-score t]
2502          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2503          ["Unread" gnus-summary-limit-to-unread t]
2504          ["Unseen" gnus-summary-limit-to-unseen t]
2505          ["Replied" gnus-summary-limit-to-replied t]
2506          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2507          ["Next articles" gnus-summary-limit-to-articles t]
2508          ["Pop limit" gnus-summary-pop-limit t]
2509          ["Show dormant" gnus-summary-limit-include-dormant t]
2510          ["Hide childless dormant"
2511           gnus-summary-limit-exclude-childless-dormant t]
2512          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2513          ["Hide marked" gnus-summary-limit-exclude-marks t]
2514          ["Show expunged" gnus-summary-limit-include-expunged t])
2515         ("Process Mark"
2516          ["Set mark" gnus-summary-mark-as-processable t]
2517          ["Remove mark" gnus-summary-unmark-as-processable t]
2518          ["Remove all marks" gnus-summary-unmark-all-processable t]
2519          ["Invert marks" gnus-uu-invert-processable t]
2520          ["Mark above" gnus-uu-mark-over t]
2521          ["Mark series" gnus-uu-mark-series t]
2522          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2523          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2524          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2525          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2526          ["Mark all" gnus-uu-mark-all t]
2527          ["Mark buffer" gnus-uu-mark-buffer t]
2528          ["Mark sparse" gnus-uu-mark-sparse t]
2529          ["Mark thread" gnus-uu-mark-thread t]
2530          ["Unmark thread" gnus-uu-unmark-thread t]
2531          ("Process Mark Sets"
2532           ["Kill" gnus-summary-kill-process-mark t]
2533           ["Yank" gnus-summary-yank-process-mark
2534            gnus-newsgroup-process-stack]
2535           ["Save" gnus-summary-save-process-mark t]
2536           ["Run command on marked..." gnus-summary-universal-argument t]))
2537         ("Scroll article"
2538          ["Page forward" gnus-summary-next-page
2539           ,@(if (featurep 'xemacs) '(t)
2540               '(:help "Show next page of article"))]
2541          ["Page backward" gnus-summary-prev-page
2542           ,@(if (featurep 'xemacs) '(t)
2543               '(:help "Show previous page of article"))]
2544          ["Line forward" gnus-summary-scroll-up t])
2545         ("Move"
2546          ["Next unread article" gnus-summary-next-unread-article t]
2547          ["Previous unread article" gnus-summary-prev-unread-article t]
2548          ["Next article" gnus-summary-next-article t]
2549          ["Previous article" gnus-summary-prev-article t]
2550          ["Next unread subject" gnus-summary-next-unread-subject t]
2551          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2552          ["Next article same subject" gnus-summary-next-same-subject t]
2553          ["Previous article same subject" gnus-summary-prev-same-subject t]
2554          ["First unread article" gnus-summary-first-unread-article t]
2555          ["Best unread article" gnus-summary-best-unread-article t]
2556          ["Go to subject number..." gnus-summary-goto-subject t]
2557          ["Go to article number..." gnus-summary-goto-article t]
2558          ["Go to the last article" gnus-summary-goto-last-article t]
2559          ["Pop article off history" gnus-summary-pop-article t])
2560         ("Sort"
2561          ["Sort by number" gnus-summary-sort-by-number t]
2562          ["Sort by author" gnus-summary-sort-by-author t]
2563          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2564          ["Sort by subject" gnus-summary-sort-by-subject t]
2565          ["Sort by date" gnus-summary-sort-by-date t]
2566          ["Sort by score" gnus-summary-sort-by-score t]
2567          ["Sort by lines" gnus-summary-sort-by-lines t]
2568          ["Sort by characters" gnus-summary-sort-by-chars t]
2569          ["Randomize" gnus-summary-sort-by-random t]
2570          ["Original sort" gnus-summary-sort-by-original t])
2571         ("Help"
2572          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2573          ["Describe group" gnus-summary-describe-group t]
2574          ["Fetch charter" gnus-group-fetch-charter
2575           ,@(if (featurep 'xemacs) nil
2576               '(:help "Display the charter of the current group"))]
2577          ["Fetch control message" gnus-group-fetch-control
2578           ,@(if (featurep 'xemacs) nil
2579               '(:help "Display the archived control message for the current group"))]
2580          ["Read manual" gnus-info-find-node t])
2581         ("Modes"
2582          ["Pick and read" gnus-pick-mode t]
2583          ["Binary" gnus-binary-mode t])
2584         ("Regeneration"
2585          ["Regenerate" gnus-summary-prepare t]
2586          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2587          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2588          ["Toggle threading" gnus-summary-toggle-threads t])
2589         ["See old articles" gnus-summary-insert-old-articles t]
2590         ["See new articles" gnus-summary-insert-new-articles t]
2591         ["Filter articles..." gnus-summary-execute-command t]
2592         ["Run command on articles..." gnus-summary-universal-argument t]
2593         ["Search articles forward..." gnus-summary-search-article-forward t]
2594         ["Search articles backward..." gnus-summary-search-article-backward t]
2595         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2596         ["Expand window" gnus-summary-expand-window t]
2597         ["Expire expirable articles" gnus-summary-expire-articles
2598          (gnus-check-backend-function
2599           'request-expire-articles gnus-newsgroup-name)]
2600         ["Edit local kill file" gnus-summary-edit-local-kill t]
2601         ["Edit main kill file" gnus-summary-edit-global-kill t]
2602         ["Edit group parameters" gnus-summary-edit-parameters t]
2603         ["Customize group parameters" gnus-summary-customize-parameters t]
2604         ["Send a bug report" gnus-bug t]
2605         ("Exit"
2606          ["Catchup and exit" gnus-summary-catchup-and-exit
2607           ,@(if (featurep 'xemacs) '(t)
2608               '(:help "Mark unread articles in this group as read, then exit"))]
2609          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2610          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2611          ["Exit group" gnus-summary-exit
2612           ,@(if (featurep 'xemacs) '(t)
2613               '(:help "Exit current group, return to group selection mode"))]
2614          ["Exit group without updating" gnus-summary-exit-no-update t]
2615          ["Exit and goto next group" gnus-summary-next-group t]
2616          ["Exit and goto prev group" gnus-summary-prev-group t]
2617          ["Reselect group" gnus-summary-reselect-current-group t]
2618          ["Rescan group" gnus-summary-rescan-group t]
2619          ["Update dribble" gnus-summary-save-newsrc t])))
2620
2621     (gnus-run-hooks 'gnus-summary-menu-hook)))
2622
2623 (defvar gnus-summary-tool-bar-map nil)
2624
2625 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2626 (defun gnus-summary-make-tool-bar ()
2627   (if (and (fboundp 'tool-bar-add-item-from-menu)
2628            (default-value 'tool-bar-mode)
2629            (not gnus-summary-tool-bar-map))
2630       (setq gnus-summary-tool-bar-map
2631             (let ((tool-bar-map (make-sparse-keymap))
2632                   (load-path (mm-image-load-path)))
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-post-news "post" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-summary-followup "followup" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-reply "reply" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2651               (tool-bar-add-item-from-menu
2652                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2653               (tool-bar-add-item-from-menu
2654                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2655               (tool-bar-add-item-from-menu
2656                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2657               (tool-bar-add-item-from-menu
2658                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2659               (tool-bar-add-item-from-menu
2660                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2661               (tool-bar-add-item-from-menu
2662                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2663               (tool-bar-add-item-from-menu
2664                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2665               tool-bar-map)))
2666   (if gnus-summary-tool-bar-map
2667       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2668
2669 (defun gnus-score-set-default (var value)
2670   "A version of set that updates the GNU Emacs menu-bar."
2671   (set var value)
2672   ;; It is the message that forces the active status to be updated.
2673   (message ""))
2674
2675 (defun gnus-make-score-map (type)
2676   "Make a summary score map of type TYPE."
2677   (if t
2678       nil
2679     (let ((headers '(("author" "from" string)
2680                      ("subject" "subject" string)
2681                      ("article body" "body" string)
2682                      ("article head" "head" string)
2683                      ("xref" "xref" string)
2684                      ("extra header" "extra" string)
2685                      ("lines" "lines" number)
2686                      ("followups to author" "followup" string)))
2687           (types '((number ("less than" <)
2688                            ("greater than" >)
2689                            ("equal" =))
2690                    (string ("substring" s)
2691                            ("exact string" e)
2692                            ("fuzzy string" f)
2693                            ("regexp" r))))
2694           (perms '(("temporary" (current-time-string))
2695                    ("permanent" nil)
2696                    ("immediate" now)))
2697           header)
2698       (list
2699        (apply
2700         'nconc
2701         (list
2702          (if (eq type 'lower)
2703              "Lower score"
2704            "Increase score"))
2705         (let (outh)
2706           (while headers
2707             (setq header (car headers))
2708             (setq outh
2709                   (cons
2710                    (apply
2711                     'nconc
2712                     (list (car header))
2713                     (let ((ts (cdr (assoc (nth 2 header) types)))
2714                           outt)
2715                       (while ts
2716                         (setq outt
2717                               (cons
2718                                (apply
2719                                 'nconc
2720                                 (list (caar ts))
2721                                 (let ((ps perms)
2722                                       outp)
2723                                   (while ps
2724                                     (setq outp
2725                                           (cons
2726                                            (vector
2727                                             (caar ps)
2728                                             (list
2729                                              'gnus-summary-score-entry
2730                                              (nth 1 header)
2731                                              (if (or (string= (nth 1 header)
2732                                                               "head")
2733                                                      (string= (nth 1 header)
2734                                                               "body"))
2735                                                  ""
2736                                                (list 'gnus-summary-header
2737                                                      (nth 1 header)))
2738                                              (list 'quote (nth 1 (car ts)))
2739                                              (list 'gnus-score-delta-default
2740                                                    nil)
2741                                              (nth 1 (car ps))
2742                                              t)
2743                                             t)
2744                                            outp))
2745                                     (setq ps (cdr ps)))
2746                                   (list (nreverse outp))))
2747                                outt))
2748                         (setq ts (cdr ts)))
2749                       (list (nreverse outt))))
2750                    outh))
2751             (setq headers (cdr headers)))
2752           (list (nreverse outh))))))))
2753
2754 \f
2755
2756 (defun gnus-summary-mode (&optional group)
2757   "Major mode for reading articles.
2758
2759 All normal editing commands are switched off.
2760 \\<gnus-summary-mode-map>
2761 Each line in this buffer represents one article.  To read an
2762 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2763 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2764 respectively.
2765
2766 You can also post articles and send mail from this buffer.  To
2767 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2768 of an article, type `\\[gnus-summary-reply]'.
2769
2770 There are approx. one gazillion commands you can execute in this
2771 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2772
2773 The following commands are available:
2774
2775 \\{gnus-summary-mode-map}"
2776   (interactive)
2777   (kill-all-local-variables)
2778   (when (gnus-visual-p 'summary-menu 'menu)
2779     (gnus-summary-make-menu-bar)
2780     (gnus-summary-make-tool-bar))
2781   (gnus-summary-make-local-variables)
2782   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2783     (gnus-summary-make-local-variables))
2784   (gnus-make-thread-indent-array)
2785   (gnus-simplify-mode-line)
2786   (setq major-mode 'gnus-summary-mode)
2787   (setq mode-name "Summary")
2788   (make-local-variable 'minor-mode-alist)
2789   (use-local-map gnus-summary-mode-map)
2790   (buffer-disable-undo)
2791   (setq buffer-read-only t              ;Disable modification
2792         show-trailing-whitespace nil)
2793   (setq truncate-lines t)
2794   (setq selective-display t)
2795   (setq selective-display-ellipses t)   ;Display `...'
2796   (gnus-summary-set-display-table)
2797   (gnus-set-default-directory)
2798   (setq gnus-newsgroup-name group)
2799   (make-local-variable 'gnus-summary-line-format)
2800   (make-local-variable 'gnus-summary-line-format-spec)
2801   (make-local-variable 'gnus-summary-dummy-line-format)
2802   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2803   (make-local-variable 'gnus-summary-mark-positions)
2804   (gnus-make-local-hook 'pre-command-hook)
2805   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2806   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2807   (turn-on-gnus-mailing-list-mode)
2808   (mm-enable-multibyte)
2809   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2810   (gnus-update-summary-mark-positions))
2811
2812 (defun gnus-summary-make-local-variables ()
2813   "Make all the local summary buffer variables."
2814   (let (global)
2815     (dolist (local gnus-summary-local-variables)
2816       (if (consp local)
2817           (progn
2818             (if (eq (cdr local) 'global)
2819                 ;; Copy the global value of the variable.
2820                 (setq global (symbol-value (car local)))
2821               ;; Use the value from the list.
2822               (setq global (eval (cdr local))))
2823             (set (make-local-variable (car local)) global))
2824         ;; Simple nil-valued local variable.
2825         (set (make-local-variable local) nil)))))
2826
2827 (defun gnus-summary-clear-local-variables ()
2828   (let ((locals gnus-summary-local-variables))
2829     (while locals
2830       (if (consp (car locals))
2831           (and (symbolp (caar locals))
2832                (set (caar locals) nil))
2833         (and (symbolp (car locals))
2834              (set (car locals) nil)))
2835       (setq locals (cdr locals)))))
2836
2837 ;; Summary data functions.
2838
2839 (defmacro gnus-data-number (data)
2840   `(car ,data))
2841
2842 (defmacro gnus-data-set-number (data number)
2843   `(setcar ,data ,number))
2844
2845 (defmacro gnus-data-mark (data)
2846   `(nth 1 ,data))
2847
2848 (defmacro gnus-data-set-mark (data mark)
2849   `(setcar (nthcdr 1 ,data) ,mark))
2850
2851 (defmacro gnus-data-pos (data)
2852   `(nth 2 ,data))
2853
2854 (defmacro gnus-data-set-pos (data pos)
2855   `(setcar (nthcdr 2 ,data) ,pos))
2856
2857 (defmacro gnus-data-header (data)
2858   `(nth 3 ,data))
2859
2860 (defmacro gnus-data-set-header (data header)
2861   `(setf (nth 3 ,data) ,header))
2862
2863 (defmacro gnus-data-level (data)
2864   `(nth 4 ,data))
2865
2866 (defmacro gnus-data-unread-p (data)
2867   `(= (nth 1 ,data) gnus-unread-mark))
2868
2869 (defmacro gnus-data-read-p (data)
2870   `(/= (nth 1 ,data) gnus-unread-mark))
2871
2872 (defmacro gnus-data-pseudo-p (data)
2873   `(consp (nth 3 ,data)))
2874
2875 (defmacro gnus-data-find (number)
2876   `(assq ,number gnus-newsgroup-data))
2877
2878 (defmacro gnus-data-find-list (number &optional data)
2879   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2880      (memq (assq ,number bdata)
2881            bdata)))
2882
2883 (defmacro gnus-data-make (number mark pos header level)
2884   `(list ,number ,mark ,pos ,header ,level))
2885
2886 (defun gnus-data-enter (after-article number mark pos header level offset)
2887   (let ((data (gnus-data-find-list after-article)))
2888     (unless data
2889       (error "No such article: %d" after-article))
2890     (setcdr data (cons (gnus-data-make number mark pos header level)
2891                        (cdr data)))
2892     (setq gnus-newsgroup-data-reverse nil)
2893     (gnus-data-update-list (cddr data) offset)))
2894
2895 (defun gnus-data-enter-list (after-article list &optional offset)
2896   (when list
2897     (let ((data (and after-article (gnus-data-find-list after-article)))
2898           (ilist list))
2899       (if (not (or data
2900                    after-article))
2901           (let ((odata gnus-newsgroup-data))
2902             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2903             (when offset
2904               (gnus-data-update-list odata offset)))
2905         ;; Find the last element in the list to be spliced into the main
2906         ;; list.
2907         (setq list (last list))
2908         (if (not data)
2909             (progn
2910               (setcdr list gnus-newsgroup-data)
2911               (setq gnus-newsgroup-data ilist)
2912               (when offset
2913                 (gnus-data-update-list (cdr list) offset)))
2914           (setcdr list (cdr data))
2915           (setcdr data ilist)
2916           (when offset
2917             (gnus-data-update-list (cdr list) offset))))
2918       (setq gnus-newsgroup-data-reverse nil))))
2919
2920 (defun gnus-data-remove (article &optional offset)
2921   (let ((data gnus-newsgroup-data))
2922     (if (= (gnus-data-number (car data)) article)
2923         (progn
2924           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2925                 gnus-newsgroup-data-reverse nil)
2926           (when offset
2927             (gnus-data-update-list gnus-newsgroup-data offset)))
2928       (while (cdr data)
2929         (when (= (gnus-data-number (cadr data)) article)
2930           (setcdr data (cddr data))
2931           (when offset
2932             (gnus-data-update-list (cdr data) offset))
2933           (setq data nil
2934                 gnus-newsgroup-data-reverse nil))
2935         (setq data (cdr data))))))
2936
2937 (defmacro gnus-data-list (backward)
2938   `(if ,backward
2939        (or gnus-newsgroup-data-reverse
2940            (setq gnus-newsgroup-data-reverse
2941                  (reverse gnus-newsgroup-data)))
2942      gnus-newsgroup-data))
2943
2944 (defun gnus-data-update-list (data offset)
2945   "Add OFFSET to the POS of all data entries in DATA."
2946   (setq gnus-newsgroup-data-reverse nil)
2947   (while data
2948     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2949     (setq data (cdr data))))
2950
2951 (defun gnus-summary-article-pseudo-p (article)
2952   "Say whether this article is a pseudo article or not."
2953   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2954
2955 (defmacro gnus-summary-article-sparse-p (article)
2956   "Say whether this article is a sparse article or not."
2957   `(memq ,article gnus-newsgroup-sparse))
2958
2959 (defmacro gnus-summary-article-ancient-p (article)
2960   "Say whether this article is a sparse article or not."
2961   `(memq ,article gnus-newsgroup-ancient))
2962
2963 (defun gnus-article-parent-p (number)
2964   "Say whether this article is a parent or not."
2965   (let ((data (gnus-data-find-list number)))
2966     (and (cdr data)              ; There has to be an article after...
2967          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2968             (gnus-data-level (nth 1 data))))))
2969
2970 (defun gnus-article-children (number)
2971   "Return a list of all children to NUMBER."
2972   (let* ((data (gnus-data-find-list number))
2973          (level (gnus-data-level (car data)))
2974          children)
2975     (setq data (cdr data))
2976     (while (and data
2977                 (= (gnus-data-level (car data)) (1+ level)))
2978       (push (gnus-data-number (car data)) children)
2979       (setq data (cdr data)))
2980     children))
2981
2982 (defmacro gnus-summary-skip-intangible ()
2983   "If the current article is intangible, then jump to a different article."
2984   '(let ((to (get-text-property (point) 'gnus-intangible)))
2985      (and to (gnus-summary-goto-subject to))))
2986
2987 (defmacro gnus-summary-article-intangible-p ()
2988   "Say whether this article is intangible or not."
2989   '(get-text-property (point) 'gnus-intangible))
2990
2991 (defun gnus-article-read-p (article)
2992   "Say whether ARTICLE is read or not."
2993   (not (or (memq article gnus-newsgroup-marked)
2994            (memq article gnus-newsgroup-spam-marked)
2995            (memq article gnus-newsgroup-unreads)
2996            (memq article gnus-newsgroup-unselected)
2997            (memq article gnus-newsgroup-dormant))))
2998
2999 ;; Some summary mode macros.
3000
3001 (defmacro gnus-summary-article-number ()
3002   "The article number of the article on the current line.
3003 If there isn't an article number here, then we return the current
3004 article number."
3005   '(progn
3006      (gnus-summary-skip-intangible)
3007      (or (get-text-property (point) 'gnus-number)
3008          (gnus-summary-last-subject))))
3009
3010 (defmacro gnus-summary-article-header (&optional number)
3011   "Return the header of article NUMBER."
3012   `(gnus-data-header (gnus-data-find
3013                       ,(or number '(gnus-summary-article-number)))))
3014
3015 (defmacro gnus-summary-thread-level (&optional number)
3016   "Return the level of thread that starts with article NUMBER."
3017   `(if (and (eq gnus-summary-make-false-root 'dummy)
3018             (get-text-property (point) 'gnus-intangible))
3019        0
3020      (gnus-data-level (gnus-data-find
3021                        ,(or number '(gnus-summary-article-number))))))
3022
3023 (defmacro gnus-summary-article-mark (&optional number)
3024   "Return the mark of article NUMBER."
3025   `(gnus-data-mark (gnus-data-find
3026                     ,(or number '(gnus-summary-article-number)))))
3027
3028 (defmacro gnus-summary-article-pos (&optional number)
3029   "Return the position of the line of article NUMBER."
3030   `(gnus-data-pos (gnus-data-find
3031                    ,(or number '(gnus-summary-article-number)))))
3032
3033 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3034 (defmacro gnus-summary-article-subject (&optional number)
3035   "Return current subject string or nil if nothing."
3036   `(let ((headers
3037           ,(if number
3038                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3039              '(gnus-data-header (assq (gnus-summary-article-number)
3040                                       gnus-newsgroup-data)))))
3041      (and headers
3042           (vectorp headers)
3043           (mail-header-subject headers))))
3044
3045 (defmacro gnus-summary-article-score (&optional number)
3046   "Return current article score."
3047   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3048                   gnus-newsgroup-scored))
3049        gnus-summary-default-score 0))
3050
3051 (defun gnus-summary-article-children (&optional number)
3052   "Return a list of article numbers that are children of article NUMBER."
3053   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3054          (level (gnus-data-level (car data)))
3055          l children)
3056     (while (and (setq data (cdr data))
3057                 (> (setq l (gnus-data-level (car data))) level))
3058       (and (= (1+ level) l)
3059            (push (gnus-data-number (car data))
3060                  children)))
3061     (nreverse children)))
3062
3063 (defun gnus-summary-article-parent (&optional number)
3064   "Return the article number of the parent of article NUMBER."
3065   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3066                                     (gnus-data-list t)))
3067          (level (gnus-data-level (car data))))
3068     (if (zerop level)
3069         ()                              ; This is a root.
3070       ;; We search until we find an article with a level less than
3071       ;; this one.  That function has to be the parent.
3072       (while (and (setq data (cdr data))
3073                   (not (< (gnus-data-level (car data)) level))))
3074       (and data (gnus-data-number (car data))))))
3075
3076 (defun gnus-unread-mark-p (mark)
3077   "Say whether MARK is the unread mark."
3078   (= mark gnus-unread-mark))
3079
3080 (defun gnus-read-mark-p (mark)
3081   "Say whether MARK is one of the marks that mark as read.
3082 This is all marks except unread, ticked, dormant, and expirable."
3083   (not (or (= mark gnus-unread-mark)
3084            (= mark gnus-ticked-mark)
3085            (= mark gnus-spam-mark)
3086            (= mark gnus-dormant-mark)
3087            (= mark gnus-expirable-mark))))
3088
3089 (defmacro gnus-article-mark (number)
3090   "Return the MARK of article NUMBER.
3091 This macro should only be used when computing the mark the \"first\"
3092 time; i.e., when generating the summary lines.  After that,
3093 `gnus-summary-article-mark' should be used to examine the
3094 marks of articles."
3095   `(cond
3096     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3097     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3098     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3099     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3100     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3101     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3102     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3103     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3104            gnus-ancient-mark))))
3105
3106 ;; Saving hidden threads.
3107
3108 (defmacro gnus-save-hidden-threads (&rest forms)
3109   "Save hidden threads, eval FORMS, and restore the hidden threads."
3110   (let ((config (make-symbol "config")))
3111     `(let ((,config (gnus-hidden-threads-configuration)))
3112        (unwind-protect
3113            (save-excursion
3114              ,@forms)
3115          (gnus-restore-hidden-threads-configuration ,config)))))
3116 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3117 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3118
3119 (defun gnus-data-compute-positions ()
3120   "Compute the positions of all articles."
3121   (setq gnus-newsgroup-data-reverse nil)
3122   (let ((data gnus-newsgroup-data))
3123     (save-excursion
3124       (gnus-save-hidden-threads
3125         (gnus-summary-show-all-threads)
3126         (goto-char (point-min))
3127         (while data
3128           (while (get-text-property (point) 'gnus-intangible)
3129             (forward-line 1))
3130           (gnus-data-set-pos (car data) (+ (point) 3))
3131           (setq data (cdr data))
3132           (forward-line 1))))))
3133
3134 (defun gnus-hidden-threads-configuration ()
3135   "Return the current hidden threads configuration."
3136   (save-excursion
3137     (let (config)
3138       (goto-char (point-min))
3139       (while (search-forward "\r" nil t)
3140         (push (1- (point)) config))
3141       config)))
3142
3143 (defun gnus-restore-hidden-threads-configuration (config)
3144   "Restore hidden threads configuration from CONFIG."
3145   (save-excursion
3146     (let (point buffer-read-only)
3147       (while (setq point (pop config))
3148         (when (and (< point (point-max))
3149                    (goto-char point)
3150                    (eq (char-after) ?\n))
3151           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3152
3153 ;; Various summary mode internalish functions.
3154
3155 (defun gnus-mouse-pick-article (e)
3156   (interactive "e")
3157   (mouse-set-point e)
3158   (gnus-summary-next-page nil t))
3159
3160 (defun gnus-summary-set-display-table ()
3161   "Change the display table.
3162 Odd characters have a tendency to mess
3163 up nicely formatted displays - we make all possible glyphs
3164 display only a single character."
3165
3166   ;; We start from the standard display table, if any.
3167   (let ((table (or (copy-sequence standard-display-table)
3168                    (make-display-table)))
3169         (i 32))
3170     ;; Nix out all the control chars...
3171     (while (>= (setq i (1- i)) 0)
3172       (aset table i [??]))
3173    ;; ... but not newline and cr, of course.  (cr is necessary for the
3174     ;; selective display).
3175     (aset table ?\n nil)
3176     (aset table ?\r nil)
3177     ;; We keep TAB as well.
3178     (aset table ?\t nil)
3179     ;; We nix out any glyphs over 126 that are not set already.
3180     (let ((i 256))
3181       (while (>= (setq i (1- i)) 127)
3182         ;; Only modify if the entry is nil.
3183         (unless (aref table i)
3184           (aset table i [??]))))
3185     (setq buffer-display-table table)))
3186
3187 (defun gnus-summary-set-article-display-arrow (pos)
3188   "Update the overlay arrow to point to line at position POS."
3189   (when (and gnus-summary-display-arrow
3190              (boundp 'overlay-arrow-position)
3191              (boundp 'overlay-arrow-string))
3192     (save-excursion
3193       (goto-char pos)
3194       (beginning-of-line)
3195       (unless overlay-arrow-position
3196         (setq overlay-arrow-position (make-marker)))
3197       (setq overlay-arrow-string "=>"
3198             overlay-arrow-position (set-marker overlay-arrow-position
3199                                                (point)
3200                                                (current-buffer))))))
3201
3202 (defun gnus-summary-setup-buffer (group)
3203   "Initialize summary buffer."
3204   (let ((buffer (gnus-summary-buffer-name group))
3205         (dead-name (concat "*Dead Summary "
3206                            (gnus-group-decoded-name group) "*")))
3207     ;; If a dead summary buffer exists, we kill it.
3208     (when (gnus-buffer-live-p dead-name)
3209       (gnus-kill-buffer dead-name))
3210     (if (get-buffer buffer)
3211         (progn
3212           (set-buffer buffer)
3213           (setq gnus-summary-buffer (current-buffer))
3214           (not gnus-newsgroup-prepared))
3215       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3216       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3217       (gnus-summary-mode group)
3218       (when gnus-carpal
3219         (gnus-carpal-setup-buffer 'summary))
3220       (unless gnus-single-article-buffer
3221         (make-local-variable 'gnus-article-buffer)
3222         (make-local-variable 'gnus-article-current)
3223         (make-local-variable 'gnus-original-article-buffer))
3224       (setq gnus-newsgroup-name group)
3225       ;; Set any local variables in the group parameters.
3226       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3227       t)))
3228
3229 (defun gnus-set-global-variables ()
3230   "Set the global equivalents of the buffer-local variables.
3231 They are set to the latest values they had.  These reflect the summary
3232 buffer that was in action when the last article was fetched."
3233   (when (eq major-mode 'gnus-summary-mode)
3234     (setq gnus-summary-buffer (current-buffer))
3235     (let ((name gnus-newsgroup-name)
3236           (marked gnus-newsgroup-marked)
3237           (spam gnus-newsgroup-spam-marked)
3238           (unread gnus-newsgroup-unreads)
3239           (headers gnus-current-headers)
3240           (data gnus-newsgroup-data)
3241           (summary gnus-summary-buffer)
3242           (article-buffer gnus-article-buffer)
3243           (original gnus-original-article-buffer)
3244           (gac gnus-article-current)
3245           (reffed gnus-reffed-article-number)
3246           (score-file gnus-current-score-file)
3247           (default-charset gnus-newsgroup-charset)
3248           vlist)
3249       (let ((locals gnus-newsgroup-variables))
3250         (while locals
3251           (if (consp (car locals))
3252               (push (eval (caar locals)) vlist)
3253             (push (eval (car locals)) vlist))
3254           (setq locals (cdr locals)))
3255         (setq vlist (nreverse vlist)))
3256       (with-current-buffer gnus-group-buffer
3257         (setq gnus-newsgroup-name name
3258               gnus-newsgroup-marked marked
3259               gnus-newsgroup-spam-marked spam
3260               gnus-newsgroup-unreads unread
3261               gnus-current-headers headers
3262               gnus-newsgroup-data data
3263               gnus-article-current gac
3264               gnus-summary-buffer summary
3265               gnus-article-buffer article-buffer
3266               gnus-original-article-buffer original
3267               gnus-reffed-article-number reffed
3268               gnus-current-score-file score-file
3269               gnus-newsgroup-charset default-charset)
3270         (let ((locals gnus-newsgroup-variables))
3271           (while locals
3272             (if (consp (car locals))
3273                 (set (caar locals) (pop vlist))
3274               (set (car locals) (pop vlist)))
3275             (setq locals (cdr locals))))
3276         ;; The article buffer also has local variables.
3277         (when (gnus-buffer-live-p gnus-article-buffer)
3278           (set-buffer gnus-article-buffer)
3279           (setq gnus-summary-buffer summary))))))
3280
3281 (defun gnus-summary-article-unread-p (article)
3282   "Say whether ARTICLE is unread or not."
3283   (memq article gnus-newsgroup-unreads))
3284
3285 (defun gnus-summary-first-article-p (&optional article)
3286   "Return whether ARTICLE is the first article in the buffer."
3287   (if (not (setq article (or article (gnus-summary-article-number))))
3288       nil
3289     (eq article (caar gnus-newsgroup-data))))
3290
3291 (defun gnus-summary-last-article-p (&optional article)
3292   "Return whether ARTICLE is the last article in the buffer."
3293   (if (not (setq article (or article (gnus-summary-article-number))))
3294       ;; All non-existent numbers are the last article.  :-)
3295       t
3296     (not (cdr (gnus-data-find-list article)))))
3297
3298 (defun gnus-make-thread-indent-array ()
3299   (let ((n 200))
3300     (unless (and gnus-thread-indent-array
3301                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3302       (setq gnus-thread-indent-array (make-vector 201 "")
3303             gnus-thread-indent-array-level gnus-thread-indent-level)
3304       (while (>= n 0)
3305         (aset gnus-thread-indent-array n
3306               (make-string (* n gnus-thread-indent-level) ? ))
3307         (setq n (1- n))))))
3308
3309 (defun gnus-update-summary-mark-positions ()
3310   "Compute where the summary marks are to go."
3311   (save-excursion
3312     (when (gnus-buffer-exists-p gnus-summary-buffer)
3313       (set-buffer gnus-summary-buffer))
3314     (let ((spec gnus-summary-line-format-spec)
3315           pos)
3316       (save-excursion
3317         (gnus-set-work-buffer)
3318         (let ((gnus-tmp-unread ?Z)
3319               (gnus-replied-mark ?Z)
3320               (gnus-score-below-mark ?Z)
3321               (gnus-score-over-mark ?Z)
3322               (gnus-undownloaded-mark ?Z)
3323               (gnus-summary-line-format-spec spec)
3324               (gnus-newsgroup-downloadable '(0))
3325               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3326               case-fold-search ignores)
3327           ;; Here, all marks are bound to Z.
3328           (gnus-summary-insert-line header
3329                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3330           (goto-char (point-min))
3331           ;; Memorize the positions of the same characters as dummy marks.
3332           (while (re-search-forward "[A-D]" nil t)
3333             (push (point) ignores))
3334           (erase-buffer)
3335           ;; We use A-D as dummy marks in order to know column positions
3336           ;; where marks should be inserted.
3337           (setq gnus-tmp-unread ?A
3338                 gnus-replied-mark ?B
3339                 gnus-score-below-mark ?C
3340                 gnus-score-over-mark ?C
3341                 gnus-undownloaded-mark ?D)
3342           (gnus-summary-insert-line header
3343                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3344           ;; Ignore characters which aren't dummy marks.
3345           (dolist (p ignores)
3346             (delete-region (goto-char (1- p)) p)
3347             (insert ?Z))
3348           (goto-char (point-min))
3349           (setq pos (list (cons 'unread
3350                                 (and (search-forward "A" nil t)
3351                                      (- (point) (point-min) 1)))))
3352           (goto-char (point-min))
3353           (push (cons 'replied (and (search-forward "B" nil t)
3354                                     (- (point) (point-min) 1)))
3355                 pos)
3356           (goto-char (point-min))
3357           (push (cons 'score (and (search-forward "C" nil t)
3358                                   (- (point) (point-min) 1)))
3359                 pos)
3360           (goto-char (point-min))
3361           (push (cons 'download (and (search-forward "D" nil t)
3362                                      (- (point) (point-min) 1)))
3363                 pos)))
3364       (setq gnus-summary-mark-positions pos))))
3365
3366 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3367   "Insert a dummy root in the summary buffer."
3368   (beginning-of-line)
3369   (gnus-add-text-properties
3370    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3371    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3372
3373 (defun gnus-summary-extract-address-component (from)
3374   (or (car (funcall gnus-extract-address-components from))
3375       from))
3376
3377 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3378   (let ((mail-parse-charset gnus-newsgroup-charset)
3379         ; Is it really necessary to do this next part for each summary line?
3380         ; Luckily, doesn't seem to slow things down much.
3381         (mail-parse-ignored-charsets
3382          (with-current-buffer gnus-summary-buffer
3383            gnus-newsgroup-ignored-charsets)))
3384     (or
3385      (and gnus-ignored-from-addresses
3386           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3387           (let ((extra-headers (mail-header-extra header))
3388                 to
3389                 newsgroups)
3390             (cond
3391              ((setq to (cdr (assq 'To extra-headers)))
3392               (concat gnus-summary-to-prefix
3393                       (inline
3394                         (gnus-summary-extract-address-component
3395                          (funcall gnus-decode-encoded-word-function to)))))
3396              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3397               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3398      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3399
3400 (defun gnus-summary-insert-line (gnus-tmp-header
3401                                  gnus-tmp-level gnus-tmp-current
3402                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3403                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3404                                  &optional gnus-tmp-dummy gnus-tmp-score
3405                                  gnus-tmp-process)
3406   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3407          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3408          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3409          (gnus-tmp-score-char
3410           (if (or (null gnus-summary-default-score)
3411                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3412                       gnus-summary-zcore-fuzz))
3413               ?                         ;Whitespace
3414             (if (< gnus-tmp-score gnus-summary-default-score)
3415                 gnus-score-below-mark gnus-score-over-mark)))
3416          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3417          (gnus-tmp-replied
3418           (cond (gnus-tmp-process gnus-process-mark)
3419                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3420                  gnus-cached-mark)
3421                 (gnus-tmp-replied gnus-replied-mark)
3422                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3423                  gnus-forwarded-mark)
3424                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3425                  gnus-saved-mark)
3426                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3427                  gnus-recent-mark)
3428                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3429                  gnus-unseen-mark)
3430                 (t gnus-no-mark)))
3431          (gnus-tmp-downloaded
3432           (cond (undownloaded
3433                  gnus-undownloaded-mark)
3434                 (gnus-newsgroup-agentized
3435                  gnus-downloaded-mark)
3436                 (t
3437                  gnus-no-mark)))
3438          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3439          (gnus-tmp-name
3440           (cond
3441            ((string-match "<[^>]+> *$" gnus-tmp-from)
3442             (let ((beg (match-beginning 0)))
3443               (or (and (string-match "^\".+\"" gnus-tmp-from)
3444                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3445                   (substring gnus-tmp-from 0 beg))))
3446            ((string-match "(.+)" gnus-tmp-from)
3447             (substring gnus-tmp-from
3448                        (1+ (match-beginning 0)) (1- (match-end 0))))
3449            (t gnus-tmp-from)))
3450          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3451          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3452          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3453          (buffer-read-only nil))
3454     (when (string= gnus-tmp-name "")
3455       (setq gnus-tmp-name gnus-tmp-from))
3456     (unless (numberp gnus-tmp-lines)
3457       (setq gnus-tmp-lines -1))
3458     (if (= gnus-tmp-lines -1)
3459         (setq gnus-tmp-lines "?")
3460       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3461       (gnus-put-text-property
3462      (point)
3463      (progn (eval gnus-summary-line-format-spec) (point))
3464        'gnus-number gnus-tmp-number)
3465     (when (gnus-visual-p 'summary-highlight 'highlight)
3466       (forward-line -1)
3467       (gnus-run-hooks 'gnus-summary-update-hook)
3468       (forward-line 1))))
3469
3470 (defun gnus-summary-update-line (&optional dont-update)
3471   "Update summary line after change."
3472   (when (and gnus-summary-default-score
3473              (not gnus-summary-inhibit-highlight))
3474     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3475            (article (gnus-summary-article-number))
3476            (score (gnus-summary-article-score article)))
3477       (unless dont-update
3478         (if (and gnus-summary-mark-below
3479                  (< (gnus-summary-article-score)
3480                     gnus-summary-mark-below))
3481             ;; This article has a low score, so we mark it as read.
3482             (when (memq article gnus-newsgroup-unreads)
3483               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3484           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3485             ;; This article was previously marked as read on account
3486             ;; of a low score, but now it has risen, so we mark it as
3487             ;; unread.
3488             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3489         (gnus-summary-update-mark
3490          (if (or (null gnus-summary-default-score)
3491                  (<= (abs (- score gnus-summary-default-score))
3492                      gnus-summary-zcore-fuzz))
3493              ?                          ;Whitespace
3494            (if (< score gnus-summary-default-score)
3495                gnus-score-below-mark gnus-score-over-mark))
3496          'score))
3497       ;; Do visual highlighting.
3498       (when (gnus-visual-p 'summary-highlight 'highlight)
3499         (gnus-run-hooks 'gnus-summary-update-hook)))))
3500
3501 (defvar gnus-tmp-new-adopts nil)
3502
3503 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3504   "Return the number of articles in THREAD.
3505 This may be 0 in some cases -- if none of the articles in
3506 the thread are to be displayed."
3507   (let* ((number
3508          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3509           (cond
3510            ((not (listp thread))
3511             1)
3512            ((and (consp thread) (cdr thread))
3513             (apply
3514              '+ 1 (mapcar
3515                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3516            ((null thread)
3517             1)
3518            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3519             1)
3520            (t 0))))
3521     (when (and level (zerop level) gnus-tmp-new-adopts)
3522       (incf number
3523             (apply '+ (mapcar
3524                        'gnus-summary-number-of-articles-in-thread
3525                        gnus-tmp-new-adopts))))
3526     (if char
3527         (if (> number 1) gnus-not-empty-thread-mark
3528           gnus-empty-thread-mark)
3529       number)))
3530
3531 (defsubst gnus-summary-line-message-size (head)
3532   "Return pretty-printed version of message size.
3533 This function is intended to be used in
3534 `gnus-summary-line-format-alist'."
3535   (let ((c (or (mail-header-chars head) -1)))
3536     (cond ((< c 0) "n/a")               ; chars not available
3537           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3538           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3539           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3540           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3541
3542
3543 (defun gnus-summary-set-local-parameters (group)
3544   "Go through the local params of GROUP and set all variable specs in that list."
3545   (let ((vars '(quit-config)))          ; Ignore quit-config.
3546     (dolist (elem (gnus-group-find-parameter group))
3547       (and (consp elem)                 ; Has to be a cons.
3548            (consp (cdr elem))           ; The cdr has to be a list.
3549            (symbolp (car elem))         ; Has to be a symbol in there.
3550            (not (memq (car elem) vars))
3551            (ignore-errors               ; So we set it.
3552              (push (car elem) vars)
3553              (make-local-variable (car elem))
3554              (set (car elem) (eval (nth 1 elem))))))))
3555
3556 (defun gnus-summary-read-group (group &optional show-all no-article
3557                                       kill-buffer no-display backward
3558                                       select-articles)
3559   "Start reading news in newsgroup GROUP.
3560 If SHOW-ALL is non-nil, already read articles are also listed.
3561 If NO-ARTICLE is non-nil, no article is selected initially.
3562 If NO-DISPLAY, don't generate a summary buffer."
3563   (let (result)
3564     (while (and group
3565                 (null (setq result
3566                             (let ((gnus-auto-select-next nil))
3567                               (or (gnus-summary-read-group-1
3568                                    group show-all no-article
3569                                    kill-buffer no-display
3570                                    select-articles)
3571                                   (setq show-all nil
3572                                         select-articles nil)))))
3573                 (eq gnus-auto-select-next 'quietly))
3574       (set-buffer gnus-group-buffer)
3575       ;; The entry function called above goes to the next
3576       ;; group automatically, so we go two groups back
3577       ;; if we are searching for the previous group.
3578       (when backward
3579         (gnus-group-prev-unread-group 2))
3580       (if (not (equal group (gnus-group-group-name)))
3581           (setq group (gnus-group-group-name))
3582         (setq group nil)))
3583     result))
3584
3585 (defun gnus-summary-read-group-1 (group show-all no-article
3586                                         kill-buffer no-display
3587                                         &optional select-articles)
3588   ;; Killed foreign groups can't be entered.
3589   ;;  (when (and (not (gnus-group-native-p group))
3590   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3591   ;;    (error "Dead non-native groups can't be entered"))
3592   (gnus-message 5 "Retrieving newsgroup: %s..."
3593                 (gnus-group-decoded-name group))
3594   (let* ((new-group (gnus-summary-setup-buffer group))
3595          (quit-config (gnus-group-quit-config group))
3596          (did-select (and new-group (gnus-select-newsgroup
3597                                      group show-all select-articles))))
3598     (cond
3599      ;; This summary buffer exists already, so we just select it.
3600      ((not new-group)
3601       (gnus-set-global-variables)
3602       (when kill-buffer
3603         (gnus-kill-or-deaden-summary kill-buffer))
3604       (gnus-configure-windows 'summary 'force)
3605       (gnus-set-mode-line 'summary)
3606       (gnus-summary-position-point)
3607       (message "")
3608       t)
3609      ;; We couldn't select this group.
3610      ((null did-select)
3611       (when (and (eq major-mode 'gnus-summary-mode)
3612                  (not (equal (current-buffer) kill-buffer)))
3613         (kill-buffer (current-buffer))
3614         (if (not quit-config)
3615             (progn
3616               ;; Update the info -- marks might need to be removed,
3617               ;; for instance.
3618               (gnus-summary-update-info)
3619               (set-buffer gnus-group-buffer)
3620               (gnus-group-jump-to-group group)
3621               (gnus-group-next-unread-group 1))
3622           (gnus-handle-ephemeral-exit quit-config)))
3623       (let ((grpinfo (gnus-get-info group)))
3624         (if (null (gnus-info-read grpinfo))
3625             (gnus-message 3 "Group %s contains no messages"
3626                           (gnus-group-decoded-name group))
3627           (gnus-message 3 "Can't select group")))
3628       nil)
3629      ;; The user did a `C-g' while prompting for number of articles,
3630      ;; so we exit this group.
3631      ((eq did-select 'quit)
3632       (and (eq major-mode 'gnus-summary-mode)
3633            (not (equal (current-buffer) kill-buffer))
3634            (kill-buffer (current-buffer)))
3635       (when kill-buffer
3636         (gnus-kill-or-deaden-summary kill-buffer))
3637       (if (not quit-config)
3638           (progn
3639             (set-buffer gnus-group-buffer)
3640             (gnus-group-jump-to-group group)
3641             (gnus-group-next-unread-group 1)
3642             (gnus-configure-windows 'group 'force))
3643         (gnus-handle-ephemeral-exit quit-config))
3644       ;; Finally signal the quit.
3645       (signal 'quit nil))
3646      ;; The group was successfully selected.
3647      (t
3648       (gnus-set-global-variables)
3649       ;; Save the active value in effect when the group was entered.
3650       (setq gnus-newsgroup-active
3651             (gnus-copy-sequence
3652              (gnus-active gnus-newsgroup-name)))
3653       ;; You can change the summary buffer in some way with this hook.
3654       (gnus-run-hooks 'gnus-select-group-hook)
3655       (when (memq 'summary (gnus-update-format-specifications
3656                             nil 'summary 'summary-mode 'summary-dummy))
3657         ;; The format specification for the summary line was updated,
3658         ;; so we need to update the mark positions as well.
3659         (gnus-update-summary-mark-positions))
3660       ;; Do score processing.
3661       (when gnus-use-scoring
3662         (gnus-possibly-score-headers))
3663       ;; Check whether to fill in the gaps in the threads.
3664       (when gnus-build-sparse-threads
3665         (gnus-build-sparse-threads))
3666       ;; Find the initial limit.
3667       (if show-all
3668           (let ((gnus-newsgroup-dormant nil))
3669             (gnus-summary-initial-limit show-all))
3670         (gnus-summary-initial-limit show-all))
3671       ;; Generate the summary buffer.
3672       (unless no-display
3673         (gnus-summary-prepare))
3674       (when gnus-use-trees
3675         (gnus-tree-open group)
3676         (setq gnus-summary-highlight-line-function
3677               'gnus-tree-highlight-article))
3678       ;; If the summary buffer is empty, but there are some low-scored
3679       ;; articles or some excluded dormants, we include these in the
3680       ;; buffer.
3681       (when (and (zerop (buffer-size))
3682                  (not no-display))
3683         (cond (gnus-newsgroup-dormant
3684                (gnus-summary-limit-include-dormant))
3685               ((and gnus-newsgroup-scored show-all)
3686                (gnus-summary-limit-include-expunged t))))
3687       ;; Function `gnus-apply-kill-file' must be called in this hook.
3688       (gnus-run-hooks 'gnus-apply-kill-hook)
3689       (if (and (zerop (buffer-size))
3690                (not no-display))
3691           (progn
3692             ;; This newsgroup is empty.
3693             (gnus-summary-catchup-and-exit nil t)
3694             (gnus-message 6 "No unread news")
3695             (when kill-buffer
3696               (gnus-kill-or-deaden-summary kill-buffer))
3697             ;; Return nil from this function.
3698             nil)
3699         ;; Hide conversation thread subtrees.  We cannot do this in
3700         ;; gnus-summary-prepare-hook since kill processing may not
3701         ;; work with hidden articles.
3702         (gnus-summary-maybe-hide-threads)
3703         (when kill-buffer
3704           (gnus-kill-or-deaden-summary kill-buffer))
3705         (gnus-summary-auto-select-subject)
3706         ;; Show first unread article if requested.
3707         (if (and (not no-article)
3708                  (not no-display)
3709                  gnus-newsgroup-unreads
3710                  gnus-auto-select-first)
3711             (progn
3712               (gnus-configure-windows 'summary)
3713               (let ((art (gnus-summary-article-number)))
3714                 (unless (and (not gnus-plugged)
3715                              (or (memq art gnus-newsgroup-undownloaded)
3716                                  (memq art gnus-newsgroup-downloadable)))
3717                   (gnus-summary-goto-article art))))
3718           ;; Don't select any articles.
3719           (gnus-summary-position-point)
3720           (gnus-configure-windows 'summary 'force)
3721           (gnus-set-mode-line 'summary))
3722         (when (and gnus-auto-center-group
3723                    (get-buffer-window gnus-group-buffer t))
3724           ;; Gotta use windows, because recenter does weird stuff if
3725           ;; the current buffer ain't the displayed window.
3726           (let ((owin (selected-window)))
3727             (select-window (get-buffer-window gnus-group-buffer t))
3728             (when (gnus-group-goto-group group)
3729               (recenter))
3730             (select-window owin)))
3731         ;; Mark this buffer as "prepared".
3732         (setq gnus-newsgroup-prepared t)
3733         (gnus-run-hooks 'gnus-summary-prepared-hook)
3734         (unless (gnus-ephemeral-group-p group)
3735           (gnus-group-update-group group))
3736         t)))))
3737
3738 (defun gnus-summary-auto-select-subject ()
3739   "Select the subject line on initial group entry."
3740   (goto-char (point-min))
3741   (cond
3742    ((eq gnus-auto-select-subject 'best)
3743     (gnus-summary-best-unread-subject))
3744    ((eq gnus-auto-select-subject 'unread)
3745     (gnus-summary-first-unread-subject))
3746    ((eq gnus-auto-select-subject 'unseen)
3747     (gnus-summary-first-unseen-subject))
3748    ((eq gnus-auto-select-subject 'unseen-or-unread)
3749     (gnus-summary-first-unseen-or-unread-subject))
3750    ((eq gnus-auto-select-subject 'first)
3751     ;; Do nothing.
3752     )
3753    ((functionp gnus-auto-select-subject)
3754     (funcall gnus-auto-select-subject))))
3755
3756 (defun gnus-summary-prepare ()
3757   "Generate the summary buffer."
3758   (interactive)
3759   (let ((buffer-read-only nil))
3760     (erase-buffer)
3761     (setq gnus-newsgroup-data nil
3762           gnus-newsgroup-data-reverse nil)
3763     (gnus-run-hooks 'gnus-summary-generate-hook)
3764     ;; Generate the buffer, either with threads or without.
3765     (when gnus-newsgroup-headers
3766       (gnus-summary-prepare-threads
3767        (if gnus-show-threads
3768            (gnus-sort-gathered-threads
3769             (funcall gnus-summary-thread-gathering-function
3770                      (gnus-sort-threads
3771                       (gnus-cut-threads (gnus-make-threads)))))
3772          ;; Unthreaded display.
3773          (gnus-sort-articles gnus-newsgroup-headers))))
3774     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3775     ;; Call hooks for modifying summary buffer.
3776     (goto-char (point-min))
3777     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3778
3779 (defsubst gnus-general-simplify-subject (subject)
3780   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3781   (setq subject
3782         (cond
3783          ;; Truncate the subject.
3784          (gnus-simplify-subject-functions
3785           (gnus-map-function gnus-simplify-subject-functions subject))
3786          ((numberp gnus-summary-gather-subject-limit)
3787           (setq subject (gnus-simplify-subject-re subject))
3788           (if (> (length subject) gnus-summary-gather-subject-limit)
3789               (substring subject 0 gnus-summary-gather-subject-limit)
3790             subject))
3791          ;; Fuzzily simplify it.
3792          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3793           (gnus-simplify-subject-fuzzy subject))
3794          ;; Just remove the leading "Re:".
3795          (t
3796           (gnus-simplify-subject-re subject))))
3797
3798   (if (and gnus-summary-gather-exclude-subject
3799            (string-match gnus-summary-gather-exclude-subject subject))
3800       nil                         ; This article shouldn't be gathered
3801     subject))
3802
3803 (defun gnus-summary-simplify-subject-query ()
3804   "Query where the respool algorithm would put this article."
3805   (interactive)
3806   (gnus-summary-select-article)
3807   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3808
3809 (defun gnus-gather-threads-by-subject (threads)
3810   "Gather threads by looking at Subject headers."
3811   (if (not gnus-summary-make-false-root)
3812       threads
3813     (let ((hashtb (gnus-make-hashtable 1024))
3814           (prev threads)
3815           (result threads)
3816           subject hthread whole-subject)
3817       (while threads
3818         (setq subject (gnus-general-simplify-subject
3819                        (setq whole-subject (mail-header-subject
3820                                             (caar threads)))))
3821         (when subject
3822           (if (setq hthread (gnus-gethash subject hashtb))
3823               (progn
3824                 ;; We enter a dummy root into the thread, if we
3825                 ;; haven't done that already.
3826                 (unless (stringp (caar hthread))
3827                   (setcar hthread (list whole-subject (car hthread))))
3828                 ;; We add this new gathered thread to this gathered
3829                 ;; thread.
3830                 (setcdr (car hthread)
3831                         (nconc (cdar hthread) (list (car threads))))
3832                 ;; Remove it from the list of threads.
3833                 (setcdr prev (cdr threads))
3834                 (setq threads prev))
3835             ;; Enter this thread into the hash table.
3836             (gnus-sethash subject
3837                           (if gnus-summary-make-false-root-always
3838                               (progn
3839                                 ;; If you want a dummy root above all
3840                                 ;; threads...
3841                                 (setcar threads (list whole-subject
3842                                                       (car threads)))
3843                                 threads)
3844                             threads)
3845                           hashtb)))
3846         (setq prev threads)
3847         (setq threads (cdr threads)))
3848       result)))
3849
3850 (defun gnus-gather-threads-by-references (threads)
3851   "Gather threads by looking at References headers."
3852   (let ((idhashtb (gnus-make-hashtable 1024))
3853         (thhashtb (gnus-make-hashtable 1024))
3854         (prev threads)
3855         (result threads)
3856         ids references id gthread gid entered ref)
3857     (while threads
3858       (when (setq references (mail-header-references (caar threads)))
3859         (setq id (mail-header-id (caar threads))
3860               ids (inline (gnus-split-references references))
3861               entered nil)
3862         (while (setq ref (pop ids))
3863           (setq ids (delete ref ids))
3864           (if (not (setq gid (gnus-gethash ref idhashtb)))
3865               (progn
3866                 (gnus-sethash ref id idhashtb)
3867                 (gnus-sethash id threads thhashtb))
3868             (setq gthread (gnus-gethash gid thhashtb))
3869             (unless entered
3870               ;; We enter a dummy root into the thread, if we
3871               ;; haven't done that already.
3872               (unless (stringp (caar gthread))
3873                 (setcar gthread (list (mail-header-subject (caar gthread))
3874                                       (car gthread))))
3875               ;; We add this new gathered thread to this gathered
3876               ;; thread.
3877               (setcdr (car gthread)
3878                       (nconc (cdar gthread) (list (car threads)))))
3879             ;; Add it into the thread hash table.
3880             (gnus-sethash id gthread thhashtb)
3881             (setq entered t)
3882             ;; Remove it from the list of threads.
3883             (setcdr prev (cdr threads))
3884             (setq threads prev))))
3885       (setq prev threads)
3886       (setq threads (cdr threads)))
3887     result))
3888
3889 (defun gnus-sort-gathered-threads (threads)
3890   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3891   (let ((result threads))
3892     (while threads
3893       (when (stringp (caar threads))
3894         (setcdr (car threads)
3895                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3896       (setq threads (cdr threads)))
3897     result))
3898
3899 (defun gnus-thread-loop-p (root thread)
3900   "Say whether ROOT is in THREAD."
3901   (let ((stack (list thread))
3902         (infloop 0)
3903         th)
3904     (while (setq thread (pop stack))
3905       (setq th (cdr thread))
3906       (while (and th
3907                   (not (eq (caar th) root)))
3908         (pop th))
3909       (if th
3910           ;; We have found a loop.
3911           (let (ref-dep)
3912             (setcdr thread (delq (car th) (cdr thread)))
3913             (if (boundp (setq ref-dep (intern "none"
3914                                               gnus-newsgroup-dependencies)))
3915                 (setcdr (symbol-value ref-dep)
3916                         (nconc (cdr (symbol-value ref-dep))
3917                                (list (car th))))
3918               (set ref-dep (list nil (car th))))
3919             (setq infloop 1
3920                   stack nil))
3921         ;; Push all the subthreads onto the stack.
3922         (push (cdr thread) stack)))
3923     infloop))
3924
3925 (defun gnus-make-threads ()
3926   "Go through the dependency hashtb and find the roots.  Return all threads."
3927   (let (threads)
3928     (while (catch 'infloop
3929              (mapatoms
3930               (lambda (refs)
3931                 ;; Deal with self-referencing References loops.
3932                 (when (and (car (symbol-value refs))
3933                            (not (zerop
3934                                  (apply
3935                                   '+
3936                                   (mapcar
3937                                    (lambda (thread)
3938                                      (gnus-thread-loop-p
3939                                       (car (symbol-value refs)) thread))
3940                                    (cdr (symbol-value refs)))))))
3941                   (setq threads nil)
3942                   (throw 'infloop t))
3943                 (unless (car (symbol-value refs))
3944                   ;; These threads do not refer back to any other
3945                   ;; articles, so they're roots.
3946                   (setq threads (append (cdr (symbol-value refs)) threads))))
3947               gnus-newsgroup-dependencies)))
3948     threads))
3949
3950 ;; Build the thread tree.
3951 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3952   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3953
3954 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3955 if it was already present.
3956
3957 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3958 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3959 Message-IDs will be renamed to a unique Message-ID before being
3960 entered.
3961
3962 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3963   (let* ((id (mail-header-id header))
3964          (id-dep (and id (intern id dependencies)))
3965          parent-id ref ref-dep ref-header replaced)
3966     ;; Enter this `header' in the `dependencies' table.
3967     (cond
3968      ((not id-dep)
3969       (setq header nil))
3970      ;; The first two cases do the normal part: enter a new `header'
3971      ;; in the `dependencies' table.
3972      ((not (boundp id-dep))
3973       (set id-dep (list header)))
3974      ((null (car (symbol-value id-dep)))
3975       (setcar (symbol-value id-dep) header))
3976
3977      ;; From here the `header' was already present in the
3978      ;; `dependencies' table.
3979      (force-new
3980       ;; Overrides an existing entry;
3981       ;; just set the header part of the entry.
3982       (setcar (symbol-value id-dep) header)
3983       (setq replaced t))
3984
3985      ;; Renames the existing `header' to a unique Message-ID.
3986      ((not gnus-summary-ignore-duplicates)
3987       ;; An article with this Message-ID has already been seen.
3988       ;; We rename the Message-ID.
3989       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3990            (list header))
3991       (mail-header-set-id header id))
3992
3993      ;; The last case ignores an existing entry, except it adds any
3994      ;; additional Xrefs (in case the two articles came from different
3995      ;; servers.
3996      ;; Also sets `header' to `nil' meaning that the `dependencies'
3997      ;; table was *not* modified.
3998      (t
3999       (mail-header-set-xref
4000        (car (symbol-value id-dep))
4001        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4002                    "")
4003                (or (mail-header-xref header) "")))
4004       (setq header nil)))
4005
4006     (when (and header (not replaced))
4007       ;; First check that we are not creating a References loop.
4008       (setq parent-id (gnus-parent-id (mail-header-references header)))
4009       (setq ref parent-id)
4010       (while (and ref
4011                   (setq ref-dep (intern-soft ref dependencies))
4012                   (boundp ref-dep)
4013                   (setq ref-header (car (symbol-value ref-dep))))
4014         (if (string= id ref)
4015             ;; Yuk!  This is a reference loop.  Make the article be a
4016             ;; root article.
4017             (progn
4018               (mail-header-set-references (car (symbol-value id-dep)) "none")
4019               (setq ref nil)
4020               (setq parent-id nil))
4021           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4022       (setq ref-dep (intern (or parent-id "none") dependencies))
4023       (if (boundp ref-dep)
4024           (setcdr (symbol-value ref-dep)
4025                   (nconc (cdr (symbol-value ref-dep))
4026                          (list (symbol-value id-dep))))
4027         (set ref-dep (list nil (symbol-value id-dep)))))
4028     header))
4029
4030 (defun gnus-extract-message-id-from-in-reply-to (string)
4031   (if (string-match "<[^>]+>" string)
4032       (substring string (match-beginning 0) (match-end 0))
4033     nil))
4034
4035 (defun gnus-build-sparse-threads ()
4036   (let ((headers gnus-newsgroup-headers)
4037         (mail-parse-charset gnus-newsgroup-charset)
4038         (gnus-summary-ignore-duplicates t)
4039         header references generation relations
4040         subject child end new-child date)
4041     ;; First we create an alist of generations/relations, where
4042     ;; generations is how much we trust the relation, and the relation
4043     ;; is parent/child.
4044     (gnus-message 7 "Making sparse threads...")
4045     (save-excursion
4046       (nnheader-set-temp-buffer " *gnus sparse threads*")
4047       (while (setq header (pop headers))
4048         (when (and (setq references (mail-header-references header))
4049                    (not (string= references "")))
4050           (insert references)
4051           (setq child (mail-header-id header)
4052                 subject (mail-header-subject header)
4053                 date (mail-header-date header)
4054                 generation 0)
4055           (while (search-backward ">" nil t)
4056             (setq end (1+ (point)))
4057             (when (search-backward "<" nil t)
4058               (setq new-child (buffer-substring (point) end))
4059               (push (list (incf generation)
4060                           child (setq child new-child)
4061                           subject date)
4062                     relations)))
4063           (when child
4064             (push (list (1+ generation) child nil subject) relations))
4065           (erase-buffer)))
4066       (kill-buffer (current-buffer)))
4067     ;; Sort over trustworthiness.
4068     (mapcar
4069      (lambda (relation)
4070        (when (gnus-dependencies-add-header
4071               (make-full-mail-header
4072                gnus-reffed-article-number
4073                (nth 3 relation) "" (or (nth 4 relation) "")
4074                (nth 1 relation)
4075                (or (nth 2 relation) "") 0 0 "")
4076               gnus-newsgroup-dependencies nil)
4077          (push gnus-reffed-article-number gnus-newsgroup-limit)
4078          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4079          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4080                gnus-newsgroup-reads)
4081          (decf gnus-reffed-article-number)))
4082      (sort relations 'car-less-than-car))
4083     (gnus-message 7 "Making sparse threads...done")))
4084
4085 (defun gnus-build-old-threads ()
4086   ;; Look at all the articles that refer back to old articles, and
4087   ;; fetch the headers for the articles that aren't there.  This will
4088   ;; build complete threads - if the roots haven't been expired by the
4089   ;; server, that is.
4090   (let ((mail-parse-charset gnus-newsgroup-charset)
4091         id heads)
4092     (mapatoms
4093      (lambda (refs)
4094        (when (not (car (symbol-value refs)))
4095          (setq heads (cdr (symbol-value refs)))
4096          (while heads
4097            (if (memq (mail-header-number (caar heads))
4098                      gnus-newsgroup-dormant)
4099                (setq heads (cdr heads))
4100              (setq id (symbol-name refs))
4101              (while (and (setq id (gnus-build-get-header id))
4102                          (not (car (gnus-id-to-thread id)))))
4103              (setq heads nil)))))
4104      gnus-newsgroup-dependencies)))
4105
4106 (defsubst gnus-remove-odd-characters (string)
4107   "Translate STRING into something that doesn't contain weird characters."
4108   (mm-subst-char-in-string
4109    ?\r ?\-
4110    (mm-subst-char-in-string ?\n ?\- string t) t))
4111
4112 ;; This function has to be called with point after the article number
4113 ;; on the beginning of the line.
4114 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4115   (let ((eol (point-at-eol))
4116         (buffer (current-buffer))
4117         header references in-reply-to)
4118
4119     ;; overview: [num subject from date id refs chars lines misc]
4120     (unwind-protect
4121         (let (x)
4122           (narrow-to-region (point) eol)
4123           (unless (eobp)
4124             (forward-char))
4125
4126           (setq header
4127                 (make-full-mail-header
4128                  number                 ; number
4129                  (condition-case ()     ; subject
4130                      (gnus-remove-odd-characters
4131                       (funcall gnus-decode-encoded-word-function
4132                                (setq x (nnheader-nov-field))))
4133                    (error x))
4134                  (condition-case ()     ; from
4135                      (gnus-remove-odd-characters
4136                       (funcall gnus-decode-encoded-word-function
4137                                (setq x (nnheader-nov-field))))
4138                    (error x))
4139                  (nnheader-nov-field)   ; date
4140                  (nnheader-nov-read-message-id number)  ; id
4141                  (setq references (nnheader-nov-field)) ; refs
4142                  (nnheader-nov-read-integer) ; chars
4143                  (nnheader-nov-read-integer) ; lines
4144                  (unless (eobp)
4145                    (if (looking-at "Xref: ")
4146                        (goto-char (match-end 0)))
4147                    (nnheader-nov-field)) ; Xref
4148                  (nnheader-nov-parse-extra)))) ; extra
4149
4150       (widen))
4151
4152     (when (and (string= references "")
4153                (setq in-reply-to (mail-header-extra header))
4154                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4155       (mail-header-set-references
4156        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4157
4158     (when gnus-alter-header-function
4159       (funcall gnus-alter-header-function header))
4160     (gnus-dependencies-add-header header dependencies force-new)))
4161
4162 (defun gnus-build-get-header (id)
4163   "Look through the buffer of NOV lines and find the header to ID.
4164 Enter this line into the dependencies hash table, and return
4165 the id of the parent article (if any)."
4166   (let ((deps gnus-newsgroup-dependencies)
4167         found header)
4168     (prog1
4169         (save-excursion
4170           (set-buffer nntp-server-buffer)
4171           (let ((case-fold-search nil))
4172             (goto-char (point-min))
4173             (while (and (not found)
4174                         (search-forward id nil t))
4175               (beginning-of-line)
4176               (setq found (looking-at
4177                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4178                                    (regexp-quote id))))
4179               (or found (beginning-of-line 2)))
4180             (when found
4181               (beginning-of-line)
4182               (and
4183                (setq header (gnus-nov-parse-line
4184                              (read (current-buffer)) deps))
4185                (gnus-parent-id (mail-header-references header))))))
4186       (when header
4187         (let ((number (mail-header-number header)))
4188           (push number gnus-newsgroup-limit)
4189           (push header gnus-newsgroup-headers)
4190           (if (memq number gnus-newsgroup-unselected)
4191               (progn
4192                 (setq gnus-newsgroup-unreads
4193                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4194                                                number))
4195                 (setq gnus-newsgroup-unselected
4196                       (delq number gnus-newsgroup-unselected)))
4197             (push number gnus-newsgroup-ancient)))))))
4198
4199 (defun gnus-build-all-threads ()
4200   "Read all the headers."
4201   (let ((gnus-summary-ignore-duplicates t)
4202         (mail-parse-charset gnus-newsgroup-charset)
4203         (dependencies gnus-newsgroup-dependencies)
4204         header article)
4205     (save-excursion
4206       (set-buffer nntp-server-buffer)
4207       (let ((case-fold-search nil))
4208         (goto-char (point-min))
4209         (while (not (eobp))
4210           (ignore-errors
4211             (setq article (read (current-buffer))
4212                   header (gnus-nov-parse-line article dependencies)))
4213           (when header
4214             (with-current-buffer gnus-summary-buffer
4215               (push header gnus-newsgroup-headers)
4216               (if (memq (setq article (mail-header-number header))
4217                         gnus-newsgroup-unselected)
4218                   (progn
4219                     (setq gnus-newsgroup-unreads
4220                           (gnus-add-to-sorted-list
4221                            gnus-newsgroup-unreads article))
4222                     (setq gnus-newsgroup-unselected
4223                           (delq article gnus-newsgroup-unselected)))
4224                 (push article gnus-newsgroup-ancient)))
4225             (forward-line 1)))))))
4226
4227 (defun gnus-summary-update-article-line (article header)
4228   "Update the line for ARTICLE using HEADER."
4229   (let* ((id (mail-header-id header))
4230          (thread (gnus-id-to-thread id)))
4231     (unless thread
4232       (error "Article in no thread"))
4233     ;; Update the thread.
4234     (setcar thread header)
4235     (gnus-summary-goto-subject article)
4236     (let* ((datal (gnus-data-find-list article))
4237            (data (car datal))
4238            (buffer-read-only nil)
4239            (level (gnus-summary-thread-level)))
4240       (gnus-delete-line)
4241       (let ((inserted (- (point)
4242                          (progn
4243                            (gnus-summary-insert-line
4244                             header level nil
4245                             (memq article gnus-newsgroup-undownloaded)
4246                             (gnus-article-mark article)
4247                             (memq article gnus-newsgroup-replied)
4248                             (memq article gnus-newsgroup-expirable)
4249                             ;; Only insert the Subject string when it's different
4250                             ;; from the previous Subject string.
4251                             (if (and
4252                                  gnus-show-threads
4253                                  (gnus-subject-equal
4254                                   (condition-case ()
4255                                       (mail-header-subject
4256                                        (gnus-data-header
4257                                         (cadr
4258                                          (gnus-data-find-list
4259                                           article
4260                                           (gnus-data-list t)))))
4261                                     ;; Error on the side of excessive subjects.
4262                                     (error ""))
4263                                   (mail-header-subject header)))
4264                                 ""
4265                               (mail-header-subject header))
4266                             nil (cdr (assq article gnus-newsgroup-scored))
4267                             (memq article gnus-newsgroup-processable))
4268                            (point)))))
4269         (when (cdr datal)
4270           (gnus-data-update-list
4271            (cdr datal)
4272            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4273
4274 (defun gnus-summary-update-article (article &optional iheader)
4275   "Update ARTICLE in the summary buffer."
4276   (set-buffer gnus-summary-buffer)
4277   (let* ((header (gnus-summary-article-header article))
4278          (id (mail-header-id header))
4279          (data (gnus-data-find article))
4280          (thread (gnus-id-to-thread id))
4281          (references (mail-header-references header))
4282          (parent
4283           (gnus-id-to-thread
4284            (or (gnus-parent-id
4285                 (when (and references
4286                            (not (equal "" references)))
4287                   references))
4288                "none")))
4289          (buffer-read-only nil)
4290          (old (car thread)))
4291     (when thread
4292       (unless iheader
4293         (setcar thread nil)
4294         (when parent
4295           (delq thread parent)))
4296       (if (gnus-summary-insert-subject id header)
4297           ;; Set the (possibly) new article number in the data structure.
4298           (gnus-data-set-number data (gnus-id-to-article id))
4299         (setcar thread old)
4300         nil))))
4301
4302 (defun gnus-rebuild-thread (id &optional line)
4303   "Rebuild the thread containing ID.
4304 If LINE, insert the rebuilt thread starting on line LINE."
4305   (let ((buffer-read-only nil)
4306         old-pos current thread data)
4307     (if (not gnus-show-threads)
4308         (setq thread (list (car (gnus-id-to-thread id))))
4309       ;; Get the thread this article is part of.
4310       (setq thread (gnus-remove-thread id)))
4311     (setq old-pos (point-at-bol))
4312     (setq current (save-excursion
4313                     (and (re-search-backward "[\r\n]" nil t)
4314                          (gnus-summary-article-number))))
4315     ;; If this is a gathered thread, we have to go some re-gathering.
4316     (when (stringp (car thread))
4317       (let ((subject (car thread))
4318             roots thr)
4319         (setq thread (cdr thread))
4320         (while thread
4321           (unless (memq (setq thr (gnus-id-to-thread
4322                                    (gnus-root-id
4323                                     (mail-header-id (caar thread)))))
4324                         roots)
4325             (push thr roots))
4326           (setq thread (cdr thread)))
4327         ;; We now have all (unique) roots.
4328         (if (= (length roots) 1)
4329             ;; All the loose roots are now one solid root.
4330             (setq thread (car roots))
4331           (setq thread (cons subject (gnus-sort-threads roots))))))
4332     (let (threads)
4333       ;; We then insert this thread into the summary buffer.
4334       (when line
4335         (goto-char (point-min))
4336         (forward-line (1- line)))
4337       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4338         (if gnus-show-threads
4339             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4340           (gnus-summary-prepare-unthreaded thread))
4341         (setq data (nreverse gnus-newsgroup-data))
4342         (setq threads gnus-newsgroup-threads))
4343       ;; We splice the new data into the data structure.
4344       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4345       ;;!!! then we want to insert at the beginning of the buffer.
4346       ;;!!! That happens to be true with Gnus now, but that may
4347       ;;!!! change in the future.  Perhaps.
4348       (gnus-data-enter-list
4349        (if line nil current) data (- (point) old-pos))
4350       (setq gnus-newsgroup-threads
4351             (nconc threads gnus-newsgroup-threads))
4352       (gnus-data-compute-positions))))
4353
4354 (defun gnus-number-to-header (number)
4355   "Return the header for article NUMBER."
4356   (let ((headers gnus-newsgroup-headers))
4357     (while (and headers
4358                 (not (= number (mail-header-number (car headers)))))
4359       (pop headers))
4360     (when headers
4361       (car headers))))
4362
4363 (defun gnus-parent-headers (in-headers &optional generation)
4364   "Return the headers of the GENERATIONeth parent of HEADERS."
4365   (unless generation
4366     (setq generation 1))
4367   (let ((parent t)
4368         (headers in-headers)
4369         references)
4370     (while (and parent
4371                 (not (zerop generation))
4372                 (setq references (mail-header-references headers)))
4373       (setq headers (if (and references
4374                              (setq parent (gnus-parent-id references)))
4375                         (car (gnus-id-to-thread parent))
4376                       nil))
4377       (decf generation))
4378     (and (not (eq headers in-headers))
4379          headers)))
4380
4381 (defun gnus-id-to-thread (id)
4382   "Return the (sub-)thread where ID appears."
4383   (gnus-gethash id gnus-newsgroup-dependencies))
4384
4385 (defun gnus-id-to-article (id)
4386   "Return the article number of ID."
4387   (let ((thread (gnus-id-to-thread id)))
4388     (when (and thread
4389                (car thread))
4390       (mail-header-number (car thread)))))
4391
4392 (defun gnus-id-to-header (id)
4393   "Return the article headers of ID."
4394   (car (gnus-id-to-thread id)))
4395
4396 (defun gnus-article-displayed-root-p (article)
4397   "Say whether ARTICLE is a root(ish) article."
4398   (let ((level (gnus-summary-thread-level article))
4399         (refs (mail-header-references  (gnus-summary-article-header article)))
4400         particle)
4401     (cond
4402      ((null level) nil)
4403      ((zerop level) t)
4404      ((null refs) t)
4405      ((null (gnus-parent-id refs)) t)
4406      ((and (= 1 level)
4407            (null (setq particle (gnus-id-to-article
4408                                  (gnus-parent-id refs))))
4409            (null (gnus-summary-thread-level particle)))))))
4410
4411 (defun gnus-root-id (id)
4412   "Return the id of the root of the thread where ID appears."
4413   (let (last-id prev)
4414     (while (and id (setq prev (car (gnus-id-to-thread id))))
4415       (setq last-id id
4416             id (gnus-parent-id (mail-header-references prev))))
4417     last-id))
4418
4419 (defun gnus-articles-in-thread (thread)
4420   "Return the list of articles in THREAD."
4421   (cons (mail-header-number (car thread))
4422         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4423
4424 (defun gnus-remove-thread (id &optional dont-remove)
4425   "Remove the thread that has ID in it."
4426   (let (headers thread last-id)
4427     ;; First go up in this thread until we find the root.
4428     (setq last-id (gnus-root-id id)
4429           headers (message-flatten-list (gnus-id-to-thread last-id)))
4430     ;; We have now found the real root of this thread.  It might have
4431     ;; been gathered into some loose thread, so we have to search
4432     ;; through the threads to find the thread we wanted.
4433     (let ((threads gnus-newsgroup-threads)
4434           sub)
4435       (while threads
4436         (setq sub (car threads))
4437         (if (stringp (car sub))
4438             ;; This is a gathered thread, so we look at the roots
4439             ;; below it to find whether this article is in this
4440             ;; gathered root.
4441             (progn
4442               (setq sub (cdr sub))
4443               (while sub
4444                 (when (member (caar sub) headers)
4445                   (setq thread (car threads)
4446                         threads nil
4447                         sub nil))
4448                 (setq sub (cdr sub))))
4449           ;; It's an ordinary thread, so we check it.
4450           (when (eq (car sub) (car headers))
4451             (setq thread sub
4452                   threads nil)))
4453         (setq threads (cdr threads)))
4454       ;; If this article is in no thread, then it's a root.
4455       (if thread
4456           (unless dont-remove
4457             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4458         (setq thread (gnus-id-to-thread last-id)))
4459       (when thread
4460         (prog1
4461             thread                      ; We return this thread.
4462           (unless dont-remove
4463             (if (stringp (car thread))
4464                 (progn
4465                   ;; If we use dummy roots, then we have to remove the
4466                   ;; dummy root as well.
4467                   (when (eq gnus-summary-make-false-root 'dummy)
4468                     ;; We go to the dummy root by going to
4469                     ;; the first sub-"thread", and then one line up.
4470                     (gnus-summary-goto-article
4471                      (mail-header-number (caadr thread)))
4472                     (forward-line -1)
4473                     (gnus-delete-line)
4474                     (gnus-data-compute-positions))
4475                   (setq thread (cdr thread))
4476                   (while thread
4477                     (gnus-remove-thread-1 (car thread))
4478                     (setq thread (cdr thread))))
4479               (gnus-remove-thread-1 thread))))))))
4480
4481 (defun gnus-remove-thread-1 (thread)
4482   "Remove the thread THREAD recursively."
4483   (let ((number (mail-header-number (pop thread)))
4484         d)
4485     (setq thread (reverse thread))
4486     (while thread
4487       (gnus-remove-thread-1 (pop thread)))
4488     (when (setq d (gnus-data-find number))
4489       (goto-char (gnus-data-pos d))
4490       (gnus-summary-show-thread)
4491       (gnus-data-remove
4492        number
4493        (- (point-at-bol)
4494           (prog1
4495               (1+ (point-at-eol))
4496             (gnus-delete-line)))))))
4497
4498 (defun gnus-sort-threads-1 (threads func)
4499   (sort (mapcar (lambda (thread)
4500                   (cons (car thread)
4501                         (and (cdr thread)
4502                              (gnus-sort-threads-1 (cdr thread) func))))
4503                 threads) func))
4504
4505 (defun gnus-sort-threads (threads)
4506   "Sort THREADS."
4507   (if (not gnus-thread-sort-functions)
4508       threads
4509     (gnus-message 8 "Sorting threads...")
4510     (let ((max-lisp-eval-depth 5000))
4511       (prog1 (gnus-sort-threads-1
4512          threads
4513          (gnus-make-sort-function gnus-thread-sort-functions))
4514         (gnus-message 8 "Sorting threads...done")))))
4515
4516 (defun gnus-sort-articles (articles)
4517   "Sort ARTICLES."
4518   (when gnus-article-sort-functions
4519     (gnus-message 7 "Sorting articles...")
4520     (prog1
4521         (setq gnus-newsgroup-headers
4522               (sort articles (gnus-make-sort-function
4523                               gnus-article-sort-functions)))
4524       (gnus-message 7 "Sorting articles...done"))))
4525
4526 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4527 (defmacro gnus-thread-header (thread)
4528   "Return header of first article in THREAD.
4529 Note that THREAD must never, ever be anything else than a variable -
4530 using some other form will lead to serious barfage."
4531   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4532   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4533   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4534         (vector thread) 2))
4535
4536 (defsubst gnus-article-sort-by-number (h1 h2)
4537   "Sort articles by article number."
4538   (< (mail-header-number h1)
4539      (mail-header-number h2)))
4540
4541 (defun gnus-thread-sort-by-number (h1 h2)
4542   "Sort threads by root article number."
4543   (gnus-article-sort-by-number
4544    (gnus-thread-header h1) (gnus-thread-header h2)))
4545
4546 (defsubst gnus-article-sort-by-random (h1 h2)
4547   "Sort articles by article number."
4548   (zerop (random 2)))
4549
4550 (defun gnus-thread-sort-by-random (h1 h2)
4551   "Sort threads by root article number."
4552   (gnus-article-sort-by-random
4553    (gnus-thread-header h1) (gnus-thread-header h2)))
4554
4555 (defsubst gnus-article-sort-by-lines (h1 h2)
4556   "Sort articles by article Lines header."
4557   (< (mail-header-lines h1)
4558      (mail-header-lines h2)))
4559
4560 (defun gnus-thread-sort-by-lines (h1 h2)
4561   "Sort threads by root article Lines header."
4562   (gnus-article-sort-by-lines
4563    (gnus-thread-header h1) (gnus-thread-header h2)))
4564
4565 (defsubst gnus-article-sort-by-chars (h1 h2)
4566   "Sort articles by octet length."
4567   (< (mail-header-chars h1)
4568      (mail-header-chars h2)))
4569
4570 (defun gnus-thread-sort-by-chars (h1 h2)
4571   "Sort threads by root article octet length."
4572   (gnus-article-sort-by-chars
4573    (gnus-thread-header h1) (gnus-thread-header h2)))
4574
4575 (defsubst gnus-article-sort-by-author (h1 h2)
4576   "Sort articles by root author."
4577   (string-lessp
4578    (let ((extract (funcall
4579                    gnus-extract-address-components
4580                    (mail-header-from h1))))
4581      (or (car extract) (cadr extract) ""))
4582    (let ((extract (funcall
4583                    gnus-extract-address-components
4584                    (mail-header-from h2))))
4585      (or (car extract) (cadr extract) ""))))
4586
4587 (defun gnus-thread-sort-by-author (h1 h2)
4588   "Sort threads by root author."
4589   (gnus-article-sort-by-author
4590    (gnus-thread-header h1)  (gnus-thread-header h2)))
4591
4592 (defsubst gnus-article-sort-by-recipient (h1 h2)
4593   "Sort articles by recipient."
4594   (string-lessp
4595    (let ((extract (funcall
4596                    gnus-extract-address-components
4597                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4598      (or (car extract) (cadr extract)))
4599    (let ((extract (funcall
4600                    gnus-extract-address-components
4601                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4602      (or (car extract) (cadr extract)))))
4603
4604 (defsubst gnus-article-sort-by-subject (h1 h2)
4605   "Sort articles by root subject."
4606   (string-lessp
4607    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4608    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4609
4610 (defun gnus-thread-sort-by-subject (h1 h2)
4611   "Sort threads by root subject."
4612   (gnus-article-sort-by-subject
4613    (gnus-thread-header h1) (gnus-thread-header h2)))
4614
4615 (defsubst gnus-article-sort-by-date (h1 h2)
4616   "Sort articles by root article date."
4617   (time-less-p
4618    (gnus-date-get-time (mail-header-date h1))
4619    (gnus-date-get-time (mail-header-date h2))))
4620
4621 (defun gnus-thread-sort-by-date (h1 h2)
4622   "Sort threads by root article date."
4623   (gnus-article-sort-by-date
4624    (gnus-thread-header h1) (gnus-thread-header h2)))
4625
4626 (defsubst gnus-article-sort-by-score (h1 h2)
4627   "Sort articles by root article score.
4628 Unscored articles will be counted as having a score of zero."
4629   (> (or (cdr (assq (mail-header-number h1)
4630                     gnus-newsgroup-scored))
4631          gnus-summary-default-score 0)
4632      (or (cdr (assq (mail-header-number h2)
4633                     gnus-newsgroup-scored))
4634          gnus-summary-default-score 0)))
4635
4636 (defun gnus-thread-sort-by-score (h1 h2)
4637   "Sort threads by root article score."
4638   (gnus-article-sort-by-score
4639    (gnus-thread-header h1) (gnus-thread-header h2)))
4640
4641 (defun gnus-thread-sort-by-total-score (h1 h2)
4642   "Sort threads by the sum of all scores in the thread.
4643 Unscored articles will be counted as having a score of zero."
4644   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4645
4646 (defun gnus-thread-total-score (thread)
4647   ;; This function find the total score of THREAD.
4648   (cond
4649    ((null thread)
4650     0)
4651    ((consp thread)
4652     (if (stringp (car thread))
4653         (apply gnus-thread-score-function 0
4654                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4655       (gnus-thread-total-score-1 thread)))
4656    (t
4657     (gnus-thread-total-score-1 (list thread)))))
4658
4659 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4660   "Sort threads such that the thread with the most recently arrived article comes first."
4661   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4662
4663 (defun gnus-thread-highest-number (thread)
4664   "Return the highest article number in THREAD."
4665   (apply 'max (mapcar (lambda (header)
4666                         (mail-header-number header))
4667                       (message-flatten-list thread))))
4668
4669 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4670   "Sort threads such that the thread with the most recently dated article comes first."
4671   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4672
4673 (defun gnus-thread-latest-date (thread)
4674   "Return the highest article date in THREAD."
4675   (let ((previous-time 0))
4676     (apply 'max
4677            (mapcar
4678             (lambda (header)
4679               (setq previous-time
4680                     (condition-case ()
4681                         (time-to-seconds (mail-header-parse-date
4682                                           (mail-header-date header)))
4683                       (error previous-time))))
4684             (sort
4685              (message-flatten-list thread)
4686              (lambda (h1 h2)
4687                (< (mail-header-number h1)
4688                   (mail-header-number h2))))))))
4689
4690 (defun gnus-thread-total-score-1 (root)
4691   ;; This function find the total score of the thread below ROOT.
4692   (setq root (car root))
4693   (apply gnus-thread-score-function
4694          (or (append
4695               (mapcar 'gnus-thread-total-score
4696                       (cdr (gnus-id-to-thread (mail-header-id root))))
4697               (when (> (mail-header-number root) 0)
4698                 (list (or (cdr (assq (mail-header-number root)
4699                                      gnus-newsgroup-scored))
4700                           gnus-summary-default-score 0))))
4701              (list gnus-summary-default-score)
4702              '(0))))
4703
4704 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4705 (defvar gnus-tmp-prev-subject nil)
4706 (defvar gnus-tmp-false-parent nil)
4707 (defvar gnus-tmp-root-expunged nil)
4708 (defvar gnus-tmp-dummy-line nil)
4709
4710 (eval-when-compile (defvar gnus-tmp-header))
4711 (defun gnus-extra-header (type &optional header)
4712   "Return the extra header of TYPE."
4713   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4714       ""))
4715
4716 (defvar gnus-tmp-thread-tree-header-string "")
4717
4718 (defcustom gnus-sum-thread-tree-root "> "
4719   "With %B spec, used for the root of a thread.
4720 If nil, use subject instead."
4721   :version "22.1"
4722   :type '(radio (const :format "%v  " nil) string)
4723   :group 'gnus-thread)
4724 (defcustom gnus-sum-thread-tree-false-root "> "
4725   "With %B spec, used for a false root of a thread.
4726 If nil, use subject instead."
4727   :version "22.1"
4728   :type '(radio (const :format "%v  " nil) string)
4729   :group 'gnus-thread)
4730 (defcustom gnus-sum-thread-tree-single-indent ""
4731   "With %B spec, used for a thread with just one message.
4732 If nil, use subject instead."
4733   :version "22.1"
4734   :type '(radio (const :format "%v  " nil) string)
4735   :group 'gnus-thread)
4736 (defcustom gnus-sum-thread-tree-vertical "| "
4737   "With %B spec, used for drawing a vertical line."
4738   :version "22.1"
4739   :type 'string
4740   :group 'gnus-thread)
4741 (defcustom gnus-sum-thread-tree-indent "  "
4742   "With %B spec, used for indenting."
4743   :version "22.1"
4744   :type 'string
4745   :group 'gnus-thread)
4746 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4747   "With %B spec, used for a leaf with brothers."
4748   :version "22.1"
4749   :type 'string
4750   :group 'gnus-thread)
4751 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4752   "With %B spec, used for a leaf without brothers."
4753   :version "22.1"
4754   :type 'string
4755   :group 'gnus-thread)
4756
4757 (defun gnus-summary-prepare-threads (threads)
4758   "Prepare summary buffer from THREADS and indentation LEVEL.
4759 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4760 or a straight list of headers."
4761   (gnus-message 7 "Generating summary...")
4762
4763   (setq gnus-newsgroup-threads threads)
4764   (beginning-of-line)
4765
4766   (let ((gnus-tmp-level 0)
4767         (default-score (or gnus-summary-default-score 0))
4768         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4769         (building-line-count gnus-summary-display-while-building)
4770         (building-count (integerp gnus-summary-display-while-building))
4771         thread number subject stack state gnus-tmp-gathered beg-match
4772         new-roots gnus-tmp-new-adopts thread-end simp-subject
4773         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4774         gnus-tmp-replied gnus-tmp-subject-or-nil
4775         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4776         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4777         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4778         tree-stack)
4779
4780     (setq gnus-tmp-prev-subject nil
4781           gnus-tmp-thread-tree-header-string "")
4782
4783     (if (vectorp (car threads))
4784         ;; If this is a straight (sic) list of headers, then a
4785         ;; threaded summary display isn't required, so we just create
4786         ;; an unthreaded one.
4787         (gnus-summary-prepare-unthreaded threads)
4788
4789       ;; Do the threaded display.
4790
4791       (if gnus-summary-display-while-building
4792           (switch-to-buffer (buffer-name)))
4793       (while (or threads stack gnus-tmp-new-adopts new-roots)
4794
4795         (if (and (= gnus-tmp-level 0)
4796                  (or (not stack)
4797                      (= (caar stack) 0))
4798                  (not gnus-tmp-false-parent)
4799                  (or gnus-tmp-new-adopts new-roots))
4800             (if gnus-tmp-new-adopts
4801                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4802                       thread (list (car gnus-tmp-new-adopts))
4803                       gnus-tmp-header (caar thread)
4804                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4805               (when new-roots
4806                 (setq thread (list (car new-roots))
4807                       gnus-tmp-header (caar thread)
4808                       new-roots (cdr new-roots))))
4809
4810           (if threads
4811               ;; If there are some threads, we do them before the
4812               ;; threads on the stack.
4813               (setq thread threads
4814                     gnus-tmp-header (caar thread))
4815             ;; There were no current threads, so we pop something off
4816             ;; the stack.
4817             (setq state (car stack)
4818                   gnus-tmp-level (car state)
4819                   tree-stack (cadr state)
4820                   thread (caddr state)
4821                   stack (cdr stack)
4822                   gnus-tmp-header (caar thread))))
4823
4824         (setq gnus-tmp-false-parent nil)
4825         (setq gnus-tmp-root-expunged nil)
4826         (setq thread-end nil)
4827
4828         (if (stringp gnus-tmp-header)
4829             ;; The header is a dummy root.
4830             (cond
4831              ((eq gnus-summary-make-false-root 'adopt)
4832               ;; We let the first article adopt the rest.
4833               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4834                                                (cddar thread)))
4835               (setq gnus-tmp-gathered
4836                     (nconc (mapcar
4837                             (lambda (h) (mail-header-number (car h)))
4838                             (cddar thread))
4839                            gnus-tmp-gathered))
4840               (setq thread (cons (list (caar thread)
4841                                        (cadar thread))
4842                                  (cdr thread)))
4843               (setq gnus-tmp-level -1
4844                     gnus-tmp-false-parent t))
4845              ((eq gnus-summary-make-false-root 'empty)
4846               ;; We print adopted articles with empty subject fields.
4847               (setq gnus-tmp-gathered
4848                     (nconc (mapcar
4849                             (lambda (h) (mail-header-number (car h)))
4850                             (cddar thread))
4851                            gnus-tmp-gathered))
4852               (setq gnus-tmp-level -1))
4853              ((eq gnus-summary-make-false-root 'dummy)
4854               ;; We remember that we probably want to output a dummy
4855               ;; root.
4856               (setq gnus-tmp-dummy-line gnus-tmp-header)
4857               (setq gnus-tmp-prev-subject gnus-tmp-header))
4858              (t
4859               ;; We do not make a root for the gathered
4860               ;; sub-threads at all.
4861               (setq gnus-tmp-level -1)))
4862
4863           (setq number (mail-header-number gnus-tmp-header)
4864                 subject (mail-header-subject gnus-tmp-header)
4865                 simp-subject (gnus-simplify-subject-fully subject))
4866
4867           (cond
4868            ;; If the thread has changed subject, we might want to make
4869            ;; this subthread into a root.
4870            ((and (null gnus-thread-ignore-subject)
4871                  (not (zerop gnus-tmp-level))
4872                  gnus-tmp-prev-subject
4873                  (not (string= gnus-tmp-prev-subject simp-subject)))
4874             (setq new-roots (nconc new-roots (list (car thread)))
4875                   thread-end t
4876                   gnus-tmp-header nil))
4877            ;; If the article lies outside the current limit,
4878            ;; then we do not display it.
4879            ((not (memq number gnus-newsgroup-limit))
4880             (setq gnus-tmp-gathered
4881                   (nconc (mapcar
4882                           (lambda (h) (mail-header-number (car h)))
4883                           (cdar thread))
4884                          gnus-tmp-gathered))
4885             (setq gnus-tmp-new-adopts (if (cdar thread)
4886                                           (append gnus-tmp-new-adopts
4887                                                   (cdar thread))
4888                                         gnus-tmp-new-adopts)
4889                   thread-end t
4890                   gnus-tmp-header nil)
4891             (when (zerop gnus-tmp-level)
4892               (setq gnus-tmp-root-expunged t)))
4893            ;; Perhaps this article is to be marked as read?
4894            ((and gnus-summary-mark-below
4895                  (< (or (cdr (assq number gnus-newsgroup-scored))
4896                         default-score)
4897                     gnus-summary-mark-below)
4898                  ;; Don't touch sparse articles.
4899                  (not (gnus-summary-article-sparse-p number))
4900                  (not (gnus-summary-article-ancient-p number)))
4901             (setq gnus-newsgroup-unreads
4902                   (delq number gnus-newsgroup-unreads))
4903             (if gnus-newsgroup-auto-expire
4904                 (setq gnus-newsgroup-expirable
4905                       (gnus-add-to-sorted-list
4906                        gnus-newsgroup-expirable number))
4907               (push (cons number gnus-low-score-mark)
4908                     gnus-newsgroup-reads))))
4909
4910           (when gnus-tmp-header
4911             ;; We may have an old dummy line to output before this
4912             ;; article.
4913             (when (and gnus-tmp-dummy-line
4914                        (gnus-subject-equal
4915                         gnus-tmp-dummy-line
4916                         (mail-header-subject gnus-tmp-header)))
4917               (gnus-summary-insert-dummy-line
4918                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4919               (setq gnus-tmp-dummy-line nil))
4920
4921             ;; Compute the mark.
4922             (setq gnus-tmp-unread (gnus-article-mark number))
4923
4924             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4925                                   gnus-tmp-header gnus-tmp-level)
4926                   gnus-newsgroup-data)
4927
4928             ;; Actually insert the line.
4929             (setq
4930              gnus-tmp-subject-or-nil
4931              (cond
4932               ((and gnus-thread-ignore-subject
4933                     gnus-tmp-prev-subject
4934                     (not (string= gnus-tmp-prev-subject simp-subject)))
4935                subject)
4936               ((zerop gnus-tmp-level)
4937                (if (and (eq gnus-summary-make-false-root 'empty)
4938                         (memq number gnus-tmp-gathered)
4939                         gnus-tmp-prev-subject
4940                         (string= gnus-tmp-prev-subject simp-subject))
4941                    gnus-summary-same-subject
4942                  subject))
4943               (t gnus-summary-same-subject)))
4944             (if (and (eq gnus-summary-make-false-root 'adopt)
4945                      (= gnus-tmp-level 1)
4946                      (memq number gnus-tmp-gathered))
4947                 (setq gnus-tmp-opening-bracket ?\<
4948                       gnus-tmp-closing-bracket ?\>)
4949               (setq gnus-tmp-opening-bracket ?\[
4950                     gnus-tmp-closing-bracket ?\]))
4951             (setq
4952              gnus-tmp-indentation
4953              (aref gnus-thread-indent-array gnus-tmp-level)
4954              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4955              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4956                                 gnus-summary-default-score 0)
4957              gnus-tmp-score-char
4958              (if (or (null gnus-summary-default-score)
4959                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4960                          gnus-summary-zcore-fuzz))
4961                  ?                      ;Whitespace
4962                (if (< gnus-tmp-score gnus-summary-default-score)
4963                    gnus-score-below-mark gnus-score-over-mark))
4964              gnus-tmp-replied
4965              (cond ((memq number gnus-newsgroup-processable)
4966                     gnus-process-mark)
4967                    ((memq number gnus-newsgroup-cached)
4968                     gnus-cached-mark)
4969                    ((memq number gnus-newsgroup-replied)
4970                     gnus-replied-mark)
4971                    ((memq number gnus-newsgroup-forwarded)
4972                     gnus-forwarded-mark)
4973                    ((memq number gnus-newsgroup-saved)
4974                     gnus-saved-mark)
4975                    ((memq number gnus-newsgroup-recent)
4976                     gnus-recent-mark)
4977                    ((memq number gnus-newsgroup-unseen)
4978                     gnus-unseen-mark)
4979                    (t gnus-no-mark))
4980              gnus-tmp-downloaded
4981              (cond ((memq number gnus-newsgroup-undownloaded)
4982                     gnus-undownloaded-mark)
4983                    (gnus-newsgroup-agentized
4984                     gnus-downloaded-mark)
4985                    (t
4986                     gnus-no-mark))
4987              gnus-tmp-from (mail-header-from gnus-tmp-header)
4988              gnus-tmp-name
4989              (cond
4990               ((string-match "<[^>]+> *$" gnus-tmp-from)
4991                (setq beg-match (match-beginning 0))
4992                (or (and (string-match "^\".+\"" gnus-tmp-from)
4993                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4994                    (substring gnus-tmp-from 0 beg-match)))
4995               ((string-match "(.+)" gnus-tmp-from)
4996                (substring gnus-tmp-from
4997                           (1+ (match-beginning 0)) (1- (match-end 0))))
4998               (t gnus-tmp-from))
4999
5000              ;; Do the %B string
5001              gnus-tmp-thread-tree-header-string
5002              (cond
5003               ((not gnus-show-threads) "")
5004               ((zerop gnus-tmp-level)
5005                (cond ((cdar thread)
5006                       (or gnus-sum-thread-tree-root subject))
5007                      (gnus-tmp-new-adopts
5008                       (or gnus-sum-thread-tree-false-root subject))
5009                      (t
5010                       (or gnus-sum-thread-tree-single-indent subject))))
5011               (t
5012                (concat (apply 'concat
5013                               (mapcar (lambda (item)
5014                                         (if (= item 1)
5015                                             gnus-sum-thread-tree-vertical
5016                                           gnus-sum-thread-tree-indent))
5017                                       (cdr (reverse tree-stack))))
5018                        (if (nth 1 thread)
5019                            gnus-sum-thread-tree-leaf-with-other
5020                          gnus-sum-thread-tree-single-leaf)))))
5021             (when (string= gnus-tmp-name "")
5022               (setq gnus-tmp-name gnus-tmp-from))
5023             (unless (numberp gnus-tmp-lines)
5024               (setq gnus-tmp-lines -1))
5025             (if (= gnus-tmp-lines -1)
5026                 (setq gnus-tmp-lines "?")
5027               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5028               (gnus-put-text-property
5029              (point)
5030              (progn (eval gnus-summary-line-format-spec) (point))
5031                'gnus-number number)
5032             (when gnus-visual-p
5033               (forward-line -1)
5034               (gnus-run-hooks 'gnus-summary-update-hook)
5035               (forward-line 1))
5036
5037             (setq gnus-tmp-prev-subject simp-subject)))
5038
5039         (when (nth 1 thread)
5040           (push (list (max 0 gnus-tmp-level)
5041                       (copy-sequence tree-stack)
5042                       (nthcdr 1 thread))
5043                 stack))
5044         (push (if (nth 1 thread) 1 0) tree-stack)
5045         (incf gnus-tmp-level)
5046         (setq threads (if thread-end nil (cdar thread)))
5047         (if gnus-summary-display-while-building
5048             (if building-count
5049                 (progn
5050                   ;; use a set frequency
5051                   (setq building-line-count (1- building-line-count))
5052                   (when (= building-line-count 0)
5053                     (sit-for 0)
5054                     (setq building-line-count
5055                           gnus-summary-display-while-building)))
5056               ;; always
5057               (sit-for 0)))
5058         (unless threads
5059           (setq gnus-tmp-level 0)))))
5060   (gnus-message 7 "Generating summary...done"))
5061
5062 (defun gnus-summary-prepare-unthreaded (headers)
5063   "Generate an unthreaded summary buffer based on HEADERS."
5064   (let (header number mark)
5065
5066     (beginning-of-line)
5067
5068     (while headers
5069       ;; We may have to root out some bad articles...
5070       (when (memq (setq number (mail-header-number
5071                                 (setq header (pop headers))))
5072                   gnus-newsgroup-limit)
5073         ;; Mark article as read when it has a low score.
5074         (when (and gnus-summary-mark-below
5075                    (< (or (cdr (assq number gnus-newsgroup-scored))
5076                           gnus-summary-default-score 0)
5077                       gnus-summary-mark-below)
5078                    (not (gnus-summary-article-ancient-p number)))
5079           (setq gnus-newsgroup-unreads
5080                 (delq number gnus-newsgroup-unreads))
5081           (if gnus-newsgroup-auto-expire
5082               (push number gnus-newsgroup-expirable)
5083             (push (cons number gnus-low-score-mark)
5084                   gnus-newsgroup-reads)))
5085
5086         (setq mark (gnus-article-mark number))
5087         (push (gnus-data-make number mark (1+ (point)) header 0)
5088               gnus-newsgroup-data)
5089         (gnus-summary-insert-line
5090          header 0 number
5091          (memq number gnus-newsgroup-undownloaded)
5092          mark (memq number gnus-newsgroup-replied)
5093          (memq number gnus-newsgroup-expirable)
5094          (mail-header-subject header) nil
5095          (cdr (assq number gnus-newsgroup-scored))
5096          (memq number gnus-newsgroup-processable))))))
5097
5098 (defun gnus-summary-remove-list-identifiers ()
5099   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5100   (let ((regexp (if (consp gnus-list-identifiers)
5101                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5102                   gnus-list-identifiers))
5103         changed subject)
5104     (when regexp
5105       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5106       (dolist (header gnus-newsgroup-headers)
5107         (setq subject (mail-header-subject header)
5108               changed nil)
5109         (while (string-match regexp subject)
5110           (setq subject
5111                 (concat (substring subject 0 (match-beginning 1))
5112                         (substring subject (match-end 0)))
5113                 changed t))
5114         (when changed
5115           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5116             (setq subject
5117                   (concat (substring subject 0 (match-beginning 1))
5118                           (substring subject (match-end 1)))))
5119           (mail-header-set-subject header subject))))))
5120
5121 (defun gnus-fetch-headers (articles)
5122   "Fetch headers of ARTICLES."
5123   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5124     (gnus-message 5 "Fetching headers for %s..." name)
5125     (prog1
5126         (if (eq 'nov
5127                 (setq gnus-headers-retrieved-by
5128                       (gnus-retrieve-headers
5129                        articles gnus-newsgroup-name
5130                        ;; We might want to fetch old headers, but
5131                        ;; not if there is only 1 article.
5132                        (and (or (and
5133                                  (not (eq gnus-fetch-old-headers 'some))
5134                                  (not (numberp gnus-fetch-old-headers)))
5135                                 (> (length articles) 1))
5136                             gnus-fetch-old-headers))))
5137             (gnus-get-newsgroup-headers-xover
5138              articles nil nil gnus-newsgroup-name t)
5139           (gnus-get-newsgroup-headers))
5140       (gnus-message 5 "Fetching headers for %s...done" name))))
5141
5142 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5143   "Select newsgroup GROUP.
5144 If READ-ALL is non-nil, all articles in the group are selected.
5145 If SELECT-ARTICLES, only select those articles from GROUP."
5146   (let* ((entry (gnus-group-entry group))
5147          ;;!!! Dirty hack; should be removed.
5148          (gnus-summary-ignore-duplicates
5149           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5150               t
5151             gnus-summary-ignore-duplicates))
5152          (info (nth 2 entry))
5153          articles fetched-articles cached)
5154
5155     (unless (gnus-check-server
5156              (set (make-local-variable 'gnus-current-select-method)
5157                   (gnus-find-method-for-group group)))
5158       (error "Couldn't open server"))
5159
5160     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5161         (gnus-activate-group group)     ; Or we can activate it...
5162         (progn                          ; Or we bug out.
5163           (when (equal major-mode 'gnus-summary-mode)
5164             (gnus-kill-buffer (current-buffer)))
5165           (error "Couldn't activate group %s: %s"
5166                  group (gnus-status-message group))))
5167
5168     (unless (gnus-request-group group t)
5169       (when (equal major-mode 'gnus-summary-mode)
5170         (gnus-kill-buffer (current-buffer)))
5171       (error "Couldn't request group %s: %s"
5172              group (gnus-status-message group)))
5173
5174     (when gnus-agent
5175       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5176
5177       (setq gnus-summary-use-undownloaded-faces
5178             (gnus-agent-find-parameter
5179              group
5180              'agent-enable-undownloaded-faces)))
5181
5182     (setq gnus-newsgroup-name group
5183           gnus-newsgroup-unselected nil
5184           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5185
5186     (let ((display (gnus-group-find-parameter group 'display)))
5187       (setq gnus-newsgroup-display
5188             (cond
5189              ((not (zerop (or (car-safe read-all) 0)))
5190               ;; The user entered the group with C-u SPC/RET, let's show
5191               ;; all articles.
5192               'gnus-not-ignore)
5193              ((eq display 'all)
5194               'gnus-not-ignore)
5195              ((arrayp display)
5196               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5197              ((numberp display)
5198               ;; The following is probably the "correct" solution, but
5199               ;; it makes Gnus fetch all headers and then limit the
5200               ;; articles (which is slow), so instead we hack the
5201               ;; select-articles parameter instead. -- Simon Josefsson
5202               ;; <jas@kth.se>
5203               ;;
5204               ;; (gnus-byte-compile
5205               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5206               ;;                         display)))))
5207               (setq select-articles
5208                     (gnus-uncompress-range
5209                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5210                              (if (> tmp 0)
5211                                  tmp
5212                                1))
5213                            (cdr (gnus-active group)))))
5214               nil)
5215              (t
5216               nil))))
5217
5218     (gnus-summary-setup-default-charset)
5219
5220     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5221     (when (gnus-virtual-group-p group)
5222       (setq cached gnus-newsgroup-cached))
5223
5224     (setq gnus-newsgroup-unreads
5225           (gnus-sorted-ndifference
5226            (gnus-sorted-ndifference gnus-newsgroup-unreads
5227                                     gnus-newsgroup-marked)
5228            gnus-newsgroup-dormant))
5229
5230     (setq gnus-newsgroup-processable nil)
5231
5232     (gnus-update-read-articles group gnus-newsgroup-unreads)
5233
5234     ;; Adjust and set lists of article marks.
5235     (when info
5236       (gnus-adjust-marked-articles info))
5237     (if (setq articles select-articles)
5238         (setq gnus-newsgroup-unselected
5239               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5240       (setq articles (gnus-articles-to-read group read-all)))
5241
5242     (cond
5243      ((null articles)
5244       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5245       'quit)
5246      ((eq articles 0) nil)
5247      (t
5248       ;; Init the dependencies hash table.
5249       (setq gnus-newsgroup-dependencies
5250             (gnus-make-hashtable (length articles)))
5251       (gnus-set-global-variables)
5252       ;; Retrieve the headers and read them in.
5253
5254       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5255
5256       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5257       (when cached
5258         (setq gnus-newsgroup-cached cached))
5259
5260       ;; Suppress duplicates?
5261       (when gnus-suppress-duplicates
5262         (gnus-dup-suppress-articles))
5263
5264       ;; Set the initial limit.
5265       (setq gnus-newsgroup-limit (copy-sequence articles))
5266       ;; Remove canceled articles from the list of unread articles.
5267       (setq fetched-articles
5268             (mapcar (lambda (headers) (mail-header-number headers))
5269                     gnus-newsgroup-headers))
5270       (setq gnus-newsgroup-articles fetched-articles)
5271       (setq gnus-newsgroup-unreads
5272             (gnus-sorted-nintersection
5273              gnus-newsgroup-unreads fetched-articles))
5274       (gnus-compute-unseen-list)
5275
5276       ;; Removed marked articles that do not exist.
5277       (gnus-update-missing-marks
5278        (gnus-sorted-difference articles fetched-articles))
5279       ;; We might want to build some more threads first.
5280       (when (and gnus-fetch-old-headers
5281                  (eq gnus-headers-retrieved-by 'nov))
5282         (if (eq gnus-fetch-old-headers 'invisible)
5283             (gnus-build-all-threads)
5284           (gnus-build-old-threads)))
5285       ;; Let the Gnus agent mark articles as read.
5286       (when gnus-agent
5287         (gnus-agent-get-undownloaded-list))
5288       ;; Remove list identifiers from subject
5289       (when gnus-list-identifiers
5290         (gnus-summary-remove-list-identifiers))
5291       ;; Check whether auto-expire is to be done in this group.
5292       (setq gnus-newsgroup-auto-expire
5293             (gnus-group-auto-expirable-p group))
5294       ;; Set up the article buffer now, if necessary.
5295       (unless gnus-single-article-buffer
5296         (gnus-article-setup-buffer))
5297       ;; First and last article in this newsgroup.
5298       (when gnus-newsgroup-headers
5299         (setq gnus-newsgroup-begin
5300               (mail-header-number (car gnus-newsgroup-headers))
5301               gnus-newsgroup-end
5302               (mail-header-number
5303                (gnus-last-element gnus-newsgroup-headers))))
5304       ;; GROUP is successfully selected.
5305       (or gnus-newsgroup-headers t)))))
5306
5307 (defun gnus-compute-unseen-list ()
5308   ;; The `seen' marks are treated specially.
5309   (if (not gnus-newsgroup-seen)
5310       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5311     (setq gnus-newsgroup-unseen
5312           (gnus-inverse-list-range-intersection
5313            gnus-newsgroup-articles gnus-newsgroup-seen))))
5314
5315 (defun gnus-summary-display-make-predicate (display)
5316   (require 'gnus-agent)
5317   (when (= (length display) 1)
5318     (setq display (car display)))
5319   (unless gnus-summary-display-cache
5320     (dolist (elem (append '((unread . unread)
5321                             (read . read)
5322                             (unseen . unseen))
5323                           gnus-article-mark-lists))
5324       (push (cons (cdr elem)
5325                   (gnus-byte-compile
5326                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5327             gnus-summary-display-cache)))
5328   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5329         (gnus-category-predicate-cache gnus-summary-display-cache))
5330     (gnus-get-predicate display)))
5331
5332 ;; Uses the dynamically bound `number' variable.
5333 (eval-when-compile
5334   (defvar number))
5335 (defun gnus-article-marked-p (type &optional article)
5336   (let ((article (or article number)))
5337     (cond
5338      ((eq type 'tick)
5339       (memq article gnus-newsgroup-marked))
5340      ((eq type 'spam)
5341       (memq article gnus-newsgroup-spam-marked))
5342      ((eq type 'unsend)
5343       (memq article gnus-newsgroup-unsendable))
5344      ((eq type 'undownload)
5345       (memq article gnus-newsgroup-undownloaded))
5346      ((eq type 'download)
5347       (memq article gnus-newsgroup-downloadable))
5348      ((eq type 'unread)
5349       (memq article gnus-newsgroup-unreads))
5350      ((eq type 'read)
5351       (memq article gnus-newsgroup-reads))
5352      ((eq type 'dormant)
5353       (memq article gnus-newsgroup-dormant) )
5354      ((eq type 'expire)
5355       (memq article gnus-newsgroup-expirable))
5356      ((eq type 'reply)
5357       (memq article gnus-newsgroup-replied))
5358      ((eq type 'killed)
5359       (memq article gnus-newsgroup-killed))
5360      ((eq type 'bookmark)
5361       (assq article gnus-newsgroup-bookmarks))
5362      ((eq type 'score)
5363       (assq article gnus-newsgroup-scored))
5364      ((eq type 'save)
5365       (memq article gnus-newsgroup-saved))
5366      ((eq type 'cache)
5367       (memq article gnus-newsgroup-cached))
5368      ((eq type 'forward)
5369       (memq article gnus-newsgroup-forwarded))
5370      ((eq type 'seen)
5371       (not (memq article gnus-newsgroup-unseen)))
5372      ((eq type 'recent)
5373       (memq article gnus-newsgroup-recent))
5374      (t t))))
5375
5376 (defun gnus-articles-to-read (group &optional read-all)
5377   "Find out what articles the user wants to read."
5378   (let* ((articles
5379           ;; Select all articles if `read-all' is non-nil, or if there
5380           ;; are no unread articles.
5381           (if (or read-all
5382                   (and (zerop (length gnus-newsgroup-marked))
5383                        (zerop (length gnus-newsgroup-unreads)))
5384                   ;; Fetch all if the predicate is non-nil.
5385                   gnus-newsgroup-display)
5386               ;; We want to select the headers for all the articles in
5387               ;; the group, so we select either all the active
5388               ;; articles in the group, or (if that's nil), the
5389               ;; articles in the cache.
5390               (or
5391                (gnus-uncompress-range (gnus-active group))
5392                (gnus-cache-articles-in-group group))
5393             ;; Select only the "normal" subset of articles.
5394             (gnus-sorted-nunion
5395              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5396              gnus-newsgroup-unreads)))
5397          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5398          (scored (length scored-list))
5399          (number (length articles))
5400          (marked (+ (length gnus-newsgroup-marked)
5401                     (length gnus-newsgroup-dormant)))
5402          (select
5403           (cond
5404            ((numberp read-all)
5405             read-all)
5406            ((numberp gnus-newsgroup-display)
5407             gnus-newsgroup-display)
5408            (t
5409             (condition-case ()
5410                 (cond
5411                  ((and (or (<= scored marked) (= scored number))
5412                        (numberp gnus-large-newsgroup)
5413                        (> number gnus-large-newsgroup))
5414                   (let* ((cursor-in-echo-area nil)
5415                          (initial (gnus-parameter-large-newsgroup-initial
5416                                    gnus-newsgroup-name))
5417                          (input
5418                           (read-string
5419                            (format
5420                             "How many articles from %s (%s %d): "
5421                             (gnus-limit-string
5422                              (gnus-group-decoded-name gnus-newsgroup-name)
5423                              35)
5424                             (if initial "max" "default")
5425                             number)
5426                            (if initial
5427                                (cons (number-to-string initial)
5428                                      0)))))
5429                     (if (string-match "^[ \t]*$" input) number input)))
5430                  ((and (> scored marked) (< scored number)
5431                        (> (- scored number) 20))
5432                   (let ((input
5433                          (read-string
5434                           (format "%s %s (%d scored, %d total): "
5435                                   "How many articles from"
5436                                   (gnus-group-decoded-name group)
5437                                   scored number))))
5438                     (if (string-match "^[ \t]*$" input)
5439                         number input)))
5440                  (t number))
5441               (quit
5442                (message "Quit getting the articles to read")
5443                nil))))))
5444     (setq select (if (stringp select) (string-to-number select) select))
5445     (if (or (null select) (zerop select))
5446         select
5447       (if (and (not (zerop scored)) (<= (abs select) scored))
5448           (progn
5449             (setq articles (sort scored-list '<))
5450             (setq number (length articles)))
5451         (setq articles (copy-sequence articles)))
5452
5453       (when (< (abs select) number)
5454         (if (< select 0)
5455             ;; Select the N oldest articles.
5456             (setcdr (nthcdr (1- (abs select)) articles) nil)
5457           ;; Select the N most recent articles.
5458           (setq articles (nthcdr (- number select) articles))))
5459       (setq gnus-newsgroup-unselected
5460             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5461       (when gnus-alter-articles-to-read-function
5462         (setq articles
5463               (sort
5464                (funcall gnus-alter-articles-to-read-function
5465                         gnus-newsgroup-name articles)
5466                '<)))
5467       articles)))
5468
5469 (defun gnus-killed-articles (killed articles)
5470   (let (out)
5471     (while articles
5472       (when (inline (gnus-member-of-range (car articles) killed))
5473         (push (car articles) out))
5474       (setq articles (cdr articles)))
5475     out))
5476
5477 (defun gnus-uncompress-marks (marks)
5478   "Uncompress the mark ranges in MARKS."
5479   (let ((uncompressed '(score bookmark))
5480         out)
5481     (while marks
5482       (if (memq (caar marks) uncompressed)
5483           (push (car marks) out)
5484         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5485       (setq marks (cdr marks)))
5486     out))
5487
5488 (defun gnus-article-mark-to-type (mark)
5489   "Return the type of MARK."
5490   (or (cadr (assq mark gnus-article-special-mark-lists))
5491       'list))
5492
5493 (defun gnus-article-unpropagatable-p (mark)
5494   "Return whether MARK should be propagated to back end."
5495   (memq mark gnus-article-unpropagated-mark-lists))
5496
5497 (defun gnus-adjust-marked-articles (info)
5498   "Set all article lists and remove all marks that are no longer valid."
5499   (let* ((marked-lists (gnus-info-marks info))
5500          (active (gnus-active (gnus-info-group info)))
5501          (min (car active))
5502          (max (cdr active))
5503          (types gnus-article-mark-lists)
5504          marks var articles article mark mark-type
5505          bgn end)
5506
5507     (dolist (marks marked-lists)
5508       (setq mark (car marks)
5509             mark-type (gnus-article-mark-to-type mark)
5510             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5511
5512       ;; We set the variable according to the type of the marks list,
5513       ;; and then adjust the marks to a subset of the active articles.
5514       (cond
5515        ;; Adjust "simple" lists - compressed yet unsorted
5516        ((eq mark-type 'list)
5517         ;; Simultaneously uncompress and clip to active range
5518         ;; See gnus-uncompress-range for a description of possible marks
5519         (let (l lh)
5520           (if (not (cadr marks))
5521               (set var nil)
5522             (setq articles (if (numberp (cddr marks))
5523                                (list (cdr marks))
5524                              (cdr marks))
5525                   lh (cons nil nil)
5526                   l lh)
5527
5528             (while (setq article (pop articles))
5529               (cond ((consp article)
5530                      (setq bgn (max (car article) min)
5531                            end (min (cdr article) max))
5532                      (while (<= bgn end)
5533                        (setq l (setcdr l (cons bgn nil))
5534                              bgn (1+ bgn))))
5535                     ((and (<= min article)
5536                           (>= max article))
5537                      (setq l (setcdr l (cons article nil))))))
5538             (set var (cdr lh)))))
5539        ;; Adjust assocs.
5540        ((eq mark-type 'tuple)
5541         (set var (setq articles (cdr marks)))
5542         (when (not (listp (cdr (symbol-value var))))
5543           (set var (list (symbol-value var))))
5544         (when (not (listp (cdr articles)))
5545           (setq articles (list articles)))
5546         (while articles
5547           (when (or (not (consp (setq article (pop articles))))
5548                     (< (car article) min)
5549                     (> (car article) max))
5550             (set var (delq article (symbol-value var))))))
5551        ;; Adjust ranges (sloppily).
5552        ((eq mark-type 'range)
5553         (cond
5554          ((eq mark 'seen)
5555           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5556           ;; It should be (seen (NUM1 . NUM2)).
5557           (when (numberp (cddr marks))
5558             (setcdr marks (list (cdr marks))))
5559           (setq articles (cdr marks))
5560           (while (and articles
5561                       (or (and (consp (car articles))
5562                                (> min (cdar articles)))
5563                           (and (numberp (car articles))
5564                                (> min (car articles)))))
5565             (pop articles))
5566           (set var articles))))))))
5567
5568 (defun gnus-update-missing-marks (missing)
5569   "Go through the list of MISSING articles and remove them from the mark lists."
5570   (when missing
5571     (let (var m)
5572       ;; Go through all types.
5573       (dolist (elem gnus-article-mark-lists)
5574         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5575           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5576           (when (symbol-value var)
5577             ;; This list has articles.  So we delete all missing
5578             ;; articles from it.
5579             (setq m missing)
5580             (while m
5581               (set var (delq (pop m) (symbol-value var))))))))))
5582
5583 (defun gnus-update-marks ()
5584   "Enter the various lists of marked articles into the newsgroup info list."
5585   (let ((types gnus-article-mark-lists)
5586         (info (gnus-get-info gnus-newsgroup-name))
5587         type list newmarked symbol delta-marks)
5588     (when info
5589       ;; Add all marks lists to the list of marks lists.
5590       (while (setq type (pop types))
5591         (setq list (symbol-value
5592                     (setq symbol
5593                           (intern (format "gnus-newsgroup-%s" (car type))))))
5594
5595         (when list
5596           ;; Get rid of the entries of the articles that have the
5597           ;; default score.
5598           (when (and (eq (cdr type) 'score)
5599                      gnus-save-score
5600                      list)
5601             (let* ((arts list)
5602                    (prev (cons nil list))
5603                    (all prev))
5604               (while arts
5605                 (if (or (not (consp (car arts)))
5606                         (= (cdar arts) gnus-summary-default-score))
5607                     (setcdr prev (cdr arts))
5608                   (setq prev arts))
5609                 (setq arts (cdr arts)))
5610               (setq list (cdr all)))))
5611
5612         (when (eq (cdr type) 'seen)
5613           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5614
5615         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5616           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5617
5618         (when (and (gnus-check-backend-function
5619                     'request-set-mark gnus-newsgroup-name)
5620                    (not (gnus-article-unpropagatable-p (cdr type))))
5621           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5622                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5623                  (add (gnus-remove-from-range
5624                        (gnus-copy-sequence list) old)))
5625             (when add
5626               (push (list add 'add (list (cdr type))) delta-marks))
5627             (when del
5628               (push (list del 'del (list (cdr type))) delta-marks))))
5629
5630         (when list
5631           (push (cons (cdr type) list) newmarked)))
5632
5633       (when delta-marks
5634         (unless (gnus-check-group gnus-newsgroup-name)
5635           (error "Can't open server for %s" gnus-newsgroup-name))
5636         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5637
5638       ;; Enter these new marks into the info of the group.
5639       (if (nthcdr 3 info)
5640           (setcar (nthcdr 3 info) newmarked)
5641         ;; Add the marks lists to the end of the info.
5642         (when newmarked
5643           (setcdr (nthcdr 2 info) (list newmarked))))
5644
5645       ;; Cut off the end of the info if there's nothing else there.
5646       (let ((i 5))
5647         (while (and (> i 2)
5648                     (not (nth i info)))
5649           (when (nthcdr (decf i) info)
5650             (setcdr (nthcdr i info) nil)))))))
5651
5652 (defun gnus-set-mode-line (where)
5653   "Set the mode line of the article or summary buffers.
5654 If WHERE is `summary', the summary mode line format will be used."
5655   ;; Is this mode line one we keep updated?
5656   (when (and (memq where gnus-updated-mode-lines)
5657              (symbol-value
5658               (intern (format "gnus-%s-mode-line-format-spec" where))))
5659     (let (mode-string)
5660       (save-excursion
5661         ;; We evaluate this in the summary buffer since these
5662         ;; variables are buffer-local to that buffer.
5663         (set-buffer gnus-summary-buffer)
5664        ;; We bind all these variables that are used in the `eval' form
5665         ;; below.
5666         (let* ((mformat (symbol-value
5667                          (intern
5668                           (format "gnus-%s-mode-line-format-spec" where))))
5669                (gnus-tmp-group-name (gnus-group-decoded-name
5670                                      gnus-newsgroup-name))
5671                (gnus-tmp-article-number (or gnus-current-article 0))
5672                (gnus-tmp-unread gnus-newsgroup-unreads)
5673                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5674                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5675                (gnus-tmp-unread-and-unselected
5676                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5677                             (zerop gnus-tmp-unselected))
5678                        "")
5679                       ((zerop gnus-tmp-unselected)
5680                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5681                       (t (format "{%d(+%d) more}"
5682                                  gnus-tmp-unread-and-unticked
5683                                  gnus-tmp-unselected))))
5684                (gnus-tmp-subject
5685                 (if (and gnus-current-headers
5686                          (vectorp gnus-current-headers))
5687                     (gnus-mode-string-quote
5688                      (mail-header-subject gnus-current-headers))
5689                   ""))
5690                bufname-length max-len
5691                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5692           (setq mode-string (eval mformat))
5693           (setq bufname-length (if (string-match "%b" mode-string)
5694                                    (- (length
5695                                        (buffer-name
5696                                         (if (eq where 'summary)
5697                                             nil
5698                                           (get-buffer gnus-article-buffer))))
5699                                       2)
5700                                  0))
5701           (setq max-len (max 4 (if gnus-mode-non-string-length
5702                                    (- (window-width)
5703                                       gnus-mode-non-string-length
5704                                       bufname-length)
5705                                  (length mode-string))))
5706           ;; We might have to chop a bit of the string off...
5707           (when (> (length mode-string) max-len)
5708             (setq mode-string
5709                   (concat (truncate-string-to-width mode-string (- max-len 3))
5710                           "...")))
5711           ;; Pad the mode string a bit.
5712           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5713       ;; Update the mode line.
5714       (setq mode-line-buffer-identification
5715             (gnus-mode-line-buffer-identification (list mode-string)))
5716       (set-buffer-modified-p t))))
5717
5718 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5719   "Go through the HEADERS list and add all Xrefs to a hash table.
5720 The resulting hash table is returned, or nil if no Xrefs were found."
5721   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5722          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5723          (xref-hashtb (gnus-make-hashtable))
5724          start group entry number xrefs header)
5725     (while headers
5726       (setq header (pop headers))
5727       (when (and (setq xrefs (mail-header-xref header))
5728                  (not (memq (setq number (mail-header-number header))
5729                             unreads)))
5730         (setq start 0)
5731         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5732           (setq start (match-end 0))
5733           (setq group (if prefix
5734                           (concat prefix (substring xrefs (match-beginning 1)
5735                                                     (match-end 1)))
5736                         (substring xrefs (match-beginning 1) (match-end 1))))
5737           (setq number
5738                 (string-to-number (substring xrefs (match-beginning 2)
5739                                           (match-end 2))))
5740           (if (setq entry (gnus-gethash group xref-hashtb))
5741               (setcdr entry (cons number (cdr entry)))
5742             (gnus-sethash group (cons number nil) xref-hashtb)))))
5743     (and start xref-hashtb)))
5744
5745 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5746   "Look through all the headers and mark the Xrefs as read."
5747   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5748         name info xref-hashtb idlist method nth4)
5749     (save-excursion
5750       (set-buffer gnus-group-buffer)
5751       (when (setq xref-hashtb
5752                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5753         (mapatoms
5754          (lambda (group)
5755            (unless (string= from-newsgroup (setq name (symbol-name group)))
5756              (setq idlist (symbol-value group))
5757              ;; Dead groups are not updated.
5758              (and (prog1
5759                       (setq info (gnus-get-info name))
5760                     (when (stringp (setq nth4 (gnus-info-method info)))
5761                       (setq nth4 (gnus-server-to-method nth4))))
5762                   ;; Only do the xrefs if the group has the same
5763                   ;; select method as the group we have just read.
5764                   (or (gnus-methods-equal-p
5765                        nth4 (gnus-find-method-for-group from-newsgroup))
5766                       virtual
5767                       (equal nth4 (setq method (gnus-find-method-for-group
5768                                                 from-newsgroup)))
5769                       (and (equal (car nth4) (car method))
5770                            (equal (nth 1 nth4) (nth 1 method))))
5771                   gnus-use-cross-reference
5772                   (or (not (eq gnus-use-cross-reference t))
5773                       virtual
5774                       ;; Only do cross-references on subscribed
5775                       ;; groups, if that is what is wanted.
5776                       (<= (gnus-info-level info) gnus-level-subscribed))
5777                   (gnus-group-make-articles-read name idlist))))
5778          xref-hashtb)))))
5779
5780 (defun gnus-compute-read-articles (group articles)
5781   (let* ((entry (gnus-group-entry group))
5782          (info (nth 2 entry))
5783          (active (gnus-active group))
5784          ninfo)
5785     (when entry
5786       ;; First peel off all invalid article numbers.
5787       (when active
5788         (let ((ids articles)
5789               id first)
5790           (while (setq id (pop ids))
5791             (when (and first (> id (cdr active)))
5792               ;; We'll end up in this situation in one particular
5793               ;; obscure situation.  If you re-scan a group and get
5794               ;; a new article that is cross-posted to a different
5795               ;; group that has not been re-scanned, you might get
5796               ;; crossposted article that has a higher number than
5797               ;; Gnus believes possible.  So we re-activate this
5798               ;; group as well.  This might mean doing the
5799               ;; crossposting thingy will *increase* the number
5800               ;; of articles in some groups.  Tsk, tsk.
5801               (setq active (or (gnus-activate-group group) active)))
5802             (when (or (> id (cdr active))
5803                       (< id (car active)))
5804               (setq articles (delq id articles))))))
5805       ;; If the read list is nil, we init it.
5806       (if (and active
5807                (null (gnus-info-read info))
5808                (> (car active) 1))
5809           (setq ninfo (cons 1 (1- (car active))))
5810         (setq ninfo (gnus-info-read info)))
5811       ;; Then we add the read articles to the range.
5812       (gnus-add-to-range
5813        ninfo (setq articles (sort articles '<))))))
5814
5815 (defun gnus-group-make-articles-read (group articles)
5816   "Update the info of GROUP to say that ARTICLES are read."
5817   (let* ((num 0)
5818          (entry (gnus-group-entry group))
5819          (info (nth 2 entry))
5820          (active (gnus-active group))
5821          range)
5822     (when entry
5823       (setq range (gnus-compute-read-articles group articles))
5824       (with-current-buffer gnus-group-buffer
5825         (gnus-undo-register
5826           `(progn
5827              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5828              (gnus-info-set-read ',info ',(gnus-info-read info))
5829              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5830              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5831              (gnus-group-update-group ,group t))))
5832       ;; Add the read articles to the range.
5833       (gnus-info-set-read info range)
5834       (gnus-request-set-mark group (list (list range 'add '(read))))
5835       ;; Then we have to re-compute how many unread
5836       ;; articles there are in this group.
5837       (when active
5838         (cond
5839          ((not range)
5840           (setq num (- (1+ (cdr active)) (car active))))
5841          ((not (listp (cdr range)))
5842           (setq num (- (cdr active) (- (1+ (cdr range))
5843                                        (car range)))))
5844          (t
5845           (while range
5846             (if (numberp (car range))
5847                 (setq num (1+ num))
5848               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5849             (setq range (cdr range)))
5850           (setq num (- (cdr active) num))))
5851         ;; Update the number of unread articles.
5852         (setcar entry num)
5853         ;; Update the group buffer.
5854         (unless (gnus-ephemeral-group-p group)
5855           (gnus-group-update-group group t))))))
5856
5857 (defvar gnus-newsgroup-none-id 0)
5858
5859 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5860   (let ((cur nntp-server-buffer)
5861         (dependencies
5862          (or dependencies
5863              (with-current-buffer gnus-summary-buffer
5864                gnus-newsgroup-dependencies)))
5865         headers id end ref number
5866         (mail-parse-charset gnus-newsgroup-charset)
5867         (mail-parse-ignored-charsets
5868          (save-excursion (condition-case nil
5869                              (set-buffer gnus-summary-buffer)
5870                            (error))
5871                          gnus-newsgroup-ignored-charsets)))
5872     (save-excursion
5873       (set-buffer nntp-server-buffer)
5874       ;; Translate all TAB characters into SPACE characters.
5875       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5876       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5877       (ietf-drums-unfold-fws)
5878       (gnus-run-hooks 'gnus-parse-headers-hook)
5879       (let ((case-fold-search t)
5880             in-reply-to header p lines chars)
5881         (goto-char (point-min))
5882         ;; Search to the beginning of the next header.  Error messages
5883         ;; do not begin with 2 or 3.
5884         (while (re-search-forward "^[23][0-9]+ " nil t)
5885           (setq id nil
5886                 ref nil)
5887           ;; This implementation of this function, with nine
5888           ;; search-forwards instead of the one re-search-forward and
5889           ;; a case (which basically was the old function) is actually
5890           ;; about twice as fast, even though it looks messier.  You
5891           ;; can't have everything, I guess.  Speed and elegance
5892           ;; doesn't always go hand in hand.
5893           (setq
5894            header
5895            (vector
5896             ;; Number.
5897             (prog1
5898                 (setq number (read cur))
5899               (end-of-line)
5900               (setq p (point))
5901               (narrow-to-region (point)
5902                                 (or (and (search-forward "\n.\n" nil t)
5903                                          (- (point) 2))
5904                                     (point))))
5905             ;; Subject.
5906             (progn
5907               (goto-char p)
5908               (if (search-forward "\nsubject:" nil t)
5909                   (funcall gnus-decode-encoded-word-function
5910                            (nnheader-header-value))
5911                 "(none)"))
5912             ;; From.
5913             (progn
5914               (goto-char p)
5915               (if (search-forward "\nfrom:" nil t)
5916                   (funcall gnus-decode-encoded-word-function
5917                            (nnheader-header-value))
5918                 "(nobody)"))
5919             ;; Date.
5920             (progn
5921               (goto-char p)
5922               (if (search-forward "\ndate:" nil t)
5923                   (nnheader-header-value) ""))
5924             ;; Message-ID.
5925             (progn
5926               (goto-char p)
5927               (setq id (if (re-search-forward
5928                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5929                            ;; We do it this way to make sure the Message-ID
5930                            ;; is (somewhat) syntactically valid.
5931                            (buffer-substring (match-beginning 1)
5932                                              (match-end 1))
5933                          ;; If there was no message-id, we just fake one
5934                          ;; to make subsequent routines simpler.
5935                          (nnheader-generate-fake-message-id number))))
5936             ;; References.
5937             (progn
5938               (goto-char p)
5939               (if (search-forward "\nreferences:" nil t)
5940                   (progn
5941                     (setq end (point))
5942                     (prog1
5943                         (nnheader-header-value)
5944                       (setq ref
5945                             (buffer-substring
5946                              (progn
5947                                (end-of-line)
5948                                (search-backward ">" end t)
5949                                (1+ (point)))
5950                              (progn
5951                                (search-backward "<" end t)
5952                                (point))))))
5953                 ;; Get the references from the in-reply-to header if there
5954                 ;; were no references and the in-reply-to header looks
5955                 ;; promising.
5956                 (if (and (search-forward "\nin-reply-to:" nil t)
5957                          (setq in-reply-to (nnheader-header-value))
5958                          (string-match "<[^>]+>" in-reply-to))
5959                     (let (ref2)
5960                       (setq ref (substring in-reply-to (match-beginning 0)
5961                                            (match-end 0)))
5962                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5963                         (setq ref2 (substring in-reply-to (match-beginning 0)
5964                                               (match-end 0)))
5965                         (when (> (length ref2) (length ref))
5966                           (setq ref ref2)))
5967                       ref)
5968                   (setq ref nil))))
5969             ;; Chars.
5970             (progn
5971               (goto-char p)
5972               (if (search-forward "\nchars: " nil t)
5973                   (if (numberp (setq chars (ignore-errors (read cur))))
5974                       chars -1)
5975                 -1))
5976             ;; Lines.
5977             (progn
5978               (goto-char p)
5979               (if (search-forward "\nlines: " nil t)
5980                   (if (numberp (setq lines (ignore-errors (read cur))))
5981                       lines -1)
5982                 -1))
5983             ;; Xref.
5984             (progn
5985               (goto-char p)
5986               (and (search-forward "\nxref:" nil t)
5987                    (nnheader-header-value)))
5988             ;; Extra.
5989             (when gnus-extra-headers
5990               (let ((extra gnus-extra-headers)
5991                     out)
5992                 (while extra
5993                   (goto-char p)
5994                   (when (search-forward
5995                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5996                     (push (cons (car extra) (nnheader-header-value))
5997                           out))
5998                   (pop extra))
5999                 out))))
6000           (when (equal id ref)
6001             (setq ref nil))
6002
6003           (when gnus-alter-header-function
6004             (funcall gnus-alter-header-function header)
6005             (setq id (mail-header-id header)
6006                   ref (gnus-parent-id (mail-header-references header))))
6007
6008           (when (setq header
6009                       (gnus-dependencies-add-header
6010                        header dependencies force-new))
6011             (push header headers))
6012           (goto-char (point-max))
6013           (widen))
6014         (nreverse headers)))))
6015
6016 ;; Goes through the xover lines and returns a list of vectors
6017 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6018                                                   force-new dependencies
6019                                                   group also-fetch-heads)
6020   "Parse the news overview data in the server buffer.
6021 Return a list of headers that match SEQUENCE (see
6022 `nntp-retrieve-headers')."
6023   ;; Get the Xref when the users reads the articles since most/some
6024   ;; NNTP servers do not include Xrefs when using XOVER.
6025   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6026   (let ((mail-parse-charset gnus-newsgroup-charset)
6027         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6028         (cur nntp-server-buffer)
6029         (dependencies (or dependencies gnus-newsgroup-dependencies))
6030         (allp (cond
6031                ((eq gnus-read-all-available-headers t)
6032                 t)
6033                ((stringp gnus-read-all-available-headers)
6034                 (string-match gnus-read-all-available-headers group))
6035                (t
6036                 nil)))
6037         number headers header)
6038     (save-excursion
6039       (set-buffer nntp-server-buffer)
6040       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6041       ;; Allow the user to mangle the headers before parsing them.
6042       (gnus-run-hooks 'gnus-parse-headers-hook)
6043       (goto-char (point-min))
6044       (gnus-parse-without-error
6045         (while (and (or sequence allp)
6046                     (not (eobp)))
6047           (setq number (read cur))
6048           (when (not allp)
6049             (while (and sequence
6050                         (< (car sequence) number))
6051               (setq sequence (cdr sequence))))
6052           (when (and (or allp
6053                          (and sequence
6054                               (eq number (car sequence))))
6055                      (progn
6056                        (setq sequence (cdr sequence))
6057                        (setq header (inline
6058                                       (gnus-nov-parse-line
6059                                        number dependencies force-new)))))
6060             (push header headers))
6061           (forward-line 1)))
6062       ;; A common bug in inn is that if you have posted an article and
6063       ;; then retrieves the active file, it will answer correctly --
6064       ;; the new article is included.  However, a NOV entry for the
6065       ;; article may not have been generated yet, so this may fail.
6066       ;; We work around this problem by retrieving the last few
6067       ;; headers using HEAD.
6068       (if (or (not also-fetch-heads)
6069               (not sequence))
6070           ;; We (probably) got all the headers.
6071           (nreverse headers)
6072         (let ((gnus-nov-is-evil t))
6073           (nconc
6074            (nreverse headers)
6075            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6076              (gnus-get-newsgroup-headers))))))))
6077
6078 (defun gnus-article-get-xrefs ()
6079   "Fill in the Xref value in `gnus-current-headers', if necessary.
6080 This is meant to be called in `gnus-article-internal-prepare-hook'."
6081   (let ((headers (with-current-buffer gnus-summary-buffer
6082                    gnus-current-headers)))
6083     (or (not gnus-use-cross-reference)
6084         (not headers)
6085         (and (mail-header-xref headers)
6086              (not (string= (mail-header-xref headers) "")))
6087         (let ((case-fold-search t)
6088               xref)
6089           (save-restriction
6090             (nnheader-narrow-to-headers)
6091             (goto-char (point-min))
6092             (when (or (and (not (eobp))
6093                            (eq (downcase (char-after)) ?x)
6094                            (looking-at "Xref:"))
6095                       (search-forward "\nXref:" nil t))
6096               (goto-char (1+ (match-end 0)))
6097               (setq xref (buffer-substring (point) (point-at-eol)))
6098               (mail-header-set-xref headers xref)))))))
6099
6100 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6101   "Find article ID and insert the summary line for that article.
6102 OLD-HEADER can either be a header or a line number to insert
6103 the subject line on."
6104   (let* ((line (and (numberp old-header) old-header))
6105          (old-header (and (vectorp old-header) old-header))
6106          (header (cond ((and old-header use-old-header)
6107                         old-header)
6108                        ((and (numberp id)
6109                              (gnus-number-to-header id))
6110                         (gnus-number-to-header id))
6111                        (t
6112                         (gnus-read-header id))))
6113          (number (and (numberp id) id))
6114          d)
6115     (when header
6116       ;; Rebuild the thread that this article is part of and go to the
6117       ;; article we have fetched.
6118       (when (and (not gnus-show-threads)
6119                  old-header)
6120         (when (and number
6121                    (setq d (gnus-data-find (mail-header-number old-header))))
6122           (goto-char (gnus-data-pos d))
6123           (gnus-data-remove
6124            number
6125            (- (point-at-bol)
6126               (prog1
6127                   (1+ (point-at-eol))
6128                 (gnus-delete-line))))))
6129       ;; Remove list identifiers from subject.
6130       (when gnus-list-identifiers
6131         (let ((gnus-newsgroup-headers (list header)))
6132           (gnus-summary-remove-list-identifiers)))
6133       (when old-header
6134         (mail-header-set-number header (mail-header-number old-header)))
6135       (setq gnus-newsgroup-sparse
6136             (delq (setq number (mail-header-number header))
6137                   gnus-newsgroup-sparse))
6138       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6139       (push number gnus-newsgroup-limit)
6140       (gnus-rebuild-thread (mail-header-id header) line)
6141       (gnus-summary-goto-subject number nil t))
6142     (when (and (numberp number)
6143                (> number 0))
6144       ;; We have to update the boundaries even if we can't fetch the
6145       ;; article if ID is a number -- so that the next `P' or `N'
6146       ;; command will fetch the previous (or next) article even
6147       ;; if the one we tried to fetch this time has been canceled.
6148       (when (> number gnus-newsgroup-end)
6149         (setq gnus-newsgroup-end number))
6150       (when (< number gnus-newsgroup-begin)
6151         (setq gnus-newsgroup-begin number))
6152       (setq gnus-newsgroup-unselected
6153             (delq number gnus-newsgroup-unselected)))
6154     ;; Report back a success?
6155     (and header (mail-header-number header))))
6156
6157 ;;; Process/prefix in the summary buffer
6158
6159 (defun gnus-summary-work-articles (n)
6160   "Return a list of articles to be worked upon.
6161 The prefix argument, the list of process marked articles, and the
6162 current article will be taken into consideration."
6163   (save-excursion
6164     (set-buffer gnus-summary-buffer)
6165     (cond
6166      (n
6167       ;; A numerical prefix has been given.
6168       (setq n (prefix-numeric-value n))
6169       (let ((backward (< n 0))
6170             (n (abs (prefix-numeric-value n)))
6171             articles article)
6172         (save-excursion
6173           (while
6174               (and (> n 0)
6175                    (push (setq article (gnus-summary-article-number))
6176                          articles)
6177                    (if backward
6178                        (gnus-summary-find-prev nil article)
6179                      (gnus-summary-find-next nil article)))
6180             (decf n)))
6181         (nreverse articles)))
6182      ((and (gnus-region-active-p) (mark))
6183       (message "region active")
6184       ;; Work on the region between point and mark.
6185       (let ((max (max (point) (mark)))
6186             articles article)
6187         (save-excursion
6188           (goto-char (min (min (point) (mark))))
6189           (while
6190               (and
6191                (push (setq article (gnus-summary-article-number)) articles)
6192                (gnus-summary-find-next nil article)
6193                (< (point) max)))
6194           (nreverse articles))))
6195      (gnus-newsgroup-processable
6196       ;; There are process-marked articles present.
6197       ;; Save current state.
6198       (gnus-summary-save-process-mark)
6199       ;; Return the list.
6200       (reverse gnus-newsgroup-processable))
6201      (t
6202       ;; Just return the current article.
6203       (list (gnus-summary-article-number))))))
6204
6205 (defmacro gnus-summary-iterate (arg &rest forms)
6206   "Iterate over the process/prefixed articles and do FORMS.
6207 ARG is the interactive prefix given to the command.  FORMS will be
6208 executed with point over the summary line of the articles."
6209   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6210     `(let ((,articles (gnus-summary-work-articles ,arg)))
6211        (while ,articles
6212          (gnus-summary-goto-subject (car ,articles))
6213          ,@forms
6214          (pop ,articles)))))
6215
6216 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6217 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6218
6219 (defun gnus-summary-save-process-mark ()
6220   "Push the current set of process marked articles on the stack."
6221   (interactive)
6222   (push (copy-sequence gnus-newsgroup-processable)
6223         gnus-newsgroup-process-stack))
6224
6225 (defun gnus-summary-kill-process-mark ()
6226   "Push the current set of process marked articles on the stack and unmark."
6227   (interactive)
6228   (gnus-summary-save-process-mark)
6229   (gnus-summary-unmark-all-processable))
6230
6231 (defun gnus-summary-yank-process-mark ()
6232   "Pop the last process mark state off the stack and restore it."
6233   (interactive)
6234   (unless gnus-newsgroup-process-stack
6235     (error "Empty mark stack"))
6236   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6237
6238 (defun gnus-summary-process-mark-set (set)
6239   "Make SET into the current process marked articles."
6240   (gnus-summary-unmark-all-processable)
6241   (mapc 'gnus-summary-set-process-mark set))
6242
6243 ;;; Searching and stuff
6244
6245 (defun gnus-summary-search-group (&optional backward use-level)
6246   "Search for next unread newsgroup.
6247 If optional argument BACKWARD is non-nil, search backward instead."
6248   (save-excursion
6249     (set-buffer gnus-group-buffer)
6250     (when (gnus-group-search-forward
6251            backward nil (if use-level (gnus-group-group-level) nil))
6252       (gnus-group-group-name))))
6253
6254 (defun gnus-summary-best-group (&optional exclude-group)
6255   "Find the name of the best unread group.
6256 If EXCLUDE-GROUP, do not go to this group."
6257   (with-current-buffer gnus-group-buffer
6258     (save-excursion
6259       (gnus-group-best-unread-group exclude-group))))
6260
6261 (defun gnus-summary-find-next (&optional unread article backward)
6262   (if backward
6263       (gnus-summary-find-prev unread article)
6264     (let* ((dummy (gnus-summary-article-intangible-p))
6265            (article (or article (gnus-summary-article-number)))
6266            (data (gnus-data-find-list article))
6267            result)
6268       (when (and (not dummy)
6269                  (or (not gnus-summary-check-current)
6270                      (not unread)
6271                      (not (gnus-data-unread-p (car data)))))
6272         (setq data (cdr data)))
6273       (when (setq result
6274                   (if unread
6275                       (progn
6276                         (while data
6277                           (unless (memq (gnus-data-number (car data))
6278                                         (cond
6279                                          ((eq gnus-auto-goto-ignores
6280                                               'always-undownloaded)
6281                                           gnus-newsgroup-undownloaded)
6282                                          (gnus-plugged
6283                                           nil)
6284                                          ((eq gnus-auto-goto-ignores
6285                                               'unfetched)
6286                                           gnus-newsgroup-unfetched)
6287                                          ((eq gnus-auto-goto-ignores
6288                                               'undownloaded)
6289                                           gnus-newsgroup-undownloaded)))
6290                             (when (gnus-data-unread-p (car data))
6291                               (setq result (car data)
6292                                     data nil)))
6293                           (setq data (cdr data)))
6294                         result)
6295                     (car data)))
6296         (goto-char (gnus-data-pos result))
6297         (gnus-data-number result)))))
6298
6299 (defun gnus-summary-find-prev (&optional unread article)
6300   (let* ((eobp (eobp))
6301          (article (or article (gnus-summary-article-number)))
6302          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6303          result)
6304     (when (and (not eobp)
6305                (or (not gnus-summary-check-current)
6306                    (not unread)
6307                    (not (gnus-data-unread-p (car data)))))
6308       (setq data (cdr data)))
6309     (when (setq result
6310                 (if unread
6311                     (progn
6312                       (while data
6313                         (unless (memq (gnus-data-number (car data))
6314                                       (cond
6315                                        ((eq gnus-auto-goto-ignores
6316                                             'always-undownloaded)
6317                                         gnus-newsgroup-undownloaded)
6318                                        (gnus-plugged
6319                                         nil)
6320                                        ((eq gnus-auto-goto-ignores
6321                                             'unfetched)
6322                                         gnus-newsgroup-unfetched)
6323                                        ((eq gnus-auto-goto-ignores
6324                                             'undownloaded)
6325                                         gnus-newsgroup-undownloaded)))
6326                           (when (gnus-data-unread-p (car data))
6327                             (setq result (car data)
6328                                   data nil)))
6329                         (setq data (cdr data)))
6330                       result)
6331                   (car data)))
6332       (goto-char (gnus-data-pos result))
6333       (gnus-data-number result))))
6334
6335 (defun gnus-summary-find-subject (subject &optional unread backward article)
6336   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6337          (article (or article (gnus-summary-article-number)))
6338          (articles (gnus-data-list backward))
6339          (arts (gnus-data-find-list article articles))
6340          result)
6341     (when (or (not gnus-summary-check-current)
6342               (not unread)
6343               (not (gnus-data-unread-p (car arts))))
6344       (setq arts (cdr arts)))
6345     (while arts
6346       (and (or (not unread)
6347                (gnus-data-unread-p (car arts)))
6348            (vectorp (gnus-data-header (car arts)))
6349            (gnus-subject-equal
6350             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6351            (setq result (car arts)
6352                  arts nil))
6353       (setq arts (cdr arts)))
6354     (and result
6355          (goto-char (gnus-data-pos result))
6356          (gnus-data-number result))))
6357
6358 (defun gnus-summary-search-forward (&optional unread subject backward)
6359   "Search forward for an article.
6360 If UNREAD, look for unread articles.  If SUBJECT, look for
6361 articles with that subject.  If BACKWARD, search backward instead."
6362   (cond (subject (gnus-summary-find-subject subject unread backward))
6363         (backward (gnus-summary-find-prev unread))
6364         (t (gnus-summary-find-next unread))))
6365
6366 (defun gnus-recenter (&optional n)
6367   "Center point in window and redisplay frame.
6368 Also do horizontal recentering."
6369   (interactive "P")
6370   (when (and gnus-auto-center-summary
6371              (not (eq gnus-auto-center-summary 'vertical)))
6372     (gnus-horizontal-recenter))
6373   (recenter n))
6374
6375 (defun gnus-summary-recenter ()
6376   "Center point in the summary window.
6377 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6378 displayed, no centering will be performed."
6379   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6380   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6381   (interactive)
6382   ;; The user has to want it.
6383   (when gnus-auto-center-summary
6384     (let* ((top (cond ((< (window-height) 4) 0)
6385                       ((< (window-height) 7) 1)
6386                       (t (if (numberp gnus-auto-center-summary)
6387                              gnus-auto-center-summary
6388                            (/ (1- (window-height)) 2)))))
6389            (height (1- (window-height)))
6390            (bottom (save-excursion (goto-char (point-max))
6391                                    (forward-line (- height))
6392                                    (point)))
6393            (window (get-buffer-window (current-buffer))))
6394       (when (get-buffer-window gnus-article-buffer)
6395         ;; Only do recentering when the article buffer is displayed,
6396         ;; Set the window start to either `bottom', which is the biggest
6397         ;; possible valid number, or the second line from the top,
6398         ;; whichever is the least.
6399         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6400           (if (> bottom top-pos)
6401               ;; Keep the second line from the top visible
6402               (set-window-start window top-pos t)
6403             ;; Try to keep the bottom line visible; if it's partially
6404             ;; obscured, either scroll one more line to make it fully
6405             ;; visible, or revert to using TOP-POS.
6406             (save-excursion
6407               (goto-char (point-max))
6408               (forward-line -1)
6409               (let ((last-line-start (point)))
6410                 (goto-char bottom)
6411                 (set-window-start window (point) t)
6412                 (when (not (pos-visible-in-window-p last-line-start window))
6413                   (forward-line 1)
6414                   (set-window-start window (min (point) top-pos) t)))))))
6415       ;; Do horizontal recentering while we're at it.
6416       (when (and (get-buffer-window (current-buffer) t)
6417                  (not (eq gnus-auto-center-summary 'vertical)))
6418         (let ((selected (selected-window)))
6419           (select-window (get-buffer-window (current-buffer) t))
6420           (gnus-summary-position-point)
6421           (gnus-horizontal-recenter)
6422           (select-window selected))))))
6423
6424 (defun gnus-summary-jump-to-group (newsgroup)
6425   "Move point to NEWSGROUP in group mode buffer."
6426   ;; Keep update point of group mode buffer if visible.
6427   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6428       (save-window-excursion
6429         ;; Take care of tree window mode.
6430         (when (get-buffer-window gnus-group-buffer)
6431           (pop-to-buffer gnus-group-buffer))
6432         (gnus-group-jump-to-group newsgroup))
6433     (save-excursion
6434       ;; Take care of tree window mode.
6435       (if (get-buffer-window gnus-group-buffer)
6436           (pop-to-buffer gnus-group-buffer)
6437         (set-buffer gnus-group-buffer))
6438       (gnus-group-jump-to-group newsgroup))))
6439
6440 ;; This function returns a list of article numbers based on the
6441 ;; difference between the ranges of read articles in this group and
6442 ;; the range of active articles.
6443 (defun gnus-list-of-unread-articles (group)
6444   (let* ((read (gnus-info-read (gnus-get-info group)))
6445          (active (or (gnus-active group) (gnus-activate-group group)))
6446          (last (or (cdr active)
6447                    (error "Group %s couldn't be activated " group)))
6448          first nlast unread)
6449     ;; If none are read, then all are unread.
6450     (if (not read)
6451         (setq first (car active))
6452       ;; If the range of read articles is a single range, then the
6453       ;; first unread article is the article after the last read
6454       ;; article.  Sounds logical, doesn't it?
6455       (if (and (not (listp (cdr read)))
6456                (or (< (car read) (car active))
6457                    (progn (setq read (list read))
6458                           nil)))
6459           (setq first (max (car active) (1+ (cdr read))))
6460         ;; `read' is a list of ranges.
6461         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6462                                   (caar read)))
6463                   1)
6464           (setq first (car active)))
6465         (while read
6466           (when first
6467             (while (< first nlast)
6468               (setq unread (cons first unread)
6469                     first (1+ first))))
6470           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6471           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6472           (setq read (cdr read)))))
6473     ;; And add the last unread articles.
6474     (while (<= first last)
6475       (setq unread (cons first unread)
6476             first (1+ first)))
6477     ;; Return the list of unread articles.
6478     (delq 0 (nreverse unread))))
6479
6480 (defun gnus-list-of-read-articles (group)
6481   "Return a list of unread, unticked and non-dormant articles."
6482   (let* ((info (gnus-get-info group))
6483          (marked (gnus-info-marks info))
6484          (active (gnus-active group)))
6485     (and info active
6486          (gnus-list-range-difference
6487           (gnus-list-range-difference
6488            (gnus-sorted-complement
6489             (gnus-uncompress-range active)
6490             (gnus-list-of-unread-articles group))
6491            (cdr (assq 'dormant marked)))
6492           (cdr (assq 'tick marked))))))
6493
6494 ;; This function returns a sequence of article numbers based on the
6495 ;; difference between the ranges of read articles in this group and
6496 ;; the range of active articles.
6497 (defun gnus-sequence-of-unread-articles (group)
6498   (let* ((read (gnus-info-read (gnus-get-info group)))
6499          (active (or (gnus-active group) (gnus-activate-group group)))
6500          (last (cdr active))
6501          first nlast unread)
6502     ;; If none are read, then all are unread.
6503     (if (not read)
6504         (setq first (car active))
6505       ;; If the range of read articles is a single range, then the
6506       ;; first unread article is the article after the last read
6507       ;; article.  Sounds logical, doesn't it?
6508       (if (and (not (listp (cdr read)))
6509                (or (< (car read) (car active))
6510                    (progn (setq read (list read))
6511                           nil)))
6512           (setq first (max (car active) (1+ (cdr read))))
6513         ;; `read' is a list of ranges.
6514         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6515                                   (caar read)))
6516                   1)
6517           (setq first (car active)))
6518         (while read
6519           (when first
6520             (push (cons first nlast) unread))
6521           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6522           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6523           (setq read (cdr read)))))
6524     ;; And add the last unread articles.
6525     (cond ((< first last)
6526            (push (cons first last) unread))
6527           ((= first last)
6528            (push first unread)))
6529     ;; Return the sequence of unread articles.
6530     (delq 0 (nreverse unread))))
6531
6532 ;; Various summary commands
6533
6534 (defun gnus-summary-select-article-buffer ()
6535   "Reconfigure windows to show article buffer."
6536   (interactive)
6537   (if (not (gnus-buffer-live-p gnus-article-buffer))
6538       (error "There is no article buffer for this summary buffer")
6539     (gnus-configure-windows 'article)
6540     (select-window (get-buffer-window gnus-article-buffer))))
6541
6542 (defun gnus-summary-universal-argument (arg)
6543   "Perform any operation on all articles that are process/prefixed."
6544   (interactive "P")
6545   (let ((articles (gnus-summary-work-articles arg))
6546         func article)
6547     (if (eq
6548          (setq
6549           func
6550           (key-binding
6551            (read-key-sequence
6552             (substitute-command-keys
6553              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6554          'undefined)
6555         (gnus-error 1 "Undefined key")
6556       (save-excursion
6557         (while articles
6558           (gnus-summary-goto-subject (setq article (pop articles)))
6559           (let (gnus-newsgroup-processable)
6560             (command-execute func))
6561           (gnus-summary-remove-process-mark article)))))
6562   (gnus-summary-position-point))
6563
6564 (defun gnus-summary-toggle-truncation (&optional arg)
6565   "Toggle truncation of summary lines.
6566 With ARG, turn line truncation on if ARG is positive."
6567   (interactive "P")
6568   (setq truncate-lines
6569         (if (null arg) (not truncate-lines)
6570           (> (prefix-numeric-value arg) 0)))
6571   (redraw-display))
6572
6573 (defun gnus-summary-find-for-reselect ()
6574   "Return the number of an article to stay on across a reselect.
6575 The current article is considered, then following articles, then previous
6576 articles.  An article is sought which is not cancelled and isn't a temporary
6577 insertion from another group.  If there's no such then return a dummy 0."
6578   (let (found)
6579     (dolist (rev '(nil t))
6580       (unless found      ; don't demand the reverse list if we don't need it
6581         (let ((data (gnus-data-find-list
6582                      (gnus-summary-article-number) (gnus-data-list rev))))
6583           (while (and data (not found))
6584             (if (and (< 0 (gnus-data-number (car data)))
6585                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6586                 (setq found (gnus-data-number (car data))))
6587             (setq data (cdr data))))))
6588     (or found 0)))
6589
6590 (defun gnus-summary-reselect-current-group (&optional all rescan)
6591   "Exit and then reselect the current newsgroup.
6592 The prefix argument ALL means to select all articles."
6593   (interactive "P")
6594   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6595     (error "Ephemeral groups can't be reselected"))
6596   (let ((current-subject (gnus-summary-find-for-reselect))
6597         (group gnus-newsgroup-name))
6598     (setq gnus-newsgroup-begin nil)
6599     (gnus-summary-exit nil 'leave-hidden)
6600     ;; We have to adjust the point of group mode buffer because
6601     ;; point was moved to the next unread newsgroup by exiting.
6602     (gnus-summary-jump-to-group group)
6603     (when rescan
6604       (save-excursion
6605         (gnus-group-get-new-news-this-group 1)))
6606     (gnus-group-read-group all t)
6607     (gnus-summary-goto-subject current-subject nil t)))
6608
6609 (defun gnus-summary-rescan-group (&optional all)
6610   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6611   (interactive "P")
6612   (gnus-summary-reselect-current-group all t))
6613
6614 (defun gnus-summary-update-info (&optional non-destructive)
6615   (save-excursion
6616     (let ((group gnus-newsgroup-name))
6617       (when group
6618         (when gnus-newsgroup-kill-headers
6619           (setq gnus-newsgroup-killed
6620                 (gnus-compress-sequence
6621                  (gnus-sorted-union
6622                   (gnus-list-range-intersection
6623                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6624                   gnus-newsgroup-unreads)
6625                  t)))
6626         (unless (listp (cdr gnus-newsgroup-killed))
6627           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6628         (let ((headers gnus-newsgroup-headers))
6629           ;; Set the new ranges of read articles.
6630           (with-current-buffer gnus-group-buffer
6631             (gnus-undo-force-boundary))
6632           (gnus-update-read-articles
6633            group (gnus-sorted-union
6634                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6635           ;; Set the current article marks.
6636           (let ((gnus-newsgroup-scored
6637                  (if (and (not gnus-save-score)
6638                           (not non-destructive))
6639                      nil
6640                    gnus-newsgroup-scored)))
6641             (save-excursion
6642               (gnus-update-marks)))
6643           ;; Do the cross-ref thing.
6644           (when gnus-use-cross-reference
6645             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6646           ;; Do not switch windows but change the buffer to work.
6647           (set-buffer gnus-group-buffer)
6648           (unless (gnus-ephemeral-group-p group)
6649             (gnus-group-update-group group)))))))
6650
6651 (defun gnus-summary-save-newsrc (&optional force)
6652   "Save the current number of read/marked articles in the dribble buffer.
6653 The dribble buffer will then be saved.
6654 If FORCE (the prefix), also save the .newsrc file(s)."
6655   (interactive "P")
6656   (gnus-summary-update-info t)
6657   (if force
6658       (gnus-save-newsrc-file)
6659     (gnus-dribble-save)))
6660
6661 (defun gnus-summary-exit (&optional temporary leave-hidden)
6662   "Exit reading current newsgroup, and then return to group selection mode.
6663 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6664   (interactive)
6665   (gnus-set-global-variables)
6666   (when (gnus-buffer-live-p gnus-article-buffer)
6667     (save-excursion
6668       (set-buffer gnus-article-buffer)
6669       (mm-destroy-parts gnus-article-mime-handles)
6670       ;; Set it to nil for safety reason.
6671       (setq gnus-article-mime-handle-alist nil)
6672       (setq gnus-article-mime-handles nil)))
6673   (gnus-kill-save-kill-buffer)
6674   (gnus-async-halt-prefetch)
6675   (let* ((group gnus-newsgroup-name)
6676          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6677          (gnus-group-is-exiting-p t)
6678          (mode major-mode)
6679          (group-point nil)
6680          (buf (current-buffer)))
6681     (unless quit-config
6682       ;; Do adaptive scoring, and possibly save score files.
6683       (when gnus-newsgroup-adaptive
6684         (gnus-score-adaptive))
6685       (when gnus-use-scoring
6686         (gnus-score-save)))
6687     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6688     ;; If we have several article buffers, we kill them at exit.
6689     (unless gnus-single-article-buffer
6690       (gnus-kill-buffer gnus-original-article-buffer)
6691       (setq gnus-article-current nil))
6692     (when gnus-use-cache
6693       (gnus-cache-possibly-remove-articles)
6694       (gnus-cache-save-buffers))
6695     (gnus-async-prefetch-remove-group group)
6696     (when gnus-suppress-duplicates
6697       (gnus-dup-enter-articles))
6698     (when gnus-use-trees
6699       (gnus-tree-close group))
6700     (when gnus-use-cache
6701       (gnus-cache-write-active))
6702     ;; Remove entries for this group.
6703     (nnmail-purge-split-history (gnus-group-real-name group))
6704     ;; Make all changes in this group permanent.
6705     (unless quit-config
6706       (gnus-run-hooks 'gnus-exit-group-hook)
6707       (gnus-summary-update-info))
6708     (gnus-close-group group)
6709     ;; Make sure where we were, and go to next newsgroup.
6710     (set-buffer gnus-group-buffer)
6711     (unless quit-config
6712       (gnus-group-jump-to-group group))
6713     (gnus-run-hooks 'gnus-summary-exit-hook)
6714     (unless (or quit-config
6715                 ;; If this group has disappeared from the summary
6716                 ;; buffer, don't skip forwards.
6717                 (not (string= group (gnus-group-group-name))))
6718       (gnus-group-next-unread-group 1))
6719     (setq group-point (point))
6720     (if temporary
6721         nil                             ;Nothing to do.
6722       ;; If we have several article buffers, we kill them at exit.
6723       (unless gnus-single-article-buffer
6724         (gnus-kill-buffer gnus-article-buffer)
6725         (gnus-kill-buffer gnus-original-article-buffer)
6726         (setq gnus-article-current nil))
6727       (set-buffer buf)
6728       (if (not gnus-kill-summary-on-exit)
6729           (progn
6730             (gnus-deaden-summary)
6731             (setq mode nil))
6732         ;; We set all buffer-local variables to nil.  It is unclear why
6733         ;; this is needed, but if we don't, buffer-local variables are
6734         ;; not garbage-collected, it seems.  This would the lead to en
6735         ;; ever-growing Emacs.
6736         (gnus-summary-clear-local-variables)
6737         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6738           (gnus-summary-clear-local-variables))
6739         (when (get-buffer gnus-article-buffer)
6740           (bury-buffer gnus-article-buffer))
6741         ;; Return to group mode buffer.
6742         (when (eq mode 'gnus-summary-mode)
6743           (gnus-kill-buffer buf)))
6744       (setq gnus-current-select-method gnus-select-method)
6745       (set-buffer gnus-group-buffer)
6746       (if quit-config
6747           (gnus-handle-ephemeral-exit quit-config)
6748         (goto-char group-point)
6749         ;; If gnus-group-buffer is already displayed, make sure we also move
6750         ;; the cursor in the window that displays it.
6751         (let ((win (get-buffer-window (current-buffer) 0)))
6752           (if win (set-window-point win (point))))
6753         (unless leave-hidden
6754           (gnus-configure-windows 'group 'force)))
6755       ;; Clear the current group name.
6756       (unless quit-config
6757         (setq gnus-newsgroup-name nil)))))
6758
6759 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6760 (defun gnus-summary-exit-no-update (&optional no-questions)
6761   "Quit reading current newsgroup without updating read article info."
6762   (interactive)
6763   (let* ((group gnus-newsgroup-name)
6764          (gnus-group-is-exiting-p t)
6765          (gnus-group-is-exiting-without-update-p t)
6766          (quit-config (gnus-group-quit-config group)))
6767     (when (or no-questions
6768               gnus-expert-user
6769               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6770       (gnus-async-halt-prefetch)
6771       (run-hooks 'gnus-summary-prepare-exit-hook)
6772       (when (gnus-buffer-live-p gnus-article-buffer)
6773         (save-excursion
6774           (set-buffer gnus-article-buffer)
6775           (mm-destroy-parts gnus-article-mime-handles)
6776           ;; Set it to nil for safety reason.
6777           (setq gnus-article-mime-handle-alist nil)
6778           (setq gnus-article-mime-handles nil)))
6779       ;; If we have several article buffers, we kill them at exit.
6780       (unless gnus-single-article-buffer
6781         (gnus-kill-buffer gnus-article-buffer)
6782         (gnus-kill-buffer gnus-original-article-buffer)
6783         (setq gnus-article-current nil))
6784       (if (not gnus-kill-summary-on-exit)
6785           (gnus-deaden-summary)
6786         (gnus-close-group group)
6787         (gnus-summary-clear-local-variables)
6788         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6789           (gnus-summary-clear-local-variables))
6790         (gnus-kill-buffer gnus-summary-buffer))
6791       (unless gnus-single-article-buffer
6792         (setq gnus-article-current nil))
6793       (when gnus-use-trees
6794         (gnus-tree-close group))
6795       (gnus-async-prefetch-remove-group group)
6796       (when (get-buffer gnus-article-buffer)
6797         (bury-buffer gnus-article-buffer))
6798       ;; Return to the group buffer.
6799       (gnus-configure-windows 'group 'force)
6800       ;; Clear the current group name.
6801       (setq gnus-newsgroup-name nil)
6802       (unless (gnus-ephemeral-group-p group)
6803         (gnus-group-update-group group))
6804       (when (equal (gnus-group-group-name) group)
6805         (gnus-group-next-unread-group 1))
6806       (when quit-config
6807         (gnus-handle-ephemeral-exit quit-config)))))
6808
6809 (defun gnus-handle-ephemeral-exit (quit-config)
6810   "Handle movement when leaving an ephemeral group.
6811 The state which existed when entering the ephemeral is reset."
6812   (if (not (buffer-name (car quit-config)))
6813       (gnus-configure-windows 'group 'force)
6814     (set-buffer (car quit-config))
6815     (cond ((eq major-mode 'gnus-summary-mode)
6816            (gnus-set-global-variables))
6817           ((eq major-mode 'gnus-article-mode)
6818            (save-excursion
6819              ;; The `gnus-summary-buffer' variable may point
6820              ;; to the old summary buffer when using a single
6821              ;; article buffer.
6822              (unless (gnus-buffer-live-p gnus-summary-buffer)
6823                (set-buffer gnus-group-buffer))
6824              (set-buffer gnus-summary-buffer)
6825              (gnus-set-global-variables))))
6826     (if (or (eq (cdr quit-config) 'article)
6827             (eq (cdr quit-config) 'pick))
6828         (progn
6829           ;; The current article may be from the ephemeral group
6830           ;; thus it is best that we reload this article
6831           ;;
6832           ;; If we're exiting from a large digest, this can be
6833           ;; extremely slow.  So, it's better not to reload it. -- jh.
6834           ;;(gnus-summary-show-article)
6835           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6836               (gnus-configure-windows 'pick 'force)
6837             (gnus-configure-windows (cdr quit-config) 'force)))
6838       (gnus-configure-windows (cdr quit-config) 'force))
6839     (when (eq major-mode 'gnus-summary-mode)
6840       (gnus-summary-next-subject 1 nil t)
6841       (gnus-summary-recenter)
6842       (gnus-summary-position-point))))
6843
6844 ;;; Dead summaries.
6845
6846 (defvar gnus-dead-summary-mode-map nil)
6847
6848 (unless gnus-dead-summary-mode-map
6849   (setq gnus-dead-summary-mode-map (make-keymap))
6850   (suppress-keymap gnus-dead-summary-mode-map)
6851   (substitute-key-definition
6852    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6853   (dolist (key '("\C-d" "\r" "\177" [delete]))
6854     (define-key gnus-dead-summary-mode-map
6855       key 'gnus-summary-wake-up-the-dead))
6856   (dolist (key '("q" "Q"))
6857     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6858
6859 (defvar gnus-dead-summary-mode nil
6860   "Minor mode for Gnus summary buffers.")
6861
6862 (defun gnus-dead-summary-mode (&optional arg)
6863   "Minor mode for Gnus summary buffers."
6864   (interactive "P")
6865   (when (eq major-mode 'gnus-summary-mode)
6866     (make-local-variable 'gnus-dead-summary-mode)
6867     (setq gnus-dead-summary-mode
6868           (if (null arg) (not gnus-dead-summary-mode)
6869             (> (prefix-numeric-value arg) 0)))
6870     (when gnus-dead-summary-mode
6871       (add-minor-mode
6872        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6873
6874 (defun gnus-deaden-summary ()
6875   "Make the current summary buffer into a dead summary buffer."
6876   ;; Kill any previous dead summary buffer.
6877   (when (and gnus-dead-summary
6878              (buffer-name gnus-dead-summary))
6879     (with-current-buffer gnus-dead-summary
6880       (when gnus-dead-summary-mode
6881         (kill-buffer (current-buffer)))))
6882   ;; Make this the current dead summary.
6883   (setq gnus-dead-summary (current-buffer))
6884   (gnus-dead-summary-mode 1)
6885   (let ((name (buffer-name)))
6886     (when (string-match "Summary" name)
6887       (rename-buffer
6888        (concat (substring name 0 (match-beginning 0)) "Dead "
6889                (substring name (match-beginning 0)))
6890        t)
6891       (bury-buffer))))
6892
6893 (defun gnus-kill-or-deaden-summary (buffer)
6894   "Kill or deaden the summary BUFFER."
6895   (save-excursion
6896     (when (and (buffer-name buffer)
6897                (not gnus-single-article-buffer))
6898       (with-current-buffer buffer
6899         (gnus-kill-buffer gnus-article-buffer)
6900         (gnus-kill-buffer gnus-original-article-buffer)))
6901     (cond
6902      ;; Kill the buffer.
6903      (gnus-kill-summary-on-exit
6904       (when (and gnus-use-trees
6905                  (gnus-buffer-exists-p buffer))
6906         (save-excursion
6907           (set-buffer buffer)
6908           (gnus-tree-close gnus-newsgroup-name)))
6909       (gnus-kill-buffer buffer))
6910      ;; Deaden the buffer.
6911      ((gnus-buffer-exists-p buffer)
6912       (save-excursion
6913         (set-buffer buffer)
6914         (gnus-deaden-summary))))))
6915
6916 (defun gnus-summary-wake-up-the-dead (&rest args)
6917   "Wake up the dead summary buffer."
6918   (interactive)
6919   (gnus-dead-summary-mode -1)
6920   (let ((name (buffer-name)))
6921     (when (string-match "Dead " name)
6922       (rename-buffer
6923        (concat (substring name 0 (match-beginning 0))
6924                (substring name (match-end 0)))
6925        t)))
6926   (gnus-message 3 "This dead summary is now alive again"))
6927
6928 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6929 (defun gnus-summary-fetch-faq (&optional faq-dir)
6930   "Fetch the FAQ for the current group.
6931 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6932 in."
6933   (interactive
6934    (list
6935     (when current-prefix-arg
6936       (completing-read
6937        "FAQ dir: " (and (listp gnus-group-faq-directory)
6938                         (mapcar 'list
6939                                 gnus-group-faq-directory))))))
6940   (let (gnus-faq-buffer)
6941     (when (setq gnus-faq-buffer
6942                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6943       (gnus-configure-windows 'summary-faq))))
6944
6945 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6946 (defun gnus-summary-describe-group (&optional force)
6947   "Describe the current newsgroup."
6948   (interactive "P")
6949   (gnus-group-describe-group force gnus-newsgroup-name))
6950
6951 (defun gnus-summary-describe-briefly ()
6952   "Describe summary mode commands briefly."
6953   (interactive)
6954   (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")))
6955
6956 ;; Walking around group mode buffer from summary mode.
6957
6958 (defun gnus-summary-next-group (&optional no-article target-group backward)
6959   "Exit current newsgroup and then select next unread newsgroup.
6960 If prefix argument NO-ARTICLE is non-nil, no article is selected
6961 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6962 previous group instead."
6963   (interactive "P")
6964   ;; Stop pre-fetching.
6965   (gnus-async-halt-prefetch)
6966   (let ((current-group gnus-newsgroup-name)
6967         (current-buffer (current-buffer))
6968         entered)
6969     ;; First we semi-exit this group to update Xrefs and all variables.
6970     ;; We can't do a real exit, because the window conf must remain
6971     ;; the same in case the user is prompted for info, and we don't
6972     ;; want the window conf to change before that...
6973     (gnus-summary-exit t)
6974     (while (not entered)
6975       ;; Then we find what group we are supposed to enter.
6976       (set-buffer gnus-group-buffer)
6977       (gnus-group-jump-to-group current-group)
6978       (setq target-group
6979             (or target-group
6980                 (if (eq gnus-keep-same-level 'best)
6981                     (gnus-summary-best-group gnus-newsgroup-name)
6982                   (gnus-summary-search-group backward gnus-keep-same-level))))
6983       (if (not target-group)
6984           ;; There are no further groups, so we return to the group
6985           ;; buffer.
6986           (progn
6987             (gnus-message 5 "Returning to the group buffer")
6988             (setq entered t)
6989             (when (gnus-buffer-live-p current-buffer)
6990               (set-buffer current-buffer)
6991               (gnus-summary-exit))
6992             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6993         ;; We try to enter the target group.
6994         (gnus-group-jump-to-group target-group)
6995         (let ((unreads (gnus-group-group-unread)))
6996           (if (and (or (eq t unreads)
6997                        (and unreads (not (zerop unreads))))
6998                    (gnus-summary-read-group
6999                     target-group nil no-article
7000                     (and (buffer-name current-buffer) current-buffer)
7001                     nil backward))
7002               (setq entered t)
7003             (setq current-group target-group
7004                   target-group nil)))))))
7005
7006 (defun gnus-summary-prev-group (&optional no-article)
7007   "Exit current newsgroup and then select previous unread newsgroup.
7008 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7009   (interactive "P")
7010   (gnus-summary-next-group no-article nil t))
7011
7012 ;; Walking around summary lines.
7013
7014 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7015   "Go to the first subject satisfying any non-nil constraint.
7016 If UNREAD is non-nil, the article should be unread.
7017 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7018 If UNSEEN is non-nil, the article should be unseen.
7019 Returns the article selected or nil if there are no matching articles."
7020   (interactive "P")
7021   (cond
7022    ;; Empty summary.
7023    ((null gnus-newsgroup-data)
7024     (gnus-message 3 "No articles in the group")
7025     nil)
7026    ;; Pick the first article.
7027    ((not (or unread undownloaded unseen))
7028     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7029     (gnus-data-number (car gnus-newsgroup-data)))
7030    ;; Find the first unread article.
7031    (t
7032     (let ((data gnus-newsgroup-data))
7033       (while (and data
7034                   (let ((num (gnus-data-number (car data))))
7035                     (or (memq num gnus-newsgroup-unfetched)
7036                         (not (or (and unread
7037                                       (memq num gnus-newsgroup-unreads))
7038                                  (and undownloaded
7039                                       (memq num gnus-newsgroup-undownloaded))
7040                                  (and unseen
7041                                       (memq num gnus-newsgroup-unseen)))))))
7042         (setq data (cdr data)))
7043       (prog1
7044           (if data
7045               (progn
7046                 (goto-char (gnus-data-pos (car data)))
7047                 (gnus-data-number (car data)))
7048             (gnus-message 3 "No more%s articles"
7049                           (let* ((r (when unread " unread"))
7050                                  (d (when undownloaded " undownloaded"))
7051                                  (s (when unseen " unseen"))
7052                                  (l (delq nil (list r d s))))
7053                             (cond ((= 3 (length l))
7054                                    (concat r "," d ", or" s))
7055                                   ((= 2 (length l))
7056                                    (concat (car l) ", or" (cadr l)))
7057                                   ((= 1 (length l))
7058                                    (car l))
7059                                   (t
7060                                    ""))))
7061             nil
7062             )
7063         (gnus-summary-position-point))))))
7064
7065 (defun gnus-summary-next-subject (n &optional unread dont-display)
7066   "Go to next N'th summary line.
7067 If N is negative, go to the previous N'th subject line.
7068 If UNREAD is non-nil, only unread articles are selected.
7069 The difference between N and the actual number of steps taken is
7070 returned."
7071   (interactive "p")
7072   (let ((backward (< n 0))
7073         (n (abs n)))
7074     (while (and (> n 0)
7075                 (if backward
7076                     (gnus-summary-find-prev unread)
7077                   (gnus-summary-find-next unread)))
7078       (unless (zerop (setq n (1- n)))
7079         (gnus-summary-show-thread)))
7080     (when (/= 0 n)
7081       (gnus-message 7 "No more%s articles"
7082                     (if unread " unread" "")))
7083     (unless dont-display
7084       (gnus-summary-recenter)
7085       (gnus-summary-position-point))
7086     n))
7087
7088 (defun gnus-summary-next-unread-subject (n)
7089   "Go to next N'th unread summary line."
7090   (interactive "p")
7091   (gnus-summary-next-subject n t))
7092
7093 (defun gnus-summary-prev-subject (n &optional unread)
7094   "Go to previous N'th summary line.
7095 If optional argument UNREAD is non-nil, only unread article is selected."
7096   (interactive "p")
7097   (gnus-summary-next-subject (- n) unread))
7098
7099 (defun gnus-summary-prev-unread-subject (n)
7100   "Go to previous N'th unread summary line."
7101   (interactive "p")
7102   (gnus-summary-next-subject (- n) t))
7103
7104 (defun gnus-summary-goto-subjects (articles)
7105   "Insert the subject header for ARTICLES in the current buffer."
7106   (save-excursion
7107     (dolist (article articles)
7108       (gnus-summary-goto-subject article t)))
7109   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7110   (gnus-summary-position-point))
7111
7112 (defun gnus-summary-goto-subject (article &optional force silent)
7113   "Go the subject line of ARTICLE.
7114 If FORCE, also allow jumping to articles not currently shown."
7115   (interactive "nArticle number: ")
7116   (unless (numberp article)
7117     (error "Article %s is not a number" article))
7118   (let ((b (point))
7119         (data (gnus-data-find article)))
7120     ;; We read in the article if we have to.
7121     (and (not data)
7122          force
7123          (gnus-summary-insert-subject
7124           article
7125           (if (or (numberp force) (vectorp force)) force)
7126           t)
7127          (setq data (gnus-data-find article)))
7128     (goto-char b)
7129     (if (not data)
7130         (progn
7131           (unless silent
7132             (gnus-message 3 "Can't find article %d" article))
7133           nil)
7134       (let ((pt (gnus-data-pos data)))
7135         (goto-char pt)
7136         (gnus-summary-set-article-display-arrow pt))
7137       (gnus-summary-position-point)
7138       article)))
7139
7140 ;; Walking around summary lines with displaying articles.
7141
7142 (defun gnus-summary-expand-window (&optional arg)
7143   "Make the summary buffer take up the entire Emacs frame.
7144 Given a prefix, will force an `article' buffer configuration."
7145   (interactive "P")
7146   (if arg
7147       (gnus-configure-windows 'article 'force)
7148     (gnus-configure-windows 'summary 'force)))
7149
7150 (defun gnus-summary-display-article (article &optional all-header)
7151   "Display ARTICLE in article buffer."
7152   (when (gnus-buffer-live-p gnus-article-buffer)
7153     (with-current-buffer gnus-article-buffer
7154       (mm-enable-multibyte)))
7155   (gnus-set-global-variables)
7156   (when (gnus-buffer-live-p gnus-article-buffer)
7157     (with-current-buffer gnus-article-buffer
7158       (setq gnus-article-charset gnus-newsgroup-charset)
7159       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7160       (mm-enable-multibyte)))
7161   (if (null article)
7162       nil
7163     (prog1
7164         (if gnus-summary-display-article-function
7165             (funcall gnus-summary-display-article-function article all-header)
7166           (gnus-article-prepare article all-header))
7167       (gnus-run-hooks 'gnus-select-article-hook)
7168       (when (and gnus-current-article
7169                  (not (zerop gnus-current-article)))
7170         (gnus-summary-goto-subject gnus-current-article))
7171       (gnus-summary-recenter)
7172       (when (and gnus-use-trees gnus-show-threads)
7173         (gnus-possibly-generate-tree article)
7174         (gnus-highlight-selected-tree article))
7175       ;; Successfully display article.
7176       (gnus-article-set-window-start
7177        (cdr (assq article gnus-newsgroup-bookmarks))))))
7178
7179 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7180   "Select the current article.
7181 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7182 non-nil, the article will be re-fetched even if it already present in
7183 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7184 be displayed."
7185   ;; Make sure we are in the summary buffer to work around bbdb bug.
7186   (unless (eq major-mode 'gnus-summary-mode)
7187     (set-buffer gnus-summary-buffer))
7188   (let ((article (or article (gnus-summary-article-number)))
7189         (all-headers (not (not all-headers))) ;Must be t or nil.
7190         gnus-summary-display-article-function)
7191     (and (not pseudo)
7192          (gnus-summary-article-pseudo-p article)
7193          (error "This is a pseudo-article"))
7194     (save-excursion
7195       (set-buffer gnus-summary-buffer)
7196       (if (or (and gnus-single-article-buffer
7197                    (or (null gnus-current-article)
7198                        (null gnus-article-current)
7199                        (null (get-buffer gnus-article-buffer))
7200                        (not (eq article (cdr gnus-article-current)))
7201                        (not (equal (car gnus-article-current)
7202                                    gnus-newsgroup-name))))
7203               (and (not gnus-single-article-buffer)
7204                    (or (null gnus-current-article)
7205                        (not (eq gnus-current-article article))))
7206               force)
7207           ;; The requested article is different from the current article.
7208           (progn
7209             (gnus-summary-display-article article all-headers)
7210             (when (gnus-buffer-live-p gnus-article-buffer)
7211               (with-current-buffer gnus-article-buffer
7212                 (if (not gnus-article-decoded-p) ;; a local variable
7213                     (mm-disable-multibyte))))
7214             (gnus-article-set-window-start
7215              (cdr (assq article gnus-newsgroup-bookmarks)))
7216             article)
7217         'old))))
7218
7219 (defun gnus-summary-force-verify-and-decrypt ()
7220   "Display buttons for signed/encrypted parts and verify/decrypt them."
7221   (interactive)
7222   (let ((mm-verify-option 'known)
7223         (mm-decrypt-option 'known)
7224         (gnus-article-emulate-mime t)
7225         (gnus-buttonized-mime-types (append (list "multipart/signed"
7226                                                   "multipart/encrypted")
7227                                             gnus-buttonized-mime-types)))
7228     (gnus-summary-select-article nil 'force)))
7229
7230 (defun gnus-summary-set-current-mark (&optional current-mark)
7231   "Obsolete function."
7232   nil)
7233
7234 (defun gnus-summary-next-article (&optional unread subject backward push)
7235   "Select the next article.
7236 If UNREAD, only unread articles are selected.
7237 If SUBJECT, only articles with SUBJECT are selected.
7238 If BACKWARD, the previous article is selected instead of the next."
7239   (interactive "P")
7240   (cond
7241    ;; Is there such an article?
7242    ((and (gnus-summary-search-forward unread subject backward)
7243          (or (gnus-summary-display-article (gnus-summary-article-number))
7244              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7245     (gnus-summary-position-point))
7246    ;; If not, we try the first unread, if that is wanted.
7247    ((and subject
7248          gnus-auto-select-same
7249          (gnus-summary-first-unread-article))
7250     (gnus-summary-position-point)
7251     (gnus-message 6 "Wrapped"))
7252    ;; Try to get next/previous article not displayed in this group.
7253    ((and gnus-auto-extend-newsgroup
7254          (not unread) (not subject))
7255     (gnus-summary-goto-article
7256      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7257      nil (count-lines (point-min) (point))))
7258    ;; Go to next/previous group.
7259    (t
7260     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7261       (gnus-summary-jump-to-group gnus-newsgroup-name))
7262     (let ((cmd last-command-char)
7263           (point
7264            (with-current-buffer gnus-group-buffer
7265              (point)))
7266           (group
7267            (if (eq gnus-keep-same-level 'best)
7268                (gnus-summary-best-group gnus-newsgroup-name)
7269              (gnus-summary-search-group backward gnus-keep-same-level))))
7270       ;; For some reason, the group window gets selected.  We change
7271       ;; it back.
7272       (select-window (get-buffer-window (current-buffer)))
7273       ;; Select next unread newsgroup automagically.
7274       (cond
7275        ((or (not gnus-auto-select-next)
7276             (not cmd))
7277         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7278        ((or (eq gnus-auto-select-next 'quietly)
7279             (and (eq gnus-auto-select-next 'slightly-quietly)
7280                  push)
7281             (and (eq gnus-auto-select-next 'almost-quietly)
7282                  (gnus-summary-last-article-p)))
7283         ;; Select quietly.
7284         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7285             (gnus-summary-exit)
7286           (gnus-message 7 "No more%s articles (%s)..."
7287                         (if unread " unread" "")
7288                         (if group (concat "selecting " group)
7289                           "exiting"))
7290           (gnus-summary-next-group nil group backward)))
7291        (t
7292         (when (gnus-key-press-event-p last-input-event)
7293           (gnus-summary-walk-group-buffer
7294            gnus-newsgroup-name cmd unread backward point))))))))
7295
7296 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7297   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7298                       (?\C-p (gnus-group-prev-unread-group 1))))
7299         (cursor-in-echo-area t)
7300         keve key group ended prompt)
7301     (save-excursion
7302       (set-buffer gnus-group-buffer)
7303       (goto-char start)
7304       (setq group
7305             (if (eq gnus-keep-same-level 'best)
7306                 (gnus-summary-best-group gnus-newsgroup-name)
7307               (gnus-summary-search-group backward gnus-keep-same-level))))
7308     (while (not ended)
7309       (setq prompt
7310             (format
7311              "No more%s articles%s " (if unread " unread" "")
7312              (if (and group
7313                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7314                  (format " (Type %s for %s [%s])"
7315                          (single-key-description cmd)
7316                          (gnus-group-decoded-name group)
7317                          (gnus-group-unread group))
7318                (format " (Type %s to exit %s)"
7319                        (single-key-description cmd)
7320                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7321       ;; Confirm auto selection.
7322       (setq key (car (setq keve (gnus-read-event-char prompt)))
7323             ended t)
7324       (cond
7325        ((assq key keystrokes)
7326         (let ((obuf (current-buffer)))
7327           (switch-to-buffer gnus-group-buffer)
7328           (when group
7329             (gnus-group-jump-to-group group))
7330           (eval (cadr (assq key keystrokes)))
7331           (setq group (gnus-group-group-name))
7332           (switch-to-buffer obuf))
7333         (setq ended nil))
7334        ((equal key cmd)
7335         (if (or (not group)
7336                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7337             (gnus-summary-exit)
7338           (gnus-summary-next-group nil group backward)))
7339        (t
7340         (push (cdr keve) unread-command-events))))))
7341
7342 (defun gnus-summary-next-unread-article ()
7343   "Select unread article after current one."
7344   (interactive)
7345   (gnus-summary-next-article
7346    (or (not (eq gnus-summary-goto-unread 'never))
7347        (gnus-summary-last-article-p (gnus-summary-article-number)))
7348    (and gnus-auto-select-same
7349         (gnus-summary-article-subject))))
7350
7351 (defun gnus-summary-prev-article (&optional unread subject)
7352   "Select the article after the current one.
7353 If UNREAD is non-nil, only unread articles are selected."
7354   (interactive "P")
7355   (gnus-summary-next-article unread subject t))
7356
7357 (defun gnus-summary-prev-unread-article ()
7358   "Select unread article before current one."
7359   (interactive)
7360   (gnus-summary-prev-article
7361    (or (not (eq gnus-summary-goto-unread 'never))
7362        (gnus-summary-first-article-p (gnus-summary-article-number)))
7363    (and gnus-auto-select-same
7364         (gnus-summary-article-subject))))
7365
7366 (defun gnus-summary-next-page (&optional lines circular stop)
7367   "Show next page of the selected article.
7368 If at the end of the current article, select the next article.
7369 LINES says how many lines should be scrolled up.
7370
7371 If CIRCULAR is non-nil, go to the start of the article instead of
7372 selecting the next article when reaching the end of the current
7373 article.
7374
7375 If STOP is non-nil, just stop when reaching the end of the message.
7376
7377 Also see the variable `gnus-article-skip-boring'."
7378   (interactive "P")
7379   (setq gnus-summary-buffer (current-buffer))
7380   (gnus-set-global-variables)
7381   (let ((article (gnus-summary-article-number))
7382         (article-window (get-buffer-window gnus-article-buffer t))
7383         endp)
7384     ;; If the buffer is empty, we have no article.
7385     (unless article
7386       (error "No article to select"))
7387     (gnus-configure-windows 'article)
7388     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7389         (if (and (eq gnus-summary-goto-unread 'never)
7390                  (not (gnus-summary-last-article-p article)))
7391             (gnus-summary-next-article)
7392           (gnus-summary-next-unread-article))
7393       (if (or (null gnus-current-article)
7394               (null gnus-article-current)
7395               (/= article (cdr gnus-article-current))
7396               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7397           ;; Selected subject is different from current article's.
7398           (gnus-summary-display-article article)
7399         (when article-window
7400           (gnus-eval-in-buffer-window gnus-article-buffer
7401             (setq endp (or (gnus-article-next-page lines)
7402                            (gnus-article-only-boring-p))))
7403           (when endp
7404             (cond (stop
7405                    (gnus-message 3 "End of message"))
7406                   (circular
7407                    (gnus-summary-beginning-of-article))
7408                   (lines
7409                    (gnus-message 3 "End of message"))
7410                   ((null lines)
7411                    (if (and (eq gnus-summary-goto-unread 'never)
7412                             (not (gnus-summary-last-article-p article)))
7413                        (gnus-summary-next-article)
7414                      (gnus-summary-next-unread-article))))))))
7415     (gnus-summary-recenter)
7416     (gnus-summary-position-point)))
7417
7418 (defun gnus-summary-prev-page (&optional lines move)
7419   "Show previous page of selected article.
7420 Argument LINES specifies lines to be scrolled down.
7421 If MOVE, move to the previous unread article if point is at
7422 the beginning of the buffer."
7423   (interactive "P")
7424   (let ((article (gnus-summary-article-number))
7425         (article-window (get-buffer-window gnus-article-buffer t))
7426         endp)
7427     (gnus-configure-windows 'article)
7428     (if (or (null gnus-current-article)
7429             (null gnus-article-current)
7430             (/= article (cdr gnus-article-current))
7431             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7432         ;; Selected subject is different from current article's.
7433         (gnus-summary-display-article article)
7434       (gnus-summary-recenter)
7435       (when article-window
7436         (gnus-eval-in-buffer-window gnus-article-buffer
7437           (setq endp (gnus-article-prev-page lines)))
7438         (when (and move endp)
7439           (cond (lines
7440                  (gnus-message 3 "Beginning of message"))
7441                 ((null lines)
7442                  (if (and (eq gnus-summary-goto-unread 'never)
7443                           (not (gnus-summary-first-article-p article)))
7444                      (gnus-summary-prev-article)
7445                    (gnus-summary-prev-unread-article))))))))
7446   (gnus-summary-position-point))
7447
7448 (defun gnus-summary-prev-page-or-article (&optional lines)
7449   "Show previous page of selected article.
7450 Argument LINES specifies lines to be scrolled down.
7451 If at the beginning of the article, go to the next article."
7452   (interactive "P")
7453   (gnus-summary-prev-page lines t))
7454
7455 (defun gnus-summary-scroll-up (lines)
7456   "Scroll up (or down) one line current article.
7457 Argument LINES specifies lines to be scrolled up (or down if negative)."
7458   (interactive "p")
7459   (gnus-configure-windows 'article)
7460   (gnus-summary-show-thread)
7461   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7462     (gnus-eval-in-buffer-window gnus-article-buffer
7463       (cond ((> lines 0)
7464              (when (gnus-article-next-page lines)
7465                (gnus-message 3 "End of message")))
7466             ((< lines 0)
7467              (gnus-article-prev-page (- lines))))))
7468   (gnus-summary-recenter)
7469   (gnus-summary-position-point))
7470
7471 (defun gnus-summary-scroll-down (lines)
7472   "Scroll down (or up) one line current article.
7473 Argument LINES specifies lines to be scrolled down (or up if negative)."
7474   (interactive "p")
7475   (gnus-summary-scroll-up (- lines)))
7476
7477 (defun gnus-summary-next-same-subject ()
7478   "Select next article which has the same subject as current one."
7479   (interactive)
7480   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7481
7482 (defun gnus-summary-prev-same-subject ()
7483   "Select previous article which has the same subject as current one."
7484   (interactive)
7485   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7486
7487 (defun gnus-summary-next-unread-same-subject ()
7488   "Select next unread article which has the same subject as current one."
7489   (interactive)
7490   (gnus-summary-next-article t (gnus-summary-article-subject)))
7491
7492 (defun gnus-summary-prev-unread-same-subject ()
7493   "Select previous unread article which has the same subject as current one."
7494   (interactive)
7495   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7496
7497 (defun gnus-summary-first-unread-article ()
7498   "Select the first unread article.
7499 Return nil if there are no unread articles."
7500   (interactive)
7501   (prog1
7502       (when (gnus-summary-first-subject t)
7503         (gnus-summary-show-thread)
7504         (gnus-summary-first-subject t)
7505         (gnus-summary-display-article (gnus-summary-article-number)))
7506     (gnus-summary-position-point)))
7507
7508 (defun gnus-summary-first-unread-subject ()
7509   "Place the point on the subject line of the first unread article.
7510 Return nil if there are no unread articles."
7511   (interactive)
7512   (prog1
7513       (when (gnus-summary-first-subject t)
7514         (gnus-summary-show-thread)
7515         (gnus-summary-first-subject t))
7516     (gnus-summary-position-point)))
7517
7518 (defun gnus-summary-first-unseen-subject ()
7519   "Place the point on the subject line of the first unseen article.
7520 Return nil if there are no unseen articles."
7521   (interactive)
7522   (prog1
7523       (when (gnus-summary-first-subject nil nil t)
7524         (gnus-summary-show-thread)
7525         (gnus-summary-first-subject nil nil t))
7526     (gnus-summary-position-point)))
7527
7528 (defun gnus-summary-first-unseen-or-unread-subject ()
7529   "Place the point on the subject line of the first unseen article or,
7530 if all article have been seen, on the subject line of the first unread
7531 article."
7532   (interactive)
7533   (prog1
7534       (unless (when (gnus-summary-first-subject nil nil t)
7535                 (gnus-summary-show-thread)
7536                 (gnus-summary-first-subject nil nil t))
7537         (when (gnus-summary-first-subject t)
7538           (gnus-summary-show-thread)
7539           (gnus-summary-first-subject t)))
7540     (gnus-summary-position-point)))
7541
7542 (defun gnus-summary-first-article ()
7543   "Select the first article.
7544 Return nil if there are no articles."
7545   (interactive)
7546   (prog1
7547       (when (gnus-summary-first-subject)
7548         (gnus-summary-show-thread)
7549         (gnus-summary-first-subject)
7550         (gnus-summary-display-article (gnus-summary-article-number)))
7551     (gnus-summary-position-point)))
7552
7553 (defun gnus-summary-best-unread-article (&optional arg)
7554   "Select the unread article with the highest score.
7555 If given a prefix argument, select the next unread article that has a
7556 score higher than the default score."
7557   (interactive "P")
7558   (let ((article (if arg
7559                      (gnus-summary-better-unread-subject)
7560                    (gnus-summary-best-unread-subject))))
7561     (if article
7562         (gnus-summary-goto-article article)
7563       (error "No unread articles"))))
7564
7565 (defun gnus-summary-best-unread-subject ()
7566   "Select the unread subject with the highest score."
7567   (interactive)
7568   (let ((best -1000000)
7569         (data gnus-newsgroup-data)
7570         article score)
7571     (while data
7572       (and (gnus-data-unread-p (car data))
7573            (> (setq score
7574                     (gnus-summary-article-score (gnus-data-number (car data))))
7575               best)
7576            (setq best score
7577                  article (gnus-data-number (car data))))
7578       (setq data (cdr data)))
7579     (when article
7580       (gnus-summary-goto-subject article))
7581     (gnus-summary-position-point)
7582     article))
7583
7584 (defun gnus-summary-better-unread-subject ()
7585   "Select the first unread subject that has a score over the default score."
7586   (interactive)
7587   (let ((data gnus-newsgroup-data)
7588         article score)
7589     (while (and (setq article (gnus-data-number (car data)))
7590                 (or (gnus-data-read-p (car data))
7591                     (not (> (gnus-summary-article-score article)
7592                             gnus-summary-default-score))))
7593       (setq data (cdr data)))
7594     (when article
7595       (gnus-summary-goto-subject article))
7596     (gnus-summary-position-point)
7597     article))
7598
7599 (defun gnus-summary-last-subject ()
7600   "Go to the last displayed subject line in the group."
7601   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7602     (when article
7603       (gnus-summary-goto-subject article))))
7604
7605 (defun gnus-summary-goto-article (article &optional all-headers force)
7606   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7607 If ALL-HEADERS is non-nil, no header lines are hidden.
7608 If FORCE, go to the article even if it isn't displayed.  If FORCE
7609 is a number, it is the line the article is to be displayed on."
7610   (interactive
7611    (list
7612     (completing-read
7613      "Article number or Message-ID: "
7614      (mapcar (lambda (number) (list (int-to-string number)))
7615              gnus-newsgroup-limit))
7616     current-prefix-arg
7617     t))
7618   (prog1
7619       (if (and (stringp article)
7620                (string-match "@\\|%40" article))
7621           (gnus-summary-refer-article article)
7622         (when (stringp article)
7623           (setq article (string-to-number article)))
7624         (if (gnus-summary-goto-subject article force)
7625             (gnus-summary-display-article article all-headers)
7626           (gnus-message 4 "Couldn't go to article %s" article) nil))
7627     (gnus-summary-position-point)))
7628
7629 (defun gnus-summary-goto-last-article ()
7630   "Go to the previously read article."
7631   (interactive)
7632   (prog1
7633       (when gnus-last-article
7634         (gnus-summary-goto-article gnus-last-article nil t))
7635     (gnus-summary-position-point)))
7636
7637 (defun gnus-summary-pop-article (number)
7638   "Pop one article off the history and go to the previous.
7639 NUMBER articles will be popped off."
7640   (interactive "p")
7641   (let (to)
7642     (setq gnus-newsgroup-history
7643           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7644     (if to
7645         (gnus-summary-goto-article (car to) nil t)
7646       (error "Article history empty")))
7647   (gnus-summary-position-point))
7648
7649 ;; Summary commands and functions for limiting the summary buffer.
7650
7651 (defun gnus-summary-limit-to-articles (n)
7652   "Limit the summary buffer to the next N articles.
7653 If not given a prefix, use the process marked articles instead."
7654   (interactive "P")
7655   (prog1
7656       (let ((articles (gnus-summary-work-articles n)))
7657         (setq gnus-newsgroup-processable nil)
7658         (gnus-summary-limit articles))
7659     (gnus-summary-position-point)))
7660
7661 (defun gnus-summary-pop-limit (&optional total)
7662   "Restore the previous limit.
7663 If given a prefix, remove all limits."
7664   (interactive "P")
7665   (when total
7666     (setq gnus-newsgroup-limits
7667           (list (mapcar (lambda (h) (mail-header-number h))
7668                         gnus-newsgroup-headers))))
7669   (unless gnus-newsgroup-limits
7670     (error "No limit to pop"))
7671   (prog1
7672       (gnus-summary-limit nil 'pop)
7673     (gnus-summary-position-point)))
7674
7675 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7676   "Limit the summary buffer to articles that have subjects that match a regexp.
7677 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7678   (interactive
7679    (list (read-string (if current-prefix-arg
7680                           "Exclude subject (regexp): "
7681                         "Limit to subject (regexp): "))
7682          nil current-prefix-arg))
7683   (unless header
7684     (setq header "subject"))
7685   (when (not (equal "" subject))
7686     (prog1
7687         (let ((articles (gnus-summary-find-matching
7688                          (or header "subject") subject 'all nil nil
7689                          not-matching)))
7690           (unless articles
7691             (error "Found no matches for \"%s\"" subject))
7692           (gnus-summary-limit articles))
7693       (gnus-summary-position-point))))
7694
7695 (defun gnus-summary-limit-to-author (from &optional not-matching)
7696   "Limit the summary buffer to articles that have authors that match a regexp.
7697 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7698   (interactive
7699    (list (read-string (if current-prefix-arg
7700                           "Exclude author (regexp): "
7701                         "Limit to author (regexp): "))
7702          current-prefix-arg))
7703   (gnus-summary-limit-to-subject from "from" not-matching))
7704
7705 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7706   "Limit the summary buffer to articles with the given RECIPIENT.
7707
7708 If NOT-MATCHING, exclude RECIPIENT.
7709
7710 To and Cc headers are checked.  You need to include them in
7711 `nnmail-extra-headers'."
7712   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7713   (interactive
7714    (list (read-string (format "%s recipient (regexp): "
7715                               (if current-prefix-arg "Exclude" "Limit to")))
7716          current-prefix-arg))
7717   (when (not (equal "" recipient))
7718     (prog1 (let* ((to
7719                    (if (memq 'To nnmail-extra-headers)
7720                        (gnus-summary-find-matching
7721                         (cons 'extra 'To) recipient 'all nil nil
7722                         not-matching)
7723                      (gnus-message
7724                       1 "`To' isn't present in `nnmail-extra-headers'")
7725                      (sit-for 1)
7726                      nil))
7727                   (cc
7728                    (if (memq 'Cc nnmail-extra-headers)
7729                        (gnus-summary-find-matching
7730                         (cons 'extra 'Cc) recipient 'all nil nil
7731                         not-matching)
7732                      (gnus-message
7733                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7734                      (sit-for 1)
7735                      nil))
7736                   (articles
7737                    (if not-matching
7738                        ;; We need the numbers that are in both lists:
7739                        (mapcar (lambda (a)
7740                                  (and (memq a to) a))
7741                                cc)
7742                      (nconc to cc))))
7743              (unless articles
7744                (error "Found no matches for \"%s\"" recipient))
7745              (gnus-summary-limit articles))
7746       (gnus-summary-position-point))))
7747
7748 (defun gnus-summary-limit-to-age (age &optional younger-p)
7749   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7750 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7751 articles that are younger than AGE days."
7752   (interactive
7753    (let ((younger current-prefix-arg)
7754          (days-got nil)
7755          days)
7756      (while (not days-got)
7757        (setq days (if younger
7758                       (read-string "Limit to articles younger than (in days, older when negative): ")
7759                     (read-string
7760                      "Limit to articles older than (in days, younger when negative): ")))
7761        (when (> (length days) 0)
7762          (setq days (read days)))
7763        (if (numberp days)
7764            (progn
7765              (setq days-got t)
7766              (when (< days 0)
7767                (setq younger (not younger))
7768                (setq days (* days -1))))
7769          (message "Please enter a number.")
7770          (sleep-for 1)))
7771      (list days younger)))
7772   (prog1
7773       (let ((data gnus-newsgroup-data)
7774             (cutoff (days-to-time age))
7775             articles d date is-younger)
7776         (while (setq d (pop data))
7777           (when (and (vectorp (gnus-data-header d))
7778                      (setq date (mail-header-date (gnus-data-header d))))
7779             (setq is-younger (time-less-p
7780                               (time-since (condition-case ()
7781                                               (date-to-time date)
7782                                             (error '(0 0))))
7783                               cutoff))
7784             (when (if younger-p
7785                       is-younger
7786                     (not is-younger))
7787               (push (gnus-data-number d) articles))))
7788         (gnus-summary-limit (nreverse articles)))
7789     (gnus-summary-position-point)))
7790
7791 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7792   "Limit the summary buffer to articles that match an 'extra' header."
7793   (interactive
7794    (let ((header
7795           (intern
7796            (gnus-completing-read-with-default
7797             (symbol-name (car gnus-extra-headers))
7798             (if current-prefix-arg
7799                 "Exclude extra header:"
7800               "Limit extra header:")
7801             (mapcar (lambda (x)
7802                       (cons (symbol-name x) x))
7803                     gnus-extra-headers)
7804             nil
7805             t))))
7806      (list header
7807            (read-string (format "%s header %s (regexp): "
7808                                 (if current-prefix-arg "Exclude" "Limit to")
7809                                 header))
7810            current-prefix-arg)))
7811   (when (not (equal "" regexp))
7812     (prog1
7813         (let ((articles (gnus-summary-find-matching
7814                          (cons 'extra header) regexp 'all nil nil
7815                          not-matching)))
7816           (unless articles
7817             (error "Found no matches for \"%s\"" regexp))
7818           (gnus-summary-limit articles))
7819       (gnus-summary-position-point))))
7820
7821 (defun gnus-summary-limit-to-display-predicate ()
7822   "Limit the summary buffer to the predicated in the `display' group parameter."
7823   (interactive)
7824   (unless gnus-newsgroup-display
7825     (error "There is no `display' group parameter"))
7826   (let (articles)
7827     (dolist (number gnus-newsgroup-articles)
7828       (when (funcall gnus-newsgroup-display)
7829         (push number articles)))
7830     (gnus-summary-limit articles))
7831   (gnus-summary-position-point))
7832
7833 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7834 (make-obsolete
7835  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7836
7837 (defun gnus-summary-limit-to-unread (&optional all)
7838   "Limit the summary buffer to articles that are not marked as read.
7839 If ALL is non-nil, limit strictly to unread articles."
7840   (interactive "P")
7841   (if all
7842       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7843     (gnus-summary-limit-to-marks
7844      ;; Concat all the marks that say that an article is read and have
7845      ;; those removed.
7846      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7847            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7848            gnus-low-score-mark gnus-expirable-mark
7849            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7850            gnus-duplicate-mark gnus-souped-mark)
7851      'reverse)))
7852
7853 (defun gnus-summary-limit-to-replied (&optional unreplied)
7854   "Limit the summary buffer to replied articles.
7855 If UNREPLIED (the prefix), limit to unreplied articles."
7856   (interactive "P")
7857   (if unreplied
7858       (gnus-summary-limit
7859        (gnus-set-difference gnus-newsgroup-articles
7860         gnus-newsgroup-replied))
7861     (gnus-summary-limit gnus-newsgroup-replied))
7862   (gnus-summary-position-point))
7863
7864 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7865 (make-obsolete 'gnus-summary-delete-marked-with
7866                'gnus-summary-limit-exclude-marks)
7867
7868 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7869   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7870 If REVERSE, limit the summary buffer to articles that are marked
7871 with MARKS.  MARKS can either be a string of marks or a list of marks.
7872 Returns how many articles were removed."
7873   (interactive "sMarks: ")
7874   (gnus-summary-limit-to-marks marks t))
7875
7876 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7877   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7878 If REVERSE (the prefix), limit the summary buffer to articles that are
7879 not marked with MARKS.  MARKS can either be a string of marks or a
7880 list of marks.
7881 Returns how many articles were removed."
7882   (interactive "sMarks: \nP")
7883   (prog1
7884       (let ((data gnus-newsgroup-data)
7885             (marks (if (listp marks) marks
7886                      (append marks nil))) ; Transform to list.
7887             articles)
7888         (while data
7889           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7890                   (memq (gnus-data-mark (car data)) marks))
7891             (push (gnus-data-number (car data)) articles))
7892           (setq data (cdr data)))
7893         (gnus-summary-limit articles))
7894     (gnus-summary-position-point)))
7895
7896 (defun gnus-summary-limit-to-score (score)
7897   "Limit to articles with score at or above SCORE."
7898   (interactive "NLimit to articles with score of at least: ")
7899   (let ((data gnus-newsgroup-data)
7900         articles)
7901     (while data
7902       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7903                 score)
7904         (push (gnus-data-number (car data)) articles))
7905       (setq data (cdr data)))
7906     (prog1
7907         (gnus-summary-limit articles)
7908       (gnus-summary-position-point))))
7909
7910 (defun gnus-summary-limit-to-unseen ()
7911   "Limit to unseen articles."
7912   (interactive)
7913   (prog1
7914       (gnus-summary-limit gnus-newsgroup-unseen)
7915     (gnus-summary-position-point)))
7916
7917 (defun gnus-summary-limit-include-thread (id)
7918   "Display all the hidden articles that is in the thread with ID in it.
7919 When called interactively, ID is the Message-ID of the current
7920 article."
7921   (interactive (list (mail-header-id (gnus-summary-article-header))))
7922   (let ((articles (gnus-articles-in-thread
7923                    (gnus-id-to-thread (gnus-root-id id)))))
7924     (prog1
7925         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7926       (gnus-summary-limit-include-matching-articles
7927        "subject"
7928        (regexp-quote (gnus-simplify-subject-re
7929                       (mail-header-subject (gnus-id-to-header id)))))
7930       (gnus-summary-position-point))))
7931
7932 (defun gnus-summary-limit-include-matching-articles (header regexp)
7933   "Display all the hidden articles that have HEADERs that match REGEXP."
7934   (interactive (list (read-string "Match on header: ")
7935                      (read-string "Regexp: ")))
7936   (let ((articles (gnus-find-matching-articles header regexp)))
7937     (prog1
7938         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7939       (gnus-summary-position-point))))
7940
7941 (defun gnus-summary-insert-dormant-articles ()
7942   "Insert all the dormant articles for this group into the current buffer."
7943   (interactive)
7944   (let ((gnus-verbose (max 6 gnus-verbose)))
7945     (if (not gnus-newsgroup-dormant)
7946         (gnus-message 3 "No cached articles for this group")
7947       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7948
7949 (defun gnus-summary-limit-include-dormant ()
7950   "Display all the hidden articles that are marked as dormant.
7951 Note that this command only works on a subset of the articles currently
7952 fetched for this group."
7953   (interactive)
7954   (unless gnus-newsgroup-dormant
7955     (error "There are no dormant articles in this group"))
7956   (prog1
7957       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7958     (gnus-summary-position-point)))
7959
7960 (defun gnus-summary-limit-exclude-dormant ()
7961   "Hide all dormant articles."
7962   (interactive)
7963   (prog1
7964       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7965     (gnus-summary-position-point)))
7966
7967 (defun gnus-summary-limit-exclude-childless-dormant ()
7968   "Hide all dormant articles that have no children."
7969   (interactive)
7970   (let ((data (gnus-data-list t))
7971         articles d children)
7972     ;; Find all articles that are either not dormant or have
7973     ;; children.
7974     (while (setq d (pop data))
7975       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7976                 (and (setq children
7977                            (gnus-article-children (gnus-data-number d)))
7978                      (let (found)
7979                        (while children
7980                          (when (memq (car children) articles)
7981                            (setq children nil
7982                                  found t))
7983                          (pop children))
7984                        found)))
7985         (push (gnus-data-number d) articles)))
7986     ;; Do the limiting.
7987     (prog1
7988         (gnus-summary-limit articles)
7989       (gnus-summary-position-point))))
7990
7991 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7992   "Mark all unread excluded articles as read.
7993 If ALL, mark even excluded ticked and dormants as read."
7994   (interactive "P")
7995   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7996   (let ((articles (gnus-sorted-ndifference
7997                    (sort
7998                     (mapcar (lambda (h) (mail-header-number h))
7999                             gnus-newsgroup-headers)
8000                     '<)
8001                    gnus-newsgroup-limit))
8002         article)
8003     (setq gnus-newsgroup-unreads
8004           (gnus-sorted-intersection gnus-newsgroup-unreads
8005                                     gnus-newsgroup-limit))
8006     (if all
8007         (setq gnus-newsgroup-dormant nil
8008               gnus-newsgroup-marked nil
8009               gnus-newsgroup-reads
8010               (nconc
8011                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8012                gnus-newsgroup-reads))
8013       (while (setq article (pop articles))
8014         (unless (or (memq article gnus-newsgroup-dormant)
8015                     (memq article gnus-newsgroup-marked))
8016           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8017
8018 (defun gnus-summary-limit (articles &optional pop)
8019   (if pop
8020       ;; We pop the previous limit off the stack and use that.
8021       (setq articles (car gnus-newsgroup-limits)
8022             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8023     ;; We use the new limit, so we push the old limit on the stack.
8024     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8025   ;; Set the limit.
8026   (setq gnus-newsgroup-limit articles)
8027   (let ((total (length gnus-newsgroup-data))
8028         (data (gnus-data-find-list (gnus-summary-article-number)))
8029         (gnus-summary-mark-below nil)   ; Inhibit this.
8030         found)
8031     ;; This will do all the work of generating the new summary buffer
8032     ;; according to the new limit.
8033     (gnus-summary-prepare)
8034     ;; Hide any threads, possibly.
8035     (gnus-summary-maybe-hide-threads)
8036     ;; Try to return to the article you were at, or one in the
8037     ;; neighborhood.
8038     (when data
8039       ;; We try to find some article after the current one.
8040       (while data
8041         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8042           (setq data nil
8043                 found t))
8044         (setq data (cdr data))))
8045     (unless found
8046       ;; If there is no data, that means that we were after the last
8047       ;; article.  The same goes when we can't find any articles
8048       ;; after the current one.
8049       (goto-char (point-max))
8050       (gnus-summary-find-prev))
8051     (gnus-set-mode-line 'summary)
8052     ;; We return how many articles were removed from the summary
8053     ;; buffer as a result of the new limit.
8054     (- total (length gnus-newsgroup-data))))
8055
8056 (defsubst gnus-invisible-cut-children (threads)
8057   (let ((num 0))
8058     (while threads
8059       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8060         (incf num))
8061       (pop threads))
8062     (< num 2)))
8063
8064 (defsubst gnus-cut-thread (thread)
8065   "Go forwards in the thread until we find an article that we want to display."
8066   (when (or (eq gnus-fetch-old-headers 'some)
8067             (eq gnus-fetch-old-headers 'invisible)
8068             (numberp gnus-fetch-old-headers)
8069             (eq gnus-build-sparse-threads 'some)
8070             (eq gnus-build-sparse-threads 'more))
8071     ;; Deal with old-fetched headers and sparse threads.
8072     (while (and
8073             thread
8074             (or
8075              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8076              (gnus-summary-article-ancient-p
8077               (mail-header-number (car thread))))
8078             (if (or (<= (length (cdr thread)) 1)
8079                     (eq gnus-fetch-old-headers 'invisible))
8080                 (setq gnus-newsgroup-limit
8081                       (delq (mail-header-number (car thread))
8082                             gnus-newsgroup-limit)
8083                       thread (cadr thread))
8084               (when (gnus-invisible-cut-children (cdr thread))
8085                 (let ((th (cdr thread)))
8086                   (while th
8087                     (if (memq (mail-header-number (caar th))
8088                               gnus-newsgroup-limit)
8089                         (setq thread (car th)
8090                               th nil)
8091                       (setq th (cdr th))))))))))
8092   thread)
8093
8094 (defun gnus-cut-threads (threads)
8095   "Cut off all uninteresting articles from the beginning of THREADS."
8096   (when (or (eq gnus-fetch-old-headers 'some)
8097             (eq gnus-fetch-old-headers 'invisible)
8098             (numberp gnus-fetch-old-headers)
8099             (eq gnus-build-sparse-threads 'some)
8100             (eq gnus-build-sparse-threads 'more))
8101     (let ((th threads))
8102       (while th
8103         (setcar th (gnus-cut-thread (car th)))
8104         (setq th (cdr th)))))
8105   ;; Remove nixed out threads.
8106   (delq nil threads))
8107
8108 (defun gnus-summary-initial-limit (&optional show-if-empty)
8109   "Figure out what the initial limit is supposed to be on group entry.
8110 This entails weeding out unwanted dormants, low-scored articles,
8111 fetch-old-headers verbiage, and so on."
8112   ;; Most groups have nothing to remove.
8113   (if (or gnus-inhibit-limiting
8114           (and (null gnus-newsgroup-dormant)
8115                (eq gnus-newsgroup-display 'gnus-not-ignore)
8116                (not (eq gnus-fetch-old-headers 'some))
8117                (not (numberp gnus-fetch-old-headers))
8118                (not (eq gnus-fetch-old-headers 'invisible))
8119                (null gnus-summary-expunge-below)
8120                (not (eq gnus-build-sparse-threads 'some))
8121                (not (eq gnus-build-sparse-threads 'more))
8122                (null gnus-thread-expunge-below)
8123                (not gnus-use-nocem)))
8124       ()                                ; Do nothing.
8125     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8126     (setq gnus-newsgroup-limit nil)
8127     (mapatoms
8128      (lambda (node)
8129        (unless (car (symbol-value node))
8130          ;; These threads have no parents -- they are roots.
8131          (let ((nodes (cdr (symbol-value node)))
8132                thread)
8133            (while nodes
8134              (if (and gnus-thread-expunge-below
8135                       (< (gnus-thread-total-score (car nodes))
8136                          gnus-thread-expunge-below))
8137                  (gnus-expunge-thread (pop nodes))
8138                (setq thread (pop nodes))
8139                (gnus-summary-limit-children thread))))))
8140      gnus-newsgroup-dependencies)
8141     ;; If this limitation resulted in an empty group, we might
8142     ;; pop the previous limit and use it instead.
8143     (when (and (not gnus-newsgroup-limit)
8144                show-if-empty)
8145       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8146     gnus-newsgroup-limit))
8147
8148 (defun gnus-summary-limit-children (thread)
8149   "Return 1 if this subthread is visible and 0 if it is not."
8150   ;; First we get the number of visible children to this thread.  This
8151   ;; is done by recursing down the thread using this function, so this
8152   ;; will really go down to a leaf article first, before slowly
8153   ;; working its way up towards the root.
8154   (when thread
8155     (let* ((max-lisp-eval-depth 5000)
8156            (children
8157            (if (cdr thread)
8158                (apply '+ (mapcar 'gnus-summary-limit-children
8159                                  (cdr thread)))
8160              0))
8161           (number (mail-header-number (car thread)))
8162           score)
8163       (if (and
8164            (not (memq number gnus-newsgroup-marked))
8165            (or
8166             ;; If this article is dormant and has absolutely no visible
8167             ;; children, then this article isn't visible.
8168             (and (memq number gnus-newsgroup-dormant)
8169                  (zerop children))
8170             ;; If this is "fetch-old-headered" and there is no
8171             ;; visible children, then we don't want this article.
8172             (and (or (eq gnus-fetch-old-headers 'some)
8173                      (numberp gnus-fetch-old-headers))
8174                  (gnus-summary-article-ancient-p number)
8175                  (zerop children))
8176             ;; If this is "fetch-old-headered" and `invisible', then
8177             ;; we don't want this article.
8178             (and (eq gnus-fetch-old-headers 'invisible)
8179                  (gnus-summary-article-ancient-p number))
8180             ;; If this is a sparsely inserted article with no children,
8181             ;; we don't want it.
8182             (and (eq gnus-build-sparse-threads 'some)
8183                  (gnus-summary-article-sparse-p number)
8184                  (zerop children))
8185             ;; If we use expunging, and this article is really
8186             ;; low-scored, then we don't want this article.
8187             (when (and gnus-summary-expunge-below
8188                        (< (setq score
8189                                 (or (cdr (assq number gnus-newsgroup-scored))
8190                                     gnus-summary-default-score))
8191                           gnus-summary-expunge-below))
8192               ;; We increase the expunge-tally here, but that has
8193               ;; nothing to do with the limits, really.
8194               (incf gnus-newsgroup-expunged-tally)
8195               ;; We also mark as read here, if that's wanted.
8196               (when (and gnus-summary-mark-below
8197                          (< score gnus-summary-mark-below))
8198                 (setq gnus-newsgroup-unreads
8199                       (delq number gnus-newsgroup-unreads))
8200                 (if gnus-newsgroup-auto-expire
8201                     (push number gnus-newsgroup-expirable)
8202                   (push (cons number gnus-low-score-mark)
8203                         gnus-newsgroup-reads)))
8204               t)
8205             ;; Do the `display' group parameter.
8206             (and gnus-newsgroup-display
8207                  (not (funcall gnus-newsgroup-display)))
8208             ;; Check NoCeM things.
8209             (when (and gnus-use-nocem
8210                        (gnus-nocem-unwanted-article-p
8211                         (mail-header-id (car thread))))
8212               (setq gnus-newsgroup-unreads
8213                     (delq number gnus-newsgroup-unreads))
8214               t)))
8215           ;; Nope, invisible article.
8216           0
8217         ;; Ok, this article is to be visible, so we add it to the limit
8218         ;; and return 1.
8219         (push number gnus-newsgroup-limit)
8220         1))))
8221
8222 (defun gnus-expunge-thread (thread)
8223   "Mark all articles in THREAD as read."
8224   (let* ((number (mail-header-number (car thread))))
8225     (incf gnus-newsgroup-expunged-tally)
8226     ;; We also mark as read here, if that's wanted.
8227     (setq gnus-newsgroup-unreads
8228           (delq number gnus-newsgroup-unreads))
8229     (if gnus-newsgroup-auto-expire
8230         (push number gnus-newsgroup-expirable)
8231       (push (cons number gnus-low-score-mark)
8232             gnus-newsgroup-reads)))
8233   ;; Go recursively through all subthreads.
8234   (mapcar 'gnus-expunge-thread (cdr thread)))
8235
8236 ;; Summary article oriented commands
8237
8238 (defun gnus-summary-refer-parent-article (n)
8239   "Refer parent article N times.
8240 If N is negative, go to ancestor -N instead.
8241 The difference between N and the number of articles fetched is returned."
8242   (interactive "p")
8243   (let ((skip 1)
8244         error header ref)
8245     (when (not (natnump n))
8246       (setq skip (abs n)
8247             n 1))
8248     (while (and (> n 0)
8249                 (not error))
8250       (setq header (gnus-summary-article-header))
8251       (if (and (eq (mail-header-number header)
8252                    (cdr gnus-article-current))
8253                (equal gnus-newsgroup-name
8254                       (car gnus-article-current)))
8255           ;; If we try to find the parent of the currently
8256           ;; displayed article, then we take a look at the actual
8257           ;; References header, since this is slightly more
8258           ;; reliable than the References field we got from the
8259           ;; server.
8260           (save-excursion
8261             (set-buffer gnus-original-article-buffer)
8262             (nnheader-narrow-to-headers)
8263             (unless (setq ref (message-fetch-field "references"))
8264               (when (setq ref (message-fetch-field "in-reply-to"))
8265                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8266             (widen))
8267         (setq ref
8268               ;; It's not the current article, so we take a bet on
8269               ;; the value we got from the server.
8270               (mail-header-references header)))
8271       (if (and ref
8272                (not (equal ref "")))
8273           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8274             (gnus-message 1 "Couldn't find parent"))
8275         (gnus-message 1 "No references in article %d"
8276                       (gnus-summary-article-number))
8277         (setq error t))
8278       (decf n))
8279     (gnus-summary-position-point)
8280     n))
8281
8282 (defun gnus-summary-refer-references ()
8283   "Fetch all articles mentioned in the References header.
8284 Return the number of articles fetched."
8285   (interactive)
8286   (let ((ref (mail-header-references (gnus-summary-article-header)))
8287         (current (gnus-summary-article-number))
8288         (n 0))
8289     (if (or (not ref)
8290             (equal ref ""))
8291         (error "No References in the current article")
8292       ;; For each Message-ID in the References header...
8293       (while (string-match "<[^>]*>" ref)
8294         (incf n)
8295         ;; ... fetch that article.
8296         (gnus-summary-refer-article
8297          (prog1 (match-string 0 ref)
8298            (setq ref (substring ref (match-end 0))))))
8299       (gnus-summary-goto-subject current)
8300       (gnus-summary-position-point)
8301       n)))
8302
8303 (defun gnus-summary-refer-thread (&optional limit)
8304   "Fetch all articles in the current thread.
8305 If LIMIT (the numerical prefix), fetch that many old headers instead
8306 of what's specified by the `gnus-refer-thread-limit' variable."
8307   (interactive "P")
8308   (let ((id (mail-header-id (gnus-summary-article-header)))
8309         (limit (if limit (prefix-numeric-value limit)
8310                  gnus-refer-thread-limit)))
8311     (unless (eq gnus-fetch-old-headers 'invisible)
8312       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8313       ;; Retrieve the headers and read them in.
8314       (if (eq (if (numberp limit)
8315                   (gnus-retrieve-headers
8316                    (list (min
8317                           (+ (mail-header-number
8318                               (gnus-summary-article-header))
8319                              limit)
8320                           gnus-newsgroup-end))
8321                    gnus-newsgroup-name (* limit 2))
8322                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8323                 ;; headers.
8324                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8325                                        gnus-newsgroup-name limit))
8326               'nov)
8327           (gnus-build-all-threads)
8328         (error "Can't fetch thread from back ends that don't support NOV"))
8329       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8330     (gnus-summary-limit-include-thread id)))
8331
8332 (defun gnus-summary-refer-article (message-id)
8333   "Fetch an article specified by MESSAGE-ID."
8334   (interactive "sMessage-ID: ")
8335   (when (and (stringp message-id)
8336              (not (zerop (length message-id))))
8337     (setq message-id (gnus-replace-in-string message-id " " ""))
8338     ;; Construct the correct Message-ID if necessary.
8339     ;; Suggested by tale@pawl.rpi.edu.
8340     (unless (string-match "^<" message-id)
8341       (setq message-id (concat "<" message-id)))
8342     (unless (string-match ">$" message-id)
8343       (setq message-id (concat message-id ">")))
8344     ;; People often post MIDs from URLs, so unhex it:
8345     (unless (string-match "@" message-id)
8346       (setq message-id (gnus-url-unhex-string message-id)))
8347     (let* ((header (gnus-id-to-header message-id))
8348            (sparse (and header
8349                         (gnus-summary-article-sparse-p
8350                          (mail-header-number header))
8351                         (memq (mail-header-number header)
8352                               gnus-newsgroup-limit)))
8353            number)
8354       (cond
8355        ;; If the article is present in the buffer we just go to it.
8356        ((and header
8357              (or (not (gnus-summary-article-sparse-p
8358                        (mail-header-number header)))
8359                  sparse))
8360         (prog1
8361             (gnus-summary-goto-article
8362              (mail-header-number header) nil t)
8363           (when sparse
8364             (gnus-summary-update-article (mail-header-number header)))))
8365        (t
8366         ;; We fetch the article.
8367         (catch 'found
8368           (dolist (gnus-override-method (gnus-refer-article-methods))
8369             (when (and (gnus-check-server gnus-override-method)
8370                        ;; Fetch the header,
8371                        (setq number (gnus-summary-insert-subject message-id)))
8372               ;; and display the article.
8373               (gnus-summary-select-article nil nil nil number)
8374               (throw 'found t)))
8375           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8376
8377 (defun gnus-refer-article-methods ()
8378   "Return a list of referable methods."
8379   (cond
8380    ;; No method, so we default to current and native.
8381    ((null gnus-refer-article-method)
8382     (list gnus-current-select-method gnus-select-method))
8383    ;; Current.
8384    ((eq 'current gnus-refer-article-method)
8385     (list gnus-current-select-method))
8386    ;; List of select methods.
8387    ((not (and (symbolp (car gnus-refer-article-method))
8388               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8389     (let (out)
8390       (dolist (method gnus-refer-article-method)
8391         (push (if (eq 'current method)
8392                   gnus-current-select-method
8393                 method)
8394               out))
8395       (nreverse out)))
8396    ;; One single select method.
8397    (t
8398     (list gnus-refer-article-method))))
8399
8400 (defun gnus-summary-edit-parameters ()
8401   "Edit the group parameters of the current group."
8402   (interactive)
8403   (gnus-group-edit-group gnus-newsgroup-name 'params))
8404
8405 (defun gnus-summary-customize-parameters ()
8406   "Customize the group parameters of the current group."
8407   (interactive)
8408   (gnus-group-customize gnus-newsgroup-name))
8409
8410 (defun gnus-summary-enter-digest-group (&optional force)
8411   "Enter an nndoc group based on the current article.
8412 If FORCE, force a digest interpretation.  If not, try
8413 to guess what the document format is."
8414   (interactive "P")
8415   (let ((conf gnus-current-window-configuration))
8416     (save-window-excursion
8417       (save-excursion
8418         (let (gnus-article-prepare-hook
8419               gnus-display-mime-function
8420               gnus-break-pages)
8421           (gnus-summary-select-article))))
8422     (setq gnus-current-window-configuration conf)
8423     (let* ((name (format "%s-%d"
8424                          (gnus-group-prefixed-name
8425                           gnus-newsgroup-name (list 'nndoc ""))
8426                          (with-current-buffer gnus-summary-buffer
8427                            gnus-current-article)))
8428            (ogroup gnus-newsgroup-name)
8429            (params (append (gnus-info-params (gnus-get-info ogroup))
8430                            (list (cons 'to-group ogroup))
8431                            (list (cons 'parent-group ogroup))
8432                            (list (cons 'save-article-group ogroup))))
8433            (case-fold-search t)
8434            (buf (current-buffer))
8435            dig to-address)
8436       (save-excursion
8437         (set-buffer gnus-original-article-buffer)
8438         ;; Have the digest group inherit the main mail address of
8439         ;; the parent article.
8440         (when (setq to-address (or (gnus-fetch-field "reply-to")
8441                                    (gnus-fetch-field "from")))
8442           (setq params (append
8443                         (list (cons 'to-address
8444                                     (funcall gnus-decode-encoded-word-function
8445                                              to-address))))))
8446         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8447         (insert-buffer-substring gnus-original-article-buffer)
8448         ;; Remove lines that may lead nndoc to misinterpret the
8449         ;; document type.
8450         (narrow-to-region
8451          (goto-char (point-min))
8452          (or (search-forward "\n\n" nil t) (point)))
8453         (goto-char (point-min))
8454         (delete-matching-lines "^Path:\\|^From ")
8455         (widen))
8456       (unwind-protect
8457           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8458                     (gnus-newsgroup-ephemeral-ignored-charsets
8459                      gnus-newsgroup-ignored-charsets))
8460                 (gnus-group-read-ephemeral-group
8461                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8462                               (nndoc-article-type
8463                                ,(if force 'mbox 'guess)))
8464                  t nil nil nil
8465                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8466                                                         "ADAPT")))))
8467               ;; Make all postings to this group go to the parent group.
8468               (nconc (gnus-info-params (gnus-get-info name))
8469                      params)
8470             ;; Couldn't select this doc group.
8471             (switch-to-buffer buf)
8472             (gnus-set-global-variables)
8473             (gnus-configure-windows 'summary)
8474             (gnus-message 3 "Article couldn't be entered?"))
8475         (kill-buffer dig)))))
8476
8477 (defun gnus-summary-read-document (n)
8478   "Open a new group based on the current article(s).
8479 This will allow you to read digests and other similar
8480 documents as newsgroups.
8481 Obeys the standard process/prefix convention."
8482   (interactive "P")
8483   (let* ((ogroup gnus-newsgroup-name)
8484          (params (append (gnus-info-params (gnus-get-info ogroup))
8485                          (list (cons 'to-group ogroup))))
8486          group egroup groups vgroup)
8487     (dolist (article (gnus-summary-work-articles n))
8488       (setq group (format "%s-%d" gnus-newsgroup-name article))
8489       (gnus-summary-remove-process-mark article)
8490       (when (gnus-summary-display-article article)
8491         (save-excursion
8492           (with-temp-buffer
8493             (insert-buffer-substring gnus-original-article-buffer)
8494             ;; Remove some headers that may lead nndoc to make
8495             ;; the wrong guess.
8496             (message-narrow-to-head)
8497             (goto-char (point-min))
8498             (delete-matching-lines "^Path:\\|^From ")
8499             (widen)
8500             (if (setq egroup
8501                       (gnus-group-read-ephemeral-group
8502                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8503                                      (nndoc-article-type guess))
8504                        t nil t))
8505                 (progn
8506             ;; Make all postings to this group go to the parent group.
8507                   (nconc (gnus-info-params (gnus-get-info egroup))
8508                          params)
8509                   (push egroup groups))
8510               ;; Couldn't select this doc group.
8511               (gnus-error 3 "Article couldn't be entered"))))))
8512     ;; Now we have selected all the documents.
8513     (cond
8514      ((not groups)
8515       (error "None of the articles could be interpreted as documents"))
8516      ((gnus-group-read-ephemeral-group
8517        (setq vgroup (format
8518                      "nnvirtual:%s-%s" gnus-newsgroup-name
8519                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8520        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8521        t
8522        (cons (current-buffer) 'summary)))
8523      (t
8524       (error "Couldn't select virtual nndoc group")))))
8525
8526 (defun gnus-summary-isearch-article (&optional regexp-p)
8527   "Do incremental search forward on the current article.
8528 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8529   (interactive "P")
8530   (gnus-summary-select-article)
8531   (gnus-configure-windows 'article)
8532   (gnus-eval-in-buffer-window gnus-article-buffer
8533     (save-restriction
8534       (widen)
8535       (isearch-forward regexp-p))))
8536
8537 (defun gnus-summary-search-article-forward (regexp &optional backward)
8538   "Search for an article containing REGEXP forward.
8539 If BACKWARD, search backward instead."
8540   (interactive
8541    (list (read-string
8542           (format "Search article %s (regexp%s): "
8543                   (if current-prefix-arg "backward" "forward")
8544                   (if gnus-last-search-regexp
8545                       (concat ", default " gnus-last-search-regexp)
8546                     "")))
8547          current-prefix-arg))
8548   (if (string-equal regexp "")
8549       (setq regexp (or gnus-last-search-regexp ""))
8550     (setq gnus-last-search-regexp regexp)
8551     (setq gnus-article-before-search gnus-current-article))
8552   ;; Intentionally set gnus-last-article.
8553   (setq gnus-last-article gnus-article-before-search)
8554   (let ((gnus-last-article gnus-last-article))
8555     (if (gnus-summary-search-article regexp backward)
8556         (gnus-summary-show-thread)
8557       (signal 'search-failed (list regexp)))))
8558
8559 (defun gnus-summary-search-article-backward (regexp)
8560   "Search for an article containing REGEXP backward."
8561   (interactive
8562    (list (read-string
8563           (format "Search article backward (regexp%s): "
8564                   (if gnus-last-search-regexp
8565                       (concat ", default " gnus-last-search-regexp)
8566                     "")))))
8567   (gnus-summary-search-article-forward regexp 'backward))
8568
8569 (defun gnus-summary-search-article (regexp &optional backward)
8570   "Search for an article containing REGEXP.
8571 Optional argument BACKWARD means do search for backward.
8572 `gnus-select-article-hook' is not called during the search."
8573   ;; We have to require this here to make sure that the following
8574   ;; dynamic binding isn't shadowed by autoloading.
8575   (require 'gnus-async)
8576   (require 'gnus-art)
8577   (let ((gnus-select-article-hook nil)  ;Disable hook.
8578         (gnus-article-prepare-hook nil)
8579         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8580         (gnus-use-article-prefetch nil)
8581         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8582         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8583         (gnus-visual nil)
8584         (gnus-keep-backlog nil)
8585         (gnus-break-pages nil)
8586         (gnus-summary-display-arrow nil)
8587         (gnus-updated-mode-lines nil)
8588         (gnus-auto-center-summary nil)
8589         (sum (current-buffer))
8590         (gnus-display-mime-function nil)
8591         (found nil)
8592         point)
8593     (gnus-save-hidden-threads
8594       (gnus-summary-select-article)
8595       (set-buffer gnus-article-buffer)
8596       (goto-char (window-point (get-buffer-window (current-buffer))))
8597       (when backward
8598         (forward-line -1))
8599       (while (not found)
8600         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8601         (if (if backward
8602                 (re-search-backward regexp nil t)
8603               (re-search-forward regexp nil t))
8604             ;; We found the regexp.
8605             (progn
8606               (setq found 'found)
8607               (beginning-of-line)
8608               (set-window-start
8609                (get-buffer-window (current-buffer))
8610                (point))
8611               (forward-line 1)
8612               (set-window-point
8613                (get-buffer-window (current-buffer))
8614                (point))
8615               (set-buffer sum)
8616               (setq point (point)))
8617           ;; We didn't find it, so we go to the next article.
8618           (set-buffer sum)
8619           (setq found 'not)
8620           (while (eq found 'not)
8621             (if (not (if backward (gnus-summary-find-prev)
8622                        (gnus-summary-find-next)))
8623                 ;; No more articles.
8624                 (setq found t)
8625               ;; Select the next article and adjust point.
8626               (unless (gnus-summary-article-sparse-p
8627                        (gnus-summary-article-number))
8628                 (setq found nil)
8629                 (gnus-summary-select-article)
8630                 (set-buffer gnus-article-buffer)
8631                 (widen)
8632                 (goto-char (if backward (point-max) (point-min))))))))
8633       (gnus-message 7 ""))
8634     ;; Return whether we found the regexp.
8635     (when (eq found 'found)
8636       (goto-char point)
8637       (gnus-summary-show-thread)
8638       (gnus-summary-goto-subject gnus-current-article)
8639       (gnus-summary-position-point)
8640       t)))
8641
8642 (defun gnus-find-matching-articles (header regexp)
8643   "Return a list of all articles that match REGEXP on HEADER.
8644 This search includes all articles in the current group that Gnus has
8645 fetched headers for, whether they are displayed or not."
8646   (let ((articles nil)
8647         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8648         (case-fold-search t))
8649     (dolist (header gnus-newsgroup-headers)
8650       (when (string-match regexp (funcall func header))
8651         (push (mail-header-number header) articles)))
8652     (nreverse articles)))
8653
8654 (defun gnus-summary-find-matching (header regexp &optional backward unread
8655                                           not-case-fold not-matching)
8656   "Return a list of all articles that match REGEXP on HEADER.
8657 The search stars on the current article and goes forwards unless
8658 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8659 If UNREAD is non-nil, only unread articles will
8660 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8661 in the comparisons. If NOT-MATCHING, return a list of all articles that
8662 not match REGEXP on HEADER."
8663   (let ((case-fold-search (not not-case-fold))
8664         articles d func)
8665     (if (consp header)
8666         (if (eq (car header) 'extra)
8667             (setq func
8668                   `(lambda (h)
8669                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8670                          "")))
8671           (error "%s is an invalid header" header))
8672       (unless (fboundp (intern (concat "mail-header-" header)))
8673         (error "%s is not a valid header" header))
8674       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8675     (dolist (d (if (eq backward 'all)
8676                    gnus-newsgroup-data
8677                  (gnus-data-find-list
8678                   (gnus-summary-article-number)
8679                   (gnus-data-list backward))))
8680       (when (and (or (not unread)       ; We want all articles...
8681                      (gnus-data-unread-p d)) ; Or just unreads.
8682                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8683                  (if not-matching
8684                      (not (string-match
8685                            regexp
8686                            (funcall func (gnus-data-header d))))
8687                    (string-match regexp
8688                                  (funcall func (gnus-data-header d)))))
8689         (push (gnus-data-number d) articles))) ; Success!
8690     (nreverse articles)))
8691
8692 (defun gnus-summary-execute-command (header regexp command &optional backward)
8693   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8694 If HEADER is an empty string (or nil), the match is done on the entire
8695 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8696   (interactive
8697    (list (let ((completion-ignore-case t))
8698            (completing-read
8699             "Header name: "
8700             (mapcar (lambda (header) (list (format "%s" header)))
8701                     (append
8702                      '("Number" "Subject" "From" "Lines" "Date"
8703                        "Message-ID" "Xref" "References" "Body")
8704                      gnus-extra-headers))
8705             nil 'require-match))
8706          (read-string "Regexp: ")
8707          (read-key-sequence "Command: ")
8708          current-prefix-arg))
8709   (when (equal header "Body")
8710     (setq header ""))
8711   ;; Hidden thread subtrees must be searched as well.
8712   (gnus-summary-show-all-threads)
8713   ;; We don't want to change current point nor window configuration.
8714   (save-excursion
8715     (save-window-excursion
8716       (let (gnus-visual
8717             gnus-treat-strip-trailing-blank-lines
8718             gnus-treat-strip-leading-blank-lines
8719             gnus-treat-strip-multiple-blank-lines
8720             gnus-treat-hide-boring-headers
8721             gnus-treat-fold-newsgroups
8722             gnus-article-prepare-hook)
8723         (gnus-message 6 "Executing %s..." (key-description command))
8724         ;; We'd like to execute COMMAND interactively so as to give arguments.
8725         (gnus-execute header regexp
8726                       `(call-interactively ',(key-binding command))
8727                       backward)
8728         (gnus-message 6 "Executing %s...done" (key-description command))))))
8729
8730 (defun gnus-summary-beginning-of-article ()
8731   "Scroll the article back to the beginning."
8732   (interactive)
8733   (gnus-summary-select-article)
8734   (gnus-configure-windows 'article)
8735   (gnus-eval-in-buffer-window gnus-article-buffer
8736     (widen)
8737     (goto-char (point-min))
8738     (when gnus-break-pages
8739       (gnus-narrow-to-page))))
8740
8741 (defun gnus-summary-end-of-article ()
8742   "Scroll to the end of the article."
8743   (interactive)
8744   (gnus-summary-select-article)
8745   (gnus-configure-windows 'article)
8746   (gnus-eval-in-buffer-window gnus-article-buffer
8747     (widen)
8748     (goto-char (point-max))
8749     (recenter -3)
8750     (when gnus-break-pages
8751       (when (re-search-backward page-delimiter nil t)
8752         (narrow-to-region (match-end 0) (point-max)))
8753       (gnus-narrow-to-page))))
8754
8755 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8756   "Truncate to LEN and quote all \"(\"'s in STRING."
8757   (gnus-replace-in-string (if (and len (> (length string) len))
8758                               (substring string 0 len)
8759                             string)
8760                           "[()]" "\\\\\\&"))
8761
8762 (defun gnus-summary-print-article (&optional filename n)
8763   "Generate and print a PostScript image of the process-marked (mail) articles.
8764
8765 If used interactively, print the current article if none are
8766 process-marked.  With prefix arg, prompt the user for the name of the
8767 file to save in.
8768
8769 When used from Lisp, accept two optional args FILENAME and N.  N means
8770 to print the next N articles.  If N is negative, print the N previous
8771 articles.  If N is nil and articles have been marked with the process
8772 mark, print these instead.
8773
8774 If the optional first argument FILENAME is nil, send the image to the
8775 printer.  If FILENAME is a string, save the PostScript image in a file with
8776 that name.  If FILENAME is a number, prompt the user for the name of the file
8777 to save in."
8778   (interactive (list (ps-print-preprint current-prefix-arg)))
8779   (dolist (article (gnus-summary-work-articles n))
8780     (gnus-summary-select-article nil nil 'pseudo article)
8781     (gnus-eval-in-buffer-window gnus-article-buffer
8782       (gnus-print-buffer))
8783     (gnus-summary-remove-process-mark article))
8784   (ps-despool filename))
8785
8786 (defun gnus-print-buffer ()
8787   (let ((buffer (generate-new-buffer " *print*")))
8788     (unwind-protect
8789         (progn
8790           (copy-to-buffer buffer (point-min) (point-max))
8791           (set-buffer buffer)
8792           (gnus-remove-text-with-property 'gnus-decoration)
8793           (when (gnus-visual-p 'article-highlight 'highlight)
8794             ;; Copy-to-buffer doesn't copy overlay.  So redo
8795             ;; highlight.
8796             (let ((gnus-article-buffer buffer))
8797               (gnus-article-highlight-citation t)
8798               (gnus-article-highlight-signature)
8799               (gnus-article-emphasize)
8800               (gnus-article-delete-invisible-text)))
8801           (let ((ps-left-header
8802                  (list
8803                   (concat "("
8804                           (gnus-summary-print-truncate-and-quote
8805                            (mail-header-subject gnus-current-headers)
8806                            66) ")")
8807                   (concat "("
8808                           (gnus-summary-print-truncate-and-quote
8809                            (mail-header-from gnus-current-headers)
8810                            45) ")")))
8811                 (ps-right-header
8812                  (list
8813                   "/pagenumberstring load"
8814                   (concat "("
8815                           (mail-header-date gnus-current-headers) ")"))))
8816             (gnus-run-hooks 'gnus-ps-print-hook)
8817             (save-excursion
8818               (if window-system
8819                   (ps-spool-buffer-with-faces)
8820                 (ps-spool-buffer)))))
8821       (kill-buffer buffer))))
8822
8823 (defun gnus-summary-show-article (&optional arg)
8824   "Force redisplaying of the current article.
8825 If ARG (the prefix) is a number, show the article with the charset
8826 defined in `gnus-summary-show-article-charset-alist', or the charset
8827 input.
8828 If ARG (the prefix) is non-nil and not a number, show the raw article
8829 without any article massaging functions being run.  Normally, the key
8830 strokes are `C-u g'."
8831   (interactive "P")
8832   (cond
8833    ((numberp arg)
8834     (gnus-summary-show-article t)
8835     (let ((gnus-newsgroup-charset
8836            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8837                (mm-read-coding-system
8838                 "View as charset: " ;; actually it is coding system.
8839                 (with-current-buffer gnus-article-buffer
8840                   (mm-detect-coding-region (point) (point-max))))))
8841           (gnus-newsgroup-ignored-charsets 'gnus-all))
8842       (gnus-summary-select-article nil 'force)
8843       (let ((deps gnus-newsgroup-dependencies)
8844             head header lines)
8845         (save-excursion
8846           (set-buffer gnus-original-article-buffer)
8847           (save-restriction
8848             (message-narrow-to-head)
8849             (setq head (buffer-string))
8850             (goto-char (point-min))
8851             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8852               (goto-char (point-max))
8853               (widen)
8854               (setq lines (1- (count-lines (point) (point-max))))))
8855           (with-temp-buffer
8856             (insert (format "211 %d Article retrieved.\n"
8857                             (cdr gnus-article-current)))
8858             (insert head)
8859             (if lines (insert (format "Lines: %d\n" lines)))
8860             (insert ".\n")
8861             (let ((nntp-server-buffer (current-buffer)))
8862               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8863         (gnus-data-set-header
8864          (gnus-data-find (cdr gnus-article-current))
8865          header)
8866         (gnus-summary-update-article-line
8867          (cdr gnus-article-current) header)
8868         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8869           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8870    ((not arg)
8871     ;; Select the article the normal way.
8872     (gnus-summary-select-article nil 'force))
8873    (t
8874     ;; We have to require this here to make sure that the following
8875     ;; dynamic binding isn't shadowed by autoloading.
8876     (require 'gnus-async)
8877     (require 'gnus-art)
8878     ;; Bind the article treatment functions to nil.
8879     (let ((gnus-have-all-headers t)
8880           gnus-article-prepare-hook
8881           gnus-article-decode-hook
8882           gnus-display-mime-function
8883           gnus-break-pages)
8884       ;; Destroy any MIME parts.
8885       (when (gnus-buffer-live-p gnus-article-buffer)
8886         (save-excursion
8887           (set-buffer gnus-article-buffer)
8888           (mm-destroy-parts gnus-article-mime-handles)
8889           ;; Set it to nil for safety reason.
8890           (setq gnus-article-mime-handle-alist nil)
8891           (setq gnus-article-mime-handles nil)))
8892       (gnus-summary-select-article nil 'force))))
8893   (gnus-summary-goto-subject gnus-current-article)
8894   (gnus-summary-position-point))
8895
8896 (defun gnus-summary-show-raw-article ()
8897   "Show the raw article without any article massaging functions being run."
8898   (interactive)
8899   (gnus-summary-show-article t))
8900
8901 (defun gnus-summary-verbose-headers (&optional arg)
8902   "Toggle permanent full header display.
8903 If ARG is a positive number, turn header display on.
8904 If ARG is a negative number, turn header display off."
8905   (interactive "P")
8906   (setq gnus-show-all-headers
8907         (cond ((or (not (numberp arg))
8908                    (zerop arg))
8909                (not gnus-show-all-headers))
8910               ((natnump arg)
8911                t)))
8912   (gnus-summary-show-article))
8913
8914 (defun gnus-summary-toggle-header (&optional arg)
8915   "Show the headers if they are hidden, or hide them if they are shown.
8916 If ARG is a positive number, show the entire header.
8917 If ARG is a negative number, hide the unwanted header lines."
8918   (interactive "P")
8919   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8920                      (get-buffer-window gnus-article-buffer t))))
8921     (with-current-buffer gnus-article-buffer
8922       (widen)
8923       (article-narrow-to-head)
8924       (let* ((buffer-read-only nil)
8925              (inhibit-point-motion-hooks t)
8926              (hidden (if (numberp arg)
8927                          (>= arg 0)
8928                        (or (not (looking-at "[^ \t\n]+:"))
8929                            (gnus-article-hidden-text-p 'headers))))
8930              s e)
8931         (delete-region (point-min) (point-max))
8932         (with-current-buffer gnus-original-article-buffer
8933           (goto-char (setq s (point-min)))
8934           (setq e (if (search-forward "\n\n" nil t)
8935                       (1- (point))
8936                     (point-max))))
8937         (insert-buffer-substring gnus-original-article-buffer s e)
8938         (run-hooks 'gnus-article-decode-hook)
8939         (if hidden
8940             (let ((gnus-treat-hide-headers nil)
8941                   (gnus-treat-hide-boring-headers nil))
8942               (gnus-delete-wash-type 'headers)
8943               (gnus-treat-article 'head))
8944           (gnus-treat-article 'head))
8945         (widen)
8946         (if window
8947             (set-window-start window (goto-char (point-min))))
8948         (if gnus-break-pages
8949             (gnus-narrow-to-page)
8950           (when (gnus-visual-p 'page-marker)
8951             (let ((buffer-read-only nil))
8952               (gnus-remove-text-with-property 'gnus-prev)
8953               (gnus-remove-text-with-property 'gnus-next))))
8954         (gnus-set-mode-line 'article)))))
8955
8956 (defun gnus-summary-show-all-headers ()
8957   "Make all header lines visible."
8958   (interactive)
8959   (gnus-summary-toggle-header 1))
8960
8961 (defun gnus-summary-caesar-message (&optional arg)
8962   "Caesar rotate the current article by 13.
8963 The numerical prefix specifies how many places to rotate each letter
8964 forward."
8965   (interactive "P")
8966   (gnus-summary-select-article)
8967   (let ((mail-header-separator ""))
8968     (gnus-eval-in-buffer-window gnus-article-buffer
8969       (save-restriction
8970         (widen)
8971         (let ((start (window-start))
8972               buffer-read-only)
8973           (message-caesar-buffer-body arg)
8974           (set-window-start (get-buffer-window (current-buffer)) start)))))
8975   ;; Create buttons and stuff...
8976   (gnus-treat-article nil))
8977
8978 (defun gnus-summary-idna-message (&optional arg)
8979   "Decode IDNA encoded domain names in the current articles.
8980 IDNA encoded domain names looks like `xn--bar'.  If a string
8981 remain unencoded after running this function, it is likely an
8982 invalid IDNA string (`xn--bar' is invalid).
8983
8984 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
8985 installed for this command to work."
8986   (interactive "P")
8987   (if (not (and (condition-case nil (require 'idna)
8988                   (file-error))
8989                 (mm-coding-system-p 'utf-8)
8990                 (executable-find (symbol-value 'idna-program))))
8991       (gnus-message
8992        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
8993     (gnus-summary-select-article)
8994     (let ((mail-header-separator ""))
8995       (gnus-eval-in-buffer-window gnus-article-buffer
8996         (save-restriction
8997           (widen)
8998           (let ((start (window-start))
8999                 buffer-read-only)
9000             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9001               (replace-match (idna-to-unicode (match-string 1))))
9002             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9003
9004 (autoload 'unmorse-region "morse"
9005   "Convert morse coded text in region to ordinary ASCII text."
9006   t)
9007
9008 (defun gnus-summary-morse-message (&optional arg)
9009   "Morse decode the current article."
9010   (interactive "P")
9011   (gnus-summary-select-article)
9012   (let ((mail-header-separator ""))
9013     (gnus-eval-in-buffer-window gnus-article-buffer
9014       (save-excursion
9015         (save-restriction
9016           (widen)
9017           (let ((pos (window-start))
9018                 buffer-read-only)
9019             (goto-char (point-min))
9020             (when (message-goto-body)
9021               (gnus-narrow-to-body))
9022             (goto-char (point-min))
9023             (while (search-forward "·" (point-max) t)
9024               (replace-match "."))
9025             (unmorse-region (point-min) (point-max))
9026             (widen)
9027             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9028
9029 (defun gnus-summary-stop-page-breaking ()
9030   "Stop page breaking in the current article."
9031   (interactive)
9032   (gnus-summary-select-article)
9033   (gnus-eval-in-buffer-window gnus-article-buffer
9034     (widen)
9035     (when (gnus-visual-p 'page-marker)
9036       (let ((buffer-read-only nil))
9037         (gnus-remove-text-with-property 'gnus-prev)
9038         (gnus-remove-text-with-property 'gnus-next))
9039       (setq gnus-page-broken nil))))
9040
9041 (defun gnus-summary-move-article (&optional n to-newsgroup
9042                                             select-method action)
9043   "Move the current article to a different newsgroup.
9044 If N is a positive number, move the N next articles.
9045 If N is a negative number, move the N previous articles.
9046 If N is nil and any articles have been marked with the process mark,
9047 move those articles instead.
9048 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9049 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9050 re-spool using this method.
9051
9052 When called interactively with TO-NEWSGROUP being nil, the value of
9053 the variable `gnus-move-split-methods' is used for finding a default
9054 for the target newsgroup.
9055
9056 For this function to work, both the current newsgroup and the
9057 newsgroup that you want to move to have to support the `request-move'
9058 and `request-accept' functions.
9059
9060 ACTION can be either `move' (the default), `crosspost' or `copy'."
9061   (interactive "P")
9062   (unless action
9063     (setq action 'move))
9064   ;; Check whether the source group supports the required functions.
9065   (cond ((and (eq action 'move)
9066               (not (gnus-check-backend-function
9067                     'request-move-article gnus-newsgroup-name)))
9068          (error "The current group does not support article moving"))
9069         ((and (eq action 'crosspost)
9070               (not (gnus-check-backend-function
9071                     'request-replace-article gnus-newsgroup-name)))
9072          (error "The current group does not support article editing")))
9073   (let ((articles (gnus-summary-work-articles n))
9074         (prefix (if (gnus-check-backend-function
9075                      'request-move-article gnus-newsgroup-name)
9076                     (funcall gnus-move-group-prefix-function
9077                              gnus-newsgroup-name)
9078                   ""))
9079         (names '((move "Move" "Moving")
9080                  (copy "Copy" "Copying")
9081                  (crosspost "Crosspost" "Crossposting")))
9082         (copy-buf (save-excursion
9083                     (nnheader-set-temp-buffer " *copy article*")))
9084         art-group to-method new-xref article to-groups articles-to-update-marks)
9085     (unless (assq action names)
9086       (error "Unknown action %s" action))
9087     ;; Read the newsgroup name.
9088     (when (and (not to-newsgroup)
9089                (not select-method))
9090       (if (and gnus-move-split-methods
9091                (not
9092                 (and (memq gnus-current-article articles)
9093                      (gnus-buffer-live-p gnus-original-article-buffer))))
9094           ;; When `gnus-move-split-methods' is non-nil, we have to
9095           ;; select an article to give `gnus-read-move-group-name' an
9096           ;; opportunity to suggest an appropriate default.  However,
9097           ;; we needn't render or mark the article.
9098           (let ((gnus-display-mime-function nil)
9099                 (gnus-article-prepare-hook nil)
9100                 (gnus-mark-article-hook nil))
9101             (gnus-summary-select-article nil nil nil (car articles))))
9102       (setq to-newsgroup
9103             (gnus-read-move-group-name
9104              (cadr (assq action names))
9105              (symbol-value (intern (format "gnus-current-%s-group" action)))
9106              articles prefix))
9107       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9108     (setq to-method (or select-method
9109                         (gnus-server-to-method
9110                          (gnus-group-method to-newsgroup))))
9111     ;; Check the method we are to move this article to...
9112     (unless (gnus-check-backend-function
9113              'request-accept-article (car to-method))
9114       (error "%s does not support article copying" (car to-method)))
9115     (unless (gnus-check-server to-method)
9116       (error "Can't open server %s" (car to-method)))
9117     (gnus-message 6 "%s to %s: %s..."
9118                   (caddr (assq action names))
9119                   (or (car select-method) to-newsgroup) articles)
9120     (while articles
9121       (setq article (pop articles))
9122       (setq
9123        art-group
9124        (cond
9125         ;; Move the article.
9126         ((eq action 'move)
9127          ;; Remove this article from future suppression.
9128          (gnus-dup-unsuppress-article article)
9129          (let* ((from-method (gnus-find-method-for-group
9130                               gnus-newsgroup-name))
9131                 (to-method (gnus-find-method-for-group
9132                             to-newsgroup))
9133                 (move-is-internal (gnus-method-equal from-method to-method)))
9134          (gnus-request-move-article
9135           article                       ; Article to move
9136           gnus-newsgroup-name           ; From newsgroup
9137           (nth 1 (gnus-find-method-for-group
9138                   gnus-newsgroup-name)) ; Server
9139           (list 'gnus-request-accept-article
9140                 to-newsgroup (list 'quote select-method)
9141                 (not articles) t)       ; Accept form
9142           (not articles)                ; Only save nov last time
9143           move-is-internal)))           ; is this move internal?
9144         ;; Copy the article.
9145         ((eq action 'copy)
9146          (save-excursion
9147            (set-buffer copy-buf)
9148            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9149              (save-restriction
9150                (nnheader-narrow-to-headers)
9151                (dolist (hdr gnus-copy-article-ignored-headers)
9152                  (message-remove-header hdr t)))
9153              (gnus-request-accept-article
9154               to-newsgroup select-method (not articles) t))))
9155         ;; Crosspost the article.
9156         ((eq action 'crosspost)
9157          (let ((xref (message-tokenize-header
9158                       (mail-header-xref (gnus-summary-article-header article))
9159                       " ")))
9160            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9161                                   ":" (number-to-string article)))
9162            (unless xref
9163              (setq xref (list (system-name))))
9164            (setq new-xref
9165                  (concat
9166                   (mapconcat 'identity
9167                              (delete "Xref:" (delete new-xref xref))
9168                              " ")
9169                   " " new-xref))
9170            (save-excursion
9171              (set-buffer copy-buf)
9172              ;; First put the article in the destination group.
9173              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9174              (when (consp (setq art-group
9175                                 (gnus-request-accept-article
9176                                  to-newsgroup select-method (not articles))))
9177                (setq new-xref (concat new-xref " " (car art-group)
9178                                       ":"
9179                                       (number-to-string (cdr art-group))))
9180                ;; Now we have the new Xrefs header, so we insert
9181                ;; it and replace the new article.
9182                (nnheader-replace-header "Xref" new-xref)
9183                (gnus-request-replace-article
9184                 (cdr art-group) to-newsgroup (current-buffer))
9185                art-group))))))
9186       (cond
9187        ((not art-group)
9188         (gnus-message 1 "Couldn't %s article %s: %s"
9189                       (cadr (assq action names)) article
9190                       (nnheader-get-report (car to-method))))
9191        ((eq art-group 'junk)
9192         (when (eq action 'move)
9193           (gnus-summary-mark-article article gnus-canceled-mark)
9194           (gnus-message 4 "Deleted article %s" article)
9195           ;; run the delete hook
9196           (run-hook-with-args 'gnus-summary-article-delete-hook
9197                               action
9198                               (gnus-data-header
9199                                (assoc article (gnus-data-list nil)))
9200                               gnus-newsgroup-name nil
9201                               select-method)))
9202        (t
9203         (let* ((pto-group (gnus-group-prefixed-name
9204                            (car art-group) to-method))
9205                (info (gnus-get-info pto-group))
9206                (to-group (gnus-info-group info))
9207                to-marks)
9208           ;; Update the group that has been moved to.
9209           (when (and info
9210                      (memq action '(move copy)))
9211             (unless (member to-group to-groups)
9212               (push to-group to-groups))
9213
9214             (unless (memq article gnus-newsgroup-unreads)
9215               (push 'read to-marks)
9216               (gnus-info-set-read
9217                info (gnus-add-to-range (gnus-info-read info)
9218                                        (list (cdr art-group)))))
9219
9220             ;; See whether the article is to be put in the cache.
9221             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9222                              gnus-article-mark-lists
9223                            (delete '(expirable . expire)
9224                                    (copy-sequence gnus-article-mark-lists))))
9225                   (to-article (cdr art-group)))
9226
9227               ;; Enter the article into the cache in the new group,
9228               ;; if that is required.
9229               (when gnus-use-cache
9230                 (gnus-cache-possibly-enter-article
9231                  to-group to-article
9232                  (memq article gnus-newsgroup-marked)
9233                  (memq article gnus-newsgroup-dormant)
9234                  (memq article gnus-newsgroup-unreads)))
9235
9236               (when gnus-preserve-marks
9237                 ;; Copy any marks over to the new group.
9238                 (when (and (equal to-group gnus-newsgroup-name)
9239                            (not (memq article gnus-newsgroup-unreads)))
9240                   ;; Mark this article as read in this group.
9241                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9242                   (setcdr (gnus-active to-group) to-article)
9243                   (setcdr gnus-newsgroup-active to-article))
9244
9245                 (while marks
9246                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9247                     (when (memq article (symbol-value
9248                                          (intern (format "gnus-newsgroup-%s"
9249                                                          (caar marks)))))
9250                       (push (cdar marks) to-marks)
9251                       ;; If the other group is the same as this group,
9252                       ;; then we have to add the mark to the list.
9253                       (when (equal to-group gnus-newsgroup-name)
9254                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9255                              (cons to-article
9256                                    (symbol-value
9257                                     (intern (format "gnus-newsgroup-%s"
9258                                                     (caar marks)))))))
9259                       ;; Copy the marks to other group.
9260                       (gnus-add-marked-articles
9261                        to-group (cdar marks) (list to-article) info)))
9262                   (setq marks (cdr marks)))
9263
9264                 (gnus-request-set-mark
9265                  to-group (list (list (list to-article) 'add to-marks))))
9266
9267               (gnus-dribble-enter
9268                (concat "(gnus-group-set-info '"
9269                        (gnus-prin1-to-string (gnus-get-info to-group))
9270                        ")"))))
9271
9272           ;; Update the Xref header in this article to point to
9273           ;; the new crossposted article we have just created.
9274           (when (eq action 'crosspost)
9275             (save-excursion
9276               (set-buffer copy-buf)
9277               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9278               (nnheader-replace-header "Xref" new-xref)
9279               (gnus-request-replace-article
9280                article gnus-newsgroup-name (current-buffer))))
9281
9282           ;; run the move/copy/crosspost/respool hook
9283           (run-hook-with-args 'gnus-summary-article-move-hook
9284                               action
9285                               (gnus-data-header
9286                                (assoc article (gnus-data-list nil)))
9287                               gnus-newsgroup-name
9288                               to-newsgroup
9289                               select-method))
9290
9291         ;;;!!!Why is this necessary?
9292         (set-buffer gnus-summary-buffer)
9293         
9294         (gnus-summary-goto-subject article)
9295         (when (eq action 'move)
9296           (gnus-summary-mark-article article gnus-canceled-mark))))
9297       (push article articles-to-update-marks))
9298
9299     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9300     ;; Re-activate all groups that have been moved to.
9301     (save-excursion
9302       (set-buffer gnus-group-buffer)
9303       (let ((gnus-group-marked to-groups))
9304         (gnus-group-get-new-news-this-group nil t)))
9305     
9306     (gnus-kill-buffer copy-buf)
9307     (gnus-summary-position-point)
9308     (gnus-set-mode-line 'summary)))
9309
9310 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9311   "Copy the current article to some other group.
9312 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9313 When called interactively, if TO-NEWSGROUP is nil, use the value of
9314 the variable `gnus-move-split-methods' for finding a default target
9315 newsgroup.
9316 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9317 re-spool using this method."
9318   (interactive "P")
9319   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9320
9321 (defun gnus-summary-crosspost-article (&optional n)
9322   "Crosspost the current article to some other group."
9323   (interactive "P")
9324   (gnus-summary-move-article n nil nil 'crosspost))
9325
9326 (defcustom gnus-summary-respool-default-method nil
9327   "Default method type for respooling an article.
9328 If nil, use to the current newsgroup method."
9329   :type 'symbol
9330   :group 'gnus-summary-mail)
9331
9332 (defcustom gnus-summary-display-while-building nil
9333   "If non-nil, show and update the summary buffer as it's being built.
9334 If the value is t, update the buffer after every line is inserted.  If
9335 the value is an integer (N), update the display every N lines."
9336   :version "22.1"
9337   :group 'gnus-thread
9338   :type '(choice (const :tag "off" nil)
9339                  number
9340                  (const :tag "frequently" t)))
9341
9342 (defun gnus-summary-respool-article (&optional n method)
9343   "Respool the current article.
9344 The article will be squeezed through the mail spooling process again,
9345 which means that it will be put in some mail newsgroup or other
9346 depending on `nnmail-split-methods'.
9347 If N is a positive number, respool the N next articles.
9348 If N is a negative number, respool the N previous articles.
9349 If N is nil and any articles have been marked with the process mark,
9350 respool those articles instead.
9351
9352 Respooling can be done both from mail groups and \"real\" newsgroups.
9353 In the former case, the articles in question will be moved from the
9354 current group into whatever groups they are destined to.  In the
9355 latter case, they will be copied into the relevant groups."
9356   (interactive
9357    (list current-prefix-arg
9358          (let* ((methods (gnus-methods-using 'respool))
9359                 (methname
9360                  (symbol-name (or gnus-summary-respool-default-method
9361                                   (car (gnus-find-method-for-group
9362                                         gnus-newsgroup-name)))))
9363                 (method
9364                  (gnus-completing-read-with-default
9365                   methname "What backend do you want to use when respooling?"
9366                   methods nil t nil 'gnus-mail-method-history))
9367                 ms)
9368            (cond
9369             ((zerop (length (setq ms (gnus-servers-using-backend
9370                                       (intern method)))))
9371              (list (intern method) ""))
9372             ((= 1 (length ms))
9373              (car ms))
9374             (t
9375              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9376                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9377                            ms-alist))))))))
9378   (unless method
9379     (error "No method given for respooling"))
9380   (if (assoc (symbol-name
9381               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9382              (gnus-methods-using 'respool))
9383       (gnus-summary-move-article n nil method)
9384     (gnus-summary-copy-article n nil method)))
9385
9386 (defun gnus-summary-import-article (file &optional edit)
9387   "Import an arbitrary file into a mail newsgroup."
9388   (interactive "fImport file: \nP")
9389   (let ((group gnus-newsgroup-name)
9390         (now (current-time))
9391         atts lines group-art)
9392     (unless (gnus-check-backend-function 'request-accept-article group)
9393       (error "%s does not support article importing" group))
9394     (or (file-readable-p file)
9395         (not (file-regular-p file))
9396         (error "Can't read %s" file))
9397     (save-excursion
9398       (set-buffer (gnus-get-buffer-create " *import file*"))
9399       (erase-buffer)
9400       (nnheader-insert-file-contents file)
9401       (goto-char (point-min))
9402       (if (nnheader-article-p)
9403           (save-restriction
9404             (goto-char (point-min))
9405             (search-forward "\n\n" nil t)
9406             (narrow-to-region (point-min) (1- (point)))
9407             (goto-char (point-min))
9408             (unless (re-search-forward "^date:" nil t)
9409               (goto-char (point-max))
9410               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9411        ;; This doesn't look like an article, so we fudge some headers.
9412         (setq atts (file-attributes file)
9413               lines (count-lines (point-min) (point-max)))
9414         (insert "From: " (read-string "From: ") "\n"
9415                 "Subject: " (read-string "Subject: ") "\n"
9416                 "Date: " (message-make-date (nth 5 atts)) "\n"
9417                 "Message-ID: " (message-make-message-id) "\n"
9418                 "Lines: " (int-to-string lines) "\n"
9419                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9420       (setq group-art (gnus-request-accept-article group nil t))
9421       (kill-buffer (current-buffer)))
9422     (setq gnus-newsgroup-active (gnus-activate-group group))
9423     (forward-line 1)
9424     (gnus-summary-goto-article (cdr group-art) nil t)
9425     (when edit
9426       (gnus-summary-edit-article))))
9427
9428 (defun gnus-summary-create-article ()
9429   "Create an article in a mail newsgroup."
9430   (interactive)
9431   (let ((group gnus-newsgroup-name)
9432         (now (current-time))
9433         group-art)
9434     (unless (gnus-check-backend-function 'request-accept-article group)
9435       (error "%s does not support article importing" group))
9436     (save-excursion
9437       (set-buffer (gnus-get-buffer-create " *import file*"))
9438       (erase-buffer)
9439       (goto-char (point-min))
9440       ;; This doesn't look like an article, so we fudge some headers.
9441       (insert "From: " (read-string "From: ") "\n"
9442               "Subject: " (read-string "Subject: ") "\n"
9443               "Date: " (message-make-date now) "\n"
9444               "Message-ID: " (message-make-message-id) "\n")
9445       (setq group-art (gnus-request-accept-article group nil t))
9446       (kill-buffer (current-buffer)))
9447     (setq gnus-newsgroup-active (gnus-activate-group group))
9448     (forward-line 1)
9449     (gnus-summary-goto-article (cdr group-art) nil t)
9450     (gnus-summary-edit-article)))
9451
9452 (defun gnus-summary-article-posted-p ()
9453   "Say whether the current (mail) article is available from news as well.
9454 This will be the case if the article has both been mailed and posted."
9455   (interactive)
9456   (let ((id (mail-header-references (gnus-summary-article-header)))
9457         (gnus-override-method (car (gnus-refer-article-methods))))
9458     (if (gnus-request-head id "")
9459         (gnus-message 2 "The current message was found on %s"
9460                       gnus-override-method)
9461       (gnus-message 2 "The current message couldn't be found on %s"
9462                     gnus-override-method)
9463       nil)))
9464
9465 (defun gnus-summary-expire-articles (&optional now)
9466   "Expire all articles that are marked as expirable in the current group."
9467   (interactive)
9468   (when (and (not gnus-group-is-exiting-without-update-p)
9469              (gnus-check-backend-function
9470               'request-expire-articles gnus-newsgroup-name))
9471     ;; This backend supports expiry.
9472     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9473            (expirable (if total
9474                           (progn
9475                             ;; We need to update the info for
9476                             ;; this group for `gnus-list-of-read-articles'
9477                             ;; to give us the right answer.
9478                             (gnus-run-hooks 'gnus-exit-group-hook)
9479                             (gnus-summary-update-info)
9480                             (gnus-list-of-read-articles gnus-newsgroup-name))
9481                         (setq gnus-newsgroup-expirable
9482                               (sort gnus-newsgroup-expirable '<))))
9483            (expiry-wait (if now 'immediate
9484                           (gnus-group-find-parameter
9485                            gnus-newsgroup-name 'expiry-wait)))
9486            (nnmail-expiry-target
9487             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9488                 nnmail-expiry-target))
9489            es)
9490       (when expirable
9491         ;; There are expirable articles in this group, so we run them
9492         ;; through the expiry process.
9493         (gnus-message 6 "Expiring articles...")
9494         (unless (gnus-check-group gnus-newsgroup-name)
9495           (error "Can't open server for %s" gnus-newsgroup-name))
9496         ;; The list of articles that weren't expired is returned.
9497         (save-excursion
9498           (if expiry-wait
9499               (let ((nnmail-expiry-wait-function nil)
9500                     (nnmail-expiry-wait expiry-wait))
9501                 (setq es (gnus-request-expire-articles
9502                           expirable gnus-newsgroup-name)))
9503             (setq es (gnus-request-expire-articles
9504                       expirable gnus-newsgroup-name)))
9505           (unless total
9506             (setq gnus-newsgroup-expirable es))
9507           ;; We go through the old list of expirable, and mark all
9508           ;; really expired articles as nonexistent.
9509           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9510             (let ((gnus-use-cache nil))
9511               (dolist (article expirable)
9512                 (when (and (not (memq article es))
9513                            (gnus-data-find article))
9514                   (gnus-summary-mark-article article gnus-canceled-mark)
9515                   (run-hook-with-args 'gnus-summary-article-expire-hook
9516                                       'delete
9517                                       (gnus-data-header
9518                                        (assoc article (gnus-data-list nil)))
9519                                       gnus-newsgroup-name
9520                                       nil
9521                                       nil))))))
9522         (gnus-message 6 "Expiring articles...done")))))
9523
9524 (defun gnus-summary-expire-articles-now ()
9525   "Expunge all expirable articles in the current group.
9526 This means that *all* articles that are marked as expirable will be
9527 deleted forever, right now."
9528   (interactive)
9529   (or gnus-expert-user
9530       (gnus-yes-or-no-p
9531        "Are you really, really, really sure you want to delete all these messages? ")
9532       (error "Phew!"))
9533   (gnus-summary-expire-articles t))
9534
9535 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9536 (defun gnus-summary-delete-article (&optional n)
9537   "Delete the N next (mail) articles.
9538 This command actually deletes articles.  This is not a marking
9539 command.  The article will disappear forever from your life, never to
9540 return.
9541
9542 If N is negative, delete backwards.
9543 If N is nil and articles have been marked with the process mark,
9544 delete these instead.
9545
9546 If `gnus-novice-user' is non-nil you will be asked for
9547 confirmation before the articles are deleted."
9548   (interactive "P")
9549   (unless (gnus-check-backend-function 'request-expire-articles
9550                                        gnus-newsgroup-name)
9551     (error "The current newsgroup does not support article deletion"))
9552   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9553     (error "Couldn't open server"))
9554   ;; Compute the list of articles to delete.
9555   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9556         (nnmail-expiry-target 'delete)
9557         not-deleted)
9558     (if (and gnus-novice-user
9559              (not (gnus-yes-or-no-p
9560                    (format "Do you really want to delete %s forever? "
9561                            (if (> (length articles) 1)
9562                                (format "these %s articles" (length articles))
9563                              "this article")))))
9564         ()
9565       ;; Delete the articles.
9566       (setq not-deleted (gnus-request-expire-articles
9567                          articles gnus-newsgroup-name 'force))
9568       (while articles
9569         (gnus-summary-remove-process-mark (car articles))
9570         ;; The backend might not have been able to delete the article
9571         ;; after all.
9572         (unless (memq (car articles) not-deleted)
9573           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9574         (let* ((article (car articles))
9575                (ghead  (gnus-data-header
9576                                     (assoc article (gnus-data-list nil)))))
9577           (run-hook-with-args 'gnus-summary-article-delete-hook
9578                               'delete ghead gnus-newsgroup-name nil
9579                               nil))
9580         (setq articles (cdr articles)))
9581       (when not-deleted
9582         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9583     (gnus-summary-position-point)
9584     (gnus-set-mode-line 'summary)
9585     not-deleted))
9586
9587 (defun gnus-summary-edit-article (&optional arg)
9588   "Edit the current article.
9589 This will have permanent effect only in mail groups.
9590 If ARG is nil, edit the decoded articles.
9591 If ARG is 1, edit the raw articles.
9592 If ARG is 2, edit the raw articles even in read-only groups.
9593 If ARG is 3, edit the articles with the current handles.
9594 Otherwise, allow editing of articles even in read-only
9595 groups."
9596   (interactive "P")
9597   (let (force raw current-handles)
9598     (cond
9599      ((null arg))
9600      ((eq arg 1)
9601       (setq raw t))
9602      ((eq arg 2)
9603       (setq raw t
9604             force t))
9605      ((eq arg 3)
9606       (setq current-handles
9607             (and (gnus-buffer-live-p gnus-article-buffer)
9608                  (with-current-buffer gnus-article-buffer
9609                    (prog1
9610                        gnus-article-mime-handles
9611                      (setq gnus-article-mime-handles nil))))))
9612      (t
9613       (setq force t)))
9614     (when (and raw (not force)
9615                (member gnus-newsgroup-name '("nndraft:delayed"
9616                                              "nndraft:drafts"
9617                                              "nndraft:queue")))
9618       (error "Can't edit the raw article in group %s"
9619              gnus-newsgroup-name))
9620     (save-excursion
9621       (set-buffer gnus-summary-buffer)
9622       (let ((mail-parse-charset gnus-newsgroup-charset)
9623             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9624         (gnus-set-global-variables)
9625         (when (and (not force)
9626                    (gnus-group-read-only-p))
9627           (error "The current newsgroup does not support article editing"))
9628         (gnus-summary-show-article t)
9629         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9630           (with-current-buffer gnus-article-buffer
9631             (mm-enable-multibyte)))
9632         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9633             (setq raw t))
9634         (gnus-article-edit-article
9635          (if raw 'ignore
9636            `(lambda ()
9637               (let ((mbl mml-buffer-list))
9638                 (setq mml-buffer-list nil)
9639                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9640                   (mime-to-mml ,'current-handles))
9641                 (let ((mbl1 mml-buffer-list))
9642                   (setq mml-buffer-list mbl)
9643                   (set (make-local-variable 'mml-buffer-list) mbl1))
9644                 (gnus-make-local-hook 'kill-buffer-hook)
9645                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9646          `(lambda (no-highlight)
9647             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9648                   (message-options message-options)
9649                   (message-options-set-recipient)
9650                   (mail-parse-ignored-charsets
9651                    ',gnus-newsgroup-ignored-charsets))
9652               ,(if (not raw) '(progn
9653                                 (mml-to-mime)
9654                                 (mml-destroy-buffers)
9655                                 (remove-hook 'kill-buffer-hook
9656                                              'mml-destroy-buffers t)
9657                                 (kill-local-variable 'mml-buffer-list)))
9658               (gnus-summary-edit-article-done
9659                ,(or (mail-header-references gnus-current-headers) "")
9660                ,(gnus-group-read-only-p)
9661                ,gnus-summary-buffer no-highlight))))))))
9662
9663 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9664
9665 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9666                                                  no-highlight)
9667   "Make edits to the current article permanent."
9668   (interactive)
9669   (save-excursion
9670    ;; The buffer restriction contains the entire article if it exists.
9671     (when (article-goto-body)
9672       (let ((lines (count-lines (point) (point-max)))
9673             (length (- (point-max) (point)))
9674             (case-fold-search t)
9675             (body (copy-marker (point))))
9676         (goto-char (point-min))
9677         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9678           (delete-region (match-beginning 1) (match-end 1))
9679           (insert (number-to-string length)))
9680         (goto-char (point-min))
9681         (when (re-search-forward
9682                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9683           (delete-region (match-beginning 1) (match-end 1))
9684           (insert (number-to-string length)))
9685         (goto-char (point-min))
9686         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9687           (delete-region (match-beginning 1) (match-end 1))
9688           (insert (number-to-string lines))))))
9689   ;; Replace the article.
9690   (let ((buf (current-buffer)))
9691     (with-temp-buffer
9692       (insert-buffer-substring buf)
9693
9694       (if (and (not read-only)
9695                (not (gnus-request-replace-article
9696                      (cdr gnus-article-current) (car gnus-article-current)
9697                      (current-buffer) t)))
9698           (error "Couldn't replace article")
9699         ;; Update the summary buffer.
9700         (if (and references
9701                  (equal (message-tokenize-header references " ")
9702                         (message-tokenize-header
9703                          (or (message-fetch-field "references") "") " ")))
9704             ;; We only have to update this line.
9705             (save-excursion
9706               (save-restriction
9707                 (message-narrow-to-head)
9708                 (let ((head (buffer-string))
9709                       header)
9710                   (with-temp-buffer
9711                     (insert (format "211 %d Article retrieved.\n"
9712                                     (cdr gnus-article-current)))
9713                     (insert head)
9714                     (insert ".\n")
9715                     (let ((nntp-server-buffer (current-buffer)))
9716                       (setq header (car (gnus-get-newsgroup-headers
9717                                          nil t))))
9718                     (save-excursion
9719                       (set-buffer gnus-summary-buffer)
9720                       (gnus-data-set-header
9721                        (gnus-data-find (cdr gnus-article-current))
9722                        header)
9723                       (gnus-summary-update-article-line
9724                        (cdr gnus-article-current) header)
9725                       (if (gnus-summary-goto-subject
9726                            (cdr gnus-article-current) nil t)
9727                           (gnus-summary-update-secondary-mark
9728                            (cdr gnus-article-current))))))))
9729           ;; Update threads.
9730           (set-buffer (or buffer gnus-summary-buffer))
9731           (gnus-summary-update-article (cdr gnus-article-current))
9732           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9733               (gnus-summary-update-secondary-mark
9734                (cdr gnus-article-current))))
9735         ;; Prettify the article buffer again.
9736         (unless no-highlight
9737           (save-excursion
9738             (set-buffer gnus-article-buffer)
9739             ;;;!!! Fix this -- article should be rehighlighted.
9740             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9741             (set-buffer gnus-original-article-buffer)
9742             (gnus-request-article
9743              (cdr gnus-article-current)
9744              (car gnus-article-current) (current-buffer))))
9745         ;; Prettify the summary buffer line.
9746         (when (gnus-visual-p 'summary-highlight 'highlight)
9747           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9748
9749 (defun gnus-summary-edit-wash (key)
9750   "Perform editing command KEY in the article buffer."
9751   (interactive
9752    (list
9753     (progn
9754       (message "%s" (concat (this-command-keys) "- "))
9755       (read-char))))
9756   (message "")
9757   (gnus-summary-edit-article)
9758   (execute-kbd-macro (concat (this-command-keys) key))
9759   (gnus-article-edit-done))
9760
9761 ;;; Respooling
9762
9763 (defun gnus-summary-respool-query (&optional silent trace)
9764   "Query where the respool algorithm would put this article."
9765   (interactive)
9766   (let (gnus-mark-article-hook)
9767     (gnus-summary-select-article)
9768     (save-excursion
9769       (set-buffer gnus-original-article-buffer)
9770       (let ((groups (nnmail-article-group 'identity trace)))
9771         (unless silent
9772           (if groups
9773               (message "This message would go to %s"
9774                        (mapconcat 'car groups ", "))
9775             (message "This message would go to no groups"))
9776           groups)))))
9777
9778 (defun gnus-summary-respool-trace ()
9779   "Trace where the respool algorithm would put this article.
9780 Display a buffer showing all fancy splitting patterns which matched."
9781   (interactive)
9782   (gnus-summary-respool-query nil t))
9783
9784 ;; Summary marking commands.
9785
9786 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9787   "Mark articles which has the same subject as read, and then select the next.
9788 If UNMARK is positive, remove any kind of mark.
9789 If UNMARK is negative, tick articles."
9790   (interactive "P")
9791   (when unmark
9792     (setq unmark (prefix-numeric-value unmark)))
9793   (let ((count
9794          (gnus-summary-mark-same-subject
9795           (gnus-summary-article-subject) unmark)))
9796     ;; Select next unread article.  If auto-select-same mode, should
9797     ;; select the first unread article.
9798     (gnus-summary-next-article t (and gnus-auto-select-same
9799                                       (gnus-summary-article-subject)))
9800     (gnus-message 7 "%d article%s marked as %s"
9801                   count (if (= count 1) " is" "s are")
9802                   (if unmark "unread" "read"))))
9803
9804 (defun gnus-summary-kill-same-subject (&optional unmark)
9805   "Mark articles which has the same subject as read.
9806 If UNMARK is positive, remove any kind of mark.
9807 If UNMARK is negative, tick articles."
9808   (interactive "P")
9809   (when unmark
9810     (setq unmark (prefix-numeric-value unmark)))
9811   (let ((count
9812          (gnus-summary-mark-same-subject
9813           (gnus-summary-article-subject) unmark)))
9814     ;; If marked as read, go to next unread subject.
9815     (when (null unmark)
9816       ;; Go to next unread subject.
9817       (gnus-summary-next-subject 1 t))
9818     (gnus-message 7 "%d articles are marked as %s"
9819                   count (if unmark "unread" "read"))))
9820
9821 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9822   "Mark articles with same SUBJECT as read, and return marked number.
9823 If optional argument UNMARK is positive, remove any kinds of marks.
9824 If optional argument UNMARK is negative, mark articles as unread instead."
9825   (let ((count 1))
9826     (save-excursion
9827       (cond
9828        ((null unmark)                   ; Mark as read.
9829         (while (and
9830                 (progn
9831                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9832                   (gnus-summary-show-thread) t)
9833                 (gnus-summary-find-subject subject))
9834           (setq count (1+ count))))
9835        ((> unmark 0)                    ; Tick.
9836         (while (and
9837                 (progn
9838                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9839                   (gnus-summary-show-thread) t)
9840                 (gnus-summary-find-subject subject))
9841           (setq count (1+ count))))
9842        (t                               ; Mark as unread.
9843         (while (and
9844                 (progn
9845                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9846                   (gnus-summary-show-thread) t)
9847                 (gnus-summary-find-subject subject))
9848           (setq count (1+ count)))))
9849       (gnus-set-mode-line 'summary)
9850       ;; Return the number of marked articles.
9851       count)))
9852
9853 (defun gnus-summary-mark-as-processable (n &optional unmark)
9854   "Set the process mark on the next N articles.
9855 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9856 the process mark instead.  The difference between N and the actual
9857 number of articles marked is returned."
9858   (interactive "P")
9859   (if (and (null n) (gnus-region-active-p))
9860       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9861     (setq n (prefix-numeric-value n))
9862     (let ((backward (< n 0))
9863           (n (abs n)))
9864       (while (and
9865               (> n 0)
9866               (if unmark
9867                   (gnus-summary-remove-process-mark
9868                    (gnus-summary-article-number))
9869                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9870               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9871         (setq n (1- n)))
9872       (when (/= 0 n)
9873         (gnus-message 7 "No more articles"))
9874       (gnus-summary-recenter)
9875       (gnus-summary-position-point)
9876       n)))
9877
9878 (defun gnus-summary-unmark-as-processable (n)
9879   "Remove the process mark from the next N articles.
9880 If N is negative, unmark backward instead.  The difference between N and
9881 the actual number of articles unmarked is returned."
9882   (interactive "P")
9883   (gnus-summary-mark-as-processable n t))
9884
9885 (defun gnus-summary-unmark-all-processable ()
9886   "Remove the process mark from all articles."
9887   (interactive)
9888   (save-excursion
9889     (while gnus-newsgroup-processable
9890       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9891   (gnus-summary-position-point))
9892
9893 (defun gnus-summary-add-mark (article type)
9894   "Mark ARTICLE with a mark of TYPE."
9895   (let ((vtype (car (assq type gnus-article-mark-lists)))
9896         var)
9897     (if (not vtype)
9898         (error "No such mark type: %s" type)
9899       (setq var (intern (format "gnus-newsgroup-%s" type)))
9900       (set var (cons article (symbol-value var)))
9901       (if (memq type '(processable cached replied forwarded recent saved))
9902           (gnus-summary-update-secondary-mark article)
9903         ;;; !!! This is bogus.  We should find out what primary
9904         ;;; !!! mark we want to set.
9905         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9906
9907 (defun gnus-summary-mark-as-expirable (n)
9908   "Mark N articles forward as expirable.
9909 If N is negative, mark backward instead.  The difference between N and
9910 the actual number of articles marked is returned."
9911   (interactive "p")
9912   (gnus-summary-mark-forward n gnus-expirable-mark))
9913
9914 (defun gnus-summary-mark-as-spam (n)
9915   "Mark N articles forward as spam.
9916 If N is negative, mark backward instead.  The difference between N and
9917 the actual number of articles marked is returned."
9918   (interactive "p")
9919   (gnus-summary-mark-forward n gnus-spam-mark))
9920
9921 (defun gnus-summary-mark-article-as-replied (article)
9922   "Mark ARTICLE as replied to and update the summary line.
9923 ARTICLE can also be a list of articles."
9924   (interactive (list (gnus-summary-article-number)))
9925   (let ((articles (if (listp article) article (list article))))
9926     (dolist (article articles)
9927       (unless (numberp article)
9928         (error "%s is not a number" article))
9929       (push article gnus-newsgroup-replied)
9930       (let ((buffer-read-only nil))
9931         (when (gnus-summary-goto-subject article nil t)
9932           (gnus-summary-update-secondary-mark article))))))
9933
9934 (defun gnus-summary-mark-article-as-forwarded (article)
9935   "Mark ARTICLE as forwarded and update the summary line.
9936 ARTICLE can also be a list of articles."
9937   (let ((articles (if (listp article) article (list article))))
9938     (dolist (article articles)
9939       (push article gnus-newsgroup-forwarded)
9940       (let ((buffer-read-only nil))
9941         (when (gnus-summary-goto-subject article nil t)
9942           (gnus-summary-update-secondary-mark article))))))
9943
9944 (defun gnus-summary-set-bookmark (article)
9945   "Set a bookmark in current article."
9946   (interactive (list (gnus-summary-article-number)))
9947   (when (or (not (get-buffer gnus-article-buffer))
9948             (not gnus-current-article)
9949             (not gnus-article-current)
9950             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9951     (error "No current article selected"))
9952   ;; Remove old bookmark, if one exists.
9953   (gnus-pull article gnus-newsgroup-bookmarks)
9954   ;; Set the new bookmark, which is on the form
9955   ;; (article-number . line-number-in-body).
9956   (push
9957    (cons article
9958          (with-current-buffer gnus-article-buffer
9959            (count-lines
9960             (min (point)
9961                  (save-excursion
9962                    (article-goto-body)
9963                    (point)))
9964             (point))))
9965    gnus-newsgroup-bookmarks)
9966   (gnus-message 6 "A bookmark has been added to the current article."))
9967
9968 (defun gnus-summary-remove-bookmark (article)
9969   "Remove the bookmark from the current article."
9970   (interactive (list (gnus-summary-article-number)))
9971   ;; Remove old bookmark, if one exists.
9972   (if (not (assq article gnus-newsgroup-bookmarks))
9973       (gnus-message 6 "No bookmark in current article.")
9974     (gnus-pull article gnus-newsgroup-bookmarks)
9975     (gnus-message 6 "Removed bookmark.")))
9976
9977 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9978 (defun gnus-summary-mark-as-dormant (n)
9979   "Mark N articles forward as dormant.
9980 If N is negative, mark backward instead.  The difference between N and
9981 the actual number of articles marked is returned."
9982   (interactive "p")
9983   (gnus-summary-mark-forward n gnus-dormant-mark))
9984
9985 (defun gnus-summary-set-process-mark (article)
9986   "Set the process mark on ARTICLE and update the summary line."
9987   (setq gnus-newsgroup-processable
9988         (cons article
9989               (delq article gnus-newsgroup-processable)))
9990   (when (gnus-summary-goto-subject article)
9991     (gnus-summary-show-thread)
9992     (gnus-summary-goto-subject article)
9993     (gnus-summary-update-secondary-mark article)))
9994
9995 (defun gnus-summary-remove-process-mark (&rest articles)
9996   "Remove the process mark from ARTICLES and update the summary line."
9997   (dolist (article articles)
9998     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9999     (when (gnus-summary-goto-subject article)
10000       (gnus-summary-show-thread)
10001       (gnus-summary-goto-subject article)
10002       (gnus-summary-update-secondary-mark article))))
10003
10004 (defun gnus-summary-set-saved-mark (article)
10005   "Set the process mark on ARTICLE and update the summary line."
10006   (push article gnus-newsgroup-saved)
10007   (when (gnus-summary-goto-subject article)
10008     (gnus-summary-update-secondary-mark article)))
10009
10010 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10011   "Mark N articles as read forwards.
10012 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10013 The difference between N and the actual number of articles marked is
10014 returned.
10015 If NO-EXPIRE, auto-expiry will be inhibited."
10016   (interactive "p")
10017   (gnus-summary-show-thread)
10018   (let ((backward (< n 0))
10019         (gnus-summary-goto-unread
10020          (and gnus-summary-goto-unread
10021               (not (eq gnus-summary-goto-unread 'never))
10022               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10023                                     gnus-ticked-mark gnus-dormant-mark)))))
10024         (n (abs n))
10025         (mark (or mark gnus-del-mark)))
10026     (while (and (> n 0)
10027                 (gnus-summary-mark-article nil mark no-expire)
10028                 (zerop (gnus-summary-next-subject
10029                         (if backward -1 1)
10030                         (and gnus-summary-goto-unread
10031                              (not (eq gnus-summary-goto-unread 'never)))
10032                         t)))
10033       (setq n (1- n)))
10034     (when (/= 0 n)
10035       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10036     (gnus-summary-recenter)
10037     (gnus-summary-position-point)
10038     (gnus-set-mode-line 'summary)
10039     n))
10040
10041 (defun gnus-summary-mark-article-as-read (mark)
10042   "Mark the current article quickly as read with MARK."
10043   (let ((article (gnus-summary-article-number)))
10044     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10045     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10046     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10047     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10048     (push (cons article mark) gnus-newsgroup-reads)
10049     ;; Possibly remove from cache, if that is used.
10050     (when gnus-use-cache
10051       (gnus-cache-enter-remove-article article))
10052     ;; Allow the backend to change the mark.
10053     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10054     ;; Check for auto-expiry.
10055     (when (and gnus-newsgroup-auto-expire
10056                (memq mark gnus-auto-expirable-marks))
10057       (setq mark gnus-expirable-mark)
10058       ;; Let the backend know about the mark change.
10059       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10060       (push article gnus-newsgroup-expirable))
10061     ;; Set the mark in the buffer.
10062     (gnus-summary-update-mark mark 'unread)
10063     t))
10064
10065 (defun gnus-summary-mark-article-as-unread (mark)
10066   "Mark the current article quickly as unread with MARK."
10067   (let* ((article (gnus-summary-article-number))
10068          (old-mark (gnus-summary-article-mark article)))
10069     ;; Allow the backend to change the mark.
10070     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10071     (if (eq mark old-mark)
10072         t
10073       (if (<= article 0)
10074           (progn
10075             (gnus-error 1 "Can't mark negative article numbers")
10076             nil)
10077         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10078         (setq gnus-newsgroup-spam-marked
10079               (delq article gnus-newsgroup-spam-marked))
10080         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10081         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10082         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10083         (cond ((= mark gnus-ticked-mark)
10084                (setq gnus-newsgroup-marked
10085                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10086                                               article)))
10087               ((= mark gnus-spam-mark)
10088                (setq gnus-newsgroup-spam-marked
10089                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10090                                               article)))
10091               ((= mark gnus-dormant-mark)
10092                (setq gnus-newsgroup-dormant
10093                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10094                                               article)))
10095               (t
10096                (setq gnus-newsgroup-unreads
10097                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10098                                               article))))
10099         (gnus-pull article gnus-newsgroup-reads)
10100
10101         ;; See whether the article is to be put in the cache.
10102         (and gnus-use-cache
10103              (vectorp (gnus-summary-article-header article))
10104              (save-excursion
10105                (gnus-cache-possibly-enter-article
10106                 gnus-newsgroup-name article
10107                 (= mark gnus-ticked-mark)
10108                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10109
10110         ;; Fix the mark.
10111         (gnus-summary-update-mark mark 'unread)
10112         t))))
10113
10114 (defun gnus-summary-mark-article (&optional article mark no-expire)
10115   "Mark ARTICLE with MARK.  MARK can be any character.
10116 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10117 `??' (dormant) and `?E' (expirable).
10118 If MARK is nil, then the default character `?r' is used.
10119 If ARTICLE is nil, then the article on the current line will be
10120 marked.
10121 If NO-EXPIRE, auto-expiry will be inhibited."
10122   ;; The mark might be a string.
10123   (when (stringp mark)
10124     (setq mark (aref mark 0)))
10125   ;; If no mark is given, then we check auto-expiring.
10126   (when (null mark)
10127     (setq mark gnus-del-mark))
10128   (when (and (not no-expire)
10129              gnus-newsgroup-auto-expire
10130              (memq mark gnus-auto-expirable-marks))
10131     (setq mark gnus-expirable-mark))
10132   (let ((article (or article (gnus-summary-article-number)))
10133         (old-mark (gnus-summary-article-mark article)))
10134     ;; Allow the backend to change the mark.
10135     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10136     (if (eq mark old-mark)
10137         t
10138       (unless article
10139         (error "No article on current line"))
10140       (if (not (if (or (= mark gnus-unread-mark)
10141                        (= mark gnus-ticked-mark)
10142                        (= mark gnus-spam-mark)
10143                        (= mark gnus-dormant-mark))
10144                    (gnus-mark-article-as-unread article mark)
10145                  (gnus-mark-article-as-read article mark)))
10146           t
10147         ;; See whether the article is to be put in the cache.
10148         (and gnus-use-cache
10149              (not (= mark gnus-canceled-mark))
10150              (vectorp (gnus-summary-article-header article))
10151              (save-excursion
10152                (gnus-cache-possibly-enter-article
10153                 gnus-newsgroup-name article
10154                 (= mark gnus-ticked-mark)
10155                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10156
10157         (when (gnus-summary-goto-subject article nil t)
10158           (let ((buffer-read-only nil))
10159             (gnus-summary-show-thread)
10160             ;; Fix the mark.
10161             (gnus-summary-update-mark mark 'unread)
10162             t))))))
10163
10164 (defun gnus-summary-update-secondary-mark (article)
10165   "Update the secondary (read, process, cache) mark."
10166   (gnus-summary-update-mark
10167    (cond ((memq article gnus-newsgroup-processable)
10168           gnus-process-mark)
10169          ((memq article gnus-newsgroup-cached)
10170           gnus-cached-mark)
10171          ((memq article gnus-newsgroup-replied)
10172           gnus-replied-mark)
10173          ((memq article gnus-newsgroup-forwarded)
10174           gnus-forwarded-mark)
10175          ((memq article gnus-newsgroup-saved)
10176           gnus-saved-mark)
10177          ((memq article gnus-newsgroup-recent)
10178           gnus-recent-mark)
10179          ((memq article gnus-newsgroup-unseen)
10180           gnus-unseen-mark)
10181          (t gnus-no-mark))
10182    'replied)
10183   (when (gnus-visual-p 'summary-highlight 'highlight)
10184     (gnus-run-hooks 'gnus-summary-update-hook))
10185   t)
10186
10187 (defun gnus-summary-update-download-mark (article)
10188   "Update the download mark."
10189   (gnus-summary-update-mark
10190    (cond ((memq article gnus-newsgroup-undownloaded)
10191           gnus-undownloaded-mark)
10192          (gnus-newsgroup-agentized
10193           gnus-downloaded-mark)
10194          (t
10195           gnus-no-mark))
10196    'download)
10197   (gnus-summary-update-line t)
10198   t)
10199
10200 (defun gnus-summary-update-mark (mark type)
10201   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10202         (buffer-read-only nil))
10203     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10204     (when forward
10205       (when (looking-at "\r")
10206         (incf forward))
10207       (when (<= (+ forward (point)) (point-max))
10208         ;; Go to the right position on the line.
10209         (goto-char (+ forward (point)))
10210         ;; Replace the old mark with the new mark.
10211         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10212         ;; Optionally update the marks by some user rule.
10213         (when (eq type 'unread)
10214           (gnus-data-set-mark
10215            (gnus-data-find (gnus-summary-article-number)) mark)
10216           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10217
10218 (defun gnus-mark-article-as-read (article &optional mark)
10219   "Enter ARTICLE in the pertinent lists and remove it from others."
10220   ;; Make the article expirable.
10221   (let ((mark (or mark gnus-del-mark)))
10222     (setq gnus-newsgroup-expirable
10223           (if (= mark gnus-expirable-mark)
10224               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10225             (delq article gnus-newsgroup-expirable)))
10226     ;; Remove from unread and marked lists.
10227     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10228     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10229     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10230     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10231     (push (cons article mark) gnus-newsgroup-reads)
10232     ;; Possibly remove from cache, if that is used.
10233     (when gnus-use-cache
10234       (gnus-cache-enter-remove-article article))
10235     t))
10236
10237 (defun gnus-mark-article-as-unread (article &optional mark)
10238   "Enter ARTICLE in the pertinent lists and remove it from others."
10239   (let ((mark (or mark gnus-ticked-mark)))
10240     (if (<= article 0)
10241         (progn
10242           (gnus-error 1 "Can't mark negative article numbers")
10243           nil)
10244       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10245             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10246             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10247             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10248             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10249
10250       ;; Unsuppress duplicates?
10251       (when gnus-suppress-duplicates
10252         (gnus-dup-unsuppress-article article))
10253
10254       (cond ((= mark gnus-ticked-mark)
10255              (setq gnus-newsgroup-marked
10256                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10257             ((= mark gnus-spam-mark)
10258              (setq gnus-newsgroup-spam-marked
10259                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10260                                             article)))
10261             ((= mark gnus-dormant-mark)
10262              (setq gnus-newsgroup-dormant
10263                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10264             (t
10265              (setq gnus-newsgroup-unreads
10266                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10267       (gnus-pull article gnus-newsgroup-reads)
10268       t)))
10269
10270 (defalias 'gnus-summary-mark-as-unread-forward
10271   'gnus-summary-tick-article-forward)
10272 (make-obsolete 'gnus-summary-mark-as-unread-forward
10273                'gnus-summary-tick-article-forward)
10274 (defun gnus-summary-tick-article-forward (n)
10275   "Tick N articles forwards.
10276 If N is negative, tick backwards instead.
10277 The difference between N and the number of articles ticked is returned."
10278   (interactive "p")
10279   (gnus-summary-mark-forward n gnus-ticked-mark))
10280
10281 (defalias 'gnus-summary-mark-as-unread-backward
10282   'gnus-summary-tick-article-backward)
10283 (make-obsolete 'gnus-summary-mark-as-unread-backward
10284                'gnus-summary-tick-article-backward)
10285 (defun gnus-summary-tick-article-backward (n)
10286   "Tick N articles backwards.
10287 The difference between N and the number of articles ticked is returned."
10288   (interactive "p")
10289   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10290
10291 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10292 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10293 (defun gnus-summary-tick-article (&optional article clear-mark)
10294   "Mark current article as unread.
10295 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10296 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10297   (interactive)
10298   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10299                                        gnus-ticked-mark)))
10300
10301 (defun gnus-summary-mark-as-read-forward (n)
10302   "Mark N articles as read forwards.
10303 If N is negative, mark backwards instead.
10304 The difference between N and the actual number of articles marked is
10305 returned."
10306   (interactive "p")
10307   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10308
10309 (defun gnus-summary-mark-as-read-backward (n)
10310   "Mark the N articles as read backwards.
10311 The difference between N and the actual number of articles marked is
10312 returned."
10313   (interactive "p")
10314   (gnus-summary-mark-forward
10315    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10316
10317 (defun gnus-summary-mark-as-read (&optional article mark)
10318   "Mark current article as read.
10319 ARTICLE specifies the article to be marked as read.
10320 MARK specifies a string to be inserted at the beginning of the line."
10321   (gnus-summary-mark-article article mark))
10322
10323 (defun gnus-summary-clear-mark-forward (n)
10324   "Clear marks from N articles forward.
10325 If N is negative, clear backward instead.
10326 The difference between N and the number of marks cleared is returned."
10327   (interactive "p")
10328   (gnus-summary-mark-forward n gnus-unread-mark))
10329
10330 (defun gnus-summary-clear-mark-backward (n)
10331   "Clear marks from N articles backward.
10332 The difference between N and the number of marks cleared is returned."
10333   (interactive "p")
10334   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10335
10336 (defun gnus-summary-mark-unread-as-read ()
10337   "Intended to be used by `gnus-summary-mark-article-hook'."
10338   (when (memq gnus-current-article gnus-newsgroup-unreads)
10339     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10340
10341 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10342   "Intended to be used by `gnus-summary-mark-article-hook'."
10343   (let ((mark (gnus-summary-article-mark)))
10344     (when (or (gnus-unread-mark-p mark)
10345               (gnus-read-mark-p mark))
10346       (gnus-summary-mark-article gnus-current-article
10347                                  (or new-mark gnus-read-mark)))))
10348
10349 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10350   "Intended to be used by `gnus-summary-mark-article-hook'."
10351   (let ((mark (gnus-summary-article-mark)))
10352     (when (or (gnus-unread-mark-p mark)
10353               (gnus-read-mark-p mark))
10354       (gnus-summary-mark-article (gnus-summary-article-number)
10355                                  (or new-mark gnus-read-mark)))))
10356
10357 (defun gnus-summary-mark-unread-as-ticked ()
10358   "Intended to be used by `gnus-summary-mark-article-hook'."
10359   (when (memq gnus-current-article gnus-newsgroup-unreads)
10360     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10361
10362 (defun gnus-summary-mark-region-as-read (point mark all)
10363   "Mark all unread articles between point and mark as read.
10364 If given a prefix, mark all articles between point and mark as read,
10365 even ticked and dormant ones."
10366   (interactive "r\nP")
10367   (save-excursion
10368     (let (article)
10369       (goto-char point)
10370       (beginning-of-line)
10371       (while (and
10372               (< (point) mark)
10373               (progn
10374                 (when (or all
10375                           (memq (setq article (gnus-summary-article-number))
10376                                 gnus-newsgroup-unreads))
10377                   (gnus-summary-mark-article article gnus-del-mark))
10378                 t)
10379               (gnus-summary-find-next))))))
10380
10381 (defun gnus-summary-mark-below (score mark)
10382   "Mark articles with score less than SCORE with MARK."
10383   (interactive "P\ncMark: ")
10384   (setq score (if score
10385                   (prefix-numeric-value score)
10386                 (or gnus-summary-default-score 0)))
10387   (save-excursion
10388     (set-buffer gnus-summary-buffer)
10389     (goto-char (point-min))
10390     (while
10391         (progn
10392           (and (< (gnus-summary-article-score) score)
10393                (gnus-summary-mark-article nil mark))
10394           (gnus-summary-find-next)))))
10395
10396 (defun gnus-summary-kill-below (&optional score)
10397   "Mark articles with score below SCORE as read."
10398   (interactive "P")
10399   (gnus-summary-mark-below score gnus-killed-mark))
10400
10401 (defun gnus-summary-clear-above (&optional score)
10402   "Clear all marks from articles with score above SCORE."
10403   (interactive "P")
10404   (gnus-summary-mark-above score gnus-unread-mark))
10405
10406 (defun gnus-summary-tick-above (&optional score)
10407   "Tick all articles with score above SCORE."
10408   (interactive "P")
10409   (gnus-summary-mark-above score gnus-ticked-mark))
10410
10411 (defun gnus-summary-mark-above (score mark)
10412   "Mark articles with score over SCORE with MARK."
10413   (interactive "P\ncMark: ")
10414   (setq score (if score
10415                   (prefix-numeric-value score)
10416                 (or gnus-summary-default-score 0)))
10417   (save-excursion
10418     (set-buffer gnus-summary-buffer)
10419     (goto-char (point-min))
10420     (while (and (progn
10421                   (when (> (gnus-summary-article-score) score)
10422                     (gnus-summary-mark-article nil mark))
10423                   t)
10424                 (gnus-summary-find-next)))))
10425
10426 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10427 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10428 (defun gnus-summary-limit-include-expunged (&optional no-error)
10429   "Display all the hidden articles that were expunged for low scores."
10430   (interactive)
10431   (let ((buffer-read-only nil))
10432     (let ((scored gnus-newsgroup-scored)
10433           headers h)
10434       (while scored
10435         (unless (gnus-summary-article-header (caar scored))
10436           (and (setq h (gnus-number-to-header (caar scored)))
10437                (< (cdar scored) gnus-summary-expunge-below)
10438                (push h headers)))
10439         (setq scored (cdr scored)))
10440       (if (not headers)
10441           (when (not no-error)
10442             (error "No expunged articles hidden"))
10443         (goto-char (point-min))
10444         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10445         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10446         (mapcar (lambda (x) (push (mail-header-number x)
10447                                   gnus-newsgroup-limit))
10448                 headers)
10449         (gnus-summary-prepare-unthreaded (nreverse headers))
10450         (goto-char (point-min))
10451         (gnus-summary-position-point)
10452         t))))
10453
10454 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10455   "Mark all unread articles in this newsgroup as read.
10456 If prefix argument ALL is non-nil, ticked and dormant articles will
10457 also be marked as read.
10458 If QUIETLY is non-nil, no questions will be asked.
10459
10460 If TO-HERE is non-nil, it should be a point in the buffer.  All
10461 articles before (after, if REVERSE is set) this point will be marked
10462 as read.
10463
10464 Note that this function will only catch up the unread article
10465 in the current summary buffer limitation.
10466
10467 The number of articles marked as read is returned."
10468   (interactive "P")
10469   (prog1
10470       (save-excursion
10471         (when (or quietly
10472                   (not gnus-interactive-catchup) ;Without confirmation?
10473                   gnus-expert-user
10474                   (gnus-y-or-n-p
10475                    (if all
10476                        "Mark absolutely all articles as read? "
10477                      "Mark all unread articles as read? ")))
10478           (if (and not-mark
10479                    (not gnus-newsgroup-adaptive)
10480                    (not gnus-newsgroup-auto-expire)
10481                    (not gnus-suppress-duplicates)
10482                    (or (not gnus-use-cache)
10483                        (eq gnus-use-cache 'passive)))
10484               (progn
10485                 (when all
10486                   (setq gnus-newsgroup-marked nil
10487                         gnus-newsgroup-spam-marked nil
10488                         gnus-newsgroup-dormant nil))
10489                 (setq gnus-newsgroup-unreads
10490                       (gnus-sorted-nunion
10491                        (gnus-intersection gnus-newsgroup-unreads
10492                                           gnus-newsgroup-downloadable)
10493                        gnus-newsgroup-unfetched)))
10494             ;; We actually mark all articles as canceled, which we
10495             ;; have to do when using auto-expiry or adaptive scoring.
10496             (gnus-summary-show-all-threads)
10497             (if (and to-here reverse)
10498                 (progn
10499                   (goto-char to-here)
10500                   (gnus-summary-mark-current-read-and-unread-as-read
10501                    gnus-catchup-mark)
10502                   (while (gnus-summary-find-next (not all))
10503                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10504               (when (gnus-summary-first-subject (not all))
10505                 (while (and
10506                         (if to-here (< (point) to-here) t)
10507                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10508                         (gnus-summary-find-next (not all))))))
10509             (gnus-set-mode-line 'summary))
10510           t))
10511     (gnus-summary-position-point)))
10512
10513 (defun gnus-summary-catchup-to-here (&optional all)
10514   "Mark all unticked articles before the current one as read.
10515 If ALL is non-nil, also mark ticked and dormant articles as read."
10516   (interactive "P")
10517   (save-excursion
10518     (gnus-save-hidden-threads
10519       (let ((beg (point)))
10520         ;; We check that there are unread articles.
10521         (when (or all (gnus-summary-find-prev))
10522           (gnus-summary-catchup all t beg)))))
10523   (gnus-summary-position-point))
10524
10525 (defun gnus-summary-catchup-from-here (&optional all)
10526   "Mark all unticked articles after (and including) the current one as read.
10527 If ALL is non-nil, also mark ticked and dormant articles as read."
10528   (interactive "P")
10529   (save-excursion
10530     (gnus-save-hidden-threads
10531       (let ((beg (point)))
10532         ;; We check that there are unread articles.
10533         (when (or all (gnus-summary-find-next))
10534           (gnus-summary-catchup all t beg nil t)))))
10535   (gnus-summary-position-point))
10536
10537 (defun gnus-summary-catchup-all (&optional quietly)
10538   "Mark all articles in this newsgroup as read.
10539 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10540 instead, which marks only unread articles as read."
10541   (interactive "P")
10542   (gnus-summary-catchup t quietly))
10543
10544 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10545   "Mark all unread articles in this group as read, then exit.
10546 If prefix argument ALL is non-nil, all articles are marked as read.
10547 If QUIETLY is non-nil, no questions will be asked."
10548   (interactive "P")
10549   (when (gnus-summary-catchup all quietly nil 'fast)
10550     ;; Select next newsgroup or exit.
10551     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10552              (eq gnus-auto-select-next 'quietly))
10553         (gnus-summary-next-group nil)
10554       (gnus-summary-exit))))
10555
10556 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10557   "Mark all articles in this newsgroup as read, and then exit.
10558 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10559 instead, which marks only unread articles as read."
10560   (interactive "P")
10561   (gnus-summary-catchup-and-exit t quietly))
10562
10563 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10564   "Mark all articles in this group as read and select the next group.
10565 If given a prefix, mark all articles, unread as well as ticked, as
10566 read."
10567   (interactive "P")
10568   (save-excursion
10569     (gnus-summary-catchup all))
10570   (gnus-summary-next-group))
10571
10572 ;;;
10573 ;;; with article
10574 ;;;
10575
10576 (defmacro gnus-with-article (article &rest forms)
10577   "Select ARTICLE and perform FORMS in the original article buffer.
10578 Then replace the article with the result."
10579   `(progn
10580      ;; We don't want the article to be marked as read.
10581      (let (gnus-mark-article-hook)
10582        (gnus-summary-select-article t t nil ,article))
10583      (set-buffer gnus-original-article-buffer)
10584      ,@forms
10585      (if (not (gnus-check-backend-function
10586                'request-replace-article (car gnus-article-current)))
10587          (gnus-message 5 "Read-only group; not replacing")
10588        (unless (gnus-request-replace-article
10589                 ,article (car gnus-article-current)
10590                 (current-buffer) t)
10591          (error "Couldn't replace article")))
10592      ;; The cache and backlog have to be flushed somewhat.
10593      (when gnus-keep-backlog
10594        (gnus-backlog-remove-article
10595         (car gnus-article-current) (cdr gnus-article-current)))
10596      (when gnus-use-cache
10597        (gnus-cache-update-article
10598         (car gnus-article-current) (cdr gnus-article-current)))))
10599
10600 (put 'gnus-with-article 'lisp-indent-function 1)
10601 (put 'gnus-with-article 'edebug-form-spec '(form body))
10602
10603 ;; Thread-based commands.
10604
10605 (defun gnus-summary-articles-in-thread (&optional article)
10606   "Return a list of all articles in the current thread.
10607 If ARTICLE is non-nil, return all articles in the thread that starts
10608 with that article."
10609   (let* ((article (or article (gnus-summary-article-number)))
10610          (data (gnus-data-find-list article))
10611          (top-level (gnus-data-level (car data)))
10612          (top-subject
10613           (cond ((null gnus-thread-operation-ignore-subject)
10614                  (gnus-simplify-subject-re
10615                   (mail-header-subject (gnus-data-header (car data)))))
10616                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10617                  (gnus-simplify-subject-fuzzy
10618                   (mail-header-subject (gnus-data-header (car data)))))
10619                 (t nil)))
10620          (end-point (save-excursion
10621                       (if (gnus-summary-go-to-next-thread)
10622                           (point) (point-max))))
10623          articles)
10624     (while (and data
10625                 (< (gnus-data-pos (car data)) end-point))
10626       (when (or (not top-subject)
10627                 (string= top-subject
10628                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10629                              (gnus-simplify-subject-fuzzy
10630                               (mail-header-subject
10631                                (gnus-data-header (car data))))
10632                            (gnus-simplify-subject-re
10633                             (mail-header-subject
10634                              (gnus-data-header (car data)))))))
10635         (push (gnus-data-number (car data)) articles))
10636       (unless (and (setq data (cdr data))
10637                    (> (gnus-data-level (car data)) top-level))
10638         (setq data nil)))
10639     ;; Return the list of articles.
10640     (nreverse articles)))
10641
10642 (defun gnus-summary-rethread-current ()
10643   "Rethread the thread the current article is part of."
10644   (interactive)
10645   (let* ((gnus-show-threads t)
10646          (article (gnus-summary-article-number))
10647          (id (mail-header-id (gnus-summary-article-header)))
10648          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10649     (unless id
10650       (error "No article on the current line"))
10651     (gnus-rebuild-thread id)
10652     (gnus-summary-goto-subject article)))
10653
10654 (defun gnus-summary-reparent-thread ()
10655   "Make the current article child of the marked (or previous) article.
10656
10657 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10658 is non-nil or the Subject: of both articles are the same."
10659   (interactive)
10660   (unless (not (gnus-group-read-only-p))
10661     (error "The current newsgroup does not support article editing"))
10662   (unless (<= (length gnus-newsgroup-processable) 1)
10663     (error "No more than one article may be marked"))
10664   (save-window-excursion
10665     (let ((gnus-article-buffer " *reparent*")
10666           (current-article (gnus-summary-article-number))
10667           ;; First grab the marked article, otherwise one line up.
10668           (parent-article (if (not (null gnus-newsgroup-processable))
10669                               (car gnus-newsgroup-processable)
10670                             (save-excursion
10671                               (if (eq (forward-line -1) 0)
10672                                   (gnus-summary-article-number)
10673                                 (error "Beginning of summary buffer"))))))
10674       (unless (not (eq current-article parent-article))
10675         (error "An article may not be self-referential"))
10676       (let ((message-id (mail-header-id
10677                          (gnus-summary-article-header parent-article))))
10678         (unless (and message-id (not (equal message-id "")))
10679           (error "No message-id in desired parent"))
10680         (gnus-with-article current-article
10681           (save-restriction
10682             (goto-char (point-min))
10683             (message-narrow-to-head)
10684             (if (re-search-forward "^References: " nil t)
10685                 (progn
10686                   (re-search-forward "^[^ \t]" nil t)
10687                   (forward-line -1)
10688                   (end-of-line)
10689                   (insert " " message-id))
10690               (insert "References: " message-id "\n"))))
10691         (set-buffer gnus-summary-buffer)
10692         (gnus-summary-unmark-all-processable)
10693         (gnus-summary-update-article current-article)
10694         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10695             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10696         (gnus-summary-rethread-current)
10697         (gnus-message 3 "Article %d is now the child of article %d"
10698                       current-article parent-article)))))
10699
10700 (defun gnus-summary-toggle-threads (&optional arg)
10701   "Toggle showing conversation threads.
10702 If ARG is positive number, turn showing conversation threads on."
10703   (interactive "P")
10704   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10705     (setq gnus-show-threads
10706           (if (null arg) (not gnus-show-threads)
10707             (> (prefix-numeric-value arg) 0)))
10708     (gnus-summary-prepare)
10709     (gnus-summary-goto-subject current)
10710     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10711     (gnus-summary-position-point)))
10712
10713 (defun gnus-summary-show-all-threads ()
10714   "Show all threads."
10715   (interactive)
10716   (save-excursion
10717     (let ((buffer-read-only nil))
10718       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10719   (gnus-summary-position-point))
10720
10721 (defun gnus-summary-show-thread ()
10722   "Show thread subtrees.
10723 Returns nil if no thread was there to be shown."
10724   (interactive)
10725   (let ((buffer-read-only nil)
10726         (orig (point))
10727         (end (point-at-eol))
10728         ;; Leave point at bol
10729         (beg (progn (beginning-of-line) (point))))
10730     (prog1
10731         ;; Any hidden lines here?
10732         (search-forward "\r" end t)
10733       (subst-char-in-region beg end ?\^M ?\n t)
10734       (goto-char orig)
10735       (gnus-summary-position-point))))
10736
10737 (defun gnus-summary-maybe-hide-threads ()
10738   "If requested, hide the threads that should be hidden."
10739   (when (and gnus-show-threads
10740              gnus-thread-hide-subtree)
10741     (gnus-summary-hide-all-threads
10742      (if (or (consp gnus-thread-hide-subtree)
10743              (functionp gnus-thread-hide-subtree))
10744          (gnus-make-predicate gnus-thread-hide-subtree)
10745        nil))))
10746
10747 ;;; Hiding predicates.
10748
10749 (defun gnus-article-unread-p (header)
10750   (memq (mail-header-number header) gnus-newsgroup-unreads))
10751
10752 (defun gnus-article-unseen-p (header)
10753   (memq (mail-header-number header) gnus-newsgroup-unseen))
10754
10755 (defun gnus-map-articles (predicate articles)
10756   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10757   (apply 'gnus-or (mapcar predicate
10758                           (mapcar 'gnus-summary-article-header articles))))
10759
10760 (defun gnus-summary-hide-all-threads (&optional predicate)
10761   "Hide all thread subtrees.
10762 If PREDICATE is supplied, threads that satisfy this predicate
10763 will not be hidden."
10764   (interactive)
10765   (save-excursion
10766     (goto-char (point-min))
10767     (let ((end nil))
10768       (while (not end)
10769         (when (or (not predicate)
10770                   (gnus-map-articles
10771                    predicate (gnus-summary-article-children)))
10772             (gnus-summary-hide-thread))
10773         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10774   (gnus-summary-position-point))
10775
10776 (defun gnus-summary-hide-thread ()
10777   "Hide thread subtrees.
10778 If PREDICATE is supplied, threads that satisfy this predicate
10779 will not be hidden.
10780 Returns nil if no threads were there to be hidden."
10781   (interactive)
10782   (let ((buffer-read-only nil)
10783         (start (point))
10784         (article (gnus-summary-article-number)))
10785     (goto-char start)
10786     ;; Go forward until either the buffer ends or the subthread
10787     ;; ends.
10788     (when (and (not (eobp))
10789                (or (zerop (gnus-summary-next-thread 1 t))
10790                    (goto-char (point-max))))
10791       (prog1
10792           (if (and (> (point) start)
10793                    (search-backward "\n" start t))
10794               (progn
10795                 (subst-char-in-region start (point) ?\n ?\^M)
10796                 (gnus-summary-goto-subject article))
10797             (goto-char start)
10798             nil)))))
10799
10800 (defun gnus-summary-go-to-next-thread (&optional previous)
10801   "Go to the same level (or less) next thread.
10802 If PREVIOUS is non-nil, go to previous thread instead.
10803 Return the article number moved to, or nil if moving was impossible."
10804   (let ((level (gnus-summary-thread-level))
10805         (way (if previous -1 1))
10806         (beg (point)))
10807     (forward-line way)
10808     (while (and (not (eobp))
10809                 (< level (gnus-summary-thread-level)))
10810       (forward-line way))
10811     (if (eobp)
10812         (progn
10813           (goto-char beg)
10814           nil)
10815       (setq beg (point))
10816       (prog1
10817           (gnus-summary-article-number)
10818         (goto-char beg)))))
10819
10820 (defun gnus-summary-next-thread (n &optional silent)
10821   "Go to the same level next N'th thread.
10822 If N is negative, search backward instead.
10823 Returns the difference between N and the number of skips actually
10824 done.
10825
10826 If SILENT, don't output messages."
10827   (interactive "p")
10828   (let ((backward (< n 0))
10829         (n (abs n)))
10830     (while (and (> n 0)
10831                 (gnus-summary-go-to-next-thread backward))
10832       (decf n))
10833     (unless silent
10834       (gnus-summary-position-point))
10835     (when (and (not silent) (/= 0 n))
10836       (gnus-message 7 "No more threads"))
10837     n))
10838
10839 (defun gnus-summary-prev-thread (n)
10840   "Go to the same level previous N'th thread.
10841 Returns the difference between N and the number of skips actually
10842 done."
10843   (interactive "p")
10844   (gnus-summary-next-thread (- n)))
10845
10846 (defun gnus-summary-go-down-thread ()
10847   "Go down one level in the current thread."
10848   (let ((children (gnus-summary-article-children)))
10849     (when children
10850       (gnus-summary-goto-subject (car children)))))
10851
10852 (defun gnus-summary-go-up-thread ()
10853   "Go up one level in the current thread."
10854   (let ((parent (gnus-summary-article-parent)))
10855     (when parent
10856       (gnus-summary-goto-subject parent))))
10857
10858 (defun gnus-summary-down-thread (n)
10859   "Go down thread N steps.
10860 If N is negative, go up instead.
10861 Returns the difference between N and how many steps down that were
10862 taken."
10863   (interactive "p")
10864   (let ((up (< n 0))
10865         (n (abs n)))
10866     (while (and (> n 0)
10867                 (if up (gnus-summary-go-up-thread)
10868                   (gnus-summary-go-down-thread)))
10869       (setq n (1- n)))
10870     (gnus-summary-position-point)
10871     (when (/= 0 n)
10872       (gnus-message 7 "Can't go further"))
10873     n))
10874
10875 (defun gnus-summary-up-thread (n)
10876   "Go up thread N steps.
10877 If N is negative, go down instead.
10878 Returns the difference between N and how many steps down that were
10879 taken."
10880   (interactive "p")
10881   (gnus-summary-down-thread (- n)))
10882
10883 (defun gnus-summary-top-thread ()
10884   "Go to the top of the thread."
10885   (interactive)
10886   (while (gnus-summary-go-up-thread))
10887   (gnus-summary-article-number))
10888
10889 (defun gnus-summary-kill-thread (&optional unmark)
10890   "Mark articles under current thread as read.
10891 If the prefix argument is positive, remove any kinds of marks.
10892 If the prefix argument is negative, tick articles instead."
10893   (interactive "P")
10894   (when unmark
10895     (setq unmark (prefix-numeric-value unmark)))
10896   (let ((articles (gnus-summary-articles-in-thread)))
10897     (save-excursion
10898       ;; Expand the thread.
10899       (gnus-summary-show-thread)
10900       ;; Mark all the articles.
10901       (while articles
10902         (gnus-summary-goto-subject (car articles))
10903         (cond ((null unmark)
10904                (gnus-summary-mark-article-as-read gnus-killed-mark))
10905               ((> unmark 0)
10906                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10907               (t
10908                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10909         (setq articles (cdr articles))))
10910     ;; Hide killed subtrees.
10911     (and (null unmark)
10912          gnus-thread-hide-killed
10913          (gnus-summary-hide-thread))
10914     ;; If marked as read, go to next unread subject.
10915     (when (null unmark)
10916       ;; Go to next unread subject.
10917       (gnus-summary-next-subject 1 t)))
10918   (gnus-set-mode-line 'summary))
10919
10920 ;; Summary sorting commands
10921
10922 (defun gnus-summary-sort-by-number (&optional reverse)
10923   "Sort the summary buffer by article number.
10924 Argument REVERSE means reverse order."
10925   (interactive "P")
10926   (gnus-summary-sort 'number reverse))
10927
10928 (defun gnus-summary-sort-by-random (&optional reverse)
10929   "Randomize the order in the summary buffer.
10930 Argument REVERSE means to randomize in reverse order."
10931   (interactive "P")
10932   (gnus-summary-sort 'random reverse))
10933
10934 (defun gnus-summary-sort-by-author (&optional reverse)
10935   "Sort the summary buffer by author name alphabetically.
10936 If `case-fold-search' is non-nil, case of letters is ignored.
10937 Argument REVERSE means reverse order."
10938   (interactive "P")
10939   (gnus-summary-sort 'author reverse))
10940
10941 (defun gnus-summary-sort-by-recipient (&optional reverse)
10942   "Sort the summary buffer by recipient name alphabetically.
10943 If `case-fold-search' is non-nil, case of letters is ignored.
10944 Argument REVERSE means reverse order."
10945   (interactive "P")
10946   (gnus-summary-sort 'recipient reverse))
10947
10948 (defun gnus-summary-sort-by-subject (&optional reverse)
10949   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10950 If `case-fold-search' is non-nil, case of letters is ignored.
10951 Argument REVERSE means reverse order."
10952   (interactive "P")
10953   (gnus-summary-sort 'subject reverse))
10954
10955 (defun gnus-summary-sort-by-date (&optional reverse)
10956   "Sort the summary buffer by date.
10957 Argument REVERSE means reverse order."
10958   (interactive "P")
10959   (gnus-summary-sort 'date reverse))
10960
10961 (defun gnus-summary-sort-by-score (&optional reverse)
10962   "Sort the summary buffer by score.
10963 Argument REVERSE means reverse order."
10964   (interactive "P")
10965   (gnus-summary-sort 'score reverse))
10966
10967 (defun gnus-summary-sort-by-lines (&optional reverse)
10968   "Sort the summary buffer by the number of lines.
10969 Argument REVERSE means reverse order."
10970   (interactive "P")
10971   (gnus-summary-sort 'lines reverse))
10972
10973 (defun gnus-summary-sort-by-chars (&optional reverse)
10974   "Sort the summary buffer by article length.
10975 Argument REVERSE means reverse order."
10976   (interactive "P")
10977   (gnus-summary-sort 'chars reverse))
10978
10979 (defun gnus-summary-sort-by-original (&optional reverse)
10980   "Sort the summary buffer using the default sorting method.
10981 Argument REVERSE means reverse order."
10982   (interactive "P")
10983   (let* ((buffer-read-only)
10984          (gnus-summary-prepare-hook nil))
10985     ;; We do the sorting by regenerating the threads.
10986     (gnus-summary-prepare)
10987     ;; Hide subthreads if needed.
10988     (gnus-summary-maybe-hide-threads)))
10989
10990 (defun gnus-summary-sort (predicate reverse)
10991   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10992   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10993          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10994          (gnus-thread-sort-functions
10995           (if (not reverse)
10996               thread
10997             `(lambda (t1 t2)
10998                (,thread t2 t1))))
10999          (gnus-sort-gathered-threads-function
11000           gnus-thread-sort-functions)
11001          (gnus-article-sort-functions
11002           (if (not reverse)
11003               article
11004             `(lambda (t1 t2)
11005                (,article t2 t1))))
11006          (buffer-read-only)
11007          (gnus-summary-prepare-hook nil))
11008     ;; We do the sorting by regenerating the threads.
11009     (gnus-summary-prepare)
11010     ;; Hide subthreads if needed.
11011     (gnus-summary-maybe-hide-threads)))
11012
11013 ;; Summary saving commands.
11014
11015 (defun gnus-summary-save-article (&optional n not-saved)
11016   "Save the current article using the default saver function.
11017 If N is a positive number, save the N next articles.
11018 If N is a negative number, save the N previous articles.
11019 If N is nil and any articles have been marked with the process mark,
11020 save those articles instead.
11021 The variable `gnus-default-article-saver' specifies the saver function."
11022   (interactive "P")
11023   (let* ((articles (gnus-summary-work-articles n))
11024          (save-buffer (save-excursion
11025                         (nnheader-set-temp-buffer " *Gnus Save*")))
11026          (num (length articles))
11027          header file)
11028     (dolist (article articles)
11029       (setq header (gnus-summary-article-header article))
11030       (if (not (vectorp header))
11031           ;; This is a pseudo-article.
11032           (if (assq 'name header)
11033               (gnus-copy-file (cdr (assq 'name header)))
11034             (gnus-message 1 "Article %d is unsaveable" article))
11035         ;; This is a real article.
11036         (save-window-excursion
11037           (let ((gnus-display-mime-function nil)
11038                 (gnus-article-prepare-hook nil))
11039             (gnus-summary-select-article t nil nil article)))
11040         (save-excursion
11041           (set-buffer save-buffer)
11042           (erase-buffer)
11043           (insert-buffer-substring gnus-original-article-buffer))
11044         (setq file (gnus-article-save save-buffer file num))
11045         (gnus-summary-remove-process-mark article)
11046         (unless not-saved
11047           (gnus-summary-set-saved-mark article))))
11048     (gnus-kill-buffer save-buffer)
11049     (gnus-summary-position-point)
11050     (gnus-set-mode-line 'summary)
11051     n))
11052
11053 (defun gnus-summary-pipe-output (&optional arg headers)
11054   "Pipe the current article to a subprocess.
11055 If N is a positive number, pipe the N next articles.
11056 If N is a negative number, pipe the N previous articles.
11057 If N is nil and any articles have been marked with the process mark,
11058 pipe those articles instead.
11059 If HEADERS (the symbolic prefix), include the headers, too."
11060   (interactive (gnus-interactive "P\ny"))
11061   (require 'gnus-art)
11062   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11063         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11064     (gnus-summary-save-article arg t))
11065   (let ((buffer (get-buffer "*Shell Command Output*")))
11066     (when (and buffer
11067                (not (zerop (buffer-size buffer))))
11068       (gnus-configure-windows 'pipe))))
11069
11070 (defun gnus-summary-save-article-mail (&optional arg)
11071   "Append the current article to an mail file.
11072 If N is a positive number, save the N next articles.
11073 If N is a negative number, save the N previous articles.
11074 If N is nil and any articles have been marked with the process mark,
11075 save those articles instead."
11076   (interactive "P")
11077   (require 'gnus-art)
11078   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11079     (gnus-summary-save-article arg)))
11080
11081 (defun gnus-summary-save-article-rmail (&optional arg)
11082   "Append the current article to an rmail file.
11083 If N is a positive number, save the N next articles.
11084 If N is a negative number, save the N previous articles.
11085 If N is nil and any articles have been marked with the process mark,
11086 save those articles instead."
11087   (interactive "P")
11088   (require 'gnus-art)
11089   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11090     (gnus-summary-save-article arg)))
11091
11092 (defun gnus-summary-save-article-file (&optional arg)
11093   "Append the current article to a file.
11094 If N is a positive number, save the N next articles.
11095 If N is a negative number, save the N previous articles.
11096 If N is nil and any articles have been marked with the process mark,
11097 save those articles instead."
11098   (interactive "P")
11099   (require 'gnus-art)
11100   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11101     (gnus-summary-save-article arg)))
11102
11103 (defun gnus-summary-write-article-file (&optional arg)
11104   "Write the current article to a file, deleting the previous file.
11105 If N is a positive number, save the N next articles.
11106 If N is a negative number, save the N previous articles.
11107 If N is nil and any articles have been marked with the process mark,
11108 save those articles instead."
11109   (interactive "P")
11110   (require 'gnus-art)
11111   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11112     (gnus-summary-save-article arg)))
11113
11114 (defun gnus-summary-save-article-body-file (&optional arg)
11115   "Append the current article body to a file.
11116 If N is a positive number, save the N next articles.
11117 If N is a negative number, save the N previous articles.
11118 If N is nil and any articles have been marked with the process mark,
11119 save those articles instead."
11120   (interactive "P")
11121   (require 'gnus-art)
11122   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11123     (gnus-summary-save-article arg)))
11124
11125 (defun gnus-summary-muttprint (&optional arg)
11126   "Print the current article using Muttprint.
11127 If N is a positive number, save the N next articles.
11128 If N is a negative number, save the N previous articles.
11129 If N is nil and any articles have been marked with the process mark,
11130 save those articles instead."
11131   (interactive "P")
11132   (require 'gnus-art)
11133   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11134     (gnus-summary-save-article arg t)))
11135
11136 (defun gnus-summary-pipe-message (program)
11137   "Pipe the current article through PROGRAM."
11138   (interactive "sProgram: ")
11139   (gnus-summary-select-article)
11140   (let ((mail-header-separator ""))
11141     (gnus-eval-in-buffer-window gnus-article-buffer
11142       (save-restriction
11143         (widen)
11144         (let ((start (window-start))
11145               buffer-read-only)
11146           (message-pipe-buffer-body program)
11147           (set-window-start (get-buffer-window (current-buffer)) start))))))
11148
11149 (defun gnus-get-split-value (methods)
11150   "Return a value based on the split METHODS."
11151   (let (split-name method result match)
11152     (when methods
11153       (save-excursion
11154         (set-buffer gnus-original-article-buffer)
11155         (save-restriction
11156           (nnheader-narrow-to-headers)
11157           (while (and methods (not split-name))
11158             (goto-char (point-min))
11159             (setq method (pop methods))
11160             (setq match (car method))
11161             (when (cond
11162                    ((stringp match)
11163                     ;; Regular expression.
11164                     (ignore-errors
11165                       (re-search-forward match nil t)))
11166                    ((functionp match)
11167                     ;; Function.
11168                     (save-restriction
11169                       (widen)
11170                       (setq result (funcall match gnus-newsgroup-name))))
11171                    ((consp match)
11172                     ;; Form.
11173                     (save-restriction
11174                       (widen)
11175                       (setq result (eval match)))))
11176               (setq split-name (cdr method))
11177               (cond ((stringp result)
11178                      (push (expand-file-name
11179                             result gnus-article-save-directory)
11180                            split-name))
11181                     ((consp result)
11182                      (setq split-name (append result split-name)))))))))
11183     (nreverse split-name)))
11184
11185 (defun gnus-valid-move-group-p (group)
11186   (and (boundp group)
11187        (symbol-name group)
11188        (symbol-value group)
11189        (gnus-get-function (gnus-find-method-for-group
11190                            (symbol-name group)) 'request-accept-article t)))
11191
11192 (defun gnus-read-move-group-name (prompt default articles prefix)
11193   "Read a group name."
11194   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11195          (minibuffer-confirm-incomplete nil) ; XEmacs
11196          (prom
11197           (format "%s %s to:"
11198                   prompt
11199                   (if (> (length articles) 1)
11200                       (format "these %d articles" (length articles))
11201                     "this article")))
11202          (to-newsgroup
11203           (cond
11204            ((null split-name)
11205             (gnus-completing-read-with-default
11206              default prom
11207              gnus-active-hashtb
11208              'gnus-valid-move-group-p
11209              nil prefix
11210              'gnus-group-history))
11211            ((= 1 (length split-name))
11212             (gnus-completing-read-with-default
11213              (car split-name) prom
11214              gnus-active-hashtb
11215              'gnus-valid-move-group-p
11216              nil nil
11217              'gnus-group-history))
11218            (t
11219             (gnus-completing-read-with-default
11220              nil prom
11221              (mapcar 'list (nreverse split-name))
11222              nil nil nil
11223              'gnus-group-history))))
11224          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11225     (when to-newsgroup
11226       (if (or (string= to-newsgroup "")
11227               (string= to-newsgroup prefix))
11228           (setq to-newsgroup default))
11229       (unless to-newsgroup
11230         (error "No group name entered"))
11231       (or (gnus-active to-newsgroup)
11232           (gnus-activate-group to-newsgroup nil nil to-method)
11233           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11234                                      to-newsgroup))
11235               (or (and (gnus-request-create-group to-newsgroup to-method)
11236                        (gnus-activate-group
11237                         to-newsgroup nil nil to-method)
11238                        (gnus-subscribe-group to-newsgroup))
11239                   (error "Couldn't create group %s" to-newsgroup)))
11240           (error "No such group: %s" to-newsgroup)))
11241     to-newsgroup))
11242
11243 (defun gnus-summary-save-parts (type dir n &optional reverse)
11244   "Save parts matching TYPE to DIR.
11245 If REVERSE, save parts that do not match TYPE."
11246   (interactive
11247    (list (read-string "Save parts of type: "
11248                       (or (car gnus-summary-save-parts-type-history)
11249                           gnus-summary-save-parts-default-mime)
11250                       'gnus-summary-save-parts-type-history)
11251          (setq gnus-summary-save-parts-last-directory
11252                (read-file-name "Save to directory: "
11253                                gnus-summary-save-parts-last-directory
11254                                nil t))
11255          current-prefix-arg))
11256   (gnus-summary-iterate n
11257     (let ((gnus-display-mime-function nil)
11258           (gnus-inhibit-treatment t))
11259       (gnus-summary-select-article))
11260     (save-excursion
11261       (set-buffer gnus-article-buffer)
11262       (let ((handles (or gnus-article-mime-handles
11263                          (mm-dissect-buffer nil gnus-article-loose-mime)
11264                          (and gnus-article-emulate-mime
11265                               (mm-uu-dissect)))))
11266         (when handles
11267           (gnus-summary-save-parts-1 type dir handles reverse)
11268           (unless gnus-article-mime-handles ;; Don't destroy this case.
11269             (mm-destroy-parts handles)))))))
11270
11271 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11272   (if (stringp (car handle))
11273       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11274               (cdr handle))
11275     (when (if reverse
11276               (not (string-match type (mm-handle-media-type handle)))
11277             (string-match type (mm-handle-media-type handle)))
11278       (let ((file (expand-file-name
11279                    (gnus-map-function
11280                     mm-file-name-rewrite-functions
11281                     (file-name-nondirectory
11282                      (or
11283                       (mail-content-type-get
11284                        (mm-handle-disposition handle) 'filename)
11285                       (mail-content-type-get
11286                        (mm-handle-type handle) 'name)
11287                       (concat gnus-newsgroup-name
11288                               "." (number-to-string
11289                                    (cdr gnus-article-current))))))
11290                    dir)))
11291         (unless (file-exists-p file)
11292           (mm-save-part-to-file handle file))))))
11293
11294 ;; Summary extract commands
11295
11296 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11297   (let ((buffer-read-only nil)
11298         (article (gnus-summary-article-number))
11299         after-article b e)
11300     (unless (gnus-summary-goto-subject article)
11301       (error "No such article: %d" article))
11302     (gnus-summary-position-point)
11303     ;; If all commands are to be bunched up on one line, we collect
11304     ;; them here.
11305     (unless gnus-view-pseudos-separately
11306       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11307             files action)
11308         (while ps
11309           (setq action (cdr (assq 'action (car ps))))
11310           (setq files (list (cdr (assq 'name (car ps)))))
11311           (while (and ps (cdr ps)
11312                       (string= (or action "1")
11313                                (or (cdr (assq 'action (cadr ps))) "2")))
11314             (push (cdr (assq 'name (cadr ps))) files)
11315             (setcdr ps (cddr ps)))
11316           (when files
11317             (when (not (string-match "%s" action))
11318               (push " " files))
11319             (push " " files)
11320             (when (assq 'execute (car ps))
11321               (setcdr (assq 'execute (car ps))
11322                       (funcall (if (string-match "%s" action)
11323                                    'format 'concat)
11324                                action
11325                                (mapconcat
11326                                 (lambda (f)
11327                                   (if (equal f " ")
11328                                       f
11329                                     (shell-quote-argument f)))
11330                                 files " ")))))
11331           (setq ps (cdr ps)))))
11332     (if (and gnus-view-pseudos (not not-view))
11333         (while pslist
11334           (when (assq 'execute (car pslist))
11335             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11336                                   (eq gnus-view-pseudos 'not-confirm)))
11337           (setq pslist (cdr pslist)))
11338       (save-excursion
11339         (while pslist
11340           (setq after-article (or (cdr (assq 'article (car pslist)))
11341                                   (gnus-summary-article-number)))
11342           (gnus-summary-goto-subject after-article)
11343           (forward-line 1)
11344           (setq b (point))
11345           (insert "    " (file-name-nondirectory
11346                           (cdr (assq 'name (car pslist))))
11347                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11348           (setq e (point))
11349           (forward-line -1)             ; back to `b'
11350           (gnus-add-text-properties
11351            b (1- e) (list 'gnus-number gnus-reffed-article-number
11352                           gnus-mouse-face-prop gnus-mouse-face))
11353           (gnus-data-enter
11354            after-article gnus-reffed-article-number
11355            gnus-unread-mark b (car pslist) 0 (- e b))
11356           (setq gnus-newsgroup-unreads
11357                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11358                                          gnus-reffed-article-number))
11359           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11360           (setq pslist (cdr pslist)))))))
11361
11362 (defun gnus-pseudos< (p1 p2)
11363   (let ((c1 (cdr (assq 'action p1)))
11364         (c2 (cdr (assq 'action p2))))
11365     (and c1 c2 (string< c1 c2))))
11366
11367 (defun gnus-request-pseudo-article (props)
11368   (cond ((assq 'execute props)
11369          (gnus-execute-command (cdr (assq 'execute props)))))
11370   (let ((gnus-current-article (gnus-summary-article-number)))
11371     (gnus-run-hooks 'gnus-mark-article-hook)))
11372
11373 (defun gnus-execute-command (command &optional automatic)
11374   (save-excursion
11375     (gnus-article-setup-buffer)
11376     (set-buffer gnus-article-buffer)
11377     (setq buffer-read-only nil)
11378     (let ((command (if automatic command
11379                      (read-string "Command: " (cons command 0)))))
11380       (erase-buffer)
11381       (insert "$ " command "\n\n")
11382       (if gnus-view-pseudo-asynchronously
11383           (start-process "gnus-execute" (current-buffer) shell-file-name
11384                          shell-command-switch command)
11385         (call-process shell-file-name nil t nil
11386                       shell-command-switch command)))))
11387
11388 ;; Summary kill commands.
11389
11390 (defun gnus-summary-edit-global-kill (article)
11391   "Edit the \"global\" kill file."
11392   (interactive (list (gnus-summary-article-number)))
11393   (gnus-group-edit-global-kill article))
11394
11395 (defun gnus-summary-edit-local-kill ()
11396   "Edit a local kill file applied to the current newsgroup."
11397   (interactive)
11398   (setq gnus-current-headers (gnus-summary-article-header))
11399   (gnus-group-edit-local-kill
11400    (gnus-summary-article-number) gnus-newsgroup-name))
11401
11402 ;;; Header reading.
11403
11404 (defun gnus-read-header (id &optional header)
11405   "Read the headers of article ID and enter them into the Gnus system."
11406   (let ((group gnus-newsgroup-name)
11407         (gnus-override-method
11408          (or
11409           gnus-override-method
11410           (and (gnus-news-group-p gnus-newsgroup-name)
11411                (car (gnus-refer-article-methods)))))
11412         where)
11413     ;; First we check to see whether the header in question is already
11414     ;; fetched.
11415     (if (stringp id)
11416         ;; This is a Message-ID.
11417         (setq header (or header (gnus-id-to-header id)))
11418       ;; This is an article number.
11419       (setq header (or header (gnus-summary-article-header id))))
11420     (if (and header
11421              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11422         ;; We have found the header.
11423         header
11424       ;; We have to really fetch the header to this article.
11425       (save-excursion
11426         (set-buffer nntp-server-buffer)
11427         (when (setq where (gnus-request-head id group))
11428           (nnheader-fold-continuation-lines)
11429           (goto-char (point-max))
11430           (insert ".\n")
11431           (goto-char (point-min))
11432           (insert "211 ")
11433           (princ (cond
11434                   ((numberp id) id)
11435                   ((cdr where) (cdr where))
11436                   (header (mail-header-number header))
11437                   (t gnus-reffed-article-number))
11438                  (current-buffer))
11439           (insert " Article retrieved.\n"))
11440         (if (or (not where)
11441                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11442             ()                          ; Malformed head.
11443           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11444             (when (and (stringp id)
11445                        (not (string= (gnus-group-real-name group)
11446                                      (car where))))
11447               ;; If we fetched by Message-ID and the article came
11448               ;; from a different group, we fudge some bogus article
11449               ;; numbers for this article.
11450               (mail-header-set-number header gnus-reffed-article-number))
11451             (save-excursion
11452               (set-buffer gnus-summary-buffer)
11453               (decf gnus-reffed-article-number)
11454               (gnus-remove-header (mail-header-number header))
11455               (push header gnus-newsgroup-headers)
11456               (setq gnus-current-headers header)
11457               (push (mail-header-number header) gnus-newsgroup-limit)))
11458           header)))))
11459
11460 (defun gnus-remove-header (number)
11461   "Remove header NUMBER from `gnus-newsgroup-headers'."
11462   (if (and gnus-newsgroup-headers
11463            (= number (mail-header-number (car gnus-newsgroup-headers))))
11464       (pop gnus-newsgroup-headers)
11465     (let ((headers gnus-newsgroup-headers))
11466       (while (and (cdr headers)
11467                   (not (= number (mail-header-number (cadr headers)))))
11468         (pop headers))
11469       (when (cdr headers)
11470         (setcdr headers (cddr headers))))))
11471
11472 ;;;
11473 ;;; summary highlights
11474 ;;;
11475
11476 (defun gnus-highlight-selected-summary ()
11477   "Highlight selected article in summary buffer."
11478   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11479   (when gnus-summary-selected-face
11480     (save-excursion
11481       (let* ((beg (point-at-bol))
11482              (end (point-at-eol))
11483              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11484              (from (if (get-text-property beg gnus-mouse-face-prop)
11485                        beg
11486                      (or (next-single-property-change
11487                           beg gnus-mouse-face-prop nil end)
11488                          beg)))
11489              (to
11490               (if (= from end)
11491                   (- from 2)
11492                 (or (next-single-property-change
11493                      from gnus-mouse-face-prop nil end)
11494                     end))))
11495         ;; If no mouse-face prop on line we will have to = from = end,
11496         ;; so we highlight the entire line instead.
11497         (when (= (+ to 2) from)
11498           (setq from beg)
11499           (setq to end))
11500         (if gnus-newsgroup-selected-overlay
11501             ;; Move old overlay.
11502             (gnus-move-overlay
11503              gnus-newsgroup-selected-overlay from to (current-buffer))
11504           ;; Create new overlay.
11505           (gnus-overlay-put
11506            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11507            'face gnus-summary-selected-face))))))
11508
11509 (defvar gnus-summary-highlight-line-cached nil)
11510 (defvar gnus-summary-highlight-line-trigger nil)
11511
11512 (defun gnus-summary-highlight-line-0 ()
11513   (if (and (eq gnus-summary-highlight-line-trigger
11514                gnus-summary-highlight)
11515            gnus-summary-highlight-line-cached)
11516       gnus-summary-highlight-line-cached
11517     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11518           gnus-summary-highlight-line-cached
11519           (let* ((cond (list 'cond))
11520                  (c cond)
11521                  (list gnus-summary-highlight))
11522             (while list
11523               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11524                               nil))
11525               (setq c (cdr c)
11526                     list (cdr list)))
11527             (gnus-byte-compile (list 'lambda nil cond))))))
11528
11529 (defun gnus-summary-highlight-line ()
11530   "Highlight current line according to `gnus-summary-highlight'."
11531   (let* ((beg (point-at-bol))
11532          (article (or (gnus-summary-article-number) gnus-current-article))
11533          (score (or (cdr (assq article
11534                                gnus-newsgroup-scored))
11535                     gnus-summary-default-score 0))
11536          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11537          (inhibit-read-only t)
11538          (default gnus-summary-default-score)
11539          (default-high gnus-summary-default-high-score)
11540          (default-low gnus-summary-default-low-score)
11541          (uncached (and gnus-summary-use-undownloaded-faces
11542                         (memq article gnus-newsgroup-undownloaded)
11543                         (not (memq article gnus-newsgroup-cached)))))
11544     (let ((face (funcall (gnus-summary-highlight-line-0))))
11545       (unless (eq face (get-text-property beg 'face))
11546         (gnus-put-text-property-excluding-characters-with-faces
11547          beg (point-at-eol) 'face
11548          (setq face (if (boundp face) (symbol-value face) face)))
11549         (when gnus-summary-highlight-line-function
11550           (funcall gnus-summary-highlight-line-function article face))))))
11551
11552 (defun gnus-update-read-articles (group unread &optional compute)
11553   "Update the list of read articles in GROUP.
11554 UNREAD is a sorted list."
11555   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11556         (info (gnus-get-info group))
11557         (prev 1)
11558         read)
11559     (if (or (not info) (not active))
11560         ;; There is no info on this group if it was, in fact,
11561         ;; killed.  Gnus stores no information on killed groups, so
11562         ;; there's nothing to be done.
11563         ;; One could store the information somewhere temporarily,
11564         ;; perhaps...  Hmmm...
11565         ()
11566       ;; Remove any negative articles numbers.
11567       (while (and unread (< (car unread) 0))
11568         (setq unread (cdr unread)))
11569       ;; Remove any expired article numbers
11570       (while (and unread (< (car unread) (car active)))
11571         (setq unread (cdr unread)))
11572       ;; Compute the ranges of read articles by looking at the list of
11573       ;; unread articles.
11574       (while unread
11575         (when (/= (car unread) prev)
11576           (push (if (= prev (1- (car unread))) prev
11577                   (cons prev (1- (car unread))))
11578                 read))
11579         (setq prev (1+ (car unread)))
11580         (setq unread (cdr unread)))
11581       (when (<= prev (cdr active))
11582         (push (cons prev (cdr active)) read))
11583       (setq read (if (> (length read) 1) (nreverse read) read))
11584       (if compute
11585           read
11586         (save-excursion
11587           (let (setmarkundo)
11588             ;; Propagate the read marks to the backend.
11589             (when (gnus-check-backend-function 'request-set-mark group)
11590               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11591                     (add (gnus-remove-from-range read (gnus-info-read info))))
11592                 (when (or add del)
11593                   (unless (gnus-check-group group)
11594                     (error "Can't open server for %s" group))
11595                   (gnus-request-set-mark
11596                    group (delq nil (list (if add (list add 'add '(read)))
11597                                          (if del (list del 'del '(read))))))
11598                   (setq setmarkundo
11599                         `(gnus-request-set-mark
11600                           ,group
11601                           ',(delq nil (list
11602                                        (if del (list del 'add '(read)))
11603                                        (if add (list add 'del '(read))))))))))
11604             (set-buffer gnus-group-buffer)
11605             (gnus-undo-register
11606               `(progn
11607                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11608                  (gnus-info-set-read ',info ',(gnus-info-read info))
11609                  (gnus-get-unread-articles-in-group ',info
11610                                                     (gnus-active ,group))
11611                  (gnus-group-update-group ,group t)
11612                  ,setmarkundo))))
11613         ;; Enter this list into the group info.
11614         (gnus-info-set-read info read)
11615         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11616         (gnus-get-unread-articles-in-group info (gnus-active group))
11617         t))))
11618
11619 (defun gnus-offer-save-summaries ()
11620   "Offer to save all active summary buffers."
11621   (let (buffers)
11622     ;; Go through all buffers and find all summaries.
11623     (dolist (buffer (buffer-list))
11624       (when (and (setq buffer (buffer-name buffer))
11625                  (string-match "Summary" buffer)
11626                  (with-current-buffer buffer
11627                    ;; We check that this is, indeed, a summary buffer.
11628                    (and (eq major-mode 'gnus-summary-mode)
11629                         ;; Also make sure this isn't bogus.
11630                         gnus-newsgroup-prepared
11631                         ;; Also make sure that this isn't a
11632                         ;; dead summary buffer.
11633                         (not gnus-dead-summary-mode))))
11634         (push buffer buffers)))
11635     ;; Go through all these summary buffers and offer to save them.
11636     (when buffers
11637       (save-excursion
11638         (map-y-or-n-p
11639          "Update summary buffer %s? "
11640          (lambda (buf)
11641            (switch-to-buffer buf)
11642            (gnus-summary-exit))
11643          buffers)))))
11644
11645 (defun gnus-summary-setup-default-charset ()
11646   "Setup newsgroup default charset."
11647   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11648       (setq gnus-newsgroup-charset nil)
11649     (let* ((ignored-charsets
11650             (or gnus-newsgroup-ephemeral-ignored-charsets
11651                 (append
11652                  (and gnus-newsgroup-name
11653                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11654                  gnus-newsgroup-ignored-charsets))))
11655       (setq gnus-newsgroup-charset
11656             (or gnus-newsgroup-ephemeral-charset
11657                 (and gnus-newsgroup-name
11658                      (gnus-parameter-charset gnus-newsgroup-name))
11659                 gnus-default-charset))
11660       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11661            ignored-charsets))))
11662
11663 ;;;
11664 ;;; Mime Commands
11665 ;;;
11666
11667 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11668   "Display the current article buffer fully MIME-buttonized.
11669 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11670 treated as multipart/mixed."
11671   (interactive "P")
11672   (require 'gnus-art)
11673   (let ((gnus-unbuttonized-mime-types nil)
11674         (gnus-mime-display-multipart-as-mixed show-all-parts))
11675     (gnus-summary-show-article)))
11676
11677 (defun gnus-summary-repair-multipart (article)
11678   "Add a Content-Type header to a multipart article without one."
11679   (interactive (list (gnus-summary-article-number)))
11680   (gnus-with-article article
11681     (message-narrow-to-head)
11682     (message-remove-header "Mime-Version")
11683     (goto-char (point-max))
11684     (insert "Mime-Version: 1.0\n")
11685     (widen)
11686     (when (search-forward "\n--" nil t)
11687       (let ((separator (buffer-substring (point) (point-at-eol))))
11688         (message-narrow-to-head)
11689         (message-remove-header "Content-Type")
11690         (goto-char (point-max))
11691         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11692                         separator))
11693         (widen))))
11694   (let (gnus-mark-article-hook)
11695     (gnus-summary-select-article t t nil article)))
11696
11697 (defun gnus-summary-toggle-display-buttonized ()
11698   "Toggle the buttonizing of the article buffer."
11699   (interactive)
11700   (require 'gnus-art)
11701   (if (setq gnus-inhibit-mime-unbuttonizing
11702             (not gnus-inhibit-mime-unbuttonizing))
11703       (let ((gnus-unbuttonized-mime-types nil))
11704         (gnus-summary-show-article))
11705     (gnus-summary-show-article)))
11706
11707 ;;;
11708 ;;; Generic summary marking commands
11709 ;;;
11710
11711 (defvar gnus-summary-marking-alist
11712   '((read gnus-del-mark "d")
11713     (unread gnus-unread-mark "u")
11714     (ticked gnus-ticked-mark "!")
11715     (dormant gnus-dormant-mark "?")
11716     (expirable gnus-expirable-mark "e"))
11717   "An alist of names/marks/keystrokes.")
11718
11719 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11720 (defvar gnus-summary-mark-map)
11721
11722 (defun gnus-summary-make-all-marking-commands ()
11723   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11724   (dolist (elem gnus-summary-marking-alist)
11725     (apply 'gnus-summary-make-marking-command elem)))
11726
11727 (defun gnus-summary-make-marking-command (name mark keystroke)
11728   (let ((map (make-sparse-keymap)))
11729     (define-key gnus-summary-generic-mark-map keystroke map)
11730     (dolist (lway `((next "next" next nil "n")
11731                     (next-unread "next unread" next t "N")
11732                     (prev "previous" prev nil "p")
11733                     (prev-unread "previous unread" prev t "P")
11734                     (nomove "" nil nil ,keystroke)))
11735       (let ((func (gnus-summary-make-marking-command-1
11736                    mark (car lway) lway name)))
11737         (setq func (eval func))
11738         (define-key map (nth 4 lway) func)))))
11739
11740 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11741   `(defun ,(intern
11742             (format "gnus-summary-put-mark-as-%s%s"
11743                     name (if (eq way 'nomove)
11744                              ""
11745                            (concat "-" (symbol-name way)))))
11746      (n)
11747      ,(format
11748        "Mark the current article as %s%s.
11749 If N, the prefix, then repeat N times.
11750 If N is negative, move in reverse order.
11751 The difference between N and the actual number of articles marked is
11752 returned."
11753        name (cadr lway))
11754      (interactive "p")
11755      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11756
11757 (defun gnus-summary-generic-mark (n mark move unread)
11758   "Mark N articles with MARK."
11759   (unless (eq major-mode 'gnus-summary-mode)
11760     (error "This command can only be used in the summary buffer"))
11761   (gnus-summary-show-thread)
11762   (let ((nummove
11763          (cond
11764           ((eq move 'next) 1)
11765           ((eq move 'prev) -1)
11766           (t 0))))
11767     (if (zerop nummove)
11768         (setq n 1)
11769       (when (< n 0)
11770         (setq n (abs n)
11771               nummove (* -1 nummove))))
11772     (while (and (> n 0)
11773                 (gnus-summary-mark-article nil mark)
11774                 (zerop (gnus-summary-next-subject nummove unread t)))
11775       (setq n (1- n)))
11776     (when (/= 0 n)
11777       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11778     (gnus-summary-recenter)
11779     (gnus-summary-position-point)
11780     (gnus-set-mode-line 'summary)
11781     n))
11782
11783 (defun gnus-summary-insert-articles (articles)
11784   (when (setq articles
11785               (gnus-sorted-difference articles
11786                                       (mapcar (lambda (h)
11787                                                 (mail-header-number h))
11788                                               gnus-newsgroup-headers)))
11789     (setq gnus-newsgroup-headers
11790           (gnus-merge 'list
11791                       gnus-newsgroup-headers
11792                       (gnus-fetch-headers articles)
11793                       'gnus-article-sort-by-number))
11794     ;; Suppress duplicates?
11795     (when gnus-suppress-duplicates
11796       (gnus-dup-suppress-articles))
11797
11798     ;; We might want to build some more threads first.
11799     (when (and gnus-fetch-old-headers
11800                (eq gnus-headers-retrieved-by 'nov))
11801       (if (eq gnus-fetch-old-headers 'invisible)
11802           (gnus-build-all-threads)
11803         (gnus-build-old-threads)))
11804     ;; Let the Gnus agent mark articles as read.
11805     (when gnus-agent
11806       (gnus-agent-get-undownloaded-list))
11807     ;; Remove list identifiers from subject
11808     (when gnus-list-identifiers
11809       (gnus-summary-remove-list-identifiers))
11810     ;; First and last article in this newsgroup.
11811     (when gnus-newsgroup-headers
11812       (setq gnus-newsgroup-begin
11813             (mail-header-number (car gnus-newsgroup-headers))
11814             gnus-newsgroup-end
11815             (mail-header-number
11816              (gnus-last-element gnus-newsgroup-headers))))
11817     (when gnus-use-scoring
11818       (gnus-possibly-score-headers))))
11819
11820 (defun gnus-summary-insert-old-articles (&optional all)
11821   "Insert all old articles in this group.
11822 If ALL is non-nil, already read articles become readable.
11823 If ALL is a number, fetch this number of articles."
11824   (interactive "P")
11825   (prog1
11826       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11827             older len)
11828         (setq older
11829               ;; Some nntp servers lie about their active range.  When
11830               ;; this happens, the active range can be in the millions.
11831               ;; Use a compressed range to avoid creating a huge list.
11832               (gnus-range-difference (list gnus-newsgroup-active) old))
11833         (setq len (gnus-range-length older))
11834         (cond
11835          ((null older) nil)
11836          ((numberp all)
11837           (if (< all len)
11838               (let ((older-range (nreverse older)))
11839                 (setq older nil)
11840
11841                 (while (> all 0)
11842                   (let* ((r (pop older-range))
11843                          (min (if (numberp r) r (car r)))
11844                          (max (if (numberp r) r (cdr r))))
11845                     (while (and (<= min max)
11846                                 (> all 0))
11847                       (push max older)
11848                       (setq all (1- all)
11849                             max (1- max))))))
11850             (setq older (gnus-uncompress-range older))))
11851          (all
11852           (setq older (gnus-uncompress-range older)))
11853          (t
11854           (when (and (numberp gnus-large-newsgroup)
11855                    (> len gnus-large-newsgroup))
11856               (let* ((cursor-in-echo-area nil)
11857                      (initial (gnus-parameter-large-newsgroup-initial
11858                                gnus-newsgroup-name))
11859                      (input
11860                       (read-string
11861                        (format
11862                         "How many articles from %s (%s %d): "
11863                         (gnus-limit-string
11864                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11865                         (if initial "max" "default")
11866                         len)
11867                        (if initial
11868                            (cons (number-to-string initial)
11869                                  0)))))
11870                 (unless (string-match "^[ \t]*$" input)
11871                   (setq all (string-to-number input))
11872                   (if (< all len)
11873                       (let ((older-range (nreverse older)))
11874                         (setq older nil)
11875
11876                         (while (> all 0)
11877                           (let* ((r (pop older-range))
11878                                  (min (if (numberp r) r (car r)))
11879                                  (max (if (numberp r) r (cdr r))))
11880                             (while (and (<= min max)
11881                                         (> all 0))
11882                               (push max older)
11883                               (setq all (1- all)
11884                                     max (1- max))))))))))
11885           (setq older (gnus-uncompress-range older))))
11886         (if (not older)
11887             (message "No old news.")
11888           (gnus-summary-insert-articles older)
11889           (gnus-summary-limit (gnus-sorted-nunion old older))))
11890     (gnus-summary-position-point)))
11891
11892 (defun gnus-summary-insert-new-articles ()
11893   "Insert all new articles in this group."
11894   (interactive)
11895   (prog1
11896       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11897             (old-active gnus-newsgroup-active)
11898             (nnmail-fetched-sources (list t))
11899             i new)
11900         (setq gnus-newsgroup-active
11901               (gnus-activate-group gnus-newsgroup-name 'scan))
11902         (setq i (cdr gnus-newsgroup-active))
11903         (while (> i (cdr old-active))
11904           (push i new)
11905           (decf i))
11906         (if (not new)
11907             (message "No gnus is bad news")
11908           (gnus-summary-insert-articles new)
11909           (setq gnus-newsgroup-unreads
11910                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11911           (gnus-summary-limit (gnus-sorted-nunion old new))))
11912     (gnus-summary-position-point)))
11913
11914 (gnus-summary-make-all-marking-commands)
11915
11916 (gnus-ems-redefine)
11917
11918 (provide 'gnus-sum)
11919
11920 (run-hooks 'gnus-sum-load-hook)
11921
11922 ;; Local Variables:
11923 ;; coding: iso-8859-1
11924 ;; End:
11925
11926 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11927 ;;; gnus-sum.el ends here