* gnus.el (gnus-maximum-newsgroup): New variable.
[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                (if gnus-maximum-newsgroup
5646                    (let ((active (gnus-active group)))
5647                      (gnus-uncompress-range
5648                       (cons (max (car active)
5649                                  (- (cdr active) gnus-maximum-newsgroup -1))
5650                             (cdr active))))
5651                  (gnus-uncompress-range (gnus-active group)))
5652                (gnus-cache-articles-in-group group))
5653             ;; Select only the "normal" subset of articles.
5654             (gnus-sorted-nunion
5655              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5656              gnus-newsgroup-unreads)))
5657          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5658          (scored (length scored-list))
5659          (number (length articles))
5660          (marked (+ (length gnus-newsgroup-marked)
5661                     (length gnus-newsgroup-dormant)))
5662          (select
5663           (cond
5664            ((numberp read-all)
5665             read-all)
5666            ((numberp gnus-newsgroup-display)
5667             gnus-newsgroup-display)
5668            (t
5669             (condition-case ()
5670                 (cond
5671                  ((and (or (<= scored marked) (= scored number))
5672                        (numberp gnus-large-newsgroup)
5673                        (> number gnus-large-newsgroup))
5674                   (let* ((cursor-in-echo-area nil)
5675                          (initial (gnus-parameter-large-newsgroup-initial
5676                                    gnus-newsgroup-name))
5677                          (input
5678                           (read-string
5679                            (format
5680                             "How many articles from %s (%s %d): "
5681                             (gnus-group-decoded-name gnus-newsgroup-name)
5682                             (if initial "max" "default")
5683                             number)
5684                            (if initial
5685                                (cons (number-to-string initial)
5686                                      0)))))
5687                     (if (string-match "^[ \t]*$" input) number input)))
5688                  ((and (> scored marked) (< scored number)
5689                        (> (- scored number) 20))
5690                   (let ((input
5691                          (read-string
5692                           (format "%s %s (%d scored, %d total): "
5693                                   "How many articles from"
5694                                   (gnus-group-decoded-name group)
5695                                   scored number))))
5696                     (if (string-match "^[ \t]*$" input)
5697                         number input)))
5698                  (t number))
5699               (quit
5700                (message "Quit getting the articles to read")
5701                nil))))))
5702     (setq select (if (stringp select) (string-to-number select) select))
5703     (if (or (null select) (zerop select))
5704         select
5705       (if (and (not (zerop scored)) (<= (abs select) scored))
5706           (progn
5707             (setq articles (sort scored-list '<))
5708             (setq number (length articles)))
5709         (setq articles (copy-sequence articles)))
5710
5711       (when (< (abs select) number)
5712         (if (< select 0)
5713             ;; Select the N oldest articles.
5714             (setcdr (nthcdr (1- (abs select)) articles) nil)
5715           ;; Select the N most recent articles.
5716           (setq articles (nthcdr (- number select) articles))))
5717       (setq gnus-newsgroup-unselected
5718             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5719       (when gnus-alter-articles-to-read-function
5720         (setq articles
5721               (sort
5722                (funcall gnus-alter-articles-to-read-function
5723                         gnus-newsgroup-name articles)
5724                '<)))
5725       articles)))
5726
5727 (defun gnus-killed-articles (killed articles)
5728   (let (out)
5729     (while articles
5730       (when (inline (gnus-member-of-range (car articles) killed))
5731         (push (car articles) out))
5732       (setq articles (cdr articles)))
5733     out))
5734
5735 (defun gnus-uncompress-marks (marks)
5736   "Uncompress the mark ranges in MARKS."
5737   (let ((uncompressed '(score bookmark))
5738         out)
5739     (while marks
5740       (if (memq (caar marks) uncompressed)
5741           (push (car marks) out)
5742         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5743       (setq marks (cdr marks)))
5744     out))
5745
5746 (defun gnus-article-mark-to-type (mark)
5747   "Return the type of MARK."
5748   (or (cadr (assq mark gnus-article-special-mark-lists))
5749       'list))
5750
5751 (defun gnus-article-unpropagatable-p (mark)
5752   "Return whether MARK should be propagated to back end."
5753   (memq mark gnus-article-unpropagated-mark-lists))
5754
5755 (defun gnus-adjust-marked-articles (info)
5756   "Set all article lists and remove all marks that are no longer valid."
5757   (let* ((marked-lists (gnus-info-marks info))
5758          (active (gnus-active (gnus-info-group info)))
5759          (min (car active))
5760          (max (cdr active))
5761          (types gnus-article-mark-lists)
5762          marks var articles article mark mark-type
5763          bgn end)
5764
5765     (dolist (marks marked-lists)
5766       (setq mark (car marks)
5767             mark-type (gnus-article-mark-to-type mark)
5768             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5769
5770       ;; We set the variable according to the type of the marks list,
5771       ;; and then adjust the marks to a subset of the active articles.
5772       (cond
5773        ;; Adjust "simple" lists - compressed yet unsorted
5774        ((eq mark-type 'list)
5775         ;; Simultaneously uncompress and clip to active range
5776         ;; See gnus-uncompress-range for a description of possible marks
5777         (let (l lh)
5778           (if (not (cadr marks))
5779               (set var nil)
5780             (setq articles (if (numberp (cddr marks))
5781                                (list (cdr marks))
5782                              (cdr marks))
5783                   lh (cons nil nil)
5784                   l lh)
5785
5786             (while (setq article (pop articles))
5787               (cond ((consp article)
5788                      (setq bgn (max (car article) min)
5789                            end (min (cdr article) max))
5790                      (while (<= bgn end)
5791                        (setq l (setcdr l (cons bgn nil))
5792                              bgn (1+ bgn))))
5793                     ((and (<= min article)
5794                           (>= max article))
5795                      (setq l (setcdr l (cons article nil))))))
5796             (set var (cdr lh)))))
5797        ;; Adjust assocs.
5798        ((eq mark-type 'tuple)
5799         (set var (setq articles (cdr marks)))
5800         (when (not (listp (cdr (symbol-value var))))
5801           (set var (list (symbol-value var))))
5802         (when (not (listp (cdr articles)))
5803           (setq articles (list articles)))
5804         (while articles
5805           (when (or (not (consp (setq article (pop articles))))
5806                     (< (car article) min)
5807                     (> (car article) max))
5808             (set var (delq article (symbol-value var))))))
5809        ;; Adjust ranges (sloppily).
5810        ((eq mark-type 'range)
5811         (cond
5812          ((eq mark 'seen)
5813           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5814           ;; It should be (seen (NUM1 . NUM2)).
5815           (when (numberp (cddr marks))
5816             (setcdr marks (list (cdr marks))))
5817           (setq articles (cdr marks))
5818           (while (and articles
5819                       (or (and (consp (car articles))
5820                                (> min (cdar articles)))
5821                           (and (numberp (car articles))
5822                                (> min (car articles)))))
5823             (pop articles))
5824           (set var articles))))))))
5825
5826 (defun gnus-update-missing-marks (missing)
5827   "Go through the list of MISSING articles and remove them from the mark lists."
5828   (when missing
5829     (let (var m)
5830       ;; Go through all types.
5831       (dolist (elem gnus-article-mark-lists)
5832         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5833           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5834           (when (symbol-value var)
5835             ;; This list has articles.  So we delete all missing
5836             ;; articles from it.
5837             (setq m missing)
5838             (while m
5839               (set var (delq (pop m) (symbol-value var))))))))))
5840
5841 (defun gnus-update-marks ()
5842   "Enter the various lists of marked articles into the newsgroup info list."
5843   (let ((types gnus-article-mark-lists)
5844         (info (gnus-get-info gnus-newsgroup-name))
5845         type list newmarked symbol delta-marks)
5846     (when info
5847       ;; Add all marks lists to the list of marks lists.
5848       (while (setq type (pop types))
5849         (setq list (symbol-value
5850                     (setq symbol
5851                           (intern (format "gnus-newsgroup-%s" (car type))))))
5852
5853         (when list
5854           ;; Get rid of the entries of the articles that have the
5855           ;; default score.
5856           (when (and (eq (cdr type) 'score)
5857                      gnus-save-score
5858                      list)
5859             (let* ((arts list)
5860                    (prev (cons nil list))
5861                    (all prev))
5862               (while arts
5863                 (if (or (not (consp (car arts)))
5864                         (= (cdar arts) gnus-summary-default-score))
5865                     (setcdr prev (cdr arts))
5866                   (setq prev arts))
5867                 (setq arts (cdr arts)))
5868               (setq list (cdr all)))))
5869
5870         (when (eq (cdr type) 'seen)
5871           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5872
5873         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5874           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5875
5876         (when (and (gnus-check-backend-function
5877                     'request-set-mark gnus-newsgroup-name)
5878                    (not (gnus-article-unpropagatable-p (cdr type))))
5879           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5880                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5881                  (add (gnus-remove-from-range
5882                        (gnus-copy-sequence list) old)))
5883             (when add
5884               (push (list add 'add (list (cdr type))) delta-marks))
5885             (when del
5886               (push (list del 'del (list (cdr type))) delta-marks))))
5887
5888         (when list
5889           (push (cons (cdr type) list) newmarked)))
5890
5891       (when delta-marks
5892         (unless (gnus-check-group gnus-newsgroup-name)
5893           (error "Can't open server for %s" gnus-newsgroup-name))
5894         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5895
5896       ;; Enter these new marks into the info of the group.
5897       (if (nthcdr 3 info)
5898           (setcar (nthcdr 3 info) newmarked)
5899         ;; Add the marks lists to the end of the info.
5900         (when newmarked
5901           (setcdr (nthcdr 2 info) (list newmarked))))
5902
5903       ;; Cut off the end of the info if there's nothing else there.
5904       (let ((i 5))
5905         (while (and (> i 2)
5906                     (not (nth i info)))
5907           (when (nthcdr (decf i) info)
5908             (setcdr (nthcdr i info) nil)))))))
5909
5910 (defun gnus-set-mode-line (where)
5911   "Set the mode line of the article or summary buffers.
5912 If WHERE is `summary', the summary mode line format will be used."
5913   ;; Is this mode line one we keep updated?
5914   (when (and (memq where gnus-updated-mode-lines)
5915              (symbol-value
5916               (intern (format "gnus-%s-mode-line-format-spec" where))))
5917     (let (mode-string)
5918       (save-excursion
5919         ;; We evaluate this in the summary buffer since these
5920         ;; variables are buffer-local to that buffer.
5921         (set-buffer gnus-summary-buffer)
5922        ;; We bind all these variables that are used in the `eval' form
5923         ;; below.
5924         (let* ((mformat (symbol-value
5925                          (intern
5926                           (format "gnus-%s-mode-line-format-spec" where))))
5927                (gnus-tmp-group-name (gnus-mode-string-quote
5928                                      (gnus-group-decoded-name
5929                                       gnus-newsgroup-name)))
5930                (gnus-tmp-article-number (or gnus-current-article 0))
5931                (gnus-tmp-unread gnus-newsgroup-unreads)
5932                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5933                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5934                (gnus-tmp-unread-and-unselected
5935                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5936                             (zerop gnus-tmp-unselected))
5937                        "")
5938                       ((zerop gnus-tmp-unselected)
5939                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5940                       (t (format "{%d(+%d) more}"
5941                                  gnus-tmp-unread-and-unticked
5942                                  gnus-tmp-unselected))))
5943                (gnus-tmp-subject
5944                 (if (and gnus-current-headers
5945                          (vectorp gnus-current-headers))
5946                     (gnus-mode-string-quote
5947                      (mail-header-subject gnus-current-headers))
5948                   ""))
5949                bufname-length max-len
5950                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5951           (setq mode-string (eval mformat))
5952           (setq bufname-length (if (string-match "%b" mode-string)
5953                                    (- (length
5954                                        (buffer-name
5955                                         (if (eq where 'summary)
5956                                             nil
5957                                           (get-buffer gnus-article-buffer))))
5958                                       2)
5959                                  0))
5960           (setq max-len (max 4 (if gnus-mode-non-string-length
5961                                    (- (window-width)
5962                                       gnus-mode-non-string-length
5963                                       bufname-length)
5964                                  (length mode-string))))
5965           ;; We might have to chop a bit of the string off...
5966           (when (> (length mode-string) max-len)
5967             (setq mode-string
5968                   (concat (truncate-string-to-width mode-string (- max-len 3))
5969                           "...")))
5970           ;; Pad the mode string a bit.
5971           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5972       ;; Update the mode line.
5973       (setq mode-line-buffer-identification
5974             (gnus-mode-line-buffer-identification (list mode-string)))
5975       (set-buffer-modified-p t))))
5976
5977 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5978   "Go through the HEADERS list and add all Xrefs to a hash table.
5979 The resulting hash table is returned, or nil if no Xrefs were found."
5980   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5981          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5982          (xref-hashtb (gnus-make-hashtable))
5983          start group entry number xrefs header)
5984     (while headers
5985       (setq header (pop headers))
5986       (when (and (setq xrefs (mail-header-xref header))
5987                  (not (memq (setq number (mail-header-number header))
5988                             unreads)))
5989         (setq start 0)
5990         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5991           (setq start (match-end 0))
5992           (setq group (if prefix
5993                           (concat prefix (substring xrefs (match-beginning 1)
5994                                                     (match-end 1)))
5995                         (substring xrefs (match-beginning 1) (match-end 1))))
5996           (setq number
5997                 (string-to-number (substring xrefs (match-beginning 2)
5998                                           (match-end 2))))
5999           (if (setq entry (gnus-gethash group xref-hashtb))
6000               (setcdr entry (cons number (cdr entry)))
6001             (gnus-sethash group (cons number nil) xref-hashtb)))))
6002     (and start xref-hashtb)))
6003
6004 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6005   "Look through all the headers and mark the Xrefs as read."
6006   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6007         name info xref-hashtb idlist method nth4)
6008     (save-excursion
6009       (set-buffer gnus-group-buffer)
6010       (when (setq xref-hashtb
6011                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6012         (mapatoms
6013          (lambda (group)
6014            (unless (string= from-newsgroup (setq name (symbol-name group)))
6015              (setq idlist (symbol-value group))
6016              ;; Dead groups are not updated.
6017              (and (prog1
6018                       (setq info (gnus-get-info name))
6019                     (when (stringp (setq nth4 (gnus-info-method info)))
6020                       (setq nth4 (gnus-server-to-method nth4))))
6021                   ;; Only do the xrefs if the group has the same
6022                   ;; select method as the group we have just read.
6023                   (or (gnus-methods-equal-p
6024                        nth4 (gnus-find-method-for-group from-newsgroup))
6025                       virtual
6026                       (equal nth4 (setq method (gnus-find-method-for-group
6027                                                 from-newsgroup)))
6028                       (and (equal (car nth4) (car method))
6029                            (equal (nth 1 nth4) (nth 1 method))))
6030                   gnus-use-cross-reference
6031                   (or (not (eq gnus-use-cross-reference t))
6032                       virtual
6033                       ;; Only do cross-references on subscribed
6034                       ;; groups, if that is what is wanted.
6035                       (<= (gnus-info-level info) gnus-level-subscribed))
6036                   (gnus-group-make-articles-read name idlist))))
6037          xref-hashtb)))))
6038
6039 (defun gnus-compute-read-articles (group articles)
6040   (let* ((entry (gnus-group-entry group))
6041          (info (nth 2 entry))
6042          (active (gnus-active group))
6043          ninfo)
6044     (when entry
6045       ;; First peel off all invalid article numbers.
6046       (when active
6047         (let ((ids articles)
6048               id first)
6049           (while (setq id (pop ids))
6050             (when (and first (> id (cdr active)))
6051               ;; We'll end up in this situation in one particular
6052               ;; obscure situation.  If you re-scan a group and get
6053               ;; a new article that is cross-posted to a different
6054               ;; group that has not been re-scanned, you might get
6055               ;; crossposted article that has a higher number than
6056               ;; Gnus believes possible.  So we re-activate this
6057               ;; group as well.  This might mean doing the
6058               ;; crossposting thingy will *increase* the number
6059               ;; of articles in some groups.  Tsk, tsk.
6060               (setq active (or (gnus-activate-group group) active)))
6061             (when (or (> id (cdr active))
6062                       (< id (car active)))
6063               (setq articles (delq id articles))))))
6064       ;; If the read list is nil, we init it.
6065       (if (and active
6066                (null (gnus-info-read info))
6067                (> (car active) 1))
6068           (setq ninfo (cons 1 (1- (car active))))
6069         (setq ninfo (gnus-info-read info)))
6070       ;; Then we add the read articles to the range.
6071       (gnus-add-to-range
6072        ninfo (setq articles (sort articles '<))))))
6073
6074 (defun gnus-group-make-articles-read (group articles)
6075   "Update the info of GROUP to say that ARTICLES are read."
6076   (let* ((num 0)
6077          (entry (gnus-group-entry group))
6078          (info (nth 2 entry))
6079          (active (gnus-active group))
6080          range)
6081     (when entry
6082       (setq range (gnus-compute-read-articles group articles))
6083       (with-current-buffer gnus-group-buffer
6084         (gnus-undo-register
6085           `(progn
6086              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6087              (gnus-info-set-read ',info ',(gnus-info-read info))
6088              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6089              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6090              (gnus-group-update-group ,group t))))
6091       ;; Add the read articles to the range.
6092       (gnus-info-set-read info range)
6093       (gnus-request-set-mark group (list (list range 'add '(read))))
6094       ;; Then we have to re-compute how many unread
6095       ;; articles there are in this group.
6096       (when active
6097         (cond
6098          ((not range)
6099           (setq num (- (1+ (cdr active)) (car active))))
6100          ((not (listp (cdr range)))
6101           (setq num (- (cdr active) (- (1+ (cdr range))
6102                                        (car range)))))
6103          (t
6104           (while range
6105             (if (numberp (car range))
6106                 (setq num (1+ num))
6107               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6108             (setq range (cdr range)))
6109           (setq num (- (cdr active) num))))
6110         ;; Update the number of unread articles.
6111         (setcar entry num)
6112         ;; Update the group buffer.
6113         (unless (gnus-ephemeral-group-p group)
6114           (gnus-group-update-group group t))))))
6115
6116 (defvar gnus-newsgroup-none-id 0)
6117
6118 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6119   (let ((cur nntp-server-buffer)
6120         (dependencies
6121          (or dependencies
6122              (with-current-buffer gnus-summary-buffer
6123                gnus-newsgroup-dependencies)))
6124         headers id end ref number
6125         (mail-parse-charset gnus-newsgroup-charset)
6126         (mail-parse-ignored-charsets
6127          (save-excursion (condition-case nil
6128                              (set-buffer gnus-summary-buffer)
6129                            (error))
6130                          gnus-newsgroup-ignored-charsets)))
6131     (save-excursion
6132       (set-buffer nntp-server-buffer)
6133       ;; Translate all TAB characters into SPACE characters.
6134       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6135       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6136       (ietf-drums-unfold-fws)
6137       (gnus-run-hooks 'gnus-parse-headers-hook)
6138       (let ((case-fold-search t)
6139             in-reply-to header p lines chars)
6140         (goto-char (point-min))
6141         ;; Search to the beginning of the next header.  Error messages
6142         ;; do not begin with 2 or 3.
6143         (while (re-search-forward "^[23][0-9]+ " nil t)
6144           (setq id nil
6145                 ref nil)
6146           ;; This implementation of this function, with nine
6147           ;; search-forwards instead of the one re-search-forward and
6148           ;; a case (which basically was the old function) is actually
6149           ;; about twice as fast, even though it looks messier.  You
6150           ;; can't have everything, I guess.  Speed and elegance
6151           ;; doesn't always go hand in hand.
6152           (setq
6153            header
6154            (vector
6155             ;; Number.
6156             (prog1
6157                 (setq number (read cur))
6158               (end-of-line)
6159               (setq p (point))
6160               (narrow-to-region (point)
6161                                 (or (and (search-forward "\n.\n" nil t)
6162                                          (- (point) 2))
6163                                     (point))))
6164             ;; Subject.
6165             (progn
6166               (goto-char p)
6167               (if (search-forward "\nsubject:" nil t)
6168                   (funcall gnus-decode-encoded-word-function
6169                            (nnheader-header-value))
6170                 "(none)"))
6171             ;; From.
6172             (progn
6173               (goto-char p)
6174               (if (search-forward "\nfrom:" nil t)
6175                   (funcall gnus-decode-encoded-address-function
6176                            (nnheader-header-value))
6177                 "(nobody)"))
6178             ;; Date.
6179             (progn
6180               (goto-char p)
6181               (if (search-forward "\ndate:" nil t)
6182                   (nnheader-header-value) ""))
6183             ;; Message-ID.
6184             (progn
6185               (goto-char p)
6186               (setq id (if (re-search-forward
6187                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6188                            ;; We do it this way to make sure the Message-ID
6189                            ;; is (somewhat) syntactically valid.
6190                            (buffer-substring (match-beginning 1)
6191                                              (match-end 1))
6192                          ;; If there was no message-id, we just fake one
6193                          ;; to make subsequent routines simpler.
6194                          (nnheader-generate-fake-message-id number))))
6195             ;; References.
6196             (progn
6197               (goto-char p)
6198               (if (search-forward "\nreferences:" nil t)
6199                   (progn
6200                     (setq end (point))
6201                     (prog1
6202                         (nnheader-header-value)
6203                       (setq ref
6204                             (buffer-substring
6205                              (progn
6206                                (end-of-line)
6207                                (search-backward ">" end t)
6208                                (1+ (point)))
6209                              (progn
6210                                (search-backward "<" end t)
6211                                (point))))))
6212                 ;; Get the references from the in-reply-to header if there
6213                 ;; were no references and the in-reply-to header looks
6214                 ;; promising.
6215                 (if (and (search-forward "\nin-reply-to:" nil t)
6216                          (setq in-reply-to (nnheader-header-value))
6217                          (string-match "<[^>]+>" in-reply-to))
6218                     (let (ref2)
6219                       (setq ref (substring in-reply-to (match-beginning 0)
6220                                            (match-end 0)))
6221                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6222                         (setq ref2 (substring in-reply-to (match-beginning 0)
6223                                               (match-end 0)))
6224                         (when (> (length ref2) (length ref))
6225                           (setq ref ref2)))
6226                       ref)
6227                   (setq ref nil))))
6228             ;; Chars.
6229             (progn
6230               (goto-char p)
6231               (if (search-forward "\nchars: " nil t)
6232                   (if (numberp (setq chars (ignore-errors (read cur))))
6233                       chars -1)
6234                 -1))
6235             ;; Lines.
6236             (progn
6237               (goto-char p)
6238               (if (search-forward "\nlines: " nil t)
6239                   (if (numberp (setq lines (ignore-errors (read cur))))
6240                       lines -1)
6241                 -1))
6242             ;; Xref.
6243             (progn
6244               (goto-char p)
6245               (and (search-forward "\nxref:" nil t)
6246                    (nnheader-header-value)))
6247             ;; Extra.
6248             (when gnus-extra-headers
6249               (let ((extra gnus-extra-headers)
6250                     out)
6251                 (while extra
6252                   (goto-char p)
6253                   (when (search-forward
6254                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6255                     (push (cons (car extra) (nnheader-header-value))
6256                           out))
6257                   (pop extra))
6258                 out))))
6259           (when (equal id ref)
6260             (setq ref nil))
6261
6262           (when gnus-alter-header-function
6263             (funcall gnus-alter-header-function header)
6264             (setq id (mail-header-id header)
6265                   ref (gnus-parent-id (mail-header-references header))))
6266
6267           (when (setq header
6268                       (gnus-dependencies-add-header
6269                        header dependencies force-new))
6270             (push header headers))
6271           (goto-char (point-max))
6272           (widen))
6273         (nreverse headers)))))
6274
6275 ;; Goes through the xover lines and returns a list of vectors
6276 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6277                                                   force-new dependencies
6278                                                   group also-fetch-heads)
6279   "Parse the news overview data in the server buffer.
6280 Return a list of headers that match SEQUENCE (see
6281 `nntp-retrieve-headers')."
6282   ;; Get the Xref when the users reads the articles since most/some
6283   ;; NNTP servers do not include Xrefs when using XOVER.
6284   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6285   (let ((mail-parse-charset gnus-newsgroup-charset)
6286         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6287         (cur nntp-server-buffer)
6288         (dependencies (or dependencies gnus-newsgroup-dependencies))
6289         (allp (cond
6290                ((eq gnus-read-all-available-headers t)
6291                 t)
6292                ((and (stringp gnus-read-all-available-headers)
6293                      group)
6294                 (string-match gnus-read-all-available-headers group))
6295                (t
6296                 nil)))
6297         number headers header)
6298     (save-excursion
6299       (set-buffer nntp-server-buffer)
6300       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6301       ;; Allow the user to mangle the headers before parsing them.
6302       (gnus-run-hooks 'gnus-parse-headers-hook)
6303       (goto-char (point-min))
6304       (gnus-parse-without-error
6305         (while (and (or sequence allp)
6306                     (not (eobp)))
6307           (setq number (read cur))
6308           (when (not allp)
6309             (while (and sequence
6310                         (< (car sequence) number))
6311               (setq sequence (cdr sequence))))
6312           (when (and (or allp
6313                          (and sequence
6314                               (eq number (car sequence))))
6315                      (progn
6316                        (setq sequence (cdr sequence))
6317                        (setq header (inline
6318                                       (gnus-nov-parse-line
6319                                        number dependencies force-new)))))
6320             (push header headers))
6321           (forward-line 1)))
6322       ;; A common bug in inn is that if you have posted an article and
6323       ;; then retrieves the active file, it will answer correctly --
6324       ;; the new article is included.  However, a NOV entry for the
6325       ;; article may not have been generated yet, so this may fail.
6326       ;; We work around this problem by retrieving the last few
6327       ;; headers using HEAD.
6328       (if (or (not also-fetch-heads)
6329               (not sequence))
6330           ;; We (probably) got all the headers.
6331           (nreverse headers)
6332         (let ((gnus-nov-is-evil t))
6333           (nconc
6334            (nreverse headers)
6335            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6336              (gnus-get-newsgroup-headers))))))))
6337
6338 (defun gnus-article-get-xrefs ()
6339   "Fill in the Xref value in `gnus-current-headers', if necessary.
6340 This is meant to be called in `gnus-article-internal-prepare-hook'."
6341   (let ((headers (with-current-buffer gnus-summary-buffer
6342                    gnus-current-headers)))
6343     (or (not gnus-use-cross-reference)
6344         (not headers)
6345         (and (mail-header-xref headers)
6346              (not (string= (mail-header-xref headers) "")))
6347         (let ((case-fold-search t)
6348               xref)
6349           (save-restriction
6350             (nnheader-narrow-to-headers)
6351             (goto-char (point-min))
6352             (when (or (and (not (eobp))
6353                            (eq (downcase (char-after)) ?x)
6354                            (looking-at "Xref:"))
6355                       (search-forward "\nXref:" nil t))
6356               (goto-char (1+ (match-end 0)))
6357               (setq xref (buffer-substring (point) (point-at-eol)))
6358               (mail-header-set-xref headers xref)))))))
6359
6360 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6361   "Find article ID and insert the summary line for that article.
6362 OLD-HEADER can either be a header or a line number to insert
6363 the subject line on."
6364   (let* ((line (and (numberp old-header) old-header))
6365          (old-header (and (vectorp old-header) old-header))
6366          (header (cond ((and old-header use-old-header)
6367                         old-header)
6368                        ((and (numberp id)
6369                              (gnus-number-to-header id))
6370                         (gnus-number-to-header id))
6371                        (t
6372                         (gnus-read-header id))))
6373          (number (and (numberp id) id))
6374          d)
6375     (when header
6376       ;; Rebuild the thread that this article is part of and go to the
6377       ;; article we have fetched.
6378       (when (and (not gnus-show-threads)
6379                  old-header)
6380         (when (and number
6381                    (setq d (gnus-data-find (mail-header-number old-header))))
6382           (goto-char (gnus-data-pos d))
6383           (gnus-data-remove
6384            number
6385            (- (point-at-bol)
6386               (prog1
6387                   (1+ (point-at-eol))
6388                 (gnus-delete-line))))))
6389       ;; Remove list identifiers from subject.
6390       (when gnus-list-identifiers
6391         (let ((gnus-newsgroup-headers (list header)))
6392           (gnus-summary-remove-list-identifiers)))
6393       (when old-header
6394         (mail-header-set-number header (mail-header-number old-header)))
6395       (setq gnus-newsgroup-sparse
6396             (delq (setq number (mail-header-number header))
6397                   gnus-newsgroup-sparse))
6398       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6399       (push number gnus-newsgroup-limit)
6400       (gnus-rebuild-thread (mail-header-id header) line)
6401       (gnus-summary-goto-subject number nil t))
6402     (when (and (numberp number)
6403                (> number 0))
6404       ;; We have to update the boundaries even if we can't fetch the
6405       ;; article if ID is a number -- so that the next `P' or `N'
6406       ;; command will fetch the previous (or next) article even
6407       ;; if the one we tried to fetch this time has been canceled.
6408       (when (> number gnus-newsgroup-end)
6409         (setq gnus-newsgroup-end number))
6410       (when (< number gnus-newsgroup-begin)
6411         (setq gnus-newsgroup-begin number))
6412       (setq gnus-newsgroup-unselected
6413             (delq number gnus-newsgroup-unselected)))
6414     ;; Report back a success?
6415     (and header (mail-header-number header))))
6416
6417 ;;; Process/prefix in the summary buffer
6418
6419 (defun gnus-summary-work-articles (n)
6420   "Return a list of articles to be worked upon.
6421 The prefix argument, the list of process marked articles, and the
6422 current article will be taken into consideration."
6423   (save-excursion
6424     (set-buffer gnus-summary-buffer)
6425     (cond
6426      (n
6427       ;; A numerical prefix has been given.
6428       (setq n (prefix-numeric-value n))
6429       (let ((backward (< n 0))
6430             (n (abs (prefix-numeric-value n)))
6431             articles article)
6432         (save-excursion
6433           (while
6434               (and (> n 0)
6435                    (push (setq article (gnus-summary-article-number))
6436                          articles)
6437                    (if backward
6438                        (gnus-summary-find-prev nil article)
6439                      (gnus-summary-find-next nil article)))
6440             (decf n)))
6441         (nreverse articles)))
6442      ((and (gnus-region-active-p) (mark))
6443       (message "region active")
6444       ;; Work on the region between point and mark.
6445       (let ((max (max (point) (mark)))
6446             articles article)
6447         (save-excursion
6448           (goto-char (min (point) (mark)))
6449           (while
6450               (and
6451                (push (setq article (gnus-summary-article-number)) articles)
6452                (gnus-summary-find-next nil article)
6453                (< (point) max)))
6454           (nreverse articles))))
6455      (gnus-newsgroup-processable
6456       ;; There are process-marked articles present.
6457       ;; Save current state.
6458       (gnus-summary-save-process-mark)
6459       ;; Return the list.
6460       (reverse gnus-newsgroup-processable))
6461      (t
6462       ;; Just return the current article.
6463       (list (gnus-summary-article-number))))))
6464
6465 (defmacro gnus-summary-iterate (arg &rest forms)
6466   "Iterate over the process/prefixed articles and do FORMS.
6467 ARG is the interactive prefix given to the command.  FORMS will be
6468 executed with point over the summary line of the articles."
6469   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6470     `(let ((,articles (gnus-summary-work-articles ,arg)))
6471        (while ,articles
6472          (gnus-summary-goto-subject (car ,articles))
6473          ,@forms
6474          (pop ,articles)))))
6475
6476 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6477 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6478
6479 (defun gnus-summary-save-process-mark ()
6480   "Push the current set of process marked articles on the stack."
6481   (interactive)
6482   (push (copy-sequence gnus-newsgroup-processable)
6483         gnus-newsgroup-process-stack))
6484
6485 (defun gnus-summary-kill-process-mark ()
6486   "Push the current set of process marked articles on the stack and unmark."
6487   (interactive)
6488   (gnus-summary-save-process-mark)
6489   (gnus-summary-unmark-all-processable))
6490
6491 (defun gnus-summary-yank-process-mark ()
6492   "Pop the last process mark state off the stack and restore it."
6493   (interactive)
6494   (unless gnus-newsgroup-process-stack
6495     (error "Empty mark stack"))
6496   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6497
6498 (defun gnus-summary-process-mark-set (set)
6499   "Make SET into the current process marked articles."
6500   (gnus-summary-unmark-all-processable)
6501   (mapc 'gnus-summary-set-process-mark set))
6502
6503 ;;; Searching and stuff
6504
6505 (defun gnus-summary-search-group (&optional backward use-level)
6506   "Search for next unread newsgroup.
6507 If optional argument BACKWARD is non-nil, search backward instead."
6508   (save-excursion
6509     (set-buffer gnus-group-buffer)
6510     (when (gnus-group-search-forward
6511            backward nil (if use-level (gnus-group-group-level) nil))
6512       (gnus-group-group-name))))
6513
6514 (defun gnus-summary-best-group (&optional exclude-group)
6515   "Find the name of the best unread group.
6516 If EXCLUDE-GROUP, do not go to this group."
6517   (with-current-buffer gnus-group-buffer
6518     (save-excursion
6519       (gnus-group-best-unread-group exclude-group))))
6520
6521 (defun gnus-summary-find-next (&optional unread article backward)
6522   (if backward
6523       (gnus-summary-find-prev unread article)
6524     (let* ((dummy (gnus-summary-article-intangible-p))
6525            (article (or article (gnus-summary-article-number)))
6526            (data (gnus-data-find-list article))
6527            result)
6528       (when (and (not dummy)
6529                  (or (not gnus-summary-check-current)
6530                      (not unread)
6531                      (not (gnus-data-unread-p (car data)))))
6532         (setq data (cdr data)))
6533       (when (setq result
6534                   (if unread
6535                       (progn
6536                         (while data
6537                           (unless (memq (gnus-data-number (car data))
6538                                         (cond
6539                                          ((eq gnus-auto-goto-ignores
6540                                               'always-undownloaded)
6541                                           gnus-newsgroup-undownloaded)
6542                                          (gnus-plugged
6543                                           nil)
6544                                          ((eq gnus-auto-goto-ignores
6545                                               'unfetched)
6546                                           gnus-newsgroup-unfetched)
6547                                          ((eq gnus-auto-goto-ignores
6548                                               'undownloaded)
6549                                           gnus-newsgroup-undownloaded)))
6550                             (when (gnus-data-unread-p (car data))
6551                               (setq result (car data)
6552                                     data nil)))
6553                           (setq data (cdr data)))
6554                         result)
6555                     (car data)))
6556         (goto-char (gnus-data-pos result))
6557         (gnus-data-number result)))))
6558
6559 (defun gnus-summary-find-prev (&optional unread article)
6560   (let* ((eobp (eobp))
6561          (article (or article (gnus-summary-article-number)))
6562          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6563          result)
6564     (when (and (not eobp)
6565                (or (not gnus-summary-check-current)
6566                    (not unread)
6567                    (not (gnus-data-unread-p (car data)))))
6568       (setq data (cdr data)))
6569     (when (setq result
6570                 (if unread
6571                     (progn
6572                       (while data
6573                         (unless (memq (gnus-data-number (car data))
6574                                       (cond
6575                                        ((eq gnus-auto-goto-ignores
6576                                             'always-undownloaded)
6577                                         gnus-newsgroup-undownloaded)
6578                                        (gnus-plugged
6579                                         nil)
6580                                        ((eq gnus-auto-goto-ignores
6581                                             'unfetched)
6582                                         gnus-newsgroup-unfetched)
6583                                        ((eq gnus-auto-goto-ignores
6584                                             'undownloaded)
6585                                         gnus-newsgroup-undownloaded)))
6586                           (when (gnus-data-unread-p (car data))
6587                             (setq result (car data)
6588                                   data nil)))
6589                         (setq data (cdr data)))
6590                       result)
6591                   (car data)))
6592       (goto-char (gnus-data-pos result))
6593       (gnus-data-number result))))
6594
6595 (defun gnus-summary-find-subject (subject &optional unread backward article)
6596   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6597          (article (or article (gnus-summary-article-number)))
6598          (articles (gnus-data-list backward))
6599          (arts (gnus-data-find-list article articles))
6600          result)
6601     (when (or (not gnus-summary-check-current)
6602               (not unread)
6603               (not (gnus-data-unread-p (car arts))))
6604       (setq arts (cdr arts)))
6605     (while arts
6606       (and (or (not unread)
6607                (gnus-data-unread-p (car arts)))
6608            (vectorp (gnus-data-header (car arts)))
6609            (gnus-subject-equal
6610             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6611            (setq result (car arts)
6612                  arts nil))
6613       (setq arts (cdr arts)))
6614     (and result
6615          (goto-char (gnus-data-pos result))
6616          (gnus-data-number result))))
6617
6618 (defun gnus-summary-search-forward (&optional unread subject backward)
6619   "Search forward for an article.
6620 If UNREAD, look for unread articles.  If SUBJECT, look for
6621 articles with that subject.  If BACKWARD, search backward instead."
6622   (cond (subject (gnus-summary-find-subject subject unread backward))
6623         (backward (gnus-summary-find-prev unread))
6624         (t (gnus-summary-find-next unread))))
6625
6626 (defun gnus-recenter (&optional n)
6627   "Center point in window and redisplay frame.
6628 Also do horizontal recentering."
6629   (interactive "P")
6630   (when (and gnus-auto-center-summary
6631              (not (eq gnus-auto-center-summary 'vertical)))
6632     (gnus-horizontal-recenter))
6633   (recenter n))
6634
6635 (defun gnus-summary-recenter ()
6636   "Center point in the summary window.
6637 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6638 displayed, no centering will be performed."
6639   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6640   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6641   (interactive)
6642   ;; The user has to want it.
6643   (when gnus-auto-center-summary
6644     (let* ((top (cond ((< (window-height) 4) 0)
6645                       ((< (window-height) 7) 1)
6646                       (t (if (numberp gnus-auto-center-summary)
6647                              gnus-auto-center-summary
6648                            (/ (1- (window-height)) 2)))))
6649            (height (1- (window-height)))
6650            (bottom (save-excursion (goto-char (point-max))
6651                                    (forward-line (- height))
6652                                    (point)))
6653            (window (get-buffer-window (current-buffer))))
6654       (when (get-buffer-window gnus-article-buffer)
6655         ;; Only do recentering when the article buffer is displayed,
6656         ;; Set the window start to either `bottom', which is the biggest
6657         ;; possible valid number, or the second line from the top,
6658         ;; whichever is the least.
6659         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6660           (if (> bottom top-pos)
6661               ;; Keep the second line from the top visible
6662               (set-window-start window top-pos)
6663             ;; Try to keep the bottom line visible; if it's partially
6664             ;; obscured, either scroll one more line to make it fully
6665             ;; visible, or revert to using TOP-POS.
6666             (save-excursion
6667               (goto-char (point-max))
6668               (forward-line -1)
6669               (let ((last-line-start (point)))
6670                 (goto-char bottom)
6671                 (set-window-start window (point) t)
6672                 (when (not (pos-visible-in-window-p last-line-start window))
6673                   (forward-line 1)
6674                   (set-window-start window (min (point) top-pos) t)))))))
6675       ;; Do horizontal recentering while we're at it.
6676       (when (and (get-buffer-window (current-buffer) t)
6677                  (not (eq gnus-auto-center-summary 'vertical)))
6678         (let ((selected (selected-window)))
6679           (select-window (get-buffer-window (current-buffer) t))
6680           (gnus-summary-position-point)
6681           (gnus-horizontal-recenter)
6682           (select-window selected))))))
6683
6684 (defun gnus-summary-jump-to-group (newsgroup)
6685   "Move point to NEWSGROUP in group mode buffer."
6686   ;; Keep update point of group mode buffer if visible.
6687   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6688       (save-window-excursion
6689         ;; Take care of tree window mode.
6690         (when (get-buffer-window gnus-group-buffer)
6691           (pop-to-buffer gnus-group-buffer))
6692         (gnus-group-jump-to-group newsgroup))
6693     (save-excursion
6694       ;; Take care of tree window mode.
6695       (if (get-buffer-window gnus-group-buffer)
6696           (pop-to-buffer gnus-group-buffer)
6697         (set-buffer gnus-group-buffer))
6698       (gnus-group-jump-to-group newsgroup))))
6699
6700 ;; This function returns a list of article numbers based on the
6701 ;; difference between the ranges of read articles in this group and
6702 ;; the range of active articles.
6703 (defun gnus-list-of-unread-articles (group)
6704   (let* ((read (gnus-info-read (gnus-get-info group)))
6705          (active (or (gnus-active group) (gnus-activate-group group)))
6706          (last (or (cdr active)
6707                    (error "Group %s couldn't be activated " group)))
6708          (bottom (if gnus-maximum-newsgroup
6709                      (max (car active) (- last gnus-maximum-newsgroup -1))
6710                    (car active)))
6711          first nlast unread)
6712     ;; If none are read, then all are unread.
6713     (if (not read)
6714         (setq first bottom)
6715       ;; If the range of read articles is a single range, then the
6716       ;; first unread article is the article after the last read
6717       ;; article.  Sounds logical, doesn't it?
6718       (if (and (not (listp (cdr read)))
6719                (or (< (car read) bottom)
6720                    (progn (setq read (list read))
6721                           nil)))
6722           (setq first (max bottom (1+ (cdr read))))
6723         ;; `read' is a list of ranges.
6724         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6725                                   (caar read)))
6726                   1)
6727           (setq first bottom))
6728         (while read
6729           (when first
6730             (while (< first nlast)
6731               (setq unread (cons first unread)
6732                     first (1+ first))))
6733           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6734           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6735           (setq read (cdr read)))))
6736     ;; And add the last unread articles.
6737     (while (<= first last)
6738       (setq unread (cons first unread)
6739             first (1+ first)))
6740     ;; Return the list of unread articles.
6741     (delq 0 (nreverse unread))))
6742
6743 (defun gnus-list-of-read-articles (group)
6744   "Return a list of unread, unticked and non-dormant articles."
6745   (let* ((info (gnus-get-info group))
6746          (marked (gnus-info-marks info))
6747          (active (gnus-active group)))
6748     (and info active
6749          (gnus-list-range-difference
6750           (gnus-list-range-difference
6751            (gnus-sorted-complement
6752             (gnus-uncompress-range
6753              (if gnus-maximum-newsgroup
6754                  (cons (max (car active)
6755                             (- (cdr active) gnus-maximum-newsgroup -1))
6756                        (cdr active))
6757                active))
6758             (gnus-list-of-unread-articles group))
6759            (cdr (assq 'dormant marked)))
6760           (cdr (assq 'tick marked))))))
6761
6762 ;; This function returns a sequence of article numbers based on the
6763 ;; difference between the ranges of read articles in this group and
6764 ;; the range of active articles.
6765 (defun gnus-sequence-of-unread-articles (group)
6766   (let* ((read (gnus-info-read (gnus-get-info group)))
6767          (active (or (gnus-active group) (gnus-activate-group group)))
6768          (last (cdr active))
6769          (bottom (if gnus-maximum-newsgroup
6770                      (max (car active) (- last gnus-maximum-newsgroup -1))
6771                    (car active)))
6772          first nlast unread)
6773     ;; If none are read, then all are unread.
6774     (if (not read)
6775         (setq first bottom)
6776       ;; If the range of read articles is a single range, then the
6777       ;; first unread article is the article after the last read
6778       ;; article.  Sounds logical, doesn't it?
6779       (if (and (not (listp (cdr read)))
6780                (or (< (car read) bottom)
6781                    (progn (setq read (list read))
6782                           nil)))
6783           (setq first (max bottom (1+ (cdr read))))
6784         ;; `read' is a list of ranges.
6785         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6786                                   (caar read)))
6787                   1)
6788           (setq first bottom))
6789         (while read
6790           (when first
6791             (push (cons first nlast) unread))
6792           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6793           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6794           (setq read (cdr read)))))
6795     ;; And add the last unread articles.
6796     (cond ((not (and first last))
6797            nil)
6798           ((< first last)
6799            (push (cons first last) unread))
6800           ((= first last)
6801            (push first unread)))
6802     ;; Return the sequence of unread articles.
6803     (delq 0 (nreverse unread))))
6804
6805 ;; Various summary commands
6806
6807 (defun gnus-summary-select-article-buffer ()
6808   "Reconfigure windows to show article buffer."
6809   (interactive)
6810   (if (not (gnus-buffer-live-p gnus-article-buffer))
6811       (error "There is no article buffer for this summary buffer")
6812     (gnus-configure-windows 'article)
6813     (select-window (get-buffer-window gnus-article-buffer))))
6814
6815 (defun gnus-summary-universal-argument (arg)
6816   "Perform any operation on all articles that are process/prefixed."
6817   (interactive "P")
6818   (let ((articles (gnus-summary-work-articles arg))
6819         func article)
6820     (if (eq
6821          (setq
6822           func
6823           (key-binding
6824            (read-key-sequence
6825             (substitute-command-keys
6826              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6827          'undefined)
6828         (gnus-error 1 "Undefined key")
6829       (save-excursion
6830         (while articles
6831           (gnus-summary-goto-subject (setq article (pop articles)))
6832           (let (gnus-newsgroup-processable)
6833             (command-execute func))
6834           (gnus-summary-remove-process-mark article)))))
6835   (gnus-summary-position-point))
6836
6837 (defun gnus-summary-toggle-truncation (&optional arg)
6838   "Toggle truncation of summary lines.
6839 With ARG, turn line truncation on if ARG is positive."
6840   (interactive "P")
6841   (setq truncate-lines
6842         (if (null arg) (not truncate-lines)
6843           (> (prefix-numeric-value arg) 0)))
6844   (redraw-display))
6845
6846 (defun gnus-summary-find-for-reselect ()
6847   "Return the number of an article to stay on across a reselect.
6848 The current article is considered, then following articles, then previous
6849 articles.  An article is sought which is not cancelled and isn't a temporary
6850 insertion from another group.  If there's no such then return a dummy 0."
6851   (let (found)
6852     (dolist (rev '(nil t))
6853       (unless found      ; don't demand the reverse list if we don't need it
6854         (let ((data (gnus-data-find-list
6855                      (gnus-summary-article-number) (gnus-data-list rev))))
6856           (while (and data (not found))
6857             (if (and (< 0 (gnus-data-number (car data)))
6858                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6859                 (setq found (gnus-data-number (car data))))
6860             (setq data (cdr data))))))
6861     (or found 0)))
6862
6863 (defun gnus-summary-reselect-current-group (&optional all rescan)
6864   "Exit and then reselect the current newsgroup.
6865 The prefix argument ALL means to select all articles."
6866   (interactive "P")
6867   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6868     (error "Ephemeral groups can't be reselected"))
6869   (let ((current-subject (gnus-summary-find-for-reselect))
6870         (group gnus-newsgroup-name))
6871     (setq gnus-newsgroup-begin nil)
6872     (gnus-summary-exit nil 'leave-hidden)
6873     ;; We have to adjust the point of group mode buffer because
6874     ;; point was moved to the next unread newsgroup by exiting.
6875     (gnus-summary-jump-to-group group)
6876     (when rescan
6877       (save-excursion
6878         (gnus-group-get-new-news-this-group 1)))
6879     (gnus-group-read-group all t)
6880     (gnus-summary-goto-subject current-subject nil t)))
6881
6882 (defun gnus-summary-rescan-group (&optional all)
6883   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6884   (interactive "P")
6885   (gnus-summary-reselect-current-group all t))
6886
6887 (defun gnus-summary-update-info (&optional non-destructive)
6888   (save-excursion
6889     (let ((group gnus-newsgroup-name))
6890       (when group
6891         (when gnus-newsgroup-kill-headers
6892           (setq gnus-newsgroup-killed
6893                 (gnus-compress-sequence
6894                  (gnus-sorted-union
6895                   (gnus-list-range-intersection
6896                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6897                   gnus-newsgroup-unreads)
6898                  t)))
6899         (unless (listp (cdr gnus-newsgroup-killed))
6900           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6901         (let ((headers gnus-newsgroup-headers))
6902           ;; Set the new ranges of read articles.
6903           (with-current-buffer gnus-group-buffer
6904             (gnus-undo-force-boundary))
6905           (gnus-update-read-articles
6906            group (gnus-sorted-union
6907                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6908           ;; Set the current article marks.
6909           (let ((gnus-newsgroup-scored
6910                  (if (and (not gnus-save-score)
6911                           (not non-destructive))
6912                      nil
6913                    gnus-newsgroup-scored)))
6914             (save-excursion
6915               (gnus-update-marks)))
6916           ;; Do the cross-ref thing.
6917           (when gnus-use-cross-reference
6918             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6919           ;; Do not switch windows but change the buffer to work.
6920           (set-buffer gnus-group-buffer)
6921           (unless (gnus-ephemeral-group-p group)
6922             (gnus-group-update-group group)))))))
6923
6924 (defun gnus-summary-save-newsrc (&optional force)
6925   "Save the current number of read/marked articles in the dribble buffer.
6926 The dribble buffer will then be saved.
6927 If FORCE (the prefix), also save the .newsrc file(s)."
6928   (interactive "P")
6929   (gnus-summary-update-info t)
6930   (if force
6931       (gnus-save-newsrc-file)
6932     (gnus-dribble-save)))
6933
6934 (defun gnus-summary-exit (&optional temporary leave-hidden)
6935   "Exit reading current newsgroup, and then return to group selection mode.
6936 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6937   (interactive)
6938   (gnus-set-global-variables)
6939   (when (gnus-buffer-live-p gnus-article-buffer)
6940     (save-excursion
6941       (set-buffer gnus-article-buffer)
6942       (mm-destroy-parts gnus-article-mime-handles)
6943       ;; Set it to nil for safety reason.
6944       (setq gnus-article-mime-handle-alist nil)
6945       (setq gnus-article-mime-handles nil)))
6946   (gnus-kill-save-kill-buffer)
6947   (gnus-async-halt-prefetch)
6948   (let* ((group gnus-newsgroup-name)
6949          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6950          (gnus-group-is-exiting-p t)
6951          (mode major-mode)
6952          (group-point nil)
6953          (buf (current-buffer)))
6954     (unless quit-config
6955       ;; Do adaptive scoring, and possibly save score files.
6956       (when gnus-newsgroup-adaptive
6957         (gnus-score-adaptive))
6958       (when gnus-use-scoring
6959         (gnus-score-save)))
6960     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6961     ;; If we have several article buffers, we kill them at exit.
6962     (unless gnus-single-article-buffer
6963       (when (gnus-buffer-live-p gnus-article-buffer)
6964         (with-current-buffer gnus-article-buffer
6965           ;; Don't kill sticky article buffers
6966           (unless (eq major-mode 'gnus-sticky-article-mode)
6967             (gnus-kill-buffer gnus-article-buffer)
6968             (setq gnus-article-current nil))))
6969       (gnus-kill-buffer gnus-original-article-buffer))
6970     (when gnus-use-cache
6971       (gnus-cache-possibly-remove-articles)
6972       (gnus-cache-save-buffers))
6973     (gnus-async-prefetch-remove-group group)
6974     (when gnus-suppress-duplicates
6975       (gnus-dup-enter-articles))
6976     (when gnus-use-trees
6977       (gnus-tree-close group))
6978     (when gnus-use-cache
6979       (gnus-cache-write-active))
6980     ;; Remove entries for this group.
6981     (nnmail-purge-split-history (gnus-group-real-name group))
6982     ;; Make all changes in this group permanent.
6983     (unless quit-config
6984       (gnus-run-hooks 'gnus-exit-group-hook)
6985       (gnus-summary-update-info))
6986     (gnus-close-group group)
6987     ;; Make sure where we were, and go to next newsgroup.
6988     (set-buffer gnus-group-buffer)
6989     (unless quit-config
6990       (gnus-group-jump-to-group group))
6991     (gnus-run-hooks 'gnus-summary-exit-hook)
6992     (unless (or quit-config
6993                 (not gnus-summary-next-group-on-exit)
6994                 ;; If this group has disappeared from the summary
6995                 ;; buffer, don't skip forwards.
6996                 (not (string= group (gnus-group-group-name))))
6997       (gnus-group-next-unread-group 1))
6998     (setq group-point (point))
6999     (if temporary
7000         nil                             ;Nothing to do.
7001       (set-buffer buf)
7002       (if (not gnus-kill-summary-on-exit)
7003           (progn
7004             (gnus-deaden-summary)
7005             (setq mode nil))
7006         ;; We set all buffer-local variables to nil.  It is unclear why
7007         ;; this is needed, but if we don't, buffer-local variables are
7008         ;; not garbage-collected, it seems.  This would the lead to en
7009         ;; ever-growing Emacs.
7010         (gnus-summary-clear-local-variables)
7011         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7012           (gnus-summary-clear-local-variables))
7013         (when (get-buffer gnus-article-buffer)
7014           (bury-buffer gnus-article-buffer))
7015         ;; Return to group mode buffer.
7016         (when (eq mode 'gnus-summary-mode)
7017           (gnus-kill-buffer buf)))
7018       (setq gnus-current-select-method gnus-select-method)
7019       (set-buffer gnus-group-buffer)
7020       (if quit-config
7021           (gnus-handle-ephemeral-exit quit-config)
7022         (goto-char group-point)
7023         ;; If gnus-group-buffer is already displayed, make sure we also move
7024         ;; the cursor in the window that displays it.
7025         (let ((win (get-buffer-window (current-buffer) 0)))
7026           (if win (set-window-point win (point))))
7027         (unless leave-hidden
7028           (gnus-configure-windows 'group 'force)))
7029       ;; Clear the current group name.
7030       (unless quit-config
7031         (setq gnus-newsgroup-name nil)))))
7032
7033 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7034 (defun gnus-summary-exit-no-update (&optional no-questions)
7035   "Quit reading current newsgroup without updating read article info."
7036   (interactive)
7037   (let* ((group gnus-newsgroup-name)
7038          (gnus-group-is-exiting-p t)
7039          (gnus-group-is-exiting-without-update-p t)
7040          (quit-config (gnus-group-quit-config group)))
7041     (when (or no-questions
7042               gnus-expert-user
7043               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7044       (gnus-async-halt-prefetch)
7045       (run-hooks 'gnus-summary-prepare-exit-hook)
7046       (when (gnus-buffer-live-p gnus-article-buffer)
7047         (save-excursion
7048           (set-buffer gnus-article-buffer)
7049           (mm-destroy-parts gnus-article-mime-handles)
7050           ;; Set it to nil for safety reason.
7051           (setq gnus-article-mime-handle-alist nil)
7052           (setq gnus-article-mime-handles nil)))
7053       ;; If we have several article buffers, we kill them at exit.
7054       (unless gnus-single-article-buffer
7055         (gnus-kill-buffer gnus-article-buffer)
7056         (gnus-kill-buffer gnus-original-article-buffer)
7057         (setq gnus-article-current nil))
7058       (if (not gnus-kill-summary-on-exit)
7059           (gnus-deaden-summary)
7060         (gnus-close-group group)
7061         (gnus-summary-clear-local-variables)
7062         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7063           (gnus-summary-clear-local-variables))
7064         (gnus-kill-buffer gnus-summary-buffer))
7065       (unless gnus-single-article-buffer
7066         (setq gnus-article-current nil))
7067       (when gnus-use-trees
7068         (gnus-tree-close group))
7069       (gnus-async-prefetch-remove-group group)
7070       (when (get-buffer gnus-article-buffer)
7071         (bury-buffer gnus-article-buffer))
7072       ;; Return to the group buffer.
7073       (gnus-configure-windows 'group 'force)
7074       ;; Clear the current group name.
7075       (setq gnus-newsgroup-name nil)
7076       (unless (gnus-ephemeral-group-p group)
7077         (gnus-group-update-group group))
7078       (when (equal (gnus-group-group-name) group)
7079         (gnus-group-next-unread-group 1))
7080       (when quit-config
7081         (gnus-handle-ephemeral-exit quit-config)))))
7082
7083 (defun gnus-handle-ephemeral-exit (quit-config)
7084   "Handle movement when leaving an ephemeral group.
7085 The state which existed when entering the ephemeral is reset."
7086   (if (not (buffer-name (car quit-config)))
7087       (gnus-configure-windows 'group 'force)
7088     (set-buffer (car quit-config))
7089     (cond ((eq major-mode 'gnus-summary-mode)
7090            (gnus-set-global-variables))
7091           ((eq major-mode 'gnus-article-mode)
7092            (save-excursion
7093              ;; The `gnus-summary-buffer' variable may point
7094              ;; to the old summary buffer when using a single
7095              ;; article buffer.
7096              (unless (gnus-buffer-live-p gnus-summary-buffer)
7097                (set-buffer gnus-group-buffer))
7098              (set-buffer gnus-summary-buffer)
7099              (gnus-set-global-variables))))
7100     (if (or (eq (cdr quit-config) 'article)
7101             (eq (cdr quit-config) 'pick))
7102         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7103             (gnus-configure-windows 'pick 'force)
7104           (gnus-configure-windows (cdr quit-config) 'force))
7105       (gnus-configure-windows (cdr quit-config) 'force))
7106     (when (eq major-mode 'gnus-summary-mode)
7107       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7108                                                      next-unread-noselect))
7109           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7110                                   'next-noselect)
7111                               (gnus-summary-next-subject 1 nil t))
7112                              ((eq gnus-auto-select-on-ephemeral-exit
7113                                   'next-unread-noselect)
7114                               (gnus-summary-next-subject 1 t t))))
7115             ;; Hide the article buffer which displays the article different
7116             ;; from the one that the cursor points to in the summary buffer.
7117             (gnus-configure-windows 'summary 'force))
7118         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7119                (gnus-summary-next-subject 1))
7120               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7121                (gnus-summary-next-subject 1 t))))
7122       (gnus-summary-recenter)
7123       (gnus-summary-position-point))))
7124
7125 ;;; Dead summaries.
7126
7127 (defvar gnus-dead-summary-mode-map nil)
7128
7129 (unless gnus-dead-summary-mode-map
7130   (setq gnus-dead-summary-mode-map (make-keymap))
7131   (suppress-keymap gnus-dead-summary-mode-map)
7132   (substitute-key-definition
7133    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7134   (dolist (key '("\C-d" "\r" "\177" [delete]))
7135     (define-key gnus-dead-summary-mode-map
7136       key 'gnus-summary-wake-up-the-dead))
7137   (dolist (key '("q" "Q"))
7138     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7139
7140 (defvar gnus-dead-summary-mode nil
7141   "Minor mode for Gnus summary buffers.")
7142
7143 (defun gnus-dead-summary-mode (&optional arg)
7144   "Minor mode for Gnus summary buffers."
7145   (interactive "P")
7146   (when (eq major-mode 'gnus-summary-mode)
7147     (make-local-variable 'gnus-dead-summary-mode)
7148     (setq gnus-dead-summary-mode
7149           (if (null arg) (not gnus-dead-summary-mode)
7150             (> (prefix-numeric-value arg) 0)))
7151     (when gnus-dead-summary-mode
7152       (add-minor-mode
7153        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7154
7155 (defun gnus-deaden-summary ()
7156   "Make the current summary buffer into a dead summary buffer."
7157   ;; Kill any previous dead summary buffer.
7158   (when (and gnus-dead-summary
7159              (buffer-name gnus-dead-summary))
7160     (with-current-buffer gnus-dead-summary
7161       (when gnus-dead-summary-mode
7162         (kill-buffer (current-buffer)))))
7163   ;; Make this the current dead summary.
7164   (setq gnus-dead-summary (current-buffer))
7165   (gnus-dead-summary-mode 1)
7166   (let ((name (buffer-name)))
7167     (when (string-match "Summary" name)
7168       (rename-buffer
7169        (concat (substring name 0 (match-beginning 0)) "Dead "
7170                (substring name (match-beginning 0)))
7171        t)
7172       (bury-buffer))))
7173
7174 (defun gnus-kill-or-deaden-summary (buffer)
7175   "Kill or deaden the summary BUFFER."
7176   (save-excursion
7177     (when (and (buffer-name buffer)
7178                (not gnus-single-article-buffer))
7179       (with-current-buffer buffer
7180         (gnus-kill-buffer gnus-article-buffer)
7181         (gnus-kill-buffer gnus-original-article-buffer)))
7182     (cond
7183      ;; Kill the buffer.
7184      (gnus-kill-summary-on-exit
7185       (when (and gnus-use-trees
7186                  (gnus-buffer-exists-p buffer))
7187         (save-excursion
7188           (set-buffer buffer)
7189           (gnus-tree-close gnus-newsgroup-name)))
7190       (gnus-kill-buffer buffer))
7191      ;; Deaden the buffer.
7192      ((gnus-buffer-exists-p buffer)
7193       (save-excursion
7194         (set-buffer buffer)
7195         (gnus-deaden-summary))))))
7196
7197 (defun gnus-summary-wake-up-the-dead (&rest args)
7198   "Wake up the dead summary buffer."
7199   (interactive)
7200   (gnus-dead-summary-mode -1)
7201   (let ((name (buffer-name)))
7202     (when (string-match "Dead " name)
7203       (rename-buffer
7204        (concat (substring name 0 (match-beginning 0))
7205                (substring name (match-end 0)))
7206        t)))
7207   (gnus-message 3 "This dead summary is now alive again"))
7208
7209 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7210 (defun gnus-summary-fetch-faq (&optional faq-dir)
7211   "Fetch the FAQ for the current group.
7212 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7213 in."
7214   (interactive
7215    (list
7216     (when current-prefix-arg
7217       (completing-read
7218        "FAQ dir: " (and (listp gnus-group-faq-directory)
7219                         (mapcar 'list
7220                                 gnus-group-faq-directory))))))
7221   (let (gnus-faq-buffer)
7222     (when (setq gnus-faq-buffer
7223                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7224       (gnus-configure-windows 'summary-faq))))
7225
7226 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7227 (defun gnus-summary-describe-group (&optional force)
7228   "Describe the current newsgroup."
7229   (interactive "P")
7230   (gnus-group-describe-group force gnus-newsgroup-name))
7231
7232 (defun gnus-summary-describe-briefly ()
7233   "Describe summary mode commands briefly."
7234   (interactive)
7235   (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")))
7236
7237 ;; Walking around group mode buffer from summary mode.
7238
7239 (defun gnus-summary-next-group (&optional no-article target-group backward)
7240   "Exit current newsgroup and then select next unread newsgroup.
7241 If prefix argument NO-ARTICLE is non-nil, no article is selected
7242 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7243 previous group instead."
7244   (interactive "P")
7245   ;; Stop pre-fetching.
7246   (gnus-async-halt-prefetch)
7247   (let ((current-group gnus-newsgroup-name)
7248         (current-buffer (current-buffer))
7249         entered)
7250     ;; First we semi-exit this group to update Xrefs and all variables.
7251     ;; We can't do a real exit, because the window conf must remain
7252     ;; the same in case the user is prompted for info, and we don't
7253     ;; want the window conf to change before that...
7254     (gnus-summary-exit t)
7255     (while (not entered)
7256       ;; Then we find what group we are supposed to enter.
7257       (set-buffer gnus-group-buffer)
7258       (gnus-group-jump-to-group current-group)
7259       (setq target-group
7260             (or target-group
7261                 (if (eq gnus-keep-same-level 'best)
7262                     (gnus-summary-best-group gnus-newsgroup-name)
7263                   (gnus-summary-search-group backward gnus-keep-same-level))))
7264       (if (not target-group)
7265           ;; There are no further groups, so we return to the group
7266           ;; buffer.
7267           (progn
7268             (gnus-message 5 "Returning to the group buffer")
7269             (setq entered t)
7270             (when (gnus-buffer-live-p current-buffer)
7271               (set-buffer current-buffer)
7272               (gnus-summary-exit))
7273             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7274         ;; We try to enter the target group.
7275         (gnus-group-jump-to-group target-group)
7276         (let ((unreads (gnus-group-group-unread)))
7277           (if (and (or (eq t unreads)
7278                        (and unreads (not (zerop unreads))))
7279                    (gnus-summary-read-group
7280                     target-group nil no-article
7281                     (and (buffer-name current-buffer) current-buffer)
7282                     nil backward))
7283               (setq entered t)
7284             (setq current-group target-group
7285                   target-group nil)))))))
7286
7287 (defun gnus-summary-prev-group (&optional no-article)
7288   "Exit current newsgroup and then select previous unread newsgroup.
7289 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7290   (interactive "P")
7291   (gnus-summary-next-group no-article nil t))
7292
7293 ;; Walking around summary lines.
7294
7295 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7296   "Go to the first subject satisfying any non-nil constraint.
7297 If UNREAD is non-nil, the article should be unread.
7298 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7299 If UNSEEN is non-nil, the article should be unseen.
7300 Returns the article selected or nil if there are no matching articles."
7301   (interactive "P")
7302   (cond
7303    ;; Empty summary.
7304    ((null gnus-newsgroup-data)
7305     (gnus-message 3 "No articles in the group")
7306     nil)
7307    ;; Pick the first article.
7308    ((not (or unread undownloaded unseen))
7309     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7310     (gnus-data-number (car gnus-newsgroup-data)))
7311    ;; Find the first unread article.
7312    (t
7313     (let ((data gnus-newsgroup-data))
7314       (while (and data
7315                   (let ((num (gnus-data-number (car data))))
7316                     (or (memq num gnus-newsgroup-unfetched)
7317                         (not (or (and unread
7318                                       (memq num gnus-newsgroup-unreads))
7319                                  (and undownloaded
7320                                       (memq num gnus-newsgroup-undownloaded))
7321                                  (and unseen
7322                                       (memq num gnus-newsgroup-unseen)))))))
7323         (setq data (cdr data)))
7324       (prog1
7325           (if data
7326               (progn
7327                 (goto-char (gnus-data-pos (car data)))
7328                 (gnus-data-number (car data)))
7329             (gnus-message 3 "No more%s articles"
7330                           (let* ((r (when unread " unread"))
7331                                  (d (when undownloaded " undownloaded"))
7332                                  (s (when unseen " unseen"))
7333                                  (l (delq nil (list r d s))))
7334                             (cond ((= 3 (length l))
7335                                    (concat r "," d ", or" s))
7336                                   ((= 2 (length l))
7337                                    (concat (car l) ", or" (cadr l)))
7338                                   ((= 1 (length l))
7339                                    (car l))
7340                                   (t
7341                                    ""))))
7342             nil
7343             )
7344         (gnus-summary-position-point))))))
7345
7346 (defun gnus-summary-next-subject (n &optional unread dont-display)
7347   "Go to next N'th summary line.
7348 If N is negative, go to the previous N'th subject line.
7349 If UNREAD is non-nil, only unread articles are selected.
7350 The difference between N and the actual number of steps taken is
7351 returned."
7352   (interactive "p")
7353   (let ((backward (< n 0))
7354         (n (abs n)))
7355     (while (and (> n 0)
7356                 (if backward
7357                     (gnus-summary-find-prev unread)
7358                   (gnus-summary-find-next unread)))
7359       (unless (zerop (setq n (1- n)))
7360         (gnus-summary-show-thread)))
7361     (when (/= 0 n)
7362       (gnus-message 7 "No more%s articles"
7363                     (if unread " unread" "")))
7364     (unless dont-display
7365       (gnus-summary-recenter)
7366       (gnus-summary-position-point))
7367     n))
7368
7369 (defun gnus-summary-next-unread-subject (n)
7370   "Go to next N'th unread summary line."
7371   (interactive "p")
7372   (gnus-summary-next-subject n t))
7373
7374 (defun gnus-summary-prev-subject (n &optional unread)
7375   "Go to previous N'th summary line.
7376 If optional argument UNREAD is non-nil, only unread article is selected."
7377   (interactive "p")
7378   (gnus-summary-next-subject (- n) unread))
7379
7380 (defun gnus-summary-prev-unread-subject (n)
7381   "Go to previous N'th unread summary line."
7382   (interactive "p")
7383   (gnus-summary-next-subject (- n) t))
7384
7385 (defun gnus-summary-goto-subjects (articles)
7386   "Insert the subject header for ARTICLES in the current buffer."
7387   (save-excursion
7388     (dolist (article articles)
7389       (gnus-summary-goto-subject article t)))
7390   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7391   (gnus-summary-position-point))
7392
7393 (defun gnus-summary-goto-subject (article &optional force silent)
7394   "Go the subject line of ARTICLE.
7395 If FORCE, also allow jumping to articles not currently shown."
7396   (interactive "nArticle number: ")
7397   (unless (numberp article)
7398     (error "Article %s is not a number" article))
7399   (let ((b (point))
7400         (data (gnus-data-find article)))
7401     ;; We read in the article if we have to.
7402     (and (not data)
7403          force
7404          (gnus-summary-insert-subject
7405           article
7406           (if (or (numberp force) (vectorp force)) force)
7407           t)
7408          (setq data (gnus-data-find article)))
7409     (goto-char b)
7410     (if (not data)
7411         (progn
7412           (unless silent
7413             (gnus-message 3 "Can't find article %d" article))
7414           nil)
7415       (let ((pt (gnus-data-pos data)))
7416         (goto-char pt)
7417         (gnus-summary-set-article-display-arrow pt))
7418       (gnus-summary-position-point)
7419       article)))
7420
7421 ;; Walking around summary lines with displaying articles.
7422
7423 (defun gnus-summary-expand-window (&optional arg)
7424   "Make the summary buffer take up the entire Emacs frame.
7425 Given a prefix, will force an `article' buffer configuration."
7426   (interactive "P")
7427   (if arg
7428       (gnus-configure-windows 'article 'force)
7429     (gnus-configure-windows 'summary 'force)))
7430
7431 (defun gnus-summary-display-article (article &optional all-header)
7432   "Display ARTICLE in article buffer."
7433   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7434                (with-current-buffer gnus-article-buffer
7435                  (eq major-mode 'gnus-article-mode)))
7436     (gnus-article-setup-buffer))
7437   (gnus-set-global-variables)
7438   (with-current-buffer gnus-article-buffer
7439     (setq gnus-article-charset gnus-newsgroup-charset)
7440     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7441     (mm-enable-multibyte))
7442   (if (null article)
7443       nil
7444     (prog1
7445         (if gnus-summary-display-article-function
7446             (funcall gnus-summary-display-article-function article all-header)
7447           (gnus-article-prepare article all-header))
7448       (gnus-run-hooks 'gnus-select-article-hook)
7449       (when (and gnus-current-article
7450                  (not (zerop gnus-current-article)))
7451         (gnus-summary-goto-subject gnus-current-article))
7452       (gnus-summary-recenter)
7453       (when (and gnus-use-trees gnus-show-threads)
7454         (gnus-possibly-generate-tree article)
7455         (gnus-highlight-selected-tree article))
7456       ;; Successfully display article.
7457       (gnus-article-set-window-start
7458        (cdr (assq article gnus-newsgroup-bookmarks))))))
7459
7460 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7461   "Select the current article.
7462 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7463 non-nil, the article will be re-fetched even if it already present in
7464 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7465 be displayed."
7466   ;; Make sure we are in the summary buffer to work around bbdb bug.
7467   (unless (eq major-mode 'gnus-summary-mode)
7468     (set-buffer gnus-summary-buffer))
7469   (let ((article (or article (gnus-summary-article-number)))
7470         (all-headers (not (not all-headers))) ;Must be t or nil.
7471         gnus-summary-display-article-function)
7472     (and (not pseudo)
7473          (gnus-summary-article-pseudo-p article)
7474          (error "This is a pseudo-article"))
7475     (save-excursion
7476       (set-buffer gnus-summary-buffer)
7477       (if (or (and gnus-single-article-buffer
7478                    (or (null gnus-current-article)
7479                        (null gnus-article-current)
7480                        (null (get-buffer gnus-article-buffer))
7481                        (not (eq article (cdr gnus-article-current)))
7482                        (not (equal (car gnus-article-current)
7483                                    gnus-newsgroup-name))))
7484               (and (not gnus-single-article-buffer)
7485                    (or (null gnus-current-article)
7486                        (not (eq gnus-current-article article))))
7487               force)
7488           ;; The requested article is different from the current article.
7489           (progn
7490             (gnus-summary-display-article article all-headers)
7491             (when (gnus-buffer-live-p gnus-article-buffer)
7492               (with-current-buffer gnus-article-buffer
7493                 (if (not gnus-article-decoded-p) ;; a local variable
7494                     (mm-disable-multibyte))))
7495             (gnus-article-set-window-start
7496              (cdr (assq article gnus-newsgroup-bookmarks)))
7497             article)
7498         'old))))
7499
7500 (defun gnus-summary-force-verify-and-decrypt ()
7501   "Display buttons for signed/encrypted parts and verify/decrypt them."
7502   (interactive)
7503   (let ((mm-verify-option 'known)
7504         (mm-decrypt-option 'known)
7505         (gnus-article-emulate-mime t)
7506         (gnus-buttonized-mime-types (append (list "multipart/signed"
7507                                                   "multipart/encrypted")
7508                                             gnus-buttonized-mime-types)))
7509     (gnus-summary-select-article nil 'force)))
7510
7511 (defun gnus-summary-set-current-mark (&optional current-mark)
7512   "Obsolete function."
7513   nil)
7514
7515 (defun gnus-summary-next-article (&optional unread subject backward push)
7516   "Select the next article.
7517 If UNREAD, only unread articles are selected.
7518 If SUBJECT, only articles with SUBJECT are selected.
7519 If BACKWARD, the previous article is selected instead of the next."
7520   (interactive "P")
7521   ;; Make sure we are in the summary buffer.
7522   (unless (eq major-mode 'gnus-summary-mode)
7523     (set-buffer gnus-summary-buffer))
7524   (cond
7525    ;; Is there such an article?
7526    ((and (gnus-summary-search-forward unread subject backward)
7527          (or (gnus-summary-display-article (gnus-summary-article-number))
7528              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7529     (gnus-summary-position-point))
7530    ;; If not, we try the first unread, if that is wanted.
7531    ((and subject
7532          gnus-auto-select-same
7533          (gnus-summary-first-unread-article))
7534     (gnus-summary-position-point)
7535     (gnus-message 6 "Wrapped"))
7536    ;; Try to get next/previous article not displayed in this group.
7537    ((and gnus-auto-extend-newsgroup
7538          (not unread) (not subject))
7539     (gnus-summary-goto-article
7540      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7541      nil (count-lines (point-min) (point))))
7542    ;; Go to next/previous group.
7543    (t
7544     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7545       (gnus-summary-jump-to-group gnus-newsgroup-name))
7546     (let ((cmd last-command-char)
7547           (point
7548            (with-current-buffer gnus-group-buffer
7549              (point)))
7550           (group
7551            (if (eq gnus-keep-same-level 'best)
7552                (gnus-summary-best-group gnus-newsgroup-name)
7553              (gnus-summary-search-group backward gnus-keep-same-level))))
7554       ;; For some reason, the group window gets selected.  We change
7555       ;; it back.
7556       (select-window (get-buffer-window (current-buffer)))
7557       ;; Select next unread newsgroup automagically.
7558       (cond
7559        ((or (not gnus-auto-select-next)
7560             (not cmd))
7561         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7562        ((or (eq gnus-auto-select-next 'quietly)
7563             (and (eq gnus-auto-select-next 'slightly-quietly)
7564                  push)
7565             (and (eq gnus-auto-select-next 'almost-quietly)
7566                  (gnus-summary-last-article-p)))
7567         ;; Select quietly.
7568         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7569             (gnus-summary-exit)
7570           (gnus-message 7 "No more%s articles (%s)..."
7571                         (if unread " unread" "")
7572                         (if group (concat "selecting " group)
7573                           "exiting"))
7574           (gnus-summary-next-group nil group backward)))
7575        (t
7576         (when (gnus-key-press-event-p last-input-event)
7577           (gnus-summary-walk-group-buffer
7578            gnus-newsgroup-name cmd unread backward point))))))))
7579
7580 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7581   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7582                       (?\C-p (gnus-group-prev-unread-group 1))))
7583         (cursor-in-echo-area t)
7584         keve key group ended prompt)
7585     (save-excursion
7586       (set-buffer gnus-group-buffer)
7587       (goto-char start)
7588       (setq group
7589             (if (eq gnus-keep-same-level 'best)
7590                 (gnus-summary-best-group gnus-newsgroup-name)
7591               (gnus-summary-search-group backward gnus-keep-same-level))))
7592     (while (not ended)
7593       (setq prompt
7594             (format
7595              "No more%s articles%s " (if unread " unread" "")
7596              (if (and group
7597                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7598                  (format " (Type %s for %s [%s])"
7599                          (single-key-description cmd)
7600                          (gnus-group-decoded-name group)
7601                          (gnus-group-unread group))
7602                (format " (Type %s to exit %s)"
7603                        (single-key-description cmd)
7604                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7605       ;; Confirm auto selection.
7606       (setq key (car (setq keve (gnus-read-event-char prompt)))
7607             ended t)
7608       (cond
7609        ((assq key keystrokes)
7610         (let ((obuf (current-buffer)))
7611           (switch-to-buffer gnus-group-buffer)
7612           (when group
7613             (gnus-group-jump-to-group group))
7614           (eval (cadr (assq key keystrokes)))
7615           (setq group (gnus-group-group-name))
7616           (switch-to-buffer obuf))
7617         (setq ended nil))
7618        ((equal key cmd)
7619         (if (or (not group)
7620                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7621             (gnus-summary-exit)
7622           (gnus-summary-next-group nil group backward)))
7623        (t
7624         (push (cdr keve) unread-command-events))))))
7625
7626 (defun gnus-summary-next-unread-article ()
7627   "Select unread article after current one."
7628   (interactive)
7629   (gnus-summary-next-article
7630    (or (not (eq gnus-summary-goto-unread 'never))
7631        (gnus-summary-last-article-p (gnus-summary-article-number)))
7632    (and gnus-auto-select-same
7633         (gnus-summary-article-subject))))
7634
7635 (defun gnus-summary-prev-article (&optional unread subject)
7636   "Select the article after the current one.
7637 If UNREAD is non-nil, only unread articles are selected."
7638   (interactive "P")
7639   (gnus-summary-next-article unread subject t))
7640
7641 (defun gnus-summary-prev-unread-article ()
7642   "Select unread article before current one."
7643   (interactive)
7644   (gnus-summary-prev-article
7645    (or (not (eq gnus-summary-goto-unread 'never))
7646        (gnus-summary-first-article-p (gnus-summary-article-number)))
7647    (and gnus-auto-select-same
7648         (gnus-summary-article-subject))))
7649
7650 (defun gnus-summary-next-page (&optional lines circular stop)
7651   "Show next page of the selected article.
7652 If at the end of the current article, select the next article.
7653 LINES says how many lines should be scrolled up.
7654
7655 If CIRCULAR is non-nil, go to the start of the article instead of
7656 selecting the next article when reaching the end of the current
7657 article.
7658
7659 If STOP is non-nil, just stop when reaching the end of the message.
7660
7661 Also see the variable `gnus-article-skip-boring'."
7662   (interactive "P")
7663   (setq gnus-summary-buffer (current-buffer))
7664   (gnus-set-global-variables)
7665   (let ((article (gnus-summary-article-number))
7666         (article-window (get-buffer-window gnus-article-buffer t))
7667         endp)
7668     ;; If the buffer is empty, we have no article.
7669     (unless article
7670       (error "No article to select"))
7671     (gnus-configure-windows 'article)
7672     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7673         (if (and (eq gnus-summary-goto-unread 'never)
7674                  (not (gnus-summary-last-article-p article)))
7675             (gnus-summary-next-article)
7676           (gnus-summary-next-unread-article))
7677       (if (or (null gnus-current-article)
7678               (null gnus-article-current)
7679               (/= article (cdr gnus-article-current))
7680               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7681           ;; Selected subject is different from current article's.
7682           (gnus-summary-display-article article)
7683         (when article-window
7684           (gnus-eval-in-buffer-window gnus-article-buffer
7685             (setq endp (or (gnus-article-next-page lines)
7686                            (gnus-article-only-boring-p))))
7687           (when endp
7688             (cond (stop
7689                    (gnus-message 3 "End of message"))
7690                   (circular
7691                    (gnus-summary-beginning-of-article))
7692                   (lines
7693                    (gnus-message 3 "End of message"))
7694                   ((null lines)
7695                    (if (and (eq gnus-summary-goto-unread 'never)
7696                             (not (gnus-summary-last-article-p article)))
7697                        (gnus-summary-next-article)
7698                      (gnus-summary-next-unread-article))))))))
7699     (gnus-summary-recenter)
7700     (gnus-summary-position-point)))
7701
7702 (defun gnus-summary-prev-page (&optional lines move)
7703   "Show previous page of selected article.
7704 Argument LINES specifies lines to be scrolled down.
7705 If MOVE, move to the previous unread article if point is at
7706 the beginning of the buffer."
7707   (interactive "P")
7708   (let ((article (gnus-summary-article-number))
7709         (article-window (get-buffer-window gnus-article-buffer t))
7710         endp)
7711     (gnus-configure-windows 'article)
7712     (if (or (null gnus-current-article)
7713             (null gnus-article-current)
7714             (/= article (cdr gnus-article-current))
7715             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7716         ;; Selected subject is different from current article's.
7717         (gnus-summary-display-article article)
7718       (gnus-summary-recenter)
7719       (when article-window
7720         (gnus-eval-in-buffer-window gnus-article-buffer
7721           (setq endp (gnus-article-prev-page lines)))
7722         (when (and move endp)
7723           (cond (lines
7724                  (gnus-message 3 "Beginning of message"))
7725                 ((null lines)
7726                  (if (and (eq gnus-summary-goto-unread 'never)
7727                           (not (gnus-summary-first-article-p article)))
7728                      (gnus-summary-prev-article)
7729                    (gnus-summary-prev-unread-article))))))))
7730   (gnus-summary-position-point))
7731
7732 (defun gnus-summary-prev-page-or-article (&optional lines)
7733   "Show previous page of selected article.
7734 Argument LINES specifies lines to be scrolled down.
7735 If at the beginning of the article, go to the next article."
7736   (interactive "P")
7737   (gnus-summary-prev-page lines t))
7738
7739 (defun gnus-summary-scroll-up (lines)
7740   "Scroll up (or down) one line current article.
7741 Argument LINES specifies lines to be scrolled up (or down if negative)."
7742   (interactive "p")
7743   (gnus-configure-windows 'article)
7744   (gnus-summary-show-thread)
7745   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7746     (gnus-eval-in-buffer-window gnus-article-buffer
7747       (cond ((> lines 0)
7748              (when (gnus-article-next-page lines)
7749                (gnus-message 3 "End of message")))
7750             ((< lines 0)
7751              (gnus-article-prev-page (- lines))))))
7752   (gnus-summary-recenter)
7753   (gnus-summary-position-point))
7754
7755 (defun gnus-summary-scroll-down (lines)
7756   "Scroll down (or up) one line current article.
7757 Argument LINES specifies lines to be scrolled down (or up if negative)."
7758   (interactive "p")
7759   (gnus-summary-scroll-up (- lines)))
7760
7761 (defun gnus-summary-next-same-subject ()
7762   "Select next article which has the same subject as current one."
7763   (interactive)
7764   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7765
7766 (defun gnus-summary-prev-same-subject ()
7767   "Select previous article which has the same subject as current one."
7768   (interactive)
7769   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7770
7771 (defun gnus-summary-next-unread-same-subject ()
7772   "Select next unread article which has the same subject as current one."
7773   (interactive)
7774   (gnus-summary-next-article t (gnus-summary-article-subject)))
7775
7776 (defun gnus-summary-prev-unread-same-subject ()
7777   "Select previous unread article which has the same subject as current one."
7778   (interactive)
7779   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7780
7781 (defun gnus-summary-first-unread-article ()
7782   "Select the first unread article.
7783 Return nil if there are no unread articles."
7784   (interactive)
7785   (prog1
7786       (when (gnus-summary-first-subject t)
7787         (gnus-summary-show-thread)
7788         (gnus-summary-first-subject t)
7789         (gnus-summary-display-article (gnus-summary-article-number)))
7790     (gnus-summary-position-point)))
7791
7792 (defun gnus-summary-first-unread-subject ()
7793   "Place the point on the subject line of the first unread article.
7794 Return nil if there are no unread articles."
7795   (interactive)
7796   (prog1
7797       (when (gnus-summary-first-subject t)
7798         (gnus-summary-show-thread)
7799         (gnus-summary-first-subject t))
7800     (gnus-summary-position-point)))
7801
7802 (defun gnus-summary-first-unseen-subject ()
7803   "Place the point on the subject line of the first unseen article.
7804 Return nil if there are no unseen articles."
7805   (interactive)
7806   (prog1
7807       (when (gnus-summary-first-subject nil nil t)
7808         (gnus-summary-show-thread)
7809         (gnus-summary-first-subject nil nil t))
7810     (gnus-summary-position-point)))
7811
7812 (defun gnus-summary-first-unseen-or-unread-subject ()
7813   "Place the point on the subject line of the first unseen article or,
7814 if all article have been seen, on the subject line of the first unread
7815 article."
7816   (interactive)
7817   (prog1
7818       (unless (when (gnus-summary-first-subject nil nil t)
7819                 (gnus-summary-show-thread)
7820                 (gnus-summary-first-subject nil nil t))
7821         (when (gnus-summary-first-subject t)
7822           (gnus-summary-show-thread)
7823           (gnus-summary-first-subject t)))
7824     (gnus-summary-position-point)))
7825
7826 (defun gnus-summary-first-article ()
7827   "Select the first article.
7828 Return nil if there are no articles."
7829   (interactive)
7830   (prog1
7831       (when (gnus-summary-first-subject)
7832         (gnus-summary-show-thread)
7833         (gnus-summary-first-subject)
7834         (gnus-summary-display-article (gnus-summary-article-number)))
7835     (gnus-summary-position-point)))
7836
7837 (defun gnus-summary-best-unread-article (&optional arg)
7838   "Select the unread article with the highest score.
7839 If given a prefix argument, select the next unread article that has a
7840 score higher than the default score."
7841   (interactive "P")
7842   (let ((article (if arg
7843                      (gnus-summary-better-unread-subject)
7844                    (gnus-summary-best-unread-subject))))
7845     (if article
7846         (gnus-summary-goto-article article)
7847       (error "No unread articles"))))
7848
7849 (defun gnus-summary-best-unread-subject ()
7850   "Select the unread subject with the highest score."
7851   (interactive)
7852   (let ((best -1000000)
7853         (data gnus-newsgroup-data)
7854         article score)
7855     (while data
7856       (and (gnus-data-unread-p (car data))
7857            (> (setq score
7858                     (gnus-summary-article-score (gnus-data-number (car data))))
7859               best)
7860            (setq best score
7861                  article (gnus-data-number (car data))))
7862       (setq data (cdr data)))
7863     (when article
7864       (gnus-summary-goto-subject article))
7865     (gnus-summary-position-point)
7866     article))
7867
7868 (defun gnus-summary-better-unread-subject ()
7869   "Select the first unread subject that has a score over the default score."
7870   (interactive)
7871   (let ((data gnus-newsgroup-data)
7872         article score)
7873     (while (and (setq article (gnus-data-number (car data)))
7874                 (or (gnus-data-read-p (car data))
7875                     (not (> (gnus-summary-article-score article)
7876                             gnus-summary-default-score))))
7877       (setq data (cdr data)))
7878     (when article
7879       (gnus-summary-goto-subject article))
7880     (gnus-summary-position-point)
7881     article))
7882
7883 (defun gnus-summary-last-subject ()
7884   "Go to the last displayed subject line in the group."
7885   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7886     (when article
7887       (gnus-summary-goto-subject article))))
7888
7889 (defun gnus-summary-goto-article (article &optional all-headers force)
7890   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7891 If ALL-HEADERS is non-nil, no header lines are hidden.
7892 If FORCE, go to the article even if it isn't displayed.  If FORCE
7893 is a number, it is the line the article is to be displayed on."
7894   (interactive
7895    (list
7896     (completing-read
7897      "Article number or Message-ID: "
7898      (mapcar (lambda (number) (list (int-to-string number)))
7899              gnus-newsgroup-limit))
7900     current-prefix-arg
7901     t))
7902   (prog1
7903       (if (and (stringp article)
7904                (string-match "@\\|%40" article))
7905           (gnus-summary-refer-article article)
7906         (when (stringp article)
7907           (setq article (string-to-number article)))
7908         (if (gnus-summary-goto-subject article force)
7909             (gnus-summary-display-article article all-headers)
7910           (gnus-message 4 "Couldn't go to article %s" article) nil))
7911     (gnus-summary-position-point)))
7912
7913 (defun gnus-summary-goto-last-article ()
7914   "Go to the previously read article."
7915   (interactive)
7916   (prog1
7917       (when gnus-last-article
7918         (gnus-summary-goto-article gnus-last-article nil t))
7919     (gnus-summary-position-point)))
7920
7921 (defun gnus-summary-pop-article (number)
7922   "Pop one article off the history and go to the previous.
7923 NUMBER articles will be popped off."
7924   (interactive "p")
7925   (let (to)
7926     (setq gnus-newsgroup-history
7927           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7928     (if to
7929         (gnus-summary-goto-article (car to) nil t)
7930       (error "Article history empty")))
7931   (gnus-summary-position-point))
7932
7933 ;; Summary commands and functions for limiting the summary buffer.
7934
7935 (defun gnus-summary-limit-to-articles (n)
7936   "Limit the summary buffer to the next N articles.
7937 If not given a prefix, use the process marked articles instead."
7938   (interactive "P")
7939   (prog1
7940       (let ((articles (gnus-summary-work-articles n)))
7941         (setq gnus-newsgroup-processable nil)
7942         (gnus-summary-limit articles))
7943     (gnus-summary-position-point)))
7944
7945 (defun gnus-summary-pop-limit (&optional total)
7946   "Restore the previous limit.
7947 If given a prefix, remove all limits."
7948   (interactive "P")
7949   (when total
7950     (setq gnus-newsgroup-limits
7951           (list (mapcar (lambda (h) (mail-header-number h))
7952                         gnus-newsgroup-headers))))
7953   (unless gnus-newsgroup-limits
7954     (error "No limit to pop"))
7955   (prog1
7956       (gnus-summary-limit nil 'pop)
7957     (gnus-summary-position-point)))
7958
7959 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7960   "Limit the summary buffer to articles that have subjects that match a regexp.
7961 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7962   (interactive
7963    (list (read-string (if current-prefix-arg
7964                           "Exclude subject (regexp): "
7965                         "Limit to subject (regexp): "))
7966          nil current-prefix-arg))
7967   (unless header
7968     (setq header "subject"))
7969   (when (not (equal "" subject))
7970     (prog1
7971         (let ((articles (gnus-summary-find-matching
7972                          (or header "subject") subject 'all nil nil
7973                          not-matching)))
7974           (unless articles
7975             (error "Found no matches for \"%s\"" subject))
7976           (gnus-summary-limit articles))
7977       (gnus-summary-position-point))))
7978
7979 (defun gnus-summary-limit-to-author (from &optional not-matching)
7980   "Limit the summary buffer to articles that have authors that match a regexp.
7981 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7982   (interactive
7983    (list (read-string (if current-prefix-arg
7984                           "Exclude author (regexp): "
7985                         "Limit to author (regexp): "))
7986          current-prefix-arg))
7987   (gnus-summary-limit-to-subject from "from" not-matching))
7988
7989 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7990   "Limit the summary buffer to articles with the given RECIPIENT.
7991
7992 If NOT-MATCHING, exclude RECIPIENT.
7993
7994 To and Cc headers are checked.  You need to include them in
7995 `nnmail-extra-headers'."
7996   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7997   (interactive
7998    (list (read-string (format "%s recipient (regexp): "
7999                               (if current-prefix-arg "Exclude" "Limit to")))
8000          current-prefix-arg))
8001   (when (not (equal "" recipient))
8002     (prog1 (let* ((to
8003                    (if (memq 'To nnmail-extra-headers)
8004                        (gnus-summary-find-matching
8005                         (cons 'extra 'To) recipient 'all nil nil
8006                         not-matching)
8007                      (gnus-message
8008                       1 "`To' isn't present in `nnmail-extra-headers'")
8009                      (sit-for 1)
8010                      nil))
8011                   (cc
8012                    (if (memq 'Cc nnmail-extra-headers)
8013                        (gnus-summary-find-matching
8014                         (cons 'extra 'Cc) recipient 'all nil nil
8015                         not-matching)
8016                      (gnus-message
8017                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8018                      (sit-for 1)
8019                      nil))
8020                   (articles
8021                    (if not-matching
8022                        ;; We need the numbers that are in both lists:
8023                        (mapcar (lambda (a)
8024                                  (and (memq a to) a))
8025                                cc)
8026                      (nconc to cc))))
8027              (unless articles
8028                (error "Found no matches for \"%s\"" recipient))
8029              (gnus-summary-limit articles))
8030       (gnus-summary-position-point))))
8031
8032 (defun gnus-summary-limit-to-address (address &optional not-matching)
8033   "Limit the summary buffer to articles with the given ADDRESS.
8034
8035 If NOT-MATCHING, exclude ADDRESS.
8036
8037 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8038 in `nnmail-extra-headers'."
8039   (interactive
8040    (list (read-string (format "%s address (regexp): "
8041                               (if current-prefix-arg "Exclude" "Limit to")))
8042          current-prefix-arg))
8043   (when (not (equal "" address))
8044     (prog1 (let* ((to
8045                    (if (memq 'To nnmail-extra-headers)
8046                        (gnus-summary-find-matching
8047                         (cons 'extra 'To) address 'all nil nil
8048                         not-matching)
8049                      (gnus-message
8050                       1 "`To' isn't present in `nnmail-extra-headers'")
8051                      (sit-for 1)
8052                      t))
8053                   (cc
8054                    (if (memq 'Cc nnmail-extra-headers)
8055                        (gnus-summary-find-matching
8056                         (cons 'extra 'Cc) address 'all nil nil
8057                         not-matching)
8058                      (gnus-message
8059                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8060                      (sit-for 1)
8061                      t))
8062                   (from
8063                    (gnus-summary-find-matching "from" address
8064                                                'all nil nil not-matching))
8065                   (articles
8066                    (if not-matching
8067                        ;; We need the numbers that are in all lists:
8068                        (if (eq cc t)
8069                            (if (eq to t)
8070                                from
8071                              (mapcar (lambda (a) (car (memq a from))) to))
8072                          (if (eq to t)
8073                              (mapcar (lambda (a) (car (memq a from))) cc)
8074                            (mapcar (lambda (a) (car (memq a from)))
8075                                    (mapcar (lambda (a) (car (memq a to)))
8076                                            cc))))
8077                      (nconc (if (eq to t) nil to)
8078                             (if (eq cc t) nil cc)
8079                             from))))
8080              (unless articles
8081                (error "Found no matches for \"%s\"" address))
8082              (gnus-summary-limit articles))
8083       (gnus-summary-position-point))))
8084
8085 (defun gnus-summary-limit-strange-charsets-predicate (header)
8086   (let ((string (concat (mail-header-subject header)
8087                         (mail-header-from header)))
8088         charset found)
8089     (dotimes (i (1- (length string)))
8090       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8091       (when (string-match "unicode\\|big\\|japanese" charset)
8092         (setq found t)))
8093     found))
8094
8095 (defun gnus-summary-limit-to-predicate (predicate)
8096   "Limit to articles where PREDICATE returns non-nil.
8097 PREDICATE will be called with the header structures of the
8098 articles."
8099   (let ((articles nil)
8100         (case-fold-search t))
8101     (dolist (header gnus-newsgroup-headers)
8102       (when (funcall predicate header)
8103         (push (mail-header-number header) articles)))
8104     (gnus-summary-limit (nreverse articles))))
8105
8106 (defun gnus-summary-limit-to-age (age &optional younger-p)
8107   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8108 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8109 articles that are younger than AGE days."
8110   (interactive
8111    (let ((younger current-prefix-arg)
8112          (days-got nil)
8113          days)
8114      (while (not days-got)
8115        (setq days (if younger
8116                       (read-string "Limit to articles younger than (in days, older when negative): ")
8117                     (read-string
8118                      "Limit to articles older than (in days, younger when negative): ")))
8119        (when (> (length days) 0)
8120          (setq days (read days)))
8121        (if (numberp days)
8122            (progn
8123              (setq days-got t)
8124              (when (< days 0)
8125                (setq younger (not younger))
8126                (setq days (* days -1))))
8127          (message "Please enter a number.")
8128          (sleep-for 1)))
8129      (list days younger)))
8130   (prog1
8131       (let ((data gnus-newsgroup-data)
8132             (cutoff (days-to-time age))
8133             articles d date is-younger)
8134         (while (setq d (pop data))
8135           (when (and (vectorp (gnus-data-header d))
8136                      (setq date (mail-header-date (gnus-data-header d))))
8137             (setq is-younger (time-less-p
8138                               (time-since (condition-case ()
8139                                               (date-to-time date)
8140                                             (error '(0 0))))
8141                               cutoff))
8142             (when (if younger-p
8143                       is-younger
8144                     (not is-younger))
8145               (push (gnus-data-number d) articles))))
8146         (gnus-summary-limit (nreverse articles)))
8147     (gnus-summary-position-point)))
8148
8149 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8150   "Limit the summary buffer to articles that match an 'extra' header."
8151   (interactive
8152    (let ((header
8153           (intern
8154            (gnus-completing-read-with-default
8155             (symbol-name (car gnus-extra-headers))
8156             (if current-prefix-arg
8157                 "Exclude extra header"
8158               "Limit extra header")
8159             (mapcar (lambda (x)
8160                       (cons (symbol-name x) x))
8161                     gnus-extra-headers)
8162             nil
8163             t))))
8164      (list header
8165            (read-string (format "%s header %s (regexp): "
8166                                 (if current-prefix-arg "Exclude" "Limit to")
8167                                 header))
8168            current-prefix-arg)))
8169   (when (not (equal "" regexp))
8170     (prog1
8171         (let ((articles (gnus-summary-find-matching
8172                          (cons 'extra header) regexp 'all nil nil
8173                          not-matching)))
8174           (unless articles
8175             (error "Found no matches for \"%s\"" regexp))
8176           (gnus-summary-limit articles))
8177       (gnus-summary-position-point))))
8178
8179 (defun gnus-summary-limit-to-display-predicate ()
8180   "Limit the summary buffer to the predicated in the `display' group parameter."
8181   (interactive)
8182   (unless gnus-newsgroup-display
8183     (error "There is no `display' group parameter"))
8184   (let (articles)
8185     (dolist (number gnus-newsgroup-articles)
8186       (when (funcall gnus-newsgroup-display)
8187         (push number articles)))
8188     (gnus-summary-limit articles))
8189   (gnus-summary-position-point))
8190
8191 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8192 (make-obsolete
8193  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8194
8195 (defun gnus-summary-limit-to-unread (&optional all)
8196   "Limit the summary buffer to articles that are not marked as read.
8197 If ALL is non-nil, limit strictly to unread articles."
8198   (interactive "P")
8199   (if all
8200       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8201     (gnus-summary-limit-to-marks
8202      ;; Concat all the marks that say that an article is read and have
8203      ;; those removed.
8204      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8205            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8206            gnus-low-score-mark gnus-expirable-mark
8207            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8208            gnus-duplicate-mark gnus-souped-mark)
8209      'reverse)))
8210
8211 (defun gnus-summary-limit-to-headers (match &optional reverse)
8212   "Limit the summary buffer to articles that have headers that match MATCH.
8213 If REVERSE (the prefix), limit to articles that don't match."
8214   (interactive "sMatch headers (regexp): \nP")
8215   (gnus-summary-limit-to-bodies match reverse t))
8216
8217 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8218   "Limit the summary buffer to articles that have bodies that match MATCH.
8219 If REVERSE (the prefix), limit to articles that don't match."
8220   (interactive "sMatch body (regexp): \nP")
8221   (let ((articles nil)
8222         (gnus-select-article-hook nil)  ;Disable hook.
8223         (gnus-article-prepare-hook nil)
8224         (gnus-use-article-prefetch nil)
8225         (gnus-keep-backlog nil)
8226         (gnus-break-pages nil)
8227         (gnus-summary-display-arrow nil)
8228         (gnus-updated-mode-lines nil)
8229         (gnus-auto-center-summary nil)
8230         (gnus-display-mime-function nil))
8231     (dolist (data gnus-newsgroup-data)
8232       (let (gnus-mark-article-hook)
8233         (gnus-summary-select-article t t nil (gnus-data-number data)))
8234       (save-excursion
8235         (set-buffer gnus-article-buffer)
8236         (article-goto-body)
8237         (let* ((case-fold-search t)
8238                (found (if headersp
8239                           (re-search-backward match nil t)
8240                         (re-search-forward match nil t))))
8241           (when (or (and found
8242                          (not reverse))
8243                     (and (not found)
8244                          reverse))
8245             (push (gnus-data-number data) articles)))))
8246     (if (not articles)
8247         (message "No messages matched")
8248       (gnus-summary-limit articles)))
8249   (gnus-summary-position-point))
8250
8251 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8252   "Limit the summary buffer to articles that aren't part on any thread.
8253 If THREADSP (the prefix), limit to articles that are in threads."
8254   (interactive "P")
8255   (let ((articles nil)
8256         thread-articles
8257         threads)
8258     (dolist (thread gnus-newsgroup-threads)
8259       (if (stringp (car thread))
8260           (dolist (thread (cdr thread))
8261             (push thread threads))
8262         (push thread threads)))
8263     (dolist (thread threads)
8264       (setq thread-articles (gnus-articles-in-thread thread))
8265       (when (or (and threadsp
8266                      (> (length thread-articles) 1))
8267                 (and (not threadsp)
8268                      (= (length thread-articles) 1)))
8269         (setq articles (nconc thread-articles articles))))
8270     (if (not articles)
8271         (message "No messages matched")
8272       (gnus-summary-limit articles))
8273     (gnus-summary-position-point)))
8274
8275 (defun gnus-summary-limit-to-replied (&optional unreplied)
8276   "Limit the summary buffer to replied articles.
8277 If UNREPLIED (the prefix), limit to unreplied articles."
8278   (interactive "P")
8279   (if unreplied
8280       (gnus-summary-limit
8281        (gnus-set-difference gnus-newsgroup-articles
8282         gnus-newsgroup-replied))
8283     (gnus-summary-limit gnus-newsgroup-replied))
8284   (gnus-summary-position-point))
8285
8286 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8287 (make-obsolete 'gnus-summary-delete-marked-with
8288                'gnus-summary-limit-exclude-marks)
8289
8290 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8291   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8292 If REVERSE, limit the summary buffer to articles that are marked
8293 with MARKS.  MARKS can either be a string of marks or a list of marks.
8294 Returns how many articles were removed."
8295   (interactive "sMarks: ")
8296   (gnus-summary-limit-to-marks marks t))
8297
8298 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8299   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8300 If REVERSE (the prefix), limit the summary buffer to articles that are
8301 not marked with MARKS.  MARKS can either be a string of marks or a
8302 list of marks.
8303 Returns how many articles were removed."
8304   (interactive "sMarks: \nP")
8305   (prog1
8306       (let ((data gnus-newsgroup-data)
8307             (marks (if (listp marks) marks
8308                      (append marks nil))) ; Transform to list.
8309             articles)
8310         (while data
8311           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8312                   (memq (gnus-data-mark (car data)) marks))
8313             (push (gnus-data-number (car data)) articles))
8314           (setq data (cdr data)))
8315         (gnus-summary-limit articles))
8316     (gnus-summary-position-point)))
8317
8318 (defun gnus-summary-limit-to-score (score)
8319   "Limit to articles with score at or above SCORE."
8320   (interactive "NLimit to articles with score of at least: ")
8321   (let ((data gnus-newsgroup-data)
8322         articles)
8323     (while data
8324       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8325                 score)
8326         (push (gnus-data-number (car data)) articles))
8327       (setq data (cdr data)))
8328     (prog1
8329         (gnus-summary-limit articles)
8330       (gnus-summary-position-point))))
8331
8332 (defun gnus-summary-limit-to-unseen ()
8333   "Limit to unseen articles."
8334   (interactive)
8335   (prog1
8336       (gnus-summary-limit gnus-newsgroup-unseen)
8337     (gnus-summary-position-point)))
8338
8339 (defun gnus-summary-limit-include-thread (id)
8340   "Display all the hidden articles that is in the thread with ID in it.
8341 When called interactively, ID is the Message-ID of the current
8342 article."
8343   (interactive (list (mail-header-id (gnus-summary-article-header))))
8344   (let ((articles (gnus-articles-in-thread
8345                    (gnus-id-to-thread (gnus-root-id id)))))
8346     (prog1
8347         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8348       (gnus-summary-limit-include-matching-articles
8349        "subject"
8350        (regexp-quote (gnus-simplify-subject-re
8351                       (mail-header-subject (gnus-id-to-header id)))))
8352       (gnus-summary-position-point))))
8353
8354 (defun gnus-summary-limit-include-matching-articles (header regexp)
8355   "Display all the hidden articles that have HEADERs that match REGEXP."
8356   (interactive (list (read-string "Match on header: ")
8357                      (read-string "Regexp: ")))
8358   (let ((articles (gnus-find-matching-articles header regexp)))
8359     (prog1
8360         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8361       (gnus-summary-position-point))))
8362
8363 (defun gnus-summary-insert-dormant-articles ()
8364   "Insert all the dormant articles for this group into the current buffer."
8365   (interactive)
8366   (let ((gnus-verbose (max 6 gnus-verbose)))
8367     (if (not gnus-newsgroup-dormant)
8368         (gnus-message 3 "No dormant articles for this group")
8369       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8370
8371 (defun gnus-summary-insert-ticked-articles ()
8372   "Insert ticked articles for this group into the current buffer."
8373   (interactive)
8374   (let ((gnus-verbose (max 6 gnus-verbose)))
8375     (if (not gnus-newsgroup-marked)
8376         (gnus-message 3 "No ticked articles for this group")
8377       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8378
8379 (defun gnus-summary-limit-include-dormant ()
8380   "Display all the hidden articles that are marked as dormant.
8381 Note that this command only works on a subset of the articles currently
8382 fetched for this group."
8383   (interactive)
8384   (unless gnus-newsgroup-dormant
8385     (error "There are no dormant articles in this group"))
8386   (prog1
8387       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8388     (gnus-summary-position-point)))
8389
8390 (defun gnus-summary-limit-exclude-dormant ()
8391   "Hide all dormant articles."
8392   (interactive)
8393   (prog1
8394       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8395     (gnus-summary-position-point)))
8396
8397 (defun gnus-summary-limit-exclude-childless-dormant ()
8398   "Hide all dormant articles that have no children."
8399   (interactive)
8400   (let ((data (gnus-data-list t))
8401         articles d children)
8402     ;; Find all articles that are either not dormant or have
8403     ;; children.
8404     (while (setq d (pop data))
8405       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8406                 (and (setq children
8407                            (gnus-article-children (gnus-data-number d)))
8408                      (let (found)
8409                        (while children
8410                          (when (memq (car children) articles)
8411                            (setq children nil
8412                                  found t))
8413                          (pop children))
8414                        found)))
8415         (push (gnus-data-number d) articles)))
8416     ;; Do the limiting.
8417     (prog1
8418         (gnus-summary-limit articles)
8419       (gnus-summary-position-point))))
8420
8421 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8422   "Mark all unread excluded articles as read.
8423 If ALL, mark even excluded ticked and dormants as read."
8424   (interactive "P")
8425   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8426   (let ((articles (gnus-sorted-ndifference
8427                    (sort
8428                     (mapcar (lambda (h) (mail-header-number h))
8429                             gnus-newsgroup-headers)
8430                     '<)
8431                    gnus-newsgroup-limit))
8432         article)
8433     (setq gnus-newsgroup-unreads
8434           (gnus-sorted-intersection gnus-newsgroup-unreads
8435                                     gnus-newsgroup-limit))
8436     (if all
8437         (setq gnus-newsgroup-dormant nil
8438               gnus-newsgroup-marked nil
8439               gnus-newsgroup-reads
8440               (nconc
8441                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8442                gnus-newsgroup-reads))
8443       (while (setq article (pop articles))
8444         (unless (or (memq article gnus-newsgroup-dormant)
8445                     (memq article gnus-newsgroup-marked))
8446           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8447
8448 (defun gnus-summary-limit (articles &optional pop)
8449   (if pop
8450       ;; We pop the previous limit off the stack and use that.
8451       (setq articles (car gnus-newsgroup-limits)
8452             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8453     ;; We use the new limit, so we push the old limit on the stack.
8454     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8455   ;; Set the limit.
8456   (setq gnus-newsgroup-limit articles)
8457   (let ((total (length gnus-newsgroup-data))
8458         (data (gnus-data-find-list (gnus-summary-article-number)))
8459         (gnus-summary-mark-below nil)   ; Inhibit this.
8460         found)
8461     ;; This will do all the work of generating the new summary buffer
8462     ;; according to the new limit.
8463     (gnus-summary-prepare)
8464     ;; Hide any threads, possibly.
8465     (gnus-summary-maybe-hide-threads)
8466     ;; Try to return to the article you were at, or one in the
8467     ;; neighborhood.
8468     (when data
8469       ;; We try to find some article after the current one.
8470       (while data
8471         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8472           (setq data nil
8473                 found t))
8474         (setq data (cdr data))))
8475     (unless found
8476       ;; If there is no data, that means that we were after the last
8477       ;; article.  The same goes when we can't find any articles
8478       ;; after the current one.
8479       (goto-char (point-max))
8480       (gnus-summary-find-prev))
8481     (gnus-set-mode-line 'summary)
8482     ;; We return how many articles were removed from the summary
8483     ;; buffer as a result of the new limit.
8484     (- total (length gnus-newsgroup-data))))
8485
8486 (defsubst gnus-invisible-cut-children (threads)
8487   (let ((num 0))
8488     (while threads
8489       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8490         (incf num))
8491       (pop threads))
8492     (< num 2)))
8493
8494 (defsubst gnus-cut-thread (thread)
8495   "Go forwards in the thread until we find an article that we want to display."
8496   (when (or (eq gnus-fetch-old-headers 'some)
8497             (eq gnus-fetch-old-headers 'invisible)
8498             (numberp gnus-fetch-old-headers)
8499             (eq gnus-build-sparse-threads 'some)
8500             (eq gnus-build-sparse-threads 'more))
8501     ;; Deal with old-fetched headers and sparse threads.
8502     (while (and
8503             thread
8504             (or
8505              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8506              (gnus-summary-article-ancient-p
8507               (mail-header-number (car thread))))
8508             (if (or (<= (length (cdr thread)) 1)
8509                     (eq gnus-fetch-old-headers 'invisible))
8510                 (setq gnus-newsgroup-limit
8511                       (delq (mail-header-number (car thread))
8512                             gnus-newsgroup-limit)
8513                       thread (cadr thread))
8514               (when (gnus-invisible-cut-children (cdr thread))
8515                 (let ((th (cdr thread)))
8516                   (while th
8517                     (if (memq (mail-header-number (caar th))
8518                               gnus-newsgroup-limit)
8519                         (setq thread (car th)
8520                               th nil)
8521                       (setq th (cdr th))))))))))
8522   thread)
8523
8524 (defun gnus-cut-threads (threads)
8525   "Cut off all uninteresting articles from the beginning of THREADS."
8526   (when (or (eq gnus-fetch-old-headers 'some)
8527             (eq gnus-fetch-old-headers 'invisible)
8528             (numberp gnus-fetch-old-headers)
8529             (eq gnus-build-sparse-threads 'some)
8530             (eq gnus-build-sparse-threads 'more))
8531     (let ((th threads))
8532       (while th
8533         (setcar th (gnus-cut-thread (car th)))
8534         (setq th (cdr th)))))
8535   ;; Remove nixed out threads.
8536   (delq nil threads))
8537
8538 (defun gnus-summary-initial-limit (&optional show-if-empty)
8539   "Figure out what the initial limit is supposed to be on group entry.
8540 This entails weeding out unwanted dormants, low-scored articles,
8541 fetch-old-headers verbiage, and so on."
8542   ;; Most groups have nothing to remove.
8543   (if (or gnus-inhibit-limiting
8544           (and (null gnus-newsgroup-dormant)
8545                (eq gnus-newsgroup-display 'gnus-not-ignore)
8546                (not (eq gnus-fetch-old-headers 'some))
8547                (not (numberp gnus-fetch-old-headers))
8548                (not (eq gnus-fetch-old-headers 'invisible))
8549                (null gnus-summary-expunge-below)
8550                (not (eq gnus-build-sparse-threads 'some))
8551                (not (eq gnus-build-sparse-threads 'more))
8552                (null gnus-thread-expunge-below)
8553                (not gnus-use-nocem)))
8554       ()                                ; Do nothing.
8555     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8556     (setq gnus-newsgroup-limit nil)
8557     (mapatoms
8558      (lambda (node)
8559        (unless (car (symbol-value node))
8560          ;; These threads have no parents -- they are roots.
8561          (let ((nodes (cdr (symbol-value node)))
8562                thread)
8563            (while nodes
8564              (if (and gnus-thread-expunge-below
8565                       (< (gnus-thread-total-score (car nodes))
8566                          gnus-thread-expunge-below))
8567                  (gnus-expunge-thread (pop nodes))
8568                (setq thread (pop nodes))
8569                (gnus-summary-limit-children thread))))))
8570      gnus-newsgroup-dependencies)
8571     ;; If this limitation resulted in an empty group, we might
8572     ;; pop the previous limit and use it instead.
8573     (when (and (not gnus-newsgroup-limit)
8574                show-if-empty)
8575       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8576     gnus-newsgroup-limit))
8577
8578 (defun gnus-summary-limit-children (thread)
8579   "Return 1 if this subthread is visible and 0 if it is not."
8580   ;; First we get the number of visible children to this thread.  This
8581   ;; is done by recursing down the thread using this function, so this
8582   ;; will really go down to a leaf article first, before slowly
8583   ;; working its way up towards the root.
8584   (when thread
8585     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8586            (children
8587            (if (cdr thread)
8588                (apply '+ (mapcar 'gnus-summary-limit-children
8589                                  (cdr thread)))
8590              0))
8591           (number (mail-header-number (car thread)))
8592           score)
8593       (if (and
8594            (not (memq number gnus-newsgroup-marked))
8595            (or
8596             ;; If this article is dormant and has absolutely no visible
8597             ;; children, then this article isn't visible.
8598             (and (memq number gnus-newsgroup-dormant)
8599                  (zerop children))
8600             ;; If this is "fetch-old-headered" and there is no
8601             ;; visible children, then we don't want this article.
8602             (and (or (eq gnus-fetch-old-headers 'some)
8603                      (numberp gnus-fetch-old-headers))
8604                  (gnus-summary-article-ancient-p number)
8605                  (zerop children))
8606             ;; If this is "fetch-old-headered" and `invisible', then
8607             ;; we don't want this article.
8608             (and (eq gnus-fetch-old-headers 'invisible)
8609                  (gnus-summary-article-ancient-p number))
8610             ;; If this is a sparsely inserted article with no children,
8611             ;; we don't want it.
8612             (and (eq gnus-build-sparse-threads 'some)
8613                  (gnus-summary-article-sparse-p number)
8614                  (zerop children))
8615             ;; If we use expunging, and this article is really
8616             ;; low-scored, then we don't want this article.
8617             (when (and gnus-summary-expunge-below
8618                        (< (setq score
8619                                 (or (cdr (assq number gnus-newsgroup-scored))
8620                                     gnus-summary-default-score))
8621                           gnus-summary-expunge-below))
8622               ;; We increase the expunge-tally here, but that has
8623               ;; nothing to do with the limits, really.
8624               (incf gnus-newsgroup-expunged-tally)
8625               ;; We also mark as read here, if that's wanted.
8626               (when (and gnus-summary-mark-below
8627                          (< score gnus-summary-mark-below))
8628                 (setq gnus-newsgroup-unreads
8629                       (delq number gnus-newsgroup-unreads))
8630                 (if gnus-newsgroup-auto-expire
8631                     (push number gnus-newsgroup-expirable)
8632                   (push (cons number gnus-low-score-mark)
8633                         gnus-newsgroup-reads)))
8634               t)
8635             ;; Do the `display' group parameter.
8636             (and gnus-newsgroup-display
8637                  (not (funcall gnus-newsgroup-display)))
8638             ;; Check NoCeM things.
8639             (when (and gnus-use-nocem
8640                        (gnus-nocem-unwanted-article-p
8641                         (mail-header-id (car thread))))
8642               (setq gnus-newsgroup-unreads
8643                     (delq number gnus-newsgroup-unreads))
8644               t)))
8645           ;; Nope, invisible article.
8646           0
8647         ;; Ok, this article is to be visible, so we add it to the limit
8648         ;; and return 1.
8649         (push number gnus-newsgroup-limit)
8650         1))))
8651
8652 (defun gnus-expunge-thread (thread)
8653   "Mark all articles in THREAD as read."
8654   (let* ((number (mail-header-number (car thread))))
8655     (incf gnus-newsgroup-expunged-tally)
8656     ;; We also mark as read here, if that's wanted.
8657     (setq gnus-newsgroup-unreads
8658           (delq number gnus-newsgroup-unreads))
8659     (if gnus-newsgroup-auto-expire
8660         (push number gnus-newsgroup-expirable)
8661       (push (cons number gnus-low-score-mark)
8662             gnus-newsgroup-reads)))
8663   ;; Go recursively through all subthreads.
8664   (mapcar 'gnus-expunge-thread (cdr thread)))
8665
8666 ;; Summary article oriented commands
8667
8668 (defun gnus-summary-refer-parent-article (n)
8669   "Refer parent article N times.
8670 If N is negative, go to ancestor -N instead.
8671 The difference between N and the number of articles fetched is returned."
8672   (interactive "p")
8673   (let ((skip 1)
8674         error header ref)
8675     (when (not (natnump n))
8676       (setq skip (abs n)
8677             n 1))
8678     (while (and (> n 0)
8679                 (not error))
8680       (setq header (gnus-summary-article-header))
8681       (if (and (eq (mail-header-number header)
8682                    (cdr gnus-article-current))
8683                (equal gnus-newsgroup-name
8684                       (car gnus-article-current)))
8685           ;; If we try to find the parent of the currently
8686           ;; displayed article, then we take a look at the actual
8687           ;; References header, since this is slightly more
8688           ;; reliable than the References field we got from the
8689           ;; server.
8690           (save-excursion
8691             (set-buffer gnus-original-article-buffer)
8692             (nnheader-narrow-to-headers)
8693             (unless (setq ref (message-fetch-field "references"))
8694               (when (setq ref (message-fetch-field "in-reply-to"))
8695                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8696             (widen))
8697         (setq ref
8698               ;; It's not the current article, so we take a bet on
8699               ;; the value we got from the server.
8700               (mail-header-references header)))
8701       (if (and ref
8702                (not (equal ref "")))
8703           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8704             (gnus-message 1 "Couldn't find parent"))
8705         (gnus-message 1 "No references in article %d"
8706                       (gnus-summary-article-number))
8707         (setq error t))
8708       (decf n))
8709     (gnus-summary-position-point)
8710     n))
8711
8712 (defun gnus-summary-refer-references ()
8713   "Fetch all articles mentioned in the References header.
8714 Return the number of articles fetched."
8715   (interactive)
8716   (let ((ref (mail-header-references (gnus-summary-article-header)))
8717         (current (gnus-summary-article-number))
8718         (n 0))
8719     (if (or (not ref)
8720             (equal ref ""))
8721         (error "No References in the current article")
8722       ;; For each Message-ID in the References header...
8723       (while (string-match "<[^>]*>" ref)
8724         (incf n)
8725         ;; ... fetch that article.
8726         (gnus-summary-refer-article
8727          (prog1 (match-string 0 ref)
8728            (setq ref (substring ref (match-end 0))))))
8729       (gnus-summary-goto-subject current)
8730       (gnus-summary-position-point)
8731       n)))
8732
8733 (defun gnus-summary-refer-thread (&optional limit)
8734   "Fetch all articles in the current thread.
8735 If LIMIT (the numerical prefix), fetch that many old headers instead
8736 of what's specified by the `gnus-refer-thread-limit' variable."
8737   (interactive "P")
8738   (let ((id (mail-header-id (gnus-summary-article-header)))
8739         (limit (if limit (prefix-numeric-value limit)
8740                  gnus-refer-thread-limit)))
8741     (unless (eq gnus-fetch-old-headers 'invisible)
8742       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8743       ;; Retrieve the headers and read them in.
8744       (if (eq (if (numberp limit)
8745                   (gnus-retrieve-headers
8746                    (list (min
8747                           (+ (mail-header-number
8748                               (gnus-summary-article-header))
8749                              limit)
8750                           gnus-newsgroup-end))
8751                    gnus-newsgroup-name (* limit 2))
8752                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8753                 ;; headers.
8754                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8755                                        gnus-newsgroup-name limit))
8756               'nov)
8757           (gnus-build-all-threads)
8758         (error "Can't fetch thread from back ends that don't support NOV"))
8759       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8760     (gnus-summary-limit-include-thread id)))
8761
8762 (defun gnus-summary-refer-article (message-id)
8763   "Fetch an article specified by MESSAGE-ID."
8764   (interactive "sMessage-ID: ")
8765   (when (and (stringp message-id)
8766              (not (zerop (length message-id))))
8767     (setq message-id (gnus-replace-in-string message-id " " ""))
8768     ;; Construct the correct Message-ID if necessary.
8769     ;; Suggested by tale@pawl.rpi.edu.
8770     (unless (string-match "^<" message-id)
8771       (setq message-id (concat "<" message-id)))
8772     (unless (string-match ">$" message-id)
8773       (setq message-id (concat message-id ">")))
8774     ;; People often post MIDs from URLs, so unhex it:
8775     (unless (string-match "@" message-id)
8776       (setq message-id (gnus-url-unhex-string message-id)))
8777     (let* ((header (gnus-id-to-header message-id))
8778            (sparse (and header
8779                         (gnus-summary-article-sparse-p
8780                          (mail-header-number header))
8781                         (memq (mail-header-number header)
8782                               gnus-newsgroup-limit)))
8783            number)
8784       (cond
8785        ;; If the article is present in the buffer we just go to it.
8786        ((and header
8787              (or (not (gnus-summary-article-sparse-p
8788                        (mail-header-number header)))
8789                  sparse))
8790         (prog1
8791             (gnus-summary-goto-article
8792              (mail-header-number header) nil t)
8793           (when sparse
8794             (gnus-summary-update-article (mail-header-number header)))))
8795        (t
8796         ;; We fetch the article.
8797         (catch 'found
8798           (dolist (gnus-override-method (gnus-refer-article-methods))
8799             (when (and (gnus-check-server gnus-override-method)
8800                        ;; Fetch the header,
8801                        (setq number (gnus-summary-insert-subject message-id)))
8802               ;; and display the article.
8803               (gnus-summary-select-article nil nil nil number)
8804               (throw 'found t)))
8805           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8806
8807 (defun gnus-refer-article-methods ()
8808   "Return a list of referable methods."
8809   (cond
8810    ;; No method, so we default to current and native.
8811    ((null gnus-refer-article-method)
8812     (list gnus-current-select-method gnus-select-method))
8813    ;; Current.
8814    ((eq 'current gnus-refer-article-method)
8815     (list gnus-current-select-method))
8816    ;; List of select methods.
8817    ((not (and (symbolp (car gnus-refer-article-method))
8818               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8819     (let (out)
8820       (dolist (method gnus-refer-article-method)
8821         (push (if (eq 'current method)
8822                   gnus-current-select-method
8823                 method)
8824               out))
8825       (nreverse out)))
8826    ;; One single select method.
8827    (t
8828     (list gnus-refer-article-method))))
8829
8830 (defun gnus-summary-edit-parameters ()
8831   "Edit the group parameters of the current group."
8832   (interactive)
8833   (gnus-group-edit-group gnus-newsgroup-name 'params))
8834
8835 (defun gnus-summary-customize-parameters ()
8836   "Customize the group parameters of the current group."
8837   (interactive)
8838   (gnus-group-customize gnus-newsgroup-name))
8839
8840 (defun gnus-summary-enter-digest-group (&optional force)
8841   "Enter an nndoc group based on the current article.
8842 If FORCE, force a digest interpretation.  If not, try
8843 to guess what the document format is."
8844   (interactive "P")
8845   (let ((conf gnus-current-window-configuration))
8846     (save-window-excursion
8847       (save-excursion
8848         (let (gnus-article-prepare-hook
8849               gnus-display-mime-function
8850               gnus-break-pages)
8851           (gnus-summary-select-article))))
8852     (setq gnus-current-window-configuration conf)
8853     (let* ((name (format "%s-%d"
8854                          (gnus-group-prefixed-name
8855                           gnus-newsgroup-name (list 'nndoc ""))
8856                          (with-current-buffer gnus-summary-buffer
8857                            gnus-current-article)))
8858            (ogroup gnus-newsgroup-name)
8859            (params (append (gnus-info-params (gnus-get-info ogroup))
8860                            (list (cons 'to-group ogroup))
8861                            (list (cons 'parent-group ogroup))
8862                            (list (cons 'save-article-group ogroup))))
8863            (case-fold-search t)
8864            (buf (current-buffer))
8865            dig to-address)
8866       (save-excursion
8867         (set-buffer gnus-original-article-buffer)
8868         ;; Have the digest group inherit the main mail address of
8869         ;; the parent article.
8870         (when (setq to-address (or (gnus-fetch-field "reply-to")
8871                                    (gnus-fetch-field "from")))
8872           (setq params
8873                 (append
8874                  (list (cons 'to-address
8875                              (funcall gnus-decode-encoded-address-function
8876                                       to-address))))))
8877         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8878         (insert-buffer-substring gnus-original-article-buffer)
8879         ;; Remove lines that may lead nndoc to misinterpret the
8880         ;; document type.
8881         (narrow-to-region
8882          (goto-char (point-min))
8883          (or (search-forward "\n\n" nil t) (point)))
8884         (goto-char (point-min))
8885         (delete-matching-lines "^Path:\\|^From ")
8886         (widen))
8887       (unwind-protect
8888           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8889                     (gnus-newsgroup-ephemeral-ignored-charsets
8890                      gnus-newsgroup-ignored-charsets))
8891                 (gnus-group-read-ephemeral-group
8892                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8893                               (nndoc-article-type
8894                                ,(if force 'mbox 'guess)))
8895                  t nil nil nil
8896                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8897                                                         "ADAPT")))))
8898               ;; Make all postings to this group go to the parent group.
8899               (nconc (gnus-info-params (gnus-get-info name))
8900                      params)
8901             ;; Couldn't select this doc group.
8902             (switch-to-buffer buf)
8903             (gnus-set-global-variables)
8904             (gnus-configure-windows 'summary)
8905             (gnus-message 3 "Article couldn't be entered?"))
8906         (kill-buffer dig)))))
8907
8908 (defun gnus-summary-read-document (n)
8909   "Open a new group based on the current article(s).
8910 This will allow you to read digests and other similar
8911 documents as newsgroups.
8912 Obeys the standard process/prefix convention."
8913   (interactive "P")
8914   (let* ((ogroup gnus-newsgroup-name)
8915          (params (append (gnus-info-params (gnus-get-info ogroup))
8916                          (list (cons 'to-group ogroup))))
8917          group egroup groups vgroup)
8918     (dolist (article (gnus-summary-work-articles n))
8919       (setq group (format "%s-%d" gnus-newsgroup-name article))
8920       (gnus-summary-remove-process-mark article)
8921       (when (gnus-summary-display-article article)
8922         (save-excursion
8923           (with-temp-buffer
8924             (insert-buffer-substring gnus-original-article-buffer)
8925             ;; Remove some headers that may lead nndoc to make
8926             ;; the wrong guess.
8927             (message-narrow-to-head)
8928             (goto-char (point-min))
8929             (delete-matching-lines "^Path:\\|^From ")
8930             (widen)
8931             (if (setq egroup
8932                       (gnus-group-read-ephemeral-group
8933                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8934                                      (nndoc-article-type guess))
8935                        t nil t))
8936                 (progn
8937             ;; Make all postings to this group go to the parent group.
8938                   (nconc (gnus-info-params (gnus-get-info egroup))
8939                          params)
8940                   (push egroup groups))
8941               ;; Couldn't select this doc group.
8942               (gnus-error 3 "Article couldn't be entered"))))))
8943     ;; Now we have selected all the documents.
8944     (cond
8945      ((not groups)
8946       (error "None of the articles could be interpreted as documents"))
8947      ((gnus-group-read-ephemeral-group
8948        (setq vgroup (format
8949                      "nnvirtual:%s-%s" gnus-newsgroup-name
8950                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8951        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8952        t
8953        (cons (current-buffer) 'summary)))
8954      (t
8955       (error "Couldn't select virtual nndoc group")))))
8956
8957 (defun gnus-summary-isearch-article (&optional regexp-p)
8958   "Do incremental search forward on the current article.
8959 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8960   (interactive "P")
8961   (gnus-summary-select-article)
8962   (gnus-configure-windows 'article)
8963   (gnus-eval-in-buffer-window gnus-article-buffer
8964     (save-restriction
8965       (widen)
8966       (isearch-forward regexp-p))))
8967
8968 (defun gnus-summary-repeat-search-article-forward ()
8969   "Repeat the previous search forwards."
8970   (interactive)
8971   (unless gnus-last-search-regexp
8972     (error "No previous search"))
8973   (gnus-summary-search-article-forward gnus-last-search-regexp))
8974
8975 (defun gnus-summary-repeat-search-article-backward ()
8976   "Repeat the previous search backwards."
8977   (interactive)
8978   (unless gnus-last-search-regexp
8979     (error "No previous search"))
8980   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8981
8982 (defun gnus-summary-search-article-forward (regexp &optional backward)
8983   "Search for an article containing REGEXP forward.
8984 If BACKWARD, search backward instead."
8985   (interactive
8986    (list (read-string
8987           (format "Search article %s (regexp%s): "
8988                   (if current-prefix-arg "backward" "forward")
8989                   (if gnus-last-search-regexp
8990                       (concat ", default " gnus-last-search-regexp)
8991                     "")))
8992          current-prefix-arg))
8993   (if (string-equal regexp "")
8994       (setq regexp (or gnus-last-search-regexp ""))
8995     (setq gnus-last-search-regexp regexp)
8996     (setq gnus-article-before-search gnus-current-article))
8997   ;; Intentionally set gnus-last-article.
8998   (setq gnus-last-article gnus-article-before-search)
8999   (let ((gnus-last-article gnus-last-article))
9000     (if (gnus-summary-search-article regexp backward)
9001         (gnus-summary-show-thread)
9002       (signal 'search-failed (list regexp)))))
9003
9004 (defun gnus-summary-search-article-backward (regexp)
9005   "Search for an article containing REGEXP backward."
9006   (interactive
9007    (list (read-string
9008           (format "Search article backward (regexp%s): "
9009                   (if gnus-last-search-regexp
9010                       (concat ", default " gnus-last-search-regexp)
9011                     "")))))
9012   (gnus-summary-search-article-forward regexp 'backward))
9013
9014 (defun gnus-summary-search-article (regexp &optional backward)
9015   "Search for an article containing REGEXP.
9016 Optional argument BACKWARD means do search for backward.
9017 `gnus-select-article-hook' is not called during the search."
9018   ;; We have to require this here to make sure that the following
9019   ;; dynamic binding isn't shadowed by autoloading.
9020   (require 'gnus-async)
9021   (require 'gnus-art)
9022   (let ((gnus-select-article-hook nil)  ;Disable hook.
9023         (gnus-article-prepare-hook nil)
9024         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9025         (gnus-use-article-prefetch nil)
9026         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9027         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9028         (gnus-visual nil)
9029         (gnus-keep-backlog nil)
9030         (gnus-break-pages nil)
9031         (gnus-summary-display-arrow nil)
9032         (gnus-updated-mode-lines nil)
9033         (gnus-auto-center-summary nil)
9034         (sum (current-buffer))
9035         (gnus-display-mime-function nil)
9036         (found nil)
9037         point)
9038     (gnus-save-hidden-threads
9039       (gnus-summary-select-article)
9040       (set-buffer gnus-article-buffer)
9041       (goto-char (window-point (get-buffer-window (current-buffer))))
9042       (when backward
9043         (forward-line -1))
9044       (while (not found)
9045         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9046         (if (if backward
9047                 (re-search-backward regexp nil t)
9048               (re-search-forward regexp nil t))
9049             ;; We found the regexp.
9050             (progn
9051               (setq found 'found)
9052               (beginning-of-line)
9053               (set-window-start
9054                (get-buffer-window (current-buffer))
9055                (point))
9056               (forward-line 1)
9057               (set-window-point
9058                (get-buffer-window (current-buffer))
9059                (point))
9060               (set-buffer sum)
9061               (setq point (point)))
9062           ;; We didn't find it, so we go to the next article.
9063           (set-buffer sum)
9064           (setq found 'not)
9065           (while (eq found 'not)
9066             (if (not (if backward (gnus-summary-find-prev)
9067                        (gnus-summary-find-next)))
9068                 ;; No more articles.
9069                 (setq found t)
9070               ;; Select the next article and adjust point.
9071               (unless (gnus-summary-article-sparse-p
9072                        (gnus-summary-article-number))
9073                 (setq found nil)
9074                 (gnus-summary-select-article)
9075                 (set-buffer gnus-article-buffer)
9076                 (widen)
9077                 (goto-char (if backward (point-max) (point-min))))))))
9078       (gnus-message 7 ""))
9079     ;; Return whether we found the regexp.
9080     (when (eq found 'found)
9081       (goto-char point)
9082       (gnus-summary-show-thread)
9083       (gnus-summary-goto-subject gnus-current-article)
9084       (gnus-summary-position-point)
9085       t)))
9086
9087 (defun gnus-find-matching-articles (header regexp)
9088   "Return a list of all articles that match REGEXP on HEADER.
9089 This search includes all articles in the current group that Gnus has
9090 fetched headers for, whether they are displayed or not."
9091   (let ((articles nil)
9092         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9093         (case-fold-search t))
9094     (dolist (header gnus-newsgroup-headers)
9095       (when (string-match regexp (funcall func header))
9096         (push (mail-header-number header) articles)))
9097     (nreverse articles)))
9098
9099 (defun gnus-summary-find-matching (header regexp &optional backward unread
9100                                           not-case-fold not-matching)
9101   "Return a list of all articles that match REGEXP on HEADER.
9102 The search stars on the current article and goes forwards unless
9103 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9104 If UNREAD is non-nil, only unread articles will
9105 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9106 in the comparisons. If NOT-MATCHING, return a list of all articles that
9107 not match REGEXP on HEADER."
9108   (let ((case-fold-search (not not-case-fold))
9109         articles d func)
9110     (if (consp header)
9111         (if (eq (car header) 'extra)
9112             (setq func
9113                   `(lambda (h)
9114                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9115                          "")))
9116           (error "%s is an invalid header" header))
9117       (unless (fboundp (intern (concat "mail-header-" header)))
9118         (error "%s is not a valid header" header))
9119       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9120     (dolist (d (if (eq backward 'all)
9121                    gnus-newsgroup-data
9122                  (gnus-data-find-list
9123                   (gnus-summary-article-number)
9124                   (gnus-data-list backward))))
9125       (when (and (or (not unread)       ; We want all articles...
9126                      (gnus-data-unread-p d)) ; Or just unreads.
9127                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9128                  (if not-matching
9129                      (not (string-match
9130                            regexp
9131                            (funcall func (gnus-data-header d))))
9132                    (string-match regexp
9133                                  (funcall func (gnus-data-header d)))))
9134         (push (gnus-data-number d) articles))) ; Success!
9135     (nreverse articles)))
9136
9137 (defun gnus-summary-execute-command (header regexp command &optional backward)
9138   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9139 If HEADER is an empty string (or nil), the match is done on the entire
9140 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9141   (interactive
9142    (list (let ((completion-ignore-case t))
9143            (completing-read
9144             "Header name: "
9145             (mapcar (lambda (header) (list (format "%s" header)))
9146                     (append
9147                      '("Number" "Subject" "From" "Lines" "Date"
9148                        "Message-ID" "Xref" "References" "Body")
9149                      gnus-extra-headers))
9150             nil 'require-match))
9151          (read-string "Regexp: ")
9152          (read-key-sequence "Command: ")
9153          current-prefix-arg))
9154   (when (equal header "Body")
9155     (setq header ""))
9156   ;; Hidden thread subtrees must be searched as well.
9157   (gnus-summary-show-all-threads)
9158   ;; We don't want to change current point nor window configuration.
9159   (save-excursion
9160     (save-window-excursion
9161       (let (gnus-visual
9162             gnus-treat-strip-trailing-blank-lines
9163             gnus-treat-strip-leading-blank-lines
9164             gnus-treat-strip-multiple-blank-lines
9165             gnus-treat-hide-boring-headers
9166             gnus-treat-fold-newsgroups
9167             gnus-article-prepare-hook)
9168         (gnus-message 6 "Executing %s..." (key-description command))
9169         ;; We'd like to execute COMMAND interactively so as to give arguments.
9170         (gnus-execute header regexp
9171                       `(call-interactively ',(key-binding command))
9172                       backward)
9173         (gnus-message 6 "Executing %s...done" (key-description command))))))
9174
9175 (defun gnus-summary-beginning-of-article ()
9176   "Scroll the article back to the beginning."
9177   (interactive)
9178   (gnus-summary-select-article)
9179   (gnus-configure-windows 'article)
9180   (gnus-eval-in-buffer-window gnus-article-buffer
9181     (widen)
9182     (goto-char (point-min))
9183     (when gnus-break-pages
9184       (gnus-narrow-to-page))))
9185
9186 (defun gnus-summary-end-of-article ()
9187   "Scroll to the end of the article."
9188   (interactive)
9189   (gnus-summary-select-article)
9190   (gnus-configure-windows 'article)
9191   (gnus-eval-in-buffer-window gnus-article-buffer
9192     (widen)
9193     (goto-char (point-max))
9194     (recenter -3)
9195     (when gnus-break-pages
9196       (when (re-search-backward page-delimiter nil t)
9197         (narrow-to-region (match-end 0) (point-max)))
9198       (gnus-narrow-to-page))))
9199
9200 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9201   "Truncate to LEN and quote all \"(\"'s in STRING."
9202   (gnus-replace-in-string (if (and len (> (length string) len))
9203                               (substring string 0 len)
9204                             string)
9205                           "[()]" "\\\\\\&"))
9206
9207 (defun gnus-summary-print-article (&optional filename n)
9208   "Generate and print a PostScript image of the process-marked (mail) articles.
9209
9210 If used interactively, print the current article if none are
9211 process-marked.  With prefix arg, prompt the user for the name of the
9212 file to save in.
9213
9214 When used from Lisp, accept two optional args FILENAME and N.  N means
9215 to print the next N articles.  If N is negative, print the N previous
9216 articles.  If N is nil and articles have been marked with the process
9217 mark, print these instead.
9218
9219 If the optional first argument FILENAME is nil, send the image to the
9220 printer.  If FILENAME is a string, save the PostScript image in a file with
9221 that name.  If FILENAME is a number, prompt the user for the name of the file
9222 to save in."
9223   (interactive (list (ps-print-preprint current-prefix-arg)))
9224   (dolist (article (gnus-summary-work-articles n))
9225     (gnus-summary-select-article nil nil 'pseudo article)
9226     (gnus-eval-in-buffer-window gnus-article-buffer
9227       (gnus-print-buffer))
9228     (gnus-summary-remove-process-mark article))
9229   (ps-despool filename))
9230
9231 (defun gnus-print-buffer ()
9232   (let ((buffer (generate-new-buffer " *print*")))
9233     (unwind-protect
9234         (progn
9235           (copy-to-buffer buffer (point-min) (point-max))
9236           (set-buffer buffer)
9237           (gnus-remove-text-with-property 'gnus-decoration)
9238           (when (gnus-visual-p 'article-highlight 'highlight)
9239             ;; Copy-to-buffer doesn't copy overlay.  So redo
9240             ;; highlight.
9241             (let ((gnus-article-buffer buffer))
9242               (gnus-article-highlight-citation t)
9243               (gnus-article-highlight-signature)
9244               (gnus-article-emphasize)
9245               (gnus-article-delete-invisible-text)))
9246           (let ((ps-left-header
9247                  (list
9248                   (concat "("
9249                           (gnus-summary-print-truncate-and-quote
9250                            (mail-header-subject gnus-current-headers)
9251                            66) ")")
9252                   (concat "("
9253                           (gnus-summary-print-truncate-and-quote
9254                            (mail-header-from gnus-current-headers)
9255                            45) ")")))
9256                 (ps-right-header
9257                  (list
9258                   "/pagenumberstring load"
9259                   (concat "("
9260                           (mail-header-date gnus-current-headers) ")"))))
9261             (gnus-run-hooks 'gnus-ps-print-hook)
9262             (save-excursion
9263               (if window-system
9264                   (ps-spool-buffer-with-faces)
9265                 (ps-spool-buffer)))))
9266       (kill-buffer buffer))))
9267
9268 (defun gnus-summary-show-article (&optional arg)
9269   "Force redisplaying of the current article.
9270 If ARG (the prefix) is a number, show the article with the charset
9271 defined in `gnus-summary-show-article-charset-alist', or the charset
9272 input.
9273 If ARG (the prefix) is non-nil and not a number, show the raw article
9274 without any article massaging functions being run.  Normally, the key
9275 strokes are `C-u g'."
9276   (interactive "P")
9277   (cond
9278    ((numberp arg)
9279     (gnus-summary-show-article t)
9280     (let ((gnus-newsgroup-charset
9281            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9282                (mm-read-coding-system
9283                 "View as charset: " ;; actually it is coding system.
9284                 (with-current-buffer gnus-article-buffer
9285                   (mm-detect-coding-region (point) (point-max))))))
9286           (gnus-newsgroup-ignored-charsets 'gnus-all))
9287       (gnus-summary-select-article nil 'force)
9288       (let ((deps gnus-newsgroup-dependencies)
9289             head header lines)
9290         (save-excursion
9291           (set-buffer gnus-original-article-buffer)
9292           (save-restriction
9293             (message-narrow-to-head)
9294             (setq head (buffer-string))
9295             (goto-char (point-min))
9296             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9297               (goto-char (point-max))
9298               (widen)
9299               (setq lines (1- (count-lines (point) (point-max))))))
9300           (with-temp-buffer
9301             (insert (format "211 %d Article retrieved.\n"
9302                             (cdr gnus-article-current)))
9303             (insert head)
9304             (if lines (insert (format "Lines: %d\n" lines)))
9305             (insert ".\n")
9306             (let ((nntp-server-buffer (current-buffer)))
9307               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9308         (gnus-data-set-header
9309          (gnus-data-find (cdr gnus-article-current))
9310          header)
9311         (gnus-summary-update-article-line
9312          (cdr gnus-article-current) header)
9313         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9314           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9315    ((not arg)
9316     ;; Select the article the normal way.
9317     (gnus-summary-select-article nil 'force))
9318    (t
9319     ;; We have to require this here to make sure that the following
9320     ;; dynamic binding isn't shadowed by autoloading.
9321     (require 'gnus-async)
9322     (require 'gnus-art)
9323     ;; Bind the article treatment functions to nil.
9324     (let ((gnus-have-all-headers t)
9325           gnus-article-prepare-hook
9326           gnus-article-decode-hook
9327           gnus-display-mime-function
9328           gnus-break-pages)
9329       ;; Destroy any MIME parts.
9330       (when (gnus-buffer-live-p gnus-article-buffer)
9331         (save-excursion
9332           (set-buffer gnus-article-buffer)
9333           (mm-destroy-parts gnus-article-mime-handles)
9334           ;; Set it to nil for safety reason.
9335           (setq gnus-article-mime-handle-alist nil)
9336           (setq gnus-article-mime-handles nil)))
9337       (gnus-summary-select-article nil 'force))))
9338   (gnus-summary-goto-subject gnus-current-article)
9339   (gnus-summary-position-point))
9340
9341 (defun gnus-summary-show-raw-article ()
9342   "Show the raw article without any article massaging functions being run."
9343   (interactive)
9344   (gnus-summary-show-article t))
9345
9346 (defun gnus-summary-verbose-headers (&optional arg)
9347   "Toggle permanent full header display.
9348 If ARG is a positive number, turn header display on.
9349 If ARG is a negative number, turn header display off."
9350   (interactive "P")
9351   (setq gnus-show-all-headers
9352         (cond ((or (not (numberp arg))
9353                    (zerop arg))
9354                (not gnus-show-all-headers))
9355               ((natnump arg)
9356                t)))
9357   (gnus-summary-show-article))
9358
9359 (defun gnus-summary-toggle-header (&optional arg)
9360   "Show the headers if they are hidden, or hide them if they are shown.
9361 If ARG is a positive number, show the entire header.
9362 If ARG is a negative number, hide the unwanted header lines."
9363   (interactive "P")
9364   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9365                      (get-buffer-window gnus-article-buffer t))))
9366     (with-current-buffer gnus-article-buffer
9367       (widen)
9368       (article-narrow-to-head)
9369       (let* ((buffer-read-only nil)
9370              (inhibit-point-motion-hooks t)
9371              (hidden (if (numberp arg)
9372                          (>= arg 0)
9373                        (or (not (looking-at "[^ \t\n]+:"))
9374                            (gnus-article-hidden-text-p 'headers))))
9375              s e)
9376         (delete-region (point-min) (point-max))
9377         (with-current-buffer gnus-original-article-buffer
9378           (goto-char (setq s (point-min)))
9379           (setq e (if (search-forward "\n\n" nil t)
9380                       (1- (point))
9381                     (point-max))))
9382         (insert-buffer-substring gnus-original-article-buffer s e)
9383         (run-hooks 'gnus-article-decode-hook)
9384         (if hidden
9385             (let ((gnus-treat-hide-headers nil)
9386                   (gnus-treat-hide-boring-headers nil))
9387               (gnus-delete-wash-type 'headers)
9388               (gnus-treat-article 'head))
9389           (gnus-treat-article 'head))
9390         (widen)
9391         (if window
9392             (set-window-start window (goto-char (point-min))))
9393         (if gnus-break-pages
9394             (gnus-narrow-to-page)
9395           (when (gnus-visual-p 'page-marker)
9396             (let ((buffer-read-only nil))
9397               (gnus-remove-text-with-property 'gnus-prev)
9398               (gnus-remove-text-with-property 'gnus-next))))
9399         (gnus-set-mode-line 'article)))))
9400
9401 (defun gnus-summary-show-all-headers ()
9402   "Make all header lines visible."
9403   (interactive)
9404   (gnus-summary-toggle-header 1))
9405
9406 (defun gnus-summary-caesar-message (&optional arg)
9407   "Caesar rotate the current article by 13.
9408 With a non-numerical prefix, also rotate headers.  A numerical
9409 prefix specifies how many places to rotate each letter forward."
9410   (interactive "P")
9411   (gnus-summary-select-article)
9412   (let ((mail-header-separator ""))
9413     (gnus-eval-in-buffer-window gnus-article-buffer
9414       (save-restriction
9415         (widen)
9416         (let ((start (window-start))
9417               buffer-read-only)
9418           (if (equal arg '(4))
9419               (message-caesar-buffer-body nil t)
9420             (message-caesar-buffer-body arg))
9421           (set-window-start (get-buffer-window (current-buffer)) start)))))
9422   ;; Create buttons and stuff...
9423   (gnus-treat-article nil))
9424
9425 (defun gnus-summary-idna-message (&optional arg)
9426   "Decode IDNA encoded domain names in the current articles.
9427 IDNA encoded domain names looks like `xn--bar'.  If a string
9428 remain unencoded after running this function, it is likely an
9429 invalid IDNA string (`xn--bar' is invalid).
9430
9431 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9432 installed for this command to work."
9433   (interactive "P")
9434   (if (not (and (condition-case nil (require 'idna)
9435                   (file-error))
9436                 (mm-coding-system-p 'utf-8)
9437                 (executable-find (symbol-value 'idna-program))))
9438       (gnus-message
9439        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9440     (gnus-summary-select-article)
9441     (let ((mail-header-separator ""))
9442       (gnus-eval-in-buffer-window gnus-article-buffer
9443         (save-restriction
9444           (widen)
9445           (let ((start (window-start))
9446                 buffer-read-only)
9447             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9448               (replace-match (idna-to-unicode (match-string 1))))
9449             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9450
9451 (defun gnus-summary-morse-message (&optional arg)
9452   "Morse decode the current article."
9453   (interactive "P")
9454   (gnus-summary-select-article)
9455   (let ((mail-header-separator ""))
9456     (gnus-eval-in-buffer-window gnus-article-buffer
9457       (save-excursion
9458         (save-restriction
9459           (widen)
9460           (let ((pos (window-start))
9461                 buffer-read-only)
9462             (goto-char (point-min))
9463             (when (message-goto-body)
9464               (gnus-narrow-to-body))
9465             (goto-char (point-min))
9466             (while (search-forward "·" (point-max) t)
9467               (replace-match "."))
9468             (unmorse-region (point-min) (point-max))
9469             (widen)
9470             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9471
9472 (defun gnus-summary-stop-page-breaking ()
9473   "Stop page breaking in the current article."
9474   (interactive)
9475   (gnus-summary-select-article)
9476   (gnus-eval-in-buffer-window gnus-article-buffer
9477     (widen)
9478     (when (gnus-visual-p 'page-marker)
9479       (let ((buffer-read-only nil))
9480         (gnus-remove-text-with-property 'gnus-prev)
9481         (gnus-remove-text-with-property 'gnus-next))
9482       (setq gnus-page-broken nil))))
9483
9484 (defun gnus-summary-move-article (&optional n to-newsgroup
9485                                             select-method action)
9486   "Move the current article to a different newsgroup.
9487 If N is a positive number, move the N next articles.
9488 If N is a negative number, move the N previous articles.
9489 If N is nil and any articles have been marked with the process mark,
9490 move those articles instead.
9491 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9492 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9493 re-spool using this method.
9494
9495 When called interactively with TO-NEWSGROUP being nil, the value of
9496 the variable `gnus-move-split-methods' is used for finding a default
9497 for the target newsgroup.
9498
9499 For this function to work, both the current newsgroup and the
9500 newsgroup that you want to move to have to support the `request-move'
9501 and `request-accept' functions.
9502
9503 ACTION can be either `move' (the default), `crosspost' or `copy'."
9504   (interactive "P")
9505   (unless action
9506     (setq action 'move))
9507   ;; Check whether the source group supports the required functions.
9508   (cond ((and (eq action 'move)
9509               (not (gnus-check-backend-function
9510                     'request-move-article gnus-newsgroup-name)))
9511          (error "The current group does not support article moving"))
9512         ((and (eq action 'crosspost)
9513               (not (gnus-check-backend-function
9514                     'request-replace-article gnus-newsgroup-name)))
9515          (error "The current group does not support article editing")))
9516   (let ((articles (gnus-summary-work-articles n))
9517         (prefix (if (gnus-check-backend-function
9518                      'request-move-article gnus-newsgroup-name)
9519                     (funcall gnus-move-group-prefix-function
9520                              gnus-newsgroup-name)
9521                   ""))
9522         (names '((move "Move" "Moving")
9523                  (copy "Copy" "Copying")
9524                  (crosspost "Crosspost" "Crossposting")))
9525         (copy-buf (save-excursion
9526                     (nnheader-set-temp-buffer " *copy article*")))
9527         art-group to-method new-xref article to-groups
9528         articles-to-update-marks encoded)
9529     (unless (assq action names)
9530       (error "Unknown action %s" action))
9531     ;; Read the newsgroup name.
9532     (when (and (not to-newsgroup)
9533                (not select-method))
9534       (if (and gnus-move-split-methods
9535                (not
9536                 (and (memq gnus-current-article articles)
9537                      (gnus-buffer-live-p gnus-original-article-buffer))))
9538           ;; When `gnus-move-split-methods' is non-nil, we have to
9539           ;; select an article to give `gnus-read-move-group-name' an
9540           ;; opportunity to suggest an appropriate default.  However,
9541           ;; we needn't render or mark the article.
9542           (let ((gnus-display-mime-function nil)
9543                 (gnus-article-prepare-hook nil)
9544                 (gnus-mark-article-hook nil))
9545             (gnus-summary-select-article nil nil nil (car articles))))
9546       (setq to-newsgroup (gnus-read-move-group-name
9547                           (cadr (assq action names))
9548                           (symbol-value
9549                            (intern (format "gnus-current-%s-group" action)))
9550                           articles prefix)
9551             encoded to-newsgroup
9552             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9553       (set (intern (format "gnus-current-%s-group" action))
9554            (mm-decode-coding-string
9555             to-newsgroup
9556             (gnus-group-name-charset to-method to-newsgroup))))
9557     (unless to-method
9558       (setq to-method (or select-method
9559                           (gnus-server-to-method
9560                            (gnus-group-method to-newsgroup)))))
9561     (setq to-newsgroup
9562           (or encoded
9563               (and to-newsgroup
9564                    (mm-encode-coding-string
9565                     to-newsgroup
9566                     (gnus-group-name-charset to-method to-newsgroup)))))
9567     ;; Check the method we are to move this article to...
9568     (unless (gnus-check-backend-function
9569              'request-accept-article (car to-method))
9570       (error "%s does not support article copying" (car to-method)))
9571     (unless (gnus-check-server to-method)
9572       (error "Can't open server %s" (car to-method)))
9573     (gnus-message 6 "%s to %s: %s..."
9574                   (caddr (assq action names))
9575                   (or (car select-method)
9576                       (gnus-group-decoded-name to-newsgroup))
9577                   articles)
9578     (while articles
9579       (setq article (pop articles))
9580       (setq
9581        art-group
9582        (cond
9583         ;; Move the article.
9584         ((eq action 'move)
9585          ;; Remove this article from future suppression.
9586          (gnus-dup-unsuppress-article article)
9587          (let* ((from-method (gnus-find-method-for-group
9588                               gnus-newsgroup-name))
9589                 (to-method (or select-method
9590                                (gnus-find-method-for-group to-newsgroup)))
9591                 (move-is-internal (gnus-method-equal from-method to-method)))
9592            (gnus-request-move-article
9593             article                     ; Article to move
9594             gnus-newsgroup-name         ; From newsgroup
9595             (nth 1 (gnus-find-method-for-group
9596                     gnus-newsgroup-name)) ; Server
9597             (list 'gnus-request-accept-article
9598                   to-newsgroup (list 'quote select-method)
9599                   (not articles) t)     ; Accept form
9600             (not articles)              ; Only save nov last time
9601             move-is-internal)))         ; is this move internal?
9602         ;; Copy the article.
9603         ((eq action 'copy)
9604          (save-excursion
9605            (set-buffer copy-buf)
9606            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9607              (save-restriction
9608                (nnheader-narrow-to-headers)
9609                (dolist (hdr gnus-copy-article-ignored-headers)
9610                  (message-remove-header hdr t)))
9611              (gnus-request-accept-article
9612               to-newsgroup select-method (not articles) t))))
9613         ;; Crosspost the article.
9614         ((eq action 'crosspost)
9615          (let ((xref (message-tokenize-header
9616                       (mail-header-xref (gnus-summary-article-header article))
9617                       " ")))
9618            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9619                                   ":" (number-to-string article)))
9620            (unless xref
9621              (setq xref (list (system-name))))
9622            (setq new-xref
9623                  (concat
9624                   (mapconcat 'identity
9625                              (delete "Xref:" (delete new-xref xref))
9626                              " ")
9627                   " " new-xref))
9628            (save-excursion
9629              (set-buffer copy-buf)
9630              ;; First put the article in the destination group.
9631              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9632              (when (consp (setq art-group
9633                                 (gnus-request-accept-article
9634                                  to-newsgroup select-method (not articles) t)))
9635                (setq new-xref (concat new-xref " " (car art-group)
9636                                       ":"
9637                                       (number-to-string (cdr art-group))))
9638                ;; Now we have the new Xrefs header, so we insert
9639                ;; it and replace the new article.
9640                (nnheader-replace-header "Xref" new-xref)
9641                (gnus-request-replace-article
9642                 (cdr art-group) to-newsgroup (current-buffer) t)
9643                art-group))))))
9644       (cond
9645        ((not art-group)
9646         (gnus-message 1 "Couldn't %s article %s: %s"
9647                       (cadr (assq action names)) article
9648                       (nnheader-get-report (car to-method))))
9649        ((eq art-group 'junk)
9650         (when (eq action 'move)
9651           (gnus-summary-mark-article article gnus-canceled-mark)
9652           (gnus-message 4 "Deleted article %s" article)
9653           ;; run the delete hook
9654           (run-hook-with-args 'gnus-summary-article-delete-hook
9655                               action
9656                               (gnus-data-header
9657                                (assoc article (gnus-data-list nil)))
9658                               gnus-newsgroup-name nil
9659                               select-method)))
9660        (t
9661         (let* ((pto-group (gnus-group-prefixed-name
9662                            (car art-group) to-method))
9663                (info (gnus-get-info pto-group))
9664                (to-group (gnus-info-group info))
9665                to-marks)
9666           ;; Update the group that has been moved to.
9667           (when (and info
9668                      (memq action '(move copy)))
9669             (unless (member to-group to-groups)
9670               (push to-group to-groups))
9671
9672             (unless (memq article gnus-newsgroup-unreads)
9673               (push 'read to-marks)
9674               (gnus-info-set-read
9675                info (gnus-add-to-range (gnus-info-read info)
9676                                        (list (cdr art-group)))))
9677
9678             ;; See whether the article is to be put in the cache.
9679             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9680                              gnus-article-mark-lists
9681                            (delete '(expirable . expire)
9682                                    (copy-sequence gnus-article-mark-lists))))
9683                   (to-article (cdr art-group)))
9684
9685               ;; Enter the article into the cache in the new group,
9686               ;; if that is required.
9687               (when gnus-use-cache
9688                 (gnus-cache-possibly-enter-article
9689                  to-group to-article
9690                  (memq article gnus-newsgroup-marked)
9691                  (memq article gnus-newsgroup-dormant)
9692                  (memq article gnus-newsgroup-unreads)))
9693
9694               (when gnus-preserve-marks
9695                 ;; Copy any marks over to the new group.
9696                 (when (and (equal to-group gnus-newsgroup-name)
9697                            (not (memq article gnus-newsgroup-unreads)))
9698                   ;; Mark this article as read in this group.
9699                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9700                   (setcdr (gnus-active to-group) to-article)
9701                   (setcdr gnus-newsgroup-active to-article))
9702
9703                 (while marks
9704                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9705                     (when (memq article (symbol-value
9706                                          (intern (format "gnus-newsgroup-%s"
9707                                                          (caar marks)))))
9708                       (push (cdar marks) to-marks)
9709                       ;; If the other group is the same as this group,
9710                       ;; then we have to add the mark to the list.
9711                       (when (equal to-group gnus-newsgroup-name)
9712                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9713                              (cons to-article
9714                                    (symbol-value
9715                                     (intern (format "gnus-newsgroup-%s"
9716                                                     (caar marks)))))))
9717                       ;; Copy the marks to other group.
9718                       (gnus-add-marked-articles
9719                        to-group (cdar marks) (list to-article) info)))
9720                   (setq marks (cdr marks)))
9721
9722                 (gnus-request-set-mark
9723                  to-group (list (list (list to-article) 'add to-marks))))
9724
9725               (gnus-dribble-enter
9726                (concat "(gnus-group-set-info '"
9727                        (gnus-prin1-to-string (gnus-get-info to-group))
9728                        ")"))))
9729
9730           ;; Update the Xref header in this article to point to
9731           ;; the new crossposted article we have just created.
9732           (when (eq action 'crosspost)
9733             (save-excursion
9734               (set-buffer copy-buf)
9735               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9736               (nnheader-replace-header "Xref" new-xref)
9737               (gnus-request-replace-article
9738                article gnus-newsgroup-name (current-buffer) t)))
9739
9740           ;; run the move/copy/crosspost/respool hook
9741           (run-hook-with-args 'gnus-summary-article-move-hook
9742                               action
9743                               (gnus-data-header
9744                                (assoc article (gnus-data-list nil)))
9745                               gnus-newsgroup-name
9746                               to-newsgroup
9747                               select-method))
9748
9749         ;;;!!!Why is this necessary?
9750         (set-buffer gnus-summary-buffer)
9751
9752         (gnus-summary-goto-subject article)
9753         (when (eq action 'move)
9754           (gnus-summary-mark-article article gnus-canceled-mark))))
9755       (push article articles-to-update-marks))
9756
9757     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9758     ;; Re-activate all groups that have been moved to.
9759     (save-excursion
9760       (set-buffer gnus-group-buffer)
9761       (let ((gnus-group-marked to-groups))
9762         (gnus-group-get-new-news-this-group nil t)))
9763
9764     (gnus-kill-buffer copy-buf)
9765     (gnus-summary-position-point)
9766     (gnus-set-mode-line 'summary)))
9767
9768 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9769   "Copy the current article to some other group.
9770 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9771 When called interactively, if TO-NEWSGROUP is nil, use the value of
9772 the variable `gnus-move-split-methods' for finding a default target
9773 newsgroup.
9774 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9775 re-spool using this method."
9776   (interactive "P")
9777   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9778
9779 (defun gnus-summary-crosspost-article (&optional n)
9780   "Crosspost the current article to some other group."
9781   (interactive "P")
9782   (gnus-summary-move-article n nil nil 'crosspost))
9783
9784 (defcustom gnus-summary-respool-default-method nil
9785   "Default method type for respooling an article.
9786 If nil, use to the current newsgroup method."
9787   :type 'symbol
9788   :group 'gnus-summary-mail)
9789
9790 (defcustom gnus-summary-display-while-building nil
9791   "If non-nil, show and update the summary buffer as it's being built.
9792 If the value is t, update the buffer after every line is inserted.  If
9793 the value is an integer (N), update the display every N lines."
9794   :version "22.1"
9795   :group 'gnus-thread
9796   :type '(choice (const :tag "off" nil)
9797                  number
9798                  (const :tag "frequently" t)))
9799
9800 (defun gnus-summary-respool-article (&optional n method)
9801   "Respool the current article.
9802 The article will be squeezed through the mail spooling process again,
9803 which means that it will be put in some mail newsgroup or other
9804 depending on `nnmail-split-methods'.
9805 If N is a positive number, respool the N next articles.
9806 If N is a negative number, respool the N previous articles.
9807 If N is nil and any articles have been marked with the process mark,
9808 respool those articles instead.
9809
9810 Respooling can be done both from mail groups and \"real\" newsgroups.
9811 In the former case, the articles in question will be moved from the
9812 current group into whatever groups they are destined to.  In the
9813 latter case, they will be copied into the relevant groups."
9814   (interactive
9815    (list current-prefix-arg
9816          (let* ((methods (gnus-methods-using 'respool))
9817                 (methname
9818                  (symbol-name (or gnus-summary-respool-default-method
9819                                   (car (gnus-find-method-for-group
9820                                         gnus-newsgroup-name)))))
9821                 (method
9822                  (gnus-completing-read-with-default
9823                   methname "Backend to use when respooling"
9824                   methods nil t nil 'gnus-mail-method-history))
9825                 ms)
9826            (cond
9827             ((zerop (length (setq ms (gnus-servers-using-backend
9828                                       (intern method)))))
9829              (list (intern method) ""))
9830             ((= 1 (length ms))
9831              (car ms))
9832             (t
9833              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9834                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9835                            ms-alist))))))))
9836   (unless method
9837     (error "No method given for respooling"))
9838   (if (assoc (symbol-name
9839               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9840              (gnus-methods-using 'respool))
9841       (gnus-summary-move-article n nil method)
9842     (gnus-summary-copy-article n nil method)))
9843
9844 (defun gnus-summary-import-article (file &optional edit)
9845   "Import an arbitrary file into a mail newsgroup."
9846   (interactive "fImport file: \nP")
9847   (let ((group gnus-newsgroup-name)
9848         (now (current-time))
9849         atts lines group-art)
9850     (unless (gnus-check-backend-function 'request-accept-article group)
9851       (error "%s does not support article importing" group))
9852     (or (file-readable-p file)
9853         (not (file-regular-p file))
9854         (error "Can't read %s" file))
9855     (save-excursion
9856       (set-buffer (gnus-get-buffer-create " *import file*"))
9857       (erase-buffer)
9858       (nnheader-insert-file-contents file)
9859       (goto-char (point-min))
9860       (if (nnheader-article-p)
9861           (save-restriction
9862             (goto-char (point-min))
9863             (search-forward "\n\n" nil t)
9864             (narrow-to-region (point-min) (1- (point)))
9865             (goto-char (point-min))
9866             (unless (re-search-forward "^date:" nil t)
9867               (goto-char (point-max))
9868               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9869        ;; This doesn't look like an article, so we fudge some headers.
9870         (setq atts (file-attributes file)
9871               lines (count-lines (point-min) (point-max)))
9872         (insert "From: " (read-string "From: ") "\n"
9873                 "Subject: " (read-string "Subject: ") "\n"
9874                 "Date: " (message-make-date (nth 5 atts)) "\n"
9875                 "Message-ID: " (message-make-message-id) "\n"
9876                 "Lines: " (int-to-string lines) "\n"
9877                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9878       (setq group-art (gnus-request-accept-article group nil t))
9879       (kill-buffer (current-buffer)))
9880     (setq gnus-newsgroup-active (gnus-activate-group group))
9881     (forward-line 1)
9882     (gnus-summary-goto-article (cdr group-art) nil t)
9883     (when edit
9884       (gnus-summary-edit-article))))
9885
9886 (defun gnus-summary-create-article ()
9887   "Create an article in a mail newsgroup."
9888   (interactive)
9889   (let ((group gnus-newsgroup-name)
9890         (now (current-time))
9891         group-art)
9892     (unless (gnus-check-backend-function 'request-accept-article group)
9893       (error "%s does not support article importing" group))
9894     (save-excursion
9895       (set-buffer (gnus-get-buffer-create " *import file*"))
9896       (erase-buffer)
9897       (goto-char (point-min))
9898       ;; This doesn't look like an article, so we fudge some headers.
9899       (insert "From: " (read-string "From: ") "\n"
9900               "Subject: " (read-string "Subject: ") "\n"
9901               "Date: " (message-make-date now) "\n"
9902               "Message-ID: " (message-make-message-id) "\n")
9903       (setq group-art (gnus-request-accept-article group nil t))
9904       (kill-buffer (current-buffer)))
9905     (setq gnus-newsgroup-active (gnus-activate-group group))
9906     (forward-line 1)
9907     (gnus-summary-goto-article (cdr group-art) nil t)
9908     (gnus-summary-edit-article)))
9909
9910 (defun gnus-summary-article-posted-p ()
9911   "Say whether the current (mail) article is available from news as well.
9912 This will be the case if the article has both been mailed and posted."
9913   (interactive)
9914   (let ((id (mail-header-references (gnus-summary-article-header)))
9915         (gnus-override-method (car (gnus-refer-article-methods))))
9916     (if (gnus-request-head id "")
9917         (gnus-message 2 "The current message was found on %s"
9918                       gnus-override-method)
9919       (gnus-message 2 "The current message couldn't be found on %s"
9920                     gnus-override-method)
9921       nil)))
9922
9923 (defun gnus-summary-expire-articles (&optional now)
9924   "Expire all articles that are marked as expirable in the current group."
9925   (interactive)
9926   (when (and (not gnus-group-is-exiting-without-update-p)
9927              (gnus-check-backend-function
9928               'request-expire-articles gnus-newsgroup-name))
9929     ;; This backend supports expiry.
9930     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9931            (expirable (if total
9932                           (progn
9933                             ;; We need to update the info for
9934                             ;; this group for `gnus-list-of-read-articles'
9935                             ;; to give us the right answer.
9936                             (gnus-run-hooks 'gnus-exit-group-hook)
9937                             (gnus-summary-update-info)
9938                             (gnus-list-of-read-articles gnus-newsgroup-name))
9939                         (setq gnus-newsgroup-expirable
9940                               (sort gnus-newsgroup-expirable '<))))
9941            (expiry-wait (if now 'immediate
9942                           (gnus-group-find-parameter
9943                            gnus-newsgroup-name 'expiry-wait)))
9944            (nnmail-expiry-target
9945             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9946                 nnmail-expiry-target))
9947            es)
9948       (when expirable
9949         ;; There are expirable articles in this group, so we run them
9950         ;; through the expiry process.
9951         (gnus-message 6 "Expiring articles...")
9952         (unless (gnus-check-group gnus-newsgroup-name)
9953           (error "Can't open server for %s" gnus-newsgroup-name))
9954         ;; The list of articles that weren't expired is returned.
9955         (save-excursion
9956           (if expiry-wait
9957               (let ((nnmail-expiry-wait-function nil)
9958                     (nnmail-expiry-wait expiry-wait))
9959                 (setq es (gnus-request-expire-articles
9960                           expirable gnus-newsgroup-name)))
9961             (setq es (gnus-request-expire-articles
9962                       expirable gnus-newsgroup-name)))
9963           (unless total
9964             (setq gnus-newsgroup-expirable es))
9965           ;; We go through the old list of expirable, and mark all
9966           ;; really expired articles as nonexistent.
9967           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9968             (let ((gnus-use-cache nil))
9969               (dolist (article expirable)
9970                 (when (and (not (memq article es))
9971                            (gnus-data-find article))
9972                   (gnus-summary-mark-article article gnus-canceled-mark)
9973                   (run-hook-with-args 'gnus-summary-article-expire-hook
9974                                       'delete
9975                                       (gnus-data-header
9976                                        (assoc article (gnus-data-list nil)))
9977                                       gnus-newsgroup-name
9978                                       nil
9979                                       nil))))))
9980         (gnus-message 6 "Expiring articles...done")))))
9981
9982 (defun gnus-summary-expire-articles-now ()
9983   "Expunge all expirable articles in the current group.
9984 This means that *all* articles that are marked as expirable will be
9985 deleted forever, right now."
9986   (interactive)
9987   (or gnus-expert-user
9988       (gnus-yes-or-no-p
9989        "Are you really, really sure you want to delete all expirable messages? ")
9990       (error "Phew!"))
9991   (gnus-summary-expire-articles t))
9992
9993 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9994 (defun gnus-summary-delete-article (&optional n)
9995   "Delete the N next (mail) articles.
9996 This command actually deletes articles.  This is not a marking
9997 command.  The article will disappear forever from your life, never to
9998 return.
9999
10000 If N is negative, delete backwards.
10001 If N is nil and articles have been marked with the process mark,
10002 delete these instead.
10003
10004 If `gnus-novice-user' is non-nil you will be asked for
10005 confirmation before the articles are deleted."
10006   (interactive "P")
10007   (unless (gnus-check-backend-function 'request-expire-articles
10008                                        gnus-newsgroup-name)
10009     (error "The current newsgroup does not support article deletion"))
10010   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10011     (error "Couldn't open server"))
10012   ;; Compute the list of articles to delete.
10013   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10014         (nnmail-expiry-target 'delete)
10015         not-deleted)
10016     (if (and gnus-novice-user
10017              (not (gnus-yes-or-no-p
10018                    (format "Do you really want to delete %s forever? "
10019                            (if (> (length articles) 1)
10020                                (format "these %s articles" (length articles))
10021                              "this article")))))
10022         ()
10023       ;; Delete the articles.
10024       (setq not-deleted (gnus-request-expire-articles
10025                          articles gnus-newsgroup-name 'force))
10026       (while articles
10027         (gnus-summary-remove-process-mark (car articles))
10028         ;; The backend might not have been able to delete the article
10029         ;; after all.
10030         (unless (memq (car articles) not-deleted)
10031           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10032         (let* ((article (car articles))
10033                (ghead  (gnus-data-header
10034                                     (assoc article (gnus-data-list nil)))))
10035           (run-hook-with-args 'gnus-summary-article-delete-hook
10036                               'delete ghead gnus-newsgroup-name nil
10037                               nil))
10038         (setq articles (cdr articles)))
10039       (when not-deleted
10040         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10041     (gnus-summary-position-point)
10042     (gnus-set-mode-line 'summary)
10043     not-deleted))
10044
10045 (defun gnus-summary-edit-article (&optional arg)
10046   "Edit the current article.
10047 This will have permanent effect only in mail groups.
10048 If ARG is nil, edit the decoded articles.
10049 If ARG is 1, edit the raw articles.
10050 If ARG is 2, edit the raw articles even in read-only groups.
10051 If ARG is 3, edit the articles with the current handles.
10052 Otherwise, allow editing of articles even in read-only
10053 groups."
10054   (interactive "P")
10055   (let (force raw current-handles)
10056     (cond
10057      ((null arg))
10058      ((eq arg 1)
10059       (setq raw t))
10060      ((eq arg 2)
10061       (setq raw t
10062             force t))
10063      ((eq arg 3)
10064       (setq current-handles
10065             (and (gnus-buffer-live-p gnus-article-buffer)
10066                  (with-current-buffer gnus-article-buffer
10067                    (prog1
10068                        gnus-article-mime-handles
10069                      (setq gnus-article-mime-handles nil))))))
10070      (t
10071       (setq force t)))
10072     (when (and raw (not force)
10073                (member gnus-newsgroup-name '("nndraft:delayed"
10074                                              "nndraft:drafts"
10075                                              "nndraft:queue")))
10076       (error "Can't edit the raw article in group %s"
10077              gnus-newsgroup-name))
10078     (save-excursion
10079       (set-buffer gnus-summary-buffer)
10080       (let ((mail-parse-charset gnus-newsgroup-charset)
10081             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10082         (gnus-set-global-variables)
10083         (when (and (not force)
10084                    (gnus-group-read-only-p))
10085           (error "The current newsgroup does not support article editing"))
10086         (gnus-summary-show-article t)
10087         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10088           (with-current-buffer gnus-article-buffer
10089             (mm-enable-multibyte)))
10090         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10091             (setq raw t))
10092         (gnus-article-edit-article
10093          (if raw 'ignore
10094            `(lambda ()
10095               (let ((mbl mml-buffer-list))
10096                 (setq mml-buffer-list nil)
10097                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10098                   (mime-to-mml ,'current-handles))
10099                 (let ((mbl1 mml-buffer-list))
10100                   (setq mml-buffer-list mbl)
10101                   (set (make-local-variable 'mml-buffer-list) mbl1))
10102                 (gnus-make-local-hook 'kill-buffer-hook)
10103                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10104          `(lambda (no-highlight)
10105             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10106                   (message-options message-options)
10107                   (message-options-set-recipient)
10108                   (mail-parse-ignored-charsets
10109                    ',gnus-newsgroup-ignored-charsets)
10110                   (rfc2047-header-encoding-alist
10111                    ',(let ((charset (gnus-group-name-charset
10112                                      (gnus-find-method-for-group
10113                                       gnus-newsgroup-name)
10114                                      gnus-newsgroup-name)))
10115                        (append (list (cons "Newsgroups" charset)
10116                                      (cons "Followup-To" charset)
10117                                      (cons "Xref" charset))
10118                                rfc2047-header-encoding-alist))))
10119               ,(if (not raw) '(progn
10120                                 (mml-to-mime)
10121                                 (mml-destroy-buffers)
10122                                 (remove-hook 'kill-buffer-hook
10123                                              'mml-destroy-buffers t)
10124                                 (kill-local-variable 'mml-buffer-list)))
10125               (gnus-summary-edit-article-done
10126                ,(or (mail-header-references gnus-current-headers) "")
10127                ,(gnus-group-read-only-p)
10128                ,gnus-summary-buffer no-highlight))))))))
10129
10130 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10131
10132 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10133                                                  no-highlight)
10134   "Make edits to the current article permanent."
10135   (interactive)
10136   (save-excursion
10137    ;; The buffer restriction contains the entire article if it exists.
10138     (when (article-goto-body)
10139       (let ((lines (count-lines (point) (point-max)))
10140             (length (- (point-max) (point)))
10141             (case-fold-search t)
10142             (body (copy-marker (point))))
10143         (goto-char (point-min))
10144         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10145           (delete-region (match-beginning 1) (match-end 1))
10146           (insert (number-to-string length)))
10147         (goto-char (point-min))
10148         (when (re-search-forward
10149                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10150           (delete-region (match-beginning 1) (match-end 1))
10151           (insert (number-to-string length)))
10152         (goto-char (point-min))
10153         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10154           (delete-region (match-beginning 1) (match-end 1))
10155           (insert (number-to-string lines))))))
10156   ;; Replace the article.
10157   (let ((buf (current-buffer)))
10158     (with-temp-buffer
10159       (insert-buffer-substring buf)
10160
10161       (if (and (not read-only)
10162                (not (gnus-request-replace-article
10163                      (cdr gnus-article-current) (car gnus-article-current)
10164                      (current-buffer) t)))
10165           (error "Couldn't replace article")
10166         ;; Update the summary buffer.
10167         (if (and references
10168                  (equal (message-tokenize-header references " ")
10169                         (message-tokenize-header
10170                          (or (message-fetch-field "references") "") " ")))
10171             ;; We only have to update this line.
10172             (save-excursion
10173               (save-restriction
10174                 (message-narrow-to-head)
10175                 (let ((head (buffer-substring-no-properties
10176                              (point-min) (point-max)))
10177                       header)
10178                   (with-temp-buffer
10179                     (insert (format "211 %d Article retrieved.\n"
10180                                     (cdr gnus-article-current)))
10181                     (insert head)
10182                     (insert ".\n")
10183                     (let ((nntp-server-buffer (current-buffer)))
10184                       (setq header (car (gnus-get-newsgroup-headers
10185                                          nil t))))
10186                     (save-excursion
10187                       (set-buffer gnus-summary-buffer)
10188                       (gnus-data-set-header
10189                        (gnus-data-find (cdr gnus-article-current))
10190                        header)
10191                       (gnus-summary-update-article-line
10192                        (cdr gnus-article-current) header)
10193                       (if (gnus-summary-goto-subject
10194                            (cdr gnus-article-current) nil t)
10195                           (gnus-summary-update-secondary-mark
10196                            (cdr gnus-article-current))))))))
10197           ;; Update threads.
10198           (set-buffer (or buffer gnus-summary-buffer))
10199           (gnus-summary-update-article (cdr gnus-article-current))
10200           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10201               (gnus-summary-update-secondary-mark
10202                (cdr gnus-article-current))))
10203         ;; Prettify the article buffer again.
10204         (unless no-highlight
10205           (save-excursion
10206             (set-buffer gnus-article-buffer)
10207             ;;;!!! Fix this -- article should be rehighlighted.
10208             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10209             (set-buffer gnus-original-article-buffer)
10210             (gnus-request-article
10211              (cdr gnus-article-current)
10212              (car gnus-article-current) (current-buffer))))
10213         ;; Prettify the summary buffer line.
10214         (when (gnus-visual-p 'summary-highlight 'highlight)
10215           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10216
10217 (defun gnus-summary-edit-wash (key)
10218   "Perform editing command KEY in the article buffer."
10219   (interactive
10220    (list
10221     (progn
10222       (message "%s" (concat (this-command-keys) "- "))
10223       (read-char))))
10224   (message "")
10225   (gnus-summary-edit-article)
10226   (execute-kbd-macro (concat (this-command-keys) key))
10227   (gnus-article-edit-done))
10228
10229 ;;; Respooling
10230
10231 (defun gnus-summary-respool-query (&optional silent trace)
10232   "Query where the respool algorithm would put this article."
10233   (interactive)
10234   (let (gnus-mark-article-hook)
10235     (gnus-summary-select-article)
10236     (save-excursion
10237       (set-buffer gnus-original-article-buffer)
10238       (let ((groups (nnmail-article-group 'identity trace)))
10239         (unless silent
10240           (if groups
10241               (message "This message would go to %s"
10242                        (mapconcat 'car groups ", "))
10243             (message "This message would go to no groups"))
10244           groups)))))
10245
10246 (defun gnus-summary-respool-trace ()
10247   "Trace where the respool algorithm would put this article.
10248 Display a buffer showing all fancy splitting patterns which matched."
10249   (interactive)
10250   (gnus-summary-respool-query nil t))
10251
10252 ;; Summary marking commands.
10253
10254 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10255   "Mark articles which has the same subject as read, and then select the next.
10256 If UNMARK is positive, remove any kind of mark.
10257 If UNMARK is negative, tick articles."
10258   (interactive "P")
10259   (when unmark
10260     (setq unmark (prefix-numeric-value unmark)))
10261   (let ((count
10262          (gnus-summary-mark-same-subject
10263           (gnus-summary-article-subject) unmark)))
10264     ;; Select next unread article.  If auto-select-same mode, should
10265     ;; select the first unread article.
10266     (gnus-summary-next-article t (and gnus-auto-select-same
10267                                       (gnus-summary-article-subject)))
10268     (gnus-message 7 "%d article%s marked as %s"
10269                   count (if (= count 1) " is" "s are")
10270                   (if unmark "unread" "read"))))
10271
10272 (defun gnus-summary-kill-same-subject (&optional unmark)
10273   "Mark articles which has the same subject as read.
10274 If UNMARK is positive, remove any kind of mark.
10275 If UNMARK is negative, tick articles."
10276   (interactive "P")
10277   (when unmark
10278     (setq unmark (prefix-numeric-value unmark)))
10279   (let ((count
10280          (gnus-summary-mark-same-subject
10281           (gnus-summary-article-subject) unmark)))
10282     ;; If marked as read, go to next unread subject.
10283     (when (null unmark)
10284       ;; Go to next unread subject.
10285       (gnus-summary-next-subject 1 t))
10286     (gnus-message 7 "%d articles are marked as %s"
10287                   count (if unmark "unread" "read"))))
10288
10289 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10290   "Mark articles with same SUBJECT as read, and return marked number.
10291 If optional argument UNMARK is positive, remove any kinds of marks.
10292 If optional argument UNMARK is negative, mark articles as unread instead."
10293   (let ((count 1))
10294     (save-excursion
10295       (cond
10296        ((null unmark)                   ; Mark as read.
10297         (while (and
10298                 (progn
10299                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10300                   (gnus-summary-show-thread) t)
10301                 (gnus-summary-find-subject subject))
10302           (setq count (1+ count))))
10303        ((> unmark 0)                    ; Tick.
10304         (while (and
10305                 (progn
10306                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10307                   (gnus-summary-show-thread) t)
10308                 (gnus-summary-find-subject subject))
10309           (setq count (1+ count))))
10310        (t                               ; Mark as unread.
10311         (while (and
10312                 (progn
10313                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10314                   (gnus-summary-show-thread) t)
10315                 (gnus-summary-find-subject subject))
10316           (setq count (1+ count)))))
10317       (gnus-set-mode-line 'summary)
10318       ;; Return the number of marked articles.
10319       count)))
10320
10321 (defun gnus-summary-mark-as-processable (n &optional unmark)
10322   "Set the process mark on the next N articles.
10323 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10324 the process mark instead.  The difference between N and the actual
10325 number of articles marked is returned."
10326   (interactive "P")
10327   (if (and (null n) (gnus-region-active-p))
10328       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10329     (setq n (prefix-numeric-value n))
10330     (let ((backward (< n 0))
10331           (n (abs n)))
10332       (while (and
10333               (> n 0)
10334               (if unmark
10335                   (gnus-summary-remove-process-mark
10336                    (gnus-summary-article-number))
10337                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10338               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10339         (setq n (1- n)))
10340       (when (/= 0 n)
10341         (gnus-message 7 "No more articles"))
10342       (gnus-summary-recenter)
10343       (gnus-summary-position-point)
10344       n)))
10345
10346 (defun gnus-summary-unmark-as-processable (n)
10347   "Remove the process mark from the next N articles.
10348 If N is negative, unmark backward instead.  The difference between N and
10349 the actual number of articles unmarked is returned."
10350   (interactive "P")
10351   (gnus-summary-mark-as-processable n t))
10352
10353 (defun gnus-summary-unmark-all-processable ()
10354   "Remove the process mark from all articles."
10355   (interactive)
10356   (save-excursion
10357     (while gnus-newsgroup-processable
10358       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10359   (gnus-summary-position-point))
10360
10361 (defun gnus-summary-add-mark (article type)
10362   "Mark ARTICLE with a mark of TYPE."
10363   (let ((vtype (car (assq type gnus-article-mark-lists)))
10364         var)
10365     (if (not vtype)
10366         (error "No such mark type: %s" type)
10367       (setq var (intern (format "gnus-newsgroup-%s" type)))
10368       (set var (cons article (symbol-value var)))
10369       (if (memq type '(processable cached replied forwarded recent saved))
10370           (gnus-summary-update-secondary-mark article)
10371         ;;; !!! This is bogus.  We should find out what primary
10372         ;;; !!! mark we want to set.
10373         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10374
10375 (defun gnus-summary-mark-as-expirable (n)
10376   "Mark N articles forward as expirable.
10377 If N is negative, mark backward instead.  The difference between N and
10378 the actual number of articles marked is returned."
10379   (interactive "p")
10380   (gnus-summary-mark-forward n gnus-expirable-mark))
10381
10382 (defun gnus-summary-mark-as-spam (n)
10383   "Mark N articles forward as spam.
10384 If N is negative, mark backward instead.  The difference between N and
10385 the actual number of articles marked is returned."
10386   (interactive "p")
10387   (gnus-summary-mark-forward n gnus-spam-mark))
10388
10389 (defun gnus-summary-mark-article-as-replied (article)
10390   "Mark ARTICLE as replied to and update the summary line.
10391 ARTICLE can also be a list of articles."
10392   (interactive (list (gnus-summary-article-number)))
10393   (let ((articles (if (listp article) article (list article))))
10394     (dolist (article articles)
10395       (unless (numberp article)
10396         (error "%s is not a number" article))
10397       (push article gnus-newsgroup-replied)
10398       (let ((buffer-read-only nil))
10399         (when (gnus-summary-goto-subject article nil t)
10400           (gnus-summary-update-secondary-mark article))))))
10401
10402 (defun gnus-summary-mark-article-as-forwarded (article)
10403   "Mark ARTICLE as forwarded and update the summary line.
10404 ARTICLE can also be a list of articles."
10405   (let ((articles (if (listp article) article (list article))))
10406     (dolist (article articles)
10407       (push article gnus-newsgroup-forwarded)
10408       (let ((buffer-read-only nil))
10409         (when (gnus-summary-goto-subject article nil t)
10410           (gnus-summary-update-secondary-mark article))))))
10411
10412 (defun gnus-summary-set-bookmark (article)
10413   "Set a bookmark in current article."
10414   (interactive (list (gnus-summary-article-number)))
10415   (when (or (not (get-buffer gnus-article-buffer))
10416             (not gnus-current-article)
10417             (not gnus-article-current)
10418             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10419     (error "No current article selected"))
10420   ;; Remove old bookmark, if one exists.
10421   (gnus-pull article gnus-newsgroup-bookmarks)
10422   ;; Set the new bookmark, which is on the form
10423   ;; (article-number . line-number-in-body).
10424   (push
10425    (cons article
10426          (with-current-buffer gnus-article-buffer
10427            (count-lines
10428             (min (point)
10429                  (save-excursion
10430                    (article-goto-body)
10431                    (point)))
10432             (point))))
10433    gnus-newsgroup-bookmarks)
10434   (gnus-message 6 "A bookmark has been added to the current article."))
10435
10436 (defun gnus-summary-remove-bookmark (article)
10437   "Remove the bookmark from the current article."
10438   (interactive (list (gnus-summary-article-number)))
10439   ;; Remove old bookmark, if one exists.
10440   (if (not (assq article gnus-newsgroup-bookmarks))
10441       (gnus-message 6 "No bookmark in current article.")
10442     (gnus-pull article gnus-newsgroup-bookmarks)
10443     (gnus-message 6 "Removed bookmark.")))
10444
10445 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10446 (defun gnus-summary-mark-as-dormant (n)
10447   "Mark N articles forward as dormant.
10448 If N is negative, mark backward instead.  The difference between N and
10449 the actual number of articles marked is returned."
10450   (interactive "p")
10451   (gnus-summary-mark-forward n gnus-dormant-mark))
10452
10453 (defun gnus-summary-set-process-mark (article)
10454   "Set the process mark on ARTICLE and update the summary line."
10455   (setq gnus-newsgroup-processable
10456         (cons article
10457               (delq article gnus-newsgroup-processable)))
10458   (when (gnus-summary-goto-subject article)
10459     (gnus-summary-show-thread)
10460     (gnus-summary-goto-subject article)
10461     (gnus-summary-update-secondary-mark article)))
10462
10463 (defun gnus-summary-remove-process-mark (&rest articles)
10464   "Remove the process mark from ARTICLES and update the summary line."
10465   (dolist (article articles)
10466     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10467     (when (gnus-summary-goto-subject article)
10468       (gnus-summary-show-thread)
10469       (gnus-summary-goto-subject article)
10470       (gnus-summary-update-secondary-mark article)))
10471   t)
10472
10473 (defun gnus-summary-set-saved-mark (article)
10474   "Set the process mark on ARTICLE and update the summary line."
10475   (push article gnus-newsgroup-saved)
10476   (when (gnus-summary-goto-subject article)
10477     (gnus-summary-update-secondary-mark article)))
10478
10479 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10480   "Mark N articles as read forwards.
10481 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10482 The difference between N and the actual number of articles marked is
10483 returned.
10484 If NO-EXPIRE, auto-expiry will be inhibited."
10485   (interactive "p")
10486   (gnus-summary-show-thread)
10487   (let ((backward (< n 0))
10488         (gnus-summary-goto-unread
10489          (and gnus-summary-goto-unread
10490               (not (eq gnus-summary-goto-unread 'never))
10491               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10492                                     gnus-ticked-mark gnus-dormant-mark)))))
10493         (n (abs n))
10494         (mark (or mark gnus-del-mark)))
10495     (while (and (> n 0)
10496                 (gnus-summary-mark-article nil mark no-expire)
10497                 (zerop (gnus-summary-next-subject
10498                         (if backward -1 1)
10499                         (and gnus-summary-goto-unread
10500                              (not (eq gnus-summary-goto-unread 'never)))
10501                         t)))
10502       (setq n (1- n)))
10503     (when (/= 0 n)
10504       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10505     (gnus-summary-recenter)
10506     (gnus-summary-position-point)
10507     (gnus-set-mode-line 'summary)
10508     n))
10509
10510 (defun gnus-summary-mark-article-as-read (mark)
10511   "Mark the current article quickly as read with MARK."
10512   (let ((article (gnus-summary-article-number)))
10513     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10514     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10515     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10516     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10517     (push (cons article mark) gnus-newsgroup-reads)
10518     ;; Possibly remove from cache, if that is used.
10519     (when gnus-use-cache
10520       (gnus-cache-enter-remove-article article))
10521     ;; Allow the backend to change the mark.
10522     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10523     ;; Check for auto-expiry.
10524     (when (and gnus-newsgroup-auto-expire
10525                (memq mark gnus-auto-expirable-marks))
10526       (setq mark gnus-expirable-mark)
10527       ;; Let the backend know about the mark change.
10528       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10529       (push article gnus-newsgroup-expirable))
10530     ;; Set the mark in the buffer.
10531     (gnus-summary-update-mark mark 'unread)
10532     t))
10533
10534 (defun gnus-summary-mark-article-as-unread (mark)
10535   "Mark the current article quickly as unread with MARK."
10536   (let* ((article (gnus-summary-article-number))
10537          (old-mark (gnus-summary-article-mark article)))
10538     ;; Allow the backend to change the mark.
10539     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10540     (if (eq mark old-mark)
10541         t
10542       (if (<= article 0)
10543           (progn
10544             (gnus-error 1 "Can't mark negative article numbers")
10545             nil)
10546         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10547         (setq gnus-newsgroup-spam-marked
10548               (delq article gnus-newsgroup-spam-marked))
10549         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10550         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10551         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10552         (cond ((= mark gnus-ticked-mark)
10553                (setq gnus-newsgroup-marked
10554                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10555                                               article)))
10556               ((= mark gnus-spam-mark)
10557                (setq gnus-newsgroup-spam-marked
10558                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10559                                               article)))
10560               ((= mark gnus-dormant-mark)
10561                (setq gnus-newsgroup-dormant
10562                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10563                                               article)))
10564               (t
10565                (setq gnus-newsgroup-unreads
10566                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10567                                               article))))
10568         (gnus-pull article gnus-newsgroup-reads)
10569
10570         ;; See whether the article is to be put in the cache.
10571         (and gnus-use-cache
10572              (vectorp (gnus-summary-article-header article))
10573              (save-excursion
10574                (gnus-cache-possibly-enter-article
10575                 gnus-newsgroup-name article
10576                 (= mark gnus-ticked-mark)
10577                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10578
10579         ;; Fix the mark.
10580         (gnus-summary-update-mark mark 'unread)
10581         t))))
10582
10583 (defun gnus-summary-mark-article (&optional article mark no-expire)
10584   "Mark ARTICLE with MARK.  MARK can be any character.
10585 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10586 `??' (dormant) and `?E' (expirable).
10587 If MARK is nil, then the default character `?r' is used.
10588 If ARTICLE is nil, then the article on the current line will be
10589 marked.
10590 If NO-EXPIRE, auto-expiry will be inhibited."
10591   ;; The mark might be a string.
10592   (when (stringp mark)
10593     (setq mark (aref mark 0)))
10594   ;; If no mark is given, then we check auto-expiring.
10595   (when (null mark)
10596     (setq mark gnus-del-mark))
10597   (when (and (not no-expire)
10598              gnus-newsgroup-auto-expire
10599              (memq mark gnus-auto-expirable-marks))
10600     (setq mark gnus-expirable-mark))
10601   (let ((article (or article (gnus-summary-article-number)))
10602         (old-mark (gnus-summary-article-mark article)))
10603     ;; Allow the backend to change the mark.
10604     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10605     (if (eq mark old-mark)
10606         t
10607       (unless article
10608         (error "No article on current line"))
10609       (if (not (if (or (= mark gnus-unread-mark)
10610                        (= mark gnus-ticked-mark)
10611                        (= mark gnus-spam-mark)
10612                        (= mark gnus-dormant-mark))
10613                    (gnus-mark-article-as-unread article mark)
10614                  (gnus-mark-article-as-read article mark)))
10615           t
10616         ;; See whether the article is to be put in the cache.
10617         (and gnus-use-cache
10618              (not (= mark gnus-canceled-mark))
10619              (vectorp (gnus-summary-article-header article))
10620              (save-excursion
10621                (gnus-cache-possibly-enter-article
10622                 gnus-newsgroup-name article
10623                 (= mark gnus-ticked-mark)
10624                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10625
10626         (when (gnus-summary-goto-subject article nil t)
10627           (let ((buffer-read-only nil))
10628             (gnus-summary-show-thread)
10629             ;; Fix the mark.
10630             (gnus-summary-update-mark mark 'unread)
10631             t))))))
10632
10633 (defun gnus-summary-update-secondary-mark (article)
10634   "Update the secondary (read, process, cache) mark."
10635   (gnus-summary-update-mark
10636    (cond ((memq article gnus-newsgroup-processable)
10637           gnus-process-mark)
10638          ((memq article gnus-newsgroup-cached)
10639           gnus-cached-mark)
10640          ((memq article gnus-newsgroup-replied)
10641           gnus-replied-mark)
10642          ((memq article gnus-newsgroup-forwarded)
10643           gnus-forwarded-mark)
10644          ((memq article gnus-newsgroup-saved)
10645           gnus-saved-mark)
10646          ((memq article gnus-newsgroup-recent)
10647           gnus-recent-mark)
10648          ((memq article gnus-newsgroup-unseen)
10649           gnus-unseen-mark)
10650          (t gnus-no-mark))
10651    'replied)
10652   (when (gnus-visual-p 'summary-highlight 'highlight)
10653     (gnus-run-hooks 'gnus-summary-update-hook))
10654   t)
10655
10656 (defun gnus-summary-update-download-mark (article)
10657   "Update the download mark."
10658   (gnus-summary-update-mark
10659    (cond ((memq article gnus-newsgroup-undownloaded)
10660           gnus-undownloaded-mark)
10661          (gnus-newsgroup-agentized
10662           gnus-downloaded-mark)
10663          (t
10664           gnus-no-mark))
10665    'download)
10666   (gnus-summary-update-line t)
10667   t)
10668
10669 (defun gnus-summary-update-mark (mark type)
10670   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10671         (buffer-read-only nil))
10672     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10673     (when forward
10674       (when (looking-at "\r")
10675         (incf forward))
10676       (when (<= (+ forward (point)) (point-max))
10677         ;; Go to the right position on the line.
10678         (goto-char (+ forward (point)))
10679         ;; Replace the old mark with the new mark.
10680         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10681         ;; Optionally update the marks by some user rule.
10682         (when (eq type 'unread)
10683           (gnus-data-set-mark
10684            (gnus-data-find (gnus-summary-article-number)) mark)
10685           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10686
10687 (defun gnus-mark-article-as-read (article &optional mark)
10688   "Enter ARTICLE in the pertinent lists and remove it from others."
10689   ;; Make the article expirable.
10690   (let ((mark (or mark gnus-del-mark)))
10691     (setq gnus-newsgroup-expirable
10692           (if (= mark gnus-expirable-mark)
10693               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10694             (delq article gnus-newsgroup-expirable)))
10695     ;; Remove from unread and marked lists.
10696     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10697     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10698     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10699     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10700     (push (cons article mark) gnus-newsgroup-reads)
10701     ;; Possibly remove from cache, if that is used.
10702     (when gnus-use-cache
10703       (gnus-cache-enter-remove-article article))
10704     t))
10705
10706 (defun gnus-mark-article-as-unread (article &optional mark)
10707   "Enter ARTICLE in the pertinent lists and remove it from others."
10708   (let ((mark (or mark gnus-ticked-mark)))
10709     (if (<= article 0)
10710         (progn
10711           (gnus-error 1 "Can't mark negative article numbers")
10712           nil)
10713       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10714             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10715             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10716             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10717             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10718
10719       ;; Unsuppress duplicates?
10720       (when gnus-suppress-duplicates
10721         (gnus-dup-unsuppress-article article))
10722
10723       (cond ((= mark gnus-ticked-mark)
10724              (setq gnus-newsgroup-marked
10725                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10726             ((= mark gnus-spam-mark)
10727              (setq gnus-newsgroup-spam-marked
10728                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10729                                             article)))
10730             ((= mark gnus-dormant-mark)
10731              (setq gnus-newsgroup-dormant
10732                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10733             (t
10734              (setq gnus-newsgroup-unreads
10735                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10736       (gnus-pull article gnus-newsgroup-reads)
10737       t)))
10738
10739 (defalias 'gnus-summary-mark-as-unread-forward
10740   'gnus-summary-tick-article-forward)
10741 (make-obsolete 'gnus-summary-mark-as-unread-forward
10742                'gnus-summary-tick-article-forward)
10743 (defun gnus-summary-tick-article-forward (n)
10744   "Tick N articles forwards.
10745 If N is negative, tick backwards instead.
10746 The difference between N and the number of articles ticked is returned."
10747   (interactive "p")
10748   (gnus-summary-mark-forward n gnus-ticked-mark))
10749
10750 (defalias 'gnus-summary-mark-as-unread-backward
10751   'gnus-summary-tick-article-backward)
10752 (make-obsolete 'gnus-summary-mark-as-unread-backward
10753                'gnus-summary-tick-article-backward)
10754 (defun gnus-summary-tick-article-backward (n)
10755   "Tick N articles backwards.
10756 The difference between N and the number of articles ticked is returned."
10757   (interactive "p")
10758   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10759
10760 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10761 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10762 (defun gnus-summary-tick-article (&optional article clear-mark)
10763   "Mark current article as unread.
10764 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10765 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10766   (interactive)
10767   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10768                                        gnus-ticked-mark)))
10769
10770 (defun gnus-summary-mark-as-read-forward (n)
10771   "Mark N articles as read forwards.
10772 If N is negative, mark backwards instead.
10773 The difference between N and the actual number of articles marked is
10774 returned."
10775   (interactive "p")
10776   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10777
10778 (defun gnus-summary-mark-as-read-backward (n)
10779   "Mark the N articles as read backwards.
10780 The difference between N and the actual number of articles marked is
10781 returned."
10782   (interactive "p")
10783   (gnus-summary-mark-forward
10784    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10785
10786 (defun gnus-summary-mark-as-read (&optional article mark)
10787   "Mark current article as read.
10788 ARTICLE specifies the article to be marked as read.
10789 MARK specifies a string to be inserted at the beginning of the line."
10790   (gnus-summary-mark-article article mark))
10791
10792 (defun gnus-summary-clear-mark-forward (n)
10793   "Clear marks from N articles forward.
10794 If N is negative, clear backward instead.
10795 The difference between N and the number of marks cleared is returned."
10796   (interactive "p")
10797   (gnus-summary-mark-forward n gnus-unread-mark))
10798
10799 (defun gnus-summary-clear-mark-backward (n)
10800   "Clear marks from N articles backward.
10801 The difference between N and the number of marks cleared is returned."
10802   (interactive "p")
10803   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10804
10805 (defun gnus-summary-mark-unread-as-read ()
10806   "Intended to be used by `gnus-summary-mark-article-hook'."
10807   (when (memq gnus-current-article gnus-newsgroup-unreads)
10808     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10809
10810 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10811   "Intended to be used by `gnus-summary-mark-article-hook'."
10812   (let ((mark (gnus-summary-article-mark)))
10813     (when (or (gnus-unread-mark-p mark)
10814               (gnus-read-mark-p mark))
10815       (gnus-summary-mark-article gnus-current-article
10816                                  (or new-mark gnus-read-mark)))))
10817
10818 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10819   "Intended to be used by `gnus-summary-mark-article-hook'."
10820   (let ((mark (gnus-summary-article-mark)))
10821     (when (or (gnus-unread-mark-p mark)
10822               (gnus-read-mark-p mark))
10823       (gnus-summary-mark-article (gnus-summary-article-number)
10824                                  (or new-mark gnus-read-mark)))))
10825
10826 (defun gnus-summary-mark-unread-as-ticked ()
10827   "Intended to be used by `gnus-summary-mark-article-hook'."
10828   (when (memq gnus-current-article gnus-newsgroup-unreads)
10829     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10830
10831 (defun gnus-summary-mark-region-as-read (point mark all)
10832   "Mark all unread articles between point and mark as read.
10833 If given a prefix, mark all articles between point and mark as read,
10834 even ticked and dormant ones."
10835   (interactive "r\nP")
10836   (save-excursion
10837     (let (article)
10838       (goto-char point)
10839       (beginning-of-line)
10840       (while (and
10841               (< (point) mark)
10842               (progn
10843                 (when (or all
10844                           (memq (setq article (gnus-summary-article-number))
10845                                 gnus-newsgroup-unreads))
10846                   (gnus-summary-mark-article article gnus-del-mark))
10847                 t)
10848               (gnus-summary-find-next))))))
10849
10850 (defun gnus-summary-mark-below (score mark)
10851   "Mark articles with score less than SCORE with MARK."
10852   (interactive "P\ncMark: ")
10853   (setq score (if score
10854                   (prefix-numeric-value score)
10855                 (or gnus-summary-default-score 0)))
10856   (save-excursion
10857     (set-buffer gnus-summary-buffer)
10858     (goto-char (point-min))
10859     (while
10860         (progn
10861           (and (< (gnus-summary-article-score) score)
10862                (gnus-summary-mark-article nil mark))
10863           (gnus-summary-find-next)))))
10864
10865 (defun gnus-summary-kill-below (&optional score)
10866   "Mark articles with score below SCORE as read."
10867   (interactive "P")
10868   (gnus-summary-mark-below score gnus-killed-mark))
10869
10870 (defun gnus-summary-clear-above (&optional score)
10871   "Clear all marks from articles with score above SCORE."
10872   (interactive "P")
10873   (gnus-summary-mark-above score gnus-unread-mark))
10874
10875 (defun gnus-summary-tick-above (&optional score)
10876   "Tick all articles with score above SCORE."
10877   (interactive "P")
10878   (gnus-summary-mark-above score gnus-ticked-mark))
10879
10880 (defun gnus-summary-mark-above (score mark)
10881   "Mark articles with score over SCORE with MARK."
10882   (interactive "P\ncMark: ")
10883   (setq score (if score
10884                   (prefix-numeric-value score)
10885                 (or gnus-summary-default-score 0)))
10886   (save-excursion
10887     (set-buffer gnus-summary-buffer)
10888     (goto-char (point-min))
10889     (while (and (progn
10890                   (when (> (gnus-summary-article-score) score)
10891                     (gnus-summary-mark-article nil mark))
10892                   t)
10893                 (gnus-summary-find-next)))))
10894
10895 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10896 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10897 (defun gnus-summary-limit-include-expunged (&optional no-error)
10898   "Display all the hidden articles that were expunged for low scores."
10899   (interactive)
10900   (let ((buffer-read-only nil))
10901     (let ((scored gnus-newsgroup-scored)
10902           headers h)
10903       (while scored
10904         (unless (gnus-summary-article-header (caar scored))
10905           (and (setq h (gnus-number-to-header (caar scored)))
10906                (< (cdar scored) gnus-summary-expunge-below)
10907                (push h headers)))
10908         (setq scored (cdr scored)))
10909       (if (not headers)
10910           (when (not no-error)
10911             (error "No expunged articles hidden"))
10912         (goto-char (point-min))
10913         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10914         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10915         (mapcar (lambda (x) (push (mail-header-number x)
10916                                   gnus-newsgroup-limit))
10917                 headers)
10918         (gnus-summary-prepare-unthreaded (nreverse headers))
10919         (goto-char (point-min))
10920         (gnus-summary-position-point)
10921         t))))
10922
10923 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10924   "Mark all unread articles in this newsgroup as read.
10925 If prefix argument ALL is non-nil, ticked and dormant articles will
10926 also be marked as read.
10927 If QUIETLY is non-nil, no questions will be asked.
10928
10929 If TO-HERE is non-nil, it should be a point in the buffer.  All
10930 articles before (after, if REVERSE is set) this point will be marked
10931 as read.
10932
10933 Note that this function will only catch up the unread article
10934 in the current summary buffer limitation.
10935
10936 The number of articles marked as read is returned."
10937   (interactive "P")
10938   (prog1
10939       (save-excursion
10940         (when (or quietly
10941                   (not gnus-interactive-catchup) ;Without confirmation?
10942                   gnus-expert-user
10943                   (gnus-y-or-n-p
10944                    (if all
10945                        "Mark absolutely all articles as read? "
10946                      "Mark all unread articles as read? ")))
10947           (if (and not-mark
10948                    (not gnus-newsgroup-adaptive)
10949                    (not gnus-newsgroup-auto-expire)
10950                    (not gnus-suppress-duplicates)
10951                    (or (not gnus-use-cache)
10952                        (eq gnus-use-cache 'passive)))
10953               (progn
10954                 (when all
10955                   (setq gnus-newsgroup-marked nil
10956                         gnus-newsgroup-spam-marked nil
10957                         gnus-newsgroup-dormant nil))
10958                 (setq gnus-newsgroup-unreads
10959                       (gnus-sorted-nunion
10960                        (gnus-sorted-intersection gnus-newsgroup-unreads
10961                                                  gnus-newsgroup-downloadable)
10962                        (gnus-sorted-difference gnus-newsgroup-unfetched
10963                                                gnus-newsgroup-cached))))
10964             ;; We actually mark all articles as canceled, which we
10965             ;; have to do when using auto-expiry or adaptive scoring.
10966             (gnus-summary-show-all-threads)
10967             (if (and to-here reverse)
10968                 (progn
10969                   (goto-char to-here)
10970                   (gnus-summary-mark-current-read-and-unread-as-read
10971                    gnus-catchup-mark)
10972                   (while (gnus-summary-find-next (not all))
10973                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10974               (when (gnus-summary-first-subject (not all))
10975                 (while (and
10976                         (if to-here (< (point) to-here) t)
10977                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10978                         (gnus-summary-find-next (not all))))))
10979             (gnus-set-mode-line 'summary))
10980           t))
10981     (gnus-summary-position-point)))
10982
10983 (defun gnus-summary-catchup-to-here (&optional all)
10984   "Mark all unticked articles before the current one as read.
10985 If ALL is non-nil, also mark ticked and dormant articles as read."
10986   (interactive "P")
10987   (save-excursion
10988     (gnus-save-hidden-threads
10989       (let ((beg (point)))
10990         ;; We check that there are unread articles.
10991         (when (or all (gnus-summary-find-prev))
10992           (gnus-summary-catchup all t beg)))))
10993   (gnus-summary-position-point))
10994
10995 (defun gnus-summary-catchup-from-here (&optional all)
10996   "Mark all unticked articles after (and including) the current one as read.
10997 If ALL is non-nil, also mark ticked and dormant articles as read."
10998   (interactive "P")
10999   (save-excursion
11000     (gnus-save-hidden-threads
11001       (let ((beg (point)))
11002         ;; We check that there are unread articles.
11003         (when (or all (gnus-summary-find-next))
11004           (gnus-summary-catchup all t beg nil t)))))
11005   (gnus-summary-position-point))
11006
11007 (defun gnus-summary-catchup-all (&optional quietly)
11008   "Mark all articles in this newsgroup as read.
11009 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11010 instead, which marks only unread articles as read."
11011   (interactive "P")
11012   (gnus-summary-catchup t quietly))
11013
11014 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11015   "Mark all unread articles in this group as read, then exit.
11016 If prefix argument ALL is non-nil, all articles are marked as read.
11017 If QUIETLY is non-nil, no questions will be asked."
11018   (interactive "P")
11019   (when (gnus-summary-catchup all quietly nil 'fast)
11020     ;; Select next newsgroup or exit.
11021     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11022              (eq gnus-auto-select-next 'quietly))
11023         (gnus-summary-next-group nil)
11024       (gnus-summary-exit))))
11025
11026 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11027   "Mark all articles in this newsgroup as read, and then exit.
11028 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11029 instead, which marks only unread articles as read."
11030   (interactive "P")
11031   (gnus-summary-catchup-and-exit t quietly))
11032
11033 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11034   "Mark all articles in this group as read and select the next group.
11035 If given a prefix, mark all articles, unread as well as ticked, as
11036 read."
11037   (interactive "P")
11038   (save-excursion
11039     (gnus-summary-catchup all))
11040   (gnus-summary-next-group))
11041
11042 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11043   "Mark all articles in this group as read and select the previous group.
11044 If given a prefix, mark all articles, unread as well as ticked, as
11045 read."
11046   (interactive "P")
11047   (save-excursion
11048     (gnus-summary-catchup all))
11049   (gnus-summary-next-group nil nil t))
11050
11051 ;;;
11052 ;;; with article
11053 ;;;
11054
11055 (defmacro gnus-with-article (article &rest forms)
11056   "Select ARTICLE and perform FORMS in the original article buffer.
11057 Then replace the article with the result."
11058   `(progn
11059      ;; We don't want the article to be marked as read.
11060      (let (gnus-mark-article-hook)
11061        (gnus-summary-select-article t t nil ,article))
11062      (set-buffer gnus-original-article-buffer)
11063      ,@forms
11064      (if (not (gnus-check-backend-function
11065                'request-replace-article (car gnus-article-current)))
11066          (gnus-message 5 "Read-only group; not replacing")
11067        (unless (gnus-request-replace-article
11068                 ,article (car gnus-article-current)
11069                 (current-buffer) t)
11070          (error "Couldn't replace article")))
11071      ;; The cache and backlog have to be flushed somewhat.
11072      (when gnus-keep-backlog
11073        (gnus-backlog-remove-article
11074         (car gnus-article-current) (cdr gnus-article-current)))
11075      (when gnus-use-cache
11076        (gnus-cache-update-article
11077         (car gnus-article-current) (cdr gnus-article-current)))))
11078
11079 (put 'gnus-with-article 'lisp-indent-function 1)
11080 (put 'gnus-with-article 'edebug-form-spec '(form body))
11081
11082 ;; Thread-based commands.
11083
11084 (defun gnus-summary-articles-in-thread (&optional article)
11085   "Return a list of all articles in the current thread.
11086 If ARTICLE is non-nil, return all articles in the thread that starts
11087 with that article."
11088   (let* ((article (or article (gnus-summary-article-number)))
11089          (data (gnus-data-find-list article))
11090          (top-level (gnus-data-level (car data)))
11091          (top-subject
11092           (cond ((null gnus-thread-operation-ignore-subject)
11093                  (gnus-simplify-subject-re
11094                   (mail-header-subject (gnus-data-header (car data)))))
11095                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11096                  (gnus-simplify-subject-fuzzy
11097                   (mail-header-subject (gnus-data-header (car data)))))
11098                 (t nil)))
11099          (end-point (save-excursion
11100                       (if (gnus-summary-go-to-next-thread)
11101                           (point) (point-max))))
11102          articles)
11103     (while (and data
11104                 (< (gnus-data-pos (car data)) end-point))
11105       (when (or (not top-subject)
11106                 (string= top-subject
11107                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11108                              (gnus-simplify-subject-fuzzy
11109                               (mail-header-subject
11110                                (gnus-data-header (car data))))
11111                            (gnus-simplify-subject-re
11112                             (mail-header-subject
11113                              (gnus-data-header (car data)))))))
11114         (push (gnus-data-number (car data)) articles))
11115       (unless (and (setq data (cdr data))
11116                    (> (gnus-data-level (car data)) top-level))
11117         (setq data nil)))
11118     ;; Return the list of articles.
11119     (nreverse articles)))
11120
11121 (defun gnus-summary-rethread-current ()
11122   "Rethread the thread the current article is part of."
11123   (interactive)
11124   (let* ((gnus-show-threads t)
11125          (article (gnus-summary-article-number))
11126          (id (mail-header-id (gnus-summary-article-header)))
11127          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11128     (unless id
11129       (error "No article on the current line"))
11130     (gnus-rebuild-thread id)
11131     (gnus-summary-goto-subject article)))
11132
11133 (defun gnus-summary-reparent-thread ()
11134   "Make the current article child of the marked (or previous) article.
11135
11136 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11137 is non-nil or the Subject: of both articles are the same."
11138   (interactive)
11139   (unless (not (gnus-group-read-only-p))
11140     (error "The current newsgroup does not support article editing"))
11141   (unless (<= (length gnus-newsgroup-processable) 1)
11142     (error "No more than one article may be marked"))
11143   (let ((child (gnus-summary-article-number))
11144         ;; First grab the marked article, otherwise one line up.
11145         (parent (if (not (null gnus-newsgroup-processable))
11146                     (car gnus-newsgroup-processable)
11147                   (save-excursion
11148                     (if (eq (forward-line -1) 0)
11149                         (gnus-summary-article-number)
11150                       (error "Beginning of summary buffer"))))))
11151     (gnus-summary-reparent-children parent (list child))))
11152
11153 (defun gnus-summary-reparent-children (parent children)
11154   "Make PARENT the parent of CHILDREN.
11155 When called interactively, PARENT is the current article and CHILDREN
11156 are the process-marked articles."
11157   (interactive
11158    (list (gnus-summary-article-number)
11159          (gnus-summary-work-articles nil)))
11160   (dolist (child children)
11161     (save-window-excursion
11162       (let ((gnus-article-buffer " *reparent*"))
11163         (unless (not (eq parent child))
11164           (error "An article may not be self-referential"))
11165         (let ((message-id (mail-header-id
11166                            (gnus-summary-article-header parent))))
11167           (unless (and message-id (not (equal message-id "")))
11168             (error "No message-id in desired parent"))
11169           (gnus-with-article child
11170             (save-restriction
11171               (goto-char (point-min))
11172               (message-narrow-to-head)
11173               (if (re-search-forward "^References: " nil t)
11174                   (progn
11175                     (re-search-forward "^[^ \t]" nil t)
11176                     (forward-line -1)
11177                     (end-of-line)
11178                     (insert " " message-id))
11179                 (insert "References: " message-id "\n"))))
11180           (set-buffer gnus-summary-buffer)
11181           (gnus-summary-unmark-all-processable)
11182           (gnus-summary-update-article child)
11183           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11184             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11185           (gnus-summary-rethread-current)
11186           (gnus-message 3 "Article %d is now the child of article %d"
11187                         child parent))))))
11188
11189 (defun gnus-summary-toggle-threads (&optional arg)
11190   "Toggle showing conversation threads.
11191 If ARG is positive number, turn showing conversation threads on."
11192   (interactive "P")
11193   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11194     (setq gnus-show-threads
11195           (if (null arg) (not gnus-show-threads)
11196             (> (prefix-numeric-value arg) 0)))
11197     (gnus-summary-prepare)
11198     (gnus-summary-goto-subject current)
11199     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11200     (gnus-summary-position-point)))
11201
11202 (defun gnus-summary-show-all-threads ()
11203   "Show all threads."
11204   (interactive)
11205   (save-excursion
11206     (let ((buffer-read-only nil))
11207       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11208   (gnus-summary-position-point))
11209
11210 (defun gnus-summary-show-thread ()
11211   "Show thread subtrees.
11212 Returns nil if no thread was there to be shown."
11213   (interactive)
11214   (let ((buffer-read-only nil)
11215         (orig (point))
11216         (end (point-at-eol))
11217         ;; Leave point at bol
11218         (beg (progn (beginning-of-line) (point))))
11219     (prog1
11220         ;; Any hidden lines here?
11221         (search-forward "\r" end t)
11222       (subst-char-in-region beg end ?\^M ?\n t)
11223       (goto-char orig)
11224       (gnus-summary-position-point))))
11225
11226 (defun gnus-summary-maybe-hide-threads ()
11227   "If requested, hide the threads that should be hidden."
11228   (when (and gnus-show-threads
11229              gnus-thread-hide-subtree)
11230     (gnus-summary-hide-all-threads
11231      (if (or (consp gnus-thread-hide-subtree)
11232              (functionp gnus-thread-hide-subtree))
11233          (gnus-make-predicate gnus-thread-hide-subtree)
11234        nil))))
11235
11236 ;;; Hiding predicates.
11237
11238 (defun gnus-article-unread-p (header)
11239   (memq (mail-header-number header) gnus-newsgroup-unreads))
11240
11241 (defun gnus-article-unseen-p (header)
11242   (memq (mail-header-number header) gnus-newsgroup-unseen))
11243
11244 (defun gnus-map-articles (predicate articles)
11245   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11246   (apply 'gnus-or (mapcar predicate
11247                           (mapcar (lambda (number)
11248                                     (gnus-summary-article-header number))
11249                                   articles))))
11250
11251 (defun gnus-summary-hide-all-threads (&optional predicate)
11252   "Hide all thread subtrees.
11253 If PREDICATE is supplied, threads that satisfy this predicate
11254 will not be hidden."
11255   (interactive)
11256   (save-excursion
11257     (goto-char (point-min))
11258     (let ((end nil))
11259       (while (not end)
11260         (when (or (not predicate)
11261                   (gnus-map-articles
11262                    predicate (gnus-summary-article-children)))
11263             (gnus-summary-hide-thread))
11264         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11265   (gnus-summary-position-point))
11266
11267 (defun gnus-summary-hide-thread ()
11268   "Hide thread subtrees.
11269 If PREDICATE is supplied, threads that satisfy this predicate
11270 will not be hidden.
11271 Returns nil if no threads were there to be hidden."
11272   (interactive)
11273   (let ((buffer-read-only nil)
11274         (start (point))
11275         (article (gnus-summary-article-number)))
11276     (goto-char start)
11277     ;; Go forward until either the buffer ends or the subthread
11278     ;; ends.
11279     (when (and (not (eobp))
11280                (or (zerop (gnus-summary-next-thread 1 t))
11281                    (goto-char (point-max))))
11282       (prog1
11283           (if (and (> (point) start)
11284                    (search-backward "\n" start t))
11285               (progn
11286                 (subst-char-in-region start (point) ?\n ?\^M)
11287                 (gnus-summary-goto-subject article))
11288             (goto-char start)
11289             nil)))))
11290
11291 (defun gnus-summary-go-to-next-thread (&optional previous)
11292   "Go to the same level (or less) next thread.
11293 If PREVIOUS is non-nil, go to previous thread instead.
11294 Return the article number moved to, or nil if moving was impossible."
11295   (let ((level (gnus-summary-thread-level))
11296         (way (if previous -1 1))
11297         (beg (point)))
11298     (forward-line way)
11299     (while (and (not (eobp))
11300                 (< level (gnus-summary-thread-level)))
11301       (forward-line way))
11302     (if (eobp)
11303         (progn
11304           (goto-char beg)
11305           nil)
11306       (setq beg (point))
11307       (prog1
11308           (gnus-summary-article-number)
11309         (goto-char beg)))))
11310
11311 (defun gnus-summary-next-thread (n &optional silent)
11312   "Go to the same level next N'th thread.
11313 If N is negative, search backward instead.
11314 Returns the difference between N and the number of skips actually
11315 done.
11316
11317 If SILENT, don't output messages."
11318   (interactive "p")
11319   (let ((backward (< n 0))
11320         (n (abs n)))
11321     (while (and (> n 0)
11322                 (gnus-summary-go-to-next-thread backward))
11323       (decf n))
11324     (unless silent
11325       (gnus-summary-position-point))
11326     (when (and (not silent) (/= 0 n))
11327       (gnus-message 7 "No more threads"))
11328     n))
11329
11330 (defun gnus-summary-prev-thread (n)
11331   "Go to the same level previous N'th thread.
11332 Returns the difference between N and the number of skips actually
11333 done."
11334   (interactive "p")
11335   (gnus-summary-next-thread (- n)))
11336
11337 (defun gnus-summary-go-down-thread ()
11338   "Go down one level in the current thread."
11339   (let ((children (gnus-summary-article-children)))
11340     (when children
11341       (gnus-summary-goto-subject (car children)))))
11342
11343 (defun gnus-summary-go-up-thread ()
11344   "Go up one level in the current thread."
11345   (let ((parent (gnus-summary-article-parent)))
11346     (when parent
11347       (gnus-summary-goto-subject parent))))
11348
11349 (defun gnus-summary-down-thread (n)
11350   "Go down thread N steps.
11351 If N is negative, go up instead.
11352 Returns the difference between N and how many steps down that were
11353 taken."
11354   (interactive "p")
11355   (let ((up (< n 0))
11356         (n (abs n)))
11357     (while (and (> n 0)
11358                 (if up (gnus-summary-go-up-thread)
11359                   (gnus-summary-go-down-thread)))
11360       (setq n (1- n)))
11361     (gnus-summary-position-point)
11362     (when (/= 0 n)
11363       (gnus-message 7 "Can't go further"))
11364     n))
11365
11366 (defun gnus-summary-up-thread (n)
11367   "Go up thread N steps.
11368 If N is negative, go down instead.
11369 Returns the difference between N and how many steps down that were
11370 taken."
11371   (interactive "p")
11372   (gnus-summary-down-thread (- n)))
11373
11374 (defun gnus-summary-top-thread ()
11375   "Go to the top of the thread."
11376   (interactive)
11377   (while (gnus-summary-go-up-thread))
11378   (gnus-summary-article-number))
11379
11380 (defun gnus-summary-kill-thread (&optional unmark)
11381   "Mark articles under current thread as read.
11382 If the prefix argument is positive, remove any kinds of marks.
11383 If the prefix argument is negative, tick articles instead."
11384   (interactive "P")
11385   (when unmark
11386     (setq unmark (prefix-numeric-value unmark)))
11387   (let ((articles (gnus-summary-articles-in-thread)))
11388     (save-excursion
11389       ;; Expand the thread.
11390       (gnus-summary-show-thread)
11391       ;; Mark all the articles.
11392       (while articles
11393         (gnus-summary-goto-subject (car articles))
11394         (cond ((null unmark)
11395                (gnus-summary-mark-article-as-read gnus-killed-mark))
11396               ((> unmark 0)
11397                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11398               (t
11399                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11400         (setq articles (cdr articles))))
11401     ;; Hide killed subtrees.
11402     (and (null unmark)
11403          gnus-thread-hide-killed
11404          (gnus-summary-hide-thread))
11405     ;; If marked as read, go to next unread subject.
11406     (when (null unmark)
11407       ;; Go to next unread subject.
11408       (gnus-summary-next-subject 1 t)))
11409   (gnus-set-mode-line 'summary))
11410
11411 ;; Summary sorting commands
11412
11413 (defun gnus-summary-sort-by-number (&optional reverse)
11414   "Sort the summary buffer by article number.
11415 Argument REVERSE means reverse order."
11416   (interactive "P")
11417   (gnus-summary-sort 'number reverse))
11418
11419 (defun gnus-summary-sort-by-random (&optional reverse)
11420   "Randomize the order in the summary buffer.
11421 Argument REVERSE means to randomize in reverse order."
11422   (interactive "P")
11423   (gnus-summary-sort 'random reverse))
11424
11425 (defun gnus-summary-sort-by-author (&optional reverse)
11426   "Sort the summary buffer by author name alphabetically.
11427 If `case-fold-search' is non-nil, case of letters is ignored.
11428 Argument REVERSE means reverse order."
11429   (interactive "P")
11430   (gnus-summary-sort 'author reverse))
11431
11432 (defun gnus-summary-sort-by-recipient (&optional reverse)
11433   "Sort the summary buffer by recipient name alphabetically.
11434 If `case-fold-search' is non-nil, case of letters is ignored.
11435 Argument REVERSE means reverse order."
11436   (interactive "P")
11437   (gnus-summary-sort 'recipient reverse))
11438
11439 (defun gnus-summary-sort-by-subject (&optional reverse)
11440   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11441 If `case-fold-search' is non-nil, case of letters is ignored.
11442 Argument REVERSE means reverse order."
11443   (interactive "P")
11444   (gnus-summary-sort 'subject reverse))
11445
11446 (defun gnus-summary-sort-by-date (&optional reverse)
11447   "Sort the summary buffer by date.
11448 Argument REVERSE means reverse order."
11449   (interactive "P")
11450   (gnus-summary-sort 'date reverse))
11451
11452 (defun gnus-summary-sort-by-score (&optional reverse)
11453   "Sort the summary buffer by score.
11454 Argument REVERSE means reverse order."
11455   (interactive "P")
11456   (gnus-summary-sort 'score reverse))
11457
11458 (defun gnus-summary-sort-by-lines (&optional reverse)
11459   "Sort the summary buffer by the number of lines.
11460 Argument REVERSE means reverse order."
11461   (interactive "P")
11462   (gnus-summary-sort 'lines reverse))
11463
11464 (defun gnus-summary-sort-by-chars (&optional reverse)
11465   "Sort the summary buffer by article length.
11466 Argument REVERSE means reverse order."
11467   (interactive "P")
11468   (gnus-summary-sort 'chars reverse))
11469
11470 (defun gnus-summary-sort-by-original (&optional reverse)
11471   "Sort the summary buffer using the default sorting method.
11472 Argument REVERSE means reverse order."
11473   (interactive "P")
11474   (let* ((buffer-read-only)
11475          (gnus-summary-prepare-hook nil))
11476     ;; We do the sorting by regenerating the threads.
11477     (gnus-summary-prepare)
11478     ;; Hide subthreads if needed.
11479     (gnus-summary-maybe-hide-threads)))
11480
11481 (defun gnus-summary-sort (predicate reverse)
11482   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11483   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11484          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11485          (gnus-thread-sort-functions
11486           (if (not reverse)
11487               thread
11488             `(lambda (t1 t2)
11489                (,thread t2 t1))))
11490          (gnus-sort-gathered-threads-function
11491           gnus-thread-sort-functions)
11492          (gnus-article-sort-functions
11493           (if (not reverse)
11494               article
11495             `(lambda (t1 t2)
11496                (,article t2 t1))))
11497          (buffer-read-only)
11498          (gnus-summary-prepare-hook nil))
11499     ;; We do the sorting by regenerating the threads.
11500     (gnus-summary-prepare)
11501     ;; Hide subthreads if needed.
11502     (gnus-summary-maybe-hide-threads)))
11503
11504 ;; Summary saving commands.
11505
11506 (defun gnus-summary-save-article (&optional n not-saved)
11507   "Save the current article using the default saver function.
11508 If N is a positive number, save the N next articles.
11509 If N is a negative number, save the N previous articles.
11510 If N is nil and any articles have been marked with the process mark,
11511 save those articles instead.
11512 The variable `gnus-default-article-saver' specifies the saver function.
11513
11514 If the optional second argument NOT-SAVED is non-nil, articles saved
11515 will not be marked as saved."
11516   (interactive "P")
11517   (require 'gnus-art)
11518   (let* ((articles (gnus-summary-work-articles n))
11519          (save-buffer (save-excursion
11520                         (nnheader-set-temp-buffer " *Gnus Save*")))
11521          (num (length articles))
11522          ;; Whether to save decoded articles or raw articles.
11523          (decode (when gnus-article-save-coding-system
11524                    (get gnus-default-article-saver :decode)))
11525          ;; When saving many articles in a single file, use the other
11526          ;; function to save articles other than the first one.
11527          (saver2 (get gnus-default-article-saver :function))
11528          (gnus-prompt-before-saving (if saver2
11529                                         t
11530                                       gnus-prompt-before-saving))
11531          (gnus-default-article-saver gnus-default-article-saver)
11532          header file)
11533     (dolist (article articles)
11534       (setq header (gnus-summary-article-header article))
11535       (if (not (vectorp header))
11536           ;; This is a pseudo-article.
11537           (if (assq 'name header)
11538               (gnus-copy-file (cdr (assq 'name header)))
11539             (gnus-message 1 "Article %d is unsaveable" article))
11540         ;; This is a real article.
11541         (save-window-excursion
11542           (let ((gnus-display-mime-function (when decode
11543                                               gnus-display-mime-function))
11544                 (gnus-article-prepare-hook (when decode
11545                                              gnus-article-prepare-hook)))
11546             (gnus-summary-select-article t nil nil article)
11547             (gnus-summary-goto-subject article)))
11548         (save-excursion
11549           (set-buffer save-buffer)
11550           (erase-buffer)
11551           (insert-buffer-substring (if decode
11552                                        gnus-article-buffer
11553                                      gnus-original-article-buffer)))
11554         (setq file (gnus-article-save save-buffer file num))
11555         (gnus-summary-remove-process-mark article)
11556         (unless not-saved
11557           (gnus-summary-set-saved-mark article)))
11558       (when saver2
11559         (setq gnus-default-article-saver saver2
11560               saver2 nil)))
11561     (gnus-kill-buffer save-buffer)
11562     (gnus-summary-position-point)
11563     (gnus-set-mode-line 'summary)
11564     n))
11565
11566 (defun gnus-summary-pipe-output (&optional arg headers)
11567   "Pipe the current article to a subprocess.
11568 If N is a positive number, pipe the N next articles.
11569 If N is a negative number, pipe the N previous articles.
11570 If N is nil and any articles have been marked with the process mark,
11571 pipe those articles instead.
11572 If HEADERS (the symbolic prefix), include the headers, too."
11573   (interactive (gnus-interactive "P\ny"))
11574   (require 'gnus-art)
11575   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11576         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11577     (gnus-summary-save-article arg t))
11578   (let ((buffer (get-buffer "*Shell Command Output*")))
11579     (when (and buffer
11580                (not (zerop (buffer-size buffer))))
11581       (gnus-configure-windows 'pipe))))
11582
11583 (defun gnus-summary-save-article-mail (&optional arg)
11584   "Append the current article to a Unix mail box file.
11585 If N is a positive number, save the N next articles.
11586 If N is a negative number, save the N previous articles.
11587 If N is nil and any articles have been marked with the process mark,
11588 save those articles instead."
11589   (interactive "P")
11590   (require 'gnus-art)
11591   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11592     (gnus-summary-save-article arg)))
11593
11594 (defun gnus-summary-save-article-rmail (&optional arg)
11595   "Append the current article to an rmail file.
11596 If N is a positive number, save the N next articles.
11597 If N is a negative number, save the N previous articles.
11598 If N is nil and any articles have been marked with the process mark,
11599 save those articles instead."
11600   (interactive "P")
11601   (require 'gnus-art)
11602   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11603     (gnus-summary-save-article arg)))
11604
11605 (defun gnus-summary-save-article-file (&optional arg)
11606   "Append the current article to a file.
11607 If N is a positive number, save the N next articles.
11608 If N is a negative number, save the N previous articles.
11609 If N is nil and any articles have been marked with the process mark,
11610 save those articles instead."
11611   (interactive "P")
11612   (require 'gnus-art)
11613   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11614     (gnus-summary-save-article arg)))
11615
11616 (defun gnus-summary-write-article-file (&optional arg)
11617   "Write the current article to a file, deleting the previous file.
11618 If N is a positive number, save the N next articles.
11619 If N is a negative number, save the N previous articles.
11620 If N is nil and any articles have been marked with the process mark,
11621 save those articles instead."
11622   (interactive "P")
11623   (require 'gnus-art)
11624   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11625     (gnus-summary-save-article arg)))
11626
11627 (defun gnus-summary-save-article-body-file (&optional arg)
11628   "Append the current article body to a file.
11629 If N is a positive number, save the N next articles.
11630 If N is a negative number, save the N previous articles.
11631 If N is nil and any articles have been marked with the process mark,
11632 save those articles instead."
11633   (interactive "P")
11634   (require 'gnus-art)
11635   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11636     (gnus-summary-save-article arg)))
11637
11638 (defun gnus-summary-write-article-body-file (&optional arg)
11639   "Write the current article body to a file, deleting the previous file.
11640 If N is a positive number, save the N next articles.
11641 If N is a negative number, save the N previous articles.
11642 If N is nil and any articles have been marked with the process mark,
11643 save those articles instead."
11644   (interactive "P")
11645   (require 'gnus-art)
11646   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11647     (gnus-summary-save-article arg)))
11648
11649 (defun gnus-summary-muttprint (&optional arg)
11650   "Print the current article using Muttprint.
11651 If N is a positive number, save the N next articles.
11652 If N is a negative number, save the N previous articles.
11653 If N is nil and any articles have been marked with the process mark,
11654 save those articles instead."
11655   (interactive "P")
11656   (require 'gnus-art)
11657   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11658     (gnus-summary-save-article arg t)))
11659
11660 (defun gnus-summary-pipe-message (program)
11661   "Pipe the current article through PROGRAM."
11662   (interactive "sProgram: ")
11663   (gnus-summary-select-article)
11664   (let ((mail-header-separator ""))
11665     (gnus-eval-in-buffer-window gnus-article-buffer
11666       (save-restriction
11667         (widen)
11668         (let ((start (window-start))
11669               buffer-read-only)
11670           (message-pipe-buffer-body program)
11671           (set-window-start (get-buffer-window (current-buffer)) start))))))
11672
11673 (defun gnus-get-split-value (methods)
11674   "Return a value based on the split METHODS."
11675   (let (split-name method result match)
11676     (when methods
11677       (save-excursion
11678         (set-buffer gnus-original-article-buffer)
11679         (save-restriction
11680           (nnheader-narrow-to-headers)
11681           (while (and methods (not split-name))
11682             (goto-char (point-min))
11683             (setq method (pop methods))
11684             (setq match (car method))
11685             (when (cond
11686                    ((stringp match)
11687                     ;; Regular expression.
11688                     (ignore-errors
11689                       (re-search-forward match nil t)))
11690                    ((functionp match)
11691                     ;; Function.
11692                     (save-restriction
11693                       (widen)
11694                       (setq result (funcall match gnus-newsgroup-name))))
11695                    ((consp match)
11696                     ;; Form.
11697                     (save-restriction
11698                       (widen)
11699                       (setq result (eval match)))))
11700               (setq split-name (cdr method))
11701               (cond ((stringp result)
11702                      (push (expand-file-name
11703                             result gnus-article-save-directory)
11704                            split-name))
11705                     ((consp result)
11706                      (setq split-name (append result split-name)))))))))
11707     (nreverse split-name)))
11708
11709 (defun gnus-valid-move-group-p (group)
11710   (and (boundp group)
11711        (symbol-name group)
11712        (symbol-value group)
11713        (gnus-get-function (gnus-find-method-for-group
11714                            (symbol-name group)) 'request-accept-article t)))
11715
11716 (defun gnus-read-move-group-name (prompt default articles prefix)
11717   "Read a group name."
11718   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11719          (minibuffer-confirm-incomplete nil) ; XEmacs
11720          (prom
11721           (format "%s %s to"
11722                   prompt
11723                   (if (> (length articles) 1)
11724                       (format "these %d articles" (length articles))
11725                     "this article")))
11726          (to-newsgroup
11727           (let (active group)
11728             (when (or (null split-name) (= 1 (length split-name)))
11729               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11730               (mapatoms (lambda (symbol)
11731                           (setq group (symbol-name symbol))
11732                           (when (string-match "[^\000-\177]" group)
11733                             (setq group (gnus-group-decoded-name group)))
11734                           (set (intern group active) group))
11735                         gnus-active-hashtb))
11736             (cond
11737              ((null split-name)
11738               (gnus-completing-read-with-default
11739                default prom active 'gnus-valid-move-group-p nil prefix
11740                'gnus-group-history))
11741              ((= 1 (length split-name))
11742               (gnus-completing-read-with-default
11743                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11744                'gnus-group-history))
11745              (t
11746               (gnus-completing-read-with-default
11747                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11748                'gnus-group-history)))))
11749          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11750          encoded)
11751     (when to-newsgroup
11752       (if (or (string= to-newsgroup "")
11753               (string= to-newsgroup prefix))
11754           (setq to-newsgroup default))
11755       (unless to-newsgroup
11756         (error "No group name entered"))
11757       (setq encoded (mm-encode-coding-string
11758                      to-newsgroup
11759                      (gnus-group-name-charset to-method to-newsgroup)))
11760       (or (gnus-active encoded)
11761           (gnus-activate-group encoded nil nil to-method)
11762           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11763                                      to-newsgroup))
11764               (or (and (gnus-request-create-group encoded to-method)
11765                        (gnus-activate-group encoded nil nil to-method)
11766                        (gnus-subscribe-group encoded))
11767                   (error "Couldn't create group %s" to-newsgroup)))
11768           (error "No such group: %s" to-newsgroup))
11769       encoded)))
11770
11771 (defvar gnus-summary-save-parts-counter)
11772
11773 (defun gnus-summary-save-parts (type dir n &optional reverse)
11774   "Save parts matching TYPE to DIR.
11775 If REVERSE, save parts that do not match TYPE."
11776   (interactive
11777    (list (read-string "Save parts of type: "
11778                       (or (car gnus-summary-save-parts-type-history)
11779                           gnus-summary-save-parts-default-mime)
11780                       'gnus-summary-save-parts-type-history)
11781          (setq gnus-summary-save-parts-last-directory
11782                (read-file-name "Save to directory: "
11783                                gnus-summary-save-parts-last-directory
11784                                nil t))
11785          current-prefix-arg))
11786   (gnus-summary-iterate n
11787     (let ((gnus-display-mime-function nil)
11788           (gnus-inhibit-treatment t))
11789       (gnus-summary-select-article))
11790     (save-excursion
11791       (set-buffer gnus-article-buffer)
11792       (let ((handles (or gnus-article-mime-handles
11793                          (mm-dissect-buffer nil gnus-article-loose-mime)
11794                          (and gnus-article-emulate-mime
11795                               (mm-uu-dissect))))
11796             (gnus-summary-save-parts-counter 1))
11797         (when handles
11798           (gnus-summary-save-parts-1 type dir handles reverse)
11799           (unless gnus-article-mime-handles ;; Don't destroy this case.
11800             (mm-destroy-parts handles)))))))
11801
11802 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11803   (if (stringp (car handle))
11804       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11805               (cdr handle))
11806     (when (if reverse
11807               (not (string-match type (mm-handle-media-type handle)))
11808             (string-match type (mm-handle-media-type handle)))
11809       (let ((file (expand-file-name
11810                    (gnus-map-function
11811                     mm-file-name-rewrite-functions
11812                     (file-name-nondirectory
11813                      (or
11814                       (mail-content-type-get
11815                        (mm-handle-disposition handle) 'filename)
11816                       (mail-content-type-get
11817                        (mm-handle-type handle) 'name)
11818                       (format "%s.%d.%d" gnus-newsgroup-name
11819                               (cdr gnus-article-current)
11820                               gnus-summary-save-parts-counter))))
11821                    dir)))
11822         (incf gnus-summary-save-parts-counter)
11823         (unless (file-exists-p file)
11824           (mm-save-part-to-file handle file))))))
11825
11826 ;; Summary extract commands
11827
11828 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11829   (let ((buffer-read-only nil)
11830         (article (gnus-summary-article-number))
11831         after-article b e)
11832     (unless (gnus-summary-goto-subject article)
11833       (error "No such article: %d" article))
11834     (gnus-summary-position-point)
11835     ;; If all commands are to be bunched up on one line, we collect
11836     ;; them here.
11837     (unless gnus-view-pseudos-separately
11838       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11839             files action)
11840         (while ps
11841           (setq action (cdr (assq 'action (car ps))))
11842           (setq files (list (cdr (assq 'name (car ps)))))
11843           (while (and ps (cdr ps)
11844                       (string= (or action "1")
11845                                (or (cdr (assq 'action (cadr ps))) "2")))
11846             (push (cdr (assq 'name (cadr ps))) files)
11847             (setcdr ps (cddr ps)))
11848           (when files
11849             (when (not (string-match "%s" action))
11850               (push " " files))
11851             (push " " files)
11852             (when (assq 'execute (car ps))
11853               (setcdr (assq 'execute (car ps))
11854                       (funcall (if (string-match "%s" action)
11855                                    'format 'concat)
11856                                action
11857                                (mapconcat
11858                                 (lambda (f)
11859                                   (if (equal f " ")
11860                                       f
11861                                     (shell-quote-argument f)))
11862                                 files " ")))))
11863           (setq ps (cdr ps)))))
11864     (if (and gnus-view-pseudos (not not-view))
11865         (while pslist
11866           (when (assq 'execute (car pslist))
11867             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11868                                   (eq gnus-view-pseudos 'not-confirm)))
11869           (setq pslist (cdr pslist)))
11870       (save-excursion
11871         (while pslist
11872           (setq after-article (or (cdr (assq 'article (car pslist)))
11873                                   (gnus-summary-article-number)))
11874           (gnus-summary-goto-subject after-article)
11875           (forward-line 1)
11876           (setq b (point))
11877           (insert "    " (file-name-nondirectory
11878                           (cdr (assq 'name (car pslist))))
11879                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11880           (setq e (point))
11881           (forward-line -1)             ; back to `b'
11882           (gnus-add-text-properties
11883            b (1- e) (list 'gnus-number gnus-reffed-article-number
11884                           gnus-mouse-face-prop gnus-mouse-face))
11885           (gnus-data-enter
11886            after-article gnus-reffed-article-number
11887            gnus-unread-mark b (car pslist) 0 (- e b))
11888           (setq gnus-newsgroup-unreads
11889                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11890                                          gnus-reffed-article-number))
11891           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11892           (setq pslist (cdr pslist)))))))
11893
11894 (defun gnus-pseudos< (p1 p2)
11895   (let ((c1 (cdr (assq 'action p1)))
11896         (c2 (cdr (assq 'action p2))))
11897     (and c1 c2 (string< c1 c2))))
11898
11899 (defun gnus-request-pseudo-article (props)
11900   (cond ((assq 'execute props)
11901          (gnus-execute-command (cdr (assq 'execute props)))))
11902   (let ((gnus-current-article (gnus-summary-article-number)))
11903     (gnus-run-hooks 'gnus-mark-article-hook)))
11904
11905 (defun gnus-execute-command (command &optional automatic)
11906   (save-excursion
11907     (gnus-article-setup-buffer)
11908     (set-buffer gnus-article-buffer)
11909     (setq buffer-read-only nil)
11910     (let ((command (if automatic command
11911                      (read-string "Command: " (cons command 0)))))
11912       (erase-buffer)
11913       (insert "$ " command "\n\n")
11914       (if gnus-view-pseudo-asynchronously
11915           (start-process "gnus-execute" (current-buffer) shell-file-name
11916                          shell-command-switch command)
11917         (call-process shell-file-name nil t nil
11918                       shell-command-switch command)))))
11919
11920 ;; Summary kill commands.
11921
11922 (defun gnus-summary-edit-global-kill (article)
11923   "Edit the \"global\" kill file."
11924   (interactive (list (gnus-summary-article-number)))
11925   (gnus-group-edit-global-kill article))
11926
11927 (defun gnus-summary-edit-local-kill ()
11928   "Edit a local kill file applied to the current newsgroup."
11929   (interactive)
11930   (setq gnus-current-headers (gnus-summary-article-header))
11931   (gnus-group-edit-local-kill
11932    (gnus-summary-article-number) gnus-newsgroup-name))
11933
11934 ;;; Header reading.
11935
11936 (defun gnus-read-header (id &optional header)
11937   "Read the headers of article ID and enter them into the Gnus system."
11938   (let ((group gnus-newsgroup-name)
11939         (gnus-override-method
11940          (or
11941           gnus-override-method
11942           (and (gnus-news-group-p gnus-newsgroup-name)
11943                (car (gnus-refer-article-methods)))))
11944         where)
11945     ;; First we check to see whether the header in question is already
11946     ;; fetched.
11947     (if (stringp id)
11948         ;; This is a Message-ID.
11949         (setq header (or header (gnus-id-to-header id)))
11950       ;; This is an article number.
11951       (setq header (or header (gnus-summary-article-header id))))
11952     (if (and header
11953              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11954         ;; We have found the header.
11955         header
11956       ;; We have to really fetch the header to this article.
11957       (save-excursion
11958         (set-buffer nntp-server-buffer)
11959         (when (setq where (gnus-request-head id group))
11960           (nnheader-fold-continuation-lines)
11961           (goto-char (point-max))
11962           (insert ".\n")
11963           (goto-char (point-min))
11964           (insert "211 ")
11965           (princ (cond
11966                   ((numberp id) id)
11967                   ((cdr where) (cdr where))
11968                   (header (mail-header-number header))
11969                   (t gnus-reffed-article-number))
11970                  (current-buffer))
11971           (insert " Article retrieved.\n"))
11972         (if (or (not where)
11973                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11974             ()                          ; Malformed head.
11975           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11976             (when (and (stringp id)
11977                        (or
11978                         (not (string= (gnus-group-real-name group)
11979                                       (car where)))
11980                         (not (gnus-server-equal gnus-override-method
11981                                                 (gnus-group-method group)))))
11982               ;; If we fetched by Message-ID and the article came from
11983               ;; a different group (or server), we fudge some bogus
11984               ;; article numbers for this article.
11985               (mail-header-set-number header gnus-reffed-article-number))
11986             (save-excursion
11987               (set-buffer gnus-summary-buffer)
11988               (decf gnus-reffed-article-number)
11989               (gnus-remove-header (mail-header-number header))
11990               (push header gnus-newsgroup-headers)
11991               (setq gnus-current-headers header)
11992               (push (mail-header-number header) gnus-newsgroup-limit)))
11993           header)))))
11994
11995 (defun gnus-remove-header (number)
11996   "Remove header NUMBER from `gnus-newsgroup-headers'."
11997   (if (and gnus-newsgroup-headers
11998            (= number (mail-header-number (car gnus-newsgroup-headers))))
11999       (pop gnus-newsgroup-headers)
12000     (let ((headers gnus-newsgroup-headers))
12001       (while (and (cdr headers)
12002                   (not (= number (mail-header-number (cadr headers)))))
12003         (pop headers))
12004       (when (cdr headers)
12005         (setcdr headers (cddr headers))))))
12006
12007 ;;;
12008 ;;; summary highlights
12009 ;;;
12010
12011 (defun gnus-highlight-selected-summary ()
12012   "Highlight selected article in summary buffer."
12013   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12014   (when gnus-summary-selected-face
12015     (save-excursion
12016       (let* ((beg (point-at-bol))
12017              (end (point-at-eol))
12018              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12019              (from (if (get-text-property beg gnus-mouse-face-prop)
12020                        beg
12021                      (or (next-single-property-change
12022                           beg gnus-mouse-face-prop nil end)
12023                          beg)))
12024              (to
12025               (if (= from end)
12026                   (- from 2)
12027                 (or (next-single-property-change
12028                      from gnus-mouse-face-prop nil end)
12029                     end))))
12030         ;; If no mouse-face prop on line we will have to = from = end,
12031         ;; so we highlight the entire line instead.
12032         (when (= (+ to 2) from)
12033           (setq from beg)
12034           (setq to end))
12035         (if gnus-newsgroup-selected-overlay
12036             ;; Move old overlay.
12037             (gnus-move-overlay
12038              gnus-newsgroup-selected-overlay from to (current-buffer))
12039           ;; Create new overlay.
12040           (gnus-overlay-put
12041            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12042            'face gnus-summary-selected-face))))))
12043
12044 (defvar gnus-summary-highlight-line-cached nil)
12045 (defvar gnus-summary-highlight-line-trigger nil)
12046
12047 (defun gnus-summary-highlight-line-0 ()
12048   (if (and (eq gnus-summary-highlight-line-trigger
12049                gnus-summary-highlight)
12050            gnus-summary-highlight-line-cached)
12051       gnus-summary-highlight-line-cached
12052     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12053           gnus-summary-highlight-line-cached
12054           (let* ((cond (list 'cond))
12055                  (c cond)
12056                  (list gnus-summary-highlight))
12057             (while list
12058               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12059                               nil))
12060               (setq c (cdr c)
12061                     list (cdr list)))
12062             (gnus-byte-compile (list 'lambda nil cond))))))
12063
12064 (defun gnus-summary-highlight-line ()
12065   "Highlight current line according to `gnus-summary-highlight'."
12066   (let* ((beg (point-at-bol))
12067          (article (or (gnus-summary-article-number) gnus-current-article))
12068          (score (or (cdr (assq article
12069                                gnus-newsgroup-scored))
12070                     gnus-summary-default-score 0))
12071          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12072          (inhibit-read-only t)
12073          (default gnus-summary-default-score)
12074          (default-high gnus-summary-default-high-score)
12075          (default-low gnus-summary-default-low-score)
12076          (uncached (and gnus-summary-use-undownloaded-faces
12077                         (memq article gnus-newsgroup-undownloaded)
12078                         (not (memq article gnus-newsgroup-cached)))))
12079     (let ((face (funcall (gnus-summary-highlight-line-0))))
12080       (unless (eq face (get-text-property beg 'face))
12081         (gnus-put-text-property-excluding-characters-with-faces
12082          beg (point-at-eol) 'face
12083          (setq face (if (boundp face) (symbol-value face) face)))
12084         (when gnus-summary-highlight-line-function
12085           (funcall gnus-summary-highlight-line-function article face))))))
12086
12087 (defun gnus-update-read-articles (group unread &optional compute)
12088   "Update the list of read articles in GROUP.
12089 UNREAD is a sorted list."
12090   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12091         (info (gnus-get-info group))
12092         (prev 1)
12093         read)
12094     (if (or (not info) (not active))
12095         ;; There is no info on this group if it was, in fact,
12096         ;; killed.  Gnus stores no information on killed groups, so
12097         ;; there's nothing to be done.
12098         ;; One could store the information somewhere temporarily,
12099         ;; perhaps...  Hmmm...
12100         ()
12101       ;; Remove any negative articles numbers.
12102       (while (and unread (< (car unread) 0))
12103         (setq unread (cdr unread)))
12104       ;; Remove any expired article numbers
12105       (while (and unread (< (car unread) (car active)))
12106         (setq unread (cdr unread)))
12107       ;; Compute the ranges of read articles by looking at the list of
12108       ;; unread articles.
12109       (while unread
12110         (when (/= (car unread) prev)
12111           (push (if (= prev (1- (car unread))) prev
12112                   (cons prev (1- (car unread))))
12113                 read))
12114         (setq prev (1+ (car unread)))
12115         (setq unread (cdr unread)))
12116       (when (<= prev (cdr active))
12117         (push (cons prev (cdr active)) read))
12118       (setq read (if (> (length read) 1) (nreverse read) read))
12119       (if compute
12120           read
12121         (save-excursion
12122           (let (setmarkundo)
12123             ;; Propagate the read marks to the backend.
12124             (when (gnus-check-backend-function 'request-set-mark group)
12125               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12126                     (add (gnus-remove-from-range read (gnus-info-read info))))
12127                 (when (or add del)
12128                   (unless (gnus-check-group group)
12129                     (error "Can't open server for %s" group))
12130                   (gnus-request-set-mark
12131                    group (delq nil (list (if add (list add 'add '(read)))
12132                                          (if del (list del 'del '(read))))))
12133                   (setq setmarkundo
12134                         `(gnus-request-set-mark
12135                           ,group
12136                           ',(delq nil (list
12137                                        (if del (list del 'add '(read)))
12138                                        (if add (list add 'del '(read))))))))))
12139             (set-buffer gnus-group-buffer)
12140             (gnus-undo-register
12141               `(progn
12142                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12143                  (gnus-info-set-read ',info ',(gnus-info-read info))
12144                  (gnus-get-unread-articles-in-group ',info
12145                                                     (gnus-active ,group))
12146                  (gnus-group-update-group ,group t)
12147                  ,setmarkundo))))
12148         ;; Enter this list into the group info.
12149         (gnus-info-set-read info read)
12150         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12151         (gnus-get-unread-articles-in-group info (gnus-active group))
12152         t))))
12153
12154 (defun gnus-offer-save-summaries ()
12155   "Offer to save all active summary buffers."
12156   (let (buffers)
12157     ;; Go through all buffers and find all summaries.
12158     (dolist (buffer (buffer-list))
12159       (when (and (setq buffer (buffer-name buffer))
12160                  (string-match "Summary" buffer)
12161                  (with-current-buffer buffer
12162                    ;; We check that this is, indeed, a summary buffer.
12163                    (and (eq major-mode 'gnus-summary-mode)
12164                         ;; Also make sure this isn't bogus.
12165                         gnus-newsgroup-prepared
12166                         ;; Also make sure that this isn't a
12167                         ;; dead summary buffer.
12168                         (not gnus-dead-summary-mode))))
12169         (push buffer buffers)))
12170     ;; Go through all these summary buffers and offer to save them.
12171     (when buffers
12172       (save-excursion
12173         (map-y-or-n-p
12174          "Update summary buffer %s? "
12175          (lambda (buf)
12176            (switch-to-buffer buf)
12177            (gnus-summary-exit))
12178          buffers)))))
12179
12180 (defun gnus-summary-setup-default-charset ()
12181   "Setup newsgroup default charset."
12182   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12183       (setq gnus-newsgroup-charset nil)
12184     (let* ((ignored-charsets
12185             (or gnus-newsgroup-ephemeral-ignored-charsets
12186                 (append
12187                  (and gnus-newsgroup-name
12188                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12189                  gnus-newsgroup-ignored-charsets))))
12190       (setq gnus-newsgroup-charset
12191             (or gnus-newsgroup-ephemeral-charset
12192                 (and gnus-newsgroup-name
12193                      (gnus-parameter-charset gnus-newsgroup-name))
12194                 gnus-default-charset))
12195       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12196            ignored-charsets))))
12197
12198 ;;;
12199 ;;; Mime Commands
12200 ;;;
12201
12202 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12203   "Display the current article buffer fully MIME-buttonized.
12204 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12205 treated as multipart/mixed."
12206   (interactive "P")
12207   (require 'gnus-art)
12208   (let ((gnus-unbuttonized-mime-types nil)
12209         (gnus-mime-display-multipart-as-mixed show-all-parts))
12210     (gnus-summary-show-article)))
12211
12212 (defun gnus-summary-repair-multipart (article)
12213   "Add a Content-Type header to a multipart article without one."
12214   (interactive (list (gnus-summary-article-number)))
12215   (gnus-with-article article
12216     (message-narrow-to-head)
12217     (message-remove-header "Mime-Version")
12218     (goto-char (point-max))
12219     (insert "Mime-Version: 1.0\n")
12220     (widen)
12221     (when (search-forward "\n--" nil t)
12222       (let ((separator (buffer-substring (point) (point-at-eol))))
12223         (message-narrow-to-head)
12224         (message-remove-header "Content-Type")
12225         (goto-char (point-max))
12226         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12227                         separator))
12228         (widen))))
12229   (let (gnus-mark-article-hook)
12230     (gnus-summary-select-article t t nil article)))
12231
12232 (defun gnus-summary-toggle-display-buttonized ()
12233   "Toggle the buttonizing of the article buffer."
12234   (interactive)
12235   (require 'gnus-art)
12236   (if (setq gnus-inhibit-mime-unbuttonizing
12237             (not gnus-inhibit-mime-unbuttonizing))
12238       (let ((gnus-unbuttonized-mime-types nil))
12239         (gnus-summary-show-article))
12240     (gnus-summary-show-article)))
12241
12242 ;;;
12243 ;;; Generic summary marking commands
12244 ;;;
12245
12246 (defvar gnus-summary-marking-alist
12247   '((read gnus-del-mark "d")
12248     (unread gnus-unread-mark "u")
12249     (ticked gnus-ticked-mark "!")
12250     (dormant gnus-dormant-mark "?")
12251     (expirable gnus-expirable-mark "e"))
12252   "An alist of names/marks/keystrokes.")
12253
12254 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12255 (defvar gnus-summary-mark-map)
12256
12257 (defun gnus-summary-make-all-marking-commands ()
12258   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12259   (dolist (elem gnus-summary-marking-alist)
12260     (apply 'gnus-summary-make-marking-command elem)))
12261
12262 (defun gnus-summary-make-marking-command (name mark keystroke)
12263   (let ((map (make-sparse-keymap)))
12264     (define-key gnus-summary-generic-mark-map keystroke map)
12265     (dolist (lway `((next "next" next nil "n")
12266                     (next-unread "next unread" next t "N")
12267                     (prev "previous" prev nil "p")
12268                     (prev-unread "previous unread" prev t "P")
12269                     (nomove "" nil nil ,keystroke)))
12270       (let ((func (gnus-summary-make-marking-command-1
12271                    mark (car lway) lway name)))
12272         (setq func (eval func))
12273         (define-key map (nth 4 lway) func)))))
12274
12275 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12276   `(defun ,(intern
12277             (format "gnus-summary-put-mark-as-%s%s"
12278                     name (if (eq way 'nomove)
12279                              ""
12280                            (concat "-" (symbol-name way)))))
12281      (n)
12282      ,(format
12283        "Mark the current article as %s%s.
12284 If N, the prefix, then repeat N times.
12285 If N is negative, move in reverse order.
12286 The difference between N and the actual number of articles marked is
12287 returned."
12288        name (cadr lway))
12289      (interactive "p")
12290      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12291
12292 (defun gnus-summary-generic-mark (n mark move unread)
12293   "Mark N articles with MARK."
12294   (unless (eq major-mode 'gnus-summary-mode)
12295     (error "This command can only be used in the summary buffer"))
12296   (gnus-summary-show-thread)
12297   (let ((nummove
12298          (cond
12299           ((eq move 'next) 1)
12300           ((eq move 'prev) -1)
12301           (t 0))))
12302     (if (zerop nummove)
12303         (setq n 1)
12304       (when (< n 0)
12305         (setq n (abs n)
12306               nummove (* -1 nummove))))
12307     (while (and (> n 0)
12308                 (gnus-summary-mark-article nil mark)
12309                 (zerop (gnus-summary-next-subject nummove unread t)))
12310       (setq n (1- n)))
12311     (when (/= 0 n)
12312       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12313     (gnus-summary-recenter)
12314     (gnus-summary-position-point)
12315     (gnus-set-mode-line 'summary)
12316     n))
12317
12318 (defun gnus-summary-insert-articles (articles)
12319   (when (setq articles
12320               (gnus-sorted-difference articles
12321                                       (mapcar (lambda (h)
12322                                                 (mail-header-number h))
12323                                               gnus-newsgroup-headers)))
12324     (setq gnus-newsgroup-headers
12325           (gnus-merge 'list
12326                       gnus-newsgroup-headers
12327                       (gnus-fetch-headers articles)
12328                       'gnus-article-sort-by-number))
12329     ;; Suppress duplicates?
12330     (when gnus-suppress-duplicates
12331       (gnus-dup-suppress-articles))
12332
12333     (if (and gnus-fetch-old-headers
12334              (eq gnus-headers-retrieved-by 'nov))
12335         ;; We might want to build some more threads first.
12336         (if (eq gnus-fetch-old-headers 'invisible)
12337             (gnus-build-all-threads)
12338           (gnus-build-old-threads))
12339       ;; Mark the inserted articles that are unread as unread.
12340       (setq gnus-newsgroup-unreads
12341             (gnus-sorted-nunion
12342              gnus-newsgroup-unreads
12343              (gnus-sorted-nintersection
12344               (gnus-list-of-unread-articles gnus-newsgroup-name)
12345               articles)))
12346       ;; Mark the inserted articles as selected so that the information
12347       ;; of the marks having been changed by a user may be updated when
12348       ;; exiting this group.  See `gnus-summary-update-info'.
12349       (dolist (art articles)
12350         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12351     ;; Let the Gnus agent mark articles as read.
12352     (when gnus-agent
12353       (gnus-agent-get-undownloaded-list))
12354     ;; Remove list identifiers from subject
12355     (when gnus-list-identifiers
12356       (gnus-summary-remove-list-identifiers))
12357     ;; First and last article in this newsgroup.
12358     (when gnus-newsgroup-headers
12359       (setq gnus-newsgroup-begin
12360             (mail-header-number (car gnus-newsgroup-headers))
12361             gnus-newsgroup-end
12362             (mail-header-number
12363              (gnus-last-element gnus-newsgroup-headers))))
12364     (when gnus-use-scoring
12365       (gnus-possibly-score-headers))))
12366
12367 (defun gnus-summary-insert-old-articles (&optional all)
12368   "Insert all old articles in this group.
12369 If ALL is non-nil, already read articles become readable.
12370 If ALL is a number, fetch this number of articles."
12371   (interactive "P")
12372   (prog1
12373       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12374             older len)
12375         (setq older
12376               ;; Some nntp servers lie about their active range.  When
12377               ;; this happens, the active range can be in the millions.
12378               ;; Use a compressed range to avoid creating a huge list.
12379               (gnus-range-difference (list gnus-newsgroup-active) old))
12380         (setq len (gnus-range-length older))
12381         (cond
12382          ((null older) nil)
12383          ((numberp all)
12384           (if (< all len)
12385               (let ((older-range (nreverse older)))
12386                 (setq older nil)
12387
12388                 (while (> all 0)
12389                   (let* ((r (pop older-range))
12390                          (min (if (numberp r) r (car r)))
12391                          (max (if (numberp r) r (cdr r))))
12392                     (while (and (<= min max)
12393                                 (> all 0))
12394                       (push max older)
12395                       (setq all (1- all)
12396                             max (1- max))))))
12397             (setq older (gnus-uncompress-range older))))
12398          (all
12399           (setq older (gnus-uncompress-range older)))
12400          (t
12401           (when (and (numberp gnus-large-newsgroup)
12402                    (> len gnus-large-newsgroup))
12403               (let* ((cursor-in-echo-area nil)
12404                      (initial (gnus-parameter-large-newsgroup-initial
12405                                gnus-newsgroup-name))
12406                      (input
12407                       (read-string
12408                        (format
12409                         "How many articles from %s (%s %d): "
12410                         (gnus-group-decoded-name gnus-newsgroup-name)
12411                         (if initial "max" "default")
12412                         len)
12413                        (if initial
12414                            (cons (number-to-string initial)
12415                                  0)))))
12416                 (unless (string-match "^[ \t]*$" input)
12417                   (setq all (string-to-number input))
12418                   (if (< all len)
12419                       (let ((older-range (nreverse older)))
12420                         (setq older nil)
12421
12422                         (while (> all 0)
12423                           (let* ((r (pop older-range))
12424                                  (min (if (numberp r) r (car r)))
12425                                  (max (if (numberp r) r (cdr r))))
12426                             (while (and (<= min max)
12427                                         (> all 0))
12428                               (push max older)
12429                               (setq all (1- all)
12430                                     max (1- max))))))))))
12431           (setq older (gnus-uncompress-range older))))
12432         (if (not older)
12433             (message "No old news.")
12434           (gnus-summary-insert-articles older)
12435           (gnus-summary-limit (gnus-sorted-nunion old older))))
12436     (gnus-summary-position-point)))
12437
12438 (defun gnus-summary-insert-new-articles ()
12439   "Insert all new articles in this group."
12440   (interactive)
12441   (prog1
12442       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12443             (old-active gnus-newsgroup-active)
12444             (nnmail-fetched-sources (list t))
12445             i new)
12446         (setq gnus-newsgroup-active
12447               (gnus-activate-group gnus-newsgroup-name 'scan))
12448         (setq i (cdr gnus-newsgroup-active))
12449         (while (> i (cdr old-active))
12450           (push i new)
12451           (decf i))
12452         (if (not new)
12453             (message "No gnus is bad news")
12454           (gnus-summary-insert-articles new)
12455           (setq gnus-newsgroup-unreads
12456                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12457           (gnus-summary-limit (gnus-sorted-nunion old new))))
12458     (gnus-summary-position-point)))
12459
12460 (gnus-summary-make-all-marking-commands)
12461
12462 (gnus-ems-redefine)
12463
12464 (provide 'gnus-sum)
12465
12466 (run-hooks 'gnus-sum-load-hook)
12467
12468 ;; Local Variables:
12469 ;; coding: iso-8859-1
12470 ;; End:
12471
12472 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12473 ;;; gnus-sum.el ends here