* gnus-art.el (gnus-sticky-article): Don't perform gnus-configure-windows here;
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-summary-next-group-on-exit t
66   "If non-nil, go to the next unread newsgroup on summary exit.
67 See `gnus-group-goto-unread'."
68   :link '(custom-manual "(gnus)Group Maneuvering")
69   :group 'gnus-summary-exit
70   :version "23.0" ;; No Gnus
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already
76 read (or just marked as read) article, the old article will not
77 normally be displayed in the Summary buffer.  If this variable is
78 t, Gnus will attempt to grab the headers to the old articles, and
79 thereby build complete threads.  If it has the value `some', all
80 old headers will be fetched but only enough headers to connect
81 otherwise loose threads will be displayed.  This variable can
82 also be a number.  In that case, no more than that number of old
83 headers will be fetched.  If it has the value `invisible', all
84 old headers will be fetched, but none will be displayed.
85
86 The server has to support NOV for any of this to work.
87
88 This feature can seriously impact performance it ignores all
89 locally cached header entries."
90   :group 'gnus-thread
91   :type '(choice (const :tag "off" nil)
92                  (const :tag "on" t)
93                  (const some)
94                  (const invisible)
95                  number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-refer-thread-limit 500
99   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
100 If t, fetch all the available old headers."
101   :group 'gnus-thread
102   :type '(choice number
103                  (sexp :menu-tag "other" t)))
104
105 (defcustom gnus-summary-make-false-root 'adopt
106   "*nil means that Gnus won't gather loose threads.
107 If the root of a thread has expired or been read in a previous
108 session, the information necessary to build a complete thread has been
109 lost.  Instead of having many small sub-threads from this original thread
110 scattered all over the summary buffer, Gnus can gather them.
111
112 If non-nil, Gnus will try to gather all loose sub-threads from an
113 original thread into one large thread.
114
115 If this variable is non-nil, it should be one of `none', `adopt',
116 `dummy' or `empty'.
117
118 If this variable is `none', Gnus will not make a false root, but just
119 present the sub-threads after another.
120 If this variable is `dummy', Gnus will create a dummy root that will
121 have all the sub-threads as children.
122 If this variable is `adopt', Gnus will make one of the \"children\"
123 the parent and mark all the step-children as such.
124 If this variable is `empty', the \"children\" are printed with empty
125 subject fields.  (Or rather, they will be printed with a string
126 given by the `gnus-summary-same-subject' variable.)"
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const none)
130                  (const dummy)
131                  (const adopt)
132                  (const empty)))
133
134 (defcustom gnus-summary-make-false-root-always nil
135   "Always make a false dummy root."
136   :version "22.1"
137   :group 'gnus-thread
138   :type 'boolean)
139
140 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
141   "*A regexp to match subjects to be excluded from loose thread gathering.
142 As loose thread gathering is done on subjects only, that means that
143 there can be many false gatherings performed.  By rooting out certain
144 common subjects, gathering might become saner."
145   :group 'gnus-thread
146   :type 'regexp)
147
148 (defcustom gnus-summary-gather-subject-limit nil
149   "*Maximum length of subject comparisons when gathering loose threads.
150 Use nil to compare full subjects.  Setting this variable to a low
151 number will help gather threads that have been corrupted by
152 newsreaders chopping off subject lines, but it might also mean that
153 unrelated articles that have subject that happen to begin with the
154 same few characters will be incorrectly gathered.
155
156 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
157 comparing subjects."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  (const fuzzy)
161                  (sexp :menu-tag "on" t)))
162
163 (defcustom gnus-simplify-subject-functions nil
164   "List of functions taking a string argument that simplify subjects.
165 The functions are applied recursively.
166
167 Useful functions to put in this list include:
168 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
169 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
170   :group 'gnus-thread
171   :type '(repeat function))
172
173 (defcustom gnus-simplify-ignored-prefixes nil
174   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  regexp))
178
179 (defcustom gnus-build-sparse-threads nil
180   "*If non-nil, fill in the gaps in threads.
181 If `some', only fill in the gaps that are needed to tie loose threads
182 together.  If `more', fill in all leaf nodes that Gnus can find.  If
183 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
184   :group 'gnus-thread
185   :type '(choice (const :tag "off" nil)
186                  (const some)
187                  (const more)
188                  (sexp :menu-tag "all" t)))
189
190 (defcustom gnus-summary-thread-gathering-function
191   'gnus-gather-threads-by-subject
192   "*Function used for gathering loose threads.
193 There are two pre-defined functions: `gnus-gather-threads-by-subject',
194 which only takes Subjects into consideration; and
195 `gnus-gather-threads-by-references', which compared the References
196 headers of the articles to find matches."
197   :group 'gnus-thread
198   :type '(radio (function-item gnus-gather-threads-by-subject)
199                 (function-item gnus-gather-threads-by-references)
200                 (function :tag "other")))
201
202 (defcustom gnus-summary-same-subject ""
203   "*String indicating that the current article has the same subject as the previous.
204 This variable will only be used if the value of
205 `gnus-summary-make-false-root' is `empty'."
206   :group 'gnus-summary-format
207   :type 'string)
208
209 (defcustom gnus-summary-goto-unread t
210   "*If t, many commands will go to the next unread article.
211 This applies to marking commands as well as other commands that
212 \"naturally\" select the next article, like, for instance, `SPC' at
213 the end of an article.
214
215 If nil, the marking commands do NOT go to the next unread article
216 \(they go to the next article instead).  If `never', commands that
217 usually go to the next unread article, will go to the next article,
218 whether it is read or not."
219   :group 'gnus-summary-marks
220   :link '(custom-manual "(gnus)Setting Marks")
221   :type '(choice (const :tag "off" nil)
222                  (const never)
223                  (sexp :menu-tag "on" t)))
224
225 (defcustom gnus-summary-default-score 0
226   "*Default article score level.
227 All scores generated by the score files will be added to this score.
228 If this variable is nil, scoring will be disabled."
229   :group 'gnus-score-default
230   :type '(choice (const :tag "disable")
231                  integer))
232
233 (defcustom gnus-summary-default-high-score 0
234   "*Default threshold for a high scored article.
235 An article will be highlighted as high scored if its score is greater
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-default-low-score 0
242   "*Default threshold for a low scored article.
243 An article will be highlighted as low scored if its score is smaller
244 than this score."
245   :version "22.1"
246   :group 'gnus-score-default
247   :type 'integer)
248
249 (defcustom gnus-summary-zcore-fuzz 0
250   "*Fuzziness factor for the zcore in the summary buffer.
251 Articles with scores closer than this to `gnus-summary-default-score'
252 will not be marked."
253   :group 'gnus-summary-format
254   :type 'integer)
255
256 (defcustom gnus-simplify-subject-fuzzy-regexp nil
257   "*Strings to be removed when doing fuzzy matches.
258 This can either be a regular expression or list of regular expressions
259 that will be removed from subject strings if fuzzy subject
260 simplification is selected."
261   :group 'gnus-thread
262   :type '(repeat regexp))
263
264 (defcustom gnus-show-threads t
265   "*If non-nil, display threads in summary mode."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-subtree nil
270   "*If non-nil, hide all threads initially.
271 This can be a predicate specifier which says which threads to hide.
272 If threads are hidden, you have to run the command
273 `gnus-summary-show-thread' by hand or select an article."
274   :group 'gnus-thread
275   :type '(radio (sexp :format "Non-nil\n"
276                       :match (lambda (widget value)
277                                (not (or (consp value) (functionp value))))
278                       :value t)
279                 (const nil)
280                 (sexp :tag "Predicate specifier")))
281
282 (defcustom gnus-thread-hide-killed t
283   "*If non-nil, hide killed threads automatically."
284   :group 'gnus-thread
285   :type 'boolean)
286
287 (defcustom gnus-thread-ignore-subject t
288   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
289 If nil, articles that have different subjects from their parents will
290 start separate threads."
291   :group 'gnus-thread
292   :type 'boolean)
293
294 (defcustom gnus-thread-operation-ignore-subject t
295   "*If non-nil, subjects will be ignored when doing thread commands.
296 This affects commands like `gnus-summary-kill-thread' and
297 `gnus-summary-lower-thread'.
298
299 If this variable is nil, articles in the same thread with different
300 subjects will not be included in the operation in question.  If this
301 variable is `fuzzy', only articles that have subjects that are fuzzily
302 equal will be included."
303   :group 'gnus-thread
304   :type '(choice (const :tag "off" nil)
305                  (const fuzzy)
306                  (sexp :tag "on" t)))
307
308 (defcustom gnus-thread-indent-level 4
309   "*Number that says how much each sub-thread should be indented."
310   :group 'gnus-thread
311   :type 'integer)
312
313 (defcustom gnus-auto-extend-newsgroup t
314   "*If non-nil, extend newsgroup forward and backward when requested."
315   :group 'gnus-summary-choose
316   :type 'boolean)
317
318 (defcustom gnus-auto-select-first t
319   "If non-nil, select an article on group entry.
320 An article is selected automatically when entering a group
321 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
322 `gnus-summary-catchup-and-goto-next-group'.
323
324 Which article is selected is controlled by the variable
325 `gnus-auto-select-subject'.
326
327 If you want to prevent automatic selection of articles in some
328 newsgroups, set the variable to nil in `gnus-select-group-hook'."
329   ;; Commands include...
330   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
331   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
332   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
333   :group 'gnus-group-select
334   :type '(choice (const :tag "none" nil)
335                  (sexp :menu-tag "first" t)))
336
337 (defcustom gnus-auto-select-subject 'unread
338   "*Says what subject to place under point when entering a group.
339
340 This variable can either be the symbols `first' (place point on the
341 first subject), `unread' (place point on the subject line of the first
342 unread article), `best' (place point on the subject line of the
343 higest-scored article), `unseen' (place point on the subject line of
344 the first unseen article), `unseen-or-unread' (place point on the subject
345 line of the first unseen article or, if all article have been seen, on the
346 subject line of the first unread article), or a function to be called to
347 place point on some subject line."
348   :version "22.1"
349   :group 'gnus-group-select
350   :type '(choice (const best)
351                  (const unread)
352                  (const first)
353                  (const unseen)
354                  (const unseen-or-unread)))
355
356 (defcustom gnus-auto-select-next t
357   "*If non-nil, offer to go to the next group from the end of the previous.
358 If the value is t and the next newsgroup is empty, Gnus will exit
359 summary mode and go back to group mode.  If the value is neither nil
360 nor t, Gnus will select the following unread newsgroup.  In
361 particular, if the value is the symbol `quietly', the next unread
362 newsgroup will be selected without any confirmation, and if it is
363 `almost-quietly', the next group will be selected without any
364 confirmation if you are located on the last article in the group.
365 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
366 will go to the next group without confirmation."
367   :group 'gnus-summary-maneuvering
368   :type '(choice (const :tag "off" nil)
369                  (const quietly)
370                  (const almost-quietly)
371                  (const slightly-quietly)
372                  (sexp :menu-tag "on" t)))
373
374 (defcustom gnus-auto-select-same nil
375   "*If non-nil, select the next article with the same subject.
376 If there are no more articles with the same subject, go to
377 the first unread article."
378   :group 'gnus-summary-maneuvering
379   :type 'boolean)
380
381 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
382   "What article should be selected after exiting an ephemeral group.
383 Valid values include:
384
385 `next'
386   Select the next article.
387 `next-unread'
388   Select the next unread article.
389 `next-noselect'
390   Move the cursor to the next article.  This is the default.
391 `next-unread-noselect'
392   Move the cursor to the next unread article.
393
394 If it has any other value or there is no next (unread) article, the
395 article selected before entering to the ephemeral group will appear."
396   :version "23.0" ;; No Gnus
397   :group 'gnus-summary-maneuvering
398   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
399                  (const next) (const next-unread)
400                  (const next-noselect) (const next-unread-noselect)
401                  (sexp :tag "other" :value nil)))
402
403 (defcustom gnus-auto-goto-ignores 'unfetched
404   "*Says how to handle unfetched articles when maneuvering.
405
406 This variable can either be the symbols nil (maneuver to any
407 article), `undownloaded' (maneuvering while unplugged ignores articles
408 that have not been fetched), `always-undownloaded' (maneuvering always
409 ignores articles that have not been fetched), `unfetched' (maneuvering
410 ignores articles whose headers have not been fetched).
411
412 NOTE: The list of unfetched articles will always be nil when plugged
413 and, when unplugged, a subset of the undownloaded article list."
414   :version "22.1"
415   :group 'gnus-summary-maneuvering
416   :type '(choice (const :tag "None" nil)
417                  (const :tag "Undownloaded when unplugged" undownloaded)
418                  (const :tag "Undownloaded" always-undownloaded)
419                  (const :tag "Unfetched" unfetched)))
420
421 (defcustom gnus-summary-check-current nil
422   "*If non-nil, consider the current article when moving.
423 The \"unread\" movement commands will stay on the same line if the
424 current article is unread."
425   :group 'gnus-summary-maneuvering
426   :type 'boolean)
427
428 (defcustom gnus-auto-center-summary 2
429   "*If non-nil, always center the current summary buffer.
430 In particular, if `vertical' do only vertical recentering.  If non-nil
431 and non-`vertical', do both horizontal and vertical recentering."
432   :group 'gnus-summary-maneuvering
433   :type '(choice (const :tag "none" nil)
434                  (const vertical)
435                  (integer :tag "height")
436                  (sexp :menu-tag "both" t)))
437
438 (defvar gnus-auto-center-group t
439   "*If non-nil, always center the group buffer.")
440
441 (defcustom gnus-show-all-headers nil
442   "*If non-nil, don't hide any headers."
443   :group 'gnus-article-hiding
444   :group 'gnus-article-headers
445   :type 'boolean)
446
447 (defcustom gnus-summary-ignore-duplicates nil
448   "*If non-nil, ignore articles with identical Message-ID headers."
449   :group 'gnus-summary
450   :type 'boolean)
451
452 (defcustom gnus-single-article-buffer t
453   "*If non-nil, display all articles in the same buffer.
454 If nil, each group will get its own article buffer."
455   :group 'gnus-article-various
456   :type 'boolean)
457
458 (defcustom gnus-break-pages t
459   "*If non-nil, do page breaking on articles.
460 The page delimiter is specified by the `gnus-page-delimiter'
461 variable."
462   :group 'gnus-article-various
463   :type 'boolean)
464
465 (defcustom gnus-move-split-methods nil
466   "*Variable used to suggest where articles are to be moved to.
467 It uses the same syntax as the `gnus-split-methods' variable.
468 However, whereas `gnus-split-methods' specifies file names as targets,
469 this variable specifies group names."
470   :group 'gnus-summary-mail
471   :type '(repeat (choice (list :value (fun) function)
472                          (cons :value ("" "") regexp (repeat string))
473                          (sexp :value nil))))
474
475 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
476   "Function used to compute default prefix for article move/copy/etc prompts.
477 The function should take one argument, a group name, and return a
478 string with the suggested prefix."
479   :group 'gnus-summary-mail
480   :type 'function)
481
482 ;; FIXME: Although the custom type is `character' for the following variables,
483 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
484
485 (defcustom gnus-unread-mark ?           ;Whitespace
486   "*Mark used for unread articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-ticked-mark ?!
491   "*Mark used for ticked articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-dormant-mark ??
496   "*Mark used for dormant articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-del-mark ?r
501   "*Mark used for del'd articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-read-mark ?R
506   "*Mark used for read articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-expirable-mark ?E
511   "*Mark used for expirable articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-killed-mark ?K
516   "*Mark used for killed articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-spam-mark ?$
521   "*Mark used for spam articles."
522   :version "22.1"
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-souped-mark ?F
527   "*Mark used for souped articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-kill-file-mark ?X
532   "*Mark used for articles killed by kill files."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-low-score-mark ?Y
537   "*Mark used for articles with a low score."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-catchup-mark ?C
542   "*Mark used for articles that are caught up."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-replied-mark ?A
547   "*Mark used for articles that have been replied to."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-forwarded-mark ?F
552   "*Mark used for articles that have been forwarded."
553   :version "22.1"
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-recent-mark ?N
558   "*Mark used for articles that are recent."
559   :version "22.1"
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-cached-mark ?*
564   "*Mark used for articles that are in the cache."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-saved-mark ?S
569   "*Mark used for articles that have been saved."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-unseen-mark ?.
574   "*Mark used for articles that haven't been seen."
575   :version "22.1"
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-no-mark ?               ;Whitespace
580   "*Mark used for articles that have no other secondary mark."
581   :version "22.1"
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-ancient-mark ?O
586   "*Mark used for ancient articles."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-sparse-mark ?Q
591   "*Mark used for sparsely reffed articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-canceled-mark ?G
596   "*Mark used for canceled articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-duplicate-mark ?M
601   "*Mark used for duplicate articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-undownloaded-mark ?-
606   "*Mark used for articles that weren't downloaded."
607   :version "22.1"
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-downloaded-mark ?+
612   "*Mark used for articles that were downloaded."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloadable-mark ?%
617   "*Mark used for articles that are to be downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-unsendable-mark ?=
622   "*Mark used for articles that won't be sent."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-score-over-mark ?+
627   "*Score mark used for articles with high scores."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-below-mark ?-
632   "*Score mark used for articles with low scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-empty-thread-mark ?     ;Whitespace
637   "*There is no thread under the article."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-not-empty-thread-mark ?=
642   "*There is a thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-view-pseudo-asynchronously nil
647   "*If non-nil, Gnus will view pseudo-articles asynchronously."
648   :group 'gnus-extract-view
649   :type 'boolean)
650
651 (defcustom gnus-auto-expirable-marks
652   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
653         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
654         gnus-souped-mark gnus-duplicate-mark)
655   "*The list of marks converted into expiration if a group is auto-expirable."
656   :version "21.1"
657   :group 'gnus-summary
658   :type '(repeat character))
659
660 (defcustom gnus-inhibit-user-auto-expire t
661   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
662   :version "21.1"
663   :group 'gnus-summary
664   :type 'boolean)
665
666 (defcustom gnus-view-pseudos nil
667   "*If `automatic', pseudo-articles will be viewed automatically.
668 If `not-confirm', pseudos will be viewed automatically, and the user
669 will not be asked to confirm the command."
670   :group 'gnus-extract-view
671   :type '(choice (const :tag "off" nil)
672                  (const automatic)
673                  (const not-confirm)))
674
675 (defcustom gnus-view-pseudos-separately t
676   "*If non-nil, one pseudo-article will be created for each file to be viewed.
677 If nil, all files that use the same viewing command will be given as a
678 list of parameters to that command."
679   :group 'gnus-extract-view
680   :type 'boolean)
681
682 (defcustom gnus-insert-pseudo-articles t
683   "*If non-nil, insert pseudo-articles when decoding articles."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-summary-dummy-line-format
688   "   %(:                             :%) %S\n"
689   "*The format specification for the dummy roots in the summary buffer.
690 It works along the same lines as a normal formatting string,
691 with some simple extensions.
692
693 %S  The subject
694
695 General format specifiers can also be used.
696 See `(gnus)Formatting Variables'."
697   :link '(custom-manual "(gnus)Formatting Variables")
698   :group 'gnus-threading
699   :type 'string)
700
701 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
702   "*The format specification for the summary mode line.
703 It works along the same lines as a normal formatting string,
704 with some simple extensions:
705
706 %G  Group name
707 %p  Unprefixed group name
708 %A  Current article number
709 %z  Current article score
710 %V  Gnus version
711 %U  Number of unread articles in the group
712 %e  Number of unselected articles in the group
713 %Z  A string with unread/unselected article counts
714 %g  Shortish group name
715 %S  Subject of the current article
716 %u  User-defined spec
717 %s  Current score file name
718 %d  Number of dormant articles
719 %r  Number of articles that have been marked as read in this session
720 %E  Number of articles expunged by the score files"
721   :group 'gnus-summary-format
722   :type 'string)
723
724 (defcustom gnus-list-identifiers nil
725   "Regexp that matches list identifiers to be removed from subject.
726 This can also be a list of regexps."
727   :version "21.1"
728   :group 'gnus-summary-format
729   :group 'gnus-article-hiding
730   :type '(choice (const :tag "none" nil)
731                  (regexp :value ".*")
732                  (repeat :value (".*") regexp)))
733
734 (defcustom gnus-summary-mark-below 0
735   "*Mark all articles with a score below this variable as read.
736 This variable is local to each summary buffer and usually set by the
737 score file."
738   :group 'gnus-score-default
739   :type 'integer)
740
741 (defun gnus-widget-reversible-match (widget value)
742   "Ignoring WIDGET, convert VALUE to internal form.
743 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
744   ;; (debug value)
745   (or (symbolp value)
746       (and (listp value)
747            (eq (length value) 2)
748            (eq (nth 0 value) 'not)
749            (symbolp (nth 1 value)))))
750
751 (defun gnus-widget-reversible-to-internal (widget value)
752   "Ignoring WIDGET, convert VALUE to internal form.
753 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
754 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
755   ;; (debug value)
756   (if (atom value)
757       (list value nil)
758     (list (nth 1 value) t)))
759
760 (defun gnus-widget-reversible-to-external (widget value)
761   "Ignoring WIDGET, convert VALUE to external form.
762 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
763 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
764   ;; (debug value)
765   (if (nth 1 value)
766       (list 'not (nth 0 value))
767     (nth 0 value)))
768
769 (define-widget 'gnus-widget-reversible 'group
770   "A `group' that convert values."
771   :match 'gnus-widget-reversible-match
772   :value-to-internal 'gnus-widget-reversible-to-internal
773   :value-to-external 'gnus-widget-reversible-to-external)
774
775 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
776   "*List of functions used for sorting articles in the summary buffer.
777
778 Each function takes two articles and returns non-nil if the first
779 article should be sorted before the other.  If you use more than one
780 function, the primary sort function should be the last.  You should
781 probably always include `gnus-article-sort-by-number' in the list of
782 sorting functions -- preferably first.  Also note that sorting by date
783 is often much slower than sorting by number, and the sorting order is
784 very similar.  (Sorting by date means sorting by the time the message
785 was sent, sorting by number means sorting by arrival time.)
786
787 Each item can also be a list `(not F)' where F is a function;
788 this reverses the sort order.
789
790 Ready-made functions include `gnus-article-sort-by-number',
791 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
792 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
793 and `gnus-article-sort-by-score'.
794
795 When threading is turned on, the variable `gnus-thread-sort-functions'
796 controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat (gnus-widget-reversible
799                   (choice (function-item gnus-article-sort-by-number)
800                           (function-item gnus-article-sort-by-author)
801                           (function-item gnus-article-sort-by-subject)
802                           (function-item gnus-article-sort-by-date)
803                           (function-item gnus-article-sort-by-score)
804                           (function-item gnus-article-sort-by-random)
805                           (function :tag "other"))
806                   (boolean :tag "Reverse order"))))
807
808
809 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
810   "*List of functions used for sorting threads in the summary buffer.
811 By default, threads are sorted by article number.
812
813 Each function takes two threads and returns non-nil if the first
814 thread should be sorted before the other.  If you use more than one
815 function, the primary sort function should be the last.  You should
816 probably always include `gnus-thread-sort-by-number' in the list of
817 sorting functions -- preferably first.  Also note that sorting by date
818 is often much slower than sorting by number, and the sorting order is
819 very similar.  (Sorting by date means sorting by the time the message
820 was sent, sorting by number means sorting by arrival time.)
821
822 Each list item can also be a list `(not F)' where F is a
823 function; this specifies reversed sort order.
824
825 Ready-made functions include `gnus-thread-sort-by-number',
826 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
827 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
828 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
829 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
830 and `gnus-thread-sort-by-total-score' (see
831 `gnus-thread-score-function').
832
833 When threading is turned off, the variable
834 `gnus-article-sort-functions' controls how articles are sorted."
835   :group 'gnus-summary-sort
836   :type '(repeat
837           (gnus-widget-reversible
838            (choice (function-item gnus-thread-sort-by-number)
839                    (function-item gnus-thread-sort-by-author)
840                    (function-item gnus-thread-sort-by-recipient)
841                    (function-item gnus-thread-sort-by-subject)
842                    (function-item gnus-thread-sort-by-date)
843                    (function-item gnus-thread-sort-by-score)
844                    (function-item gnus-thread-sort-by-most-recent-number)
845                    (function-item gnus-thread-sort-by-most-recent-date)
846                    (function-item gnus-thread-sort-by-random)
847                    (function-item gnus-thread-sort-by-total-score)
848                    (function :tag "other"))
849            (boolean :tag "Reverse order"))))
850
851 (defcustom gnus-thread-score-function '+
852   "*Function used for calculating the total score of a thread.
853
854 The function is called with the scores of the article and each
855 subthread and should then return the score of the thread.
856
857 Some functions you can use are `+', `max', or `min'."
858   :group 'gnus-summary-sort
859   :type 'function)
860
861 (defcustom gnus-summary-expunge-below nil
862   "All articles that have a score less than this variable will be expunged.
863 This variable is local to the summary buffers."
864   :group 'gnus-score-default
865   :type '(choice (const :tag "off" nil)
866                  integer))
867
868 (defcustom gnus-thread-expunge-below nil
869   "All threads that have a total score less than this variable will be expunged.
870 See `gnus-thread-score-function' for en explanation of what a
871 \"thread score\" is.
872
873 This variable is local to the summary buffers."
874   :group 'gnus-threading
875   :group 'gnus-score-default
876   :type '(choice (const :tag "off" nil)
877                  integer))
878
879 (defcustom gnus-summary-mode-hook nil
880   "*A hook for Gnus summary mode.
881 This hook is run before any variables are set in the summary buffer."
882   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
883   :group 'gnus-summary-various
884   :type 'hook)
885
886 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
887 (when (featurep 'xemacs)
888   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
889   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
890   (add-hook 'gnus-summary-mode-hook
891             'gnus-xmas-switch-horizontal-scrollbar-off))
892
893 (defcustom gnus-summary-menu-hook nil
894   "*Hook run after the creation of the summary mode menu."
895   :group 'gnus-summary-visual
896   :type 'hook)
897
898 (defcustom gnus-summary-exit-hook nil
899   "*A hook called on exit from the summary buffer.
900 It will be called with point in the group buffer."
901   :group 'gnus-summary-exit
902   :type 'hook)
903
904 (defcustom gnus-summary-prepare-hook nil
905   "*A hook called after the summary buffer has been generated.
906 If you want to modify the summary buffer, you can use this hook."
907   :group 'gnus-summary-various
908   :type 'hook)
909
910 (defcustom gnus-summary-prepared-hook nil
911   "*A hook called as the last thing after the summary buffer has been generated."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-generate-hook nil
916   "*A hook run just before generating the summary buffer.
917 This hook is commonly used to customize threading variables and the
918 like."
919   :group 'gnus-summary-various
920   :type 'hook)
921
922 (defcustom gnus-select-group-hook nil
923   "*A hook called when a newsgroup is selected.
924
925 If you'd like to simplify subjects like the
926 `gnus-summary-next-same-subject' command does, you can use the
927 following hook:
928
929  (add-hook gnus-select-group-hook
930            (lambda ()
931              (mapcar (lambda (header)
932                        (mail-header-set-subject
933                         header
934                         (gnus-simplify-subject
935                          (mail-header-subject header) 're-only)))
936                      gnus-newsgroup-headers)))"
937   :group 'gnus-group-select
938   :type 'hook)
939
940 (defcustom gnus-select-article-hook nil
941   "*A hook called when an article is selected."
942   :group 'gnus-summary-choose
943   :options '(gnus-agent-fetch-selected-article)
944   :type 'hook)
945
946 (defcustom gnus-visual-mark-article-hook
947   (list 'gnus-highlight-selected-summary)
948   "*Hook run after selecting an article in the summary buffer.
949 It is meant to be used for highlighting the article in some way.  It
950 is not run if `gnus-visual' is nil."
951   :group 'gnus-summary-visual
952   :type 'hook)
953
954 (defcustom gnus-parse-headers-hook nil
955   "*A hook called before parsing the headers."
956   :group 'gnus-various
957   :type 'hook)
958
959 (defcustom gnus-exit-group-hook nil
960   "*A hook called when exiting summary mode.
961 This hook is not called from the non-updating exit commands like `Q'."
962   :group 'gnus-various
963   :type 'hook)
964
965 (defcustom gnus-summary-update-hook
966   (list 'gnus-summary-highlight-line)
967   "*A hook called when a summary line is changed.
968 The hook will not be called if `gnus-visual' is nil.
969
970 The default function `gnus-summary-highlight-line' will
971 highlight the line according to the `gnus-summary-highlight'
972 variable."
973   :group 'gnus-summary-visual
974   :type 'hook)
975
976 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
977   "*A hook called when an article is selected for the first time.
978 The hook is intended to mark an article as read (or unread)
979 automatically when it is selected."
980   :group 'gnus-summary-choose
981   :type 'hook)
982
983 (defcustom gnus-group-no-more-groups-hook nil
984   "*A hook run when returning to group mode having no more (unread) groups."
985   :group 'gnus-group-select
986   :type 'hook)
987
988 (defcustom gnus-ps-print-hook nil
989   "*A hook run before ps-printing something from Gnus."
990   :group 'gnus-summary
991   :type 'hook)
992
993 (defcustom gnus-summary-article-move-hook nil
994   "*A hook called after an article is moved, copied, respooled, or crossposted."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'hook)
998
999 (defcustom gnus-summary-article-delete-hook nil
1000   "*A hook called after an article is deleted."
1001   :version "22.1"
1002   :group 'gnus-summary
1003   :type 'hook)
1004
1005 (defcustom gnus-summary-article-expire-hook nil
1006   "*A hook called after an article is expired."
1007   :version "22.1"
1008   :group 'gnus-summary
1009   :type 'hook)
1010
1011 (defcustom gnus-summary-display-arrow
1012   (and (fboundp 'display-graphic-p)
1013        (display-graphic-p))
1014   "*If non-nil, display an arrow highlighting the current article."
1015   :version "22.1"
1016   :group 'gnus-summary
1017   :type 'boolean)
1018
1019 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1020   "Face used for highlighting the current article in the summary buffer."
1021   :group 'gnus-summary-visual
1022   :type 'face)
1023
1024 (defvar gnus-tmp-downloaded nil)
1025
1026 (defcustom gnus-summary-highlight
1027   '(((eq mark gnus-canceled-mark)
1028      . gnus-summary-cancelled)
1029     ((and uncached (> score default-high))
1030      . gnus-summary-high-undownloaded)
1031     ((and uncached (< score default-low))
1032      . gnus-summary-low-undownloaded)
1033     (uncached
1034      . gnus-summary-normal-undownloaded)
1035     ((and (> score default-high)
1036           (or (eq mark gnus-dormant-mark)
1037               (eq mark gnus-ticked-mark)))
1038      . gnus-summary-high-ticked)
1039     ((and (< score default-low)
1040           (or (eq mark gnus-dormant-mark)
1041               (eq mark gnus-ticked-mark)))
1042      . gnus-summary-low-ticked)
1043     ((or (eq mark gnus-dormant-mark)
1044          (eq mark gnus-ticked-mark))
1045      . gnus-summary-normal-ticked)
1046     ((and (> score default-high) (eq mark gnus-ancient-mark))
1047      . gnus-summary-high-ancient)
1048     ((and (< score default-low) (eq mark gnus-ancient-mark))
1049      . gnus-summary-low-ancient)
1050     ((eq mark gnus-ancient-mark)
1051      . gnus-summary-normal-ancient)
1052     ((and (> score default-high) (eq mark gnus-unread-mark))
1053      . gnus-summary-high-unread)
1054     ((and (< score default-low) (eq mark gnus-unread-mark))
1055      . gnus-summary-low-unread)
1056     ((eq mark gnus-unread-mark)
1057      . gnus-summary-normal-unread)
1058     ((> score default-high)
1059      . gnus-summary-high-read)
1060     ((< score default-low)
1061      . gnus-summary-low-read)
1062     (t
1063      . gnus-summary-normal-read))
1064   "*Controls the highlighting of summary buffer lines.
1065
1066 A list of (FORM . FACE) pairs.  When deciding how a particular
1067 summary line should be displayed, each form is evaluated.  The content
1068 of the face field after the first true form is used.  You can change
1069 how those summary lines are displayed, by editing the face field.
1070
1071 You can use the following variables in the FORM field.
1072
1073 score:        The article's score.
1074 default:      The default article score.
1075 default-high: The default score for high scored articles.
1076 default-low:  The default score for low scored articles.
1077 below:        The score below which articles are automatically marked as read.
1078 mark:         The article's mark.
1079 uncached:     Non-nil if the article is uncached."
1080   :group 'gnus-summary-visual
1081   :type '(repeat (cons (sexp :tag "Form" nil)
1082                        face)))
1083
1084 (defcustom gnus-alter-header-function nil
1085   "Function called to allow alteration of article header structures.
1086 The function is called with one parameter, the article header vector,
1087 which it may alter in any way."
1088   :type '(choice (const :tag "None" nil)
1089                  function)
1090   :group 'gnus-summary)
1091
1092 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1093   "Function used to decode a string with encoded words.")
1094
1095 (defvar gnus-decode-encoded-address-function
1096   'mail-decode-encoded-address-string
1097   "Function used to decode addresses with encoded words.")
1098
1099 (defcustom gnus-extra-headers '(To Newsgroups)
1100   "*Extra headers to parse."
1101   :version "21.1"
1102   :group 'gnus-summary
1103   :type '(repeat symbol))
1104
1105 (defcustom gnus-ignored-from-addresses
1106   (and user-mail-address
1107        (not (string= user-mail-address ""))
1108        (regexp-quote user-mail-address))
1109   "*From headers that may be suppressed in favor of To headers.
1110 This can be a regexp or a list of regexps."
1111   :version "21.1"
1112   :group 'gnus-summary
1113   :type '(choice regexp
1114                  (repeat :tag "Regexp List" regexp)))
1115
1116 (defsubst gnus-ignored-from-addresses ()
1117   (gmm-regexp-concat gnus-ignored-from-addresses))
1118
1119 (defcustom gnus-summary-to-prefix "-> "
1120   "*String prefixed to the To field in the summary line when
1121 using `gnus-ignored-from-addresses'."
1122   :version "22.1"
1123   :group 'gnus-summary
1124   :type 'string)
1125
1126 (defcustom gnus-summary-newsgroup-prefix "=> "
1127   "*String prefixed to the Newsgroup field in the summary
1128 line when using `gnus-ignored-from-addresses'."
1129   :version "22.1"
1130   :group 'gnus-summary
1131   :type 'string)
1132
1133 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1134   "List of charsets that should be ignored.
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead."
1137   :version "21.1"
1138   :type '(repeat symbol)
1139   :group 'gnus-charset)
1140
1141 (gnus-define-group-parameter
1142  ignored-charsets
1143  :type list
1144  :function-document
1145  "Return the ignored charsets of GROUP."
1146  :variable gnus-group-ignored-charsets-alist
1147  :variable-default
1148  '(("alt\\.chinese\\.text" iso-8859-1))
1149  :variable-document
1150  "Alist of regexps (to match group names) and charsets that should be ignored.
1151 When these charsets are used in the \"charset\" parameter, the
1152 default charset will be used instead."
1153  :variable-group gnus-charset
1154  :variable-type '(repeat (cons (regexp :tag "Group")
1155                                (repeat symbol)))
1156  :parameter-type '(choice :tag "Ignored charsets"
1157                           :value nil
1158                           (repeat (symbol)))
1159  :parameter-document       "\
1160 List of charsets that should be ignored.
1161
1162 When these charsets are used in the \"charset\" parameter, the
1163 default charset will be used instead.")
1164
1165 (defcustom gnus-group-highlight-words-alist nil
1166   "Alist of group regexps and highlight regexps.
1167 This variable uses the same syntax as `gnus-emphasis-alist'."
1168   :version "21.1"
1169   :type '(repeat (cons (regexp :tag "Group")
1170                        (repeat (list (regexp :tag "Highlight regexp")
1171                                      (number :tag "Group for entire word" 0)
1172                                      (number :tag "Group for displayed part" 0)
1173                                      (symbol :tag "Face"
1174                                              gnus-emphasis-highlight-words)))))
1175   :group 'gnus-summary-visual)
1176
1177 (defcustom gnus-summary-show-article-charset-alist
1178   nil
1179   "Alist of number and charset.
1180 The article will be shown with the charset corresponding to the
1181 numbered argument.
1182 For example: ((1 . cn-gb-2312) (2 . big5))."
1183   :version "21.1"
1184   :type '(repeat (cons (number :tag "Argument" 1)
1185                        (symbol :tag "Charset")))
1186   :group 'gnus-charset)
1187
1188 (defcustom gnus-preserve-marks t
1189   "Whether marks are preserved when moving, copying and respooling messages."
1190   :version "21.1"
1191   :type 'boolean
1192   :group 'gnus-summary-marks)
1193
1194 (defcustom gnus-alter-articles-to-read-function nil
1195   "Function to be called to alter the list of articles to be selected."
1196   :type '(choice (const nil) function)
1197   :group 'gnus-summary)
1198
1199 (defcustom gnus-orphan-score nil
1200   "*All orphans get this score added.  Set in the score file."
1201   :group 'gnus-score-default
1202   :type '(choice (const nil)
1203                  integer))
1204
1205 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1206   "*A regexp to match MIME parts when saving multiple parts of a
1207 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1208 This regexp will be used by default when prompting the user for which
1209 type of files to save."
1210   :group 'gnus-summary
1211   :type 'regexp)
1212
1213 (defcustom gnus-read-all-available-headers nil
1214   "Whether Gnus should parse all headers made available to it.
1215 This is mostly relevant for slow back ends where the user may
1216 wish to widen the summary buffer to include all headers
1217 that were fetched.  Say, for nnultimate groups."
1218   :version "22.1"
1219   :group 'gnus-summary
1220   :type '(choice boolean regexp))
1221
1222 (defcustom gnus-summary-muttprint-program "muttprint"
1223   "Command (and optional arguments) used to run Muttprint."
1224   :version "22.1"
1225   :group 'gnus-summary
1226   :type 'string)
1227
1228 (defcustom gnus-article-loose-mime t
1229   "If non-nil, don't require MIME-Version header.
1230 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1231 supply the MIME-Version header or deliberately strip it from the mail.
1232 If non-nil (the default), Gnus will treat some articles as MIME
1233 even if the MIME-Version header is missing."
1234   :version "22.1"
1235   :type 'boolean
1236   :group 'gnus-article-mime)
1237
1238 (defcustom gnus-article-emulate-mime t
1239   "If non-nil, use MIME emulation for uuencode and the like.
1240 This means that Gnus will search message bodies for text that look
1241 like uuencoded bits, yEncoded bits, and so on, and present that using
1242 the normal Gnus MIME machinery."
1243   :version "22.1"
1244   :type 'boolean
1245   :group 'gnus-article-mime)
1246
1247 ;;; Internal variables
1248
1249 (defvar gnus-summary-display-cache nil)
1250 (defvar gnus-article-mime-handles nil)
1251 (defvar gnus-article-decoded-p nil)
1252 (defvar gnus-article-charset nil)
1253 (defvar gnus-article-ignored-charsets nil)
1254 (defvar gnus-scores-exclude-files nil)
1255 (defvar gnus-page-broken nil)
1256
1257 (defvar gnus-original-article nil)
1258 (defvar gnus-article-internal-prepare-hook nil)
1259 (defvar gnus-newsgroup-process-stack nil)
1260
1261 (defvar gnus-thread-indent-array nil)
1262 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1263 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1264   "Function called to sort the articles within a thread after it has been gathered together.")
1265
1266 (defvar gnus-summary-save-parts-type-history nil)
1267 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1268
1269 ;; Avoid highlighting in kill files.
1270 (defvar gnus-summary-inhibit-highlight nil)
1271 (defvar gnus-newsgroup-selected-overlay nil)
1272 (defvar gnus-inhibit-limiting nil)
1273 (defvar gnus-newsgroup-adaptive-score-file nil)
1274 (defvar gnus-current-score-file nil)
1275 (defvar gnus-current-move-group nil)
1276 (defvar gnus-current-copy-group nil)
1277 (defvar gnus-current-crosspost-group nil)
1278 (defvar gnus-newsgroup-display nil)
1279
1280 (defvar gnus-newsgroup-dependencies nil)
1281 (defvar gnus-newsgroup-adaptive nil)
1282 (defvar gnus-summary-display-article-function nil)
1283 (defvar gnus-summary-highlight-line-function nil
1284   "Function called after highlighting a summary line.")
1285
1286 (defvar gnus-summary-line-format-alist
1287   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1288     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1289     (?s gnus-tmp-subject-or-nil ?s)
1290     (?n gnus-tmp-name ?s)
1291     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1292         ?s)
1293     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1294             gnus-tmp-from) ?s)
1295     (?F gnus-tmp-from ?s)
1296     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1297     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1298     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1299     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1300     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1301     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1302     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1303     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1304     (?L gnus-tmp-lines ?s)
1305     (?O gnus-tmp-downloaded ?c)
1306     (?I gnus-tmp-indentation ?s)
1307     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1308     (?R gnus-tmp-replied ?c)
1309     (?\[ gnus-tmp-opening-bracket ?c)
1310     (?\] gnus-tmp-closing-bracket ?c)
1311     (?\> (make-string gnus-tmp-level ? ) ?s)
1312     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1313     (?i gnus-tmp-score ?d)
1314     (?z gnus-tmp-score-char ?c)
1315     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1316     (?U gnus-tmp-unread ?c)
1317     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1318         ?s)
1319     (?t (gnus-summary-number-of-articles-in-thread
1320          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1321         ?d)
1322     (?e (gnus-summary-number-of-articles-in-thread
1323          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1324         ?c)
1325     (?u gnus-tmp-user-defined ?s)
1326     (?P (gnus-pick-line-number) ?d)
1327     (?B gnus-tmp-thread-tree-header-string ?s)
1328     (user-date (gnus-user-date
1329                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1330   "An alist of format specifications that can appear in summary lines.
1331 These are paired with what variables they correspond with, along with
1332 the type of the variable (string, integer, character, etc).")
1333
1334 (defvar gnus-summary-dummy-line-format-alist
1335   `((?S gnus-tmp-subject ?s)
1336     (?N gnus-tmp-number ?d)
1337     (?u gnus-tmp-user-defined ?s)))
1338
1339 (defvar gnus-summary-mode-line-format-alist
1340   `((?G gnus-tmp-group-name ?s)
1341     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1342     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1343     (?A gnus-tmp-article-number ?d)
1344     (?Z gnus-tmp-unread-and-unselected ?s)
1345     (?V gnus-version ?s)
1346     (?U gnus-tmp-unread-and-unticked ?d)
1347     (?S gnus-tmp-subject ?s)
1348     (?e gnus-tmp-unselected ?d)
1349     (?u gnus-tmp-user-defined ?s)
1350     (?d (length gnus-newsgroup-dormant) ?d)
1351     (?t (length gnus-newsgroup-marked) ?d)
1352     (?h (length gnus-newsgroup-spam-marked) ?d)
1353     (?r (length gnus-newsgroup-reads) ?d)
1354     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1355     (?E gnus-newsgroup-expunged-tally ?d)
1356     (?s (gnus-current-score-file-nondirectory) ?s)))
1357
1358 (defvar gnus-last-search-regexp nil
1359   "Default regexp for article search command.")
1360
1361 (defvar gnus-last-shell-command nil
1362   "Default shell command on article.")
1363
1364 (defvar gnus-newsgroup-agentized nil
1365   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1366 (defvar gnus-newsgroup-begin nil)
1367 (defvar gnus-newsgroup-end nil)
1368 (defvar gnus-newsgroup-last-rmail nil)
1369 (defvar gnus-newsgroup-last-mail nil)
1370 (defvar gnus-newsgroup-last-folder nil)
1371 (defvar gnus-newsgroup-last-file nil)
1372 (defvar gnus-newsgroup-last-directory nil)
1373 (defvar gnus-newsgroup-auto-expire nil)
1374 (defvar gnus-newsgroup-active nil)
1375
1376 (defvar gnus-newsgroup-data nil)
1377 (defvar gnus-newsgroup-data-reverse nil)
1378 (defvar gnus-newsgroup-limit nil)
1379 (defvar gnus-newsgroup-limits nil)
1380 (defvar gnus-summary-use-undownloaded-faces nil)
1381
1382 (defvar gnus-newsgroup-unreads nil
1383   "Sorted list of unread articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-unselected nil
1386   "Sorted list of unselected unread articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-reads nil
1389   "Alist of read articles and article marks in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-expunged-tally nil)
1392
1393 (defvar gnus-newsgroup-marked nil
1394   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1395
1396 (defvar gnus-newsgroup-spam-marked nil
1397   "List of ranges of articles that have been marked as spam.")
1398
1399 (defvar gnus-newsgroup-killed nil
1400   "List of ranges of articles that have been through the scoring process.")
1401
1402 (defvar gnus-newsgroup-cached nil
1403   "Sorted list of articles that come from the article cache.")
1404
1405 (defvar gnus-newsgroup-saved nil
1406   "List of articles that have been saved.")
1407
1408 (defvar gnus-newsgroup-kill-headers nil)
1409
1410 (defvar gnus-newsgroup-replied nil
1411   "List of articles that have been replied to in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-forwarded nil
1414   "List of articles that have been forwarded in the current newsgroup.")
1415
1416 (defvar gnus-newsgroup-recent nil
1417   "List of articles that have are recent in the current newsgroup.")
1418
1419 (defvar gnus-newsgroup-expirable nil
1420   "Sorted list of articles in the current newsgroup that can be expired.")
1421
1422 (defvar gnus-newsgroup-processable nil
1423   "List of articles in the current newsgroup that can be processed.")
1424
1425 (defvar gnus-newsgroup-downloadable nil
1426   "Sorted list of articles in the current newsgroup that can be processed.")
1427
1428 (defvar gnus-newsgroup-unfetched nil
1429   "Sorted list of articles in the current newsgroup whose headers have
1430 not been fetched into the agent.
1431
1432 This list will always be a subset of gnus-newsgroup-undownloaded.")
1433
1434 (defvar gnus-newsgroup-undownloaded nil
1435   "List of articles in the current newsgroup that haven't been downloaded.")
1436
1437 (defvar gnus-newsgroup-unsendable nil
1438   "List of articles in the current newsgroup that won't be sent.")
1439
1440 (defvar gnus-newsgroup-bookmarks nil
1441   "List of articles in the current newsgroup that have bookmarks.")
1442
1443 (defvar gnus-newsgroup-dormant nil
1444   "Sorted list of dormant articles in the current newsgroup.")
1445
1446 (defvar gnus-newsgroup-unseen nil
1447   "List of unseen articles in the current newsgroup.")
1448
1449 (defvar gnus-newsgroup-seen nil
1450   "Range of seen articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-articles nil
1453   "List of articles in the current newsgroup.")
1454
1455 (defvar gnus-newsgroup-scored nil
1456   "List of scored articles in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-headers nil
1459   "List of article headers in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-threads nil)
1462
1463 (defvar gnus-newsgroup-prepared nil
1464   "Whether the current group has been prepared properly.")
1465
1466 (defvar gnus-newsgroup-ancient nil
1467   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-sparse nil)
1470
1471 (defvar gnus-current-article nil)
1472 (defvar gnus-article-current nil)
1473 (defvar gnus-current-headers nil)
1474 (defvar gnus-have-all-headers nil)
1475 (defvar gnus-last-article nil)
1476 (defvar gnus-newsgroup-history nil)
1477 (defvar gnus-newsgroup-charset nil)
1478 (defvar gnus-newsgroup-ephemeral-charset nil)
1479 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1480
1481 (defvar gnus-article-before-search nil)
1482
1483 (defvar gnus-summary-local-variables
1484   '(gnus-newsgroup-name
1485     gnus-newsgroup-begin gnus-newsgroup-end
1486     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1487     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1488     gnus-newsgroup-last-directory
1489     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1490     gnus-newsgroup-unselected gnus-newsgroup-marked
1491     gnus-newsgroup-spam-marked
1492     gnus-newsgroup-reads gnus-newsgroup-saved
1493     gnus-newsgroup-replied gnus-newsgroup-forwarded
1494     gnus-newsgroup-recent
1495     gnus-newsgroup-expirable
1496     gnus-newsgroup-processable gnus-newsgroup-killed
1497     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1498     gnus-newsgroup-unfetched
1499     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1500     gnus-newsgroup-seen gnus-newsgroup-articles
1501     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1502     gnus-newsgroup-headers gnus-newsgroup-threads
1503     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1504     gnus-current-article gnus-current-headers gnus-have-all-headers
1505     gnus-last-article gnus-article-internal-prepare-hook
1506     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1507     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1508     gnus-thread-expunge-below
1509     gnus-score-alist gnus-current-score-file
1510     (gnus-summary-expunge-below . global)
1511     (gnus-summary-mark-below . global)
1512     (gnus-orphan-score . global)
1513     gnus-newsgroup-active gnus-scores-exclude-files
1514     gnus-newsgroup-history gnus-newsgroup-ancient
1515     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1516     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1517     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1518     (gnus-newsgroup-expunged-tally . 0)
1519     gnus-cache-removable-articles gnus-newsgroup-cached
1520     gnus-newsgroup-data gnus-newsgroup-data-reverse
1521     gnus-newsgroup-limit gnus-newsgroup-limits
1522     gnus-newsgroup-charset gnus-newsgroup-display
1523     gnus-summary-use-undownloaded-faces)
1524   "Variables that are buffer-local to the summary buffers.")
1525
1526 (defvar gnus-newsgroup-variables nil
1527   "A list of variables that have separate values in different newsgroups.
1528 A list of newsgroup (summary buffer) local variables, or cons of
1529 variables and their default expressions to be evalled (when the default
1530 values are not nil), that should be made global while the summary buffer
1531 is active.
1532
1533 Note: The default expressions will be evaluated (using function `eval')
1534 before assignment to the local variable rather than just assigned to it.
1535 If the default expression is the symbol `global', that symbol will not
1536 be evaluated but the global value of the local variable will be used
1537 instead.
1538
1539 These variables can be used to set variables in the group parameters
1540 while still allowing them to affect operations done in other buffers.
1541 For example:
1542
1543 \(setq gnus-newsgroup-variables
1544      '(message-use-followup-to
1545        (gnus-visible-headers .
1546          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1547 ")
1548
1549 ;; Byte-compiler warning.
1550 (eval-when-compile
1551   ;; Bind features so that require will believe that gnus-sum has
1552   ;; already been loaded (avoids infinite recursion)
1553   (let ((features (cons 'gnus-sum features)))
1554     ;; Several of the declarations in gnus-sum are needed to load the
1555     ;; following files. Right now, these definitions have been
1556     ;; compiled but not defined (evaluated).  We could either do a
1557     ;; eval-and-compile about all of the declarations or evaluate the
1558     ;; source file.
1559     (if (boundp 'gnus-newsgroup-variables)
1560         nil
1561       (load "gnus-sum.el" t t t))
1562     (require 'gnus)
1563     (require 'gnus-art)))
1564
1565 ;; MIME stuff.
1566
1567 (defvar gnus-decode-encoded-word-methods
1568   '(mail-decode-encoded-word-string)
1569   "List of methods used to decode encoded words.
1570
1571 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1572 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1573 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1574 whose names match REGEXP.
1575
1576 For example:
1577 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1578  mail-decode-encoded-word-string
1579  (\"chinese\" . rfc1843-decode-string))")
1580
1581 (defvar gnus-decode-encoded-word-methods-cache nil)
1582
1583 (defun gnus-multi-decode-encoded-word-string (string)
1584   "Apply the functions from `gnus-encoded-word-methods' that match."
1585   (unless (and gnus-decode-encoded-word-methods-cache
1586                (eq gnus-newsgroup-name
1587                    (car gnus-decode-encoded-word-methods-cache)))
1588     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1589     (mapcar (lambda (x)
1590               (if (symbolp x)
1591                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1592                 (if (and gnus-newsgroup-name
1593                          (string-match (car x) gnus-newsgroup-name))
1594                     (nconc gnus-decode-encoded-word-methods-cache
1595                            (list (cdr x))))))
1596             gnus-decode-encoded-word-methods))
1597   (let ((xlist gnus-decode-encoded-word-methods-cache))
1598     (pop xlist)
1599     (while xlist
1600       (setq string (funcall (pop xlist) string))))
1601   string)
1602
1603 ;; Subject simplification.
1604
1605 (defun gnus-simplify-whitespace (str)
1606   "Remove excessive whitespace from STR."
1607   ;; Multiple spaces.
1608   (while (string-match "[ \t][ \t]+" str)
1609     (setq str (concat (substring str 0 (match-beginning 0))
1610                         " "
1611                         (substring str (match-end 0)))))
1612   ;; Leading spaces.
1613   (when (string-match "^[ \t]+" str)
1614     (setq str (substring str (match-end 0))))
1615   ;; Trailing spaces.
1616   (when (string-match "[ \t]+$" str)
1617     (setq str (substring str 0 (match-beginning 0))))
1618   str)
1619
1620 (defun gnus-simplify-all-whitespace (str)
1621   "Remove all whitespace from STR."
1622   (while (string-match "[ \t\n]+" str)
1623     (setq str (replace-match "" nil nil str)))
1624   str)
1625
1626 (defsubst gnus-simplify-subject-re (subject)
1627   "Remove \"Re:\" from subject lines."
1628   (if (string-match message-subject-re-regexp subject)
1629       (substring subject (match-end 0))
1630     subject))
1631
1632 (defun gnus-simplify-subject (subject &optional re-only)
1633   "Remove `Re:' and words in parentheses.
1634 If RE-ONLY is non-nil, strip leading `Re:'s only."
1635   (let ((case-fold-search t))           ;Ignore case.
1636     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1637     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1638       (setq subject (substring subject (match-end 0))))
1639     ;; Remove uninteresting prefixes.
1640     (when (and (not re-only)
1641                gnus-simplify-ignored-prefixes
1642                (string-match gnus-simplify-ignored-prefixes subject))
1643       (setq subject (substring subject (match-end 0))))
1644     ;; Remove words in parentheses from end.
1645     (unless re-only
1646       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1647         (setq subject (substring subject 0 (match-beginning 0)))))
1648     ;; Return subject string.
1649     subject))
1650
1651 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1652 ;; all whitespace.
1653 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1654   (goto-char (point-min))
1655   (while (re-search-forward regexp nil t)
1656     (replace-match (or newtext ""))))
1657
1658 (defun gnus-simplify-buffer-fuzzy ()
1659   "Simplify string in the buffer fuzzily.
1660 The string in the accessible portion of the current buffer is simplified.
1661 It is assumed to be a single-line subject.
1662 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1663 matter is removed.  Additional things can be deleted by setting
1664 `gnus-simplify-subject-fuzzy-regexp'."
1665   (let ((case-fold-search t)
1666         (modified-tick))
1667     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1668
1669     (while (not (eq modified-tick (buffer-modified-tick)))
1670       (setq modified-tick (buffer-modified-tick))
1671       (cond
1672        ((listp gnus-simplify-subject-fuzzy-regexp)
1673         (mapcar 'gnus-simplify-buffer-fuzzy-step
1674                 gnus-simplify-subject-fuzzy-regexp))
1675        (gnus-simplify-subject-fuzzy-regexp
1676         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1677       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1678       (gnus-simplify-buffer-fuzzy-step
1679        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1680       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1681
1682     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1683     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1684     (gnus-simplify-buffer-fuzzy-step " $")
1685     (gnus-simplify-buffer-fuzzy-step "^ +")))
1686
1687 (defun gnus-simplify-subject-fuzzy (subject)
1688   "Simplify a subject string fuzzily.
1689 See `gnus-simplify-buffer-fuzzy' for details."
1690   (save-excursion
1691     (gnus-set-work-buffer)
1692     (let ((case-fold-search t))
1693       ;; Remove uninteresting prefixes.
1694       (when (and gnus-simplify-ignored-prefixes
1695                  (string-match gnus-simplify-ignored-prefixes subject))
1696         (setq subject (substring subject (match-end 0))))
1697       (insert subject)
1698       (inline (gnus-simplify-buffer-fuzzy))
1699       (buffer-string))))
1700
1701 (defsubst gnus-simplify-subject-fully (subject)
1702   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1703   (cond
1704    (gnus-simplify-subject-functions
1705     (gnus-map-function gnus-simplify-subject-functions subject))
1706    ((null gnus-summary-gather-subject-limit)
1707     (gnus-simplify-subject-re subject))
1708    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1709     (gnus-simplify-subject-fuzzy subject))
1710    ((numberp gnus-summary-gather-subject-limit)
1711     (truncate-string-to-width (gnus-simplify-subject-re subject)
1712                               gnus-summary-gather-subject-limit))
1713    (t
1714     subject)))
1715
1716 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1717   "Check whether two subjects are equal.
1718 If optional argument SIMPLE-FIRST is t, first argument is already
1719 simplified."
1720   (cond
1721    ((null simple-first)
1722     (equal (gnus-simplify-subject-fully s1)
1723            (gnus-simplify-subject-fully s2)))
1724    (t
1725     (equal s1
1726            (gnus-simplify-subject-fully s2)))))
1727
1728 (defun gnus-summary-bubble-group ()
1729   "Increase the score of the current group.
1730 This is a handy function to add to `gnus-summary-exit-hook' to
1731 increase the score of each group you read."
1732   (gnus-group-add-score gnus-newsgroup-name))
1733
1734 \f
1735 ;;;
1736 ;;; Gnus summary mode
1737 ;;;
1738
1739 (put 'gnus-summary-mode 'mode-class 'special)
1740
1741 (defvar gnus-article-commands-menu)
1742
1743 ;; Non-orthogonal keys
1744
1745 (gnus-define-keys gnus-summary-mode-map
1746   " " gnus-summary-next-page
1747   "\177" gnus-summary-prev-page
1748   [delete] gnus-summary-prev-page
1749   [backspace] gnus-summary-prev-page
1750   "\r" gnus-summary-scroll-up
1751   "\M-\r" gnus-summary-scroll-down
1752   "n" gnus-summary-next-unread-article
1753   "p" gnus-summary-prev-unread-article
1754   "N" gnus-summary-next-article
1755   "P" gnus-summary-prev-article
1756   "\M-\C-n" gnus-summary-next-same-subject
1757   "\M-\C-p" gnus-summary-prev-same-subject
1758   "\M-n" gnus-summary-next-unread-subject
1759   "\M-p" gnus-summary-prev-unread-subject
1760   "." gnus-summary-first-unread-article
1761   "," gnus-summary-best-unread-article
1762   "\M-s" gnus-summary-search-article-forward
1763   "\M-r" gnus-summary-search-article-backward
1764   "\M-S" gnus-summary-repeat-search-article-forward
1765   "\M-R" gnus-summary-repeat-search-article-backward
1766   "<" gnus-summary-beginning-of-article
1767   ">" gnus-summary-end-of-article
1768   "j" gnus-summary-goto-article
1769   "^" gnus-summary-refer-parent-article
1770   "\M-^" gnus-summary-refer-article
1771   "u" gnus-summary-tick-article-forward
1772   "!" gnus-summary-tick-article-forward
1773   "U" gnus-summary-tick-article-backward
1774   "d" gnus-summary-mark-as-read-forward
1775   "D" gnus-summary-mark-as-read-backward
1776   "E" gnus-summary-mark-as-expirable
1777   "\M-u" gnus-summary-clear-mark-forward
1778   "\M-U" gnus-summary-clear-mark-backward
1779   "k" gnus-summary-kill-same-subject-and-select
1780   "\C-k" gnus-summary-kill-same-subject
1781   "\M-\C-k" gnus-summary-kill-thread
1782   "\M-\C-l" gnus-summary-lower-thread
1783   "e" gnus-summary-edit-article
1784   "#" gnus-summary-mark-as-processable
1785   "\M-#" gnus-summary-unmark-as-processable
1786   "\M-\C-t" gnus-summary-toggle-threads
1787   "\M-\C-s" gnus-summary-show-thread
1788   "\M-\C-h" gnus-summary-hide-thread
1789   "\M-\C-f" gnus-summary-next-thread
1790   "\M-\C-b" gnus-summary-prev-thread
1791   [(meta down)] gnus-summary-next-thread
1792   [(meta up)] gnus-summary-prev-thread
1793   "\M-\C-u" gnus-summary-up-thread
1794   "\M-\C-d" gnus-summary-down-thread
1795   "&" gnus-summary-execute-command
1796   "c" gnus-summary-catchup-and-exit
1797   "\C-w" gnus-summary-mark-region-as-read
1798   "\C-t" gnus-summary-toggle-truncation
1799   "?" gnus-summary-mark-as-dormant
1800   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1801   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1802   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1803   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1804   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1805   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1806   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1807   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1808   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1809   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1810   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1811   "=" gnus-summary-expand-window
1812   "\C-x\C-s" gnus-summary-reselect-current-group
1813   "\M-g" gnus-summary-rescan-group
1814   "w" gnus-summary-stop-page-breaking
1815   "\C-c\C-r" gnus-summary-caesar-message
1816   "f" gnus-summary-followup
1817   "F" gnus-summary-followup-with-original
1818   "C" gnus-summary-cancel-article
1819   "r" gnus-summary-reply
1820   "R" gnus-summary-reply-with-original
1821   "\C-c\C-f" gnus-summary-mail-forward
1822   "o" gnus-summary-save-article
1823   "\C-o" gnus-summary-save-article-mail
1824   "|" gnus-summary-pipe-output
1825   "\M-k" gnus-summary-edit-local-kill
1826   "\M-K" gnus-summary-edit-global-kill
1827   ;; "V" gnus-version
1828   "\C-c\C-d" gnus-summary-describe-group
1829   "q" gnus-summary-exit
1830   "Q" gnus-summary-exit-no-update
1831   "\C-c\C-i" gnus-info-find-node
1832   gnus-mouse-2 gnus-mouse-pick-article
1833   [follow-link] mouse-face
1834   "m" gnus-summary-mail-other-window
1835   "a" gnus-summary-post-news
1836   "i" gnus-summary-news-other-window
1837   "x" gnus-summary-limit-to-unread
1838   "s" gnus-summary-isearch-article
1839   "t" gnus-summary-toggle-header
1840   "g" gnus-summary-show-article
1841   "l" gnus-summary-goto-last-article
1842   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1843   "\C-d" gnus-summary-enter-digest-group
1844   "\M-\C-d" gnus-summary-read-document
1845   "\M-\C-e" gnus-summary-edit-parameters
1846   "\M-\C-a" gnus-summary-customize-parameters
1847   "\C-c\C-b" gnus-bug
1848   "*" gnus-cache-enter-article
1849   "\M-*" gnus-cache-remove-article
1850   "\M-&" gnus-summary-universal-argument
1851   "\C-l" gnus-recenter
1852   "I" gnus-summary-increase-score
1853   "L" gnus-summary-lower-score
1854   "\M-i" gnus-symbolic-argument
1855   "h" gnus-summary-select-article-buffer
1856
1857   "b" gnus-article-view-part
1858   "\M-t" gnus-summary-toggle-display-buttonized
1859
1860   "V" gnus-summary-score-map
1861   "X" gnus-uu-extract-map
1862   "S" gnus-summary-send-map)
1863
1864 ;; Sort of orthogonal keymap
1865 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1866   "t" gnus-summary-tick-article-forward
1867   "!" gnus-summary-tick-article-forward
1868   "d" gnus-summary-mark-as-read-forward
1869   "r" gnus-summary-mark-as-read-forward
1870   "c" gnus-summary-clear-mark-forward
1871   " " gnus-summary-clear-mark-forward
1872   "e" gnus-summary-mark-as-expirable
1873   "x" gnus-summary-mark-as-expirable
1874   "?" gnus-summary-mark-as-dormant
1875   "b" gnus-summary-set-bookmark
1876   "B" gnus-summary-remove-bookmark
1877   "#" gnus-summary-mark-as-processable
1878   "\M-#" gnus-summary-unmark-as-processable
1879   "S" gnus-summary-limit-include-expunged
1880   "C" gnus-summary-catchup
1881   "H" gnus-summary-catchup-to-here
1882   "h" gnus-summary-catchup-from-here
1883   "\C-c" gnus-summary-catchup-all
1884   "k" gnus-summary-kill-same-subject-and-select
1885   "K" gnus-summary-kill-same-subject
1886   "P" gnus-uu-mark-map)
1887
1888 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1889   "c" gnus-summary-clear-above
1890   "u" gnus-summary-tick-above
1891   "m" gnus-summary-mark-above
1892   "k" gnus-summary-kill-below)
1893
1894 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1895   "/" gnus-summary-limit-to-subject
1896   "n" gnus-summary-limit-to-articles
1897   "b" gnus-summary-limit-to-bodies
1898   "h" gnus-summary-limit-to-headers
1899   "w" gnus-summary-pop-limit
1900   "s" gnus-summary-limit-to-subject
1901   "a" gnus-summary-limit-to-author
1902   "u" gnus-summary-limit-to-unread
1903   "m" gnus-summary-limit-to-marks
1904   "M" gnus-summary-limit-exclude-marks
1905   "v" gnus-summary-limit-to-score
1906   "*" gnus-summary-limit-include-cached
1907   "D" gnus-summary-limit-include-dormant
1908   "T" gnus-summary-limit-include-thread
1909   "d" gnus-summary-limit-exclude-dormant
1910   "t" gnus-summary-limit-to-age
1911   "." gnus-summary-limit-to-unseen
1912   "x" gnus-summary-limit-to-extra
1913   "p" gnus-summary-limit-to-display-predicate
1914   "E" gnus-summary-limit-include-expunged
1915   "c" gnus-summary-limit-exclude-childless-dormant
1916   "C" gnus-summary-limit-mark-excluded-as-read
1917   "o" gnus-summary-insert-old-articles
1918   "N" gnus-summary-insert-new-articles
1919   "S" gnus-summary-limit-to-singletons
1920   "r" gnus-summary-limit-to-replied
1921   "R" gnus-summary-limit-to-recipient
1922   "A" gnus-summary-limit-to-address)
1923
1924 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1925   "n" gnus-summary-next-unread-article
1926   "p" gnus-summary-prev-unread-article
1927   "N" gnus-summary-next-article
1928   "P" gnus-summary-prev-article
1929   "\C-n" gnus-summary-next-same-subject
1930   "\C-p" gnus-summary-prev-same-subject
1931   "\M-n" gnus-summary-next-unread-subject
1932   "\M-p" gnus-summary-prev-unread-subject
1933   "f" gnus-summary-first-unread-article
1934   "b" gnus-summary-best-unread-article
1935   "j" gnus-summary-goto-article
1936   "g" gnus-summary-goto-subject
1937   "l" gnus-summary-goto-last-article
1938   "o" gnus-summary-pop-article)
1939
1940 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1941   "k" gnus-summary-kill-thread
1942   "l" gnus-summary-lower-thread
1943   "i" gnus-summary-raise-thread
1944   "T" gnus-summary-toggle-threads
1945   "t" gnus-summary-rethread-current
1946   "^" gnus-summary-reparent-thread
1947   "\M-^" gnus-summary-reparent-children
1948   "s" gnus-summary-show-thread
1949   "S" gnus-summary-show-all-threads
1950   "h" gnus-summary-hide-thread
1951   "H" gnus-summary-hide-all-threads
1952   "n" gnus-summary-next-thread
1953   "p" gnus-summary-prev-thread
1954   "u" gnus-summary-up-thread
1955   "o" gnus-summary-top-thread
1956   "d" gnus-summary-down-thread
1957   "#" gnus-uu-mark-thread
1958   "\M-#" gnus-uu-unmark-thread)
1959
1960 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1961   "g" gnus-summary-prepare
1962   "c" gnus-summary-insert-cached-articles
1963   "d" gnus-summary-insert-dormant-articles
1964   "t" gnus-summary-insert-ticked-articles)
1965
1966 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1967   "c" gnus-summary-catchup-and-exit
1968   "C" gnus-summary-catchup-all-and-exit
1969   "E" gnus-summary-exit-no-update
1970   "Q" gnus-summary-exit
1971   "Z" gnus-summary-exit
1972   "n" gnus-summary-catchup-and-goto-next-group
1973   "p" gnus-summary-catchup-and-goto-prev-group
1974   "R" gnus-summary-reselect-current-group
1975   "G" gnus-summary-rescan-group
1976   "N" gnus-summary-next-group
1977   "s" gnus-summary-save-newsrc
1978   "P" gnus-summary-prev-group)
1979
1980 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1981   " " gnus-summary-next-page
1982   "n" gnus-summary-next-page
1983   "\177" gnus-summary-prev-page
1984   [delete] gnus-summary-prev-page
1985   "p" gnus-summary-prev-page
1986   "\r" gnus-summary-scroll-up
1987   "\M-\r" gnus-summary-scroll-down
1988   "<" gnus-summary-beginning-of-article
1989   ">" gnus-summary-end-of-article
1990   "b" gnus-summary-beginning-of-article
1991   "e" gnus-summary-end-of-article
1992   "^" gnus-summary-refer-parent-article
1993   "r" gnus-summary-refer-parent-article
1994   "D" gnus-summary-enter-digest-group
1995   "R" gnus-summary-refer-references
1996   "T" gnus-summary-refer-thread
1997   "g" gnus-summary-show-article
1998   "s" gnus-summary-isearch-article
1999   "P" gnus-summary-print-article
2000   "S" gnus-sticky-article
2001   "M" gnus-mailing-list-insinuate
2002   "t" gnus-article-babel)
2003
2004 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2005   "b" gnus-article-add-buttons
2006   "B" gnus-article-add-buttons-to-head
2007   "o" gnus-article-treat-overstrike
2008   "e" gnus-article-emphasize
2009   "w" gnus-article-fill-cited-article
2010   "Q" gnus-article-fill-long-lines
2011   "L" gnus-article-toggle-truncate-lines
2012   "C" gnus-article-capitalize-sentences
2013   "c" gnus-article-remove-cr
2014   "q" gnus-article-de-quoted-unreadable
2015   "6" gnus-article-de-base64-unreadable
2016   "Z" gnus-article-decode-HZ
2017   "A" gnus-article-treat-ansi-sequences
2018   "h" gnus-article-wash-html
2019   "u" gnus-article-unsplit-urls
2020   "s" gnus-summary-force-verify-and-decrypt
2021   "f" gnus-article-display-x-face
2022   "l" gnus-summary-stop-page-breaking
2023   "r" gnus-summary-caesar-message
2024   "m" gnus-summary-morse-message
2025   "t" gnus-summary-toggle-header
2026   "g" gnus-treat-smiley
2027   "v" gnus-summary-verbose-headers
2028   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2029   "p" gnus-article-verify-x-pgp-sig
2030   "d" gnus-article-treat-dumbquotes
2031   "i" gnus-summary-idna-message)
2032
2033 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2034   ;; mnemonic: deuglif*Y*
2035   "u" gnus-article-outlook-unwrap-lines
2036   "a" gnus-article-outlook-repair-attribution
2037   "c" gnus-article-outlook-rearrange-citation
2038   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2039
2040 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2041   "a" gnus-article-hide
2042   "h" gnus-article-hide-headers
2043   "b" gnus-article-hide-boring-headers
2044   "s" gnus-article-hide-signature
2045   "c" gnus-article-hide-citation
2046   "C" gnus-article-hide-citation-in-followups
2047   "l" gnus-article-hide-list-identifiers
2048   "B" gnus-article-strip-banner
2049   "P" gnus-article-hide-pem
2050   "\C-c" gnus-article-hide-citation-maybe)
2051
2052 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2053   "a" gnus-article-highlight
2054   "h" gnus-article-highlight-headers
2055   "c" gnus-article-highlight-citation
2056   "s" gnus-article-highlight-signature)
2057
2058 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2059   "f" gnus-article-treat-fold-headers
2060   "u" gnus-article-treat-unfold-headers
2061   "n" gnus-article-treat-fold-newsgroups)
2062
2063 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2064   "x" gnus-article-display-x-face
2065   "d" gnus-article-display-face
2066   "s" gnus-treat-smiley
2067   "D" gnus-article-remove-images
2068   "f" gnus-treat-from-picon
2069   "m" gnus-treat-mail-picon
2070   "n" gnus-treat-newsgroups-picon)
2071
2072 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2073   "w" gnus-article-decode-mime-words
2074   "c" gnus-article-decode-charset
2075   "v" gnus-mime-view-all-parts
2076   "b" gnus-article-view-part)
2077
2078 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2079   "z" gnus-article-date-ut
2080   "u" gnus-article-date-ut
2081   "l" gnus-article-date-local
2082   "p" gnus-article-date-english
2083   "e" gnus-article-date-lapsed
2084   "o" gnus-article-date-original
2085   "i" gnus-article-date-iso8601
2086   "s" gnus-article-date-user)
2087
2088 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2089   "t" gnus-article-remove-trailing-blank-lines
2090   "l" gnus-article-strip-leading-blank-lines
2091   "m" gnus-article-strip-multiple-blank-lines
2092   "a" gnus-article-strip-blank-lines
2093   "A" gnus-article-strip-all-blank-lines
2094   "s" gnus-article-strip-leading-space
2095   "e" gnus-article-strip-trailing-space
2096   "w" gnus-article-remove-leading-whitespace)
2097
2098 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2099   "v" gnus-version
2100   "f" gnus-summary-fetch-faq
2101   "d" gnus-summary-describe-group
2102   "h" gnus-summary-describe-briefly
2103   "i" gnus-info-find-node
2104   "c" gnus-group-fetch-charter
2105   "C" gnus-group-fetch-control)
2106
2107 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2108   "e" gnus-summary-expire-articles
2109   "\M-\C-e" gnus-summary-expire-articles-now
2110   "\177" gnus-summary-delete-article
2111   [delete] gnus-summary-delete-article
2112   [backspace] gnus-summary-delete-article
2113   "m" gnus-summary-move-article
2114   "r" gnus-summary-respool-article
2115   "w" gnus-summary-edit-article
2116   "c" gnus-summary-copy-article
2117   "B" gnus-summary-crosspost-article
2118   "q" gnus-summary-respool-query
2119   "t" gnus-summary-respool-trace
2120   "i" gnus-summary-import-article
2121   "I" gnus-summary-create-article
2122   "p" gnus-summary-article-posted-p)
2123
2124 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2125   "o" gnus-summary-save-article
2126   "m" gnus-summary-save-article-mail
2127   "F" gnus-summary-write-article-file
2128   "r" gnus-summary-save-article-rmail
2129   "f" gnus-summary-save-article-file
2130   "b" gnus-summary-save-article-body-file
2131   "B" gnus-summary-write-article-body-file
2132   "h" gnus-summary-save-article-folder
2133   "v" gnus-summary-save-article-vm
2134   "p" gnus-summary-pipe-output
2135   "P" gnus-summary-muttprint
2136   "s" gnus-soup-add-article)
2137
2138 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2139   "b" gnus-summary-display-buttonized
2140   "m" gnus-summary-repair-multipart
2141   "v" gnus-article-view-part
2142   "o" gnus-article-save-part
2143   "O" gnus-article-save-part-and-strip
2144   "r" gnus-article-replace-part
2145   "d" gnus-article-delete-part
2146   "t" gnus-article-view-part-as-type
2147   "j" gnus-article-jump-to-part
2148   "c" gnus-article-copy-part
2149   "C" gnus-article-view-part-as-charset
2150   "e" gnus-article-view-part-externally
2151   "H" gnus-article-browse-html-article
2152   "E" gnus-article-encrypt-body
2153   "i" gnus-article-inline-part
2154   "|" gnus-article-pipe-part)
2155
2156 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2157   "p" gnus-summary-mark-as-processable
2158   "u" gnus-summary-unmark-as-processable
2159   "U" gnus-summary-unmark-all-processable
2160   "v" gnus-uu-mark-over
2161   "s" gnus-uu-mark-series
2162   "r" gnus-uu-mark-region
2163   "g" gnus-uu-unmark-region
2164   "R" gnus-uu-mark-by-regexp
2165   "G" gnus-uu-unmark-by-regexp
2166   "t" gnus-uu-mark-thread
2167   "T" gnus-uu-unmark-thread
2168   "a" gnus-uu-mark-all
2169   "b" gnus-uu-mark-buffer
2170   "S" gnus-uu-mark-sparse
2171   "k" gnus-summary-kill-process-mark
2172   "y" gnus-summary-yank-process-mark
2173   "w" gnus-summary-save-process-mark
2174   "i" gnus-uu-invert-processable)
2175
2176 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2177   ;;"x" gnus-uu-extract-any
2178   "m" gnus-summary-save-parts
2179   "u" gnus-uu-decode-uu
2180   "U" gnus-uu-decode-uu-and-save
2181   "s" gnus-uu-decode-unshar
2182   "S" gnus-uu-decode-unshar-and-save
2183   "o" gnus-uu-decode-save
2184   "O" gnus-uu-decode-save
2185   "b" gnus-uu-decode-binhex
2186   "B" gnus-uu-decode-binhex
2187   "p" gnus-uu-decode-postscript
2188   "P" gnus-uu-decode-postscript-and-save)
2189
2190 (gnus-define-keys
2191     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2192   "u" gnus-uu-decode-uu-view
2193   "U" gnus-uu-decode-uu-and-save-view
2194   "s" gnus-uu-decode-unshar-view
2195   "S" gnus-uu-decode-unshar-and-save-view
2196   "o" gnus-uu-decode-save-view
2197   "O" gnus-uu-decode-save-view
2198   "b" gnus-uu-decode-binhex-view
2199   "B" gnus-uu-decode-binhex-view
2200   "p" gnus-uu-decode-postscript-view
2201   "P" gnus-uu-decode-postscript-and-save-view)
2202
2203 (defvar gnus-article-post-menu nil)
2204
2205 (defconst gnus-summary-menu-maxlen 20)
2206
2207 (defun gnus-summary-menu-split (menu)
2208   ;; If we have lots of elements, divide them into groups of 20
2209   ;; and make a pane (or submenu) for each one.
2210   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2211       (let ((menu menu) sublists next
2212             (i 1))
2213         (while menu
2214           ;; Pull off the next gnus-summary-menu-maxlen elements
2215           ;; and make them the next element of sublist.
2216           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2217           (if next
2218               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2219                       nil))
2220           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2221                                              (aref (car (last menu)) 0)) menu)
2222                                sublists))
2223           (setq i (1+ i))
2224           (setq menu next))
2225         (nreverse sublists))
2226     ;; Few elements--put them all in one pane.
2227     menu))
2228
2229 (defun gnus-summary-make-menu-bar ()
2230   (gnus-turn-off-edit-menu 'summary)
2231
2232   (unless (boundp 'gnus-summary-misc-menu)
2233
2234     (easy-menu-define
2235       gnus-summary-kill-menu gnus-summary-mode-map ""
2236       (cons
2237        "Score"
2238        (nconc
2239         (list
2240          ["Customize" gnus-score-customize t])
2241         (gnus-make-score-map 'increase)
2242         (gnus-make-score-map 'lower)
2243         '(("Mark"
2244            ["Kill below" gnus-summary-kill-below t]
2245            ["Mark above" gnus-summary-mark-above t]
2246            ["Tick above" gnus-summary-tick-above t]
2247            ["Clear above" gnus-summary-clear-above t])
2248           ["Current score" gnus-summary-current-score t]
2249           ["Set score" gnus-summary-set-score t]
2250           ["Switch current score file..." gnus-score-change-score-file t]
2251           ["Set mark below..." gnus-score-set-mark-below t]
2252           ["Set expunge below..." gnus-score-set-expunge-below t]
2253           ["Edit current score file" gnus-score-edit-current-scores t]
2254           ["Edit score file" gnus-score-edit-file t]
2255           ["Trace score" gnus-score-find-trace t]
2256           ["Find words" gnus-score-find-favourite-words t]
2257           ["Rescore buffer" gnus-summary-rescore t]
2258           ["Increase score..." gnus-summary-increase-score t]
2259           ["Lower score..." gnus-summary-lower-score t]))))
2260
2261     ;; Define both the Article menu in the summary buffer and the
2262     ;; equivalent Commands menu in the article buffer here for
2263     ;; consistency.
2264     (let ((innards
2265            `(("Hide"
2266               ["All" gnus-article-hide t]
2267               ["Headers" gnus-article-hide-headers t]
2268               ["Signature" gnus-article-hide-signature t]
2269               ["Citation" gnus-article-hide-citation t]
2270               ["List identifiers" gnus-article-hide-list-identifiers t]
2271               ["Banner" gnus-article-strip-banner t]
2272               ["Boring headers" gnus-article-hide-boring-headers t])
2273              ("Highlight"
2274               ["All" gnus-article-highlight t]
2275               ["Headers" gnus-article-highlight-headers t]
2276               ["Signature" gnus-article-highlight-signature t]
2277               ["Citation" gnus-article-highlight-citation t])
2278              ("MIME"
2279               ["Words" gnus-article-decode-mime-words t]
2280               ["Charset" gnus-article-decode-charset t]
2281               ["QP" gnus-article-de-quoted-unreadable t]
2282               ["Base64" gnus-article-de-base64-unreadable t]
2283               ["View MIME buttons" gnus-summary-display-buttonized t]
2284               ["View all" gnus-mime-view-all-parts t]
2285               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2286               ["Encrypt body" gnus-article-encrypt-body
2287                :active (not (gnus-group-read-only-p))
2288                ,@(if (featurep 'xemacs) nil
2289                    '(:help "Encrypt the message body on disk"))]
2290               ["Extract all parts..." gnus-summary-save-parts t]
2291               ("Multipart"
2292                ["Repair multipart" gnus-summary-repair-multipart t]
2293                ["Pipe part..." gnus-article-pipe-part t]
2294                ["Inline part" gnus-article-inline-part t]
2295                ["View part as type..." gnus-article-view-part-as-type t]
2296                ["Encrypt body" gnus-article-encrypt-body
2297                 :active (not (gnus-group-read-only-p))
2298                ,@(if (featurep 'xemacs) nil
2299                    '(:help "Encrypt the message body on disk"))]
2300                ["View part externally" gnus-article-view-part-externally t]
2301                ["View HTML parts in browser" gnus-article-browse-html-article t]
2302                ["View part with charset..." gnus-article-view-part-as-charset t]
2303                ["Copy part" gnus-article-copy-part t]
2304                ["Save part..." gnus-article-save-part t]
2305                ["View part" gnus-article-view-part t]))
2306              ("Date"
2307               ["Local" gnus-article-date-local t]
2308               ["ISO8601" gnus-article-date-iso8601 t]
2309               ["UT" gnus-article-date-ut t]
2310               ["Original" gnus-article-date-original t]
2311               ["Lapsed" gnus-article-date-lapsed t]
2312               ["User-defined" gnus-article-date-user t])
2313              ("Display"
2314               ["Remove images" gnus-article-remove-images t]
2315               ["Toggle smiley" gnus-treat-smiley t]
2316               ["Show X-Face" gnus-article-display-x-face t]
2317               ["Show picons in From" gnus-treat-from-picon t]
2318               ["Show picons in mail headers" gnus-treat-mail-picon t]
2319               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2320               ("View as different encoding"
2321                ,@(gnus-summary-menu-split
2322                   (mapcar
2323                    (lambda (cs)
2324                      ;; Since easymenu under Emacs doesn't allow
2325                      ;; lambda forms for menu commands, we should
2326                      ;; provide intern'ed function symbols.
2327                      (let ((command (intern (format "\
2328 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2329                        (fset command
2330                              `(lambda ()
2331                                 (interactive)
2332                                 (let ((gnus-summary-show-article-charset-alist
2333                                        '((1 . ,cs))))
2334                                   (gnus-summary-show-article 1))))
2335                        `[,(symbol-name cs) ,command t]))
2336                    (sort (if (fboundp 'coding-system-list)
2337                              (coding-system-list)
2338                            (mapcar 'car mm-mime-mule-charset-alist))
2339                          'string<)))))
2340              ("Washing"
2341               ("Remove Blanks"
2342                ["Leading" gnus-article-strip-leading-blank-lines t]
2343                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2344                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2345                ["All of the above" gnus-article-strip-blank-lines t]
2346                ["All" gnus-article-strip-all-blank-lines t]
2347                ["Leading space" gnus-article-strip-leading-space t]
2348                ["Trailing space" gnus-article-strip-trailing-space t]
2349                ["Leading space in headers"
2350                 gnus-article-remove-leading-whitespace t])
2351               ["Overstrike" gnus-article-treat-overstrike t]
2352               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2353               ["Emphasis" gnus-article-emphasize t]
2354               ["Word wrap" gnus-article-fill-cited-article t]
2355               ["Fill long lines" gnus-article-fill-long-lines t]
2356               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2357               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2358               ["Remove CR" gnus-article-remove-cr t]
2359               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2360               ["Base64" gnus-article-de-base64-unreadable t]
2361               ["Rot 13" gnus-summary-caesar-message
2362                ,@(if (featurep 'xemacs) '(t)
2363                    '(:help "\"Caesar rotate\" article by 13"))]
2364               ["De-IDNA" gnus-summary-idna-message t]
2365               ["Morse decode" gnus-summary-morse-message t]
2366               ["Unix pipe..." gnus-summary-pipe-message t]
2367               ["Add buttons" gnus-article-add-buttons t]
2368               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2369               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2370               ["Verbose header" gnus-summary-verbose-headers t]
2371               ["Toggle header" gnus-summary-toggle-header t]
2372               ["Unfold headers" gnus-article-treat-unfold-headers t]
2373               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2374               ["Html" gnus-article-wash-html t]
2375               ["Unsplit URLs" gnus-article-unsplit-urls t]
2376               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2377               ["Decode HZ" gnus-article-decode-HZ t]
2378               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2379               ("(Outlook) Deuglify"
2380                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2381                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2382                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2383                ["Full (Outlook) deuglify"
2384                 gnus-article-outlook-deuglify-article t])
2385               )
2386              ("Output"
2387               ["Save in default format..." gnus-summary-save-article
2388                ,@(if (featurep 'xemacs) '(t)
2389                    '(:help "Save article using default method"))]
2390               ["Save in file..." gnus-summary-save-article-file
2391                ,@(if (featurep 'xemacs) '(t)
2392                    '(:help "Save article in file"))]
2393               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2394               ["Save in MH folder..." gnus-summary-save-article-folder t]
2395               ["Save in VM folder..." gnus-summary-save-article-vm t]
2396               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2397               ["Save body in file..." gnus-summary-save-article-body-file t]
2398               ["Pipe through a filter..." gnus-summary-pipe-output t]
2399               ["Add to SOUP packet" gnus-soup-add-article t]
2400               ["Print with Muttprint..." gnus-summary-muttprint t]
2401               ["Print" gnus-summary-print-article
2402                ,@(if (featurep 'xemacs) '(t)
2403                    '(:help "Generate and print a PostScript image"))])
2404              ("Copy, move,... (Backend)"
2405               ,@(if (featurep 'xemacs) nil
2406                   '(:help "Copying, moving, expiring articles..."))
2407               ["Respool article..." gnus-summary-respool-article t]
2408               ["Move article..." gnus-summary-move-article
2409                (gnus-check-backend-function
2410                 'request-move-article gnus-newsgroup-name)]
2411               ["Copy article..." gnus-summary-copy-article t]
2412               ["Crosspost article..." gnus-summary-crosspost-article
2413                (gnus-check-backend-function
2414                 'request-replace-article gnus-newsgroup-name)]
2415               ["Import file..." gnus-summary-import-article
2416                (gnus-check-backend-function
2417                 'request-accept-article gnus-newsgroup-name)]
2418               ["Create article..." gnus-summary-create-article
2419                (gnus-check-backend-function
2420                 'request-accept-article gnus-newsgroup-name)]
2421               ["Check if posted" gnus-summary-article-posted-p t]
2422               ["Edit article" gnus-summary-edit-article
2423                (not (gnus-group-read-only-p))]
2424               ["Delete article" gnus-summary-delete-article
2425                (gnus-check-backend-function
2426                 'request-expire-articles gnus-newsgroup-name)]
2427               ["Query respool" gnus-summary-respool-query t]
2428               ["Trace respool" gnus-summary-respool-trace t]
2429               ["Delete expirable articles" gnus-summary-expire-articles-now
2430                (gnus-check-backend-function
2431                 'request-expire-articles gnus-newsgroup-name)])
2432              ("Extract"
2433               ["Uudecode" gnus-uu-decode-uu
2434                ,@(if (featurep 'xemacs) '(t)
2435                    '(:help "Decode uuencoded article(s)"))]
2436               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2437               ["Unshar" gnus-uu-decode-unshar t]
2438               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2439               ["Save" gnus-uu-decode-save t]
2440               ["Binhex" gnus-uu-decode-binhex t]
2441               ["Postscript" gnus-uu-decode-postscript t]
2442               ["All MIME parts" gnus-summary-save-parts t])
2443              ("Cache"
2444               ["Enter article" gnus-cache-enter-article t]
2445               ["Remove article" gnus-cache-remove-article t])
2446              ["Translate" gnus-article-babel t]
2447              ["Select article buffer" gnus-summary-select-article-buffer t]
2448              ["Make article buffer sticky" gnus-sticky-article t]
2449              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2450              ["Isearch article..." gnus-summary-isearch-article t]
2451              ["Beginning of the article" gnus-summary-beginning-of-article t]
2452              ["End of the article" gnus-summary-end-of-article t]
2453              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2454              ["Fetch referenced articles" gnus-summary-refer-references t]
2455              ["Fetch current thread" gnus-summary-refer-thread t]
2456              ["Fetch article with id..." gnus-summary-refer-article t]
2457              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2458              ["Redisplay" gnus-summary-show-article t]
2459              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2460       (easy-menu-define
2461         gnus-summary-article-menu gnus-summary-mode-map ""
2462         (cons "Article" innards))
2463
2464       (if (not (keymapp gnus-summary-article-menu))
2465           (easy-menu-define
2466             gnus-article-commands-menu gnus-article-mode-map ""
2467             (cons "Commands" innards))
2468         ;; in Emacs, don't share menu.
2469         (setq gnus-article-commands-menu
2470               (copy-keymap gnus-summary-article-menu))
2471         (define-key gnus-article-mode-map [menu-bar commands]
2472           (cons "Commands" gnus-article-commands-menu))))
2473
2474     (easy-menu-define
2475       gnus-summary-thread-menu gnus-summary-mode-map ""
2476       '("Threads"
2477         ["Find all messages in thread" gnus-summary-refer-thread t]
2478         ["Toggle threading" gnus-summary-toggle-threads t]
2479         ["Hide threads" gnus-summary-hide-all-threads t]
2480         ["Show threads" gnus-summary-show-all-threads t]
2481         ["Hide thread" gnus-summary-hide-thread t]
2482         ["Show thread" gnus-summary-show-thread t]
2483         ["Go to next thread" gnus-summary-next-thread t]
2484         ["Go to previous thread" gnus-summary-prev-thread t]
2485         ["Go down thread" gnus-summary-down-thread t]
2486         ["Go up thread" gnus-summary-up-thread t]
2487         ["Top of thread" gnus-summary-top-thread t]
2488         ["Mark thread as read" gnus-summary-kill-thread t]
2489         ["Lower thread score" gnus-summary-lower-thread t]
2490         ["Raise thread score" gnus-summary-raise-thread t]
2491         ["Rethread current" gnus-summary-rethread-current t]))
2492
2493     (easy-menu-define
2494       gnus-summary-post-menu gnus-summary-mode-map ""
2495       `("Post"
2496         ["Send a message (mail or news)" gnus-summary-post-news
2497          ,@(if (featurep 'xemacs) '(t)
2498              '(:help "Compose a new message (mail or news)"))]
2499         ["Followup" gnus-summary-followup
2500          ,@(if (featurep 'xemacs) '(t)
2501              '(:help "Post followup to this article"))]
2502         ["Followup and yank" gnus-summary-followup-with-original
2503          ,@(if (featurep 'xemacs) '(t)
2504              '(:help "Post followup to this article, quoting its contents"))]
2505         ["Supersede article" gnus-summary-supersede-article t]
2506         ["Cancel article" gnus-summary-cancel-article
2507          ,@(if (featurep 'xemacs) '(t)
2508              '(:help "Cancel an article you posted"))]
2509         ["Reply" gnus-summary-reply t]
2510         ["Reply and yank" gnus-summary-reply-with-original t]
2511         ["Wide reply" gnus-summary-wide-reply t]
2512         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2513          ,@(if (featurep 'xemacs) '(t)
2514              '(:help "Mail a reply, quoting this article"))]
2515         ["Very wide reply" gnus-summary-very-wide-reply t]
2516         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2517          ,@(if (featurep 'xemacs) '(t)
2518              '(:help "Mail a very wide reply, quoting this article"))]
2519         ["Mail forward" gnus-summary-mail-forward t]
2520         ["Post forward" gnus-summary-post-forward t]
2521         ["Digest and mail" gnus-uu-digest-mail-forward t]
2522         ["Digest and post" gnus-uu-digest-post-forward t]
2523         ["Resend message" gnus-summary-resend-message t]
2524         ["Resend message edit" gnus-summary-resend-message-edit t]
2525         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2526         ["Send a mail" gnus-summary-mail-other-window t]
2527         ["Create a local message" gnus-summary-news-other-window t]
2528         ["Uuencode and post" gnus-uu-post-news
2529          ,@(if (featurep 'xemacs) '(t)
2530              '(:help "Post a uuencoded article"))]
2531         ["Followup via news" gnus-summary-followup-to-mail t]
2532         ["Followup via news and yank"
2533          gnus-summary-followup-to-mail-with-original t]
2534         ;;("Draft"
2535         ;;["Send" gnus-summary-send-draft t]
2536         ;;["Send bounced" gnus-resend-bounced-mail t])
2537         ))
2538
2539     (cond
2540      ((not (keymapp gnus-summary-post-menu))
2541       (setq gnus-article-post-menu gnus-summary-post-menu))
2542      ((not gnus-article-post-menu)
2543       ;; Don't share post menu.
2544       (setq gnus-article-post-menu
2545             (copy-keymap gnus-summary-post-menu))))
2546     (define-key gnus-article-mode-map [menu-bar post]
2547       (cons "Post" gnus-article-post-menu))
2548
2549     (easy-menu-define
2550       gnus-summary-misc-menu gnus-summary-mode-map ""
2551       `("Gnus"
2552         ("Mark Read"
2553          ["Mark as read" gnus-summary-mark-as-read-forward t]
2554          ["Mark same subject and select"
2555           gnus-summary-kill-same-subject-and-select t]
2556          ["Mark same subject" gnus-summary-kill-same-subject t]
2557          ["Catchup" gnus-summary-catchup
2558           ,@(if (featurep 'xemacs) '(t)
2559               '(:help "Mark unread articles in this group as read"))]
2560          ["Catchup all" gnus-summary-catchup-all t]
2561          ["Catchup to here" gnus-summary-catchup-to-here t]
2562          ["Catchup from here" gnus-summary-catchup-from-here t]
2563          ["Catchup region" gnus-summary-mark-region-as-read
2564           (gnus-mark-active-p)]
2565          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2566         ("Mark Various"
2567          ["Tick" gnus-summary-tick-article-forward t]
2568          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2569          ["Remove marks" gnus-summary-clear-mark-forward t]
2570          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2571          ["Set bookmark" gnus-summary-set-bookmark t]
2572          ["Remove bookmark" gnus-summary-remove-bookmark t])
2573         ("Limit to"
2574          ["Marks..." gnus-summary-limit-to-marks t]
2575          ["Subject..." gnus-summary-limit-to-subject t]
2576          ["Author..." gnus-summary-limit-to-author t]
2577          ["Recipient..." gnus-summary-limit-to-recipient t]
2578          ["Address..." gnus-summary-limit-to-address t]
2579          ["Age..." gnus-summary-limit-to-age t]
2580          ["Extra..." gnus-summary-limit-to-extra t]
2581          ["Score..." gnus-summary-limit-to-score t]
2582          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2583          ["Unread" gnus-summary-limit-to-unread t]
2584          ["Unseen" gnus-summary-limit-to-unseen t]
2585          ["Singletons" gnus-summary-limit-to-singletons t]
2586          ["Replied" gnus-summary-limit-to-replied t]
2587          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2588          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2589          ["Pop limit" gnus-summary-pop-limit t]
2590          ["Show dormant" gnus-summary-limit-include-dormant t]
2591          ["Hide childless dormant"
2592           gnus-summary-limit-exclude-childless-dormant t]
2593          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2594          ["Hide marked" gnus-summary-limit-exclude-marks t]
2595          ["Show expunged" gnus-summary-limit-include-expunged t])
2596         ("Process Mark"
2597          ["Set mark" gnus-summary-mark-as-processable t]
2598          ["Remove mark" gnus-summary-unmark-as-processable t]
2599          ["Remove all marks" gnus-summary-unmark-all-processable t]
2600          ["Invert marks" gnus-uu-invert-processable t]
2601          ["Mark above" gnus-uu-mark-over t]
2602          ["Mark series" gnus-uu-mark-series t]
2603          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2604          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2605          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2606          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2607          ["Mark all" gnus-uu-mark-all t]
2608          ["Mark buffer" gnus-uu-mark-buffer t]
2609          ["Mark sparse" gnus-uu-mark-sparse t]
2610          ["Mark thread" gnus-uu-mark-thread t]
2611          ["Unmark thread" gnus-uu-unmark-thread t]
2612          ("Process Mark Sets"
2613           ["Kill" gnus-summary-kill-process-mark t]
2614           ["Yank" gnus-summary-yank-process-mark
2615            gnus-newsgroup-process-stack]
2616           ["Save" gnus-summary-save-process-mark t]
2617           ["Run command on marked..." gnus-summary-universal-argument t]))
2618         ("Scroll article"
2619          ["Page forward" gnus-summary-next-page
2620           ,@(if (featurep 'xemacs) '(t)
2621               '(:help "Show next page of article"))]
2622          ["Page backward" gnus-summary-prev-page
2623           ,@(if (featurep 'xemacs) '(t)
2624               '(:help "Show previous page of article"))]
2625          ["Line forward" gnus-summary-scroll-up t])
2626         ("Move"
2627          ["Next unread article" gnus-summary-next-unread-article t]
2628          ["Previous unread article" gnus-summary-prev-unread-article t]
2629          ["Next article" gnus-summary-next-article t]
2630          ["Previous article" gnus-summary-prev-article t]
2631          ["Next unread subject" gnus-summary-next-unread-subject t]
2632          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2633          ["Next article same subject" gnus-summary-next-same-subject t]
2634          ["Previous article same subject" gnus-summary-prev-same-subject t]
2635          ["First unread article" gnus-summary-first-unread-article t]
2636          ["Best unread article" gnus-summary-best-unread-article t]
2637          ["Go to subject number..." gnus-summary-goto-subject t]
2638          ["Go to article number..." gnus-summary-goto-article t]
2639          ["Go to the last article" gnus-summary-goto-last-article t]
2640          ["Pop article off history" gnus-summary-pop-article t])
2641         ("Sort"
2642          ["Sort by number" gnus-summary-sort-by-number t]
2643          ["Sort by author" gnus-summary-sort-by-author t]
2644          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2645          ["Sort by subject" gnus-summary-sort-by-subject t]
2646          ["Sort by date" gnus-summary-sort-by-date t]
2647          ["Sort by score" gnus-summary-sort-by-score t]
2648          ["Sort by lines" gnus-summary-sort-by-lines t]
2649          ["Sort by characters" gnus-summary-sort-by-chars t]
2650          ["Randomize" gnus-summary-sort-by-random t]
2651          ["Original sort" gnus-summary-sort-by-original t])
2652         ("Help"
2653          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2654          ["Describe group" gnus-summary-describe-group t]
2655          ["Fetch charter" gnus-group-fetch-charter
2656           ,@(if (featurep 'xemacs) nil
2657               '(:help "Display the charter of the current group"))]
2658          ["Fetch control message" gnus-group-fetch-control
2659           ,@(if (featurep 'xemacs) nil
2660               '(:help "Display the archived control message for the current group"))]
2661          ["Read manual" gnus-info-find-node t])
2662         ("Modes"
2663          ["Pick and read" gnus-pick-mode t]
2664          ["Binary" gnus-binary-mode t])
2665         ("Regeneration"
2666          ["Regenerate" gnus-summary-prepare t]
2667          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2668          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2669          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2670          ["Toggle threading" gnus-summary-toggle-threads t])
2671         ["See old articles" gnus-summary-insert-old-articles t]
2672         ["See new articles" gnus-summary-insert-new-articles t]
2673         ["Filter articles..." gnus-summary-execute-command t]
2674         ["Run command on articles..." gnus-summary-universal-argument t]
2675         ["Search articles forward..." gnus-summary-search-article-forward t]
2676         ["Search articles backward..." gnus-summary-search-article-backward t]
2677         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2678         ["Expand window" gnus-summary-expand-window t]
2679         ["Expire expirable articles" gnus-summary-expire-articles
2680          (gnus-check-backend-function
2681           'request-expire-articles gnus-newsgroup-name)]
2682         ["Edit local kill file" gnus-summary-edit-local-kill t]
2683         ["Edit main kill file" gnus-summary-edit-global-kill t]
2684         ["Edit group parameters" gnus-summary-edit-parameters t]
2685         ["Customize group parameters" gnus-summary-customize-parameters t]
2686         ["Send a bug report" gnus-bug t]
2687         ("Exit"
2688          ["Catchup and exit" gnus-summary-catchup-and-exit
2689           ,@(if (featurep 'xemacs) '(t)
2690               '(:help "Mark unread articles in this group as read, then exit"))]
2691          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2692          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2693          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2694          ["Exit group" gnus-summary-exit
2695           ,@(if (featurep 'xemacs) '(t)
2696               '(:help "Exit current group, return to group selection mode"))]
2697          ["Exit group without updating" gnus-summary-exit-no-update t]
2698          ["Exit and goto next group" gnus-summary-next-group t]
2699          ["Exit and goto prev group" gnus-summary-prev-group t]
2700          ["Reselect group" gnus-summary-reselect-current-group t]
2701          ["Rescan group" gnus-summary-rescan-group t]
2702          ["Update dribble" gnus-summary-save-newsrc t])))
2703
2704     (gnus-run-hooks 'gnus-summary-menu-hook)))
2705
2706 (defvar gnus-summary-tool-bar-map nil)
2707
2708 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2709 ;; affect _new_ message buffers.  We might add a function that walks thru all
2710 ;; summary-mode buffers and force the update.
2711 (defun gnus-summary-tool-bar-update (&optional symbol value)
2712   "Update summary mode toolbar.
2713 Setter function for custom variables."
2714   (setq-default gnus-summary-tool-bar-map nil)
2715   (when symbol
2716     ;; When used as ":set" function:
2717     (set-default symbol value))
2718   (when (gnus-buffer-live-p gnus-summary-buffer)
2719     (with-current-buffer gnus-summary-buffer
2720       (gnus-summary-make-tool-bar))))
2721
2722 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2723                                      'gnus-summary-tool-bar-gnome
2724                                    'gnus-summary-tool-bar-retro)
2725   "Specifies the Gnus summary tool bar.
2726
2727 It can be either a list or a symbol refering to a list.  See
2728 `gmm-tool-bar-from-list' for the format of the list.  The
2729 default key map is `gnus-summary-mode-map'.
2730
2731 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2732 `gnus-summary-tool-bar-retro'."
2733   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2734                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2735                  (repeat :tag "User defined list" gmm-tool-bar-item)
2736                  (symbol))
2737   :version "23.0" ;; No Gnus
2738   :initialize 'custom-initialize-default
2739   :set 'gnus-summary-tool-bar-update
2740   :group 'gnus-summary)
2741
2742 (defcustom gnus-summary-tool-bar-gnome
2743   '((gnus-summary-post-news "mail/compose" nil)
2744     (gnus-summary-insert-new-articles "mail/inbox" nil
2745                                       :visible (or (not gnus-agent)
2746                                                    gnus-plugged))
2747     (gnus-summary-reply-with-original "mail/reply")
2748     (gnus-summary-reply "mail/reply" nil :visible nil)
2749     (gnus-summary-followup-with-original "mail/reply-all")
2750     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2751     (gnus-summary-mail-forward "mail/forward")
2752     (gnus-summary-save-article "mail/save")
2753     (gnus-summary-search-article-forward "search" nil :visible nil)
2754     (gnus-summary-print-article "print")
2755     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2756     ;; Some new commands that may need more suitable icons:
2757     (gnus-summary-save-newsrc "save" nil :visible nil)
2758     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2759     (gnus-summary-prev-article "left-arrow")
2760     (gnus-summary-next-article "right-arrow")
2761     (gnus-summary-next-page "next-page")
2762     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2763     ;;
2764     ;; Maybe some sort-by-... could be added:
2765     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2766     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2767     (gnus-summary-mark-as-expirable
2768      "delete" nil
2769      :visible (gnus-check-backend-function 'request-expire-articles
2770                                            gnus-newsgroup-name))
2771     (gnus-summary-mark-as-spam
2772      "mail/spam" t
2773      :visible (and (fboundp 'spam-group-ham-contents-p)
2774                    (spam-group-ham-contents-p gnus-newsgroup-name))
2775      :help "Mark as spam")
2776     (gnus-summary-mark-as-read-forward
2777      "mail/not-spam" nil
2778      :visible (and (fboundp 'spam-group-spam-contents-p)
2779                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2780     ;;
2781     (gnus-summary-exit "exit")
2782     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2783     (gnus-info-find-node "help"))
2784   "List of functions for the summary tool bar (GNOME style).
2785
2786 See `gmm-tool-bar-from-list' for the format of the list."
2787   :type '(repeat gmm-tool-bar-item)
2788   :version "23.0" ;; No Gnus
2789   :initialize 'custom-initialize-default
2790   :set 'gnus-summary-tool-bar-update
2791   :group 'gnus-summary)
2792
2793 (defcustom gnus-summary-tool-bar-retro
2794   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2795     (gnus-summary-next-unread-article "gnus/next-ur")
2796     (gnus-summary-post-news "gnus/post")
2797     (gnus-summary-followup-with-original "gnus/fuwo")
2798     (gnus-summary-followup "gnus/followup")
2799     (gnus-summary-reply-with-original "gnus/reply-wo")
2800     (gnus-summary-reply "gnus/reply")
2801     (gnus-summary-caesar-message "gnus/rot13")
2802     (gnus-uu-decode-uu "gnus/uu-decode")
2803     (gnus-summary-save-article-file "gnus/save-aif")
2804     (gnus-summary-save-article "gnus/save-art")
2805     (gnus-uu-post-news "gnus/uu-post")
2806     (gnus-summary-catchup "gnus/catchup")
2807     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2808     (gnus-summary-exit "gnus/exit-summ")
2809     ;; Some new command that may need more suitable icons:
2810     (gnus-summary-print-article "gnus/print" nil :visible nil)
2811     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2812     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2813     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2814     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2815     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2816     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2817     ;;
2818     (gnus-info-find-node "gnus/help" nil :visible nil))
2819   "List of functions for the summary tool bar (retro look).
2820
2821 See `gmm-tool-bar-from-list' for the format of the list."
2822   :type '(repeat gmm-tool-bar-item)
2823   :version "23.0" ;; No Gnus
2824   :initialize 'custom-initialize-default
2825   :set 'gnus-summary-tool-bar-update
2826   :group 'gnus-summary)
2827
2828 (defcustom gnus-summary-tool-bar-zap-list t
2829   "List of icon items from the global tool bar.
2830 These items are not displayed in the Gnus summary mode tool bar.
2831
2832 See `gmm-tool-bar-from-list' for the format of the list."
2833   :type 'gmm-tool-bar-zap-list
2834   :version "23.0" ;; No Gnus
2835   :initialize 'custom-initialize-default
2836   :set 'gnus-summary-tool-bar-update
2837   :group 'gnus-summary)
2838
2839 (defvar image-load-path)
2840
2841 (defun gnus-summary-make-tool-bar (&optional force)
2842   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2843 When FORCE, rebuild the tool bar."
2844   (when (and (not (featurep 'xemacs))
2845              (boundp 'tool-bar-mode)
2846              tool-bar-mode
2847              (or (not gnus-summary-tool-bar-map) force))
2848     (let* ((load-path
2849             (gmm-image-load-path-for-library "gnus"
2850                                              "mail/save.xpm"
2851                                              nil t))
2852            (image-load-path (cons (car load-path)
2853                                   (when (boundp 'image-load-path)
2854                                     image-load-path)))
2855            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2856                                         gnus-summary-tool-bar-zap-list
2857                                         'gnus-summary-mode-map)))
2858       (when map
2859         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2860         ;; uses it's value.
2861         (setq gnus-summary-tool-bar-map map))))
2862   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2863
2864 (defun gnus-score-set-default (var value)
2865   "A version of set that updates the GNU Emacs menu-bar."
2866   (set var value)
2867   ;; It is the message that forces the active status to be updated.
2868   (message ""))
2869
2870 (defun gnus-make-score-map (type)
2871   "Make a summary score map of type TYPE."
2872   (if t
2873       nil
2874     (let ((headers '(("author" "from" string)
2875                      ("subject" "subject" string)
2876                      ("article body" "body" string)
2877                      ("article head" "head" string)
2878                      ("xref" "xref" string)
2879                      ("extra header" "extra" string)
2880                      ("lines" "lines" number)
2881                      ("followups to author" "followup" string)))
2882           (types '((number ("less than" <)
2883                            ("greater than" >)
2884                            ("equal" =))
2885                    (string ("substring" s)
2886                            ("exact string" e)
2887                            ("fuzzy string" f)
2888                            ("regexp" r))))
2889           (perms '(("temporary" (current-time-string))
2890                    ("permanent" nil)
2891                    ("immediate" now)))
2892           header)
2893       (list
2894        (apply
2895         'nconc
2896         (list
2897          (if (eq type 'lower)
2898              "Lower score"
2899            "Increase score"))
2900         (let (outh)
2901           (while headers
2902             (setq header (car headers))
2903             (setq outh
2904                   (cons
2905                    (apply
2906                     'nconc
2907                     (list (car header))
2908                     (let ((ts (cdr (assoc (nth 2 header) types)))
2909                           outt)
2910                       (while ts
2911                         (setq outt
2912                               (cons
2913                                (apply
2914                                 'nconc
2915                                 (list (caar ts))
2916                                 (let ((ps perms)
2917                                       outp)
2918                                   (while ps
2919                                     (setq outp
2920                                           (cons
2921                                            (vector
2922                                             (caar ps)
2923                                             (list
2924                                              'gnus-summary-score-entry
2925                                              (nth 1 header)
2926                                              (if (or (string= (nth 1 header)
2927                                                               "head")
2928                                                      (string= (nth 1 header)
2929                                                               "body"))
2930                                                  ""
2931                                                (list 'gnus-summary-header
2932                                                      (nth 1 header)))
2933                                              (list 'quote (nth 1 (car ts)))
2934                                              (list 'gnus-score-delta-default
2935                                                    nil)
2936                                              (nth 1 (car ps))
2937                                              t)
2938                                             t)
2939                                            outp))
2940                                     (setq ps (cdr ps)))
2941                                   (list (nreverse outp))))
2942                                outt))
2943                         (setq ts (cdr ts)))
2944                       (list (nreverse outt))))
2945                    outh))
2946             (setq headers (cdr headers)))
2947           (list (nreverse outh))))))))
2948
2949 \f
2950
2951 (defun gnus-summary-mode (&optional group)
2952   "Major mode for reading articles.
2953
2954 All normal editing commands are switched off.
2955 \\<gnus-summary-mode-map>
2956 Each line in this buffer represents one article.  To read an
2957 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2958 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2959 respectively.
2960
2961 You can also post articles and send mail from this buffer.  To
2962 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2963 of an article, type `\\[gnus-summary-reply]'.
2964
2965 There are approx. one gazillion commands you can execute in this
2966 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2967
2968 The following commands are available:
2969
2970 \\{gnus-summary-mode-map}"
2971   (interactive)
2972   (kill-all-local-variables)
2973   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2974     (gnus-summary-make-local-variables))
2975   (gnus-summary-make-local-variables)
2976   (setq gnus-newsgroup-name group)
2977   (when (gnus-visual-p 'summary-menu 'menu)
2978     (gnus-summary-make-menu-bar)
2979     (gnus-summary-make-tool-bar))
2980   (gnus-make-thread-indent-array)
2981   (gnus-simplify-mode-line)
2982   (setq major-mode 'gnus-summary-mode)
2983   (setq mode-name "Summary")
2984   (make-local-variable 'minor-mode-alist)
2985   (use-local-map gnus-summary-mode-map)
2986   (buffer-disable-undo)
2987   (setq buffer-read-only t              ;Disable modification
2988         show-trailing-whitespace nil)
2989   (setq truncate-lines t)
2990   (setq selective-display t)
2991   (setq selective-display-ellipses t)   ;Display `...'
2992   (gnus-summary-set-display-table)
2993   (gnus-set-default-directory)
2994   (make-local-variable 'gnus-summary-line-format)
2995   (make-local-variable 'gnus-summary-line-format-spec)
2996   (make-local-variable 'gnus-summary-dummy-line-format)
2997   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2998   (make-local-variable 'gnus-summary-mark-positions)
2999   (gnus-make-local-hook 'pre-command-hook)
3000   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3001   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3002   (turn-on-gnus-mailing-list-mode)
3003   (mm-enable-multibyte)
3004   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3005   (gnus-update-summary-mark-positions))
3006
3007 (defun gnus-summary-make-local-variables ()
3008   "Make all the local summary buffer variables."
3009   (let (global)
3010     (dolist (local gnus-summary-local-variables)
3011       (if (consp local)
3012           (progn
3013             (if (eq (cdr local) 'global)
3014                 ;; Copy the global value of the variable.
3015                 (setq global (symbol-value (car local)))
3016               ;; Use the value from the list.
3017               (setq global (eval (cdr local))))
3018             (set (make-local-variable (car local)) global))
3019         ;; Simple nil-valued local variable.
3020         (set (make-local-variable local) nil)))))
3021
3022 (defun gnus-summary-clear-local-variables ()
3023   (let ((locals gnus-summary-local-variables))
3024     (while locals
3025       (if (consp (car locals))
3026           (and (symbolp (caar locals))
3027                (set (caar locals) nil))
3028         (and (symbolp (car locals))
3029              (set (car locals) nil)))
3030       (setq locals (cdr locals)))))
3031
3032 ;; Summary data functions.
3033
3034 (defmacro gnus-data-number (data)
3035   `(car ,data))
3036
3037 (defmacro gnus-data-set-number (data number)
3038   `(setcar ,data ,number))
3039
3040 (defmacro gnus-data-mark (data)
3041   `(nth 1 ,data))
3042
3043 (defmacro gnus-data-set-mark (data mark)
3044   `(setcar (nthcdr 1 ,data) ,mark))
3045
3046 (defmacro gnus-data-pos (data)
3047   `(nth 2 ,data))
3048
3049 (defmacro gnus-data-set-pos (data pos)
3050   `(setcar (nthcdr 2 ,data) ,pos))
3051
3052 (defmacro gnus-data-header (data)
3053   `(nth 3 ,data))
3054
3055 (defmacro gnus-data-set-header (data header)
3056   `(setf (nth 3 ,data) ,header))
3057
3058 (defmacro gnus-data-level (data)
3059   `(nth 4 ,data))
3060
3061 (defmacro gnus-data-unread-p (data)
3062   `(= (nth 1 ,data) gnus-unread-mark))
3063
3064 (defmacro gnus-data-read-p (data)
3065   `(/= (nth 1 ,data) gnus-unread-mark))
3066
3067 (defmacro gnus-data-pseudo-p (data)
3068   `(consp (nth 3 ,data)))
3069
3070 (defmacro gnus-data-find (number)
3071   `(assq ,number gnus-newsgroup-data))
3072
3073 (defmacro gnus-data-find-list (number &optional data)
3074   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3075      (memq (assq ,number bdata)
3076            bdata)))
3077
3078 (defmacro gnus-data-make (number mark pos header level)
3079   `(list ,number ,mark ,pos ,header ,level))
3080
3081 (defun gnus-data-enter (after-article number mark pos header level offset)
3082   (let ((data (gnus-data-find-list after-article)))
3083     (unless data
3084       (error "No such article: %d" after-article))
3085     (setcdr data (cons (gnus-data-make number mark pos header level)
3086                        (cdr data)))
3087     (setq gnus-newsgroup-data-reverse nil)
3088     (gnus-data-update-list (cddr data) offset)))
3089
3090 (defun gnus-data-enter-list (after-article list &optional offset)
3091   (when list
3092     (let ((data (and after-article (gnus-data-find-list after-article)))
3093           (ilist list))
3094       (if (not (or data
3095                    after-article))
3096           (let ((odata gnus-newsgroup-data))
3097             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3098             (when offset
3099               (gnus-data-update-list odata offset)))
3100         ;; Find the last element in the list to be spliced into the main
3101         ;; list.
3102         (setq list (last list))
3103         (if (not data)
3104             (progn
3105               (setcdr list gnus-newsgroup-data)
3106               (setq gnus-newsgroup-data ilist)
3107               (when offset
3108                 (gnus-data-update-list (cdr list) offset)))
3109           (setcdr list (cdr data))
3110           (setcdr data ilist)
3111           (when offset
3112             (gnus-data-update-list (cdr list) offset))))
3113       (setq gnus-newsgroup-data-reverse nil))))
3114
3115 (defun gnus-data-remove (article &optional offset)
3116   (let ((data gnus-newsgroup-data))
3117     (if (= (gnus-data-number (car data)) article)
3118         (progn
3119           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3120                 gnus-newsgroup-data-reverse nil)
3121           (when offset
3122             (gnus-data-update-list gnus-newsgroup-data offset)))
3123       (while (cdr data)
3124         (when (= (gnus-data-number (cadr data)) article)
3125           (setcdr data (cddr data))
3126           (when offset
3127             (gnus-data-update-list (cdr data) offset))
3128           (setq data nil
3129                 gnus-newsgroup-data-reverse nil))
3130         (setq data (cdr data))))))
3131
3132 (defmacro gnus-data-list (backward)
3133   `(if ,backward
3134        (or gnus-newsgroup-data-reverse
3135            (setq gnus-newsgroup-data-reverse
3136                  (reverse gnus-newsgroup-data)))
3137      gnus-newsgroup-data))
3138
3139 (defun gnus-data-update-list (data offset)
3140   "Add OFFSET to the POS of all data entries in DATA."
3141   (setq gnus-newsgroup-data-reverse nil)
3142   (while data
3143     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3144     (setq data (cdr data))))
3145
3146 (defun gnus-summary-article-pseudo-p (article)
3147   "Say whether this article is a pseudo article or not."
3148   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3149
3150 (defmacro gnus-summary-article-sparse-p (article)
3151   "Say whether this article is a sparse article or not."
3152   `(memq ,article gnus-newsgroup-sparse))
3153
3154 (defmacro gnus-summary-article-ancient-p (article)
3155   "Say whether this article is a sparse article or not."
3156   `(memq ,article gnus-newsgroup-ancient))
3157
3158 (defun gnus-article-parent-p (number)
3159   "Say whether this article is a parent or not."
3160   (let ((data (gnus-data-find-list number)))
3161     (and (cdr data)              ; There has to be an article after...
3162          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3163             (gnus-data-level (nth 1 data))))))
3164
3165 (defun gnus-article-children (number)
3166   "Return a list of all children to NUMBER."
3167   (let* ((data (gnus-data-find-list number))
3168          (level (gnus-data-level (car data)))
3169          children)
3170     (setq data (cdr data))
3171     (while (and data
3172                 (= (gnus-data-level (car data)) (1+ level)))
3173       (push (gnus-data-number (car data)) children)
3174       (setq data (cdr data)))
3175     children))
3176
3177 (defmacro gnus-summary-skip-intangible ()
3178   "If the current article is intangible, then jump to a different article."
3179   '(let ((to (get-text-property (point) 'gnus-intangible)))
3180      (and to (gnus-summary-goto-subject to))))
3181
3182 (defmacro gnus-summary-article-intangible-p ()
3183   "Say whether this article is intangible or not."
3184   '(get-text-property (point) 'gnus-intangible))
3185
3186 (defun gnus-article-read-p (article)
3187   "Say whether ARTICLE is read or not."
3188   (not (or (memq article gnus-newsgroup-marked)
3189            (memq article gnus-newsgroup-spam-marked)
3190            (memq article gnus-newsgroup-unreads)
3191            (memq article gnus-newsgroup-unselected)
3192            (memq article gnus-newsgroup-dormant))))
3193
3194 ;; Some summary mode macros.
3195
3196 (defmacro gnus-summary-article-number ()
3197   "The article number of the article on the current line.
3198 If there isn't an article number here, then we return the current
3199 article number."
3200   '(progn
3201      (gnus-summary-skip-intangible)
3202      (or (get-text-property (point) 'gnus-number)
3203          (gnus-summary-last-subject))))
3204
3205 (defmacro gnus-summary-article-header (&optional number)
3206   "Return the header of article NUMBER."
3207   `(gnus-data-header (gnus-data-find
3208                       ,(or number '(gnus-summary-article-number)))))
3209
3210 (defmacro gnus-summary-thread-level (&optional number)
3211   "Return the level of thread that starts with article NUMBER."
3212   `(if (and (eq gnus-summary-make-false-root 'dummy)
3213             (get-text-property (point) 'gnus-intangible))
3214        0
3215      (gnus-data-level (gnus-data-find
3216                        ,(or number '(gnus-summary-article-number))))))
3217
3218 (defmacro gnus-summary-article-mark (&optional number)
3219   "Return the mark of article NUMBER."
3220   `(gnus-data-mark (gnus-data-find
3221                     ,(or number '(gnus-summary-article-number)))))
3222
3223 (defmacro gnus-summary-article-pos (&optional number)
3224   "Return the position of the line of article NUMBER."
3225   `(gnus-data-pos (gnus-data-find
3226                    ,(or number '(gnus-summary-article-number)))))
3227
3228 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3229 (defmacro gnus-summary-article-subject (&optional number)
3230   "Return current subject string or nil if nothing."
3231   `(let ((headers
3232           ,(if number
3233                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3234              '(gnus-data-header (assq (gnus-summary-article-number)
3235                                       gnus-newsgroup-data)))))
3236      (and headers
3237           (vectorp headers)
3238           (mail-header-subject headers))))
3239
3240 (defmacro gnus-summary-article-score (&optional number)
3241   "Return current article score."
3242   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3243                   gnus-newsgroup-scored))
3244        gnus-summary-default-score 0))
3245
3246 (defun gnus-summary-article-children (&optional number)
3247   "Return a list of article numbers that are children of article NUMBER."
3248   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3249          (level (gnus-data-level (car data)))
3250          l children)
3251     (while (and (setq data (cdr data))
3252                 (> (setq l (gnus-data-level (car data))) level))
3253       (and (= (1+ level) l)
3254            (push (gnus-data-number (car data))
3255                  children)))
3256     (nreverse children)))
3257
3258 (defun gnus-summary-article-parent (&optional number)
3259   "Return the article number of the parent of article NUMBER."
3260   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3261                                     (gnus-data-list t)))
3262          (level (gnus-data-level (car data))))
3263     (if (zerop level)
3264         ()                              ; This is a root.
3265       ;; We search until we find an article with a level less than
3266       ;; this one.  That function has to be the parent.
3267       (while (and (setq data (cdr data))
3268                   (not (< (gnus-data-level (car data)) level))))
3269       (and data (gnus-data-number (car data))))))
3270
3271 (defun gnus-unread-mark-p (mark)
3272   "Say whether MARK is the unread mark."
3273   (= mark gnus-unread-mark))
3274
3275 (defun gnus-read-mark-p (mark)
3276   "Say whether MARK is one of the marks that mark as read.
3277 This is all marks except unread, ticked, dormant, and expirable."
3278   (not (or (= mark gnus-unread-mark)
3279            (= mark gnus-ticked-mark)
3280            (= mark gnus-spam-mark)
3281            (= mark gnus-dormant-mark)
3282            (= mark gnus-expirable-mark))))
3283
3284 (defmacro gnus-article-mark (number)
3285   "Return the MARK of article NUMBER.
3286 This macro should only be used when computing the mark the \"first\"
3287 time; i.e., when generating the summary lines.  After that,
3288 `gnus-summary-article-mark' should be used to examine the
3289 marks of articles."
3290   `(cond
3291     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3292     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3293     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3294     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3295     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3296     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3297     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3298     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3299            gnus-ancient-mark))))
3300
3301 ;; Saving hidden threads.
3302
3303 (defmacro gnus-save-hidden-threads (&rest forms)
3304   "Save hidden threads, eval FORMS, and restore the hidden threads."
3305   (let ((config (make-symbol "config")))
3306     `(let ((,config (gnus-hidden-threads-configuration)))
3307        (unwind-protect
3308            (save-excursion
3309              ,@forms)
3310          (gnus-restore-hidden-threads-configuration ,config)))))
3311 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3312 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3313
3314 (defun gnus-data-compute-positions ()
3315   "Compute the positions of all articles."
3316   (setq gnus-newsgroup-data-reverse nil)
3317   (let ((data gnus-newsgroup-data))
3318     (save-excursion
3319       (gnus-save-hidden-threads
3320         (gnus-summary-show-all-threads)
3321         (goto-char (point-min))
3322         (while data
3323           (while (get-text-property (point) 'gnus-intangible)
3324             (forward-line 1))
3325           (gnus-data-set-pos (car data) (+ (point) 3))
3326           (setq data (cdr data))
3327           (forward-line 1))))))
3328
3329 (defun gnus-hidden-threads-configuration ()
3330   "Return the current hidden threads configuration."
3331   (save-excursion
3332     (let (config)
3333       (goto-char (point-min))
3334       (while (search-forward "\r" nil t)
3335         (push (1- (point)) config))
3336       config)))
3337
3338 (defun gnus-restore-hidden-threads-configuration (config)
3339   "Restore hidden threads configuration from CONFIG."
3340   (save-excursion
3341     (let (point buffer-read-only)
3342       (while (setq point (pop config))
3343         (when (and (< point (point-max))
3344                    (goto-char point)
3345                    (eq (char-after) ?\n))
3346           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3347
3348 ;; Various summary mode internalish functions.
3349
3350 (defun gnus-mouse-pick-article (e)
3351   (interactive "e")
3352   (mouse-set-point e)
3353   (gnus-summary-next-page nil t))
3354
3355 (defun gnus-summary-set-display-table ()
3356   "Change the display table.
3357 Odd characters have a tendency to mess
3358 up nicely formatted displays - we make all possible glyphs
3359 display only a single character."
3360
3361   ;; We start from the standard display table, if any.
3362   (let ((table (or (copy-sequence standard-display-table)
3363                    (make-display-table)))
3364         (i 32))
3365     ;; Nix out all the control chars...
3366     (while (>= (setq i (1- i)) 0)
3367       (aset table i [??]))
3368    ;; ... but not newline and cr, of course.  (cr is necessary for the
3369     ;; selective display).
3370     (aset table ?\n nil)
3371     (aset table ?\r nil)
3372     ;; We keep TAB as well.
3373     (aset table ?\t nil)
3374     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3375     ;; Emacs 23 (unicode), that are not set already.
3376     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3377                  160
3378                256)))
3379       (while (>= (setq i (1- i)) 127)
3380         ;; Only modify if the entry is nil.
3381         (unless (aref table i)
3382           (aset table i [??]))))
3383     (setq buffer-display-table table)))
3384
3385 (defun gnus-summary-set-article-display-arrow (pos)
3386   "Update the overlay arrow to point to line at position POS."
3387   (when (and gnus-summary-display-arrow
3388              (boundp 'overlay-arrow-position)
3389              (boundp 'overlay-arrow-string))
3390     (save-excursion
3391       (goto-char pos)
3392       (beginning-of-line)
3393       (unless overlay-arrow-position
3394         (setq overlay-arrow-position (make-marker)))
3395       (setq overlay-arrow-string "=>"
3396             overlay-arrow-position (set-marker overlay-arrow-position
3397                                                (point)
3398                                                (current-buffer))))))
3399
3400 (defun gnus-summary-setup-buffer (group)
3401   "Initialize summary buffer."
3402   (let ((buffer (gnus-summary-buffer-name group))
3403         (dead-name (concat "*Dead Summary "
3404                            (gnus-group-decoded-name group) "*")))
3405     ;; If a dead summary buffer exists, we kill it.
3406     (when (gnus-buffer-live-p dead-name)
3407       (gnus-kill-buffer dead-name))
3408     (if (get-buffer buffer)
3409         (progn
3410           (set-buffer buffer)
3411           (setq gnus-summary-buffer (current-buffer))
3412           (not gnus-newsgroup-prepared))
3413       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3414       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3415       (gnus-summary-mode group)
3416       (when gnus-carpal
3417         (gnus-carpal-setup-buffer 'summary))
3418       (when (gnus-group-quit-config group)
3419         (set (make-local-variable 'gnus-single-article-buffer) nil))
3420       (make-local-variable 'gnus-article-buffer)
3421       (make-local-variable 'gnus-article-current)
3422       (make-local-variable 'gnus-original-article-buffer)
3423       (setq gnus-newsgroup-name group)
3424       ;; Set any local variables in the group parameters.
3425       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3426       t)))
3427
3428 (defun gnus-set-global-variables ()
3429   "Set the global equivalents of the buffer-local variables.
3430 They are set to the latest values they had.  These reflect the summary
3431 buffer that was in action when the last article was fetched."
3432   (when (eq major-mode 'gnus-summary-mode)
3433     (setq gnus-summary-buffer (current-buffer))
3434     (let ((name gnus-newsgroup-name)
3435           (marked gnus-newsgroup-marked)
3436           (spam gnus-newsgroup-spam-marked)
3437           (unread gnus-newsgroup-unreads)
3438           (headers gnus-current-headers)
3439           (data gnus-newsgroup-data)
3440           (summary gnus-summary-buffer)
3441           (article-buffer gnus-article-buffer)
3442           (original gnus-original-article-buffer)
3443           (gac gnus-article-current)
3444           (reffed gnus-reffed-article-number)
3445           (score-file gnus-current-score-file)
3446           (default-charset gnus-newsgroup-charset)
3447           vlist)
3448       (let ((locals gnus-newsgroup-variables))
3449         (while locals
3450           (if (consp (car locals))
3451               (push (eval (caar locals)) vlist)
3452             (push (eval (car locals)) vlist))
3453           (setq locals (cdr locals)))
3454         (setq vlist (nreverse vlist)))
3455       (with-current-buffer gnus-group-buffer
3456         (setq gnus-newsgroup-name name
3457               gnus-newsgroup-marked marked
3458               gnus-newsgroup-spam-marked spam
3459               gnus-newsgroup-unreads unread
3460               gnus-current-headers headers
3461               gnus-newsgroup-data data
3462               gnus-article-current gac
3463               gnus-summary-buffer summary
3464               gnus-article-buffer article-buffer
3465               gnus-original-article-buffer original
3466               gnus-reffed-article-number reffed
3467               gnus-current-score-file score-file
3468               gnus-newsgroup-charset default-charset)
3469         (let ((locals gnus-newsgroup-variables))
3470           (while locals
3471             (if (consp (car locals))
3472                 (set (caar locals) (pop vlist))
3473               (set (car locals) (pop vlist)))
3474             (setq locals (cdr locals))))
3475         ;; The article buffer also has local variables.
3476         (when (gnus-buffer-live-p gnus-article-buffer)
3477           (set-buffer gnus-article-buffer)
3478           (setq gnus-summary-buffer summary))))))
3479
3480 (defun gnus-summary-article-unread-p (article)
3481   "Say whether ARTICLE is unread or not."
3482   (memq article gnus-newsgroup-unreads))
3483
3484 (defun gnus-summary-first-article-p (&optional article)
3485   "Return whether ARTICLE is the first article in the buffer."
3486   (if (not (setq article (or article (gnus-summary-article-number))))
3487       nil
3488     (eq article (caar gnus-newsgroup-data))))
3489
3490 (defun gnus-summary-last-article-p (&optional article)
3491   "Return whether ARTICLE is the last article in the buffer."
3492   (if (not (setq article (or article (gnus-summary-article-number))))
3493       ;; All non-existent numbers are the last article.  :-)
3494       t
3495     (not (cdr (gnus-data-find-list article)))))
3496
3497 (defun gnus-make-thread-indent-array (&optional n)
3498   (when (or n
3499             (progn (setq n 200) nil)
3500             (null gnus-thread-indent-array)
3501             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3502     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3503           gnus-thread-indent-array-level gnus-thread-indent-level)
3504     (while (>= n 0)
3505       (aset gnus-thread-indent-array n
3506             (make-string (* n gnus-thread-indent-level) ? ))
3507       (setq n (1- n)))))
3508
3509 (defun gnus-update-summary-mark-positions ()
3510   "Compute where the summary marks are to go."
3511   (save-excursion
3512     (when (gnus-buffer-exists-p gnus-summary-buffer)
3513       (set-buffer gnus-summary-buffer))
3514     (let ((spec gnus-summary-line-format-spec)
3515           pos)
3516       (save-excursion
3517         (gnus-set-work-buffer)
3518         (let ((gnus-tmp-unread ?Z)
3519               (gnus-replied-mark ?Z)
3520               (gnus-score-below-mark ?Z)
3521               (gnus-score-over-mark ?Z)
3522               (gnus-undownloaded-mark ?Z)
3523               (gnus-summary-line-format-spec spec)
3524               (gnus-newsgroup-downloadable '(0))
3525               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3526               case-fold-search ignores)
3527           ;; Here, all marks are bound to Z.
3528           (gnus-summary-insert-line header
3529                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3530           (goto-char (point-min))
3531           ;; Memorize the positions of the same characters as dummy marks.
3532           (while (re-search-forward "[A-D]" nil t)
3533             (push (point) ignores))
3534           (erase-buffer)
3535           ;; We use A-D as dummy marks in order to know column positions
3536           ;; where marks should be inserted.
3537           (setq gnus-tmp-unread ?A
3538                 gnus-replied-mark ?B
3539                 gnus-score-below-mark ?C
3540                 gnus-score-over-mark ?C
3541                 gnus-undownloaded-mark ?D)
3542           (gnus-summary-insert-line header
3543                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3544           ;; Ignore characters which aren't dummy marks.
3545           (dolist (p ignores)
3546             (delete-region (goto-char (1- p)) p)
3547             (insert ?Z))
3548           (goto-char (point-min))
3549           (setq pos (list (cons 'unread
3550                                 (and (search-forward "A" nil t)
3551                                      (- (point) (point-min) 1)))))
3552           (goto-char (point-min))
3553           (push (cons 'replied (and (search-forward "B" nil t)
3554                                     (- (point) (point-min) 1)))
3555                 pos)
3556           (goto-char (point-min))
3557           (push (cons 'score (and (search-forward "C" nil t)
3558                                   (- (point) (point-min) 1)))
3559                 pos)
3560           (goto-char (point-min))
3561           (push (cons 'download (and (search-forward "D" nil t)
3562                                      (- (point) (point-min) 1)))
3563                 pos)))
3564       (setq gnus-summary-mark-positions pos))))
3565
3566 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3567   "Insert a dummy root in the summary buffer."
3568   (beginning-of-line)
3569   (gnus-add-text-properties
3570    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3571    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3572
3573 (defun gnus-summary-extract-address-component (from)
3574   (or (car (funcall gnus-extract-address-components from))
3575       from))
3576
3577 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3578   (let ((mail-parse-charset gnus-newsgroup-charset)
3579         (ignored-from-addresses (gnus-ignored-from-addresses))
3580         ; Is it really necessary to do this next part for each summary line?
3581         ; Luckily, doesn't seem to slow things down much.
3582         (mail-parse-ignored-charsets
3583          (with-current-buffer gnus-summary-buffer
3584            gnus-newsgroup-ignored-charsets)))
3585     (or
3586      (and ignored-from-addresses
3587           (string-match ignored-from-addresses gnus-tmp-from)
3588           (let ((extra-headers (mail-header-extra header))
3589                 to
3590                 newsgroups)
3591             (cond
3592              ((setq to (cdr (assq 'To extra-headers)))
3593               (concat gnus-summary-to-prefix
3594                       (inline
3595                         (gnus-summary-extract-address-component
3596                          (funcall gnus-decode-encoded-address-function to)))))
3597              ((setq newsgroups
3598                     (or
3599                      (cdr (assq 'Newsgroups extra-headers))
3600                      (and
3601                       (memq 'Newsgroups gnus-extra-headers)
3602                       (eq (car (gnus-find-method-for-group
3603                                 gnus-newsgroup-name)) 'nntp)
3604                       (gnus-group-real-name gnus-newsgroup-name))))
3605               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3606      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3607
3608 (defun gnus-summary-insert-line (gnus-tmp-header
3609                                  gnus-tmp-level gnus-tmp-current
3610                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3611                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3612                                  &optional gnus-tmp-dummy gnus-tmp-score
3613                                  gnus-tmp-process)
3614   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3615       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3616                                           gnus-tmp-level)))
3617   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3618          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3619          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3620          (gnus-tmp-score-char
3621           (if (or (null gnus-summary-default-score)
3622                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3623                       gnus-summary-zcore-fuzz))
3624               ?                         ;Whitespace
3625             (if (< gnus-tmp-score gnus-summary-default-score)
3626                 gnus-score-below-mark gnus-score-over-mark)))
3627          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3628          (gnus-tmp-replied
3629           (cond (gnus-tmp-process gnus-process-mark)
3630                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3631                  gnus-cached-mark)
3632                 (gnus-tmp-replied gnus-replied-mark)
3633                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3634                  gnus-forwarded-mark)
3635                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3636                  gnus-saved-mark)
3637                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3638                  gnus-recent-mark)
3639                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3640                  gnus-unseen-mark)
3641                 (t gnus-no-mark)))
3642          (gnus-tmp-downloaded
3643           (cond (undownloaded
3644                  gnus-undownloaded-mark)
3645                 (gnus-newsgroup-agentized
3646                  gnus-downloaded-mark)
3647                 (t
3648                  gnus-no-mark)))
3649          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3650          (gnus-tmp-name
3651           (cond
3652            ((string-match "<[^>]+> *$" gnus-tmp-from)
3653             (let ((beg (match-beginning 0)))
3654               (or (and (string-match "^\".+\"" gnus-tmp-from)
3655                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3656                   (substring gnus-tmp-from 0 beg))))
3657            ((string-match "(.+)" gnus-tmp-from)
3658             (substring gnus-tmp-from
3659                        (1+ (match-beginning 0)) (1- (match-end 0))))
3660            (t gnus-tmp-from)))
3661          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3662          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3663          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3664          (buffer-read-only nil))
3665     (when (string= gnus-tmp-name "")
3666       (setq gnus-tmp-name gnus-tmp-from))
3667     (unless (numberp gnus-tmp-lines)
3668       (setq gnus-tmp-lines -1))
3669     (if (= gnus-tmp-lines -1)
3670         (setq gnus-tmp-lines "?")
3671       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3672       (gnus-put-text-property
3673      (point)
3674      (progn (eval gnus-summary-line-format-spec) (point))
3675        'gnus-number gnus-tmp-number)
3676     (when (gnus-visual-p 'summary-highlight 'highlight)
3677       (forward-line -1)
3678       (gnus-run-hooks 'gnus-summary-update-hook)
3679       (forward-line 1))))
3680
3681 (defun gnus-summary-update-line (&optional dont-update)
3682   "Update summary line after change."
3683   (when (and gnus-summary-default-score
3684              (not gnus-summary-inhibit-highlight))
3685     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3686            (article (gnus-summary-article-number))
3687            (score (gnus-summary-article-score article)))
3688       (unless dont-update
3689         (if (and gnus-summary-mark-below
3690                  (< (gnus-summary-article-score)
3691                     gnus-summary-mark-below))
3692             ;; This article has a low score, so we mark it as read.
3693             (when (memq article gnus-newsgroup-unreads)
3694               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3695           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3696             ;; This article was previously marked as read on account
3697             ;; of a low score, but now it has risen, so we mark it as
3698             ;; unread.
3699             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3700         (gnus-summary-update-mark
3701          (if (or (null gnus-summary-default-score)
3702                  (<= (abs (- score gnus-summary-default-score))
3703                      gnus-summary-zcore-fuzz))
3704              ?                          ;Whitespace
3705            (if (< score gnus-summary-default-score)
3706                gnus-score-below-mark gnus-score-over-mark))
3707          'score))
3708       ;; Do visual highlighting.
3709       (when (gnus-visual-p 'summary-highlight 'highlight)
3710         (gnus-run-hooks 'gnus-summary-update-hook)))))
3711
3712 (defvar gnus-tmp-new-adopts nil)
3713
3714 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3715   "Return the number of articles in THREAD.
3716 This may be 0 in some cases -- if none of the articles in
3717 the thread are to be displayed."
3718   (let* ((number
3719          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3720           (cond
3721            ((not (listp thread))
3722             1)
3723            ((and (consp thread) (cdr thread))
3724             (apply
3725              '+ 1 (mapcar
3726                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3727            ((null thread)
3728             1)
3729            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3730             1)
3731            (t 0))))
3732     (when (and level (zerop level) gnus-tmp-new-adopts)
3733       (incf number
3734             (apply '+ (mapcar
3735                        'gnus-summary-number-of-articles-in-thread
3736                        gnus-tmp-new-adopts))))
3737     (if char
3738         (if (> number 1) gnus-not-empty-thread-mark
3739           gnus-empty-thread-mark)
3740       number)))
3741
3742 (defsubst gnus-summary-line-message-size (head)
3743   "Return pretty-printed version of message size.
3744 This function is intended to be used in
3745 `gnus-summary-line-format-alist'."
3746   (let ((c (or (mail-header-chars head) -1)))
3747     (cond ((< c 0) "n/a")               ; chars not available
3748           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3749           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3750           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3751           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3752
3753
3754 (defun gnus-summary-set-local-parameters (group)
3755   "Go through the local params of GROUP and set all variable specs in that list."
3756   (let ((vars '(quit-config)))          ; Ignore quit-config.
3757     (dolist (elem (gnus-group-find-parameter group))
3758       (and (consp elem)                 ; Has to be a cons.
3759            (consp (cdr elem))           ; The cdr has to be a list.
3760            (symbolp (car elem))         ; Has to be a symbol in there.
3761            (not (memq (car elem) vars))
3762            (ignore-errors               ; So we set it.
3763              (push (car elem) vars)
3764              (make-local-variable (car elem))
3765              (set (car elem) (eval (nth 1 elem))))))))
3766
3767 (defun gnus-summary-read-group (group &optional show-all no-article
3768                                       kill-buffer no-display backward
3769                                       select-articles)
3770   "Start reading news in newsgroup GROUP.
3771 If SHOW-ALL is non-nil, already read articles are also listed.
3772 If NO-ARTICLE is non-nil, no article is selected initially.
3773 If NO-DISPLAY, don't generate a summary buffer."
3774   (let (result)
3775     (while (and group
3776                 (null (setq result
3777                             (let ((gnus-auto-select-next nil))
3778                               (or (gnus-summary-read-group-1
3779                                    group show-all no-article
3780                                    kill-buffer no-display
3781                                    select-articles)
3782                                   (setq show-all nil
3783                                         select-articles nil)))))
3784                 (eq gnus-auto-select-next 'quietly))
3785       (set-buffer gnus-group-buffer)
3786       ;; The entry function called above goes to the next
3787       ;; group automatically, so we go two groups back
3788       ;; if we are searching for the previous group.
3789       (when backward
3790         (gnus-group-prev-unread-group 2))
3791       (if (not (equal group (gnus-group-group-name)))
3792           (setq group (gnus-group-group-name))
3793         (setq group nil)))
3794     result))
3795
3796 (defun gnus-summary-read-group-1 (group show-all no-article
3797                                         kill-buffer no-display
3798                                         &optional select-articles)
3799   ;; Killed foreign groups can't be entered.
3800   ;;  (when (and (not (gnus-group-native-p group))
3801   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3802   ;;    (error "Dead non-native groups can't be entered"))
3803   (gnus-message 5 "Retrieving newsgroup: %s..."
3804                 (gnus-group-decoded-name group))
3805   (let* ((new-group (gnus-summary-setup-buffer group))
3806          (quit-config (gnus-group-quit-config group))
3807          (did-select (and new-group (gnus-select-newsgroup
3808                                      group show-all select-articles))))
3809     (cond
3810      ;; This summary buffer exists already, so we just select it.
3811      ((not new-group)
3812       (gnus-set-global-variables)
3813       (when kill-buffer
3814         (gnus-kill-or-deaden-summary kill-buffer))
3815       (gnus-configure-windows 'summary 'force)
3816       (gnus-set-mode-line 'summary)
3817       (gnus-summary-position-point)
3818       (message "")
3819       t)
3820      ;; We couldn't select this group.
3821      ((null did-select)
3822       (when (and (eq major-mode 'gnus-summary-mode)
3823                  (not (equal (current-buffer) kill-buffer)))
3824         (kill-buffer (current-buffer))
3825         (if (not quit-config)
3826             (progn
3827               ;; Update the info -- marks might need to be removed,
3828               ;; for instance.
3829               (gnus-summary-update-info)
3830               (set-buffer gnus-group-buffer)
3831               (gnus-group-jump-to-group group)
3832               (gnus-group-next-unread-group 1))
3833           (gnus-handle-ephemeral-exit quit-config)))
3834       (let ((grpinfo (gnus-get-info group)))
3835         (if (null (gnus-info-read grpinfo))
3836             (gnus-message 3 "Group %s contains no messages"
3837                           (gnus-group-decoded-name group))
3838           (gnus-message 3 "Can't select group")))
3839       nil)
3840      ;; The user did a `C-g' while prompting for number of articles,
3841      ;; so we exit this group.
3842      ((eq did-select 'quit)
3843       (and (eq major-mode 'gnus-summary-mode)
3844            (not (equal (current-buffer) kill-buffer))
3845            (kill-buffer (current-buffer)))
3846       (when kill-buffer
3847         (gnus-kill-or-deaden-summary kill-buffer))
3848       (if (not quit-config)
3849           (progn
3850             (set-buffer gnus-group-buffer)
3851             (gnus-group-jump-to-group group)
3852             (gnus-group-next-unread-group 1)
3853             (gnus-configure-windows 'group 'force))
3854         (gnus-handle-ephemeral-exit quit-config))
3855       ;; Finally signal the quit.
3856       (signal 'quit nil))
3857      ;; The group was successfully selected.
3858      (t
3859       (gnus-set-global-variables)
3860       ;; Save the active value in effect when the group was entered.
3861       (setq gnus-newsgroup-active
3862             (gnus-copy-sequence
3863              (gnus-active gnus-newsgroup-name)))
3864       ;; You can change the summary buffer in some way with this hook.
3865       (gnus-run-hooks 'gnus-select-group-hook)
3866       (when (memq 'summary (gnus-update-format-specifications
3867                             nil 'summary 'summary-mode 'summary-dummy))
3868         ;; The format specification for the summary line was updated,
3869         ;; so we need to update the mark positions as well.
3870         (gnus-update-summary-mark-positions))
3871       ;; Do score processing.
3872       (when gnus-use-scoring
3873         (gnus-possibly-score-headers))
3874       ;; Check whether to fill in the gaps in the threads.
3875       (when gnus-build-sparse-threads
3876         (gnus-build-sparse-threads))
3877       ;; Find the initial limit.
3878       (if show-all
3879           (let ((gnus-newsgroup-dormant nil))
3880             (gnus-summary-initial-limit show-all))
3881         (gnus-summary-initial-limit show-all))
3882       ;; Generate the summary buffer.
3883       (unless no-display
3884         (gnus-summary-prepare))
3885       (when gnus-use-trees
3886         (gnus-tree-open group)
3887         (setq gnus-summary-highlight-line-function
3888               'gnus-tree-highlight-article))
3889       ;; If the summary buffer is empty, but there are some low-scored
3890       ;; articles or some excluded dormants, we include these in the
3891       ;; buffer.
3892       (when (and (zerop (buffer-size))
3893                  (not no-display))
3894         (cond (gnus-newsgroup-dormant
3895                (gnus-summary-limit-include-dormant))
3896               ((and gnus-newsgroup-scored show-all)
3897                (gnus-summary-limit-include-expunged t))))
3898       ;; Function `gnus-apply-kill-file' must be called in this hook.
3899       (gnus-run-hooks 'gnus-apply-kill-hook)
3900       (if (and (zerop (buffer-size))
3901                (not no-display))
3902           (progn
3903             ;; This newsgroup is empty.
3904             (gnus-summary-catchup-and-exit nil t)
3905             (gnus-message 6 "No unread news")
3906             (when kill-buffer
3907               (gnus-kill-or-deaden-summary kill-buffer))
3908             ;; Return nil from this function.
3909             nil)
3910         ;; Hide conversation thread subtrees.  We cannot do this in
3911         ;; gnus-summary-prepare-hook since kill processing may not
3912         ;; work with hidden articles.
3913         (gnus-summary-maybe-hide-threads)
3914         (when kill-buffer
3915           (gnus-kill-or-deaden-summary kill-buffer))
3916         (gnus-summary-auto-select-subject)
3917         ;; Show first unread article if requested.
3918         (if (and (not no-article)
3919                  (not no-display)
3920                  gnus-newsgroup-unreads
3921                  gnus-auto-select-first)
3922             (progn
3923               (gnus-configure-windows 'summary)
3924               (let ((art (gnus-summary-article-number)))
3925                 (unless (and (not gnus-plugged)
3926                              (or (memq art gnus-newsgroup-undownloaded)
3927                                  (memq art gnus-newsgroup-downloadable)))
3928                   (gnus-summary-goto-article art))))
3929           ;; Don't select any articles.
3930           (gnus-summary-position-point)
3931           (gnus-configure-windows 'summary 'force)
3932           (gnus-set-mode-line 'summary))
3933         (when (and gnus-auto-center-group
3934                    (get-buffer-window gnus-group-buffer t))
3935           ;; Gotta use windows, because recenter does weird stuff if
3936           ;; the current buffer ain't the displayed window.
3937           (let ((owin (selected-window)))
3938             (select-window (get-buffer-window gnus-group-buffer t))
3939             (when (gnus-group-goto-group group)
3940               (recenter))
3941             (select-window owin)))
3942         ;; Mark this buffer as "prepared".
3943         (setq gnus-newsgroup-prepared t)
3944         (gnus-run-hooks 'gnus-summary-prepared-hook)
3945         (unless (gnus-ephemeral-group-p group)
3946           (gnus-group-update-group group))
3947         t)))))
3948
3949 (defun gnus-summary-auto-select-subject ()
3950   "Select the subject line on initial group entry."
3951   (goto-char (point-min))
3952   (cond
3953    ((eq gnus-auto-select-subject 'best)
3954     (gnus-summary-best-unread-subject))
3955    ((eq gnus-auto-select-subject 'unread)
3956     (gnus-summary-first-unread-subject))
3957    ((eq gnus-auto-select-subject 'unseen)
3958     (gnus-summary-first-unseen-subject))
3959    ((eq gnus-auto-select-subject 'unseen-or-unread)
3960     (gnus-summary-first-unseen-or-unread-subject))
3961    ((eq gnus-auto-select-subject 'first)
3962     ;; Do nothing.
3963     )
3964    ((functionp gnus-auto-select-subject)
3965     (funcall gnus-auto-select-subject))))
3966
3967 (defun gnus-summary-prepare ()
3968   "Generate the summary buffer."
3969   (interactive)
3970   (let ((buffer-read-only nil))
3971     (erase-buffer)
3972     (setq gnus-newsgroup-data nil
3973           gnus-newsgroup-data-reverse nil)
3974     (gnus-run-hooks 'gnus-summary-generate-hook)
3975     ;; Generate the buffer, either with threads or without.
3976     (when gnus-newsgroup-headers
3977       (gnus-summary-prepare-threads
3978        (if gnus-show-threads
3979            (gnus-sort-gathered-threads
3980             (funcall gnus-summary-thread-gathering-function
3981                      (gnus-sort-threads
3982                       (gnus-cut-threads (gnus-make-threads)))))
3983          ;; Unthreaded display.
3984          (gnus-sort-articles gnus-newsgroup-headers))))
3985     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3986     ;; Call hooks for modifying summary buffer.
3987     (goto-char (point-min))
3988     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3989
3990 (defsubst gnus-general-simplify-subject (subject)
3991   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3992   (setq subject
3993         (cond
3994          ;; Truncate the subject.
3995          (gnus-simplify-subject-functions
3996           (gnus-map-function gnus-simplify-subject-functions subject))
3997          ((numberp gnus-summary-gather-subject-limit)
3998           (setq subject (gnus-simplify-subject-re subject))
3999           (if (> (length subject) gnus-summary-gather-subject-limit)
4000               (substring subject 0 gnus-summary-gather-subject-limit)
4001             subject))
4002          ;; Fuzzily simplify it.
4003          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4004           (gnus-simplify-subject-fuzzy subject))
4005          ;; Just remove the leading "Re:".
4006          (t
4007           (gnus-simplify-subject-re subject))))
4008
4009   (if (and gnus-summary-gather-exclude-subject
4010            (string-match gnus-summary-gather-exclude-subject subject))
4011       nil                         ; This article shouldn't be gathered
4012     subject))
4013
4014 (defun gnus-summary-simplify-subject-query ()
4015   "Query where the respool algorithm would put this article."
4016   (interactive)
4017   (gnus-summary-select-article)
4018   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4019
4020 (defun gnus-gather-threads-by-subject (threads)
4021   "Gather threads by looking at Subject headers."
4022   (if (not gnus-summary-make-false-root)
4023       threads
4024     (let ((hashtb (gnus-make-hashtable 1024))
4025           (prev threads)
4026           (result threads)
4027           subject hthread whole-subject)
4028       (while threads
4029         (setq subject (gnus-general-simplify-subject
4030                        (setq whole-subject (mail-header-subject
4031                                             (caar threads)))))
4032         (when subject
4033           (if (setq hthread (gnus-gethash subject hashtb))
4034               (progn
4035                 ;; We enter a dummy root into the thread, if we
4036                 ;; haven't done that already.
4037                 (unless (stringp (caar hthread))
4038                   (setcar hthread (list whole-subject (car hthread))))
4039                 ;; We add this new gathered thread to this gathered
4040                 ;; thread.
4041                 (setcdr (car hthread)
4042                         (nconc (cdar hthread) (list (car threads))))
4043                 ;; Remove it from the list of threads.
4044                 (setcdr prev (cdr threads))
4045                 (setq threads prev))
4046             ;; Enter this thread into the hash table.
4047             (gnus-sethash subject
4048                           (if gnus-summary-make-false-root-always
4049                               (progn
4050                                 ;; If you want a dummy root above all
4051                                 ;; threads...
4052                                 (setcar threads (list whole-subject
4053                                                       (car threads)))
4054                                 threads)
4055                             threads)
4056                           hashtb)))
4057         (setq prev threads)
4058         (setq threads (cdr threads)))
4059       result)))
4060
4061 (defun gnus-gather-threads-by-references (threads)
4062   "Gather threads by looking at References headers."
4063   (let ((idhashtb (gnus-make-hashtable 1024))
4064         (thhashtb (gnus-make-hashtable 1024))
4065         (prev threads)
4066         (result threads)
4067         ids references id gthread gid entered ref)
4068     (while threads
4069       (when (setq references (mail-header-references (caar threads)))
4070         (setq id (mail-header-id (caar threads))
4071               ids (inline (gnus-split-references references))
4072               entered nil)
4073         (while (setq ref (pop ids))
4074           (setq ids (delete ref ids))
4075           (if (not (setq gid (gnus-gethash ref idhashtb)))
4076               (progn
4077                 (gnus-sethash ref id idhashtb)
4078                 (gnus-sethash id threads thhashtb))
4079             (setq gthread (gnus-gethash gid thhashtb))
4080             (unless entered
4081               ;; We enter a dummy root into the thread, if we
4082               ;; haven't done that already.
4083               (unless (stringp (caar gthread))
4084                 (setcar gthread (list (mail-header-subject (caar gthread))
4085                                       (car gthread))))
4086               ;; We add this new gathered thread to this gathered
4087               ;; thread.
4088               (setcdr (car gthread)
4089                       (nconc (cdar gthread) (list (car threads)))))
4090             ;; Add it into the thread hash table.
4091             (gnus-sethash id gthread thhashtb)
4092             (setq entered t)
4093             ;; Remove it from the list of threads.
4094             (setcdr prev (cdr threads))
4095             (setq threads prev))))
4096       (setq prev threads)
4097       (setq threads (cdr threads)))
4098     result))
4099
4100 (defun gnus-sort-gathered-threads (threads)
4101   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4102   (let ((result threads))
4103     (while threads
4104       (when (stringp (caar threads))
4105         (setcdr (car threads)
4106                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4107       (setq threads (cdr threads)))
4108     result))
4109
4110 (defun gnus-thread-loop-p (root thread)
4111   "Say whether ROOT is in THREAD."
4112   (let ((stack (list thread))
4113         (infloop 0)
4114         th)
4115     (while (setq thread (pop stack))
4116       (setq th (cdr thread))
4117       (while (and th
4118                   (not (eq (caar th) root)))
4119         (pop th))
4120       (if th
4121           ;; We have found a loop.
4122           (let (ref-dep)
4123             (setcdr thread (delq (car th) (cdr thread)))
4124             (if (boundp (setq ref-dep (intern "none"
4125                                               gnus-newsgroup-dependencies)))
4126                 (setcdr (symbol-value ref-dep)
4127                         (nconc (cdr (symbol-value ref-dep))
4128                                (list (car th))))
4129               (set ref-dep (list nil (car th))))
4130             (setq infloop 1
4131                   stack nil))
4132         ;; Push all the subthreads onto the stack.
4133         (push (cdr thread) stack)))
4134     infloop))
4135
4136 (defun gnus-make-threads ()
4137   "Go through the dependency hashtb and find the roots.  Return all threads."
4138   (let (threads)
4139     (while (catch 'infloop
4140              (mapatoms
4141               (lambda (refs)
4142                 ;; Deal with self-referencing References loops.
4143                 (when (and (car (symbol-value refs))
4144                            (not (zerop
4145                                  (apply
4146                                   '+
4147                                   (mapcar
4148                                    (lambda (thread)
4149                                      (gnus-thread-loop-p
4150                                       (car (symbol-value refs)) thread))
4151                                    (cdr (symbol-value refs)))))))
4152                   (setq threads nil)
4153                   (throw 'infloop t))
4154                 (unless (car (symbol-value refs))
4155                   ;; These threads do not refer back to any other
4156                   ;; articles, so they're roots.
4157                   (setq threads (append (cdr (symbol-value refs)) threads))))
4158               gnus-newsgroup-dependencies)))
4159     threads))
4160
4161 ;; Build the thread tree.
4162 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4163   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4164
4165 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4166 if it was already present.
4167
4168 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4169 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4170 Message-IDs will be renamed to a unique Message-ID before being
4171 entered.
4172
4173 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4174   (let* ((id (mail-header-id header))
4175          (id-dep (and id (intern id dependencies)))
4176          parent-id ref ref-dep ref-header replaced)
4177     ;; Enter this `header' in the `dependencies' table.
4178     (cond
4179      ((not id-dep)
4180       (setq header nil))
4181      ;; The first two cases do the normal part: enter a new `header'
4182      ;; in the `dependencies' table.
4183      ((not (boundp id-dep))
4184       (set id-dep (list header)))
4185      ((null (car (symbol-value id-dep)))
4186       (setcar (symbol-value id-dep) header))
4187
4188      ;; From here the `header' was already present in the
4189      ;; `dependencies' table.
4190      (force-new
4191       ;; Overrides an existing entry;
4192       ;; just set the header part of the entry.
4193       (setcar (symbol-value id-dep) header)
4194       (setq replaced t))
4195
4196      ;; Renames the existing `header' to a unique Message-ID.
4197      ((not gnus-summary-ignore-duplicates)
4198       ;; An article with this Message-ID has already been seen.
4199       ;; We rename the Message-ID.
4200       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4201            (list header))
4202       (mail-header-set-id header id))
4203
4204      ;; The last case ignores an existing entry, except it adds any
4205      ;; additional Xrefs (in case the two articles came from different
4206      ;; servers.
4207      ;; Also sets `header' to `nil' meaning that the `dependencies'
4208      ;; table was *not* modified.
4209      (t
4210       (mail-header-set-xref
4211        (car (symbol-value id-dep))
4212        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4213                    "")
4214                (or (mail-header-xref header) "")))
4215       (setq header nil)))
4216
4217     (when (and header (not replaced))
4218       ;; First check that we are not creating a References loop.
4219       (setq parent-id (gnus-parent-id (mail-header-references header)))
4220       (setq ref parent-id)
4221       (while (and ref
4222                   (setq ref-dep (intern-soft ref dependencies))
4223                   (boundp ref-dep)
4224                   (setq ref-header (car (symbol-value ref-dep))))
4225         (if (string= id ref)
4226             ;; Yuk!  This is a reference loop.  Make the article be a
4227             ;; root article.
4228             (progn
4229               (mail-header-set-references (car (symbol-value id-dep)) "none")
4230               (setq ref nil)
4231               (setq parent-id nil))
4232           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4233       (setq ref-dep (intern (or parent-id "none") dependencies))
4234       (if (boundp ref-dep)
4235           (setcdr (symbol-value ref-dep)
4236                   (nconc (cdr (symbol-value ref-dep))
4237                          (list (symbol-value id-dep))))
4238         (set ref-dep (list nil (symbol-value id-dep)))))
4239     header))
4240
4241 (defun gnus-extract-message-id-from-in-reply-to (string)
4242   (if (string-match "<[^>]+>" string)
4243       (substring string (match-beginning 0) (match-end 0))
4244     nil))
4245
4246 (defun gnus-build-sparse-threads ()
4247   (let ((headers gnus-newsgroup-headers)
4248         (mail-parse-charset gnus-newsgroup-charset)
4249         (gnus-summary-ignore-duplicates t)
4250         header references generation relations
4251         subject child end new-child date)
4252     ;; First we create an alist of generations/relations, where
4253     ;; generations is how much we trust the relation, and the relation
4254     ;; is parent/child.
4255     (gnus-message 7 "Making sparse threads...")
4256     (save-excursion
4257       (nnheader-set-temp-buffer " *gnus sparse threads*")
4258       (while (setq header (pop headers))
4259         (when (and (setq references (mail-header-references header))
4260                    (not (string= references "")))
4261           (insert references)
4262           (setq child (mail-header-id header)
4263                 subject (mail-header-subject header)
4264                 date (mail-header-date header)
4265                 generation 0)
4266           (while (search-backward ">" nil t)
4267             (setq end (1+ (point)))
4268             (when (search-backward "<" nil t)
4269               (setq new-child (buffer-substring (point) end))
4270               (push (list (incf generation)
4271                           child (setq child new-child)
4272                           subject date)
4273                     relations)))
4274           (when child
4275             (push (list (1+ generation) child nil subject) relations))
4276           (erase-buffer)))
4277       (kill-buffer (current-buffer)))
4278     ;; Sort over trustworthiness.
4279     (mapcar
4280      (lambda (relation)
4281        (when (gnus-dependencies-add-header
4282               (make-full-mail-header
4283                gnus-reffed-article-number
4284                (nth 3 relation) "" (or (nth 4 relation) "")
4285                (nth 1 relation)
4286                (or (nth 2 relation) "") 0 0 "")
4287               gnus-newsgroup-dependencies nil)
4288          (push gnus-reffed-article-number gnus-newsgroup-limit)
4289          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4290          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4291                gnus-newsgroup-reads)
4292          (decf gnus-reffed-article-number)))
4293      (sort relations 'car-less-than-car))
4294     (gnus-message 7 "Making sparse threads...done")))
4295
4296 (defun gnus-build-old-threads ()
4297   ;; Look at all the articles that refer back to old articles, and
4298   ;; fetch the headers for the articles that aren't there.  This will
4299   ;; build complete threads - if the roots haven't been expired by the
4300   ;; server, that is.
4301   (let ((mail-parse-charset gnus-newsgroup-charset)
4302         id heads)
4303     (mapatoms
4304      (lambda (refs)
4305        (when (not (car (symbol-value refs)))
4306          (setq heads (cdr (symbol-value refs)))
4307          (while heads
4308            (if (memq (mail-header-number (caar heads))
4309                      gnus-newsgroup-dormant)
4310                (setq heads (cdr heads))
4311              (setq id (symbol-name refs))
4312              (while (and (setq id (gnus-build-get-header id))
4313                          (not (car (gnus-id-to-thread id)))))
4314              (setq heads nil)))))
4315      gnus-newsgroup-dependencies)))
4316
4317 (defsubst gnus-remove-odd-characters (string)
4318   "Translate STRING into something that doesn't contain weird characters."
4319   (mm-subst-char-in-string
4320    ?\r ?\-
4321    (mm-subst-char-in-string ?\n ?\- string t) t))
4322
4323 ;; This function has to be called with point after the article number
4324 ;; on the beginning of the line.
4325 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4326   (let ((eol (point-at-eol))
4327         (buffer (current-buffer))
4328         header references in-reply-to)
4329
4330     ;; overview: [num subject from date id refs chars lines misc]
4331     (unwind-protect
4332         (let (x)
4333           (narrow-to-region (point) eol)
4334           (unless (eobp)
4335             (forward-char))
4336
4337           (setq header
4338                 (make-full-mail-header
4339                  number                 ; number
4340                  (condition-case ()     ; subject
4341                      (gnus-remove-odd-characters
4342                       (funcall gnus-decode-encoded-word-function
4343                                (setq x (nnheader-nov-field))))
4344                    (error x))
4345                  (condition-case ()     ; from
4346                      (gnus-remove-odd-characters
4347                       (funcall gnus-decode-encoded-address-function
4348                                (setq x (nnheader-nov-field))))
4349                    (error x))
4350                  (nnheader-nov-field)   ; date
4351                  (nnheader-nov-read-message-id number)  ; id
4352                  (setq references (nnheader-nov-field)) ; refs
4353                  (nnheader-nov-read-integer) ; chars
4354                  (nnheader-nov-read-integer) ; lines
4355                  (unless (eobp)
4356                    (if (looking-at "Xref: ")
4357                        (goto-char (match-end 0)))
4358                    (nnheader-nov-field)) ; Xref
4359                  (nnheader-nov-parse-extra)))) ; extra
4360
4361       (widen))
4362
4363     (when (and (string= references "")
4364                (setq in-reply-to (mail-header-extra header))
4365                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4366       (mail-header-set-references
4367        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4368
4369     (when gnus-alter-header-function
4370       (funcall gnus-alter-header-function header))
4371     (gnus-dependencies-add-header header dependencies force-new)))
4372
4373 (defun gnus-build-get-header (id)
4374   "Look through the buffer of NOV lines and find the header to ID.
4375 Enter this line into the dependencies hash table, and return
4376 the id of the parent article (if any)."
4377   (let ((deps gnus-newsgroup-dependencies)
4378         found header)
4379     (prog1
4380         (save-excursion
4381           (set-buffer nntp-server-buffer)
4382           (let ((case-fold-search nil))
4383             (goto-char (point-min))
4384             (while (and (not found)
4385                         (search-forward id nil t))
4386               (beginning-of-line)
4387               (setq found (looking-at
4388                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4389                                    (regexp-quote id))))
4390               (or found (beginning-of-line 2)))
4391             (when found
4392               (beginning-of-line)
4393               (and
4394                (setq header (gnus-nov-parse-line
4395                              (read (current-buffer)) deps))
4396                (gnus-parent-id (mail-header-references header))))))
4397       (when header
4398         (let ((number (mail-header-number header)))
4399           (push number gnus-newsgroup-limit)
4400           (push header gnus-newsgroup-headers)
4401           (if (memq number gnus-newsgroup-unselected)
4402               (progn
4403                 (setq gnus-newsgroup-unreads
4404                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4405                                                number))
4406                 (setq gnus-newsgroup-unselected
4407                       (delq number gnus-newsgroup-unselected)))
4408             (push number gnus-newsgroup-ancient)))))))
4409
4410 (defun gnus-build-all-threads ()
4411   "Read all the headers."
4412   (let ((gnus-summary-ignore-duplicates t)
4413         (mail-parse-charset gnus-newsgroup-charset)
4414         (dependencies gnus-newsgroup-dependencies)
4415         header article)
4416     (save-excursion
4417       (set-buffer nntp-server-buffer)
4418       (let ((case-fold-search nil))
4419         (goto-char (point-min))
4420         (while (not (eobp))
4421           (ignore-errors
4422             (setq article (read (current-buffer))
4423                   header (gnus-nov-parse-line article dependencies)))
4424           (when header
4425             (with-current-buffer gnus-summary-buffer
4426               (push header gnus-newsgroup-headers)
4427               (if (memq (setq article (mail-header-number header))
4428                         gnus-newsgroup-unselected)
4429                   (progn
4430                     (setq gnus-newsgroup-unreads
4431                           (gnus-add-to-sorted-list
4432                            gnus-newsgroup-unreads article))
4433                     (setq gnus-newsgroup-unselected
4434                           (delq article gnus-newsgroup-unselected)))
4435                 (push article gnus-newsgroup-ancient)))
4436             (forward-line 1)))))))
4437
4438 (defun gnus-summary-update-article-line (article header)
4439   "Update the line for ARTICLE using HEADER."
4440   (let* ((id (mail-header-id header))
4441          (thread (gnus-id-to-thread id)))
4442     (unless thread
4443       (error "Article in no thread"))
4444     ;; Update the thread.
4445     (setcar thread header)
4446     (gnus-summary-goto-subject article)
4447     (let* ((datal (gnus-data-find-list article))
4448            (data (car datal))
4449            (buffer-read-only nil)
4450            (level (gnus-summary-thread-level)))
4451       (gnus-delete-line)
4452       (let ((inserted (- (point)
4453                          (progn
4454                            (gnus-summary-insert-line
4455                             header level nil
4456                             (memq article gnus-newsgroup-undownloaded)
4457                             (gnus-article-mark article)
4458                             (memq article gnus-newsgroup-replied)
4459                             (memq article gnus-newsgroup-expirable)
4460                             ;; Only insert the Subject string when it's different
4461                             ;; from the previous Subject string.
4462                             (if (and
4463                                  gnus-show-threads
4464                                  (gnus-subject-equal
4465                                   (condition-case ()
4466                                       (mail-header-subject
4467                                        (gnus-data-header
4468                                         (cadr
4469                                          (gnus-data-find-list
4470                                           article
4471                                           (gnus-data-list t)))))
4472                                     ;; Error on the side of excessive subjects.
4473                                     (error ""))
4474                                   (mail-header-subject header)))
4475                                 ""
4476                               (mail-header-subject header))
4477                             nil (cdr (assq article gnus-newsgroup-scored))
4478                             (memq article gnus-newsgroup-processable))
4479                            (point)))))
4480         (when (cdr datal)
4481           (gnus-data-update-list
4482            (cdr datal)
4483            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4484
4485 (defun gnus-summary-update-article (article &optional iheader)
4486   "Update ARTICLE in the summary buffer."
4487   (set-buffer gnus-summary-buffer)
4488   (let* ((header (gnus-summary-article-header article))
4489          (id (mail-header-id header))
4490          (data (gnus-data-find article))
4491          (thread (gnus-id-to-thread id))
4492          (references (mail-header-references header))
4493          (parent
4494           (gnus-id-to-thread
4495            (or (gnus-parent-id
4496                 (when (and references
4497                            (not (equal "" references)))
4498                   references))
4499                "none")))
4500          (buffer-read-only nil)
4501          (old (car thread)))
4502     (when thread
4503       (unless iheader
4504         (setcar thread nil)
4505         (when parent
4506           (delq thread parent)))
4507       (if (gnus-summary-insert-subject id header)
4508           ;; Set the (possibly) new article number in the data structure.
4509           (gnus-data-set-number data (gnus-id-to-article id))
4510         (setcar thread old)
4511         nil))))
4512
4513 (defun gnus-rebuild-thread (id &optional line)
4514   "Rebuild the thread containing ID.
4515 If LINE, insert the rebuilt thread starting on line LINE."
4516   (let ((buffer-read-only nil)
4517         old-pos current thread data)
4518     (if (not gnus-show-threads)
4519         (setq thread (list (car (gnus-id-to-thread id))))
4520       ;; Get the thread this article is part of.
4521       (setq thread (gnus-remove-thread id)))
4522     (setq old-pos (point-at-bol))
4523     (setq current (save-excursion
4524                     (and (re-search-backward "[\r\n]" nil t)
4525                          (gnus-summary-article-number))))
4526     ;; If this is a gathered thread, we have to go some re-gathering.
4527     (when (stringp (car thread))
4528       (let ((subject (car thread))
4529             roots thr)
4530         (setq thread (cdr thread))
4531         (while thread
4532           (unless (memq (setq thr (gnus-id-to-thread
4533                                    (gnus-root-id
4534                                     (mail-header-id (caar thread)))))
4535                         roots)
4536             (push thr roots))
4537           (setq thread (cdr thread)))
4538         ;; We now have all (unique) roots.
4539         (if (= (length roots) 1)
4540             ;; All the loose roots are now one solid root.
4541             (setq thread (car roots))
4542           (setq thread (cons subject (gnus-sort-threads roots))))))
4543     (let (threads)
4544       ;; We then insert this thread into the summary buffer.
4545       (when line
4546         (goto-char (point-min))
4547         (forward-line (1- line)))
4548       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4549         (if gnus-show-threads
4550             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4551           (gnus-summary-prepare-unthreaded thread))
4552         (setq data (nreverse gnus-newsgroup-data))
4553         (setq threads gnus-newsgroup-threads))
4554       ;; We splice the new data into the data structure.
4555       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4556       ;;!!! then we want to insert at the beginning of the buffer.
4557       ;;!!! That happens to be true with Gnus now, but that may
4558       ;;!!! change in the future.  Perhaps.
4559       (gnus-data-enter-list
4560        (if line nil current) data (- (point) old-pos))
4561       (setq gnus-newsgroup-threads
4562             (nconc threads gnus-newsgroup-threads))
4563       (gnus-data-compute-positions))))
4564
4565 (defun gnus-number-to-header (number)
4566   "Return the header for article NUMBER."
4567   (let ((headers gnus-newsgroup-headers))
4568     (while (and headers
4569                 (not (= number (mail-header-number (car headers)))))
4570       (pop headers))
4571     (when headers
4572       (car headers))))
4573
4574 (defun gnus-parent-headers (in-headers &optional generation)
4575   "Return the headers of the GENERATIONeth parent of HEADERS."
4576   (unless generation
4577     (setq generation 1))
4578   (let ((parent t)
4579         (headers in-headers)
4580         references)
4581     (while (and parent
4582                 (not (zerop generation))
4583                 (setq references (mail-header-references headers)))
4584       (setq headers (if (and references
4585                              (setq parent (gnus-parent-id references)))
4586                         (car (gnus-id-to-thread parent))
4587                       nil))
4588       (decf generation))
4589     (and (not (eq headers in-headers))
4590          headers)))
4591
4592 (defun gnus-id-to-thread (id)
4593   "Return the (sub-)thread where ID appears."
4594   (gnus-gethash id gnus-newsgroup-dependencies))
4595
4596 (defun gnus-id-to-article (id)
4597   "Return the article number of ID."
4598   (let ((thread (gnus-id-to-thread id)))
4599     (when (and thread
4600                (car thread))
4601       (mail-header-number (car thread)))))
4602
4603 (defun gnus-id-to-header (id)
4604   "Return the article headers of ID."
4605   (car (gnus-id-to-thread id)))
4606
4607 (defun gnus-article-displayed-root-p (article)
4608   "Say whether ARTICLE is a root(ish) article."
4609   (let ((level (gnus-summary-thread-level article))
4610         (refs (mail-header-references  (gnus-summary-article-header article)))
4611         particle)
4612     (cond
4613      ((null level) nil)
4614      ((zerop level) t)
4615      ((null refs) t)
4616      ((null (gnus-parent-id refs)) t)
4617      ((and (= 1 level)
4618            (null (setq particle (gnus-id-to-article
4619                                  (gnus-parent-id refs))))
4620            (null (gnus-summary-thread-level particle)))))))
4621
4622 (defun gnus-root-id (id)
4623   "Return the id of the root of the thread where ID appears."
4624   (let (last-id prev)
4625     (while (and id (setq prev (car (gnus-id-to-thread id))))
4626       (setq last-id id
4627             id (gnus-parent-id (mail-header-references prev))))
4628     last-id))
4629
4630 (defun gnus-articles-in-thread (thread)
4631   "Return the list of articles in THREAD."
4632   (cons (mail-header-number (car thread))
4633         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4634
4635 (defun gnus-remove-thread (id &optional dont-remove)
4636   "Remove the thread that has ID in it."
4637   (let (headers thread last-id)
4638     ;; First go up in this thread until we find the root.
4639     (setq last-id (gnus-root-id id)
4640           headers (message-flatten-list (gnus-id-to-thread last-id)))
4641     ;; We have now found the real root of this thread.  It might have
4642     ;; been gathered into some loose thread, so we have to search
4643     ;; through the threads to find the thread we wanted.
4644     (let ((threads gnus-newsgroup-threads)
4645           sub)
4646       (while threads
4647         (setq sub (car threads))
4648         (if (stringp (car sub))
4649             ;; This is a gathered thread, so we look at the roots
4650             ;; below it to find whether this article is in this
4651             ;; gathered root.
4652             (progn
4653               (setq sub (cdr sub))
4654               (while sub
4655                 (when (member (caar sub) headers)
4656                   (setq thread (car threads)
4657                         threads nil
4658                         sub nil))
4659                 (setq sub (cdr sub))))
4660           ;; It's an ordinary thread, so we check it.
4661           (when (eq (car sub) (car headers))
4662             (setq thread sub
4663                   threads nil)))
4664         (setq threads (cdr threads)))
4665       ;; If this article is in no thread, then it's a root.
4666       (if thread
4667           (unless dont-remove
4668             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4669         (setq thread (gnus-id-to-thread last-id)))
4670       (when thread
4671         (prog1
4672             thread                      ; We return this thread.
4673           (unless dont-remove
4674             (if (stringp (car thread))
4675                 (progn
4676                   ;; If we use dummy roots, then we have to remove the
4677                   ;; dummy root as well.
4678                   (when (eq gnus-summary-make-false-root 'dummy)
4679                     ;; We go to the dummy root by going to
4680                     ;; the first sub-"thread", and then one line up.
4681                     (gnus-summary-goto-article
4682                      (mail-header-number (caadr thread)))
4683                     (forward-line -1)
4684                     (gnus-delete-line)
4685                     (gnus-data-compute-positions))
4686                   (setq thread (cdr thread))
4687                   (while thread
4688                     (gnus-remove-thread-1 (car thread))
4689                     (setq thread (cdr thread))))
4690               (gnus-remove-thread-1 thread))))))))
4691
4692 (defun gnus-remove-thread-1 (thread)
4693   "Remove the thread THREAD recursively."
4694   (let ((number (mail-header-number (pop thread)))
4695         d)
4696     (setq thread (reverse thread))
4697     (while thread
4698       (gnus-remove-thread-1 (pop thread)))
4699     (when (setq d (gnus-data-find number))
4700       (goto-char (gnus-data-pos d))
4701       (gnus-summary-show-thread)
4702       (gnus-data-remove
4703        number
4704        (- (point-at-bol)
4705           (prog1
4706               (1+ (point-at-eol))
4707             (gnus-delete-line)))))))
4708
4709 (defun gnus-sort-threads-recursive (threads func)
4710   (sort (mapcar (lambda (thread)
4711                   (cons (car thread)
4712                         (and (cdr thread)
4713                              (gnus-sort-threads-recursive (cdr thread) func))))
4714                 threads) func))
4715
4716 (defun gnus-sort-threads-loop (threads func)
4717   (let* ((superthread (cons nil threads))
4718          (stack (list (cons superthread threads)))
4719          remaining-threads thread)
4720     (while stack
4721       (setq remaining-threads (cdr (car stack)))
4722       (if remaining-threads
4723           (progn (setq thread (car remaining-threads))
4724                  (setcdr (car stack) (cdr remaining-threads))
4725                  (if (cdr thread)
4726                      (push (cons thread (cdr thread)) stack)))
4727         (setq thread (caar stack))
4728         (setcdr thread (sort (cdr thread) func))
4729         (pop stack)))
4730     (cdr superthread)))
4731
4732 (defun gnus-sort-threads (threads)
4733   "Sort THREADS."
4734   (if (not gnus-thread-sort-functions)
4735       threads
4736     (gnus-message 8 "Sorting threads...")
4737     (prog1
4738         (condition-case nil
4739             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4740               (gnus-sort-threads-recursive
4741                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4742           ;; Even after binding max-lisp-eval-depth, the recursive
4743           ;; sorter might fail for very long threads.  In that case,
4744           ;; try using a (less well-tested) non-recursive sorter.
4745           (error (gnus-sort-threads-loop
4746                   threads (gnus-make-sort-function
4747                            gnus-thread-sort-functions))))
4748       (gnus-message 8 "Sorting threads...done"))))
4749
4750 (defun gnus-sort-articles (articles)
4751   "Sort ARTICLES."
4752   (when gnus-article-sort-functions
4753     (gnus-message 7 "Sorting articles...")
4754     (prog1
4755         (setq gnus-newsgroup-headers
4756               (sort articles (gnus-make-sort-function
4757                               gnus-article-sort-functions)))
4758       (gnus-message 7 "Sorting articles...done"))))
4759
4760 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4761 (defmacro gnus-thread-header (thread)
4762   "Return header of first article in THREAD.
4763 Note that THREAD must never, ever be anything else than a variable -
4764 using some other form will lead to serious barfage."
4765   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4766   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4767   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4768         (vector thread) 2))
4769
4770 (defsubst gnus-article-sort-by-number (h1 h2)
4771   "Sort articles by article number."
4772   (< (mail-header-number h1)
4773      (mail-header-number h2)))
4774
4775 (defun gnus-thread-sort-by-number (h1 h2)
4776   "Sort threads by root article number."
4777   (gnus-article-sort-by-number
4778    (gnus-thread-header h1) (gnus-thread-header h2)))
4779
4780 (defsubst gnus-article-sort-by-random (h1 h2)
4781   "Sort articles by article number."
4782   (zerop (random 2)))
4783
4784 (defun gnus-thread-sort-by-random (h1 h2)
4785   "Sort threads by root article number."
4786   (gnus-article-sort-by-random
4787    (gnus-thread-header h1) (gnus-thread-header h2)))
4788
4789 (defsubst gnus-article-sort-by-lines (h1 h2)
4790   "Sort articles by article Lines header."
4791   (< (mail-header-lines h1)
4792      (mail-header-lines h2)))
4793
4794 (defun gnus-thread-sort-by-lines (h1 h2)
4795   "Sort threads by root article Lines header."
4796   (gnus-article-sort-by-lines
4797    (gnus-thread-header h1) (gnus-thread-header h2)))
4798
4799 (defsubst gnus-article-sort-by-chars (h1 h2)
4800   "Sort articles by octet length."
4801   (< (mail-header-chars h1)
4802      (mail-header-chars h2)))
4803
4804 (defun gnus-thread-sort-by-chars (h1 h2)
4805   "Sort threads by root article octet length."
4806   (gnus-article-sort-by-chars
4807    (gnus-thread-header h1) (gnus-thread-header h2)))
4808
4809 (defsubst gnus-article-sort-by-author (h1 h2)
4810   "Sort articles by root author."
4811   (string-lessp
4812    (let ((extract (funcall
4813                    gnus-extract-address-components
4814                    (mail-header-from h1))))
4815      (or (car extract) (cadr extract) ""))
4816    (let ((extract (funcall
4817                    gnus-extract-address-components
4818                    (mail-header-from h2))))
4819      (or (car extract) (cadr extract) ""))))
4820
4821 (defun gnus-thread-sort-by-author (h1 h2)
4822   "Sort threads by root author."
4823   (gnus-article-sort-by-author
4824    (gnus-thread-header h1)  (gnus-thread-header h2)))
4825
4826 (defsubst gnus-article-sort-by-recipient (h1 h2)
4827   "Sort articles by recipient."
4828   (string-lessp
4829    (let ((extract (funcall
4830                    gnus-extract-address-components
4831                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4832      (or (car extract) (cadr extract)))
4833    (let ((extract (funcall
4834                    gnus-extract-address-components
4835                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4836      (or (car extract) (cadr extract)))))
4837
4838 (defun gnus-thread-sort-by-recipient (h1 h2)
4839   "Sort threads by root recipient."
4840   (gnus-article-sort-by-recipient
4841    (gnus-thread-header h1) (gnus-thread-header h2)))
4842
4843 (defsubst gnus-article-sort-by-subject (h1 h2)
4844   "Sort articles by root subject."
4845   (string-lessp
4846    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4847    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4848
4849 (defun gnus-thread-sort-by-subject (h1 h2)
4850   "Sort threads by root subject."
4851   (gnus-article-sort-by-subject
4852    (gnus-thread-header h1) (gnus-thread-header h2)))
4853
4854 (defsubst gnus-article-sort-by-date (h1 h2)
4855   "Sort articles by root article date."
4856   (time-less-p
4857    (gnus-date-get-time (mail-header-date h1))
4858    (gnus-date-get-time (mail-header-date h2))))
4859
4860 (defun gnus-thread-sort-by-date (h1 h2)
4861   "Sort threads by root article date."
4862   (gnus-article-sort-by-date
4863    (gnus-thread-header h1) (gnus-thread-header h2)))
4864
4865 (defsubst gnus-article-sort-by-score (h1 h2)
4866   "Sort articles by root article score.
4867 Unscored articles will be counted as having a score of zero."
4868   (> (or (cdr (assq (mail-header-number h1)
4869                     gnus-newsgroup-scored))
4870          gnus-summary-default-score 0)
4871      (or (cdr (assq (mail-header-number h2)
4872                     gnus-newsgroup-scored))
4873          gnus-summary-default-score 0)))
4874
4875 (defun gnus-thread-sort-by-score (h1 h2)
4876   "Sort threads by root article score."
4877   (gnus-article-sort-by-score
4878    (gnus-thread-header h1) (gnus-thread-header h2)))
4879
4880 (defun gnus-thread-sort-by-total-score (h1 h2)
4881   "Sort threads by the sum of all scores in the thread.
4882 Unscored articles will be counted as having a score of zero."
4883   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4884
4885 (defun gnus-thread-total-score (thread)
4886   ;; This function find the total score of THREAD.
4887   (cond
4888    ((null thread)
4889     0)
4890    ((consp thread)
4891     (if (stringp (car thread))
4892         (apply gnus-thread-score-function 0
4893                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4894       (gnus-thread-total-score-1 thread)))
4895    (t
4896     (gnus-thread-total-score-1 (list thread)))))
4897
4898 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4899   "Sort threads such that the thread with the most recently arrived article comes first."
4900   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4901
4902 (defun gnus-thread-highest-number (thread)
4903   "Return the highest article number in THREAD."
4904   (apply 'max (mapcar (lambda (header)
4905                         (mail-header-number header))
4906                       (message-flatten-list thread))))
4907
4908 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4909   "Sort threads such that the thread with the most recently dated article comes first."
4910   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4911
4912 (defun gnus-thread-latest-date (thread)
4913   "Return the highest article date in THREAD."
4914   (let ((previous-time 0))
4915     (apply 'max
4916            (mapcar
4917             (lambda (header)
4918               (setq previous-time
4919                     (condition-case ()
4920                         (time-to-seconds (mail-header-parse-date
4921                                           (mail-header-date header)))
4922                       (error previous-time))))
4923             (sort
4924              (message-flatten-list thread)
4925              (lambda (h1 h2)
4926                (< (mail-header-number h1)
4927                   (mail-header-number h2))))))))
4928
4929 (defun gnus-thread-total-score-1 (root)
4930   ;; This function find the total score of the thread below ROOT.
4931   (setq root (car root))
4932   (apply gnus-thread-score-function
4933          (or (append
4934               (mapcar 'gnus-thread-total-score
4935                       (cdr (gnus-id-to-thread (mail-header-id root))))
4936               (when (> (mail-header-number root) 0)
4937                 (list (or (cdr (assq (mail-header-number root)
4938                                      gnus-newsgroup-scored))
4939                           gnus-summary-default-score 0))))
4940              (list gnus-summary-default-score)
4941              '(0))))
4942
4943 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4944 (defvar gnus-tmp-prev-subject nil)
4945 (defvar gnus-tmp-false-parent nil)
4946 (defvar gnus-tmp-root-expunged nil)
4947 (defvar gnus-tmp-dummy-line nil)
4948
4949 (eval-when-compile (defvar gnus-tmp-header))
4950 (defun gnus-extra-header (type &optional header)
4951   "Return the extra header of TYPE."
4952   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4953       ""))
4954
4955 (defvar gnus-tmp-thread-tree-header-string "")
4956
4957 (defcustom gnus-sum-thread-tree-root "> "
4958   "With %B spec, used for the root of a thread.
4959 If nil, use subject instead."
4960   :version "22.1"
4961   :type '(radio (const :format "%v  " nil) string)
4962   :group 'gnus-thread)
4963
4964 (defcustom gnus-sum-thread-tree-false-root "> "
4965   "With %B spec, used for a false root of a thread.
4966 If nil, use subject instead."
4967   :version "22.1"
4968   :type '(radio (const :format "%v  " nil) string)
4969   :group 'gnus-thread)
4970
4971 (defcustom gnus-sum-thread-tree-single-indent ""
4972   "With %B spec, used for a thread with just one message.
4973 If nil, use subject instead."
4974   :version "22.1"
4975   :type '(radio (const :format "%v  " nil) string)
4976   :group 'gnus-thread)
4977
4978 (defcustom gnus-sum-thread-tree-vertical "| "
4979   "With %B spec, used for drawing a vertical line."
4980   :version "22.1"
4981   :type 'string
4982   :group 'gnus-thread)
4983
4984 (defcustom gnus-sum-thread-tree-indent "  "
4985   "With %B spec, used for indenting."
4986   :version "22.1"
4987   :type 'string
4988   :group 'gnus-thread)
4989
4990 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4991   "With %B spec, used for a leaf with brothers."
4992   :version "22.1"
4993   :type 'string
4994   :group 'gnus-thread)
4995
4996 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4997   "With %B spec, used for a leaf without brothers."
4998   :version "22.1"
4999   :type 'string
5000   :group 'gnus-thread)
5001
5002 (defun gnus-summary-prepare-threads (threads)
5003   "Prepare summary buffer from THREADS and indentation LEVEL.
5004 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5005 or a straight list of headers."
5006   (gnus-message 7 "Generating summary...")
5007
5008   (setq gnus-newsgroup-threads threads)
5009   (beginning-of-line)
5010
5011   (let ((gnus-tmp-level 0)
5012         (default-score (or gnus-summary-default-score 0))
5013         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5014         (building-line-count gnus-summary-display-while-building)
5015         (building-count (integerp gnus-summary-display-while-building))
5016         thread number subject stack state gnus-tmp-gathered beg-match
5017         new-roots gnus-tmp-new-adopts thread-end simp-subject
5018         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5019         gnus-tmp-replied gnus-tmp-subject-or-nil
5020         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5021         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5022         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5023         tree-stack)
5024
5025     (setq gnus-tmp-prev-subject nil
5026           gnus-tmp-thread-tree-header-string "")
5027
5028     (if (vectorp (car threads))
5029         ;; If this is a straight (sic) list of headers, then a
5030         ;; threaded summary display isn't required, so we just create
5031         ;; an unthreaded one.
5032         (gnus-summary-prepare-unthreaded threads)
5033
5034       ;; Do the threaded display.
5035
5036       (if gnus-summary-display-while-building
5037           (switch-to-buffer (buffer-name)))
5038       (while (or threads stack gnus-tmp-new-adopts new-roots)
5039
5040         (if (and (= gnus-tmp-level 0)
5041                  (or (not stack)
5042                      (= (caar stack) 0))
5043                  (not gnus-tmp-false-parent)
5044                  (or gnus-tmp-new-adopts new-roots))
5045             (if gnus-tmp-new-adopts
5046                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5047                       thread (list (car gnus-tmp-new-adopts))
5048                       gnus-tmp-header (caar thread)
5049                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5050               (when new-roots
5051                 (setq thread (list (car new-roots))
5052                       gnus-tmp-header (caar thread)
5053                       new-roots (cdr new-roots))))
5054
5055           (if threads
5056               ;; If there are some threads, we do them before the
5057               ;; threads on the stack.
5058               (setq thread threads
5059                     gnus-tmp-header (caar thread))
5060             ;; There were no current threads, so we pop something off
5061             ;; the stack.
5062             (setq state (car stack)
5063                   gnus-tmp-level (car state)
5064                   tree-stack (cadr state)
5065                   thread (caddr state)
5066                   stack (cdr stack)
5067                   gnus-tmp-header (caar thread))))
5068
5069         (setq gnus-tmp-false-parent nil)
5070         (setq gnus-tmp-root-expunged nil)
5071         (setq thread-end nil)
5072
5073         (if (stringp gnus-tmp-header)
5074             ;; The header is a dummy root.
5075             (cond
5076              ((eq gnus-summary-make-false-root 'adopt)
5077               ;; We let the first article adopt the rest.
5078               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5079                                                (cddar thread)))
5080               (setq gnus-tmp-gathered
5081                     (nconc (mapcar
5082                             (lambda (h) (mail-header-number (car h)))
5083                             (cddar thread))
5084                            gnus-tmp-gathered))
5085               (setq thread (cons (list (caar thread)
5086                                        (cadar thread))
5087                                  (cdr thread)))
5088               (setq gnus-tmp-level -1
5089                     gnus-tmp-false-parent t))
5090              ((eq gnus-summary-make-false-root 'empty)
5091               ;; We print adopted articles with empty subject fields.
5092               (setq gnus-tmp-gathered
5093                     (nconc (mapcar
5094                             (lambda (h) (mail-header-number (car h)))
5095                             (cddar thread))
5096                            gnus-tmp-gathered))
5097               (setq gnus-tmp-level -1))
5098              ((eq gnus-summary-make-false-root 'dummy)
5099               ;; We remember that we probably want to output a dummy
5100               ;; root.
5101               (setq gnus-tmp-dummy-line gnus-tmp-header)
5102               (setq gnus-tmp-prev-subject gnus-tmp-header))
5103              (t
5104               ;; We do not make a root for the gathered
5105               ;; sub-threads at all.
5106               (setq gnus-tmp-level -1)))
5107
5108           (setq number (mail-header-number gnus-tmp-header)
5109                 subject (mail-header-subject gnus-tmp-header)
5110                 simp-subject (gnus-simplify-subject-fully subject))
5111
5112           (cond
5113            ;; If the thread has changed subject, we might want to make
5114            ;; this subthread into a root.
5115            ((and (null gnus-thread-ignore-subject)
5116                  (not (zerop gnus-tmp-level))
5117                  gnus-tmp-prev-subject
5118                  (not (string= gnus-tmp-prev-subject simp-subject)))
5119             (setq new-roots (nconc new-roots (list (car thread)))
5120                   thread-end t
5121                   gnus-tmp-header nil))
5122            ;; If the article lies outside the current limit,
5123            ;; then we do not display it.
5124            ((not (memq number gnus-newsgroup-limit))
5125             (setq gnus-tmp-gathered
5126                   (nconc (mapcar
5127                           (lambda (h) (mail-header-number (car h)))
5128                           (cdar thread))
5129                          gnus-tmp-gathered))
5130             (setq gnus-tmp-new-adopts (if (cdar thread)
5131                                           (append gnus-tmp-new-adopts
5132                                                   (cdar thread))
5133                                         gnus-tmp-new-adopts)
5134                   thread-end t
5135                   gnus-tmp-header nil)
5136             (when (zerop gnus-tmp-level)
5137               (setq gnus-tmp-root-expunged t)))
5138            ;; Perhaps this article is to be marked as read?
5139            ((and gnus-summary-mark-below
5140                  (< (or (cdr (assq number gnus-newsgroup-scored))
5141                         default-score)
5142                     gnus-summary-mark-below)
5143                  ;; Don't touch sparse articles.
5144                  (not (gnus-summary-article-sparse-p number))
5145                  (not (gnus-summary-article-ancient-p number)))
5146             (setq gnus-newsgroup-unreads
5147                   (delq number gnus-newsgroup-unreads))
5148             (if gnus-newsgroup-auto-expire
5149                 (setq gnus-newsgroup-expirable
5150                       (gnus-add-to-sorted-list
5151                        gnus-newsgroup-expirable number))
5152               (push (cons number gnus-low-score-mark)
5153                     gnus-newsgroup-reads))))
5154
5155           (when gnus-tmp-header
5156             ;; We may have an old dummy line to output before this
5157             ;; article.
5158             (when (and gnus-tmp-dummy-line
5159                        (gnus-subject-equal
5160                         gnus-tmp-dummy-line
5161                         (mail-header-subject gnus-tmp-header)))
5162               (gnus-summary-insert-dummy-line
5163                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5164               (setq gnus-tmp-dummy-line nil))
5165
5166             ;; Compute the mark.
5167             (setq gnus-tmp-unread (gnus-article-mark number))
5168
5169             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5170                                   gnus-tmp-header gnus-tmp-level)
5171                   gnus-newsgroup-data)
5172
5173             ;; Actually insert the line.
5174             (setq
5175              gnus-tmp-subject-or-nil
5176              (cond
5177               ((and gnus-thread-ignore-subject
5178                     gnus-tmp-prev-subject
5179                     (not (string= gnus-tmp-prev-subject simp-subject)))
5180                subject)
5181               ((zerop gnus-tmp-level)
5182                (if (and (eq gnus-summary-make-false-root 'empty)
5183                         (memq number gnus-tmp-gathered)
5184                         gnus-tmp-prev-subject
5185                         (string= gnus-tmp-prev-subject simp-subject))
5186                    gnus-summary-same-subject
5187                  subject))
5188               (t gnus-summary-same-subject)))
5189             (if (and (eq gnus-summary-make-false-root 'adopt)
5190                      (= gnus-tmp-level 1)
5191                      (memq number gnus-tmp-gathered))
5192                 (setq gnus-tmp-opening-bracket ?\<
5193                       gnus-tmp-closing-bracket ?\>)
5194               (setq gnus-tmp-opening-bracket ?\[
5195                     gnus-tmp-closing-bracket ?\]))
5196             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5197                 (gnus-make-thread-indent-array
5198                  (max (* 2 (length gnus-thread-indent-array))
5199                       gnus-tmp-level)))
5200             (setq
5201              gnus-tmp-indentation
5202              (aref gnus-thread-indent-array gnus-tmp-level)
5203              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5204              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5205                                 gnus-summary-default-score 0)
5206              gnus-tmp-score-char
5207              (if (or (null gnus-summary-default-score)
5208                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5209                          gnus-summary-zcore-fuzz))
5210                  ?                      ;Whitespace
5211                (if (< gnus-tmp-score gnus-summary-default-score)
5212                    gnus-score-below-mark gnus-score-over-mark))
5213              gnus-tmp-replied
5214              (cond ((memq number gnus-newsgroup-processable)
5215                     gnus-process-mark)
5216                    ((memq number gnus-newsgroup-cached)
5217                     gnus-cached-mark)
5218                    ((memq number gnus-newsgroup-replied)
5219                     gnus-replied-mark)
5220                    ((memq number gnus-newsgroup-forwarded)
5221                     gnus-forwarded-mark)
5222                    ((memq number gnus-newsgroup-saved)
5223                     gnus-saved-mark)
5224                    ((memq number gnus-newsgroup-recent)
5225                     gnus-recent-mark)
5226                    ((memq number gnus-newsgroup-unseen)
5227                     gnus-unseen-mark)
5228                    (t gnus-no-mark))
5229              gnus-tmp-downloaded
5230              (cond ((memq number gnus-newsgroup-undownloaded)
5231                     gnus-undownloaded-mark)
5232                    (gnus-newsgroup-agentized
5233                     gnus-downloaded-mark)
5234                    (t
5235                     gnus-no-mark))
5236              gnus-tmp-from (mail-header-from gnus-tmp-header)
5237              gnus-tmp-name
5238              (cond
5239               ((string-match "<[^>]+> *$" gnus-tmp-from)
5240                (setq beg-match (match-beginning 0))
5241                (or (and (string-match "^\".+\"" gnus-tmp-from)
5242                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5243                    (substring gnus-tmp-from 0 beg-match)))
5244               ((string-match "(.+)" gnus-tmp-from)
5245                (substring gnus-tmp-from
5246                           (1+ (match-beginning 0)) (1- (match-end 0))))
5247               (t gnus-tmp-from))
5248
5249              ;; Do the %B string
5250              gnus-tmp-thread-tree-header-string
5251              (cond
5252               ((not gnus-show-threads) "")
5253               ((zerop gnus-tmp-level)
5254                (cond ((cdar thread)
5255                       (or gnus-sum-thread-tree-root subject))
5256                      (gnus-tmp-new-adopts
5257                       (or gnus-sum-thread-tree-false-root subject))
5258                      (t
5259                       (or gnus-sum-thread-tree-single-indent subject))))
5260               (t
5261                (concat (apply 'concat
5262                               (mapcar (lambda (item)
5263                                         (if (= item 1)
5264                                             gnus-sum-thread-tree-vertical
5265                                           gnus-sum-thread-tree-indent))
5266                                       (cdr (reverse tree-stack))))
5267                        (if (nth 1 thread)
5268                            gnus-sum-thread-tree-leaf-with-other
5269                          gnus-sum-thread-tree-single-leaf)))))
5270             (when (string= gnus-tmp-name "")
5271               (setq gnus-tmp-name gnus-tmp-from))
5272             (unless (numberp gnus-tmp-lines)
5273               (setq gnus-tmp-lines -1))
5274             (if (= gnus-tmp-lines -1)
5275                 (setq gnus-tmp-lines "?")
5276               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5277               (gnus-put-text-property
5278              (point)
5279              (progn (eval gnus-summary-line-format-spec) (point))
5280                'gnus-number number)
5281             (when gnus-visual-p
5282               (forward-line -1)
5283               (gnus-run-hooks 'gnus-summary-update-hook)
5284               (forward-line 1))
5285
5286             (setq gnus-tmp-prev-subject simp-subject)))
5287
5288         (when (nth 1 thread)
5289           (push (list (max 0 gnus-tmp-level)
5290                       (copy-sequence tree-stack)
5291                       (nthcdr 1 thread))
5292                 stack))
5293         (push (if (nth 1 thread) 1 0) tree-stack)
5294         (incf gnus-tmp-level)
5295         (setq threads (if thread-end nil (cdar thread)))
5296         (if gnus-summary-display-while-building
5297             (if building-count
5298                 (progn
5299                   ;; use a set frequency
5300                   (setq building-line-count (1- building-line-count))
5301                   (when (= building-line-count 0)
5302                     (sit-for 0)
5303                     (setq building-line-count
5304                           gnus-summary-display-while-building)))
5305               ;; always
5306               (sit-for 0)))
5307         (unless threads
5308           (setq gnus-tmp-level 0)))))
5309   (gnus-message 7 "Generating summary...done"))
5310
5311 (defun gnus-summary-prepare-unthreaded (headers)
5312   "Generate an unthreaded summary buffer based on HEADERS."
5313   (let (header number mark)
5314
5315     (beginning-of-line)
5316
5317     (while headers
5318       ;; We may have to root out some bad articles...
5319       (when (memq (setq number (mail-header-number
5320                                 (setq header (pop headers))))
5321                   gnus-newsgroup-limit)
5322         ;; Mark article as read when it has a low score.
5323         (when (and gnus-summary-mark-below
5324                    (< (or (cdr (assq number gnus-newsgroup-scored))
5325                           gnus-summary-default-score 0)
5326                       gnus-summary-mark-below)
5327                    (not (gnus-summary-article-ancient-p number)))
5328           (setq gnus-newsgroup-unreads
5329                 (delq number gnus-newsgroup-unreads))
5330           (if gnus-newsgroup-auto-expire
5331               (push number gnus-newsgroup-expirable)
5332             (push (cons number gnus-low-score-mark)
5333                   gnus-newsgroup-reads)))
5334
5335         (setq mark (gnus-article-mark number))
5336         (push (gnus-data-make number mark (1+ (point)) header 0)
5337               gnus-newsgroup-data)
5338         (gnus-summary-insert-line
5339          header 0 number
5340          (memq number gnus-newsgroup-undownloaded)
5341          mark (memq number gnus-newsgroup-replied)
5342          (memq number gnus-newsgroup-expirable)
5343          (mail-header-subject header) nil
5344          (cdr (assq number gnus-newsgroup-scored))
5345          (memq number gnus-newsgroup-processable))))))
5346
5347 (defun gnus-summary-remove-list-identifiers ()
5348   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5349   (let ((regexp (if (consp gnus-list-identifiers)
5350                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5351                   gnus-list-identifiers))
5352         changed subject)
5353     (when regexp
5354       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5355       (dolist (header gnus-newsgroup-headers)
5356         (setq subject (mail-header-subject header)
5357               changed nil)
5358         (while (string-match regexp subject)
5359           (setq subject
5360                 (concat (substring subject 0 (match-beginning 1))
5361                         (substring subject (match-end 0)))
5362                 changed t))
5363         (when changed
5364           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5365             (setq subject
5366                   (concat (substring subject 0 (match-beginning 1))
5367                           (substring subject (match-end 1)))))
5368           (mail-header-set-subject header subject))))))
5369
5370 (defun gnus-fetch-headers (articles)
5371   "Fetch headers of ARTICLES."
5372   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5373     (gnus-message 5 "Fetching headers for %s..." name)
5374     (prog1
5375         (if (eq 'nov
5376                 (setq gnus-headers-retrieved-by
5377                       (gnus-retrieve-headers
5378                        articles gnus-newsgroup-name
5379                        ;; We might want to fetch old headers, but
5380                        ;; not if there is only 1 article.
5381                        (and (or (and
5382                                  (not (eq gnus-fetch-old-headers 'some))
5383                                  (not (numberp gnus-fetch-old-headers)))
5384                                 (> (length articles) 1))
5385                             gnus-fetch-old-headers))))
5386             (gnus-get-newsgroup-headers-xover
5387              articles nil nil gnus-newsgroup-name t)
5388           (gnus-get-newsgroup-headers))
5389       (gnus-message 5 "Fetching headers for %s...done" name))))
5390
5391 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5392   "Select newsgroup GROUP.
5393 If READ-ALL is non-nil, all articles in the group are selected.
5394 If SELECT-ARTICLES, only select those articles from GROUP."
5395   (let* ((entry (gnus-group-entry group))
5396          ;;!!! Dirty hack; should be removed.
5397          (gnus-summary-ignore-duplicates
5398           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5399               t
5400             gnus-summary-ignore-duplicates))
5401          (info (nth 2 entry))
5402          charset articles fetched-articles cached)
5403
5404     (unless (gnus-check-server
5405              (set (make-local-variable 'gnus-current-select-method)
5406                   (gnus-find-method-for-group group)))
5407       (error "Couldn't open server"))
5408     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5409
5410     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5411         (gnus-activate-group group)     ; Or we can activate it...
5412         (progn                          ; Or we bug out.
5413           (when (equal major-mode 'gnus-summary-mode)
5414             (gnus-kill-buffer (current-buffer)))
5415           (error
5416            "Couldn't activate group %s: %s"
5417            (mm-decode-coding-string group charset)
5418            (mm-decode-coding-string (gnus-status-message group) charset))))
5419
5420     (unless (gnus-request-group group t)
5421         (when (equal major-mode 'gnus-summary-mode)
5422           (gnus-kill-buffer (current-buffer)))
5423         (error "Couldn't request group %s: %s"
5424                (mm-decode-coding-string group charset)
5425                (mm-decode-coding-string (gnus-status-message group) charset)))
5426
5427     (when gnus-agent
5428       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5429
5430       (setq gnus-summary-use-undownloaded-faces
5431             (gnus-agent-find-parameter
5432              group
5433              'agent-enable-undownloaded-faces)))
5434
5435     (setq gnus-newsgroup-name group
5436           gnus-newsgroup-unselected nil
5437           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5438
5439     (let ((display (gnus-group-find-parameter group 'display)))
5440       (setq gnus-newsgroup-display
5441             (cond
5442              ((not (zerop (or (car-safe read-all) 0)))
5443               ;; The user entered the group with C-u SPC/RET, let's show
5444               ;; all articles.
5445               'gnus-not-ignore)
5446              ((eq display 'all)
5447               'gnus-not-ignore)
5448              ((arrayp display)
5449               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5450              ((numberp display)
5451               ;; The following is probably the "correct" solution, but
5452               ;; it makes Gnus fetch all headers and then limit the
5453               ;; articles (which is slow), so instead we hack the
5454               ;; select-articles parameter instead. -- Simon Josefsson
5455               ;; <jas@kth.se>
5456               ;;
5457               ;; (gnus-byte-compile
5458               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5459               ;;                         display)))))
5460               (setq select-articles
5461                     (gnus-uncompress-range
5462                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5463                              (if (> tmp 0)
5464                                  tmp
5465                                1))
5466                            (cdr (gnus-active group)))))
5467               nil)
5468              (t
5469               nil))))
5470
5471     (gnus-summary-setup-default-charset)
5472
5473     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5474     (when (gnus-virtual-group-p group)
5475       (setq cached gnus-newsgroup-cached))
5476
5477     (setq gnus-newsgroup-unreads
5478           (gnus-sorted-ndifference
5479            (gnus-sorted-ndifference gnus-newsgroup-unreads
5480                                     gnus-newsgroup-marked)
5481            gnus-newsgroup-dormant))
5482
5483     (setq gnus-newsgroup-processable nil)
5484
5485     (gnus-update-read-articles group gnus-newsgroup-unreads)
5486
5487     ;; Adjust and set lists of article marks.
5488     (when info
5489       (gnus-adjust-marked-articles info))
5490     (if (setq articles select-articles)
5491         (setq gnus-newsgroup-unselected
5492               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5493       (setq articles (gnus-articles-to-read group read-all)))
5494
5495     (cond
5496      ((null articles)
5497       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5498       'quit)
5499      ((eq articles 0) nil)
5500      (t
5501       ;; Init the dependencies hash table.
5502       (setq gnus-newsgroup-dependencies
5503             (gnus-make-hashtable (length articles)))
5504       (gnus-set-global-variables)
5505       ;; Retrieve the headers and read them in.
5506
5507       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5508
5509       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5510       (when cached
5511         (setq gnus-newsgroup-cached cached))
5512
5513       ;; Suppress duplicates?
5514       (when gnus-suppress-duplicates
5515         (gnus-dup-suppress-articles))
5516
5517       ;; Set the initial limit.
5518       (setq gnus-newsgroup-limit (copy-sequence articles))
5519       ;; Remove canceled articles from the list of unread articles.
5520       (setq fetched-articles
5521             (mapcar (lambda (headers) (mail-header-number headers))
5522                     gnus-newsgroup-headers))
5523       (setq gnus-newsgroup-articles fetched-articles)
5524       (setq gnus-newsgroup-unreads
5525             (gnus-sorted-nintersection
5526              gnus-newsgroup-unreads fetched-articles))
5527       (gnus-compute-unseen-list)
5528
5529       ;; Removed marked articles that do not exist.
5530       (gnus-update-missing-marks
5531        (gnus-sorted-difference articles fetched-articles))
5532       ;; We might want to build some more threads first.
5533       (when (and gnus-fetch-old-headers
5534                  (eq gnus-headers-retrieved-by 'nov))
5535         (if (eq gnus-fetch-old-headers 'invisible)
5536             (gnus-build-all-threads)
5537           (gnus-build-old-threads)))
5538       ;; Let the Gnus agent mark articles as read.
5539       (when gnus-agent
5540         (gnus-agent-get-undownloaded-list))
5541       ;; Remove list identifiers from subject
5542       (when gnus-list-identifiers
5543         (gnus-summary-remove-list-identifiers))
5544       ;; Check whether auto-expire is to be done in this group.
5545       (setq gnus-newsgroup-auto-expire
5546             (gnus-group-auto-expirable-p group))
5547       ;; Set up the article buffer now, if necessary.
5548       (unless (and gnus-single-article-buffer
5549                    (equal gnus-article-buffer "*Article*"))
5550         (gnus-article-setup-buffer))
5551       ;; First and last article in this newsgroup.
5552       (when gnus-newsgroup-headers
5553         (setq gnus-newsgroup-begin
5554               (mail-header-number (car gnus-newsgroup-headers))
5555               gnus-newsgroup-end
5556               (mail-header-number
5557                (gnus-last-element gnus-newsgroup-headers))))
5558       ;; GROUP is successfully selected.
5559       (or gnus-newsgroup-headers t)))))
5560
5561 (defun gnus-compute-unseen-list ()
5562   ;; The `seen' marks are treated specially.
5563   (if (not gnus-newsgroup-seen)
5564       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5565     (setq gnus-newsgroup-unseen
5566           (gnus-inverse-list-range-intersection
5567            gnus-newsgroup-articles gnus-newsgroup-seen))))
5568
5569 (defun gnus-summary-display-make-predicate (display)
5570   (require 'gnus-agent)
5571   (when (= (length display) 1)
5572     (setq display (car display)))
5573   (unless gnus-summary-display-cache
5574     (dolist (elem (append '((unread . unread)
5575                             (read . read)
5576                             (unseen . unseen))
5577                           gnus-article-mark-lists))
5578       (push (cons (cdr elem)
5579                   (gnus-byte-compile
5580                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5581             gnus-summary-display-cache)))
5582   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5583         (gnus-category-predicate-cache gnus-summary-display-cache))
5584     (gnus-get-predicate display)))
5585
5586 ;; Uses the dynamically bound `number' variable.
5587 (eval-when-compile
5588   (defvar number))
5589 (defun gnus-article-marked-p (type &optional article)
5590   (let ((article (or article number)))
5591     (cond
5592      ((eq type 'tick)
5593       (memq article gnus-newsgroup-marked))
5594      ((eq type 'spam)
5595       (memq article gnus-newsgroup-spam-marked))
5596      ((eq type 'unsend)
5597       (memq article gnus-newsgroup-unsendable))
5598      ((eq type 'undownload)
5599       (memq article gnus-newsgroup-undownloaded))
5600      ((eq type 'download)
5601       (memq article gnus-newsgroup-downloadable))
5602      ((eq type 'unread)
5603       (memq article gnus-newsgroup-unreads))
5604      ((eq type 'read)
5605       (memq article gnus-newsgroup-reads))
5606      ((eq type 'dormant)
5607       (memq article gnus-newsgroup-dormant) )
5608      ((eq type 'expire)
5609       (memq article gnus-newsgroup-expirable))
5610      ((eq type 'reply)
5611       (memq article gnus-newsgroup-replied))
5612      ((eq type 'killed)
5613       (memq article gnus-newsgroup-killed))
5614      ((eq type 'bookmark)
5615       (assq article gnus-newsgroup-bookmarks))
5616      ((eq type 'score)
5617       (assq article gnus-newsgroup-scored))
5618      ((eq type 'save)
5619       (memq article gnus-newsgroup-saved))
5620      ((eq type 'cache)
5621       (memq article gnus-newsgroup-cached))
5622      ((eq type 'forward)
5623       (memq article gnus-newsgroup-forwarded))
5624      ((eq type 'seen)
5625       (not (memq article gnus-newsgroup-unseen)))
5626      ((eq type 'recent)
5627       (memq article gnus-newsgroup-recent))
5628      (t t))))
5629
5630 (defun gnus-articles-to-read (group &optional read-all)
5631   "Find out what articles the user wants to read."
5632   (let* ((articles
5633           ;; Select all articles if `read-all' is non-nil, or if there
5634           ;; are no unread articles.
5635           (if (or read-all
5636                   (and (zerop (length gnus-newsgroup-marked))
5637                        (zerop (length gnus-newsgroup-unreads)))
5638                   ;; Fetch all if the predicate is non-nil.
5639                   gnus-newsgroup-display)
5640               ;; We want to select the headers for all the articles in
5641               ;; the group, so we select either all the active
5642               ;; articles in the group, or (if that's nil), the
5643               ;; articles in the cache.
5644               (or
5645                (gnus-uncompress-range (gnus-active group))
5646                (gnus-cache-articles-in-group group))
5647             ;; Select only the "normal" subset of articles.
5648             (gnus-sorted-nunion
5649              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5650              gnus-newsgroup-unreads)))
5651          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5652          (scored (length scored-list))
5653          (number (length articles))
5654          (marked (+ (length gnus-newsgroup-marked)
5655                     (length gnus-newsgroup-dormant)))
5656          (select
5657           (cond
5658            ((numberp read-all)
5659             read-all)
5660            ((numberp gnus-newsgroup-display)
5661             gnus-newsgroup-display)
5662            (t
5663             (condition-case ()
5664                 (cond
5665                  ((and (or (<= scored marked) (= scored number))
5666                        (numberp gnus-large-newsgroup)
5667                        (> number gnus-large-newsgroup))
5668                   (let* ((cursor-in-echo-area nil)
5669                          (initial (gnus-parameter-large-newsgroup-initial
5670                                    gnus-newsgroup-name))
5671                          (input
5672                           (read-string
5673                            (format
5674                             "How many articles from %s (%s %d): "
5675                             (gnus-group-decoded-name gnus-newsgroup-name)
5676                             (if initial "max" "default")
5677                             number)
5678                            (if initial
5679                                (cons (number-to-string initial)
5680                                      0)))))
5681                     (if (string-match "^[ \t]*$" input) number input)))
5682                  ((and (> scored marked) (< scored number)
5683                        (> (- scored number) 20))
5684                   (let ((input
5685                          (read-string
5686                           (format "%s %s (%d scored, %d total): "
5687                                   "How many articles from"
5688                                   (gnus-group-decoded-name group)
5689                                   scored number))))
5690                     (if (string-match "^[ \t]*$" input)
5691                         number input)))
5692                  (t number))
5693               (quit
5694                (message "Quit getting the articles to read")
5695                nil))))))
5696     (setq select (if (stringp select) (string-to-number select) select))
5697     (if (or (null select) (zerop select))
5698         select
5699       (if (and (not (zerop scored)) (<= (abs select) scored))
5700           (progn
5701             (setq articles (sort scored-list '<))
5702             (setq number (length articles)))
5703         (setq articles (copy-sequence articles)))
5704
5705       (when (< (abs select) number)
5706         (if (< select 0)
5707             ;; Select the N oldest articles.
5708             (setcdr (nthcdr (1- (abs select)) articles) nil)
5709           ;; Select the N most recent articles.
5710           (setq articles (nthcdr (- number select) articles))))
5711       (setq gnus-newsgroup-unselected
5712             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5713       (when gnus-alter-articles-to-read-function
5714         (setq articles
5715               (sort
5716                (funcall gnus-alter-articles-to-read-function
5717                         gnus-newsgroup-name articles)
5718                '<)))
5719       articles)))
5720
5721 (defun gnus-killed-articles (killed articles)
5722   (let (out)
5723     (while articles
5724       (when (inline (gnus-member-of-range (car articles) killed))
5725         (push (car articles) out))
5726       (setq articles (cdr articles)))
5727     out))
5728
5729 (defun gnus-uncompress-marks (marks)
5730   "Uncompress the mark ranges in MARKS."
5731   (let ((uncompressed '(score bookmark))
5732         out)
5733     (while marks
5734       (if (memq (caar marks) uncompressed)
5735           (push (car marks) out)
5736         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5737       (setq marks (cdr marks)))
5738     out))
5739
5740 (defun gnus-article-mark-to-type (mark)
5741   "Return the type of MARK."
5742   (or (cadr (assq mark gnus-article-special-mark-lists))
5743       'list))
5744
5745 (defun gnus-article-unpropagatable-p (mark)
5746   "Return whether MARK should be propagated to back end."
5747   (memq mark gnus-article-unpropagated-mark-lists))
5748
5749 (defun gnus-adjust-marked-articles (info)
5750   "Set all article lists and remove all marks that are no longer valid."
5751   (let* ((marked-lists (gnus-info-marks info))
5752          (active (gnus-active (gnus-info-group info)))
5753          (min (car active))
5754          (max (cdr active))
5755          (types gnus-article-mark-lists)
5756          marks var articles article mark mark-type
5757          bgn end)
5758
5759     (dolist (marks marked-lists)
5760       (setq mark (car marks)
5761             mark-type (gnus-article-mark-to-type mark)
5762             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5763
5764       ;; We set the variable according to the type of the marks list,
5765       ;; and then adjust the marks to a subset of the active articles.
5766       (cond
5767        ;; Adjust "simple" lists - compressed yet unsorted
5768        ((eq mark-type 'list)
5769         ;; Simultaneously uncompress and clip to active range
5770         ;; See gnus-uncompress-range for a description of possible marks
5771         (let (l lh)
5772           (if (not (cadr marks))
5773               (set var nil)
5774             (setq articles (if (numberp (cddr marks))
5775                                (list (cdr marks))
5776                              (cdr marks))
5777                   lh (cons nil nil)
5778                   l lh)
5779
5780             (while (setq article (pop articles))
5781               (cond ((consp article)
5782                      (setq bgn (max (car article) min)
5783                            end (min (cdr article) max))
5784                      (while (<= bgn end)
5785                        (setq l (setcdr l (cons bgn nil))
5786                              bgn (1+ bgn))))
5787                     ((and (<= min article)
5788                           (>= max article))
5789                      (setq l (setcdr l (cons article nil))))))
5790             (set var (cdr lh)))))
5791        ;; Adjust assocs.
5792        ((eq mark-type 'tuple)
5793         (set var (setq articles (cdr marks)))
5794         (when (not (listp (cdr (symbol-value var))))
5795           (set var (list (symbol-value var))))
5796         (when (not (listp (cdr articles)))
5797           (setq articles (list articles)))
5798         (while articles
5799           (when (or (not (consp (setq article (pop articles))))
5800                     (< (car article) min)
5801                     (> (car article) max))
5802             (set var (delq article (symbol-value var))))))
5803        ;; Adjust ranges (sloppily).
5804        ((eq mark-type 'range)
5805         (cond
5806          ((eq mark 'seen)
5807           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5808           ;; It should be (seen (NUM1 . NUM2)).
5809           (when (numberp (cddr marks))
5810             (setcdr marks (list (cdr marks))))
5811           (setq articles (cdr marks))
5812           (while (and articles
5813                       (or (and (consp (car articles))
5814                                (> min (cdar articles)))
5815                           (and (numberp (car articles))
5816                                (> min (car articles)))))
5817             (pop articles))
5818           (set var articles))))))))
5819
5820 (defun gnus-update-missing-marks (missing)
5821   "Go through the list of MISSING articles and remove them from the mark lists."
5822   (when missing
5823     (let (var m)
5824       ;; Go through all types.
5825       (dolist (elem gnus-article-mark-lists)
5826         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5827           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5828           (when (symbol-value var)
5829             ;; This list has articles.  So we delete all missing
5830             ;; articles from it.
5831             (setq m missing)
5832             (while m
5833               (set var (delq (pop m) (symbol-value var))))))))))
5834
5835 (defun gnus-update-marks ()
5836   "Enter the various lists of marked articles into the newsgroup info list."
5837   (let ((types gnus-article-mark-lists)
5838         (info (gnus-get-info gnus-newsgroup-name))
5839         type list newmarked symbol delta-marks)
5840     (when info
5841       ;; Add all marks lists to the list of marks lists.
5842       (while (setq type (pop types))
5843         (setq list (symbol-value
5844                     (setq symbol
5845                           (intern (format "gnus-newsgroup-%s" (car type))))))
5846
5847         (when list
5848           ;; Get rid of the entries of the articles that have the
5849           ;; default score.
5850           (when (and (eq (cdr type) 'score)
5851                      gnus-save-score
5852                      list)
5853             (let* ((arts list)
5854                    (prev (cons nil list))
5855                    (all prev))
5856               (while arts
5857                 (if (or (not (consp (car arts)))
5858                         (= (cdar arts) gnus-summary-default-score))
5859                     (setcdr prev (cdr arts))
5860                   (setq prev arts))
5861                 (setq arts (cdr arts)))
5862               (setq list (cdr all)))))
5863
5864         (when (eq (cdr type) 'seen)
5865           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5866
5867         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5868           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5869
5870         (when (and (gnus-check-backend-function
5871                     'request-set-mark gnus-newsgroup-name)
5872                    (not (gnus-article-unpropagatable-p (cdr type))))
5873           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5874                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5875                  (add (gnus-remove-from-range
5876                        (gnus-copy-sequence list) old)))
5877             (when add
5878               (push (list add 'add (list (cdr type))) delta-marks))
5879             (when del
5880               (push (list del 'del (list (cdr type))) delta-marks))))
5881
5882         (when list
5883           (push (cons (cdr type) list) newmarked)))
5884
5885       (when delta-marks
5886         (unless (gnus-check-group gnus-newsgroup-name)
5887           (error "Can't open server for %s" gnus-newsgroup-name))
5888         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5889
5890       ;; Enter these new marks into the info of the group.
5891       (if (nthcdr 3 info)
5892           (setcar (nthcdr 3 info) newmarked)
5893         ;; Add the marks lists to the end of the info.
5894         (when newmarked
5895           (setcdr (nthcdr 2 info) (list newmarked))))
5896
5897       ;; Cut off the end of the info if there's nothing else there.
5898       (let ((i 5))
5899         (while (and (> i 2)
5900                     (not (nth i info)))
5901           (when (nthcdr (decf i) info)
5902             (setcdr (nthcdr i info) nil)))))))
5903
5904 (defun gnus-set-mode-line (where)
5905   "Set the mode line of the article or summary buffers.
5906 If WHERE is `summary', the summary mode line format will be used."
5907   ;; Is this mode line one we keep updated?
5908   (when (and (memq where gnus-updated-mode-lines)
5909              (symbol-value
5910               (intern (format "gnus-%s-mode-line-format-spec" where))))
5911     (let (mode-string)
5912       (save-excursion
5913         ;; We evaluate this in the summary buffer since these
5914         ;; variables are buffer-local to that buffer.
5915         (set-buffer gnus-summary-buffer)
5916        ;; We bind all these variables that are used in the `eval' form
5917         ;; below.
5918         (let* ((mformat (symbol-value
5919                          (intern
5920                           (format "gnus-%s-mode-line-format-spec" where))))
5921                (gnus-tmp-group-name (gnus-mode-string-quote
5922                                      (gnus-group-decoded-name
5923                                       gnus-newsgroup-name)))
5924                (gnus-tmp-article-number (or gnus-current-article 0))
5925                (gnus-tmp-unread gnus-newsgroup-unreads)
5926                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5927                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5928                (gnus-tmp-unread-and-unselected
5929                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5930                             (zerop gnus-tmp-unselected))
5931                        "")
5932                       ((zerop gnus-tmp-unselected)
5933                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5934                       (t (format "{%d(+%d) more}"
5935                                  gnus-tmp-unread-and-unticked
5936                                  gnus-tmp-unselected))))
5937                (gnus-tmp-subject
5938                 (if (and gnus-current-headers
5939                          (vectorp gnus-current-headers))
5940                     (gnus-mode-string-quote
5941                      (mail-header-subject gnus-current-headers))
5942                   ""))
5943                bufname-length max-len
5944                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5945           (setq mode-string (eval mformat))
5946           (setq bufname-length (if (string-match "%b" mode-string)
5947                                    (- (length
5948                                        (buffer-name
5949                                         (if (eq where 'summary)
5950                                             nil
5951                                           (get-buffer gnus-article-buffer))))
5952                                       2)
5953                                  0))
5954           (setq max-len (max 4 (if gnus-mode-non-string-length
5955                                    (- (window-width)
5956                                       gnus-mode-non-string-length
5957                                       bufname-length)
5958                                  (length mode-string))))
5959           ;; We might have to chop a bit of the string off...
5960           (when (> (length mode-string) max-len)
5961             (setq mode-string
5962                   (concat (truncate-string-to-width mode-string (- max-len 3))
5963                           "...")))
5964           ;; Pad the mode string a bit.
5965           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5966       ;; Update the mode line.
5967       (setq mode-line-buffer-identification
5968             (gnus-mode-line-buffer-identification (list mode-string)))
5969       (set-buffer-modified-p t))))
5970
5971 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5972   "Go through the HEADERS list and add all Xrefs to a hash table.
5973 The resulting hash table is returned, or nil if no Xrefs were found."
5974   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5975          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5976          (xref-hashtb (gnus-make-hashtable))
5977          start group entry number xrefs header)
5978     (while headers
5979       (setq header (pop headers))
5980       (when (and (setq xrefs (mail-header-xref header))
5981                  (not (memq (setq number (mail-header-number header))
5982                             unreads)))
5983         (setq start 0)
5984         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5985           (setq start (match-end 0))
5986           (setq group (if prefix
5987                           (concat prefix (substring xrefs (match-beginning 1)
5988                                                     (match-end 1)))
5989                         (substring xrefs (match-beginning 1) (match-end 1))))
5990           (setq number
5991                 (string-to-number (substring xrefs (match-beginning 2)
5992                                           (match-end 2))))
5993           (if (setq entry (gnus-gethash group xref-hashtb))
5994               (setcdr entry (cons number (cdr entry)))
5995             (gnus-sethash group (cons number nil) xref-hashtb)))))
5996     (and start xref-hashtb)))
5997
5998 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5999   "Look through all the headers and mark the Xrefs as read."
6000   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6001         name info xref-hashtb idlist method nth4)
6002     (save-excursion
6003       (set-buffer gnus-group-buffer)
6004       (when (setq xref-hashtb
6005                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6006         (mapatoms
6007          (lambda (group)
6008            (unless (string= from-newsgroup (setq name (symbol-name group)))
6009              (setq idlist (symbol-value group))
6010              ;; Dead groups are not updated.
6011              (and (prog1
6012                       (setq info (gnus-get-info name))
6013                     (when (stringp (setq nth4 (gnus-info-method info)))
6014                       (setq nth4 (gnus-server-to-method nth4))))
6015                   ;; Only do the xrefs if the group has the same
6016                   ;; select method as the group we have just read.
6017                   (or (gnus-methods-equal-p
6018                        nth4 (gnus-find-method-for-group from-newsgroup))
6019                       virtual
6020                       (equal nth4 (setq method (gnus-find-method-for-group
6021                                                 from-newsgroup)))
6022                       (and (equal (car nth4) (car method))
6023                            (equal (nth 1 nth4) (nth 1 method))))
6024                   gnus-use-cross-reference
6025                   (or (not (eq gnus-use-cross-reference t))
6026                       virtual
6027                       ;; Only do cross-references on subscribed
6028                       ;; groups, if that is what is wanted.
6029                       (<= (gnus-info-level info) gnus-level-subscribed))
6030                   (gnus-group-make-articles-read name idlist))))
6031          xref-hashtb)))))
6032
6033 (defun gnus-compute-read-articles (group articles)
6034   (let* ((entry (gnus-group-entry group))
6035          (info (nth 2 entry))
6036          (active (gnus-active group))
6037          ninfo)
6038     (when entry
6039       ;; First peel off all invalid article numbers.
6040       (when active
6041         (let ((ids articles)
6042               id first)
6043           (while (setq id (pop ids))
6044             (when (and first (> id (cdr active)))
6045               ;; We'll end up in this situation in one particular
6046               ;; obscure situation.  If you re-scan a group and get
6047               ;; a new article that is cross-posted to a different
6048               ;; group that has not been re-scanned, you might get
6049               ;; crossposted article that has a higher number than
6050               ;; Gnus believes possible.  So we re-activate this
6051               ;; group as well.  This might mean doing the
6052               ;; crossposting thingy will *increase* the number
6053               ;; of articles in some groups.  Tsk, tsk.
6054               (setq active (or (gnus-activate-group group) active)))
6055             (when (or (> id (cdr active))
6056                       (< id (car active)))
6057               (setq articles (delq id articles))))))
6058       ;; If the read list is nil, we init it.
6059       (if (and active
6060                (null (gnus-info-read info))
6061                (> (car active) 1))
6062           (setq ninfo (cons 1 (1- (car active))))
6063         (setq ninfo (gnus-info-read info)))
6064       ;; Then we add the read articles to the range.
6065       (gnus-add-to-range
6066        ninfo (setq articles (sort articles '<))))))
6067
6068 (defun gnus-group-make-articles-read (group articles)
6069   "Update the info of GROUP to say that ARTICLES are read."
6070   (let* ((num 0)
6071          (entry (gnus-group-entry group))
6072          (info (nth 2 entry))
6073          (active (gnus-active group))
6074          range)
6075     (when entry
6076       (setq range (gnus-compute-read-articles group articles))
6077       (with-current-buffer gnus-group-buffer
6078         (gnus-undo-register
6079           `(progn
6080              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6081              (gnus-info-set-read ',info ',(gnus-info-read info))
6082              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6083              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6084              (gnus-group-update-group ,group t))))
6085       ;; Add the read articles to the range.
6086       (gnus-info-set-read info range)
6087       (gnus-request-set-mark group (list (list range 'add '(read))))
6088       ;; Then we have to re-compute how many unread
6089       ;; articles there are in this group.
6090       (when active
6091         (cond
6092          ((not range)
6093           (setq num (- (1+ (cdr active)) (car active))))
6094          ((not (listp (cdr range)))
6095           (setq num (- (cdr active) (- (1+ (cdr range))
6096                                        (car range)))))
6097          (t
6098           (while range
6099             (if (numberp (car range))
6100                 (setq num (1+ num))
6101               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6102             (setq range (cdr range)))
6103           (setq num (- (cdr active) num))))
6104         ;; Update the number of unread articles.
6105         (setcar entry num)
6106         ;; Update the group buffer.
6107         (unless (gnus-ephemeral-group-p group)
6108           (gnus-group-update-group group t))))))
6109
6110 (defvar gnus-newsgroup-none-id 0)
6111
6112 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6113   (let ((cur nntp-server-buffer)
6114         (dependencies
6115          (or dependencies
6116              (with-current-buffer gnus-summary-buffer
6117                gnus-newsgroup-dependencies)))
6118         headers id end ref number
6119         (mail-parse-charset gnus-newsgroup-charset)
6120         (mail-parse-ignored-charsets
6121          (save-excursion (condition-case nil
6122                              (set-buffer gnus-summary-buffer)
6123                            (error))
6124                          gnus-newsgroup-ignored-charsets)))
6125     (save-excursion
6126       (set-buffer nntp-server-buffer)
6127       ;; Translate all TAB characters into SPACE characters.
6128       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6129       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6130       (ietf-drums-unfold-fws)
6131       (gnus-run-hooks 'gnus-parse-headers-hook)
6132       (let ((case-fold-search t)
6133             in-reply-to header p lines chars)
6134         (goto-char (point-min))
6135         ;; Search to the beginning of the next header.  Error messages
6136         ;; do not begin with 2 or 3.
6137         (while (re-search-forward "^[23][0-9]+ " nil t)
6138           (setq id nil
6139                 ref nil)
6140           ;; This implementation of this function, with nine
6141           ;; search-forwards instead of the one re-search-forward and
6142           ;; a case (which basically was the old function) is actually
6143           ;; about twice as fast, even though it looks messier.  You
6144           ;; can't have everything, I guess.  Speed and elegance
6145           ;; doesn't always go hand in hand.
6146           (setq
6147            header
6148            (vector
6149             ;; Number.
6150             (prog1
6151                 (setq number (read cur))
6152               (end-of-line)
6153               (setq p (point))
6154               (narrow-to-region (point)
6155                                 (or (and (search-forward "\n.\n" nil t)
6156                                          (- (point) 2))
6157                                     (point))))
6158             ;; Subject.
6159             (progn
6160               (goto-char p)
6161               (if (search-forward "\nsubject:" nil t)
6162                   (funcall gnus-decode-encoded-word-function
6163                            (nnheader-header-value))
6164                 "(none)"))
6165             ;; From.
6166             (progn
6167               (goto-char p)
6168               (if (search-forward "\nfrom:" nil t)
6169                   (funcall gnus-decode-encoded-address-function
6170                            (nnheader-header-value))
6171                 "(nobody)"))
6172             ;; Date.
6173             (progn
6174               (goto-char p)
6175               (if (search-forward "\ndate:" nil t)
6176                   (nnheader-header-value) ""))
6177             ;; Message-ID.
6178             (progn
6179               (goto-char p)
6180               (setq id (if (re-search-forward
6181                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6182                            ;; We do it this way to make sure the Message-ID
6183                            ;; is (somewhat) syntactically valid.
6184                            (buffer-substring (match-beginning 1)
6185                                              (match-end 1))
6186                          ;; If there was no message-id, we just fake one
6187                          ;; to make subsequent routines simpler.
6188                          (nnheader-generate-fake-message-id number))))
6189             ;; References.
6190             (progn
6191               (goto-char p)
6192               (if (search-forward "\nreferences:" nil t)
6193                   (progn
6194                     (setq end (point))
6195                     (prog1
6196                         (nnheader-header-value)
6197                       (setq ref
6198                             (buffer-substring
6199                              (progn
6200                                (end-of-line)
6201                                (search-backward ">" end t)
6202                                (1+ (point)))
6203                              (progn
6204                                (search-backward "<" end t)
6205                                (point))))))
6206                 ;; Get the references from the in-reply-to header if there
6207                 ;; were no references and the in-reply-to header looks
6208                 ;; promising.
6209                 (if (and (search-forward "\nin-reply-to:" nil t)
6210                          (setq in-reply-to (nnheader-header-value))
6211                          (string-match "<[^>]+>" in-reply-to))
6212                     (let (ref2)
6213                       (setq ref (substring in-reply-to (match-beginning 0)
6214                                            (match-end 0)))
6215                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6216                         (setq ref2 (substring in-reply-to (match-beginning 0)
6217                                               (match-end 0)))
6218                         (when (> (length ref2) (length ref))
6219                           (setq ref ref2)))
6220                       ref)
6221                   (setq ref nil))))
6222             ;; Chars.
6223             (progn
6224               (goto-char p)
6225               (if (search-forward "\nchars: " nil t)
6226                   (if (numberp (setq chars (ignore-errors (read cur))))
6227                       chars -1)
6228                 -1))
6229             ;; Lines.
6230             (progn
6231               (goto-char p)
6232               (if (search-forward "\nlines: " nil t)
6233                   (if (numberp (setq lines (ignore-errors (read cur))))
6234                       lines -1)
6235                 -1))
6236             ;; Xref.
6237             (progn
6238               (goto-char p)
6239               (and (search-forward "\nxref:" nil t)
6240                    (nnheader-header-value)))
6241             ;; Extra.
6242             (when gnus-extra-headers
6243               (let ((extra gnus-extra-headers)
6244                     out)
6245                 (while extra
6246                   (goto-char p)
6247                   (when (search-forward
6248                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6249                     (push (cons (car extra) (nnheader-header-value))
6250                           out))
6251                   (pop extra))
6252                 out))))
6253           (when (equal id ref)
6254             (setq ref nil))
6255
6256           (when gnus-alter-header-function
6257             (funcall gnus-alter-header-function header)
6258             (setq id (mail-header-id header)
6259                   ref (gnus-parent-id (mail-header-references header))))
6260
6261           (when (setq header
6262                       (gnus-dependencies-add-header
6263                        header dependencies force-new))
6264             (push header headers))
6265           (goto-char (point-max))
6266           (widen))
6267         (nreverse headers)))))
6268
6269 ;; Goes through the xover lines and returns a list of vectors
6270 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6271                                                   force-new dependencies
6272                                                   group also-fetch-heads)
6273   "Parse the news overview data in the server buffer.
6274 Return a list of headers that match SEQUENCE (see
6275 `nntp-retrieve-headers')."
6276   ;; Get the Xref when the users reads the articles since most/some
6277   ;; NNTP servers do not include Xrefs when using XOVER.
6278   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6279   (let ((mail-parse-charset gnus-newsgroup-charset)
6280         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6281         (cur nntp-server-buffer)
6282         (dependencies (or dependencies gnus-newsgroup-dependencies))
6283         (allp (cond
6284                ((eq gnus-read-all-available-headers t)
6285                 t)
6286                ((and (stringp gnus-read-all-available-headers)
6287                      group)
6288                 (string-match gnus-read-all-available-headers group))
6289                (t
6290                 nil)))
6291         number headers header)
6292     (save-excursion
6293       (set-buffer nntp-server-buffer)
6294       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6295       ;; Allow the user to mangle the headers before parsing them.
6296       (gnus-run-hooks 'gnus-parse-headers-hook)
6297       (goto-char (point-min))
6298       (gnus-parse-without-error
6299         (while (and (or sequence allp)
6300                     (not (eobp)))
6301           (setq number (read cur))
6302           (when (not allp)
6303             (while (and sequence
6304                         (< (car sequence) number))
6305               (setq sequence (cdr sequence))))
6306           (when (and (or allp
6307                          (and sequence
6308                               (eq number (car sequence))))
6309                      (progn
6310                        (setq sequence (cdr sequence))
6311                        (setq header (inline
6312                                       (gnus-nov-parse-line
6313                                        number dependencies force-new)))))
6314             (push header headers))
6315           (forward-line 1)))
6316       ;; A common bug in inn is that if you have posted an article and
6317       ;; then retrieves the active file, it will answer correctly --
6318       ;; the new article is included.  However, a NOV entry for the
6319       ;; article may not have been generated yet, so this may fail.
6320       ;; We work around this problem by retrieving the last few
6321       ;; headers using HEAD.
6322       (if (or (not also-fetch-heads)
6323               (not sequence))
6324           ;; We (probably) got all the headers.
6325           (nreverse headers)
6326         (let ((gnus-nov-is-evil t))
6327           (nconc
6328            (nreverse headers)
6329            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6330              (gnus-get-newsgroup-headers))))))))
6331
6332 (defun gnus-article-get-xrefs ()
6333   "Fill in the Xref value in `gnus-current-headers', if necessary.
6334 This is meant to be called in `gnus-article-internal-prepare-hook'."
6335   (let ((headers (with-current-buffer gnus-summary-buffer
6336                    gnus-current-headers)))
6337     (or (not gnus-use-cross-reference)
6338         (not headers)
6339         (and (mail-header-xref headers)
6340              (not (string= (mail-header-xref headers) "")))
6341         (let ((case-fold-search t)
6342               xref)
6343           (save-restriction
6344             (nnheader-narrow-to-headers)
6345             (goto-char (point-min))
6346             (when (or (and (not (eobp))
6347                            (eq (downcase (char-after)) ?x)
6348                            (looking-at "Xref:"))
6349                       (search-forward "\nXref:" nil t))
6350               (goto-char (1+ (match-end 0)))
6351               (setq xref (buffer-substring (point) (point-at-eol)))
6352               (mail-header-set-xref headers xref)))))))
6353
6354 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6355   "Find article ID and insert the summary line for that article.
6356 OLD-HEADER can either be a header or a line number to insert
6357 the subject line on."
6358   (let* ((line (and (numberp old-header) old-header))
6359          (old-header (and (vectorp old-header) old-header))
6360          (header (cond ((and old-header use-old-header)
6361                         old-header)
6362                        ((and (numberp id)
6363                              (gnus-number-to-header id))
6364                         (gnus-number-to-header id))
6365                        (t
6366                         (gnus-read-header id))))
6367          (number (and (numberp id) id))
6368          d)
6369     (when header
6370       ;; Rebuild the thread that this article is part of and go to the
6371       ;; article we have fetched.
6372       (when (and (not gnus-show-threads)
6373                  old-header)
6374         (when (and number
6375                    (setq d (gnus-data-find (mail-header-number old-header))))
6376           (goto-char (gnus-data-pos d))
6377           (gnus-data-remove
6378            number
6379            (- (point-at-bol)
6380               (prog1
6381                   (1+ (point-at-eol))
6382                 (gnus-delete-line))))))
6383       ;; Remove list identifiers from subject.
6384       (when gnus-list-identifiers
6385         (let ((gnus-newsgroup-headers (list header)))
6386           (gnus-summary-remove-list-identifiers)))
6387       (when old-header
6388         (mail-header-set-number header (mail-header-number old-header)))
6389       (setq gnus-newsgroup-sparse
6390             (delq (setq number (mail-header-number header))
6391                   gnus-newsgroup-sparse))
6392       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6393       (push number gnus-newsgroup-limit)
6394       (gnus-rebuild-thread (mail-header-id header) line)
6395       (gnus-summary-goto-subject number nil t))
6396     (when (and (numberp number)
6397                (> number 0))
6398       ;; We have to update the boundaries even if we can't fetch the
6399       ;; article if ID is a number -- so that the next `P' or `N'
6400       ;; command will fetch the previous (or next) article even
6401       ;; if the one we tried to fetch this time has been canceled.
6402       (when (> number gnus-newsgroup-end)
6403         (setq gnus-newsgroup-end number))
6404       (when (< number gnus-newsgroup-begin)
6405         (setq gnus-newsgroup-begin number))
6406       (setq gnus-newsgroup-unselected
6407             (delq number gnus-newsgroup-unselected)))
6408     ;; Report back a success?
6409     (and header (mail-header-number header))))
6410
6411 ;;; Process/prefix in the summary buffer
6412
6413 (defun gnus-summary-work-articles (n)
6414   "Return a list of articles to be worked upon.
6415 The prefix argument, the list of process marked articles, and the
6416 current article will be taken into consideration."
6417   (save-excursion
6418     (set-buffer gnus-summary-buffer)
6419     (cond
6420      (n
6421       ;; A numerical prefix has been given.
6422       (setq n (prefix-numeric-value n))
6423       (let ((backward (< n 0))
6424             (n (abs (prefix-numeric-value n)))
6425             articles article)
6426         (save-excursion
6427           (while
6428               (and (> n 0)
6429                    (push (setq article (gnus-summary-article-number))
6430                          articles)
6431                    (if backward
6432                        (gnus-summary-find-prev nil article)
6433                      (gnus-summary-find-next nil article)))
6434             (decf n)))
6435         (nreverse articles)))
6436      ((and (gnus-region-active-p) (mark))
6437       (message "region active")
6438       ;; Work on the region between point and mark.
6439       (let ((max (max (point) (mark)))
6440             articles article)
6441         (save-excursion
6442           (goto-char (min (point) (mark)))
6443           (while
6444               (and
6445                (push (setq article (gnus-summary-article-number)) articles)
6446                (gnus-summary-find-next nil article)
6447                (< (point) max)))
6448           (nreverse articles))))
6449      (gnus-newsgroup-processable
6450       ;; There are process-marked articles present.
6451       ;; Save current state.
6452       (gnus-summary-save-process-mark)
6453       ;; Return the list.
6454       (reverse gnus-newsgroup-processable))
6455      (t
6456       ;; Just return the current article.
6457       (list (gnus-summary-article-number))))))
6458
6459 (defmacro gnus-summary-iterate (arg &rest forms)
6460   "Iterate over the process/prefixed articles and do FORMS.
6461 ARG is the interactive prefix given to the command.  FORMS will be
6462 executed with point over the summary line of the articles."
6463   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6464     `(let ((,articles (gnus-summary-work-articles ,arg)))
6465        (while ,articles
6466          (gnus-summary-goto-subject (car ,articles))
6467          ,@forms
6468          (pop ,articles)))))
6469
6470 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6471 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6472
6473 (defun gnus-summary-save-process-mark ()
6474   "Push the current set of process marked articles on the stack."
6475   (interactive)
6476   (push (copy-sequence gnus-newsgroup-processable)
6477         gnus-newsgroup-process-stack))
6478
6479 (defun gnus-summary-kill-process-mark ()
6480   "Push the current set of process marked articles on the stack and unmark."
6481   (interactive)
6482   (gnus-summary-save-process-mark)
6483   (gnus-summary-unmark-all-processable))
6484
6485 (defun gnus-summary-yank-process-mark ()
6486   "Pop the last process mark state off the stack and restore it."
6487   (interactive)
6488   (unless gnus-newsgroup-process-stack
6489     (error "Empty mark stack"))
6490   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6491
6492 (defun gnus-summary-process-mark-set (set)
6493   "Make SET into the current process marked articles."
6494   (gnus-summary-unmark-all-processable)
6495   (mapc 'gnus-summary-set-process-mark set))
6496
6497 ;;; Searching and stuff
6498
6499 (defun gnus-summary-search-group (&optional backward use-level)
6500   "Search for next unread newsgroup.
6501 If optional argument BACKWARD is non-nil, search backward instead."
6502   (save-excursion
6503     (set-buffer gnus-group-buffer)
6504     (when (gnus-group-search-forward
6505            backward nil (if use-level (gnus-group-group-level) nil))
6506       (gnus-group-group-name))))
6507
6508 (defun gnus-summary-best-group (&optional exclude-group)
6509   "Find the name of the best unread group.
6510 If EXCLUDE-GROUP, do not go to this group."
6511   (with-current-buffer gnus-group-buffer
6512     (save-excursion
6513       (gnus-group-best-unread-group exclude-group))))
6514
6515 (defun gnus-summary-find-next (&optional unread article backward)
6516   (if backward
6517       (gnus-summary-find-prev unread article)
6518     (let* ((dummy (gnus-summary-article-intangible-p))
6519            (article (or article (gnus-summary-article-number)))
6520            (data (gnus-data-find-list article))
6521            result)
6522       (when (and (not dummy)
6523                  (or (not gnus-summary-check-current)
6524                      (not unread)
6525                      (not (gnus-data-unread-p (car data)))))
6526         (setq data (cdr data)))
6527       (when (setq result
6528                   (if unread
6529                       (progn
6530                         (while data
6531                           (unless (memq (gnus-data-number (car data))
6532                                         (cond
6533                                          ((eq gnus-auto-goto-ignores
6534                                               'always-undownloaded)
6535                                           gnus-newsgroup-undownloaded)
6536                                          (gnus-plugged
6537                                           nil)
6538                                          ((eq gnus-auto-goto-ignores
6539                                               'unfetched)
6540                                           gnus-newsgroup-unfetched)
6541                                          ((eq gnus-auto-goto-ignores
6542                                               'undownloaded)
6543                                           gnus-newsgroup-undownloaded)))
6544                             (when (gnus-data-unread-p (car data))
6545                               (setq result (car data)
6546                                     data nil)))
6547                           (setq data (cdr data)))
6548                         result)
6549                     (car data)))
6550         (goto-char (gnus-data-pos result))
6551         (gnus-data-number result)))))
6552
6553 (defun gnus-summary-find-prev (&optional unread article)
6554   (let* ((eobp (eobp))
6555          (article (or article (gnus-summary-article-number)))
6556          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6557          result)
6558     (when (and (not eobp)
6559                (or (not gnus-summary-check-current)
6560                    (not unread)
6561                    (not (gnus-data-unread-p (car data)))))
6562       (setq data (cdr data)))
6563     (when (setq result
6564                 (if unread
6565                     (progn
6566                       (while data
6567                         (unless (memq (gnus-data-number (car data))
6568                                       (cond
6569                                        ((eq gnus-auto-goto-ignores
6570                                             'always-undownloaded)
6571                                         gnus-newsgroup-undownloaded)
6572                                        (gnus-plugged
6573                                         nil)
6574                                        ((eq gnus-auto-goto-ignores
6575                                             'unfetched)
6576                                         gnus-newsgroup-unfetched)
6577                                        ((eq gnus-auto-goto-ignores
6578                                             'undownloaded)
6579                                         gnus-newsgroup-undownloaded)))
6580                           (when (gnus-data-unread-p (car data))
6581                             (setq result (car data)
6582                                   data nil)))
6583                         (setq data (cdr data)))
6584                       result)
6585                   (car data)))
6586       (goto-char (gnus-data-pos result))
6587       (gnus-data-number result))))
6588
6589 (defun gnus-summary-find-subject (subject &optional unread backward article)
6590   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6591          (article (or article (gnus-summary-article-number)))
6592          (articles (gnus-data-list backward))
6593          (arts (gnus-data-find-list article articles))
6594          result)
6595     (when (or (not gnus-summary-check-current)
6596               (not unread)
6597               (not (gnus-data-unread-p (car arts))))
6598       (setq arts (cdr arts)))
6599     (while arts
6600       (and (or (not unread)
6601                (gnus-data-unread-p (car arts)))
6602            (vectorp (gnus-data-header (car arts)))
6603            (gnus-subject-equal
6604             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6605            (setq result (car arts)
6606                  arts nil))
6607       (setq arts (cdr arts)))
6608     (and result
6609          (goto-char (gnus-data-pos result))
6610          (gnus-data-number result))))
6611
6612 (defun gnus-summary-search-forward (&optional unread subject backward)
6613   "Search forward for an article.
6614 If UNREAD, look for unread articles.  If SUBJECT, look for
6615 articles with that subject.  If BACKWARD, search backward instead."
6616   (cond (subject (gnus-summary-find-subject subject unread backward))
6617         (backward (gnus-summary-find-prev unread))
6618         (t (gnus-summary-find-next unread))))
6619
6620 (defun gnus-recenter (&optional n)
6621   "Center point in window and redisplay frame.
6622 Also do horizontal recentering."
6623   (interactive "P")
6624   (when (and gnus-auto-center-summary
6625              (not (eq gnus-auto-center-summary 'vertical)))
6626     (gnus-horizontal-recenter))
6627   (recenter n))
6628
6629 (defun gnus-summary-recenter ()
6630   "Center point in the summary window.
6631 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6632 displayed, no centering will be performed."
6633   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6634   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6635   (interactive)
6636   ;; The user has to want it.
6637   (when gnus-auto-center-summary
6638     (let* ((top (cond ((< (window-height) 4) 0)
6639                       ((< (window-height) 7) 1)
6640                       (t (if (numberp gnus-auto-center-summary)
6641                              gnus-auto-center-summary
6642                            (/ (1- (window-height)) 2)))))
6643            (height (1- (window-height)))
6644            (bottom (save-excursion (goto-char (point-max))
6645                                    (forward-line (- height))
6646                                    (point)))
6647            (window (get-buffer-window (current-buffer))))
6648       (when (get-buffer-window gnus-article-buffer)
6649         ;; Only do recentering when the article buffer is displayed,
6650         ;; Set the window start to either `bottom', which is the biggest
6651         ;; possible valid number, or the second line from the top,
6652         ;; whichever is the least.
6653         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6654           (if (> bottom top-pos)
6655               ;; Keep the second line from the top visible
6656               (set-window-start window top-pos)
6657             ;; Try to keep the bottom line visible; if it's partially
6658             ;; obscured, either scroll one more line to make it fully
6659             ;; visible, or revert to using TOP-POS.
6660             (save-excursion
6661               (goto-char (point-max))
6662               (forward-line -1)
6663               (let ((last-line-start (point)))
6664                 (goto-char bottom)
6665                 (set-window-start window (point) t)
6666                 (when (not (pos-visible-in-window-p last-line-start window))
6667                   (forward-line 1)
6668                   (set-window-start window (min (point) top-pos) t)))))))
6669       ;; Do horizontal recentering while we're at it.
6670       (when (and (get-buffer-window (current-buffer) t)
6671                  (not (eq gnus-auto-center-summary 'vertical)))
6672         (let ((selected (selected-window)))
6673           (select-window (get-buffer-window (current-buffer) t))
6674           (gnus-summary-position-point)
6675           (gnus-horizontal-recenter)
6676           (select-window selected))))))
6677
6678 (defun gnus-summary-jump-to-group (newsgroup)
6679   "Move point to NEWSGROUP in group mode buffer."
6680   ;; Keep update point of group mode buffer if visible.
6681   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6682       (save-window-excursion
6683         ;; Take care of tree window mode.
6684         (when (get-buffer-window gnus-group-buffer)
6685           (pop-to-buffer gnus-group-buffer))
6686         (gnus-group-jump-to-group newsgroup))
6687     (save-excursion
6688       ;; Take care of tree window mode.
6689       (if (get-buffer-window gnus-group-buffer)
6690           (pop-to-buffer gnus-group-buffer)
6691         (set-buffer gnus-group-buffer))
6692       (gnus-group-jump-to-group newsgroup))))
6693
6694 ;; This function returns a list of article numbers based on the
6695 ;; difference between the ranges of read articles in this group and
6696 ;; the range of active articles.
6697 (defun gnus-list-of-unread-articles (group)
6698   (let* ((read (gnus-info-read (gnus-get-info group)))
6699          (active (or (gnus-active group) (gnus-activate-group group)))
6700          (last (or (cdr active)
6701                    (error "Group %s couldn't be activated " group)))
6702          first nlast unread)
6703     ;; If none are read, then all are unread.
6704     (if (not read)
6705         (setq first (car active))
6706       ;; If the range of read articles is a single range, then the
6707       ;; first unread article is the article after the last read
6708       ;; article.  Sounds logical, doesn't it?
6709       (if (and (not (listp (cdr read)))
6710                (or (< (car read) (car active))
6711                    (progn (setq read (list read))
6712                           nil)))
6713           (setq first (max (car active) (1+ (cdr read))))
6714         ;; `read' is a list of ranges.
6715         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6716                                   (caar read)))
6717                   1)
6718           (setq first (car active)))
6719         (while read
6720           (when first
6721             (while (< first nlast)
6722               (setq unread (cons first unread)
6723                     first (1+ first))))
6724           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6725           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6726           (setq read (cdr read)))))
6727     ;; And add the last unread articles.
6728     (while (<= first last)
6729       (setq unread (cons first unread)
6730             first (1+ first)))
6731     ;; Return the list of unread articles.
6732     (delq 0 (nreverse unread))))
6733
6734 (defun gnus-list-of-read-articles (group)
6735   "Return a list of unread, unticked and non-dormant articles."
6736   (let* ((info (gnus-get-info group))
6737          (marked (gnus-info-marks info))
6738          (active (gnus-active group)))
6739     (and info active
6740          (gnus-list-range-difference
6741           (gnus-list-range-difference
6742            (gnus-sorted-complement
6743             (gnus-uncompress-range active)
6744             (gnus-list-of-unread-articles group))
6745            (cdr (assq 'dormant marked)))
6746           (cdr (assq 'tick marked))))))
6747
6748 ;; This function returns a sequence of article numbers based on the
6749 ;; difference between the ranges of read articles in this group and
6750 ;; the range of active articles.
6751 (defun gnus-sequence-of-unread-articles (group)
6752   (let* ((read (gnus-info-read (gnus-get-info group)))
6753          (active (or (gnus-active group) (gnus-activate-group group)))
6754          (last (cdr active))
6755          first nlast unread)
6756     ;; If none are read, then all are unread.
6757     (if (not read)
6758         (setq first (car active))
6759       ;; If the range of read articles is a single range, then the
6760       ;; first unread article is the article after the last read
6761       ;; article.  Sounds logical, doesn't it?
6762       (if (and (not (listp (cdr read)))
6763                (or (< (car read) (car active))
6764                    (progn (setq read (list read))
6765                           nil)))
6766           (setq first (max (car active) (1+ (cdr read))))
6767         ;; `read' is a list of ranges.
6768         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6769                                   (caar read)))
6770                   1)
6771           (setq first (car active)))
6772         (while read
6773           (when first
6774             (push (cons first nlast) unread))
6775           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6776           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6777           (setq read (cdr read)))))
6778     ;; And add the last unread articles.
6779     (cond ((not (and first last))
6780            nil)
6781           ((< first last)
6782            (push (cons first last) unread))
6783           ((= first last)
6784            (push first unread)))
6785     ;; Return the sequence of unread articles.
6786     (delq 0 (nreverse unread))))
6787
6788 ;; Various summary commands
6789
6790 (defun gnus-summary-select-article-buffer ()
6791   "Reconfigure windows to show article buffer."
6792   (interactive)
6793   (if (not (gnus-buffer-live-p gnus-article-buffer))
6794       (error "There is no article buffer for this summary buffer")
6795     (gnus-configure-windows 'article)
6796     (select-window (get-buffer-window gnus-article-buffer))))
6797
6798 (defun gnus-summary-universal-argument (arg)
6799   "Perform any operation on all articles that are process/prefixed."
6800   (interactive "P")
6801   (let ((articles (gnus-summary-work-articles arg))
6802         func article)
6803     (if (eq
6804          (setq
6805           func
6806           (key-binding
6807            (read-key-sequence
6808             (substitute-command-keys
6809              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6810          'undefined)
6811         (gnus-error 1 "Undefined key")
6812       (save-excursion
6813         (while articles
6814           (gnus-summary-goto-subject (setq article (pop articles)))
6815           (let (gnus-newsgroup-processable)
6816             (command-execute func))
6817           (gnus-summary-remove-process-mark article)))))
6818   (gnus-summary-position-point))
6819
6820 (defun gnus-summary-toggle-truncation (&optional arg)
6821   "Toggle truncation of summary lines.
6822 With ARG, turn line truncation on if ARG is positive."
6823   (interactive "P")
6824   (setq truncate-lines
6825         (if (null arg) (not truncate-lines)
6826           (> (prefix-numeric-value arg) 0)))
6827   (redraw-display))
6828
6829 (defun gnus-summary-find-for-reselect ()
6830   "Return the number of an article to stay on across a reselect.
6831 The current article is considered, then following articles, then previous
6832 articles.  An article is sought which is not cancelled and isn't a temporary
6833 insertion from another group.  If there's no such then return a dummy 0."
6834   (let (found)
6835     (dolist (rev '(nil t))
6836       (unless found      ; don't demand the reverse list if we don't need it
6837         (let ((data (gnus-data-find-list
6838                      (gnus-summary-article-number) (gnus-data-list rev))))
6839           (while (and data (not found))
6840             (if (and (< 0 (gnus-data-number (car data)))
6841                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6842                 (setq found (gnus-data-number (car data))))
6843             (setq data (cdr data))))))
6844     (or found 0)))
6845
6846 (defun gnus-summary-reselect-current-group (&optional all rescan)
6847   "Exit and then reselect the current newsgroup.
6848 The prefix argument ALL means to select all articles."
6849   (interactive "P")
6850   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6851     (error "Ephemeral groups can't be reselected"))
6852   (let ((current-subject (gnus-summary-find-for-reselect))
6853         (group gnus-newsgroup-name))
6854     (setq gnus-newsgroup-begin nil)
6855     (gnus-summary-exit nil 'leave-hidden)
6856     ;; We have to adjust the point of group mode buffer because
6857     ;; point was moved to the next unread newsgroup by exiting.
6858     (gnus-summary-jump-to-group group)
6859     (when rescan
6860       (save-excursion
6861         (gnus-group-get-new-news-this-group 1)))
6862     (gnus-group-read-group all t)
6863     (gnus-summary-goto-subject current-subject nil t)))
6864
6865 (defun gnus-summary-rescan-group (&optional all)
6866   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6867   (interactive "P")
6868   (gnus-summary-reselect-current-group all t))
6869
6870 (defun gnus-summary-update-info (&optional non-destructive)
6871   (save-excursion
6872     (let ((group gnus-newsgroup-name))
6873       (when group
6874         (when gnus-newsgroup-kill-headers
6875           (setq gnus-newsgroup-killed
6876                 (gnus-compress-sequence
6877                  (gnus-sorted-union
6878                   (gnus-list-range-intersection
6879                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6880                   gnus-newsgroup-unreads)
6881                  t)))
6882         (unless (listp (cdr gnus-newsgroup-killed))
6883           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6884         (let ((headers gnus-newsgroup-headers))
6885           ;; Set the new ranges of read articles.
6886           (with-current-buffer gnus-group-buffer
6887             (gnus-undo-force-boundary))
6888           (gnus-update-read-articles
6889            group (gnus-sorted-union
6890                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6891           ;; Set the current article marks.
6892           (let ((gnus-newsgroup-scored
6893                  (if (and (not gnus-save-score)
6894                           (not non-destructive))
6895                      nil
6896                    gnus-newsgroup-scored)))
6897             (save-excursion
6898               (gnus-update-marks)))
6899           ;; Do the cross-ref thing.
6900           (when gnus-use-cross-reference
6901             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6902           ;; Do not switch windows but change the buffer to work.
6903           (set-buffer gnus-group-buffer)
6904           (unless (gnus-ephemeral-group-p group)
6905             (gnus-group-update-group group)))))))
6906
6907 (defun gnus-summary-save-newsrc (&optional force)
6908   "Save the current number of read/marked articles in the dribble buffer.
6909 The dribble buffer will then be saved.
6910 If FORCE (the prefix), also save the .newsrc file(s)."
6911   (interactive "P")
6912   (gnus-summary-update-info t)
6913   (if force
6914       (gnus-save-newsrc-file)
6915     (gnus-dribble-save)))
6916
6917 (defun gnus-summary-exit (&optional temporary leave-hidden)
6918   "Exit reading current newsgroup, and then return to group selection mode.
6919 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6920   (interactive)
6921   (gnus-set-global-variables)
6922   (when (gnus-buffer-live-p gnus-article-buffer)
6923     (save-excursion
6924       (set-buffer gnus-article-buffer)
6925       (mm-destroy-parts gnus-article-mime-handles)
6926       ;; Set it to nil for safety reason.
6927       (setq gnus-article-mime-handle-alist nil)
6928       (setq gnus-article-mime-handles nil)))
6929   (gnus-kill-save-kill-buffer)
6930   (gnus-async-halt-prefetch)
6931   (let* ((group gnus-newsgroup-name)
6932          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6933          (gnus-group-is-exiting-p t)
6934          (mode major-mode)
6935          (group-point nil)
6936          (buf (current-buffer)))
6937     (unless quit-config
6938       ;; Do adaptive scoring, and possibly save score files.
6939       (when gnus-newsgroup-adaptive
6940         (gnus-score-adaptive))
6941       (when gnus-use-scoring
6942         (gnus-score-save)))
6943     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6944     ;; If we have several article buffers, we kill them at exit.
6945     (unless gnus-single-article-buffer
6946       (when (gnus-buffer-live-p gnus-article-buffer)
6947         (with-current-buffer gnus-article-buffer
6948           ;; Don't kill sticky article buffers
6949           (unless (eq major-mode 'gnus-sticky-article-mode)
6950             (gnus-kill-buffer gnus-article-buffer)
6951             (setq gnus-article-current nil))))
6952       (gnus-kill-buffer gnus-original-article-buffer))
6953     (when gnus-use-cache
6954       (gnus-cache-possibly-remove-articles)
6955       (gnus-cache-save-buffers))
6956     (gnus-async-prefetch-remove-group group)
6957     (when gnus-suppress-duplicates
6958       (gnus-dup-enter-articles))
6959     (when gnus-use-trees
6960       (gnus-tree-close group))
6961     (when gnus-use-cache
6962       (gnus-cache-write-active))
6963     ;; Remove entries for this group.
6964     (nnmail-purge-split-history (gnus-group-real-name group))
6965     ;; Make all changes in this group permanent.
6966     (unless quit-config
6967       (gnus-run-hooks 'gnus-exit-group-hook)
6968       (gnus-summary-update-info))
6969     (gnus-close-group group)
6970     ;; Make sure where we were, and go to next newsgroup.
6971     (set-buffer gnus-group-buffer)
6972     (unless quit-config
6973       (gnus-group-jump-to-group group))
6974     (gnus-run-hooks 'gnus-summary-exit-hook)
6975     (unless (or quit-config
6976                 (not gnus-summary-next-group-on-exit)
6977                 ;; If this group has disappeared from the summary
6978                 ;; buffer, don't skip forwards.
6979                 (not (string= group (gnus-group-group-name))))
6980       (gnus-group-next-unread-group 1))
6981     (setq group-point (point))
6982     (if temporary
6983         nil                             ;Nothing to do.
6984       (set-buffer buf)
6985       (if (not gnus-kill-summary-on-exit)
6986           (progn
6987             (gnus-deaden-summary)
6988             (setq mode nil))
6989         ;; We set all buffer-local variables to nil.  It is unclear why
6990         ;; this is needed, but if we don't, buffer-local variables are
6991         ;; not garbage-collected, it seems.  This would the lead to en
6992         ;; ever-growing Emacs.
6993         (gnus-summary-clear-local-variables)
6994         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6995           (gnus-summary-clear-local-variables))
6996         (when (get-buffer gnus-article-buffer)
6997           (bury-buffer gnus-article-buffer))
6998         ;; Return to group mode buffer.
6999         (when (eq mode 'gnus-summary-mode)
7000           (gnus-kill-buffer buf)))
7001       (setq gnus-current-select-method gnus-select-method)
7002       (set-buffer gnus-group-buffer)
7003       (if quit-config
7004           (gnus-handle-ephemeral-exit quit-config)
7005         (goto-char group-point)
7006         ;; If gnus-group-buffer is already displayed, make sure we also move
7007         ;; the cursor in the window that displays it.
7008         (let ((win (get-buffer-window (current-buffer) 0)))
7009           (if win (set-window-point win (point))))
7010         (unless leave-hidden
7011           (gnus-configure-windows 'group 'force)))
7012       ;; Clear the current group name.
7013       (unless quit-config
7014         (setq gnus-newsgroup-name nil)))))
7015
7016 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7017 (defun gnus-summary-exit-no-update (&optional no-questions)
7018   "Quit reading current newsgroup without updating read article info."
7019   (interactive)
7020   (let* ((group gnus-newsgroup-name)
7021          (gnus-group-is-exiting-p t)
7022          (gnus-group-is-exiting-without-update-p t)
7023          (quit-config (gnus-group-quit-config group)))
7024     (when (or no-questions
7025               gnus-expert-user
7026               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7027       (gnus-async-halt-prefetch)
7028       (run-hooks 'gnus-summary-prepare-exit-hook)
7029       (when (gnus-buffer-live-p gnus-article-buffer)
7030         (save-excursion
7031           (set-buffer gnus-article-buffer)
7032           (mm-destroy-parts gnus-article-mime-handles)
7033           ;; Set it to nil for safety reason.
7034           (setq gnus-article-mime-handle-alist nil)
7035           (setq gnus-article-mime-handles nil)))
7036       ;; If we have several article buffers, we kill them at exit.
7037       (unless gnus-single-article-buffer
7038         (gnus-kill-buffer gnus-article-buffer)
7039         (gnus-kill-buffer gnus-original-article-buffer)
7040         (setq gnus-article-current nil))
7041       (if (not gnus-kill-summary-on-exit)
7042           (gnus-deaden-summary)
7043         (gnus-close-group group)
7044         (gnus-summary-clear-local-variables)
7045         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7046           (gnus-summary-clear-local-variables))
7047         (gnus-kill-buffer gnus-summary-buffer))
7048       (unless gnus-single-article-buffer
7049         (setq gnus-article-current nil))
7050       (when gnus-use-trees
7051         (gnus-tree-close group))
7052       (gnus-async-prefetch-remove-group group)
7053       (when (get-buffer gnus-article-buffer)
7054         (bury-buffer gnus-article-buffer))
7055       ;; Return to the group buffer.
7056       (gnus-configure-windows 'group 'force)
7057       ;; Clear the current group name.
7058       (setq gnus-newsgroup-name nil)
7059       (unless (gnus-ephemeral-group-p group)
7060         (gnus-group-update-group group))
7061       (when (equal (gnus-group-group-name) group)
7062         (gnus-group-next-unread-group 1))
7063       (when quit-config
7064         (gnus-handle-ephemeral-exit quit-config)))))
7065
7066 (defun gnus-handle-ephemeral-exit (quit-config)
7067   "Handle movement when leaving an ephemeral group.
7068 The state which existed when entering the ephemeral is reset."
7069   (if (not (buffer-name (car quit-config)))
7070       (gnus-configure-windows 'group 'force)
7071     (set-buffer (car quit-config))
7072     (cond ((eq major-mode 'gnus-summary-mode)
7073            (gnus-set-global-variables))
7074           ((eq major-mode 'gnus-article-mode)
7075            (save-excursion
7076              ;; The `gnus-summary-buffer' variable may point
7077              ;; to the old summary buffer when using a single
7078              ;; article buffer.
7079              (unless (gnus-buffer-live-p gnus-summary-buffer)
7080                (set-buffer gnus-group-buffer))
7081              (set-buffer gnus-summary-buffer)
7082              (gnus-set-global-variables))))
7083     (if (or (eq (cdr quit-config) 'article)
7084             (eq (cdr quit-config) 'pick))
7085         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7086             (gnus-configure-windows 'pick 'force)
7087           (gnus-configure-windows (cdr quit-config) 'force))
7088       (gnus-configure-windows (cdr quit-config) 'force))
7089     (when (eq major-mode 'gnus-summary-mode)
7090       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7091                                                      next-unread-noselect))
7092           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7093                                   'next-noselect)
7094                               (gnus-summary-next-subject 1 nil t))
7095                              ((eq gnus-auto-select-on-ephemeral-exit
7096                                   'next-unread-noselect)
7097                               (gnus-summary-next-subject 1 t t))))
7098             ;; Hide the article buffer which displays the article different
7099             ;; from the one that the cursor points to in the summary buffer.
7100             (gnus-configure-windows 'summary 'force))
7101         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7102                (gnus-summary-next-subject 1))
7103               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7104                (gnus-summary-next-subject 1 t))))
7105       (gnus-summary-recenter)
7106       (gnus-summary-position-point))))
7107
7108 ;;; Dead summaries.
7109
7110 (defvar gnus-dead-summary-mode-map nil)
7111
7112 (unless gnus-dead-summary-mode-map
7113   (setq gnus-dead-summary-mode-map (make-keymap))
7114   (suppress-keymap gnus-dead-summary-mode-map)
7115   (substitute-key-definition
7116    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7117   (dolist (key '("\C-d" "\r" "\177" [delete]))
7118     (define-key gnus-dead-summary-mode-map
7119       key 'gnus-summary-wake-up-the-dead))
7120   (dolist (key '("q" "Q"))
7121     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7122
7123 (defvar gnus-dead-summary-mode nil
7124   "Minor mode for Gnus summary buffers.")
7125
7126 (defun gnus-dead-summary-mode (&optional arg)
7127   "Minor mode for Gnus summary buffers."
7128   (interactive "P")
7129   (when (eq major-mode 'gnus-summary-mode)
7130     (make-local-variable 'gnus-dead-summary-mode)
7131     (setq gnus-dead-summary-mode
7132           (if (null arg) (not gnus-dead-summary-mode)
7133             (> (prefix-numeric-value arg) 0)))
7134     (when gnus-dead-summary-mode
7135       (add-minor-mode
7136        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7137
7138 (defun gnus-deaden-summary ()
7139   "Make the current summary buffer into a dead summary buffer."
7140   ;; Kill any previous dead summary buffer.
7141   (when (and gnus-dead-summary
7142              (buffer-name gnus-dead-summary))
7143     (with-current-buffer gnus-dead-summary
7144       (when gnus-dead-summary-mode
7145         (kill-buffer (current-buffer)))))
7146   ;; Make this the current dead summary.
7147   (setq gnus-dead-summary (current-buffer))
7148   (gnus-dead-summary-mode 1)
7149   (let ((name (buffer-name)))
7150     (when (string-match "Summary" name)
7151       (rename-buffer
7152        (concat (substring name 0 (match-beginning 0)) "Dead "
7153                (substring name (match-beginning 0)))
7154        t)
7155       (bury-buffer))))
7156
7157 (defun gnus-kill-or-deaden-summary (buffer)
7158   "Kill or deaden the summary BUFFER."
7159   (save-excursion
7160     (when (and (buffer-name buffer)
7161                (not gnus-single-article-buffer))
7162       (with-current-buffer buffer
7163         (gnus-kill-buffer gnus-article-buffer)
7164         (gnus-kill-buffer gnus-original-article-buffer)))
7165     (cond
7166      ;; Kill the buffer.
7167      (gnus-kill-summary-on-exit
7168       (when (and gnus-use-trees
7169                  (gnus-buffer-exists-p buffer))
7170         (save-excursion
7171           (set-buffer buffer)
7172           (gnus-tree-close gnus-newsgroup-name)))
7173       (gnus-kill-buffer buffer))
7174      ;; Deaden the buffer.
7175      ((gnus-buffer-exists-p buffer)
7176       (save-excursion
7177         (set-buffer buffer)
7178         (gnus-deaden-summary))))))
7179
7180 (defun gnus-summary-wake-up-the-dead (&rest args)
7181   "Wake up the dead summary buffer."
7182   (interactive)
7183   (gnus-dead-summary-mode -1)
7184   (let ((name (buffer-name)))
7185     (when (string-match "Dead " name)
7186       (rename-buffer
7187        (concat (substring name 0 (match-beginning 0))
7188                (substring name (match-end 0)))
7189        t)))
7190   (gnus-message 3 "This dead summary is now alive again"))
7191
7192 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7193 (defun gnus-summary-fetch-faq (&optional faq-dir)
7194   "Fetch the FAQ for the current group.
7195 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7196 in."
7197   (interactive
7198    (list
7199     (when current-prefix-arg
7200       (completing-read
7201        "FAQ dir: " (and (listp gnus-group-faq-directory)
7202                         (mapcar 'list
7203                                 gnus-group-faq-directory))))))
7204   (let (gnus-faq-buffer)
7205     (when (setq gnus-faq-buffer
7206                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7207       (gnus-configure-windows 'summary-faq))))
7208
7209 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7210 (defun gnus-summary-describe-group (&optional force)
7211   "Describe the current newsgroup."
7212   (interactive "P")
7213   (gnus-group-describe-group force gnus-newsgroup-name))
7214
7215 (defun gnus-summary-describe-briefly ()
7216   "Describe summary mode commands briefly."
7217   (interactive)
7218   (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")))
7219
7220 ;; Walking around group mode buffer from summary mode.
7221
7222 (defun gnus-summary-next-group (&optional no-article target-group backward)
7223   "Exit current newsgroup and then select next unread newsgroup.
7224 If prefix argument NO-ARTICLE is non-nil, no article is selected
7225 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7226 previous group instead."
7227   (interactive "P")
7228   ;; Stop pre-fetching.
7229   (gnus-async-halt-prefetch)
7230   (let ((current-group gnus-newsgroup-name)
7231         (current-buffer (current-buffer))
7232         entered)
7233     ;; First we semi-exit this group to update Xrefs and all variables.
7234     ;; We can't do a real exit, because the window conf must remain
7235     ;; the same in case the user is prompted for info, and we don't
7236     ;; want the window conf to change before that...
7237     (gnus-summary-exit t)
7238     (while (not entered)
7239       ;; Then we find what group we are supposed to enter.
7240       (set-buffer gnus-group-buffer)
7241       (gnus-group-jump-to-group current-group)
7242       (setq target-group
7243             (or target-group
7244                 (if (eq gnus-keep-same-level 'best)
7245                     (gnus-summary-best-group gnus-newsgroup-name)
7246                   (gnus-summary-search-group backward gnus-keep-same-level))))
7247       (if (not target-group)
7248           ;; There are no further groups, so we return to the group
7249           ;; buffer.
7250           (progn
7251             (gnus-message 5 "Returning to the group buffer")
7252             (setq entered t)
7253             (when (gnus-buffer-live-p current-buffer)
7254               (set-buffer current-buffer)
7255               (gnus-summary-exit))
7256             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7257         ;; We try to enter the target group.
7258         (gnus-group-jump-to-group target-group)
7259         (let ((unreads (gnus-group-group-unread)))
7260           (if (and (or (eq t unreads)
7261                        (and unreads (not (zerop unreads))))
7262                    (gnus-summary-read-group
7263                     target-group nil no-article
7264                     (and (buffer-name current-buffer) current-buffer)
7265                     nil backward))
7266               (setq entered t)
7267             (setq current-group target-group
7268                   target-group nil)))))))
7269
7270 (defun gnus-summary-prev-group (&optional no-article)
7271   "Exit current newsgroup and then select previous unread newsgroup.
7272 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7273   (interactive "P")
7274   (gnus-summary-next-group no-article nil t))
7275
7276 ;; Walking around summary lines.
7277
7278 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7279   "Go to the first subject satisfying any non-nil constraint.
7280 If UNREAD is non-nil, the article should be unread.
7281 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7282 If UNSEEN is non-nil, the article should be unseen.
7283 Returns the article selected or nil if there are no matching articles."
7284   (interactive "P")
7285   (cond
7286    ;; Empty summary.
7287    ((null gnus-newsgroup-data)
7288     (gnus-message 3 "No articles in the group")
7289     nil)
7290    ;; Pick the first article.
7291    ((not (or unread undownloaded unseen))
7292     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7293     (gnus-data-number (car gnus-newsgroup-data)))
7294    ;; Find the first unread article.
7295    (t
7296     (let ((data gnus-newsgroup-data))
7297       (while (and data
7298                   (let ((num (gnus-data-number (car data))))
7299                     (or (memq num gnus-newsgroup-unfetched)
7300                         (not (or (and unread
7301                                       (memq num gnus-newsgroup-unreads))
7302                                  (and undownloaded
7303                                       (memq num gnus-newsgroup-undownloaded))
7304                                  (and unseen
7305                                       (memq num gnus-newsgroup-unseen)))))))
7306         (setq data (cdr data)))
7307       (prog1
7308           (if data
7309               (progn
7310                 (goto-char (gnus-data-pos (car data)))
7311                 (gnus-data-number (car data)))
7312             (gnus-message 3 "No more%s articles"
7313                           (let* ((r (when unread " unread"))
7314                                  (d (when undownloaded " undownloaded"))
7315                                  (s (when unseen " unseen"))
7316                                  (l (delq nil (list r d s))))
7317                             (cond ((= 3 (length l))
7318                                    (concat r "," d ", or" s))
7319                                   ((= 2 (length l))
7320                                    (concat (car l) ", or" (cadr l)))
7321                                   ((= 1 (length l))
7322                                    (car l))
7323                                   (t
7324                                    ""))))
7325             nil
7326             )
7327         (gnus-summary-position-point))))))
7328
7329 (defun gnus-summary-next-subject (n &optional unread dont-display)
7330   "Go to next N'th summary line.
7331 If N is negative, go to the previous N'th subject line.
7332 If UNREAD is non-nil, only unread articles are selected.
7333 The difference between N and the actual number of steps taken is
7334 returned."
7335   (interactive "p")
7336   (let ((backward (< n 0))
7337         (n (abs n)))
7338     (while (and (> n 0)
7339                 (if backward
7340                     (gnus-summary-find-prev unread)
7341                   (gnus-summary-find-next unread)))
7342       (unless (zerop (setq n (1- n)))
7343         (gnus-summary-show-thread)))
7344     (when (/= 0 n)
7345       (gnus-message 7 "No more%s articles"
7346                     (if unread " unread" "")))
7347     (unless dont-display
7348       (gnus-summary-recenter)
7349       (gnus-summary-position-point))
7350     n))
7351
7352 (defun gnus-summary-next-unread-subject (n)
7353   "Go to next N'th unread summary line."
7354   (interactive "p")
7355   (gnus-summary-next-subject n t))
7356
7357 (defun gnus-summary-prev-subject (n &optional unread)
7358   "Go to previous N'th summary line.
7359 If optional argument UNREAD is non-nil, only unread article is selected."
7360   (interactive "p")
7361   (gnus-summary-next-subject (- n) unread))
7362
7363 (defun gnus-summary-prev-unread-subject (n)
7364   "Go to previous N'th unread summary line."
7365   (interactive "p")
7366   (gnus-summary-next-subject (- n) t))
7367
7368 (defun gnus-summary-goto-subjects (articles)
7369   "Insert the subject header for ARTICLES in the current buffer."
7370   (save-excursion
7371     (dolist (article articles)
7372       (gnus-summary-goto-subject article t)))
7373   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7374   (gnus-summary-position-point))
7375
7376 (defun gnus-summary-goto-subject (article &optional force silent)
7377   "Go the subject line of ARTICLE.
7378 If FORCE, also allow jumping to articles not currently shown."
7379   (interactive "nArticle number: ")
7380   (unless (numberp article)
7381     (error "Article %s is not a number" article))
7382   (let ((b (point))
7383         (data (gnus-data-find article)))
7384     ;; We read in the article if we have to.
7385     (and (not data)
7386          force
7387          (gnus-summary-insert-subject
7388           article
7389           (if (or (numberp force) (vectorp force)) force)
7390           t)
7391          (setq data (gnus-data-find article)))
7392     (goto-char b)
7393     (if (not data)
7394         (progn
7395           (unless silent
7396             (gnus-message 3 "Can't find article %d" article))
7397           nil)
7398       (let ((pt (gnus-data-pos data)))
7399         (goto-char pt)
7400         (gnus-summary-set-article-display-arrow pt))
7401       (gnus-summary-position-point)
7402       article)))
7403
7404 ;; Walking around summary lines with displaying articles.
7405
7406 (defun gnus-summary-expand-window (&optional arg)
7407   "Make the summary buffer take up the entire Emacs frame.
7408 Given a prefix, will force an `article' buffer configuration."
7409   (interactive "P")
7410   (if arg
7411       (gnus-configure-windows 'article 'force)
7412     (gnus-configure-windows 'summary 'force)))
7413
7414 (defun gnus-summary-display-article (article &optional all-header)
7415   "Display ARTICLE in article buffer."
7416   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7417                (with-current-buffer gnus-article-buffer
7418                  (eq major-mode 'gnus-article-mode)))
7419     (gnus-article-setup-buffer))
7420   (gnus-set-global-variables)
7421   (with-current-buffer gnus-article-buffer
7422     (setq gnus-article-charset gnus-newsgroup-charset)
7423     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7424     (mm-enable-multibyte))
7425   (if (null article)
7426       nil
7427     (prog1
7428         (if gnus-summary-display-article-function
7429             (funcall gnus-summary-display-article-function article all-header)
7430           (gnus-article-prepare article all-header))
7431       (gnus-run-hooks 'gnus-select-article-hook)
7432       (when (and gnus-current-article
7433                  (not (zerop gnus-current-article)))
7434         (gnus-summary-goto-subject gnus-current-article))
7435       (gnus-summary-recenter)
7436       (when (and gnus-use-trees gnus-show-threads)
7437         (gnus-possibly-generate-tree article)
7438         (gnus-highlight-selected-tree article))
7439       ;; Successfully display article.
7440       (gnus-article-set-window-start
7441        (cdr (assq article gnus-newsgroup-bookmarks))))))
7442
7443 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7444   "Select the current article.
7445 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7446 non-nil, the article will be re-fetched even if it already present in
7447 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7448 be displayed."
7449   ;; Make sure we are in the summary buffer to work around bbdb bug.
7450   (unless (eq major-mode 'gnus-summary-mode)
7451     (set-buffer gnus-summary-buffer))
7452   (let ((article (or article (gnus-summary-article-number)))
7453         (all-headers (not (not all-headers))) ;Must be t or nil.
7454         gnus-summary-display-article-function)
7455     (and (not pseudo)
7456          (gnus-summary-article-pseudo-p article)
7457          (error "This is a pseudo-article"))
7458     (save-excursion
7459       (set-buffer gnus-summary-buffer)
7460       (if (or (and gnus-single-article-buffer
7461                    (or (null gnus-current-article)
7462                        (null gnus-article-current)
7463                        (null (get-buffer gnus-article-buffer))
7464                        (not (eq article (cdr gnus-article-current)))
7465                        (not (equal (car gnus-article-current)
7466                                    gnus-newsgroup-name))))
7467               (and (not gnus-single-article-buffer)
7468                    (or (null gnus-current-article)
7469                        (not (eq gnus-current-article article))))
7470               force)
7471           ;; The requested article is different from the current article.
7472           (progn
7473             (gnus-summary-display-article article all-headers)
7474             (when (gnus-buffer-live-p gnus-article-buffer)
7475               (with-current-buffer gnus-article-buffer
7476                 (if (not gnus-article-decoded-p) ;; a local variable
7477                     (mm-disable-multibyte))))
7478             (gnus-article-set-window-start
7479              (cdr (assq article gnus-newsgroup-bookmarks)))
7480             article)
7481         'old))))
7482
7483 (defun gnus-summary-force-verify-and-decrypt ()
7484   "Display buttons for signed/encrypted parts and verify/decrypt them."
7485   (interactive)
7486   (let ((mm-verify-option 'known)
7487         (mm-decrypt-option 'known)
7488         (gnus-article-emulate-mime t)
7489         (gnus-buttonized-mime-types (append (list "multipart/signed"
7490                                                   "multipart/encrypted")
7491                                             gnus-buttonized-mime-types)))
7492     (gnus-summary-select-article nil 'force)))
7493
7494 (defun gnus-summary-set-current-mark (&optional current-mark)
7495   "Obsolete function."
7496   nil)
7497
7498 (defun gnus-summary-next-article (&optional unread subject backward push)
7499   "Select the next article.
7500 If UNREAD, only unread articles are selected.
7501 If SUBJECT, only articles with SUBJECT are selected.
7502 If BACKWARD, the previous article is selected instead of the next."
7503   (interactive "P")
7504   ;; Make sure we are in the summary buffer.
7505   (unless (eq major-mode 'gnus-summary-mode)
7506     (set-buffer gnus-summary-buffer))
7507   (cond
7508    ;; Is there such an article?
7509    ((and (gnus-summary-search-forward unread subject backward)
7510          (or (gnus-summary-display-article (gnus-summary-article-number))
7511              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7512     (gnus-summary-position-point))
7513    ;; If not, we try the first unread, if that is wanted.
7514    ((and subject
7515          gnus-auto-select-same
7516          (gnus-summary-first-unread-article))
7517     (gnus-summary-position-point)
7518     (gnus-message 6 "Wrapped"))
7519    ;; Try to get next/previous article not displayed in this group.
7520    ((and gnus-auto-extend-newsgroup
7521          (not unread) (not subject))
7522     (gnus-summary-goto-article
7523      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7524      nil (count-lines (point-min) (point))))
7525    ;; Go to next/previous group.
7526    (t
7527     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7528       (gnus-summary-jump-to-group gnus-newsgroup-name))
7529     (let ((cmd last-command-char)
7530           (point
7531            (with-current-buffer gnus-group-buffer
7532              (point)))
7533           (group
7534            (if (eq gnus-keep-same-level 'best)
7535                (gnus-summary-best-group gnus-newsgroup-name)
7536              (gnus-summary-search-group backward gnus-keep-same-level))))
7537       ;; For some reason, the group window gets selected.  We change
7538       ;; it back.
7539       (select-window (get-buffer-window (current-buffer)))
7540       ;; Select next unread newsgroup automagically.
7541       (cond
7542        ((or (not gnus-auto-select-next)
7543             (not cmd))
7544         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7545        ((or (eq gnus-auto-select-next 'quietly)
7546             (and (eq gnus-auto-select-next 'slightly-quietly)
7547                  push)
7548             (and (eq gnus-auto-select-next 'almost-quietly)
7549                  (gnus-summary-last-article-p)))
7550         ;; Select quietly.
7551         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7552             (gnus-summary-exit)
7553           (gnus-message 7 "No more%s articles (%s)..."
7554                         (if unread " unread" "")
7555                         (if group (concat "selecting " group)
7556                           "exiting"))
7557           (gnus-summary-next-group nil group backward)))
7558        (t
7559         (when (gnus-key-press-event-p last-input-event)
7560           (gnus-summary-walk-group-buffer
7561            gnus-newsgroup-name cmd unread backward point))))))))
7562
7563 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7564   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7565                       (?\C-p (gnus-group-prev-unread-group 1))))
7566         (cursor-in-echo-area t)
7567         keve key group ended prompt)
7568     (save-excursion
7569       (set-buffer gnus-group-buffer)
7570       (goto-char start)
7571       (setq group
7572             (if (eq gnus-keep-same-level 'best)
7573                 (gnus-summary-best-group gnus-newsgroup-name)
7574               (gnus-summary-search-group backward gnus-keep-same-level))))
7575     (while (not ended)
7576       (setq prompt
7577             (format
7578              "No more%s articles%s " (if unread " unread" "")
7579              (if (and group
7580                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7581                  (format " (Type %s for %s [%s])"
7582                          (single-key-description cmd)
7583                          (gnus-group-decoded-name group)
7584                          (gnus-group-unread group))
7585                (format " (Type %s to exit %s)"
7586                        (single-key-description cmd)
7587                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7588       ;; Confirm auto selection.
7589       (setq key (car (setq keve (gnus-read-event-char prompt)))
7590             ended t)
7591       (cond
7592        ((assq key keystrokes)
7593         (let ((obuf (current-buffer)))
7594           (switch-to-buffer gnus-group-buffer)
7595           (when group
7596             (gnus-group-jump-to-group group))
7597           (eval (cadr (assq key keystrokes)))
7598           (setq group (gnus-group-group-name))
7599           (switch-to-buffer obuf))
7600         (setq ended nil))
7601        ((equal key cmd)
7602         (if (or (not group)
7603                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7604             (gnus-summary-exit)
7605           (gnus-summary-next-group nil group backward)))
7606        (t
7607         (push (cdr keve) unread-command-events))))))
7608
7609 (defun gnus-summary-next-unread-article ()
7610   "Select unread article after current one."
7611   (interactive)
7612   (gnus-summary-next-article
7613    (or (not (eq gnus-summary-goto-unread 'never))
7614        (gnus-summary-last-article-p (gnus-summary-article-number)))
7615    (and gnus-auto-select-same
7616         (gnus-summary-article-subject))))
7617
7618 (defun gnus-summary-prev-article (&optional unread subject)
7619   "Select the article after the current one.
7620 If UNREAD is non-nil, only unread articles are selected."
7621   (interactive "P")
7622   (gnus-summary-next-article unread subject t))
7623
7624 (defun gnus-summary-prev-unread-article ()
7625   "Select unread article before current one."
7626   (interactive)
7627   (gnus-summary-prev-article
7628    (or (not (eq gnus-summary-goto-unread 'never))
7629        (gnus-summary-first-article-p (gnus-summary-article-number)))
7630    (and gnus-auto-select-same
7631         (gnus-summary-article-subject))))
7632
7633 (defun gnus-summary-next-page (&optional lines circular stop)
7634   "Show next page of the selected article.
7635 If at the end of the current article, select the next article.
7636 LINES says how many lines should be scrolled up.
7637
7638 If CIRCULAR is non-nil, go to the start of the article instead of
7639 selecting the next article when reaching the end of the current
7640 article.
7641
7642 If STOP is non-nil, just stop when reaching the end of the message.
7643
7644 Also see the variable `gnus-article-skip-boring'."
7645   (interactive "P")
7646   (setq gnus-summary-buffer (current-buffer))
7647   (gnus-set-global-variables)
7648   (let ((article (gnus-summary-article-number))
7649         (article-window (get-buffer-window gnus-article-buffer t))
7650         endp)
7651     ;; If the buffer is empty, we have no article.
7652     (unless article
7653       (error "No article to select"))
7654     (gnus-configure-windows 'article)
7655     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7656         (if (and (eq gnus-summary-goto-unread 'never)
7657                  (not (gnus-summary-last-article-p article)))
7658             (gnus-summary-next-article)
7659           (gnus-summary-next-unread-article))
7660       (if (or (null gnus-current-article)
7661               (null gnus-article-current)
7662               (/= article (cdr gnus-article-current))
7663               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7664           ;; Selected subject is different from current article's.
7665           (gnus-summary-display-article article)
7666         (when article-window
7667           (gnus-eval-in-buffer-window gnus-article-buffer
7668             (setq endp (or (gnus-article-next-page lines)
7669                            (gnus-article-only-boring-p))))
7670           (when endp
7671             (cond (stop
7672                    (gnus-message 3 "End of message"))
7673                   (circular
7674                    (gnus-summary-beginning-of-article))
7675                   (lines
7676                    (gnus-message 3 "End of message"))
7677                   ((null lines)
7678                    (if (and (eq gnus-summary-goto-unread 'never)
7679                             (not (gnus-summary-last-article-p article)))
7680                        (gnus-summary-next-article)
7681                      (gnus-summary-next-unread-article))))))))
7682     (gnus-summary-recenter)
7683     (gnus-summary-position-point)))
7684
7685 (defun gnus-summary-prev-page (&optional lines move)
7686   "Show previous page of selected article.
7687 Argument LINES specifies lines to be scrolled down.
7688 If MOVE, move to the previous unread article if point is at
7689 the beginning of the buffer."
7690   (interactive "P")
7691   (let ((article (gnus-summary-article-number))
7692         (article-window (get-buffer-window gnus-article-buffer t))
7693         endp)
7694     (gnus-configure-windows 'article)
7695     (if (or (null gnus-current-article)
7696             (null gnus-article-current)
7697             (/= article (cdr gnus-article-current))
7698             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7699         ;; Selected subject is different from current article's.
7700         (gnus-summary-display-article article)
7701       (gnus-summary-recenter)
7702       (when article-window
7703         (gnus-eval-in-buffer-window gnus-article-buffer
7704           (setq endp (gnus-article-prev-page lines)))
7705         (when (and move endp)
7706           (cond (lines
7707                  (gnus-message 3 "Beginning of message"))
7708                 ((null lines)
7709                  (if (and (eq gnus-summary-goto-unread 'never)
7710                           (not (gnus-summary-first-article-p article)))
7711                      (gnus-summary-prev-article)
7712                    (gnus-summary-prev-unread-article))))))))
7713   (gnus-summary-position-point))
7714
7715 (defun gnus-summary-prev-page-or-article (&optional lines)
7716   "Show previous page of selected article.
7717 Argument LINES specifies lines to be scrolled down.
7718 If at the beginning of the article, go to the next article."
7719   (interactive "P")
7720   (gnus-summary-prev-page lines t))
7721
7722 (defun gnus-summary-scroll-up (lines)
7723   "Scroll up (or down) one line current article.
7724 Argument LINES specifies lines to be scrolled up (or down if negative)."
7725   (interactive "p")
7726   (gnus-configure-windows 'article)
7727   (gnus-summary-show-thread)
7728   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7729     (gnus-eval-in-buffer-window gnus-article-buffer
7730       (cond ((> lines 0)
7731              (when (gnus-article-next-page lines)
7732                (gnus-message 3 "End of message")))
7733             ((< lines 0)
7734              (gnus-article-prev-page (- lines))))))
7735   (gnus-summary-recenter)
7736   (gnus-summary-position-point))
7737
7738 (defun gnus-summary-scroll-down (lines)
7739   "Scroll down (or up) one line current article.
7740 Argument LINES specifies lines to be scrolled down (or up if negative)."
7741   (interactive "p")
7742   (gnus-summary-scroll-up (- lines)))
7743
7744 (defun gnus-summary-next-same-subject ()
7745   "Select next article which has the same subject as current one."
7746   (interactive)
7747   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7748
7749 (defun gnus-summary-prev-same-subject ()
7750   "Select previous article which has the same subject as current one."
7751   (interactive)
7752   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7753
7754 (defun gnus-summary-next-unread-same-subject ()
7755   "Select next unread article which has the same subject as current one."
7756   (interactive)
7757   (gnus-summary-next-article t (gnus-summary-article-subject)))
7758
7759 (defun gnus-summary-prev-unread-same-subject ()
7760   "Select previous unread article which has the same subject as current one."
7761   (interactive)
7762   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7763
7764 (defun gnus-summary-first-unread-article ()
7765   "Select the first unread article.
7766 Return nil if there are no unread articles."
7767   (interactive)
7768   (prog1
7769       (when (gnus-summary-first-subject t)
7770         (gnus-summary-show-thread)
7771         (gnus-summary-first-subject t)
7772         (gnus-summary-display-article (gnus-summary-article-number)))
7773     (gnus-summary-position-point)))
7774
7775 (defun gnus-summary-first-unread-subject ()
7776   "Place the point on the subject line of the first unread article.
7777 Return nil if there are no unread articles."
7778   (interactive)
7779   (prog1
7780       (when (gnus-summary-first-subject t)
7781         (gnus-summary-show-thread)
7782         (gnus-summary-first-subject t))
7783     (gnus-summary-position-point)))
7784
7785 (defun gnus-summary-first-unseen-subject ()
7786   "Place the point on the subject line of the first unseen article.
7787 Return nil if there are no unseen articles."
7788   (interactive)
7789   (prog1
7790       (when (gnus-summary-first-subject nil nil t)
7791         (gnus-summary-show-thread)
7792         (gnus-summary-first-subject nil nil t))
7793     (gnus-summary-position-point)))
7794
7795 (defun gnus-summary-first-unseen-or-unread-subject ()
7796   "Place the point on the subject line of the first unseen article or,
7797 if all article have been seen, on the subject line of the first unread
7798 article."
7799   (interactive)
7800   (prog1
7801       (unless (when (gnus-summary-first-subject nil nil t)
7802                 (gnus-summary-show-thread)
7803                 (gnus-summary-first-subject nil nil t))
7804         (when (gnus-summary-first-subject t)
7805           (gnus-summary-show-thread)
7806           (gnus-summary-first-subject t)))
7807     (gnus-summary-position-point)))
7808
7809 (defun gnus-summary-first-article ()
7810   "Select the first article.
7811 Return nil if there are no articles."
7812   (interactive)
7813   (prog1
7814       (when (gnus-summary-first-subject)
7815         (gnus-summary-show-thread)
7816         (gnus-summary-first-subject)
7817         (gnus-summary-display-article (gnus-summary-article-number)))
7818     (gnus-summary-position-point)))
7819
7820 (defun gnus-summary-best-unread-article (&optional arg)
7821   "Select the unread article with the highest score.
7822 If given a prefix argument, select the next unread article that has a
7823 score higher than the default score."
7824   (interactive "P")
7825   (let ((article (if arg
7826                      (gnus-summary-better-unread-subject)
7827                    (gnus-summary-best-unread-subject))))
7828     (if article
7829         (gnus-summary-goto-article article)
7830       (error "No unread articles"))))
7831
7832 (defun gnus-summary-best-unread-subject ()
7833   "Select the unread subject with the highest score."
7834   (interactive)
7835   (let ((best -1000000)
7836         (data gnus-newsgroup-data)
7837         article score)
7838     (while data
7839       (and (gnus-data-unread-p (car data))
7840            (> (setq score
7841                     (gnus-summary-article-score (gnus-data-number (car data))))
7842               best)
7843            (setq best score
7844                  article (gnus-data-number (car data))))
7845       (setq data (cdr data)))
7846     (when article
7847       (gnus-summary-goto-subject article))
7848     (gnus-summary-position-point)
7849     article))
7850
7851 (defun gnus-summary-better-unread-subject ()
7852   "Select the first unread subject that has a score over the default score."
7853   (interactive)
7854   (let ((data gnus-newsgroup-data)
7855         article score)
7856     (while (and (setq article (gnus-data-number (car data)))
7857                 (or (gnus-data-read-p (car data))
7858                     (not (> (gnus-summary-article-score article)
7859                             gnus-summary-default-score))))
7860       (setq data (cdr data)))
7861     (when article
7862       (gnus-summary-goto-subject article))
7863     (gnus-summary-position-point)
7864     article))
7865
7866 (defun gnus-summary-last-subject ()
7867   "Go to the last displayed subject line in the group."
7868   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7869     (when article
7870       (gnus-summary-goto-subject article))))
7871
7872 (defun gnus-summary-goto-article (article &optional all-headers force)
7873   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7874 If ALL-HEADERS is non-nil, no header lines are hidden.
7875 If FORCE, go to the article even if it isn't displayed.  If FORCE
7876 is a number, it is the line the article is to be displayed on."
7877   (interactive
7878    (list
7879     (completing-read
7880      "Article number or Message-ID: "
7881      (mapcar (lambda (number) (list (int-to-string number)))
7882              gnus-newsgroup-limit))
7883     current-prefix-arg
7884     t))
7885   (prog1
7886       (if (and (stringp article)
7887                (string-match "@\\|%40" article))
7888           (gnus-summary-refer-article article)
7889         (when (stringp article)
7890           (setq article (string-to-number article)))
7891         (if (gnus-summary-goto-subject article force)
7892             (gnus-summary-display-article article all-headers)
7893           (gnus-message 4 "Couldn't go to article %s" article) nil))
7894     (gnus-summary-position-point)))
7895
7896 (defun gnus-summary-goto-last-article ()
7897   "Go to the previously read article."
7898   (interactive)
7899   (prog1
7900       (when gnus-last-article
7901         (gnus-summary-goto-article gnus-last-article nil t))
7902     (gnus-summary-position-point)))
7903
7904 (defun gnus-summary-pop-article (number)
7905   "Pop one article off the history and go to the previous.
7906 NUMBER articles will be popped off."
7907   (interactive "p")
7908   (let (to)
7909     (setq gnus-newsgroup-history
7910           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7911     (if to
7912         (gnus-summary-goto-article (car to) nil t)
7913       (error "Article history empty")))
7914   (gnus-summary-position-point))
7915
7916 ;; Summary commands and functions for limiting the summary buffer.
7917
7918 (defun gnus-summary-limit-to-articles (n)
7919   "Limit the summary buffer to the next N articles.
7920 If not given a prefix, use the process marked articles instead."
7921   (interactive "P")
7922   (prog1
7923       (let ((articles (gnus-summary-work-articles n)))
7924         (setq gnus-newsgroup-processable nil)
7925         (gnus-summary-limit articles))
7926     (gnus-summary-position-point)))
7927
7928 (defun gnus-summary-pop-limit (&optional total)
7929   "Restore the previous limit.
7930 If given a prefix, remove all limits."
7931   (interactive "P")
7932   (when total
7933     (setq gnus-newsgroup-limits
7934           (list (mapcar (lambda (h) (mail-header-number h))
7935                         gnus-newsgroup-headers))))
7936   (unless gnus-newsgroup-limits
7937     (error "No limit to pop"))
7938   (prog1
7939       (gnus-summary-limit nil 'pop)
7940     (gnus-summary-position-point)))
7941
7942 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7943   "Limit the summary buffer to articles that have subjects that match a regexp.
7944 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7945   (interactive
7946    (list (read-string (if current-prefix-arg
7947                           "Exclude subject (regexp): "
7948                         "Limit to subject (regexp): "))
7949          nil current-prefix-arg))
7950   (unless header
7951     (setq header "subject"))
7952   (when (not (equal "" subject))
7953     (prog1
7954         (let ((articles (gnus-summary-find-matching
7955                          (or header "subject") subject 'all nil nil
7956                          not-matching)))
7957           (unless articles
7958             (error "Found no matches for \"%s\"" subject))
7959           (gnus-summary-limit articles))
7960       (gnus-summary-position-point))))
7961
7962 (defun gnus-summary-limit-to-author (from &optional not-matching)
7963   "Limit the summary buffer to articles that have authors that match a regexp.
7964 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7965   (interactive
7966    (list (read-string (if current-prefix-arg
7967                           "Exclude author (regexp): "
7968                         "Limit to author (regexp): "))
7969          current-prefix-arg))
7970   (gnus-summary-limit-to-subject from "from" not-matching))
7971
7972 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7973   "Limit the summary buffer to articles with the given RECIPIENT.
7974
7975 If NOT-MATCHING, exclude RECIPIENT.
7976
7977 To and Cc headers are checked.  You need to include them in
7978 `nnmail-extra-headers'."
7979   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7980   (interactive
7981    (list (read-string (format "%s recipient (regexp): "
7982                               (if current-prefix-arg "Exclude" "Limit to")))
7983          current-prefix-arg))
7984   (when (not (equal "" recipient))
7985     (prog1 (let* ((to
7986                    (if (memq 'To nnmail-extra-headers)
7987                        (gnus-summary-find-matching
7988                         (cons 'extra 'To) recipient 'all nil nil
7989                         not-matching)
7990                      (gnus-message
7991                       1 "`To' isn't present in `nnmail-extra-headers'")
7992                      (sit-for 1)
7993                      nil))
7994                   (cc
7995                    (if (memq 'Cc nnmail-extra-headers)
7996                        (gnus-summary-find-matching
7997                         (cons 'extra 'Cc) recipient 'all nil nil
7998                         not-matching)
7999                      (gnus-message
8000                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8001                      (sit-for 1)
8002                      nil))
8003                   (articles
8004                    (if not-matching
8005                        ;; We need the numbers that are in both lists:
8006                        (mapcar (lambda (a)
8007                                  (and (memq a to) a))
8008                                cc)
8009                      (nconc to cc))))
8010              (unless articles
8011                (error "Found no matches for \"%s\"" recipient))
8012              (gnus-summary-limit articles))
8013       (gnus-summary-position-point))))
8014
8015 (defun gnus-summary-limit-to-address (address &optional not-matching)
8016   "Limit the summary buffer to articles with the given ADDRESS.
8017
8018 If NOT-MATCHING, exclude ADDRESS.
8019
8020 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8021 in `nnmail-extra-headers'."
8022   (interactive
8023    (list (read-string (format "%s address (regexp): "
8024                               (if current-prefix-arg "Exclude" "Limit to")))
8025          current-prefix-arg))
8026   (when (not (equal "" address))
8027     (prog1 (let* ((to
8028                    (if (memq 'To nnmail-extra-headers)
8029                        (gnus-summary-find-matching
8030                         (cons 'extra 'To) address 'all nil nil
8031                         not-matching)
8032                      (gnus-message
8033                       1 "`To' isn't present in `nnmail-extra-headers'")
8034                      (sit-for 1)
8035                      t))
8036                   (cc
8037                    (if (memq 'Cc nnmail-extra-headers)
8038                        (gnus-summary-find-matching
8039                         (cons 'extra 'Cc) address 'all nil nil
8040                         not-matching)
8041                      (gnus-message
8042                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8043                      (sit-for 1)
8044                      t))
8045                   (from
8046                    (gnus-summary-find-matching "from" address
8047                                                'all nil nil not-matching))
8048                   (articles
8049                    (if not-matching
8050                        ;; We need the numbers that are in all lists:
8051                        (if (eq cc t)
8052                            (if (eq to t)
8053                                from
8054                              (mapcar (lambda (a) (car (memq a from))) to))
8055                          (if (eq to t)
8056                              (mapcar (lambda (a) (car (memq a from))) cc)
8057                            (mapcar (lambda (a) (car (memq a from)))
8058                                    (mapcar (lambda (a) (car (memq a to)))
8059                                            cc))))
8060                      (nconc (if (eq to t) nil to)
8061                             (if (eq cc t) nil cc)
8062                             from))))
8063              (unless articles
8064                (error "Found no matches for \"%s\"" address))
8065              (gnus-summary-limit articles))
8066       (gnus-summary-position-point))))
8067
8068 (defun gnus-summary-limit-strange-charsets-predicate (header)
8069   (let ((string (concat (mail-header-subject header)
8070                         (mail-header-from header)))
8071         charset found)
8072     (dotimes (i (1- (length string)))
8073       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8074       (when (string-match "unicode\\|big\\|japanese" charset)
8075         (setq found t)))
8076     found))
8077
8078 (defun gnus-summary-limit-to-predicate (predicate)
8079   "Limit to articles where PREDICATE returns non-nil.
8080 PREDICATE will be called with the header structures of the
8081 articles."
8082   (let ((articles nil)
8083         (case-fold-search t))
8084     (dolist (header gnus-newsgroup-headers)
8085       (when (funcall predicate header)
8086         (push (mail-header-number header) articles)))
8087     (gnus-summary-limit (nreverse articles))))
8088
8089 (defun gnus-summary-limit-to-age (age &optional younger-p)
8090   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8091 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8092 articles that are younger than AGE days."
8093   (interactive
8094    (let ((younger current-prefix-arg)
8095          (days-got nil)
8096          days)
8097      (while (not days-got)
8098        (setq days (if younger
8099                       (read-string "Limit to articles younger than (in days, older when negative): ")
8100                     (read-string
8101                      "Limit to articles older than (in days, younger when negative): ")))
8102        (when (> (length days) 0)
8103          (setq days (read days)))
8104        (if (numberp days)
8105            (progn
8106              (setq days-got t)
8107              (when (< days 0)
8108                (setq younger (not younger))
8109                (setq days (* days -1))))
8110          (message "Please enter a number.")
8111          (sleep-for 1)))
8112      (list days younger)))
8113   (prog1
8114       (let ((data gnus-newsgroup-data)
8115             (cutoff (days-to-time age))
8116             articles d date is-younger)
8117         (while (setq d (pop data))
8118           (when (and (vectorp (gnus-data-header d))
8119                      (setq date (mail-header-date (gnus-data-header d))))
8120             (setq is-younger (time-less-p
8121                               (time-since (condition-case ()
8122                                               (date-to-time date)
8123                                             (error '(0 0))))
8124                               cutoff))
8125             (when (if younger-p
8126                       is-younger
8127                     (not is-younger))
8128               (push (gnus-data-number d) articles))))
8129         (gnus-summary-limit (nreverse articles)))
8130     (gnus-summary-position-point)))
8131
8132 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8133   "Limit the summary buffer to articles that match an 'extra' header."
8134   (interactive
8135    (let ((header
8136           (intern
8137            (gnus-completing-read-with-default
8138             (symbol-name (car gnus-extra-headers))
8139             (if current-prefix-arg
8140                 "Exclude extra header"
8141               "Limit extra header")
8142             (mapcar (lambda (x)
8143                       (cons (symbol-name x) x))
8144                     gnus-extra-headers)
8145             nil
8146             t))))
8147      (list header
8148            (read-string (format "%s header %s (regexp): "
8149                                 (if current-prefix-arg "Exclude" "Limit to")
8150                                 header))
8151            current-prefix-arg)))
8152   (when (not (equal "" regexp))
8153     (prog1
8154         (let ((articles (gnus-summary-find-matching
8155                          (cons 'extra header) regexp 'all nil nil
8156                          not-matching)))
8157           (unless articles
8158             (error "Found no matches for \"%s\"" regexp))
8159           (gnus-summary-limit articles))
8160       (gnus-summary-position-point))))
8161
8162 (defun gnus-summary-limit-to-display-predicate ()
8163   "Limit the summary buffer to the predicated in the `display' group parameter."
8164   (interactive)
8165   (unless gnus-newsgroup-display
8166     (error "There is no `display' group parameter"))
8167   (let (articles)
8168     (dolist (number gnus-newsgroup-articles)
8169       (when (funcall gnus-newsgroup-display)
8170         (push number articles)))
8171     (gnus-summary-limit articles))
8172   (gnus-summary-position-point))
8173
8174 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8175 (make-obsolete
8176  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8177
8178 (defun gnus-summary-limit-to-unread (&optional all)
8179   "Limit the summary buffer to articles that are not marked as read.
8180 If ALL is non-nil, limit strictly to unread articles."
8181   (interactive "P")
8182   (if all
8183       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8184     (gnus-summary-limit-to-marks
8185      ;; Concat all the marks that say that an article is read and have
8186      ;; those removed.
8187      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8188            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8189            gnus-low-score-mark gnus-expirable-mark
8190            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8191            gnus-duplicate-mark gnus-souped-mark)
8192      'reverse)))
8193
8194 (defun gnus-summary-limit-to-headers (match &optional reverse)
8195   "Limit the summary buffer to articles that have headers that match MATCH.
8196 If REVERSE (the prefix), limit to articles that don't match."
8197   (interactive "sMatch headers (regexp): \nP")
8198   (gnus-summary-limit-to-bodies match reverse t))
8199
8200 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8201   "Limit the summary buffer to articles that have bodies that match MATCH.
8202 If REVERSE (the prefix), limit to articles that don't match."
8203   (interactive "sMatch body (regexp): \nP")
8204   (let ((articles nil)
8205         (gnus-select-article-hook nil)  ;Disable hook.
8206         (gnus-article-prepare-hook nil)
8207         (gnus-use-article-prefetch nil)
8208         (gnus-keep-backlog nil)
8209         (gnus-break-pages nil)
8210         (gnus-summary-display-arrow nil)
8211         (gnus-updated-mode-lines nil)
8212         (gnus-auto-center-summary nil)
8213         (gnus-display-mime-function nil))
8214     (dolist (data gnus-newsgroup-data)
8215       (let (gnus-mark-article-hook)
8216         (gnus-summary-select-article t t nil (gnus-data-number data)))
8217       (save-excursion
8218         (set-buffer gnus-article-buffer)
8219         (article-goto-body)
8220         (let* ((case-fold-search t)
8221                (found (if headersp
8222                           (re-search-backward match nil t)
8223                         (re-search-forward match nil t))))
8224           (when (or (and found
8225                          (not reverse))
8226                     (and (not found)
8227                          reverse))
8228             (push (gnus-data-number data) articles)))))
8229     (if (not articles)
8230         (message "No messages matched")
8231       (gnus-summary-limit articles)))
8232   (gnus-summary-position-point))
8233
8234 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8235   "Limit the summary buffer to articles that aren't part on any thread.
8236 If THREADSP (the prefix), limit to articles that are in threads."
8237   (interactive "P")
8238   (let ((articles nil)
8239         thread-articles
8240         threads)
8241     (dolist (thread gnus-newsgroup-threads)
8242       (if (stringp (car thread))
8243           (dolist (thread (cdr thread))
8244             (push thread threads))
8245         (push thread threads)))
8246     (dolist (thread threads)
8247       (setq thread-articles (gnus-articles-in-thread thread))
8248       (when (or (and threadsp
8249                      (> (length thread-articles) 1))
8250                 (and (not threadsp)
8251                      (= (length thread-articles) 1)))
8252         (setq articles (nconc thread-articles articles))))
8253     (if (not articles)
8254         (message "No messages matched")
8255       (gnus-summary-limit articles))
8256     (gnus-summary-position-point)))
8257
8258 (defun gnus-summary-limit-to-replied (&optional unreplied)
8259   "Limit the summary buffer to replied articles.
8260 If UNREPLIED (the prefix), limit to unreplied articles."
8261   (interactive "P")
8262   (if unreplied
8263       (gnus-summary-limit
8264        (gnus-set-difference gnus-newsgroup-articles
8265         gnus-newsgroup-replied))
8266     (gnus-summary-limit gnus-newsgroup-replied))
8267   (gnus-summary-position-point))
8268
8269 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8270 (make-obsolete 'gnus-summary-delete-marked-with
8271                'gnus-summary-limit-exclude-marks)
8272
8273 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8274   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8275 If REVERSE, limit the summary buffer to articles that are marked
8276 with MARKS.  MARKS can either be a string of marks or a list of marks.
8277 Returns how many articles were removed."
8278   (interactive "sMarks: ")
8279   (gnus-summary-limit-to-marks marks t))
8280
8281 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8282   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8283 If REVERSE (the prefix), limit the summary buffer to articles that are
8284 not marked with MARKS.  MARKS can either be a string of marks or a
8285 list of marks.
8286 Returns how many articles were removed."
8287   (interactive "sMarks: \nP")
8288   (prog1
8289       (let ((data gnus-newsgroup-data)
8290             (marks (if (listp marks) marks
8291                      (append marks nil))) ; Transform to list.
8292             articles)
8293         (while data
8294           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8295                   (memq (gnus-data-mark (car data)) marks))
8296             (push (gnus-data-number (car data)) articles))
8297           (setq data (cdr data)))
8298         (gnus-summary-limit articles))
8299     (gnus-summary-position-point)))
8300
8301 (defun gnus-summary-limit-to-score (score)
8302   "Limit to articles with score at or above SCORE."
8303   (interactive "NLimit to articles with score of at least: ")
8304   (let ((data gnus-newsgroup-data)
8305         articles)
8306     (while data
8307       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8308                 score)
8309         (push (gnus-data-number (car data)) articles))
8310       (setq data (cdr data)))
8311     (prog1
8312         (gnus-summary-limit articles)
8313       (gnus-summary-position-point))))
8314
8315 (defun gnus-summary-limit-to-unseen ()
8316   "Limit to unseen articles."
8317   (interactive)
8318   (prog1
8319       (gnus-summary-limit gnus-newsgroup-unseen)
8320     (gnus-summary-position-point)))
8321
8322 (defun gnus-summary-limit-include-thread (id)
8323   "Display all the hidden articles that is in the thread with ID in it.
8324 When called interactively, ID is the Message-ID of the current
8325 article."
8326   (interactive (list (mail-header-id (gnus-summary-article-header))))
8327   (let ((articles (gnus-articles-in-thread
8328                    (gnus-id-to-thread (gnus-root-id id)))))
8329     (prog1
8330         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8331       (gnus-summary-limit-include-matching-articles
8332        "subject"
8333        (regexp-quote (gnus-simplify-subject-re
8334                       (mail-header-subject (gnus-id-to-header id)))))
8335       (gnus-summary-position-point))))
8336
8337 (defun gnus-summary-limit-include-matching-articles (header regexp)
8338   "Display all the hidden articles that have HEADERs that match REGEXP."
8339   (interactive (list (read-string "Match on header: ")
8340                      (read-string "Regexp: ")))
8341   (let ((articles (gnus-find-matching-articles header regexp)))
8342     (prog1
8343         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8344       (gnus-summary-position-point))))
8345
8346 (defun gnus-summary-insert-dormant-articles ()
8347   "Insert all the dormant articles for this group into the current buffer."
8348   (interactive)
8349   (let ((gnus-verbose (max 6 gnus-verbose)))
8350     (if (not gnus-newsgroup-dormant)
8351         (gnus-message 3 "No dormant articles for this group")
8352       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8353
8354 (defun gnus-summary-insert-ticked-articles ()
8355   "Insert ticked articles for this group into the current buffer."
8356   (interactive)
8357   (let ((gnus-verbose (max 6 gnus-verbose)))
8358     (if (not gnus-newsgroup-marked)
8359         (gnus-message 3 "No ticked articles for this group")
8360       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8361
8362 (defun gnus-summary-limit-include-dormant ()
8363   "Display all the hidden articles that are marked as dormant.
8364 Note that this command only works on a subset of the articles currently
8365 fetched for this group."
8366   (interactive)
8367   (unless gnus-newsgroup-dormant
8368     (error "There are no dormant articles in this group"))
8369   (prog1
8370       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8371     (gnus-summary-position-point)))
8372
8373 (defun gnus-summary-limit-exclude-dormant ()
8374   "Hide all dormant articles."
8375   (interactive)
8376   (prog1
8377       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8378     (gnus-summary-position-point)))
8379
8380 (defun gnus-summary-limit-exclude-childless-dormant ()
8381   "Hide all dormant articles that have no children."
8382   (interactive)
8383   (let ((data (gnus-data-list t))
8384         articles d children)
8385     ;; Find all articles that are either not dormant or have
8386     ;; children.
8387     (while (setq d (pop data))
8388       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8389                 (and (setq children
8390                            (gnus-article-children (gnus-data-number d)))
8391                      (let (found)
8392                        (while children
8393                          (when (memq (car children) articles)
8394                            (setq children nil
8395                                  found t))
8396                          (pop children))
8397                        found)))
8398         (push (gnus-data-number d) articles)))
8399     ;; Do the limiting.
8400     (prog1
8401         (gnus-summary-limit articles)
8402       (gnus-summary-position-point))))
8403
8404 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8405   "Mark all unread excluded articles as read.
8406 If ALL, mark even excluded ticked and dormants as read."
8407   (interactive "P")
8408   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8409   (let ((articles (gnus-sorted-ndifference
8410                    (sort
8411                     (mapcar (lambda (h) (mail-header-number h))
8412                             gnus-newsgroup-headers)
8413                     '<)
8414                    gnus-newsgroup-limit))
8415         article)
8416     (setq gnus-newsgroup-unreads
8417           (gnus-sorted-intersection gnus-newsgroup-unreads
8418                                     gnus-newsgroup-limit))
8419     (if all
8420         (setq gnus-newsgroup-dormant nil
8421               gnus-newsgroup-marked nil
8422               gnus-newsgroup-reads
8423               (nconc
8424                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8425                gnus-newsgroup-reads))
8426       (while (setq article (pop articles))
8427         (unless (or (memq article gnus-newsgroup-dormant)
8428                     (memq article gnus-newsgroup-marked))
8429           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8430
8431 (defun gnus-summary-limit (articles &optional pop)
8432   (if pop
8433       ;; We pop the previous limit off the stack and use that.
8434       (setq articles (car gnus-newsgroup-limits)
8435             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8436     ;; We use the new limit, so we push the old limit on the stack.
8437     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8438   ;; Set the limit.
8439   (setq gnus-newsgroup-limit articles)
8440   (let ((total (length gnus-newsgroup-data))
8441         (data (gnus-data-find-list (gnus-summary-article-number)))
8442         (gnus-summary-mark-below nil)   ; Inhibit this.
8443         found)
8444     ;; This will do all the work of generating the new summary buffer
8445     ;; according to the new limit.
8446     (gnus-summary-prepare)
8447     ;; Hide any threads, possibly.
8448     (gnus-summary-maybe-hide-threads)
8449     ;; Try to return to the article you were at, or one in the
8450     ;; neighborhood.
8451     (when data
8452       ;; We try to find some article after the current one.
8453       (while data
8454         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8455           (setq data nil
8456                 found t))
8457         (setq data (cdr data))))
8458     (unless found
8459       ;; If there is no data, that means that we were after the last
8460       ;; article.  The same goes when we can't find any articles
8461       ;; after the current one.
8462       (goto-char (point-max))
8463       (gnus-summary-find-prev))
8464     (gnus-set-mode-line 'summary)
8465     ;; We return how many articles were removed from the summary
8466     ;; buffer as a result of the new limit.
8467     (- total (length gnus-newsgroup-data))))
8468
8469 (defsubst gnus-invisible-cut-children (threads)
8470   (let ((num 0))
8471     (while threads
8472       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8473         (incf num))
8474       (pop threads))
8475     (< num 2)))
8476
8477 (defsubst gnus-cut-thread (thread)
8478   "Go forwards in the thread until we find an article that we want to display."
8479   (when (or (eq gnus-fetch-old-headers 'some)
8480             (eq gnus-fetch-old-headers 'invisible)
8481             (numberp gnus-fetch-old-headers)
8482             (eq gnus-build-sparse-threads 'some)
8483             (eq gnus-build-sparse-threads 'more))
8484     ;; Deal with old-fetched headers and sparse threads.
8485     (while (and
8486             thread
8487             (or
8488              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8489              (gnus-summary-article-ancient-p
8490               (mail-header-number (car thread))))
8491             (if (or (<= (length (cdr thread)) 1)
8492                     (eq gnus-fetch-old-headers 'invisible))
8493                 (setq gnus-newsgroup-limit
8494                       (delq (mail-header-number (car thread))
8495                             gnus-newsgroup-limit)
8496                       thread (cadr thread))
8497               (when (gnus-invisible-cut-children (cdr thread))
8498                 (let ((th (cdr thread)))
8499                   (while th
8500                     (if (memq (mail-header-number (caar th))
8501                               gnus-newsgroup-limit)
8502                         (setq thread (car th)
8503                               th nil)
8504                       (setq th (cdr th))))))))))
8505   thread)
8506
8507 (defun gnus-cut-threads (threads)
8508   "Cut off all uninteresting articles from the beginning of THREADS."
8509   (when (or (eq gnus-fetch-old-headers 'some)
8510             (eq gnus-fetch-old-headers 'invisible)
8511             (numberp gnus-fetch-old-headers)
8512             (eq gnus-build-sparse-threads 'some)
8513             (eq gnus-build-sparse-threads 'more))
8514     (let ((th threads))
8515       (while th
8516         (setcar th (gnus-cut-thread (car th)))
8517         (setq th (cdr th)))))
8518   ;; Remove nixed out threads.
8519   (delq nil threads))
8520
8521 (defun gnus-summary-initial-limit (&optional show-if-empty)
8522   "Figure out what the initial limit is supposed to be on group entry.
8523 This entails weeding out unwanted dormants, low-scored articles,
8524 fetch-old-headers verbiage, and so on."
8525   ;; Most groups have nothing to remove.
8526   (if (or gnus-inhibit-limiting
8527           (and (null gnus-newsgroup-dormant)
8528                (eq gnus-newsgroup-display 'gnus-not-ignore)
8529                (not (eq gnus-fetch-old-headers 'some))
8530                (not (numberp gnus-fetch-old-headers))
8531                (not (eq gnus-fetch-old-headers 'invisible))
8532                (null gnus-summary-expunge-below)
8533                (not (eq gnus-build-sparse-threads 'some))
8534                (not (eq gnus-build-sparse-threads 'more))
8535                (null gnus-thread-expunge-below)
8536                (not gnus-use-nocem)))
8537       ()                                ; Do nothing.
8538     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8539     (setq gnus-newsgroup-limit nil)
8540     (mapatoms
8541      (lambda (node)
8542        (unless (car (symbol-value node))
8543          ;; These threads have no parents -- they are roots.
8544          (let ((nodes (cdr (symbol-value node)))
8545                thread)
8546            (while nodes
8547              (if (and gnus-thread-expunge-below
8548                       (< (gnus-thread-total-score (car nodes))
8549                          gnus-thread-expunge-below))
8550                  (gnus-expunge-thread (pop nodes))
8551                (setq thread (pop nodes))
8552                (gnus-summary-limit-children thread))))))
8553      gnus-newsgroup-dependencies)
8554     ;; If this limitation resulted in an empty group, we might
8555     ;; pop the previous limit and use it instead.
8556     (when (and (not gnus-newsgroup-limit)
8557                show-if-empty)
8558       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8559     gnus-newsgroup-limit))
8560
8561 (defun gnus-summary-limit-children (thread)
8562   "Return 1 if this subthread is visible and 0 if it is not."
8563   ;; First we get the number of visible children to this thread.  This
8564   ;; is done by recursing down the thread using this function, so this
8565   ;; will really go down to a leaf article first, before slowly
8566   ;; working its way up towards the root.
8567   (when thread
8568     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8569            (children
8570            (if (cdr thread)
8571                (apply '+ (mapcar 'gnus-summary-limit-children
8572                                  (cdr thread)))
8573              0))
8574           (number (mail-header-number (car thread)))
8575           score)
8576       (if (and
8577            (not (memq number gnus-newsgroup-marked))
8578            (or
8579             ;; If this article is dormant and has absolutely no visible
8580             ;; children, then this article isn't visible.
8581             (and (memq number gnus-newsgroup-dormant)
8582                  (zerop children))
8583             ;; If this is "fetch-old-headered" and there is no
8584             ;; visible children, then we don't want this article.
8585             (and (or (eq gnus-fetch-old-headers 'some)
8586                      (numberp gnus-fetch-old-headers))
8587                  (gnus-summary-article-ancient-p number)
8588                  (zerop children))
8589             ;; If this is "fetch-old-headered" and `invisible', then
8590             ;; we don't want this article.
8591             (and (eq gnus-fetch-old-headers 'invisible)
8592                  (gnus-summary-article-ancient-p number))
8593             ;; If this is a sparsely inserted article with no children,
8594             ;; we don't want it.
8595             (and (eq gnus-build-sparse-threads 'some)
8596                  (gnus-summary-article-sparse-p number)
8597                  (zerop children))
8598             ;; If we use expunging, and this article is really
8599             ;; low-scored, then we don't want this article.
8600             (when (and gnus-summary-expunge-below
8601                        (< (setq score
8602                                 (or (cdr (assq number gnus-newsgroup-scored))
8603                                     gnus-summary-default-score))
8604                           gnus-summary-expunge-below))
8605               ;; We increase the expunge-tally here, but that has
8606               ;; nothing to do with the limits, really.
8607               (incf gnus-newsgroup-expunged-tally)
8608               ;; We also mark as read here, if that's wanted.
8609               (when (and gnus-summary-mark-below
8610                          (< score gnus-summary-mark-below))
8611                 (setq gnus-newsgroup-unreads
8612                       (delq number gnus-newsgroup-unreads))
8613                 (if gnus-newsgroup-auto-expire
8614                     (push number gnus-newsgroup-expirable)
8615                   (push (cons number gnus-low-score-mark)
8616                         gnus-newsgroup-reads)))
8617               t)
8618             ;; Do the `display' group parameter.
8619             (and gnus-newsgroup-display
8620                  (not (funcall gnus-newsgroup-display)))
8621             ;; Check NoCeM things.
8622             (when (and gnus-use-nocem
8623                        (gnus-nocem-unwanted-article-p
8624                         (mail-header-id (car thread))))
8625               (setq gnus-newsgroup-unreads
8626                     (delq number gnus-newsgroup-unreads))
8627               t)))
8628           ;; Nope, invisible article.
8629           0
8630         ;; Ok, this article is to be visible, so we add it to the limit
8631         ;; and return 1.
8632         (push number gnus-newsgroup-limit)
8633         1))))
8634
8635 (defun gnus-expunge-thread (thread)
8636   "Mark all articles in THREAD as read."
8637   (let* ((number (mail-header-number (car thread))))
8638     (incf gnus-newsgroup-expunged-tally)
8639     ;; We also mark as read here, if that's wanted.
8640     (setq gnus-newsgroup-unreads
8641           (delq number gnus-newsgroup-unreads))
8642     (if gnus-newsgroup-auto-expire
8643         (push number gnus-newsgroup-expirable)
8644       (push (cons number gnus-low-score-mark)
8645             gnus-newsgroup-reads)))
8646   ;; Go recursively through all subthreads.
8647   (mapcar 'gnus-expunge-thread (cdr thread)))
8648
8649 ;; Summary article oriented commands
8650
8651 (defun gnus-summary-refer-parent-article (n)
8652   "Refer parent article N times.
8653 If N is negative, go to ancestor -N instead.
8654 The difference between N and the number of articles fetched is returned."
8655   (interactive "p")
8656   (let ((skip 1)
8657         error header ref)
8658     (when (not (natnump n))
8659       (setq skip (abs n)
8660             n 1))
8661     (while (and (> n 0)
8662                 (not error))
8663       (setq header (gnus-summary-article-header))
8664       (if (and (eq (mail-header-number header)
8665                    (cdr gnus-article-current))
8666                (equal gnus-newsgroup-name
8667                       (car gnus-article-current)))
8668           ;; If we try to find the parent of the currently
8669           ;; displayed article, then we take a look at the actual
8670           ;; References header, since this is slightly more
8671           ;; reliable than the References field we got from the
8672           ;; server.
8673           (save-excursion
8674             (set-buffer gnus-original-article-buffer)
8675             (nnheader-narrow-to-headers)
8676             (unless (setq ref (message-fetch-field "references"))
8677               (when (setq ref (message-fetch-field "in-reply-to"))
8678                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8679             (widen))
8680         (setq ref
8681               ;; It's not the current article, so we take a bet on
8682               ;; the value we got from the server.
8683               (mail-header-references header)))
8684       (if (and ref
8685                (not (equal ref "")))
8686           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8687             (gnus-message 1 "Couldn't find parent"))
8688         (gnus-message 1 "No references in article %d"
8689                       (gnus-summary-article-number))
8690         (setq error t))
8691       (decf n))
8692     (gnus-summary-position-point)
8693     n))
8694
8695 (defun gnus-summary-refer-references ()
8696   "Fetch all articles mentioned in the References header.
8697 Return the number of articles fetched."
8698   (interactive)
8699   (let ((ref (mail-header-references (gnus-summary-article-header)))
8700         (current (gnus-summary-article-number))
8701         (n 0))
8702     (if (or (not ref)
8703             (equal ref ""))
8704         (error "No References in the current article")
8705       ;; For each Message-ID in the References header...
8706       (while (string-match "<[^>]*>" ref)
8707         (incf n)
8708         ;; ... fetch that article.
8709         (gnus-summary-refer-article
8710          (prog1 (match-string 0 ref)
8711            (setq ref (substring ref (match-end 0))))))
8712       (gnus-summary-goto-subject current)
8713       (gnus-summary-position-point)
8714       n)))
8715
8716 (defun gnus-summary-refer-thread (&optional limit)
8717   "Fetch all articles in the current thread.
8718 If LIMIT (the numerical prefix), fetch that many old headers instead
8719 of what's specified by the `gnus-refer-thread-limit' variable."
8720   (interactive "P")
8721   (let ((id (mail-header-id (gnus-summary-article-header)))
8722         (limit (if limit (prefix-numeric-value limit)
8723                  gnus-refer-thread-limit)))
8724     (unless (eq gnus-fetch-old-headers 'invisible)
8725       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8726       ;; Retrieve the headers and read them in.
8727       (if (eq (if (numberp limit)
8728                   (gnus-retrieve-headers
8729                    (list (min
8730                           (+ (mail-header-number
8731                               (gnus-summary-article-header))
8732                              limit)
8733                           gnus-newsgroup-end))
8734                    gnus-newsgroup-name (* limit 2))
8735                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8736                 ;; headers.
8737                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8738                                        gnus-newsgroup-name limit))
8739               'nov)
8740           (gnus-build-all-threads)
8741         (error "Can't fetch thread from back ends that don't support NOV"))
8742       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8743     (gnus-summary-limit-include-thread id)))
8744
8745 (defun gnus-summary-refer-article (message-id)
8746   "Fetch an article specified by MESSAGE-ID."
8747   (interactive "sMessage-ID: ")
8748   (when (and (stringp message-id)
8749              (not (zerop (length message-id))))
8750     (setq message-id (gnus-replace-in-string message-id " " ""))
8751     ;; Construct the correct Message-ID if necessary.
8752     ;; Suggested by tale@pawl.rpi.edu.
8753     (unless (string-match "^<" message-id)
8754       (setq message-id (concat "<" message-id)))
8755     (unless (string-match ">$" message-id)
8756       (setq message-id (concat message-id ">")))
8757     ;; People often post MIDs from URLs, so unhex it:
8758     (unless (string-match "@" message-id)
8759       (setq message-id (gnus-url-unhex-string message-id)))
8760     (let* ((header (gnus-id-to-header message-id))
8761            (sparse (and header
8762                         (gnus-summary-article-sparse-p
8763                          (mail-header-number header))
8764                         (memq (mail-header-number header)
8765                               gnus-newsgroup-limit)))
8766            number)
8767       (cond
8768        ;; If the article is present in the buffer we just go to it.
8769        ((and header
8770              (or (not (gnus-summary-article-sparse-p
8771                        (mail-header-number header)))
8772                  sparse))
8773         (prog1
8774             (gnus-summary-goto-article
8775              (mail-header-number header) nil t)
8776           (when sparse
8777             (gnus-summary-update-article (mail-header-number header)))))
8778        (t
8779         ;; We fetch the article.
8780         (catch 'found
8781           (dolist (gnus-override-method (gnus-refer-article-methods))
8782             (when (and (gnus-check-server gnus-override-method)
8783                        ;; Fetch the header,
8784                        (setq number (gnus-summary-insert-subject message-id)))
8785               ;; and display the article.
8786               (gnus-summary-select-article nil nil nil number)
8787               (throw 'found t)))
8788           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8789
8790 (defun gnus-refer-article-methods ()
8791   "Return a list of referable methods."
8792   (cond
8793    ;; No method, so we default to current and native.
8794    ((null gnus-refer-article-method)
8795     (list gnus-current-select-method gnus-select-method))
8796    ;; Current.
8797    ((eq 'current gnus-refer-article-method)
8798     (list gnus-current-select-method))
8799    ;; List of select methods.
8800    ((not (and (symbolp (car gnus-refer-article-method))
8801               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8802     (let (out)
8803       (dolist (method gnus-refer-article-method)
8804         (push (if (eq 'current method)
8805                   gnus-current-select-method
8806                 method)
8807               out))
8808       (nreverse out)))
8809    ;; One single select method.
8810    (t
8811     (list gnus-refer-article-method))))
8812
8813 (defun gnus-summary-edit-parameters ()
8814   "Edit the group parameters of the current group."
8815   (interactive)
8816   (gnus-group-edit-group gnus-newsgroup-name 'params))
8817
8818 (defun gnus-summary-customize-parameters ()
8819   "Customize the group parameters of the current group."
8820   (interactive)
8821   (gnus-group-customize gnus-newsgroup-name))
8822
8823 (defun gnus-summary-enter-digest-group (&optional force)
8824   "Enter an nndoc group based on the current article.
8825 If FORCE, force a digest interpretation.  If not, try
8826 to guess what the document format is."
8827   (interactive "P")
8828   (let ((conf gnus-current-window-configuration))
8829     (save-window-excursion
8830       (save-excursion
8831         (let (gnus-article-prepare-hook
8832               gnus-display-mime-function
8833               gnus-break-pages)
8834           (gnus-summary-select-article))))
8835     (setq gnus-current-window-configuration conf)
8836     (let* ((name (format "%s-%d"
8837                          (gnus-group-prefixed-name
8838                           gnus-newsgroup-name (list 'nndoc ""))
8839                          (with-current-buffer gnus-summary-buffer
8840                            gnus-current-article)))
8841            (ogroup gnus-newsgroup-name)
8842            (params (append (gnus-info-params (gnus-get-info ogroup))
8843                            (list (cons 'to-group ogroup))
8844                            (list (cons 'parent-group ogroup))
8845                            (list (cons 'save-article-group ogroup))))
8846            (case-fold-search t)
8847            (buf (current-buffer))
8848            dig to-address)
8849       (save-excursion
8850         (set-buffer gnus-original-article-buffer)
8851         ;; Have the digest group inherit the main mail address of
8852         ;; the parent article.
8853         (when (setq to-address (or (gnus-fetch-field "reply-to")
8854                                    (gnus-fetch-field "from")))
8855           (setq params
8856                 (append
8857                  (list (cons 'to-address
8858                              (funcall gnus-decode-encoded-address-function
8859                                       to-address))))))
8860         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8861         (insert-buffer-substring gnus-original-article-buffer)
8862         ;; Remove lines that may lead nndoc to misinterpret the
8863         ;; document type.
8864         (narrow-to-region
8865          (goto-char (point-min))
8866          (or (search-forward "\n\n" nil t) (point)))
8867         (goto-char (point-min))
8868         (delete-matching-lines "^Path:\\|^From ")
8869         (widen))
8870       (unwind-protect
8871           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8872                     (gnus-newsgroup-ephemeral-ignored-charsets
8873                      gnus-newsgroup-ignored-charsets))
8874                 (gnus-group-read-ephemeral-group
8875                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8876                               (nndoc-article-type
8877                                ,(if force 'mbox 'guess)))
8878                  t nil nil nil
8879                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8880                                                         "ADAPT")))))
8881               ;; Make all postings to this group go to the parent group.
8882               (nconc (gnus-info-params (gnus-get-info name))
8883                      params)
8884             ;; Couldn't select this doc group.
8885             (switch-to-buffer buf)
8886             (gnus-set-global-variables)
8887             (gnus-configure-windows 'summary)
8888             (gnus-message 3 "Article couldn't be entered?"))
8889         (kill-buffer dig)))))
8890
8891 (defun gnus-summary-read-document (n)
8892   "Open a new group based on the current article(s).
8893 This will allow you to read digests and other similar
8894 documents as newsgroups.
8895 Obeys the standard process/prefix convention."
8896   (interactive "P")
8897   (let* ((ogroup gnus-newsgroup-name)
8898          (params (append (gnus-info-params (gnus-get-info ogroup))
8899                          (list (cons 'to-group ogroup))))
8900          group egroup groups vgroup)
8901     (dolist (article (gnus-summary-work-articles n))
8902       (setq group (format "%s-%d" gnus-newsgroup-name article))
8903       (gnus-summary-remove-process-mark article)
8904       (when (gnus-summary-display-article article)
8905         (save-excursion
8906           (with-temp-buffer
8907             (insert-buffer-substring gnus-original-article-buffer)
8908             ;; Remove some headers that may lead nndoc to make
8909             ;; the wrong guess.
8910             (message-narrow-to-head)
8911             (goto-char (point-min))
8912             (delete-matching-lines "^Path:\\|^From ")
8913             (widen)
8914             (if (setq egroup
8915                       (gnus-group-read-ephemeral-group
8916                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8917                                      (nndoc-article-type guess))
8918                        t nil t))
8919                 (progn
8920             ;; Make all postings to this group go to the parent group.
8921                   (nconc (gnus-info-params (gnus-get-info egroup))
8922                          params)
8923                   (push egroup groups))
8924               ;; Couldn't select this doc group.
8925               (gnus-error 3 "Article couldn't be entered"))))))
8926     ;; Now we have selected all the documents.
8927     (cond
8928      ((not groups)
8929       (error "None of the articles could be interpreted as documents"))
8930      ((gnus-group-read-ephemeral-group
8931        (setq vgroup (format
8932                      "nnvirtual:%s-%s" gnus-newsgroup-name
8933                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8934        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8935        t
8936        (cons (current-buffer) 'summary)))
8937      (t
8938       (error "Couldn't select virtual nndoc group")))))
8939
8940 (defun gnus-summary-isearch-article (&optional regexp-p)
8941   "Do incremental search forward on the current article.
8942 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8943   (interactive "P")
8944   (gnus-summary-select-article)
8945   (gnus-configure-windows 'article)
8946   (gnus-eval-in-buffer-window gnus-article-buffer
8947     (save-restriction
8948       (widen)
8949       (isearch-forward regexp-p))))
8950
8951 (defun gnus-summary-repeat-search-article-forward ()
8952   "Repeat the previous search forwards."
8953   (interactive)
8954   (unless gnus-last-search-regexp
8955     (error "No previous search"))
8956   (gnus-summary-search-article-forward gnus-last-search-regexp))
8957
8958 (defun gnus-summary-repeat-search-article-backward ()
8959   "Repeat the previous search backwards."
8960   (interactive)
8961   (unless gnus-last-search-regexp
8962     (error "No previous search"))
8963   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8964
8965 (defun gnus-summary-search-article-forward (regexp &optional backward)
8966   "Search for an article containing REGEXP forward.
8967 If BACKWARD, search backward instead."
8968   (interactive
8969    (list (read-string
8970           (format "Search article %s (regexp%s): "
8971                   (if current-prefix-arg "backward" "forward")
8972                   (if gnus-last-search-regexp
8973                       (concat ", default " gnus-last-search-regexp)
8974                     "")))
8975          current-prefix-arg))
8976   (if (string-equal regexp "")
8977       (setq regexp (or gnus-last-search-regexp ""))
8978     (setq gnus-last-search-regexp regexp)
8979     (setq gnus-article-before-search gnus-current-article))
8980   ;; Intentionally set gnus-last-article.
8981   (setq gnus-last-article gnus-article-before-search)
8982   (let ((gnus-last-article gnus-last-article))
8983     (if (gnus-summary-search-article regexp backward)
8984         (gnus-summary-show-thread)
8985       (signal 'search-failed (list regexp)))))
8986
8987 (defun gnus-summary-search-article-backward (regexp)
8988   "Search for an article containing REGEXP backward."
8989   (interactive
8990    (list (read-string
8991           (format "Search article backward (regexp%s): "
8992                   (if gnus-last-search-regexp
8993                       (concat ", default " gnus-last-search-regexp)
8994                     "")))))
8995   (gnus-summary-search-article-forward regexp 'backward))
8996
8997 (defun gnus-summary-search-article (regexp &optional backward)
8998   "Search for an article containing REGEXP.
8999 Optional argument BACKWARD means do search for backward.
9000 `gnus-select-article-hook' is not called during the search."
9001   ;; We have to require this here to make sure that the following
9002   ;; dynamic binding isn't shadowed by autoloading.
9003   (require 'gnus-async)
9004   (require 'gnus-art)
9005   (let ((gnus-select-article-hook nil)  ;Disable hook.
9006         (gnus-article-prepare-hook nil)
9007         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9008         (gnus-use-article-prefetch nil)
9009         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9010         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9011         (gnus-visual nil)
9012         (gnus-keep-backlog nil)
9013         (gnus-break-pages nil)
9014         (gnus-summary-display-arrow nil)
9015         (gnus-updated-mode-lines nil)
9016         (gnus-auto-center-summary nil)
9017         (sum (current-buffer))
9018         (gnus-display-mime-function nil)
9019         (found nil)
9020         point)
9021     (gnus-save-hidden-threads
9022       (gnus-summary-select-article)
9023       (set-buffer gnus-article-buffer)
9024       (goto-char (window-point (get-buffer-window (current-buffer))))
9025       (when backward
9026         (forward-line -1))
9027       (while (not found)
9028         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9029         (if (if backward
9030                 (re-search-backward regexp nil t)
9031               (re-search-forward regexp nil t))
9032             ;; We found the regexp.
9033             (progn
9034               (setq found 'found)
9035               (beginning-of-line)
9036               (set-window-start
9037                (get-buffer-window (current-buffer))
9038                (point))
9039               (forward-line 1)
9040               (set-window-point
9041                (get-buffer-window (current-buffer))
9042                (point))
9043               (set-buffer sum)
9044               (setq point (point)))
9045           ;; We didn't find it, so we go to the next article.
9046           (set-buffer sum)
9047           (setq found 'not)
9048           (while (eq found 'not)
9049             (if (not (if backward (gnus-summary-find-prev)
9050                        (gnus-summary-find-next)))
9051                 ;; No more articles.
9052                 (setq found t)
9053               ;; Select the next article and adjust point.
9054               (unless (gnus-summary-article-sparse-p
9055                        (gnus-summary-article-number))
9056                 (setq found nil)
9057                 (gnus-summary-select-article)
9058                 (set-buffer gnus-article-buffer)
9059                 (widen)
9060                 (goto-char (if backward (point-max) (point-min))))))))
9061       (gnus-message 7 ""))
9062     ;; Return whether we found the regexp.
9063     (when (eq found 'found)
9064       (goto-char point)
9065       (gnus-summary-show-thread)
9066       (gnus-summary-goto-subject gnus-current-article)
9067       (gnus-summary-position-point)
9068       t)))
9069
9070 (defun gnus-find-matching-articles (header regexp)
9071   "Return a list of all articles that match REGEXP on HEADER.
9072 This search includes all articles in the current group that Gnus has
9073 fetched headers for, whether they are displayed or not."
9074   (let ((articles nil)
9075         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9076         (case-fold-search t))
9077     (dolist (header gnus-newsgroup-headers)
9078       (when (string-match regexp (funcall func header))
9079         (push (mail-header-number header) articles)))
9080     (nreverse articles)))
9081
9082 (defun gnus-summary-find-matching (header regexp &optional backward unread
9083                                           not-case-fold not-matching)
9084   "Return a list of all articles that match REGEXP on HEADER.
9085 The search stars on the current article and goes forwards unless
9086 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9087 If UNREAD is non-nil, only unread articles will
9088 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9089 in the comparisons. If NOT-MATCHING, return a list of all articles that
9090 not match REGEXP on HEADER."
9091   (let ((case-fold-search (not not-case-fold))
9092         articles d func)
9093     (if (consp header)
9094         (if (eq (car header) 'extra)
9095             (setq func
9096                   `(lambda (h)
9097                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9098                          "")))
9099           (error "%s is an invalid header" header))
9100       (unless (fboundp (intern (concat "mail-header-" header)))
9101         (error "%s is not a valid header" header))
9102       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9103     (dolist (d (if (eq backward 'all)
9104                    gnus-newsgroup-data
9105                  (gnus-data-find-list
9106                   (gnus-summary-article-number)
9107                   (gnus-data-list backward))))
9108       (when (and (or (not unread)       ; We want all articles...
9109                      (gnus-data-unread-p d)) ; Or just unreads.
9110                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9111                  (if not-matching
9112                      (not (string-match
9113                            regexp
9114                            (funcall func (gnus-data-header d))))
9115                    (string-match regexp
9116                                  (funcall func (gnus-data-header d)))))
9117         (push (gnus-data-number d) articles))) ; Success!
9118     (nreverse articles)))
9119
9120 (defun gnus-summary-execute-command (header regexp command &optional backward)
9121   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9122 If HEADER is an empty string (or nil), the match is done on the entire
9123 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9124   (interactive
9125    (list (let ((completion-ignore-case t))
9126            (completing-read
9127             "Header name: "
9128             (mapcar (lambda (header) (list (format "%s" header)))
9129                     (append
9130                      '("Number" "Subject" "From" "Lines" "Date"
9131                        "Message-ID" "Xref" "References" "Body")
9132                      gnus-extra-headers))
9133             nil 'require-match))
9134          (read-string "Regexp: ")
9135          (read-key-sequence "Command: ")
9136          current-prefix-arg))
9137   (when (equal header "Body")
9138     (setq header ""))
9139   ;; Hidden thread subtrees must be searched as well.
9140   (gnus-summary-show-all-threads)
9141   ;; We don't want to change current point nor window configuration.
9142   (save-excursion
9143     (save-window-excursion
9144       (let (gnus-visual
9145             gnus-treat-strip-trailing-blank-lines
9146             gnus-treat-strip-leading-blank-lines
9147             gnus-treat-strip-multiple-blank-lines
9148             gnus-treat-hide-boring-headers
9149             gnus-treat-fold-newsgroups
9150             gnus-article-prepare-hook)
9151         (gnus-message 6 "Executing %s..." (key-description command))
9152         ;; We'd like to execute COMMAND interactively so as to give arguments.
9153         (gnus-execute header regexp
9154                       `(call-interactively ',(key-binding command))
9155                       backward)
9156         (gnus-message 6 "Executing %s...done" (key-description command))))))
9157
9158 (defun gnus-summary-beginning-of-article ()
9159   "Scroll the article back to the beginning."
9160   (interactive)
9161   (gnus-summary-select-article)
9162   (gnus-configure-windows 'article)
9163   (gnus-eval-in-buffer-window gnus-article-buffer
9164     (widen)
9165     (goto-char (point-min))
9166     (when gnus-break-pages
9167       (gnus-narrow-to-page))))
9168
9169 (defun gnus-summary-end-of-article ()
9170   "Scroll to the end of the article."
9171   (interactive)
9172   (gnus-summary-select-article)
9173   (gnus-configure-windows 'article)
9174   (gnus-eval-in-buffer-window gnus-article-buffer
9175     (widen)
9176     (goto-char (point-max))
9177     (recenter -3)
9178     (when gnus-break-pages
9179       (when (re-search-backward page-delimiter nil t)
9180         (narrow-to-region (match-end 0) (point-max)))
9181       (gnus-narrow-to-page))))
9182
9183 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9184   "Truncate to LEN and quote all \"(\"'s in STRING."
9185   (gnus-replace-in-string (if (and len (> (length string) len))
9186                               (substring string 0 len)
9187                             string)
9188                           "[()]" "\\\\\\&"))
9189
9190 (defun gnus-summary-print-article (&optional filename n)
9191   "Generate and print a PostScript image of the process-marked (mail) articles.
9192
9193 If used interactively, print the current article if none are
9194 process-marked.  With prefix arg, prompt the user for the name of the
9195 file to save in.
9196
9197 When used from Lisp, accept two optional args FILENAME and N.  N means
9198 to print the next N articles.  If N is negative, print the N previous
9199 articles.  If N is nil and articles have been marked with the process
9200 mark, print these instead.
9201
9202 If the optional first argument FILENAME is nil, send the image to the
9203 printer.  If FILENAME is a string, save the PostScript image in a file with
9204 that name.  If FILENAME is a number, prompt the user for the name of the file
9205 to save in."
9206   (interactive (list (ps-print-preprint current-prefix-arg)))
9207   (dolist (article (gnus-summary-work-articles n))
9208     (gnus-summary-select-article nil nil 'pseudo article)
9209     (gnus-eval-in-buffer-window gnus-article-buffer
9210       (gnus-print-buffer))
9211     (gnus-summary-remove-process-mark article))
9212   (ps-despool filename))
9213
9214 (defun gnus-print-buffer ()
9215   (let ((buffer (generate-new-buffer " *print*")))
9216     (unwind-protect
9217         (progn
9218           (copy-to-buffer buffer (point-min) (point-max))
9219           (set-buffer buffer)
9220           (gnus-remove-text-with-property 'gnus-decoration)
9221           (when (gnus-visual-p 'article-highlight 'highlight)
9222             ;; Copy-to-buffer doesn't copy overlay.  So redo
9223             ;; highlight.
9224             (let ((gnus-article-buffer buffer))
9225               (gnus-article-highlight-citation t)
9226               (gnus-article-highlight-signature)
9227               (gnus-article-emphasize)
9228               (gnus-article-delete-invisible-text)))
9229           (let ((ps-left-header
9230                  (list
9231                   (concat "("
9232                           (gnus-summary-print-truncate-and-quote
9233                            (mail-header-subject gnus-current-headers)
9234                            66) ")")
9235                   (concat "("
9236                           (gnus-summary-print-truncate-and-quote
9237                            (mail-header-from gnus-current-headers)
9238                            45) ")")))
9239                 (ps-right-header
9240                  (list
9241                   "/pagenumberstring load"
9242                   (concat "("
9243                           (mail-header-date gnus-current-headers) ")"))))
9244             (gnus-run-hooks 'gnus-ps-print-hook)
9245             (save-excursion
9246               (if window-system
9247                   (ps-spool-buffer-with-faces)
9248                 (ps-spool-buffer)))))
9249       (kill-buffer buffer))))
9250
9251 (defun gnus-summary-show-article (&optional arg)
9252   "Force redisplaying of the current article.
9253 If ARG (the prefix) is a number, show the article with the charset
9254 defined in `gnus-summary-show-article-charset-alist', or the charset
9255 input.
9256 If ARG (the prefix) is non-nil and not a number, show the raw article
9257 without any article massaging functions being run.  Normally, the key
9258 strokes are `C-u g'."
9259   (interactive "P")
9260   (cond
9261    ((numberp arg)
9262     (gnus-summary-show-article t)
9263     (let ((gnus-newsgroup-charset
9264            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9265                (mm-read-coding-system
9266                 "View as charset: " ;; actually it is coding system.
9267                 (with-current-buffer gnus-article-buffer
9268                   (mm-detect-coding-region (point) (point-max))))))
9269           (gnus-newsgroup-ignored-charsets 'gnus-all))
9270       (gnus-summary-select-article nil 'force)
9271       (let ((deps gnus-newsgroup-dependencies)
9272             head header lines)
9273         (save-excursion
9274           (set-buffer gnus-original-article-buffer)
9275           (save-restriction
9276             (message-narrow-to-head)
9277             (setq head (buffer-string))
9278             (goto-char (point-min))
9279             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9280               (goto-char (point-max))
9281               (widen)
9282               (setq lines (1- (count-lines (point) (point-max))))))
9283           (with-temp-buffer
9284             (insert (format "211 %d Article retrieved.\n"
9285                             (cdr gnus-article-current)))
9286             (insert head)
9287             (if lines (insert (format "Lines: %d\n" lines)))
9288             (insert ".\n")
9289             (let ((nntp-server-buffer (current-buffer)))
9290               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9291         (gnus-data-set-header
9292          (gnus-data-find (cdr gnus-article-current))
9293          header)
9294         (gnus-summary-update-article-line
9295          (cdr gnus-article-current) header)
9296         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9297           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9298    ((not arg)
9299     ;; Select the article the normal way.
9300     (gnus-summary-select-article nil 'force))
9301    (t
9302     ;; We have to require this here to make sure that the following
9303     ;; dynamic binding isn't shadowed by autoloading.
9304     (require 'gnus-async)
9305     (require 'gnus-art)
9306     ;; Bind the article treatment functions to nil.
9307     (let ((gnus-have-all-headers t)
9308           gnus-article-prepare-hook
9309           gnus-article-decode-hook
9310           gnus-display-mime-function
9311           gnus-break-pages)
9312       ;; Destroy any MIME parts.
9313       (when (gnus-buffer-live-p gnus-article-buffer)
9314         (save-excursion
9315           (set-buffer gnus-article-buffer)
9316           (mm-destroy-parts gnus-article-mime-handles)
9317           ;; Set it to nil for safety reason.
9318           (setq gnus-article-mime-handle-alist nil)
9319           (setq gnus-article-mime-handles nil)))
9320       (gnus-summary-select-article nil 'force))))
9321   (gnus-summary-goto-subject gnus-current-article)
9322   (gnus-summary-position-point))
9323
9324 (defun gnus-summary-show-raw-article ()
9325   "Show the raw article without any article massaging functions being run."
9326   (interactive)
9327   (gnus-summary-show-article t))
9328
9329 (defun gnus-summary-verbose-headers (&optional arg)
9330   "Toggle permanent full header display.
9331 If ARG is a positive number, turn header display on.
9332 If ARG is a negative number, turn header display off."
9333   (interactive "P")
9334   (setq gnus-show-all-headers
9335         (cond ((or (not (numberp arg))
9336                    (zerop arg))
9337                (not gnus-show-all-headers))
9338               ((natnump arg)
9339                t)))
9340   (gnus-summary-show-article))
9341
9342 (defun gnus-summary-toggle-header (&optional arg)
9343   "Show the headers if they are hidden, or hide them if they are shown.
9344 If ARG is a positive number, show the entire header.
9345 If ARG is a negative number, hide the unwanted header lines."
9346   (interactive "P")
9347   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9348                      (get-buffer-window gnus-article-buffer t))))
9349     (with-current-buffer gnus-article-buffer
9350       (widen)
9351       (article-narrow-to-head)
9352       (let* ((buffer-read-only nil)
9353              (inhibit-point-motion-hooks t)
9354              (hidden (if (numberp arg)
9355                          (>= arg 0)
9356                        (or (not (looking-at "[^ \t\n]+:"))
9357                            (gnus-article-hidden-text-p 'headers))))
9358              s e)
9359         (delete-region (point-min) (point-max))
9360         (with-current-buffer gnus-original-article-buffer
9361           (goto-char (setq s (point-min)))
9362           (setq e (if (search-forward "\n\n" nil t)
9363                       (1- (point))
9364                     (point-max))))
9365         (insert-buffer-substring gnus-original-article-buffer s e)
9366         (run-hooks 'gnus-article-decode-hook)
9367         (if hidden
9368             (let ((gnus-treat-hide-headers nil)
9369                   (gnus-treat-hide-boring-headers nil))
9370               (gnus-delete-wash-type 'headers)
9371               (gnus-treat-article 'head))
9372           (gnus-treat-article 'head))
9373         (widen)
9374         (if window
9375             (set-window-start window (goto-char (point-min))))
9376         (if gnus-break-pages
9377             (gnus-narrow-to-page)
9378           (when (gnus-visual-p 'page-marker)
9379             (let ((buffer-read-only nil))
9380               (gnus-remove-text-with-property 'gnus-prev)
9381               (gnus-remove-text-with-property 'gnus-next))))
9382         (gnus-set-mode-line 'article)))))
9383
9384 (defun gnus-summary-show-all-headers ()
9385   "Make all header lines visible."
9386   (interactive)
9387   (gnus-summary-toggle-header 1))
9388
9389 (defun gnus-summary-caesar-message (&optional arg)
9390   "Caesar rotate the current article by 13.
9391 With a non-numerical prefix, also rotate headers.  A numerical
9392 prefix specifies how many places to rotate each letter forward."
9393   (interactive "P")
9394   (gnus-summary-select-article)
9395   (let ((mail-header-separator ""))
9396     (gnus-eval-in-buffer-window gnus-article-buffer
9397       (save-restriction
9398         (widen)
9399         (let ((start (window-start))
9400               buffer-read-only)
9401           (if (equal arg '(4))
9402               (message-caesar-buffer-body nil t)
9403             (message-caesar-buffer-body arg))
9404           (set-window-start (get-buffer-window (current-buffer)) start)))))
9405   ;; Create buttons and stuff...
9406   (gnus-treat-article nil))
9407
9408 (defun gnus-summary-idna-message (&optional arg)
9409   "Decode IDNA encoded domain names in the current articles.
9410 IDNA encoded domain names looks like `xn--bar'.  If a string
9411 remain unencoded after running this function, it is likely an
9412 invalid IDNA string (`xn--bar' is invalid).
9413
9414 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9415 installed for this command to work."
9416   (interactive "P")
9417   (if (not (and (condition-case nil (require 'idna)
9418                   (file-error))
9419                 (mm-coding-system-p 'utf-8)
9420                 (executable-find (symbol-value 'idna-program))))
9421       (gnus-message
9422        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9423     (gnus-summary-select-article)
9424     (let ((mail-header-separator ""))
9425       (gnus-eval-in-buffer-window gnus-article-buffer
9426         (save-restriction
9427           (widen)
9428           (let ((start (window-start))
9429                 buffer-read-only)
9430             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9431               (replace-match (idna-to-unicode (match-string 1))))
9432             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9433
9434 (defun gnus-summary-morse-message (&optional arg)
9435   "Morse decode the current article."
9436   (interactive "P")
9437   (gnus-summary-select-article)
9438   (let ((mail-header-separator ""))
9439     (gnus-eval-in-buffer-window gnus-article-buffer
9440       (save-excursion
9441         (save-restriction
9442           (widen)
9443           (let ((pos (window-start))
9444                 buffer-read-only)
9445             (goto-char (point-min))
9446             (when (message-goto-body)
9447               (gnus-narrow-to-body))
9448             (goto-char (point-min))
9449             (while (search-forward "·" (point-max) t)
9450               (replace-match "."))
9451             (unmorse-region (point-min) (point-max))
9452             (widen)
9453             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9454
9455 (defun gnus-summary-stop-page-breaking ()
9456   "Stop page breaking in the current article."
9457   (interactive)
9458   (gnus-summary-select-article)
9459   (gnus-eval-in-buffer-window gnus-article-buffer
9460     (widen)
9461     (when (gnus-visual-p 'page-marker)
9462       (let ((buffer-read-only nil))
9463         (gnus-remove-text-with-property 'gnus-prev)
9464         (gnus-remove-text-with-property 'gnus-next))
9465       (setq gnus-page-broken nil))))
9466
9467 (defun gnus-summary-move-article (&optional n to-newsgroup
9468                                             select-method action)
9469   "Move the current article to a different newsgroup.
9470 If N is a positive number, move the N next articles.
9471 If N is a negative number, move the N previous articles.
9472 If N is nil and any articles have been marked with the process mark,
9473 move those articles instead.
9474 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9475 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9476 re-spool using this method.
9477
9478 When called interactively with TO-NEWSGROUP being nil, the value of
9479 the variable `gnus-move-split-methods' is used for finding a default
9480 for the target newsgroup.
9481
9482 For this function to work, both the current newsgroup and the
9483 newsgroup that you want to move to have to support the `request-move'
9484 and `request-accept' functions.
9485
9486 ACTION can be either `move' (the default), `crosspost' or `copy'."
9487   (interactive "P")
9488   (unless action
9489     (setq action 'move))
9490   ;; Check whether the source group supports the required functions.
9491   (cond ((and (eq action 'move)
9492               (not (gnus-check-backend-function
9493                     'request-move-article gnus-newsgroup-name)))
9494          (error "The current group does not support article moving"))
9495         ((and (eq action 'crosspost)
9496               (not (gnus-check-backend-function
9497                     'request-replace-article gnus-newsgroup-name)))
9498          (error "The current group does not support article editing")))
9499   (let ((articles (gnus-summary-work-articles n))
9500         (prefix (if (gnus-check-backend-function
9501                      'request-move-article gnus-newsgroup-name)
9502                     (funcall gnus-move-group-prefix-function
9503                              gnus-newsgroup-name)
9504                   ""))
9505         (names '((move "Move" "Moving")
9506                  (copy "Copy" "Copying")
9507                  (crosspost "Crosspost" "Crossposting")))
9508         (copy-buf (save-excursion
9509                     (nnheader-set-temp-buffer " *copy article*")))
9510         art-group to-method new-xref article to-groups
9511         articles-to-update-marks encoded)
9512     (unless (assq action names)
9513       (error "Unknown action %s" action))
9514     ;; Read the newsgroup name.
9515     (when (and (not to-newsgroup)
9516                (not select-method))
9517       (if (and gnus-move-split-methods
9518                (not
9519                 (and (memq gnus-current-article articles)
9520                      (gnus-buffer-live-p gnus-original-article-buffer))))
9521           ;; When `gnus-move-split-methods' is non-nil, we have to
9522           ;; select an article to give `gnus-read-move-group-name' an
9523           ;; opportunity to suggest an appropriate default.  However,
9524           ;; we needn't render or mark the article.
9525           (let ((gnus-display-mime-function nil)
9526                 (gnus-article-prepare-hook nil)
9527                 (gnus-mark-article-hook nil))
9528             (gnus-summary-select-article nil nil nil (car articles))))
9529       (setq to-newsgroup (gnus-read-move-group-name
9530                           (cadr (assq action names))
9531                           (symbol-value
9532                            (intern (format "gnus-current-%s-group" action)))
9533                           articles prefix)
9534             encoded to-newsgroup
9535             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9536       (set (intern (format "gnus-current-%s-group" action))
9537            (mm-decode-coding-string
9538             to-newsgroup
9539             (gnus-group-name-charset to-method to-newsgroup))))
9540     (unless to-method
9541       (setq to-method (or select-method
9542                           (gnus-server-to-method
9543                            (gnus-group-method to-newsgroup)))))
9544     (setq to-newsgroup
9545           (or encoded
9546               (and to-newsgroup
9547                    (mm-encode-coding-string
9548                     to-newsgroup
9549                     (gnus-group-name-charset to-method to-newsgroup)))))
9550     ;; Check the method we are to move this article to...
9551     (unless (gnus-check-backend-function
9552              'request-accept-article (car to-method))
9553       (error "%s does not support article copying" (car to-method)))
9554     (unless (gnus-check-server to-method)
9555       (error "Can't open server %s" (car to-method)))
9556     (gnus-message 6 "%s to %s: %s..."
9557                   (caddr (assq action names))
9558                   (or (car select-method)
9559                       (gnus-group-decoded-name to-newsgroup))
9560                   articles)
9561     (while articles
9562       (setq article (pop articles))
9563       (setq
9564        art-group
9565        (cond
9566         ;; Move the article.
9567         ((eq action 'move)
9568          ;; Remove this article from future suppression.
9569          (gnus-dup-unsuppress-article article)
9570          (let* ((from-method (gnus-find-method-for-group
9571                               gnus-newsgroup-name))
9572                 (to-method (or select-method
9573                                (gnus-find-method-for-group to-newsgroup)))
9574                 (move-is-internal (gnus-method-equal from-method to-method)))
9575            (gnus-request-move-article
9576             article                     ; Article to move
9577             gnus-newsgroup-name         ; From newsgroup
9578             (nth 1 (gnus-find-method-for-group
9579                     gnus-newsgroup-name)) ; Server
9580             (list 'gnus-request-accept-article
9581                   to-newsgroup (list 'quote select-method)
9582                   (not articles) t)     ; Accept form
9583             (not articles)              ; Only save nov last time
9584             move-is-internal)))         ; is this move internal?
9585         ;; Copy the article.
9586         ((eq action 'copy)
9587          (save-excursion
9588            (set-buffer copy-buf)
9589            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9590              (save-restriction
9591                (nnheader-narrow-to-headers)
9592                (dolist (hdr gnus-copy-article-ignored-headers)
9593                  (message-remove-header hdr t)))
9594              (gnus-request-accept-article
9595               to-newsgroup select-method (not articles) t))))
9596         ;; Crosspost the article.
9597         ((eq action 'crosspost)
9598          (let ((xref (message-tokenize-header
9599                       (mail-header-xref (gnus-summary-article-header article))
9600                       " ")))
9601            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9602                                   ":" (number-to-string article)))
9603            (unless xref
9604              (setq xref (list (system-name))))
9605            (setq new-xref
9606                  (concat
9607                   (mapconcat 'identity
9608                              (delete "Xref:" (delete new-xref xref))
9609                              " ")
9610                   " " new-xref))
9611            (save-excursion
9612              (set-buffer copy-buf)
9613              ;; First put the article in the destination group.
9614              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9615              (when (consp (setq art-group
9616                                 (gnus-request-accept-article
9617                                  to-newsgroup select-method (not articles) t)))
9618                (setq new-xref (concat new-xref " " (car art-group)
9619                                       ":"
9620                                       (number-to-string (cdr art-group))))
9621                ;; Now we have the new Xrefs header, so we insert
9622                ;; it and replace the new article.
9623                (nnheader-replace-header "Xref" new-xref)
9624                (gnus-request-replace-article
9625                 (cdr art-group) to-newsgroup (current-buffer) t)
9626                art-group))))))
9627       (cond
9628        ((not art-group)
9629         (gnus-message 1 "Couldn't %s article %s: %s"
9630                       (cadr (assq action names)) article
9631                       (nnheader-get-report (car to-method))))
9632        ((eq art-group 'junk)
9633         (when (eq action 'move)
9634           (gnus-summary-mark-article article gnus-canceled-mark)
9635           (gnus-message 4 "Deleted article %s" article)
9636           ;; run the delete hook
9637           (run-hook-with-args 'gnus-summary-article-delete-hook
9638                               action
9639                               (gnus-data-header
9640                                (assoc article (gnus-data-list nil)))
9641                               gnus-newsgroup-name nil
9642                               select-method)))
9643        (t
9644         (let* ((pto-group (gnus-group-prefixed-name
9645                            (car art-group) to-method))
9646                (info (gnus-get-info pto-group))
9647                (to-group (gnus-info-group info))
9648                to-marks)
9649           ;; Update the group that has been moved to.
9650           (when (and info
9651                      (memq action '(move copy)))
9652             (unless (member to-group to-groups)
9653               (push to-group to-groups))
9654
9655             (unless (memq article gnus-newsgroup-unreads)
9656               (push 'read to-marks)
9657               (gnus-info-set-read
9658                info (gnus-add-to-range (gnus-info-read info)
9659                                        (list (cdr art-group)))))
9660
9661             ;; See whether the article is to be put in the cache.
9662             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9663                              gnus-article-mark-lists
9664                            (delete '(expirable . expire)
9665                                    (copy-sequence gnus-article-mark-lists))))
9666                   (to-article (cdr art-group)))
9667
9668               ;; Enter the article into the cache in the new group,
9669               ;; if that is required.
9670               (when gnus-use-cache
9671                 (gnus-cache-possibly-enter-article
9672                  to-group to-article
9673                  (memq article gnus-newsgroup-marked)
9674                  (memq article gnus-newsgroup-dormant)
9675                  (memq article gnus-newsgroup-unreads)))
9676
9677               (when gnus-preserve-marks
9678                 ;; Copy any marks over to the new group.
9679                 (when (and (equal to-group gnus-newsgroup-name)
9680                            (not (memq article gnus-newsgroup-unreads)))
9681                   ;; Mark this article as read in this group.
9682                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9683                   (setcdr (gnus-active to-group) to-article)
9684                   (setcdr gnus-newsgroup-active to-article))
9685
9686                 (while marks
9687                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9688                     (when (memq article (symbol-value
9689                                          (intern (format "gnus-newsgroup-%s"
9690                                                          (caar marks)))))
9691                       (push (cdar marks) to-marks)
9692                       ;; If the other group is the same as this group,
9693                       ;; then we have to add the mark to the list.
9694                       (when (equal to-group gnus-newsgroup-name)
9695                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9696                              (cons to-article
9697                                    (symbol-value
9698                                     (intern (format "gnus-newsgroup-%s"
9699                                                     (caar marks)))))))
9700                       ;; Copy the marks to other group.
9701                       (gnus-add-marked-articles
9702                        to-group (cdar marks) (list to-article) info)))
9703                   (setq marks (cdr marks)))
9704
9705                 (gnus-request-set-mark
9706                  to-group (list (list (list to-article) 'add to-marks))))
9707
9708               (gnus-dribble-enter
9709                (concat "(gnus-group-set-info '"
9710                        (gnus-prin1-to-string (gnus-get-info to-group))
9711                        ")"))))
9712
9713           ;; Update the Xref header in this article to point to
9714           ;; the new crossposted article we have just created.
9715           (when (eq action 'crosspost)
9716             (save-excursion
9717               (set-buffer copy-buf)
9718               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9719               (nnheader-replace-header "Xref" new-xref)
9720               (gnus-request-replace-article
9721                article gnus-newsgroup-name (current-buffer) t)))
9722
9723           ;; run the move/copy/crosspost/respool hook
9724           (run-hook-with-args 'gnus-summary-article-move-hook
9725                               action
9726                               (gnus-data-header
9727                                (assoc article (gnus-data-list nil)))
9728                               gnus-newsgroup-name
9729                               to-newsgroup
9730                               select-method))
9731
9732         ;;;!!!Why is this necessary?
9733         (set-buffer gnus-summary-buffer)
9734
9735         (gnus-summary-goto-subject article)
9736         (when (eq action 'move)
9737           (gnus-summary-mark-article article gnus-canceled-mark))))
9738       (push article articles-to-update-marks))
9739
9740     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9741     ;; Re-activate all groups that have been moved to.
9742     (save-excursion
9743       (set-buffer gnus-group-buffer)
9744       (let ((gnus-group-marked to-groups))
9745         (gnus-group-get-new-news-this-group nil t)))
9746
9747     (gnus-kill-buffer copy-buf)
9748     (gnus-summary-position-point)
9749     (gnus-set-mode-line 'summary)))
9750
9751 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9752   "Copy the current article to some other group.
9753 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9754 When called interactively, if TO-NEWSGROUP is nil, use the value of
9755 the variable `gnus-move-split-methods' for finding a default target
9756 newsgroup.
9757 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9758 re-spool using this method."
9759   (interactive "P")
9760   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9761
9762 (defun gnus-summary-crosspost-article (&optional n)
9763   "Crosspost the current article to some other group."
9764   (interactive "P")
9765   (gnus-summary-move-article n nil nil 'crosspost))
9766
9767 (defcustom gnus-summary-respool-default-method nil
9768   "Default method type for respooling an article.
9769 If nil, use to the current newsgroup method."
9770   :type 'symbol
9771   :group 'gnus-summary-mail)
9772
9773 (defcustom gnus-summary-display-while-building nil
9774   "If non-nil, show and update the summary buffer as it's being built.
9775 If the value is t, update the buffer after every line is inserted.  If
9776 the value is an integer (N), update the display every N lines."
9777   :version "22.1"
9778   :group 'gnus-thread
9779   :type '(choice (const :tag "off" nil)
9780                  number
9781                  (const :tag "frequently" t)))
9782
9783 (defun gnus-summary-respool-article (&optional n method)
9784   "Respool the current article.
9785 The article will be squeezed through the mail spooling process again,
9786 which means that it will be put in some mail newsgroup or other
9787 depending on `nnmail-split-methods'.
9788 If N is a positive number, respool the N next articles.
9789 If N is a negative number, respool the N previous articles.
9790 If N is nil and any articles have been marked with the process mark,
9791 respool those articles instead.
9792
9793 Respooling can be done both from mail groups and \"real\" newsgroups.
9794 In the former case, the articles in question will be moved from the
9795 current group into whatever groups they are destined to.  In the
9796 latter case, they will be copied into the relevant groups."
9797   (interactive
9798    (list current-prefix-arg
9799          (let* ((methods (gnus-methods-using 'respool))
9800                 (methname
9801                  (symbol-name (or gnus-summary-respool-default-method
9802                                   (car (gnus-find-method-for-group
9803                                         gnus-newsgroup-name)))))
9804                 (method
9805                  (gnus-completing-read-with-default
9806                   methname "Backend to use when respooling"
9807                   methods nil t nil 'gnus-mail-method-history))
9808                 ms)
9809            (cond
9810             ((zerop (length (setq ms (gnus-servers-using-backend
9811                                       (intern method)))))
9812              (list (intern method) ""))
9813             ((= 1 (length ms))
9814              (car ms))
9815             (t
9816              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9817                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9818                            ms-alist))))))))
9819   (unless method
9820     (error "No method given for respooling"))
9821   (if (assoc (symbol-name
9822               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9823              (gnus-methods-using 'respool))
9824       (gnus-summary-move-article n nil method)
9825     (gnus-summary-copy-article n nil method)))
9826
9827 (defun gnus-summary-import-article (file &optional edit)
9828   "Import an arbitrary file into a mail newsgroup."
9829   (interactive "fImport file: \nP")
9830   (let ((group gnus-newsgroup-name)
9831         (now (current-time))
9832         atts lines group-art)
9833     (unless (gnus-check-backend-function 'request-accept-article group)
9834       (error "%s does not support article importing" group))
9835     (or (file-readable-p file)
9836         (not (file-regular-p file))
9837         (error "Can't read %s" file))
9838     (save-excursion
9839       (set-buffer (gnus-get-buffer-create " *import file*"))
9840       (erase-buffer)
9841       (nnheader-insert-file-contents file)
9842       (goto-char (point-min))
9843       (if (nnheader-article-p)
9844           (save-restriction
9845             (goto-char (point-min))
9846             (search-forward "\n\n" nil t)
9847             (narrow-to-region (point-min) (1- (point)))
9848             (goto-char (point-min))
9849             (unless (re-search-forward "^date:" nil t)
9850               (goto-char (point-max))
9851               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9852        ;; This doesn't look like an article, so we fudge some headers.
9853         (setq atts (file-attributes file)
9854               lines (count-lines (point-min) (point-max)))
9855         (insert "From: " (read-string "From: ") "\n"
9856                 "Subject: " (read-string "Subject: ") "\n"
9857                 "Date: " (message-make-date (nth 5 atts)) "\n"
9858                 "Message-ID: " (message-make-message-id) "\n"
9859                 "Lines: " (int-to-string lines) "\n"
9860                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9861       (setq group-art (gnus-request-accept-article group nil t))
9862       (kill-buffer (current-buffer)))
9863     (setq gnus-newsgroup-active (gnus-activate-group group))
9864     (forward-line 1)
9865     (gnus-summary-goto-article (cdr group-art) nil t)
9866     (when edit
9867       (gnus-summary-edit-article))))
9868
9869 (defun gnus-summary-create-article ()
9870   "Create an article in a mail newsgroup."
9871   (interactive)
9872   (let ((group gnus-newsgroup-name)
9873         (now (current-time))
9874         group-art)
9875     (unless (gnus-check-backend-function 'request-accept-article group)
9876       (error "%s does not support article importing" group))
9877     (save-excursion
9878       (set-buffer (gnus-get-buffer-create " *import file*"))
9879       (erase-buffer)
9880       (goto-char (point-min))
9881       ;; This doesn't look like an article, so we fudge some headers.
9882       (insert "From: " (read-string "From: ") "\n"
9883               "Subject: " (read-string "Subject: ") "\n"
9884               "Date: " (message-make-date now) "\n"
9885               "Message-ID: " (message-make-message-id) "\n")
9886       (setq group-art (gnus-request-accept-article group nil t))
9887       (kill-buffer (current-buffer)))
9888     (setq gnus-newsgroup-active (gnus-activate-group group))
9889     (forward-line 1)
9890     (gnus-summary-goto-article (cdr group-art) nil t)
9891     (gnus-summary-edit-article)))
9892
9893 (defun gnus-summary-article-posted-p ()
9894   "Say whether the current (mail) article is available from news as well.
9895 This will be the case if the article has both been mailed and posted."
9896   (interactive)
9897   (let ((id (mail-header-references (gnus-summary-article-header)))
9898         (gnus-override-method (car (gnus-refer-article-methods))))
9899     (if (gnus-request-head id "")
9900         (gnus-message 2 "The current message was found on %s"
9901                       gnus-override-method)
9902       (gnus-message 2 "The current message couldn't be found on %s"
9903                     gnus-override-method)
9904       nil)))
9905
9906 (defun gnus-summary-expire-articles (&optional now)
9907   "Expire all articles that are marked as expirable in the current group."
9908   (interactive)
9909   (when (and (not gnus-group-is-exiting-without-update-p)
9910              (gnus-check-backend-function
9911               'request-expire-articles gnus-newsgroup-name))
9912     ;; This backend supports expiry.
9913     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9914            (expirable (if total
9915                           (progn
9916                             ;; We need to update the info for
9917                             ;; this group for `gnus-list-of-read-articles'
9918                             ;; to give us the right answer.
9919                             (gnus-run-hooks 'gnus-exit-group-hook)
9920                             (gnus-summary-update-info)
9921                             (gnus-list-of-read-articles gnus-newsgroup-name))
9922                         (setq gnus-newsgroup-expirable
9923                               (sort gnus-newsgroup-expirable '<))))
9924            (expiry-wait (if now 'immediate
9925                           (gnus-group-find-parameter
9926                            gnus-newsgroup-name 'expiry-wait)))
9927            (nnmail-expiry-target
9928             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9929                 nnmail-expiry-target))
9930            es)
9931       (when expirable
9932         ;; There are expirable articles in this group, so we run them
9933         ;; through the expiry process.
9934         (gnus-message 6 "Expiring articles...")
9935         (unless (gnus-check-group gnus-newsgroup-name)
9936           (error "Can't open server for %s" gnus-newsgroup-name))
9937         ;; The list of articles that weren't expired is returned.
9938         (save-excursion
9939           (if expiry-wait
9940               (let ((nnmail-expiry-wait-function nil)
9941                     (nnmail-expiry-wait expiry-wait))
9942                 (setq es (gnus-request-expire-articles
9943                           expirable gnus-newsgroup-name)))
9944             (setq es (gnus-request-expire-articles
9945                       expirable gnus-newsgroup-name)))
9946           (unless total
9947             (setq gnus-newsgroup-expirable es))
9948           ;; We go through the old list of expirable, and mark all
9949           ;; really expired articles as nonexistent.
9950           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9951             (let ((gnus-use-cache nil))
9952               (dolist (article expirable)
9953                 (when (and (not (memq article es))
9954                            (gnus-data-find article))
9955                   (gnus-summary-mark-article article gnus-canceled-mark)
9956                   (run-hook-with-args 'gnus-summary-article-expire-hook
9957                                       'delete
9958                                       (gnus-data-header
9959                                        (assoc article (gnus-data-list nil)))
9960                                       gnus-newsgroup-name
9961                                       nil
9962                                       nil))))))
9963         (gnus-message 6 "Expiring articles...done")))))
9964
9965 (defun gnus-summary-expire-articles-now ()
9966   "Expunge all expirable articles in the current group.
9967 This means that *all* articles that are marked as expirable will be
9968 deleted forever, right now."
9969   (interactive)
9970   (or gnus-expert-user
9971       (gnus-yes-or-no-p
9972        "Are you really, really sure you want to delete all expirable messages? ")
9973       (error "Phew!"))
9974   (gnus-summary-expire-articles t))
9975
9976 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9977 (defun gnus-summary-delete-article (&optional n)
9978   "Delete the N next (mail) articles.
9979 This command actually deletes articles.  This is not a marking
9980 command.  The article will disappear forever from your life, never to
9981 return.
9982
9983 If N is negative, delete backwards.
9984 If N is nil and articles have been marked with the process mark,
9985 delete these instead.
9986
9987 If `gnus-novice-user' is non-nil you will be asked for
9988 confirmation before the articles are deleted."
9989   (interactive "P")
9990   (unless (gnus-check-backend-function 'request-expire-articles
9991                                        gnus-newsgroup-name)
9992     (error "The current newsgroup does not support article deletion"))
9993   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9994     (error "Couldn't open server"))
9995   ;; Compute the list of articles to delete.
9996   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9997         (nnmail-expiry-target 'delete)
9998         not-deleted)
9999     (if (and gnus-novice-user
10000              (not (gnus-yes-or-no-p
10001                    (format "Do you really want to delete %s forever? "
10002                            (if (> (length articles) 1)
10003                                (format "these %s articles" (length articles))
10004                              "this article")))))
10005         ()
10006       ;; Delete the articles.
10007       (setq not-deleted (gnus-request-expire-articles
10008                          articles gnus-newsgroup-name 'force))
10009       (while articles
10010         (gnus-summary-remove-process-mark (car articles))
10011         ;; The backend might not have been able to delete the article
10012         ;; after all.
10013         (unless (memq (car articles) not-deleted)
10014           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10015         (let* ((article (car articles))
10016                (ghead  (gnus-data-header
10017                                     (assoc article (gnus-data-list nil)))))
10018           (run-hook-with-args 'gnus-summary-article-delete-hook
10019                               'delete ghead gnus-newsgroup-name nil
10020                               nil))
10021         (setq articles (cdr articles)))
10022       (when not-deleted
10023         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10024     (gnus-summary-position-point)
10025     (gnus-set-mode-line 'summary)
10026     not-deleted))
10027
10028 (defun gnus-summary-edit-article (&optional arg)
10029   "Edit the current article.
10030 This will have permanent effect only in mail groups.
10031 If ARG is nil, edit the decoded articles.
10032 If ARG is 1, edit the raw articles.
10033 If ARG is 2, edit the raw articles even in read-only groups.
10034 If ARG is 3, edit the articles with the current handles.
10035 Otherwise, allow editing of articles even in read-only
10036 groups."
10037   (interactive "P")
10038   (let (force raw current-handles)
10039     (cond
10040      ((null arg))
10041      ((eq arg 1)
10042       (setq raw t))
10043      ((eq arg 2)
10044       (setq raw t
10045             force t))
10046      ((eq arg 3)
10047       (setq current-handles
10048             (and (gnus-buffer-live-p gnus-article-buffer)
10049                  (with-current-buffer gnus-article-buffer
10050                    (prog1
10051                        gnus-article-mime-handles
10052                      (setq gnus-article-mime-handles nil))))))
10053      (t
10054       (setq force t)))
10055     (when (and raw (not force)
10056                (member gnus-newsgroup-name '("nndraft:delayed"
10057                                              "nndraft:drafts"
10058                                              "nndraft:queue")))
10059       (error "Can't edit the raw article in group %s"
10060              gnus-newsgroup-name))
10061     (save-excursion
10062       (set-buffer gnus-summary-buffer)
10063       (let ((mail-parse-charset gnus-newsgroup-charset)
10064             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10065         (gnus-set-global-variables)
10066         (when (and (not force)
10067                    (gnus-group-read-only-p))
10068           (error "The current newsgroup does not support article editing"))
10069         (gnus-summary-show-article t)
10070         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10071           (with-current-buffer gnus-article-buffer
10072             (mm-enable-multibyte)))
10073         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10074             (setq raw t))
10075         (gnus-article-edit-article
10076          (if raw 'ignore
10077            `(lambda ()
10078               (let ((mbl mml-buffer-list))
10079                 (setq mml-buffer-list nil)
10080                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10081                   (mime-to-mml ,'current-handles))
10082                 (let ((mbl1 mml-buffer-list))
10083                   (setq mml-buffer-list mbl)
10084                   (set (make-local-variable 'mml-buffer-list) mbl1))
10085                 (gnus-make-local-hook 'kill-buffer-hook)
10086                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10087          `(lambda (no-highlight)
10088             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10089                   (message-options message-options)
10090                   (message-options-set-recipient)
10091                   (mail-parse-ignored-charsets
10092                    ',gnus-newsgroup-ignored-charsets)
10093                   (rfc2047-header-encoding-alist
10094                    ',(let ((charset (gnus-group-name-charset
10095                                      (gnus-find-method-for-group
10096                                       gnus-newsgroup-name)
10097                                      gnus-newsgroup-name)))
10098                        (append (list (cons "Newsgroups" charset)
10099                                      (cons "Followup-To" charset)
10100                                      (cons "Xref" charset))
10101                                rfc2047-header-encoding-alist))))
10102               ,(if (not raw) '(progn
10103                                 (mml-to-mime)
10104                                 (mml-destroy-buffers)
10105                                 (remove-hook 'kill-buffer-hook
10106                                              'mml-destroy-buffers t)
10107                                 (kill-local-variable 'mml-buffer-list)))
10108               (gnus-summary-edit-article-done
10109                ,(or (mail-header-references gnus-current-headers) "")
10110                ,(gnus-group-read-only-p)
10111                ,gnus-summary-buffer no-highlight))))))))
10112
10113 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10114
10115 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10116                                                  no-highlight)
10117   "Make edits to the current article permanent."
10118   (interactive)
10119   (save-excursion
10120    ;; The buffer restriction contains the entire article if it exists.
10121     (when (article-goto-body)
10122       (let ((lines (count-lines (point) (point-max)))
10123             (length (- (point-max) (point)))
10124             (case-fold-search t)
10125             (body (copy-marker (point))))
10126         (goto-char (point-min))
10127         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10128           (delete-region (match-beginning 1) (match-end 1))
10129           (insert (number-to-string length)))
10130         (goto-char (point-min))
10131         (when (re-search-forward
10132                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10133           (delete-region (match-beginning 1) (match-end 1))
10134           (insert (number-to-string length)))
10135         (goto-char (point-min))
10136         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10137           (delete-region (match-beginning 1) (match-end 1))
10138           (insert (number-to-string lines))))))
10139   ;; Replace the article.
10140   (let ((buf (current-buffer)))
10141     (with-temp-buffer
10142       (insert-buffer-substring buf)
10143
10144       (if (and (not read-only)
10145                (not (gnus-request-replace-article
10146                      (cdr gnus-article-current) (car gnus-article-current)
10147                      (current-buffer) t)))
10148           (error "Couldn't replace article")
10149         ;; Update the summary buffer.
10150         (if (and references
10151                  (equal (message-tokenize-header references " ")
10152                         (message-tokenize-header
10153                          (or (message-fetch-field "references") "") " ")))
10154             ;; We only have to update this line.
10155             (save-excursion
10156               (save-restriction
10157                 (message-narrow-to-head)
10158                 (let ((head (buffer-substring-no-properties
10159                              (point-min) (point-max)))
10160                       header)
10161                   (with-temp-buffer
10162                     (insert (format "211 %d Article retrieved.\n"
10163                                     (cdr gnus-article-current)))
10164                     (insert head)
10165                     (insert ".\n")
10166                     (let ((nntp-server-buffer (current-buffer)))
10167                       (setq header (car (gnus-get-newsgroup-headers
10168                                          nil t))))
10169                     (save-excursion
10170                       (set-buffer gnus-summary-buffer)
10171                       (gnus-data-set-header
10172                        (gnus-data-find (cdr gnus-article-current))
10173                        header)
10174                       (gnus-summary-update-article-line
10175                        (cdr gnus-article-current) header)
10176                       (if (gnus-summary-goto-subject
10177                            (cdr gnus-article-current) nil t)
10178                           (gnus-summary-update-secondary-mark
10179                            (cdr gnus-article-current))))))))
10180           ;; Update threads.
10181           (set-buffer (or buffer gnus-summary-buffer))
10182           (gnus-summary-update-article (cdr gnus-article-current))
10183           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10184               (gnus-summary-update-secondary-mark
10185                (cdr gnus-article-current))))
10186         ;; Prettify the article buffer again.
10187         (unless no-highlight
10188           (save-excursion
10189             (set-buffer gnus-article-buffer)
10190             ;;;!!! Fix this -- article should be rehighlighted.
10191             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10192             (set-buffer gnus-original-article-buffer)
10193             (gnus-request-article
10194              (cdr gnus-article-current)
10195              (car gnus-article-current) (current-buffer))))
10196         ;; Prettify the summary buffer line.
10197         (when (gnus-visual-p 'summary-highlight 'highlight)
10198           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10199
10200 (defun gnus-summary-edit-wash (key)
10201   "Perform editing command KEY in the article buffer."
10202   (interactive
10203    (list
10204     (progn
10205       (message "%s" (concat (this-command-keys) "- "))
10206       (read-char))))
10207   (message "")
10208   (gnus-summary-edit-article)
10209   (execute-kbd-macro (concat (this-command-keys) key))
10210   (gnus-article-edit-done))
10211
10212 ;;; Respooling
10213
10214 (defun gnus-summary-respool-query (&optional silent trace)
10215   "Query where the respool algorithm would put this article."
10216   (interactive)
10217   (let (gnus-mark-article-hook)
10218     (gnus-summary-select-article)
10219     (save-excursion
10220       (set-buffer gnus-original-article-buffer)
10221       (let ((groups (nnmail-article-group 'identity trace)))
10222         (unless silent
10223           (if groups
10224               (message "This message would go to %s"
10225                        (mapconcat 'car groups ", "))
10226             (message "This message would go to no groups"))
10227           groups)))))
10228
10229 (defun gnus-summary-respool-trace ()
10230   "Trace where the respool algorithm would put this article.
10231 Display a buffer showing all fancy splitting patterns which matched."
10232   (interactive)
10233   (gnus-summary-respool-query nil t))
10234
10235 ;; Summary marking commands.
10236
10237 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10238   "Mark articles which has the same subject as read, and then select the next.
10239 If UNMARK is positive, remove any kind of mark.
10240 If UNMARK is negative, tick articles."
10241   (interactive "P")
10242   (when unmark
10243     (setq unmark (prefix-numeric-value unmark)))
10244   (let ((count
10245          (gnus-summary-mark-same-subject
10246           (gnus-summary-article-subject) unmark)))
10247     ;; Select next unread article.  If auto-select-same mode, should
10248     ;; select the first unread article.
10249     (gnus-summary-next-article t (and gnus-auto-select-same
10250                                       (gnus-summary-article-subject)))
10251     (gnus-message 7 "%d article%s marked as %s"
10252                   count (if (= count 1) " is" "s are")
10253                   (if unmark "unread" "read"))))
10254
10255 (defun gnus-summary-kill-same-subject (&optional unmark)
10256   "Mark articles which has the same subject as read.
10257 If UNMARK is positive, remove any kind of mark.
10258 If UNMARK is negative, tick articles."
10259   (interactive "P")
10260   (when unmark
10261     (setq unmark (prefix-numeric-value unmark)))
10262   (let ((count
10263          (gnus-summary-mark-same-subject
10264           (gnus-summary-article-subject) unmark)))
10265     ;; If marked as read, go to next unread subject.
10266     (when (null unmark)
10267       ;; Go to next unread subject.
10268       (gnus-summary-next-subject 1 t))
10269     (gnus-message 7 "%d articles are marked as %s"
10270                   count (if unmark "unread" "read"))))
10271
10272 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10273   "Mark articles with same SUBJECT as read, and return marked number.
10274 If optional argument UNMARK is positive, remove any kinds of marks.
10275 If optional argument UNMARK is negative, mark articles as unread instead."
10276   (let ((count 1))
10277     (save-excursion
10278       (cond
10279        ((null unmark)                   ; Mark as read.
10280         (while (and
10281                 (progn
10282                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10283                   (gnus-summary-show-thread) t)
10284                 (gnus-summary-find-subject subject))
10285           (setq count (1+ count))))
10286        ((> unmark 0)                    ; Tick.
10287         (while (and
10288                 (progn
10289                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10290                   (gnus-summary-show-thread) t)
10291                 (gnus-summary-find-subject subject))
10292           (setq count (1+ count))))
10293        (t                               ; Mark as unread.
10294         (while (and
10295                 (progn
10296                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10297                   (gnus-summary-show-thread) t)
10298                 (gnus-summary-find-subject subject))
10299           (setq count (1+ count)))))
10300       (gnus-set-mode-line 'summary)
10301       ;; Return the number of marked articles.
10302       count)))
10303
10304 (defun gnus-summary-mark-as-processable (n &optional unmark)
10305   "Set the process mark on the next N articles.
10306 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10307 the process mark instead.  The difference between N and the actual
10308 number of articles marked is returned."
10309   (interactive "P")
10310   (if (and (null n) (gnus-region-active-p))
10311       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10312     (setq n (prefix-numeric-value n))
10313     (let ((backward (< n 0))
10314           (n (abs n)))
10315       (while (and
10316               (> n 0)
10317               (if unmark
10318                   (gnus-summary-remove-process-mark
10319                    (gnus-summary-article-number))
10320                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10321               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10322         (setq n (1- n)))
10323       (when (/= 0 n)
10324         (gnus-message 7 "No more articles"))
10325       (gnus-summary-recenter)
10326       (gnus-summary-position-point)
10327       n)))
10328
10329 (defun gnus-summary-unmark-as-processable (n)
10330   "Remove the process mark from the next N articles.
10331 If N is negative, unmark backward instead.  The difference between N and
10332 the actual number of articles unmarked is returned."
10333   (interactive "P")
10334   (gnus-summary-mark-as-processable n t))
10335
10336 (defun gnus-summary-unmark-all-processable ()
10337   "Remove the process mark from all articles."
10338   (interactive)
10339   (save-excursion
10340     (while gnus-newsgroup-processable
10341       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10342   (gnus-summary-position-point))
10343
10344 (defun gnus-summary-add-mark (article type)
10345   "Mark ARTICLE with a mark of TYPE."
10346   (let ((vtype (car (assq type gnus-article-mark-lists)))
10347         var)
10348     (if (not vtype)
10349         (error "No such mark type: %s" type)
10350       (setq var (intern (format "gnus-newsgroup-%s" type)))
10351       (set var (cons article (symbol-value var)))
10352       (if (memq type '(processable cached replied forwarded recent saved))
10353           (gnus-summary-update-secondary-mark article)
10354         ;;; !!! This is bogus.  We should find out what primary
10355         ;;; !!! mark we want to set.
10356         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10357
10358 (defun gnus-summary-mark-as-expirable (n)
10359   "Mark N articles forward as expirable.
10360 If N is negative, mark backward instead.  The difference between N and
10361 the actual number of articles marked is returned."
10362   (interactive "p")
10363   (gnus-summary-mark-forward n gnus-expirable-mark))
10364
10365 (defun gnus-summary-mark-as-spam (n)
10366   "Mark N articles forward as spam.
10367 If N is negative, mark backward instead.  The difference between N and
10368 the actual number of articles marked is returned."
10369   (interactive "p")
10370   (gnus-summary-mark-forward n gnus-spam-mark))
10371
10372 (defun gnus-summary-mark-article-as-replied (article)
10373   "Mark ARTICLE as replied to and update the summary line.
10374 ARTICLE can also be a list of articles."
10375   (interactive (list (gnus-summary-article-number)))
10376   (let ((articles (if (listp article) article (list article))))
10377     (dolist (article articles)
10378       (unless (numberp article)
10379         (error "%s is not a number" article))
10380       (push article gnus-newsgroup-replied)
10381       (let ((buffer-read-only nil))
10382         (when (gnus-summary-goto-subject article nil t)
10383           (gnus-summary-update-secondary-mark article))))))
10384
10385 (defun gnus-summary-mark-article-as-forwarded (article)
10386   "Mark ARTICLE as forwarded and update the summary line.
10387 ARTICLE can also be a list of articles."
10388   (let ((articles (if (listp article) article (list article))))
10389     (dolist (article articles)
10390       (push article gnus-newsgroup-forwarded)
10391       (let ((buffer-read-only nil))
10392         (when (gnus-summary-goto-subject article nil t)
10393           (gnus-summary-update-secondary-mark article))))))
10394
10395 (defun gnus-summary-set-bookmark (article)
10396   "Set a bookmark in current article."
10397   (interactive (list (gnus-summary-article-number)))
10398   (when (or (not (get-buffer gnus-article-buffer))
10399             (not gnus-current-article)
10400             (not gnus-article-current)
10401             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10402     (error "No current article selected"))
10403   ;; Remove old bookmark, if one exists.
10404   (gnus-pull article gnus-newsgroup-bookmarks)
10405   ;; Set the new bookmark, which is on the form
10406   ;; (article-number . line-number-in-body).
10407   (push
10408    (cons article
10409          (with-current-buffer gnus-article-buffer
10410            (count-lines
10411             (min (point)
10412                  (save-excursion
10413                    (article-goto-body)
10414                    (point)))
10415             (point))))
10416    gnus-newsgroup-bookmarks)
10417   (gnus-message 6 "A bookmark has been added to the current article."))
10418
10419 (defun gnus-summary-remove-bookmark (article)
10420   "Remove the bookmark from the current article."
10421   (interactive (list (gnus-summary-article-number)))
10422   ;; Remove old bookmark, if one exists.
10423   (if (not (assq article gnus-newsgroup-bookmarks))
10424       (gnus-message 6 "No bookmark in current article.")
10425     (gnus-pull article gnus-newsgroup-bookmarks)
10426     (gnus-message 6 "Removed bookmark.")))
10427
10428 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10429 (defun gnus-summary-mark-as-dormant (n)
10430   "Mark N articles forward as dormant.
10431 If N is negative, mark backward instead.  The difference between N and
10432 the actual number of articles marked is returned."
10433   (interactive "p")
10434   (gnus-summary-mark-forward n gnus-dormant-mark))
10435
10436 (defun gnus-summary-set-process-mark (article)
10437   "Set the process mark on ARTICLE and update the summary line."
10438   (setq gnus-newsgroup-processable
10439         (cons article
10440               (delq article gnus-newsgroup-processable)))
10441   (when (gnus-summary-goto-subject article)
10442     (gnus-summary-show-thread)
10443     (gnus-summary-goto-subject article)
10444     (gnus-summary-update-secondary-mark article)))
10445
10446 (defun gnus-summary-remove-process-mark (&rest articles)
10447   "Remove the process mark from ARTICLES and update the summary line."
10448   (dolist (article articles)
10449     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10450     (when (gnus-summary-goto-subject article)
10451       (gnus-summary-show-thread)
10452       (gnus-summary-goto-subject article)
10453       (gnus-summary-update-secondary-mark article)))
10454   t)
10455
10456 (defun gnus-summary-set-saved-mark (article)
10457   "Set the process mark on ARTICLE and update the summary line."
10458   (push article gnus-newsgroup-saved)
10459   (when (gnus-summary-goto-subject article)
10460     (gnus-summary-update-secondary-mark article)))
10461
10462 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10463   "Mark N articles as read forwards.
10464 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10465 The difference between N and the actual number of articles marked is
10466 returned.
10467 If NO-EXPIRE, auto-expiry will be inhibited."
10468   (interactive "p")
10469   (gnus-summary-show-thread)
10470   (let ((backward (< n 0))
10471         (gnus-summary-goto-unread
10472          (and gnus-summary-goto-unread
10473               (not (eq gnus-summary-goto-unread 'never))
10474               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10475                                     gnus-ticked-mark gnus-dormant-mark)))))
10476         (n (abs n))
10477         (mark (or mark gnus-del-mark)))
10478     (while (and (> n 0)
10479                 (gnus-summary-mark-article nil mark no-expire)
10480                 (zerop (gnus-summary-next-subject
10481                         (if backward -1 1)
10482                         (and gnus-summary-goto-unread
10483                              (not (eq gnus-summary-goto-unread 'never)))
10484                         t)))
10485       (setq n (1- n)))
10486     (when (/= 0 n)
10487       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10488     (gnus-summary-recenter)
10489     (gnus-summary-position-point)
10490     (gnus-set-mode-line 'summary)
10491     n))
10492
10493 (defun gnus-summary-mark-article-as-read (mark)
10494   "Mark the current article quickly as read with MARK."
10495   (let ((article (gnus-summary-article-number)))
10496     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10497     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10498     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10499     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10500     (push (cons article mark) gnus-newsgroup-reads)
10501     ;; Possibly remove from cache, if that is used.
10502     (when gnus-use-cache
10503       (gnus-cache-enter-remove-article article))
10504     ;; Allow the backend to change the mark.
10505     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10506     ;; Check for auto-expiry.
10507     (when (and gnus-newsgroup-auto-expire
10508                (memq mark gnus-auto-expirable-marks))
10509       (setq mark gnus-expirable-mark)
10510       ;; Let the backend know about the mark change.
10511       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10512       (push article gnus-newsgroup-expirable))
10513     ;; Set the mark in the buffer.
10514     (gnus-summary-update-mark mark 'unread)
10515     t))
10516
10517 (defun gnus-summary-mark-article-as-unread (mark)
10518   "Mark the current article quickly as unread with MARK."
10519   (let* ((article (gnus-summary-article-number))
10520          (old-mark (gnus-summary-article-mark article)))
10521     ;; Allow the backend to change the mark.
10522     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10523     (if (eq mark old-mark)
10524         t
10525       (if (<= article 0)
10526           (progn
10527             (gnus-error 1 "Can't mark negative article numbers")
10528             nil)
10529         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10530         (setq gnus-newsgroup-spam-marked
10531               (delq article gnus-newsgroup-spam-marked))
10532         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10533         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10534         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10535         (cond ((= mark gnus-ticked-mark)
10536                (setq gnus-newsgroup-marked
10537                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10538                                               article)))
10539               ((= mark gnus-spam-mark)
10540                (setq gnus-newsgroup-spam-marked
10541                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10542                                               article)))
10543               ((= mark gnus-dormant-mark)
10544                (setq gnus-newsgroup-dormant
10545                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10546                                               article)))
10547               (t
10548                (setq gnus-newsgroup-unreads
10549                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10550                                               article))))
10551         (gnus-pull article gnus-newsgroup-reads)
10552
10553         ;; See whether the article is to be put in the cache.
10554         (and gnus-use-cache
10555              (vectorp (gnus-summary-article-header article))
10556              (save-excursion
10557                (gnus-cache-possibly-enter-article
10558                 gnus-newsgroup-name article
10559                 (= mark gnus-ticked-mark)
10560                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10561
10562         ;; Fix the mark.
10563         (gnus-summary-update-mark mark 'unread)
10564         t))))
10565
10566 (defun gnus-summary-mark-article (&optional article mark no-expire)
10567   "Mark ARTICLE with MARK.  MARK can be any character.
10568 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10569 `??' (dormant) and `?E' (expirable).
10570 If MARK is nil, then the default character `?r' is used.
10571 If ARTICLE is nil, then the article on the current line will be
10572 marked.
10573 If NO-EXPIRE, auto-expiry will be inhibited."
10574   ;; The mark might be a string.
10575   (when (stringp mark)
10576     (setq mark (aref mark 0)))
10577   ;; If no mark is given, then we check auto-expiring.
10578   (when (null mark)
10579     (setq mark gnus-del-mark))
10580   (when (and (not no-expire)
10581              gnus-newsgroup-auto-expire
10582              (memq mark gnus-auto-expirable-marks))
10583     (setq mark gnus-expirable-mark))
10584   (let ((article (or article (gnus-summary-article-number)))
10585         (old-mark (gnus-summary-article-mark article)))
10586     ;; Allow the backend to change the mark.
10587     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10588     (if (eq mark old-mark)
10589         t
10590       (unless article
10591         (error "No article on current line"))
10592       (if (not (if (or (= mark gnus-unread-mark)
10593                        (= mark gnus-ticked-mark)
10594                        (= mark gnus-spam-mark)
10595                        (= mark gnus-dormant-mark))
10596                    (gnus-mark-article-as-unread article mark)
10597                  (gnus-mark-article-as-read article mark)))
10598           t
10599         ;; See whether the article is to be put in the cache.
10600         (and gnus-use-cache
10601              (not (= mark gnus-canceled-mark))
10602              (vectorp (gnus-summary-article-header article))
10603              (save-excursion
10604                (gnus-cache-possibly-enter-article
10605                 gnus-newsgroup-name article
10606                 (= mark gnus-ticked-mark)
10607                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10608
10609         (when (gnus-summary-goto-subject article nil t)
10610           (let ((buffer-read-only nil))
10611             (gnus-summary-show-thread)
10612             ;; Fix the mark.
10613             (gnus-summary-update-mark mark 'unread)
10614             t))))))
10615
10616 (defun gnus-summary-update-secondary-mark (article)
10617   "Update the secondary (read, process, cache) mark."
10618   (gnus-summary-update-mark
10619    (cond ((memq article gnus-newsgroup-processable)
10620           gnus-process-mark)
10621          ((memq article gnus-newsgroup-cached)
10622           gnus-cached-mark)
10623          ((memq article gnus-newsgroup-replied)
10624           gnus-replied-mark)
10625          ((memq article gnus-newsgroup-forwarded)
10626           gnus-forwarded-mark)
10627          ((memq article gnus-newsgroup-saved)
10628           gnus-saved-mark)
10629          ((memq article gnus-newsgroup-recent)
10630           gnus-recent-mark)
10631          ((memq article gnus-newsgroup-unseen)
10632           gnus-unseen-mark)
10633          (t gnus-no-mark))
10634    'replied)
10635   (when (gnus-visual-p 'summary-highlight 'highlight)
10636     (gnus-run-hooks 'gnus-summary-update-hook))
10637   t)
10638
10639 (defun gnus-summary-update-download-mark (article)
10640   "Update the download mark."
10641   (gnus-summary-update-mark
10642    (cond ((memq article gnus-newsgroup-undownloaded)
10643           gnus-undownloaded-mark)
10644          (gnus-newsgroup-agentized
10645           gnus-downloaded-mark)
10646          (t
10647           gnus-no-mark))
10648    'download)
10649   (gnus-summary-update-line t)
10650   t)
10651
10652 (defun gnus-summary-update-mark (mark type)
10653   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10654         (buffer-read-only nil))
10655     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10656     (when forward
10657       (when (looking-at "\r")
10658         (incf forward))
10659       (when (<= (+ forward (point)) (point-max))
10660         ;; Go to the right position on the line.
10661         (goto-char (+ forward (point)))
10662         ;; Replace the old mark with the new mark.
10663         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10664         ;; Optionally update the marks by some user rule.
10665         (when (eq type 'unread)
10666           (gnus-data-set-mark
10667            (gnus-data-find (gnus-summary-article-number)) mark)
10668           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10669
10670 (defun gnus-mark-article-as-read (article &optional mark)
10671   "Enter ARTICLE in the pertinent lists and remove it from others."
10672   ;; Make the article expirable.
10673   (let ((mark (or mark gnus-del-mark)))
10674     (setq gnus-newsgroup-expirable
10675           (if (= mark gnus-expirable-mark)
10676               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10677             (delq article gnus-newsgroup-expirable)))
10678     ;; Remove from unread and marked lists.
10679     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10680     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10681     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10682     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10683     (push (cons article mark) gnus-newsgroup-reads)
10684     ;; Possibly remove from cache, if that is used.
10685     (when gnus-use-cache
10686       (gnus-cache-enter-remove-article article))
10687     t))
10688
10689 (defun gnus-mark-article-as-unread (article &optional mark)
10690   "Enter ARTICLE in the pertinent lists and remove it from others."
10691   (let ((mark (or mark gnus-ticked-mark)))
10692     (if (<= article 0)
10693         (progn
10694           (gnus-error 1 "Can't mark negative article numbers")
10695           nil)
10696       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10697             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10698             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10699             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10700             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10701
10702       ;; Unsuppress duplicates?
10703       (when gnus-suppress-duplicates
10704         (gnus-dup-unsuppress-article article))
10705
10706       (cond ((= mark gnus-ticked-mark)
10707              (setq gnus-newsgroup-marked
10708                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10709             ((= mark gnus-spam-mark)
10710              (setq gnus-newsgroup-spam-marked
10711                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10712                                             article)))
10713             ((= mark gnus-dormant-mark)
10714              (setq gnus-newsgroup-dormant
10715                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10716             (t
10717              (setq gnus-newsgroup-unreads
10718                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10719       (gnus-pull article gnus-newsgroup-reads)
10720       t)))
10721
10722 (defalias 'gnus-summary-mark-as-unread-forward
10723   'gnus-summary-tick-article-forward)
10724 (make-obsolete 'gnus-summary-mark-as-unread-forward
10725                'gnus-summary-tick-article-forward)
10726 (defun gnus-summary-tick-article-forward (n)
10727   "Tick N articles forwards.
10728 If N is negative, tick backwards instead.
10729 The difference between N and the number of articles ticked is returned."
10730   (interactive "p")
10731   (gnus-summary-mark-forward n gnus-ticked-mark))
10732
10733 (defalias 'gnus-summary-mark-as-unread-backward
10734   'gnus-summary-tick-article-backward)
10735 (make-obsolete 'gnus-summary-mark-as-unread-backward
10736                'gnus-summary-tick-article-backward)
10737 (defun gnus-summary-tick-article-backward (n)
10738   "Tick N articles backwards.
10739 The difference between N and the number of articles ticked is returned."
10740   (interactive "p")
10741   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10742
10743 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10744 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10745 (defun gnus-summary-tick-article (&optional article clear-mark)
10746   "Mark current article as unread.
10747 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10748 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10749   (interactive)
10750   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10751                                        gnus-ticked-mark)))
10752
10753 (defun gnus-summary-mark-as-read-forward (n)
10754   "Mark N articles as read forwards.
10755 If N is negative, mark backwards instead.
10756 The difference between N and the actual number of articles marked is
10757 returned."
10758   (interactive "p")
10759   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10760
10761 (defun gnus-summary-mark-as-read-backward (n)
10762   "Mark the N articles as read backwards.
10763 The difference between N and the actual number of articles marked is
10764 returned."
10765   (interactive "p")
10766   (gnus-summary-mark-forward
10767    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10768
10769 (defun gnus-summary-mark-as-read (&optional article mark)
10770   "Mark current article as read.
10771 ARTICLE specifies the article to be marked as read.
10772 MARK specifies a string to be inserted at the beginning of the line."
10773   (gnus-summary-mark-article article mark))
10774
10775 (defun gnus-summary-clear-mark-forward (n)
10776   "Clear marks from N articles forward.
10777 If N is negative, clear backward instead.
10778 The difference between N and the number of marks cleared is returned."
10779   (interactive "p")
10780   (gnus-summary-mark-forward n gnus-unread-mark))
10781
10782 (defun gnus-summary-clear-mark-backward (n)
10783   "Clear marks from N articles backward.
10784 The difference between N and the number of marks cleared is returned."
10785   (interactive "p")
10786   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10787
10788 (defun gnus-summary-mark-unread-as-read ()
10789   "Intended to be used by `gnus-summary-mark-article-hook'."
10790   (when (memq gnus-current-article gnus-newsgroup-unreads)
10791     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10792
10793 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10794   "Intended to be used by `gnus-summary-mark-article-hook'."
10795   (let ((mark (gnus-summary-article-mark)))
10796     (when (or (gnus-unread-mark-p mark)
10797               (gnus-read-mark-p mark))
10798       (gnus-summary-mark-article gnus-current-article
10799                                  (or new-mark gnus-read-mark)))))
10800
10801 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10802   "Intended to be used by `gnus-summary-mark-article-hook'."
10803   (let ((mark (gnus-summary-article-mark)))
10804     (when (or (gnus-unread-mark-p mark)
10805               (gnus-read-mark-p mark))
10806       (gnus-summary-mark-article (gnus-summary-article-number)
10807                                  (or new-mark gnus-read-mark)))))
10808
10809 (defun gnus-summary-mark-unread-as-ticked ()
10810   "Intended to be used by `gnus-summary-mark-article-hook'."
10811   (when (memq gnus-current-article gnus-newsgroup-unreads)
10812     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10813
10814 (defun gnus-summary-mark-region-as-read (point mark all)
10815   "Mark all unread articles between point and mark as read.
10816 If given a prefix, mark all articles between point and mark as read,
10817 even ticked and dormant ones."
10818   (interactive "r\nP")
10819   (save-excursion
10820     (let (article)
10821       (goto-char point)
10822       (beginning-of-line)
10823       (while (and
10824               (< (point) mark)
10825               (progn
10826                 (when (or all
10827                           (memq (setq article (gnus-summary-article-number))
10828                                 gnus-newsgroup-unreads))
10829                   (gnus-summary-mark-article article gnus-del-mark))
10830                 t)
10831               (gnus-summary-find-next))))))
10832
10833 (defun gnus-summary-mark-below (score mark)
10834   "Mark articles with score less than SCORE with MARK."
10835   (interactive "P\ncMark: ")
10836   (setq score (if score
10837                   (prefix-numeric-value score)
10838                 (or gnus-summary-default-score 0)))
10839   (save-excursion
10840     (set-buffer gnus-summary-buffer)
10841     (goto-char (point-min))
10842     (while
10843         (progn
10844           (and (< (gnus-summary-article-score) score)
10845                (gnus-summary-mark-article nil mark))
10846           (gnus-summary-find-next)))))
10847
10848 (defun gnus-summary-kill-below (&optional score)
10849   "Mark articles with score below SCORE as read."
10850   (interactive "P")
10851   (gnus-summary-mark-below score gnus-killed-mark))
10852
10853 (defun gnus-summary-clear-above (&optional score)
10854   "Clear all marks from articles with score above SCORE."
10855   (interactive "P")
10856   (gnus-summary-mark-above score gnus-unread-mark))
10857
10858 (defun gnus-summary-tick-above (&optional score)
10859   "Tick all articles with score above SCORE."
10860   (interactive "P")
10861   (gnus-summary-mark-above score gnus-ticked-mark))
10862
10863 (defun gnus-summary-mark-above (score mark)
10864   "Mark articles with score over SCORE with MARK."
10865   (interactive "P\ncMark: ")
10866   (setq score (if score
10867                   (prefix-numeric-value score)
10868                 (or gnus-summary-default-score 0)))
10869   (save-excursion
10870     (set-buffer gnus-summary-buffer)
10871     (goto-char (point-min))
10872     (while (and (progn
10873                   (when (> (gnus-summary-article-score) score)
10874                     (gnus-summary-mark-article nil mark))
10875                   t)
10876                 (gnus-summary-find-next)))))
10877
10878 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10879 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10880 (defun gnus-summary-limit-include-expunged (&optional no-error)
10881   "Display all the hidden articles that were expunged for low scores."
10882   (interactive)
10883   (let ((buffer-read-only nil))
10884     (let ((scored gnus-newsgroup-scored)
10885           headers h)
10886       (while scored
10887         (unless (gnus-summary-article-header (caar scored))
10888           (and (setq h (gnus-number-to-header (caar scored)))
10889                (< (cdar scored) gnus-summary-expunge-below)
10890                (push h headers)))
10891         (setq scored (cdr scored)))
10892       (if (not headers)
10893           (when (not no-error)
10894             (error "No expunged articles hidden"))
10895         (goto-char (point-min))
10896         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10897         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10898         (mapcar (lambda (x) (push (mail-header-number x)
10899                                   gnus-newsgroup-limit))
10900                 headers)
10901         (gnus-summary-prepare-unthreaded (nreverse headers))
10902         (goto-char (point-min))
10903         (gnus-summary-position-point)
10904         t))))
10905
10906 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10907   "Mark all unread articles in this newsgroup as read.
10908 If prefix argument ALL is non-nil, ticked and dormant articles will
10909 also be marked as read.
10910 If QUIETLY is non-nil, no questions will be asked.
10911
10912 If TO-HERE is non-nil, it should be a point in the buffer.  All
10913 articles before (after, if REVERSE is set) this point will be marked
10914 as read.
10915
10916 Note that this function will only catch up the unread article
10917 in the current summary buffer limitation.
10918
10919 The number of articles marked as read is returned."
10920   (interactive "P")
10921   (prog1
10922       (save-excursion
10923         (when (or quietly
10924                   (not gnus-interactive-catchup) ;Without confirmation?
10925                   gnus-expert-user
10926                   (gnus-y-or-n-p
10927                    (if all
10928                        "Mark absolutely all articles as read? "
10929                      "Mark all unread articles as read? ")))
10930           (if (and not-mark
10931                    (not gnus-newsgroup-adaptive)
10932                    (not gnus-newsgroup-auto-expire)
10933                    (not gnus-suppress-duplicates)
10934                    (or (not gnus-use-cache)
10935                        (eq gnus-use-cache 'passive)))
10936               (progn
10937                 (when all
10938                   (setq gnus-newsgroup-marked nil
10939                         gnus-newsgroup-spam-marked nil
10940                         gnus-newsgroup-dormant nil))
10941                 (setq gnus-newsgroup-unreads
10942                       (gnus-sorted-nunion
10943                        (gnus-sorted-intersection gnus-newsgroup-unreads
10944                                                  gnus-newsgroup-downloadable)
10945                        (gnus-sorted-difference gnus-newsgroup-unfetched
10946                                                gnus-newsgroup-cached))))
10947             ;; We actually mark all articles as canceled, which we
10948             ;; have to do when using auto-expiry or adaptive scoring.
10949             (gnus-summary-show-all-threads)
10950             (if (and to-here reverse)
10951                 (progn
10952                   (goto-char to-here)
10953                   (gnus-summary-mark-current-read-and-unread-as-read
10954                    gnus-catchup-mark)
10955                   (while (gnus-summary-find-next (not all))
10956                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10957               (when (gnus-summary-first-subject (not all))
10958                 (while (and
10959                         (if to-here (< (point) to-here) t)
10960                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10961                         (gnus-summary-find-next (not all))))))
10962             (gnus-set-mode-line 'summary))
10963           t))
10964     (gnus-summary-position-point)))
10965
10966 (defun gnus-summary-catchup-to-here (&optional all)
10967   "Mark all unticked articles before the current one as read.
10968 If ALL is non-nil, also mark ticked and dormant articles as read."
10969   (interactive "P")
10970   (save-excursion
10971     (gnus-save-hidden-threads
10972       (let ((beg (point)))
10973         ;; We check that there are unread articles.
10974         (when (or all (gnus-summary-find-prev))
10975           (gnus-summary-catchup all t beg)))))
10976   (gnus-summary-position-point))
10977
10978 (defun gnus-summary-catchup-from-here (&optional all)
10979   "Mark all unticked articles after (and including) the current one as read.
10980 If ALL is non-nil, also mark ticked and dormant articles as read."
10981   (interactive "P")
10982   (save-excursion
10983     (gnus-save-hidden-threads
10984       (let ((beg (point)))
10985         ;; We check that there are unread articles.
10986         (when (or all (gnus-summary-find-next))
10987           (gnus-summary-catchup all t beg nil t)))))
10988   (gnus-summary-position-point))
10989
10990 (defun gnus-summary-catchup-all (&optional quietly)
10991   "Mark all articles in this newsgroup as read.
10992 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10993 instead, which marks only unread articles as read."
10994   (interactive "P")
10995   (gnus-summary-catchup t quietly))
10996
10997 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10998   "Mark all unread articles in this group as read, then exit.
10999 If prefix argument ALL is non-nil, all articles are marked as read.
11000 If QUIETLY is non-nil, no questions will be asked."
11001   (interactive "P")
11002   (when (gnus-summary-catchup all quietly nil 'fast)
11003     ;; Select next newsgroup or exit.
11004     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11005              (eq gnus-auto-select-next 'quietly))
11006         (gnus-summary-next-group nil)
11007       (gnus-summary-exit))))
11008
11009 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11010   "Mark all articles in this newsgroup as read, and then exit.
11011 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11012 instead, which marks only unread articles as read."
11013   (interactive "P")
11014   (gnus-summary-catchup-and-exit t quietly))
11015
11016 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11017   "Mark all articles in this group as read and select the next group.
11018 If given a prefix, mark all articles, unread as well as ticked, as
11019 read."
11020   (interactive "P")
11021   (save-excursion
11022     (gnus-summary-catchup all))
11023   (gnus-summary-next-group))
11024
11025 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11026   "Mark all articles in this group as read and select the previous group.
11027 If given a prefix, mark all articles, unread as well as ticked, as
11028 read."
11029   (interactive "P")
11030   (save-excursion
11031     (gnus-summary-catchup all))
11032   (gnus-summary-next-group nil nil t))
11033
11034 ;;;
11035 ;;; with article
11036 ;;;
11037
11038 (defmacro gnus-with-article (article &rest forms)
11039   "Select ARTICLE and perform FORMS in the original article buffer.
11040 Then replace the article with the result."
11041   `(progn
11042      ;; We don't want the article to be marked as read.
11043      (let (gnus-mark-article-hook)
11044        (gnus-summary-select-article t t nil ,article))
11045      (set-buffer gnus-original-article-buffer)
11046      ,@forms
11047      (if (not (gnus-check-backend-function
11048                'request-replace-article (car gnus-article-current)))
11049          (gnus-message 5 "Read-only group; not replacing")
11050        (unless (gnus-request-replace-article
11051                 ,article (car gnus-article-current)
11052                 (current-buffer) t)
11053          (error "Couldn't replace article")))
11054      ;; The cache and backlog have to be flushed somewhat.
11055      (when gnus-keep-backlog
11056        (gnus-backlog-remove-article
11057         (car gnus-article-current) (cdr gnus-article-current)))
11058      (when gnus-use-cache
11059        (gnus-cache-update-article
11060         (car gnus-article-current) (cdr gnus-article-current)))))
11061
11062 (put 'gnus-with-article 'lisp-indent-function 1)
11063 (put 'gnus-with-article 'edebug-form-spec '(form body))
11064
11065 ;; Thread-based commands.
11066
11067 (defun gnus-summary-articles-in-thread (&optional article)
11068   "Return a list of all articles in the current thread.
11069 If ARTICLE is non-nil, return all articles in the thread that starts
11070 with that article."
11071   (let* ((article (or article (gnus-summary-article-number)))
11072          (data (gnus-data-find-list article))
11073          (top-level (gnus-data-level (car data)))
11074          (top-subject
11075           (cond ((null gnus-thread-operation-ignore-subject)
11076                  (gnus-simplify-subject-re
11077                   (mail-header-subject (gnus-data-header (car data)))))
11078                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11079                  (gnus-simplify-subject-fuzzy
11080                   (mail-header-subject (gnus-data-header (car data)))))
11081                 (t nil)))
11082          (end-point (save-excursion
11083                       (if (gnus-summary-go-to-next-thread)
11084                           (point) (point-max))))
11085          articles)
11086     (while (and data
11087                 (< (gnus-data-pos (car data)) end-point))
11088       (when (or (not top-subject)
11089                 (string= top-subject
11090                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11091                              (gnus-simplify-subject-fuzzy
11092                               (mail-header-subject
11093                                (gnus-data-header (car data))))
11094                            (gnus-simplify-subject-re
11095                             (mail-header-subject
11096                              (gnus-data-header (car data)))))))
11097         (push (gnus-data-number (car data)) articles))
11098       (unless (and (setq data (cdr data))
11099                    (> (gnus-data-level (car data)) top-level))
11100         (setq data nil)))
11101     ;; Return the list of articles.
11102     (nreverse articles)))
11103
11104 (defun gnus-summary-rethread-current ()
11105   "Rethread the thread the current article is part of."
11106   (interactive)
11107   (let* ((gnus-show-threads t)
11108          (article (gnus-summary-article-number))
11109          (id (mail-header-id (gnus-summary-article-header)))
11110          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11111     (unless id
11112       (error "No article on the current line"))
11113     (gnus-rebuild-thread id)
11114     (gnus-summary-goto-subject article)))
11115
11116 (defun gnus-summary-reparent-thread ()
11117   "Make the current article child of the marked (or previous) article.
11118
11119 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11120 is non-nil or the Subject: of both articles are the same."
11121   (interactive)
11122   (unless (not (gnus-group-read-only-p))
11123     (error "The current newsgroup does not support article editing"))
11124   (unless (<= (length gnus-newsgroup-processable) 1)
11125     (error "No more than one article may be marked"))
11126   (let ((child (gnus-summary-article-number))
11127         ;; First grab the marked article, otherwise one line up.
11128         (parent (if (not (null gnus-newsgroup-processable))
11129                     (car gnus-newsgroup-processable)
11130                   (save-excursion
11131                     (if (eq (forward-line -1) 0)
11132                         (gnus-summary-article-number)
11133                       (error "Beginning of summary buffer"))))))
11134     (gnus-summary-reparent-children parent (list child))))
11135
11136 (defun gnus-summary-reparent-children (parent children)
11137   "Make PARENT the parent of CHILDREN.
11138 When called interactively, PARENT is the current article and CHILDREN
11139 are the process-marked articles."
11140   (interactive
11141    (list (gnus-summary-article-number)
11142          (gnus-summary-work-articles nil)))
11143   (dolist (child children)
11144     (save-window-excursion
11145       (let ((gnus-article-buffer " *reparent*"))
11146         (unless (not (eq parent child))
11147           (error "An article may not be self-referential"))
11148         (let ((message-id (mail-header-id
11149                            (gnus-summary-article-header parent))))
11150           (unless (and message-id (not (equal message-id "")))
11151             (error "No message-id in desired parent"))
11152           (gnus-with-article child
11153             (save-restriction
11154               (goto-char (point-min))
11155               (message-narrow-to-head)
11156               (if (re-search-forward "^References: " nil t)
11157                   (progn
11158                     (re-search-forward "^[^ \t]" nil t)
11159                     (forward-line -1)
11160                     (end-of-line)
11161                     (insert " " message-id))
11162                 (insert "References: " message-id "\n"))))
11163           (set-buffer gnus-summary-buffer)
11164           (gnus-summary-unmark-all-processable)
11165           (gnus-summary-update-article child)
11166           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11167             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11168           (gnus-summary-rethread-current)
11169           (gnus-message 3 "Article %d is now the child of article %d"
11170                         child parent))))))
11171
11172 (defun gnus-summary-toggle-threads (&optional arg)
11173   "Toggle showing conversation threads.
11174 If ARG is positive number, turn showing conversation threads on."
11175   (interactive "P")
11176   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11177     (setq gnus-show-threads
11178           (if (null arg) (not gnus-show-threads)
11179             (> (prefix-numeric-value arg) 0)))
11180     (gnus-summary-prepare)
11181     (gnus-summary-goto-subject current)
11182     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11183     (gnus-summary-position-point)))
11184
11185 (defun gnus-summary-show-all-threads ()
11186   "Show all threads."
11187   (interactive)
11188   (save-excursion
11189     (let ((buffer-read-only nil))
11190       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11191   (gnus-summary-position-point))
11192
11193 (defun gnus-summary-show-thread ()
11194   "Show thread subtrees.
11195 Returns nil if no thread was there to be shown."
11196   (interactive)
11197   (let ((buffer-read-only nil)
11198         (orig (point))
11199         (end (point-at-eol))
11200         ;; Leave point at bol
11201         (beg (progn (beginning-of-line) (point))))
11202     (prog1
11203         ;; Any hidden lines here?
11204         (search-forward "\r" end t)
11205       (subst-char-in-region beg end ?\^M ?\n t)
11206       (goto-char orig)
11207       (gnus-summary-position-point))))
11208
11209 (defun gnus-summary-maybe-hide-threads ()
11210   "If requested, hide the threads that should be hidden."
11211   (when (and gnus-show-threads
11212              gnus-thread-hide-subtree)
11213     (gnus-summary-hide-all-threads
11214      (if (or (consp gnus-thread-hide-subtree)
11215              (functionp gnus-thread-hide-subtree))
11216          (gnus-make-predicate gnus-thread-hide-subtree)
11217        nil))))
11218
11219 ;;; Hiding predicates.
11220
11221 (defun gnus-article-unread-p (header)
11222   (memq (mail-header-number header) gnus-newsgroup-unreads))
11223
11224 (defun gnus-article-unseen-p (header)
11225   (memq (mail-header-number header) gnus-newsgroup-unseen))
11226
11227 (defun gnus-map-articles (predicate articles)
11228   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11229   (apply 'gnus-or (mapcar predicate
11230                           (mapcar (lambda (number)
11231                                     (gnus-summary-article-header number))
11232                                   articles))))
11233
11234 (defun gnus-summary-hide-all-threads (&optional predicate)
11235   "Hide all thread subtrees.
11236 If PREDICATE is supplied, threads that satisfy this predicate
11237 will not be hidden."
11238   (interactive)
11239   (save-excursion
11240     (goto-char (point-min))
11241     (let ((end nil))
11242       (while (not end)
11243         (when (or (not predicate)
11244                   (gnus-map-articles
11245                    predicate (gnus-summary-article-children)))
11246             (gnus-summary-hide-thread))
11247         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11248   (gnus-summary-position-point))
11249
11250 (defun gnus-summary-hide-thread ()
11251   "Hide thread subtrees.
11252 If PREDICATE is supplied, threads that satisfy this predicate
11253 will not be hidden.
11254 Returns nil if no threads were there to be hidden."
11255   (interactive)
11256   (let ((buffer-read-only nil)
11257         (start (point))
11258         (article (gnus-summary-article-number)))
11259     (goto-char start)
11260     ;; Go forward until either the buffer ends or the subthread
11261     ;; ends.
11262     (when (and (not (eobp))
11263                (or (zerop (gnus-summary-next-thread 1 t))
11264                    (goto-char (point-max))))
11265       (prog1
11266           (if (and (> (point) start)
11267                    (search-backward "\n" start t))
11268               (progn
11269                 (subst-char-in-region start (point) ?\n ?\^M)
11270                 (gnus-summary-goto-subject article))
11271             (goto-char start)
11272             nil)))))
11273
11274 (defun gnus-summary-go-to-next-thread (&optional previous)
11275   "Go to the same level (or less) next thread.
11276 If PREVIOUS is non-nil, go to previous thread instead.
11277 Return the article number moved to, or nil if moving was impossible."
11278   (let ((level (gnus-summary-thread-level))
11279         (way (if previous -1 1))
11280         (beg (point)))
11281     (forward-line way)
11282     (while (and (not (eobp))
11283                 (< level (gnus-summary-thread-level)))
11284       (forward-line way))
11285     (if (eobp)
11286         (progn
11287           (goto-char beg)
11288           nil)
11289       (setq beg (point))
11290       (prog1
11291           (gnus-summary-article-number)
11292         (goto-char beg)))))
11293
11294 (defun gnus-summary-next-thread (n &optional silent)
11295   "Go to the same level next N'th thread.
11296 If N is negative, search backward instead.
11297 Returns the difference between N and the number of skips actually
11298 done.
11299
11300 If SILENT, don't output messages."
11301   (interactive "p")
11302   (let ((backward (< n 0))
11303         (n (abs n)))
11304     (while (and (> n 0)
11305                 (gnus-summary-go-to-next-thread backward))
11306       (decf n))
11307     (unless silent
11308       (gnus-summary-position-point))
11309     (when (and (not silent) (/= 0 n))
11310       (gnus-message 7 "No more threads"))
11311     n))
11312
11313 (defun gnus-summary-prev-thread (n)
11314   "Go to the same level previous N'th thread.
11315 Returns the difference between N and the number of skips actually
11316 done."
11317   (interactive "p")
11318   (gnus-summary-next-thread (- n)))
11319
11320 (defun gnus-summary-go-down-thread ()
11321   "Go down one level in the current thread."
11322   (let ((children (gnus-summary-article-children)))
11323     (when children
11324       (gnus-summary-goto-subject (car children)))))
11325
11326 (defun gnus-summary-go-up-thread ()
11327   "Go up one level in the current thread."
11328   (let ((parent (gnus-summary-article-parent)))
11329     (when parent
11330       (gnus-summary-goto-subject parent))))
11331
11332 (defun gnus-summary-down-thread (n)
11333   "Go down thread N steps.
11334 If N is negative, go up instead.
11335 Returns the difference between N and how many steps down that were
11336 taken."
11337   (interactive "p")
11338   (let ((up (< n 0))
11339         (n (abs n)))
11340     (while (and (> n 0)
11341                 (if up (gnus-summary-go-up-thread)
11342                   (gnus-summary-go-down-thread)))
11343       (setq n (1- n)))
11344     (gnus-summary-position-point)
11345     (when (/= 0 n)
11346       (gnus-message 7 "Can't go further"))
11347     n))
11348
11349 (defun gnus-summary-up-thread (n)
11350   "Go up thread N steps.
11351 If N is negative, go down instead.
11352 Returns the difference between N and how many steps down that were
11353 taken."
11354   (interactive "p")
11355   (gnus-summary-down-thread (- n)))
11356
11357 (defun gnus-summary-top-thread ()
11358   "Go to the top of the thread."
11359   (interactive)
11360   (while (gnus-summary-go-up-thread))
11361   (gnus-summary-article-number))
11362
11363 (defun gnus-summary-kill-thread (&optional unmark)
11364   "Mark articles under current thread as read.
11365 If the prefix argument is positive, remove any kinds of marks.
11366 If the prefix argument is negative, tick articles instead."
11367   (interactive "P")
11368   (when unmark
11369     (setq unmark (prefix-numeric-value unmark)))
11370   (let ((articles (gnus-summary-articles-in-thread)))
11371     (save-excursion
11372       ;; Expand the thread.
11373       (gnus-summary-show-thread)
11374       ;; Mark all the articles.
11375       (while articles
11376         (gnus-summary-goto-subject (car articles))
11377         (cond ((null unmark)
11378                (gnus-summary-mark-article-as-read gnus-killed-mark))
11379               ((> unmark 0)
11380                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11381               (t
11382                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11383         (setq articles (cdr articles))))
11384     ;; Hide killed subtrees.
11385     (and (null unmark)
11386          gnus-thread-hide-killed
11387          (gnus-summary-hide-thread))
11388     ;; If marked as read, go to next unread subject.
11389     (when (null unmark)
11390       ;; Go to next unread subject.
11391       (gnus-summary-next-subject 1 t)))
11392   (gnus-set-mode-line 'summary))
11393
11394 ;; Summary sorting commands
11395
11396 (defun gnus-summary-sort-by-number (&optional reverse)
11397   "Sort the summary buffer by article number.
11398 Argument REVERSE means reverse order."
11399   (interactive "P")
11400   (gnus-summary-sort 'number reverse))
11401
11402 (defun gnus-summary-sort-by-random (&optional reverse)
11403   "Randomize the order in the summary buffer.
11404 Argument REVERSE means to randomize in reverse order."
11405   (interactive "P")
11406   (gnus-summary-sort 'random reverse))
11407
11408 (defun gnus-summary-sort-by-author (&optional reverse)
11409   "Sort the summary buffer by author name alphabetically.
11410 If `case-fold-search' is non-nil, case of letters is ignored.
11411 Argument REVERSE means reverse order."
11412   (interactive "P")
11413   (gnus-summary-sort 'author reverse))
11414
11415 (defun gnus-summary-sort-by-recipient (&optional reverse)
11416   "Sort the summary buffer by recipient name alphabetically.
11417 If `case-fold-search' is non-nil, case of letters is ignored.
11418 Argument REVERSE means reverse order."
11419   (interactive "P")
11420   (gnus-summary-sort 'recipient reverse))
11421
11422 (defun gnus-summary-sort-by-subject (&optional reverse)
11423   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11424 If `case-fold-search' is non-nil, case of letters is ignored.
11425 Argument REVERSE means reverse order."
11426   (interactive "P")
11427   (gnus-summary-sort 'subject reverse))
11428
11429 (defun gnus-summary-sort-by-date (&optional reverse)
11430   "Sort the summary buffer by date.
11431 Argument REVERSE means reverse order."
11432   (interactive "P")
11433   (gnus-summary-sort 'date reverse))
11434
11435 (defun gnus-summary-sort-by-score (&optional reverse)
11436   "Sort the summary buffer by score.
11437 Argument REVERSE means reverse order."
11438   (interactive "P")
11439   (gnus-summary-sort 'score reverse))
11440
11441 (defun gnus-summary-sort-by-lines (&optional reverse)
11442   "Sort the summary buffer by the number of lines.
11443 Argument REVERSE means reverse order."
11444   (interactive "P")
11445   (gnus-summary-sort 'lines reverse))
11446
11447 (defun gnus-summary-sort-by-chars (&optional reverse)
11448   "Sort the summary buffer by article length.
11449 Argument REVERSE means reverse order."
11450   (interactive "P")
11451   (gnus-summary-sort 'chars reverse))
11452
11453 (defun gnus-summary-sort-by-original (&optional reverse)
11454   "Sort the summary buffer using the default sorting method.
11455 Argument REVERSE means reverse order."
11456   (interactive "P")
11457   (let* ((buffer-read-only)
11458          (gnus-summary-prepare-hook nil))
11459     ;; We do the sorting by regenerating the threads.
11460     (gnus-summary-prepare)
11461     ;; Hide subthreads if needed.
11462     (gnus-summary-maybe-hide-threads)))
11463
11464 (defun gnus-summary-sort (predicate reverse)
11465   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11466   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11467          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11468          (gnus-thread-sort-functions
11469           (if (not reverse)
11470               thread
11471             `(lambda (t1 t2)
11472                (,thread t2 t1))))
11473          (gnus-sort-gathered-threads-function
11474           gnus-thread-sort-functions)
11475          (gnus-article-sort-functions
11476           (if (not reverse)
11477               article
11478             `(lambda (t1 t2)
11479                (,article t2 t1))))
11480          (buffer-read-only)
11481          (gnus-summary-prepare-hook nil))
11482     ;; We do the sorting by regenerating the threads.
11483     (gnus-summary-prepare)
11484     ;; Hide subthreads if needed.
11485     (gnus-summary-maybe-hide-threads)))
11486
11487 ;; Summary saving commands.
11488
11489 (defun gnus-summary-save-article (&optional n not-saved)
11490   "Save the current article using the default saver function.
11491 If N is a positive number, save the N next articles.
11492 If N is a negative number, save the N previous articles.
11493 If N is nil and any articles have been marked with the process mark,
11494 save those articles instead.
11495 The variable `gnus-default-article-saver' specifies the saver function.
11496
11497 If the optional second argument NOT-SAVED is non-nil, articles saved
11498 will not be marked as saved."
11499   (interactive "P")
11500   (require 'gnus-art)
11501   (let* ((articles (gnus-summary-work-articles n))
11502          (save-buffer (save-excursion
11503                         (nnheader-set-temp-buffer " *Gnus Save*")))
11504          (num (length articles))
11505          ;; Whether to save decoded articles or raw articles.
11506          (decode (when gnus-article-save-coding-system
11507                    (get gnus-default-article-saver :decode)))
11508          ;; When saving many articles in a single file, use the other
11509          ;; function to save articles other than the first one.
11510          (saver2 (get gnus-default-article-saver :function))
11511          (gnus-prompt-before-saving (if saver2
11512                                         t
11513                                       gnus-prompt-before-saving))
11514          (gnus-default-article-saver gnus-default-article-saver)
11515          header file)
11516     (dolist (article articles)
11517       (setq header (gnus-summary-article-header article))
11518       (if (not (vectorp header))
11519           ;; This is a pseudo-article.
11520           (if (assq 'name header)
11521               (gnus-copy-file (cdr (assq 'name header)))
11522             (gnus-message 1 "Article %d is unsaveable" article))
11523         ;; This is a real article.
11524         (save-window-excursion
11525           (let ((gnus-display-mime-function (when decode
11526                                               gnus-display-mime-function))
11527                 (gnus-article-prepare-hook (when decode
11528                                              gnus-article-prepare-hook)))
11529             (gnus-summary-select-article t nil nil article)
11530             (gnus-summary-goto-subject article)))
11531         (save-excursion
11532           (set-buffer save-buffer)
11533           (erase-buffer)
11534           (insert-buffer-substring (if decode
11535                                        gnus-article-buffer
11536                                      gnus-original-article-buffer)))
11537         (setq file (gnus-article-save save-buffer file num))
11538         (gnus-summary-remove-process-mark article)
11539         (unless not-saved
11540           (gnus-summary-set-saved-mark article)))
11541       (when saver2
11542         (setq gnus-default-article-saver saver2
11543               saver2 nil)))
11544     (gnus-kill-buffer save-buffer)
11545     (gnus-summary-position-point)
11546     (gnus-set-mode-line 'summary)
11547     n))
11548
11549 (defun gnus-summary-pipe-output (&optional arg headers)
11550   "Pipe the current article to a subprocess.
11551 If N is a positive number, pipe the N next articles.
11552 If N is a negative number, pipe the N previous articles.
11553 If N is nil and any articles have been marked with the process mark,
11554 pipe those articles instead.
11555 If HEADERS (the symbolic prefix), include the headers, too."
11556   (interactive (gnus-interactive "P\ny"))
11557   (require 'gnus-art)
11558   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11559         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11560     (gnus-summary-save-article arg t))
11561   (let ((buffer (get-buffer "*Shell Command Output*")))
11562     (when (and buffer
11563                (not (zerop (buffer-size buffer))))
11564       (gnus-configure-windows 'pipe))))
11565
11566 (defun gnus-summary-save-article-mail (&optional arg)
11567   "Append the current article to a Unix mail box file.
11568 If N is a positive number, save the N next articles.
11569 If N is a negative number, save the N previous articles.
11570 If N is nil and any articles have been marked with the process mark,
11571 save those articles instead."
11572   (interactive "P")
11573   (require 'gnus-art)
11574   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11575     (gnus-summary-save-article arg)))
11576
11577 (defun gnus-summary-save-article-rmail (&optional arg)
11578   "Append the current article to an rmail file.
11579 If N is a positive number, save the N next articles.
11580 If N is a negative number, save the N previous articles.
11581 If N is nil and any articles have been marked with the process mark,
11582 save those articles instead."
11583   (interactive "P")
11584   (require 'gnus-art)
11585   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11586     (gnus-summary-save-article arg)))
11587
11588 (defun gnus-summary-save-article-file (&optional arg)
11589   "Append the current article to a file.
11590 If N is a positive number, save the N next articles.
11591 If N is a negative number, save the N previous articles.
11592 If N is nil and any articles have been marked with the process mark,
11593 save those articles instead."
11594   (interactive "P")
11595   (require 'gnus-art)
11596   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11597     (gnus-summary-save-article arg)))
11598
11599 (defun gnus-summary-write-article-file (&optional arg)
11600   "Write the current article to a file, deleting the previous file.
11601 If N is a positive number, save the N next articles.
11602 If N is a negative number, save the N previous articles.
11603 If N is nil and any articles have been marked with the process mark,
11604 save those articles instead."
11605   (interactive "P")
11606   (require 'gnus-art)
11607   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11608     (gnus-summary-save-article arg)))
11609
11610 (defun gnus-summary-save-article-body-file (&optional arg)
11611   "Append the current article body to a file.
11612 If N is a positive number, save the N next articles.
11613 If N is a negative number, save the N previous articles.
11614 If N is nil and any articles have been marked with the process mark,
11615 save those articles instead."
11616   (interactive "P")
11617   (require 'gnus-art)
11618   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11619     (gnus-summary-save-article arg)))
11620
11621 (defun gnus-summary-write-article-body-file (&optional arg)
11622   "Write the current article body to a file, deleting the previous file.
11623 If N is a positive number, save the N next articles.
11624 If N is a negative number, save the N previous articles.
11625 If N is nil and any articles have been marked with the process mark,
11626 save those articles instead."
11627   (interactive "P")
11628   (require 'gnus-art)
11629   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11630     (gnus-summary-save-article arg)))
11631
11632 (defun gnus-summary-muttprint (&optional arg)
11633   "Print the current article using Muttprint.
11634 If N is a positive number, save the N next articles.
11635 If N is a negative number, save the N previous articles.
11636 If N is nil and any articles have been marked with the process mark,
11637 save those articles instead."
11638   (interactive "P")
11639   (require 'gnus-art)
11640   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11641     (gnus-summary-save-article arg t)))
11642
11643 (defun gnus-summary-pipe-message (program)
11644   "Pipe the current article through PROGRAM."
11645   (interactive "sProgram: ")
11646   (gnus-summary-select-article)
11647   (let ((mail-header-separator ""))
11648     (gnus-eval-in-buffer-window gnus-article-buffer
11649       (save-restriction
11650         (widen)
11651         (let ((start (window-start))
11652               buffer-read-only)
11653           (message-pipe-buffer-body program)
11654           (set-window-start (get-buffer-window (current-buffer)) start))))))
11655
11656 (defun gnus-get-split-value (methods)
11657   "Return a value based on the split METHODS."
11658   (let (split-name method result match)
11659     (when methods
11660       (save-excursion
11661         (set-buffer gnus-original-article-buffer)
11662         (save-restriction
11663           (nnheader-narrow-to-headers)
11664           (while (and methods (not split-name))
11665             (goto-char (point-min))
11666             (setq method (pop methods))
11667             (setq match (car method))
11668             (when (cond
11669                    ((stringp match)
11670                     ;; Regular expression.
11671                     (ignore-errors
11672                       (re-search-forward match nil t)))
11673                    ((functionp match)
11674                     ;; Function.
11675                     (save-restriction
11676                       (widen)
11677                       (setq result (funcall match gnus-newsgroup-name))))
11678                    ((consp match)
11679                     ;; Form.
11680                     (save-restriction
11681                       (widen)
11682                       (setq result (eval match)))))
11683               (setq split-name (cdr method))
11684               (cond ((stringp result)
11685                      (push (expand-file-name
11686                             result gnus-article-save-directory)
11687                            split-name))
11688                     ((consp result)
11689                      (setq split-name (append result split-name)))))))))
11690     (nreverse split-name)))
11691
11692 (defun gnus-valid-move-group-p (group)
11693   (and (boundp group)
11694        (symbol-name group)
11695        (symbol-value group)
11696        (gnus-get-function (gnus-find-method-for-group
11697                            (symbol-name group)) 'request-accept-article t)))
11698
11699 (defun gnus-read-move-group-name (prompt default articles prefix)
11700   "Read a group name."
11701   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11702          (minibuffer-confirm-incomplete nil) ; XEmacs
11703          (prom
11704           (format "%s %s to"
11705                   prompt
11706                   (if (> (length articles) 1)
11707                       (format "these %d articles" (length articles))
11708                     "this article")))
11709          (to-newsgroup
11710           (let (active group)
11711             (when (or (null split-name) (= 1 (length split-name)))
11712               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11713               (mapatoms (lambda (symbol)
11714                           (setq group (symbol-name symbol))
11715                           (when (string-match "[^\000-\177]" group)
11716                             (setq group (gnus-group-decoded-name group)))
11717                           (set (intern group active) group))
11718                         gnus-active-hashtb))
11719             (cond
11720              ((null split-name)
11721               (gnus-completing-read-with-default
11722                default prom active 'gnus-valid-move-group-p nil prefix
11723                'gnus-group-history))
11724              ((= 1 (length split-name))
11725               (gnus-completing-read-with-default
11726                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11727                'gnus-group-history))
11728              (t
11729               (gnus-completing-read-with-default
11730                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11731                'gnus-group-history)))))
11732          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11733          encoded)
11734     (when to-newsgroup
11735       (if (or (string= to-newsgroup "")
11736               (string= to-newsgroup prefix))
11737           (setq to-newsgroup default))
11738       (unless to-newsgroup
11739         (error "No group name entered"))
11740       (setq encoded (mm-encode-coding-string
11741                      to-newsgroup
11742                      (gnus-group-name-charset to-method to-newsgroup)))
11743       (or (gnus-active encoded)
11744           (gnus-activate-group encoded nil nil to-method)
11745           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11746                                      to-newsgroup))
11747               (or (and (gnus-request-create-group encoded to-method)
11748                        (gnus-activate-group encoded nil nil to-method)
11749                        (gnus-subscribe-group encoded))
11750                   (error "Couldn't create group %s" to-newsgroup)))
11751           (error "No such group: %s" to-newsgroup))
11752       encoded)))
11753
11754 (defvar gnus-summary-save-parts-counter)
11755
11756 (defun gnus-summary-save-parts (type dir n &optional reverse)
11757   "Save parts matching TYPE to DIR.
11758 If REVERSE, save parts that do not match TYPE."
11759   (interactive
11760    (list (read-string "Save parts of type: "
11761                       (or (car gnus-summary-save-parts-type-history)
11762                           gnus-summary-save-parts-default-mime)
11763                       'gnus-summary-save-parts-type-history)
11764          (setq gnus-summary-save-parts-last-directory
11765                (read-file-name "Save to directory: "
11766                                gnus-summary-save-parts-last-directory
11767                                nil t))
11768          current-prefix-arg))
11769   (gnus-summary-iterate n
11770     (let ((gnus-display-mime-function nil)
11771           (gnus-inhibit-treatment t))
11772       (gnus-summary-select-article))
11773     (save-excursion
11774       (set-buffer gnus-article-buffer)
11775       (let ((handles (or gnus-article-mime-handles
11776                          (mm-dissect-buffer nil gnus-article-loose-mime)
11777                          (and gnus-article-emulate-mime
11778                               (mm-uu-dissect))))
11779             (gnus-summary-save-parts-counter 1))
11780         (when handles
11781           (gnus-summary-save-parts-1 type dir handles reverse)
11782           (unless gnus-article-mime-handles ;; Don't destroy this case.
11783             (mm-destroy-parts handles)))))))
11784
11785 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11786   (if (stringp (car handle))
11787       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11788               (cdr handle))
11789     (when (if reverse
11790               (not (string-match type (mm-handle-media-type handle)))
11791             (string-match type (mm-handle-media-type handle)))
11792       (let ((file (expand-file-name
11793                    (gnus-map-function
11794                     mm-file-name-rewrite-functions
11795                     (file-name-nondirectory
11796                      (or
11797                       (mail-content-type-get
11798                        (mm-handle-disposition handle) 'filename)
11799                       (mail-content-type-get
11800                        (mm-handle-type handle) 'name)
11801                       (format "%s.%d.%d" gnus-newsgroup-name
11802                               (cdr gnus-article-current)
11803                               gnus-summary-save-parts-counter))))
11804                    dir)))
11805         (incf gnus-summary-save-parts-counter)
11806         (unless (file-exists-p file)
11807           (mm-save-part-to-file handle file))))))
11808
11809 ;; Summary extract commands
11810
11811 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11812   (let ((buffer-read-only nil)
11813         (article (gnus-summary-article-number))
11814         after-article b e)
11815     (unless (gnus-summary-goto-subject article)
11816       (error "No such article: %d" article))
11817     (gnus-summary-position-point)
11818     ;; If all commands are to be bunched up on one line, we collect
11819     ;; them here.
11820     (unless gnus-view-pseudos-separately
11821       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11822             files action)
11823         (while ps
11824           (setq action (cdr (assq 'action (car ps))))
11825           (setq files (list (cdr (assq 'name (car ps)))))
11826           (while (and ps (cdr ps)
11827                       (string= (or action "1")
11828                                (or (cdr (assq 'action (cadr ps))) "2")))
11829             (push (cdr (assq 'name (cadr ps))) files)
11830             (setcdr ps (cddr ps)))
11831           (when files
11832             (when (not (string-match "%s" action))
11833               (push " " files))
11834             (push " " files)
11835             (when (assq 'execute (car ps))
11836               (setcdr (assq 'execute (car ps))
11837                       (funcall (if (string-match "%s" action)
11838                                    'format 'concat)
11839                                action
11840                                (mapconcat
11841                                 (lambda (f)
11842                                   (if (equal f " ")
11843                                       f
11844                                     (shell-quote-argument f)))
11845                                 files " ")))))
11846           (setq ps (cdr ps)))))
11847     (if (and gnus-view-pseudos (not not-view))
11848         (while pslist
11849           (when (assq 'execute (car pslist))
11850             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11851                                   (eq gnus-view-pseudos 'not-confirm)))
11852           (setq pslist (cdr pslist)))
11853       (save-excursion
11854         (while pslist
11855           (setq after-article (or (cdr (assq 'article (car pslist)))
11856                                   (gnus-summary-article-number)))
11857           (gnus-summary-goto-subject after-article)
11858           (forward-line 1)
11859           (setq b (point))
11860           (insert "    " (file-name-nondirectory
11861                           (cdr (assq 'name (car pslist))))
11862                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11863           (setq e (point))
11864           (forward-line -1)             ; back to `b'
11865           (gnus-add-text-properties
11866            b (1- e) (list 'gnus-number gnus-reffed-article-number
11867                           gnus-mouse-face-prop gnus-mouse-face))
11868           (gnus-data-enter
11869            after-article gnus-reffed-article-number
11870            gnus-unread-mark b (car pslist) 0 (- e b))
11871           (setq gnus-newsgroup-unreads
11872                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11873                                          gnus-reffed-article-number))
11874           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11875           (setq pslist (cdr pslist)))))))
11876
11877 (defun gnus-pseudos< (p1 p2)
11878   (let ((c1 (cdr (assq 'action p1)))
11879         (c2 (cdr (assq 'action p2))))
11880     (and c1 c2 (string< c1 c2))))
11881
11882 (defun gnus-request-pseudo-article (props)
11883   (cond ((assq 'execute props)
11884          (gnus-execute-command (cdr (assq 'execute props)))))
11885   (let ((gnus-current-article (gnus-summary-article-number)))
11886     (gnus-run-hooks 'gnus-mark-article-hook)))
11887
11888 (defun gnus-execute-command (command &optional automatic)
11889   (save-excursion
11890     (gnus-article-setup-buffer)
11891     (set-buffer gnus-article-buffer)
11892     (setq buffer-read-only nil)
11893     (let ((command (if automatic command
11894                      (read-string "Command: " (cons command 0)))))
11895       (erase-buffer)
11896       (insert "$ " command "\n\n")
11897       (if gnus-view-pseudo-asynchronously
11898           (start-process "gnus-execute" (current-buffer) shell-file-name
11899                          shell-command-switch command)
11900         (call-process shell-file-name nil t nil
11901                       shell-command-switch command)))))
11902
11903 ;; Summary kill commands.
11904
11905 (defun gnus-summary-edit-global-kill (article)
11906   "Edit the \"global\" kill file."
11907   (interactive (list (gnus-summary-article-number)))
11908   (gnus-group-edit-global-kill article))
11909
11910 (defun gnus-summary-edit-local-kill ()
11911   "Edit a local kill file applied to the current newsgroup."
11912   (interactive)
11913   (setq gnus-current-headers (gnus-summary-article-header))
11914   (gnus-group-edit-local-kill
11915    (gnus-summary-article-number) gnus-newsgroup-name))
11916
11917 ;;; Header reading.
11918
11919 (defun gnus-read-header (id &optional header)
11920   "Read the headers of article ID and enter them into the Gnus system."
11921   (let ((group gnus-newsgroup-name)
11922         (gnus-override-method
11923          (or
11924           gnus-override-method
11925           (and (gnus-news-group-p gnus-newsgroup-name)
11926                (car (gnus-refer-article-methods)))))
11927         where)
11928     ;; First we check to see whether the header in question is already
11929     ;; fetched.
11930     (if (stringp id)
11931         ;; This is a Message-ID.
11932         (setq header (or header (gnus-id-to-header id)))
11933       ;; This is an article number.
11934       (setq header (or header (gnus-summary-article-header id))))
11935     (if (and header
11936              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11937         ;; We have found the header.
11938         header
11939       ;; We have to really fetch the header to this article.
11940       (save-excursion
11941         (set-buffer nntp-server-buffer)
11942         (when (setq where (gnus-request-head id group))
11943           (nnheader-fold-continuation-lines)
11944           (goto-char (point-max))
11945           (insert ".\n")
11946           (goto-char (point-min))
11947           (insert "211 ")
11948           (princ (cond
11949                   ((numberp id) id)
11950                   ((cdr where) (cdr where))
11951                   (header (mail-header-number header))
11952                   (t gnus-reffed-article-number))
11953                  (current-buffer))
11954           (insert " Article retrieved.\n"))
11955         (if (or (not where)
11956                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11957             ()                          ; Malformed head.
11958           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11959             (when (and (stringp id)
11960                        (or
11961                         (not (string= (gnus-group-real-name group)
11962                                       (car where)))
11963                         (not (gnus-server-equal gnus-override-method
11964                                                 (gnus-group-method group)))))
11965               ;; If we fetched by Message-ID and the article came from
11966               ;; a different group (or server), we fudge some bogus
11967               ;; article numbers for this article.
11968               (mail-header-set-number header gnus-reffed-article-number))
11969             (save-excursion
11970               (set-buffer gnus-summary-buffer)
11971               (decf gnus-reffed-article-number)
11972               (gnus-remove-header (mail-header-number header))
11973               (push header gnus-newsgroup-headers)
11974               (setq gnus-current-headers header)
11975               (push (mail-header-number header) gnus-newsgroup-limit)))
11976           header)))))
11977
11978 (defun gnus-remove-header (number)
11979   "Remove header NUMBER from `gnus-newsgroup-headers'."
11980   (if (and gnus-newsgroup-headers
11981            (= number (mail-header-number (car gnus-newsgroup-headers))))
11982       (pop gnus-newsgroup-headers)
11983     (let ((headers gnus-newsgroup-headers))
11984       (while (and (cdr headers)
11985                   (not (= number (mail-header-number (cadr headers)))))
11986         (pop headers))
11987       (when (cdr headers)
11988         (setcdr headers (cddr headers))))))
11989
11990 ;;;
11991 ;;; summary highlights
11992 ;;;
11993
11994 (defun gnus-highlight-selected-summary ()
11995   "Highlight selected article in summary buffer."
11996   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11997   (when gnus-summary-selected-face
11998     (save-excursion
11999       (let* ((beg (point-at-bol))
12000              (end (point-at-eol))
12001              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12002              (from (if (get-text-property beg gnus-mouse-face-prop)
12003                        beg
12004                      (or (next-single-property-change
12005                           beg gnus-mouse-face-prop nil end)
12006                          beg)))
12007              (to
12008               (if (= from end)
12009                   (- from 2)
12010                 (or (next-single-property-change
12011                      from gnus-mouse-face-prop nil end)
12012                     end))))
12013         ;; If no mouse-face prop on line we will have to = from = end,
12014         ;; so we highlight the entire line instead.
12015         (when (= (+ to 2) from)
12016           (setq from beg)
12017           (setq to end))
12018         (if gnus-newsgroup-selected-overlay
12019             ;; Move old overlay.
12020             (gnus-move-overlay
12021              gnus-newsgroup-selected-overlay from to (current-buffer))
12022           ;; Create new overlay.
12023           (gnus-overlay-put
12024            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12025            'face gnus-summary-selected-face))))))
12026
12027 (defvar gnus-summary-highlight-line-cached nil)
12028 (defvar gnus-summary-highlight-line-trigger nil)
12029
12030 (defun gnus-summary-highlight-line-0 ()
12031   (if (and (eq gnus-summary-highlight-line-trigger
12032                gnus-summary-highlight)
12033            gnus-summary-highlight-line-cached)
12034       gnus-summary-highlight-line-cached
12035     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12036           gnus-summary-highlight-line-cached
12037           (let* ((cond (list 'cond))
12038                  (c cond)
12039                  (list gnus-summary-highlight))
12040             (while list
12041               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12042                               nil))
12043               (setq c (cdr c)
12044                     list (cdr list)))
12045             (gnus-byte-compile (list 'lambda nil cond))))))
12046
12047 (defun gnus-summary-highlight-line ()
12048   "Highlight current line according to `gnus-summary-highlight'."
12049   (let* ((beg (point-at-bol))
12050          (article (or (gnus-summary-article-number) gnus-current-article))
12051          (score (or (cdr (assq article
12052                                gnus-newsgroup-scored))
12053                     gnus-summary-default-score 0))
12054          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12055          (inhibit-read-only t)
12056          (default gnus-summary-default-score)
12057          (default-high gnus-summary-default-high-score)
12058          (default-low gnus-summary-default-low-score)
12059          (uncached (and gnus-summary-use-undownloaded-faces
12060                         (memq article gnus-newsgroup-undownloaded)
12061                         (not (memq article gnus-newsgroup-cached)))))
12062     (let ((face (funcall (gnus-summary-highlight-line-0))))
12063       (unless (eq face (get-text-property beg 'face))
12064         (gnus-put-text-property-excluding-characters-with-faces
12065          beg (point-at-eol) 'face
12066          (setq face (if (boundp face) (symbol-value face) face)))
12067         (when gnus-summary-highlight-line-function
12068           (funcall gnus-summary-highlight-line-function article face))))))
12069
12070 (defun gnus-update-read-articles (group unread &optional compute)
12071   "Update the list of read articles in GROUP.
12072 UNREAD is a sorted list."
12073   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12074         (info (gnus-get-info group))
12075         (prev 1)
12076         read)
12077     (if (or (not info) (not active))
12078         ;; There is no info on this group if it was, in fact,
12079         ;; killed.  Gnus stores no information on killed groups, so
12080         ;; there's nothing to be done.
12081         ;; One could store the information somewhere temporarily,
12082         ;; perhaps...  Hmmm...
12083         ()
12084       ;; Remove any negative articles numbers.
12085       (while (and unread (< (car unread) 0))
12086         (setq unread (cdr unread)))
12087       ;; Remove any expired article numbers
12088       (while (and unread (< (car unread) (car active)))
12089         (setq unread (cdr unread)))
12090       ;; Compute the ranges of read articles by looking at the list of
12091       ;; unread articles.
12092       (while unread
12093         (when (/= (car unread) prev)
12094           (push (if (= prev (1- (car unread))) prev
12095                   (cons prev (1- (car unread))))
12096                 read))
12097         (setq prev (1+ (car unread)))
12098         (setq unread (cdr unread)))
12099       (when (<= prev (cdr active))
12100         (push (cons prev (cdr active)) read))
12101       (setq read (if (> (length read) 1) (nreverse read) read))
12102       (if compute
12103           read
12104         (save-excursion
12105           (let (setmarkundo)
12106             ;; Propagate the read marks to the backend.
12107             (when (gnus-check-backend-function 'request-set-mark group)
12108               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12109                     (add (gnus-remove-from-range read (gnus-info-read info))))
12110                 (when (or add del)
12111                   (unless (gnus-check-group group)
12112                     (error "Can't open server for %s" group))
12113                   (gnus-request-set-mark
12114                    group (delq nil (list (if add (list add 'add '(read)))
12115                                          (if del (list del 'del '(read))))))
12116                   (setq setmarkundo
12117                         `(gnus-request-set-mark
12118                           ,group
12119                           ',(delq nil (list
12120                                        (if del (list del 'add '(read)))
12121                                        (if add (list add 'del '(read))))))))))
12122             (set-buffer gnus-group-buffer)
12123             (gnus-undo-register
12124               `(progn
12125                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12126                  (gnus-info-set-read ',info ',(gnus-info-read info))
12127                  (gnus-get-unread-articles-in-group ',info
12128                                                     (gnus-active ,group))
12129                  (gnus-group-update-group ,group t)
12130                  ,setmarkundo))))
12131         ;; Enter this list into the group info.
12132         (gnus-info-set-read info read)
12133         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12134         (gnus-get-unread-articles-in-group info (gnus-active group))
12135         t))))
12136
12137 (defun gnus-offer-save-summaries ()
12138   "Offer to save all active summary buffers."
12139   (let (buffers)
12140     ;; Go through all buffers and find all summaries.
12141     (dolist (buffer (buffer-list))
12142       (when (and (setq buffer (buffer-name buffer))
12143                  (string-match "Summary" buffer)
12144                  (with-current-buffer buffer
12145                    ;; We check that this is, indeed, a summary buffer.
12146                    (and (eq major-mode 'gnus-summary-mode)
12147                         ;; Also make sure this isn't bogus.
12148                         gnus-newsgroup-prepared
12149                         ;; Also make sure that this isn't a
12150                         ;; dead summary buffer.
12151                         (not gnus-dead-summary-mode))))
12152         (push buffer buffers)))
12153     ;; Go through all these summary buffers and offer to save them.
12154     (when buffers
12155       (save-excursion
12156         (map-y-or-n-p
12157          "Update summary buffer %s? "
12158          (lambda (buf)
12159            (switch-to-buffer buf)
12160            (gnus-summary-exit))
12161          buffers)))))
12162
12163 (defun gnus-summary-setup-default-charset ()
12164   "Setup newsgroup default charset."
12165   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12166       (setq gnus-newsgroup-charset nil)
12167     (let* ((ignored-charsets
12168             (or gnus-newsgroup-ephemeral-ignored-charsets
12169                 (append
12170                  (and gnus-newsgroup-name
12171                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12172                  gnus-newsgroup-ignored-charsets))))
12173       (setq gnus-newsgroup-charset
12174             (or gnus-newsgroup-ephemeral-charset
12175                 (and gnus-newsgroup-name
12176                      (gnus-parameter-charset gnus-newsgroup-name))
12177                 gnus-default-charset))
12178       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12179            ignored-charsets))))
12180
12181 ;;;
12182 ;;; Mime Commands
12183 ;;;
12184
12185 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12186   "Display the current article buffer fully MIME-buttonized.
12187 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12188 treated as multipart/mixed."
12189   (interactive "P")
12190   (require 'gnus-art)
12191   (let ((gnus-unbuttonized-mime-types nil)
12192         (gnus-mime-display-multipart-as-mixed show-all-parts))
12193     (gnus-summary-show-article)))
12194
12195 (defun gnus-summary-repair-multipart (article)
12196   "Add a Content-Type header to a multipart article without one."
12197   (interactive (list (gnus-summary-article-number)))
12198   (gnus-with-article article
12199     (message-narrow-to-head)
12200     (message-remove-header "Mime-Version")
12201     (goto-char (point-max))
12202     (insert "Mime-Version: 1.0\n")
12203     (widen)
12204     (when (search-forward "\n--" nil t)
12205       (let ((separator (buffer-substring (point) (point-at-eol))))
12206         (message-narrow-to-head)
12207         (message-remove-header "Content-Type")
12208         (goto-char (point-max))
12209         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12210                         separator))
12211         (widen))))
12212   (let (gnus-mark-article-hook)
12213     (gnus-summary-select-article t t nil article)))
12214
12215 (defun gnus-summary-toggle-display-buttonized ()
12216   "Toggle the buttonizing of the article buffer."
12217   (interactive)
12218   (require 'gnus-art)
12219   (if (setq gnus-inhibit-mime-unbuttonizing
12220             (not gnus-inhibit-mime-unbuttonizing))
12221       (let ((gnus-unbuttonized-mime-types nil))
12222         (gnus-summary-show-article))
12223     (gnus-summary-show-article)))
12224
12225 ;;;
12226 ;;; Generic summary marking commands
12227 ;;;
12228
12229 (defvar gnus-summary-marking-alist
12230   '((read gnus-del-mark "d")
12231     (unread gnus-unread-mark "u")
12232     (ticked gnus-ticked-mark "!")
12233     (dormant gnus-dormant-mark "?")
12234     (expirable gnus-expirable-mark "e"))
12235   "An alist of names/marks/keystrokes.")
12236
12237 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12238 (defvar gnus-summary-mark-map)
12239
12240 (defun gnus-summary-make-all-marking-commands ()
12241   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12242   (dolist (elem gnus-summary-marking-alist)
12243     (apply 'gnus-summary-make-marking-command elem)))
12244
12245 (defun gnus-summary-make-marking-command (name mark keystroke)
12246   (let ((map (make-sparse-keymap)))
12247     (define-key gnus-summary-generic-mark-map keystroke map)
12248     (dolist (lway `((next "next" next nil "n")
12249                     (next-unread "next unread" next t "N")
12250                     (prev "previous" prev nil "p")
12251                     (prev-unread "previous unread" prev t "P")
12252                     (nomove "" nil nil ,keystroke)))
12253       (let ((func (gnus-summary-make-marking-command-1
12254                    mark (car lway) lway name)))
12255         (setq func (eval func))
12256         (define-key map (nth 4 lway) func)))))
12257
12258 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12259   `(defun ,(intern
12260             (format "gnus-summary-put-mark-as-%s%s"
12261                     name (if (eq way 'nomove)
12262                              ""
12263                            (concat "-" (symbol-name way)))))
12264      (n)
12265      ,(format
12266        "Mark the current article as %s%s.
12267 If N, the prefix, then repeat N times.
12268 If N is negative, move in reverse order.
12269 The difference between N and the actual number of articles marked is
12270 returned."
12271        name (cadr lway))
12272      (interactive "p")
12273      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12274
12275 (defun gnus-summary-generic-mark (n mark move unread)
12276   "Mark N articles with MARK."
12277   (unless (eq major-mode 'gnus-summary-mode)
12278     (error "This command can only be used in the summary buffer"))
12279   (gnus-summary-show-thread)
12280   (let ((nummove
12281          (cond
12282           ((eq move 'next) 1)
12283           ((eq move 'prev) -1)
12284           (t 0))))
12285     (if (zerop nummove)
12286         (setq n 1)
12287       (when (< n 0)
12288         (setq n (abs n)
12289               nummove (* -1 nummove))))
12290     (while (and (> n 0)
12291                 (gnus-summary-mark-article nil mark)
12292                 (zerop (gnus-summary-next-subject nummove unread t)))
12293       (setq n (1- n)))
12294     (when (/= 0 n)
12295       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12296     (gnus-summary-recenter)
12297     (gnus-summary-position-point)
12298     (gnus-set-mode-line 'summary)
12299     n))
12300
12301 (defun gnus-summary-insert-articles (articles)
12302   (when (setq articles
12303               (gnus-sorted-difference articles
12304                                       (mapcar (lambda (h)
12305                                                 (mail-header-number h))
12306                                               gnus-newsgroup-headers)))
12307     (setq gnus-newsgroup-headers
12308           (gnus-merge 'list
12309                       gnus-newsgroup-headers
12310                       (gnus-fetch-headers articles)
12311                       'gnus-article-sort-by-number))
12312     ;; Suppress duplicates?
12313     (when gnus-suppress-duplicates
12314       (gnus-dup-suppress-articles))
12315
12316     (if (and gnus-fetch-old-headers
12317              (eq gnus-headers-retrieved-by 'nov))
12318         ;; We might want to build some more threads first.
12319         (if (eq gnus-fetch-old-headers 'invisible)
12320             (gnus-build-all-threads)
12321           (gnus-build-old-threads))
12322       ;; Mark the inserted articles that are unread as unread.
12323       (setq gnus-newsgroup-unreads
12324             (gnus-sorted-nunion
12325              gnus-newsgroup-unreads
12326              (gnus-sorted-nintersection
12327               (gnus-list-of-unread-articles gnus-newsgroup-name)
12328               articles)))
12329       ;; Mark the inserted articles as selected so that the information
12330       ;; of the marks having been changed by a user may be updated when
12331       ;; exiting this group.  See `gnus-summary-update-info'.
12332       (dolist (art articles)
12333         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12334     ;; Let the Gnus agent mark articles as read.
12335     (when gnus-agent
12336       (gnus-agent-get-undownloaded-list))
12337     ;; Remove list identifiers from subject
12338     (when gnus-list-identifiers
12339       (gnus-summary-remove-list-identifiers))
12340     ;; First and last article in this newsgroup.
12341     (when gnus-newsgroup-headers
12342       (setq gnus-newsgroup-begin
12343             (mail-header-number (car gnus-newsgroup-headers))
12344             gnus-newsgroup-end
12345             (mail-header-number
12346              (gnus-last-element gnus-newsgroup-headers))))
12347     (when gnus-use-scoring
12348       (gnus-possibly-score-headers))))
12349
12350 (defun gnus-summary-insert-old-articles (&optional all)
12351   "Insert all old articles in this group.
12352 If ALL is non-nil, already read articles become readable.
12353 If ALL is a number, fetch this number of articles."
12354   (interactive "P")
12355   (prog1
12356       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12357             older len)
12358         (setq older
12359               ;; Some nntp servers lie about their active range.  When
12360               ;; this happens, the active range can be in the millions.
12361               ;; Use a compressed range to avoid creating a huge list.
12362               (gnus-range-difference (list gnus-newsgroup-active) old))
12363         (setq len (gnus-range-length older))
12364         (cond
12365          ((null older) nil)
12366          ((numberp all)
12367           (if (< all len)
12368               (let ((older-range (nreverse older)))
12369                 (setq older nil)
12370
12371                 (while (> all 0)
12372                   (let* ((r (pop older-range))
12373                          (min (if (numberp r) r (car r)))
12374                          (max (if (numberp r) r (cdr r))))
12375                     (while (and (<= min max)
12376                                 (> all 0))
12377                       (push max older)
12378                       (setq all (1- all)
12379                             max (1- max))))))
12380             (setq older (gnus-uncompress-range older))))
12381          (all
12382           (setq older (gnus-uncompress-range older)))
12383          (t
12384           (when (and (numberp gnus-large-newsgroup)
12385                    (> len gnus-large-newsgroup))
12386               (let* ((cursor-in-echo-area nil)
12387                      (initial (gnus-parameter-large-newsgroup-initial
12388                                gnus-newsgroup-name))
12389                      (input
12390                       (read-string
12391                        (format
12392                         "How many articles from %s (%s %d): "
12393                         (gnus-group-decoded-name gnus-newsgroup-name)
12394                         (if initial "max" "default")
12395                         len)
12396                        (if initial
12397                            (cons (number-to-string initial)
12398                                  0)))))
12399                 (unless (string-match "^[ \t]*$" input)
12400                   (setq all (string-to-number input))
12401                   (if (< all len)
12402                       (let ((older-range (nreverse older)))
12403                         (setq older nil)
12404
12405                         (while (> all 0)
12406                           (let* ((r (pop older-range))
12407                                  (min (if (numberp r) r (car r)))
12408                                  (max (if (numberp r) r (cdr r))))
12409                             (while (and (<= min max)
12410                                         (> all 0))
12411                               (push max older)
12412                               (setq all (1- all)
12413                                     max (1- max))))))))))
12414           (setq older (gnus-uncompress-range older))))
12415         (if (not older)
12416             (message "No old news.")
12417           (gnus-summary-insert-articles older)
12418           (gnus-summary-limit (gnus-sorted-nunion old older))))
12419     (gnus-summary-position-point)))
12420
12421 (defun gnus-summary-insert-new-articles ()
12422   "Insert all new articles in this group."
12423   (interactive)
12424   (prog1
12425       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12426             (old-active gnus-newsgroup-active)
12427             (nnmail-fetched-sources (list t))
12428             i new)
12429         (setq gnus-newsgroup-active
12430               (gnus-activate-group gnus-newsgroup-name 'scan))
12431         (setq i (cdr gnus-newsgroup-active))
12432         (while (> i (cdr old-active))
12433           (push i new)
12434           (decf i))
12435         (if (not new)
12436             (message "No gnus is bad news")
12437           (gnus-summary-insert-articles new)
12438           (setq gnus-newsgroup-unreads
12439                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12440           (gnus-summary-limit (gnus-sorted-nunion old new))))
12441     (gnus-summary-position-point)))
12442
12443 (gnus-summary-make-all-marking-commands)
12444
12445 (gnus-ems-redefine)
12446
12447 (provide 'gnus-sum)
12448
12449 (run-hooks 'gnus-sum-load-hook)
12450
12451 ;; Local Variables:
12452 ;; coding: iso-8859-1
12453 ;; End:
12454
12455 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12456 ;;; gnus-sum.el ends here