6b74845c14953c821233fadd6457a8358bfef0a3
[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 (defcustom gnus-newsgroup-maximum-articles nil
1142   "The maximum number of articles a newsgroup.
1143 If this is a number, old articles in a newsgroup exceeding this number
1144 are silently ignored.  If it is nil, no article is ignored.  Note that
1145 setting this variable to a number might prevent you from reading very
1146 old articles."
1147   :group 'gnus-group-select
1148   :version "22.2"
1149   :type '(choice (const :tag "No limit" nil)
1150                  integer))
1151
1152 (gnus-define-group-parameter
1153  ignored-charsets
1154  :type list
1155  :function-document
1156  "Return the ignored charsets of GROUP."
1157  :variable gnus-group-ignored-charsets-alist
1158  :variable-default
1159  '(("alt\\.chinese\\.text" iso-8859-1))
1160  :variable-document
1161  "Alist of regexps (to match group names) and charsets that should be ignored.
1162 When these charsets are used in the \"charset\" parameter, the
1163 default charset will be used instead."
1164  :variable-group gnus-charset
1165  :variable-type '(repeat (cons (regexp :tag "Group")
1166                                (repeat symbol)))
1167  :parameter-type '(choice :tag "Ignored charsets"
1168                           :value nil
1169                           (repeat (symbol)))
1170  :parameter-document       "\
1171 List of charsets that should be ignored.
1172
1173 When these charsets are used in the \"charset\" parameter, the
1174 default charset will be used instead.")
1175
1176 (defcustom gnus-group-highlight-words-alist nil
1177   "Alist of group regexps and highlight regexps.
1178 This variable uses the same syntax as `gnus-emphasis-alist'."
1179   :version "21.1"
1180   :type '(repeat (cons (regexp :tag "Group")
1181                        (repeat (list (regexp :tag "Highlight regexp")
1182                                      (number :tag "Group for entire word" 0)
1183                                      (number :tag "Group for displayed part" 0)
1184                                      (symbol :tag "Face"
1185                                              gnus-emphasis-highlight-words)))))
1186   :group 'gnus-summary-visual)
1187
1188 (defcustom gnus-summary-show-article-charset-alist
1189   nil
1190   "Alist of number and charset.
1191 The article will be shown with the charset corresponding to the
1192 numbered argument.
1193 For example: ((1 . cn-gb-2312) (2 . big5))."
1194   :version "21.1"
1195   :type '(repeat (cons (number :tag "Argument" 1)
1196                        (symbol :tag "Charset")))
1197   :group 'gnus-charset)
1198
1199 (defcustom gnus-preserve-marks t
1200   "Whether marks are preserved when moving, copying and respooling messages."
1201   :version "21.1"
1202   :type 'boolean
1203   :group 'gnus-summary-marks)
1204
1205 (defcustom gnus-alter-articles-to-read-function nil
1206   "Function to be called to alter the list of articles to be selected."
1207   :type '(choice (const nil) function)
1208   :group 'gnus-summary)
1209
1210 (defcustom gnus-orphan-score nil
1211   "*All orphans get this score added.  Set in the score file."
1212   :group 'gnus-score-default
1213   :type '(choice (const nil)
1214                  integer))
1215
1216 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1217   "*A regexp to match MIME parts when saving multiple parts of a
1218 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1219 This regexp will be used by default when prompting the user for which
1220 type of files to save."
1221   :group 'gnus-summary
1222   :type 'regexp)
1223
1224 (defcustom gnus-read-all-available-headers nil
1225   "Whether Gnus should parse all headers made available to it.
1226 This is mostly relevant for slow back ends where the user may
1227 wish to widen the summary buffer to include all headers
1228 that were fetched.  Say, for nnultimate groups."
1229   :version "22.1"
1230   :group 'gnus-summary
1231   :type '(choice boolean regexp))
1232
1233 (defcustom gnus-summary-muttprint-program "muttprint"
1234   "Command (and optional arguments) used to run Muttprint."
1235   :version "22.1"
1236   :group 'gnus-summary
1237   :type 'string)
1238
1239 (defcustom gnus-article-loose-mime t
1240   "If non-nil, don't require MIME-Version header.
1241 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1242 supply the MIME-Version header or deliberately strip it from the mail.
1243 If non-nil (the default), Gnus will treat some articles as MIME
1244 even if the MIME-Version header is missing."
1245   :version "22.1"
1246   :type 'boolean
1247   :group 'gnus-article-mime)
1248
1249 (defcustom gnus-article-emulate-mime t
1250   "If non-nil, use MIME emulation for uuencode and the like.
1251 This means that Gnus will search message bodies for text that look
1252 like uuencoded bits, yEncoded bits, and so on, and present that using
1253 the normal Gnus MIME machinery."
1254   :version "22.1"
1255   :type 'boolean
1256   :group 'gnus-article-mime)
1257
1258 ;;; Internal variables
1259
1260 (defvar gnus-summary-display-cache nil)
1261 (defvar gnus-article-mime-handles nil)
1262 (defvar gnus-article-decoded-p nil)
1263 (defvar gnus-article-charset nil)
1264 (defvar gnus-article-ignored-charsets nil)
1265 (defvar gnus-scores-exclude-files nil)
1266 (defvar gnus-page-broken nil)
1267
1268 (defvar gnus-original-article nil)
1269 (defvar gnus-article-internal-prepare-hook nil)
1270 (defvar gnus-newsgroup-process-stack nil)
1271
1272 (defvar gnus-thread-indent-array nil)
1273 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1274 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1275   "Function called to sort the articles within a thread after it has been gathered together.")
1276
1277 (defvar gnus-summary-save-parts-type-history nil)
1278 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1279
1280 ;; Avoid highlighting in kill files.
1281 (defvar gnus-summary-inhibit-highlight nil)
1282 (defvar gnus-newsgroup-selected-overlay nil)
1283 (defvar gnus-inhibit-limiting nil)
1284 (defvar gnus-newsgroup-adaptive-score-file nil)
1285 (defvar gnus-current-score-file nil)
1286 (defvar gnus-current-move-group nil)
1287 (defvar gnus-current-copy-group nil)
1288 (defvar gnus-current-crosspost-group nil)
1289 (defvar gnus-newsgroup-display nil)
1290
1291 (defvar gnus-newsgroup-dependencies nil)
1292 (defvar gnus-newsgroup-adaptive nil)
1293 (defvar gnus-summary-display-article-function nil)
1294 (defvar gnus-summary-highlight-line-function nil
1295   "Function called after highlighting a summary line.")
1296
1297 (defvar gnus-summary-line-format-alist
1298   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1299     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1300     (?s gnus-tmp-subject-or-nil ?s)
1301     (?n gnus-tmp-name ?s)
1302     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1303         ?s)
1304     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1305             gnus-tmp-from) ?s)
1306     (?F gnus-tmp-from ?s)
1307     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1308     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1309     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1310     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1311     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1312     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1313     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1314     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1315     (?L gnus-tmp-lines ?s)
1316     (?O gnus-tmp-downloaded ?c)
1317     (?I gnus-tmp-indentation ?s)
1318     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1319     (?R gnus-tmp-replied ?c)
1320     (?\[ gnus-tmp-opening-bracket ?c)
1321     (?\] gnus-tmp-closing-bracket ?c)
1322     (?\> (make-string gnus-tmp-level ? ) ?s)
1323     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1324     (?i gnus-tmp-score ?d)
1325     (?z gnus-tmp-score-char ?c)
1326     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1327     (?U gnus-tmp-unread ?c)
1328     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1329         ?s)
1330     (?t (gnus-summary-number-of-articles-in-thread
1331          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1332         ?d)
1333     (?e (gnus-summary-number-of-articles-in-thread
1334          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1335         ?c)
1336     (?u gnus-tmp-user-defined ?s)
1337     (?P (gnus-pick-line-number) ?d)
1338     (?B gnus-tmp-thread-tree-header-string ?s)
1339     (user-date (gnus-user-date
1340                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1341   "An alist of format specifications that can appear in summary lines.
1342 These are paired with what variables they correspond with, along with
1343 the type of the variable (string, integer, character, etc).")
1344
1345 (defvar gnus-summary-dummy-line-format-alist
1346   `((?S gnus-tmp-subject ?s)
1347     (?N gnus-tmp-number ?d)
1348     (?u gnus-tmp-user-defined ?s)))
1349
1350 (defvar gnus-summary-mode-line-format-alist
1351   `((?G gnus-tmp-group-name ?s)
1352     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1353     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1354     (?A gnus-tmp-article-number ?d)
1355     (?Z gnus-tmp-unread-and-unselected ?s)
1356     (?V gnus-version ?s)
1357     (?U gnus-tmp-unread-and-unticked ?d)
1358     (?S gnus-tmp-subject ?s)
1359     (?e gnus-tmp-unselected ?d)
1360     (?u gnus-tmp-user-defined ?s)
1361     (?d (length gnus-newsgroup-dormant) ?d)
1362     (?t (length gnus-newsgroup-marked) ?d)
1363     (?h (length gnus-newsgroup-spam-marked) ?d)
1364     (?r (length gnus-newsgroup-reads) ?d)
1365     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1366     (?E gnus-newsgroup-expunged-tally ?d)
1367     (?s (gnus-current-score-file-nondirectory) ?s)))
1368
1369 (defvar gnus-last-search-regexp nil
1370   "Default regexp for article search command.")
1371
1372 (defvar gnus-last-shell-command nil
1373   "Default shell command on article.")
1374
1375 (defvar gnus-newsgroup-agentized nil
1376   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1377 (defvar gnus-newsgroup-begin nil)
1378 (defvar gnus-newsgroup-end nil)
1379 (defvar gnus-newsgroup-last-rmail nil)
1380 (defvar gnus-newsgroup-last-mail nil)
1381 (defvar gnus-newsgroup-last-folder nil)
1382 (defvar gnus-newsgroup-last-file nil)
1383 (defvar gnus-newsgroup-last-directory nil)
1384 (defvar gnus-newsgroup-auto-expire nil)
1385 (defvar gnus-newsgroup-active nil)
1386
1387 (defvar gnus-newsgroup-data nil)
1388 (defvar gnus-newsgroup-data-reverse nil)
1389 (defvar gnus-newsgroup-limit nil)
1390 (defvar gnus-newsgroup-limits nil)
1391 (defvar gnus-summary-use-undownloaded-faces nil)
1392
1393 (defvar gnus-newsgroup-unreads nil
1394   "Sorted list of unread articles in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-unselected nil
1397   "Sorted list of unselected unread articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-reads nil
1400   "Alist of read articles and article marks in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-expunged-tally nil)
1403
1404 (defvar gnus-newsgroup-marked nil
1405   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1406
1407 (defvar gnus-newsgroup-spam-marked nil
1408   "List of ranges of articles that have been marked as spam.")
1409
1410 (defvar gnus-newsgroup-killed nil
1411   "List of ranges of articles that have been through the scoring process.")
1412
1413 (defvar gnus-newsgroup-cached nil
1414   "Sorted list of articles that come from the article cache.")
1415
1416 (defvar gnus-newsgroup-saved nil
1417   "List of articles that have been saved.")
1418
1419 (defvar gnus-newsgroup-kill-headers nil)
1420
1421 (defvar gnus-newsgroup-replied nil
1422   "List of articles that have been replied to in the current newsgroup.")
1423
1424 (defvar gnus-newsgroup-forwarded nil
1425   "List of articles that have been forwarded in the current newsgroup.")
1426
1427 (defvar gnus-newsgroup-recent nil
1428   "List of articles that have are recent in the current newsgroup.")
1429
1430 (defvar gnus-newsgroup-expirable nil
1431   "Sorted list of articles in the current newsgroup that can be expired.")
1432
1433 (defvar gnus-newsgroup-processable nil
1434   "List of articles in the current newsgroup that can be processed.")
1435
1436 (defvar gnus-newsgroup-downloadable nil
1437   "Sorted list of articles in the current newsgroup that can be processed.")
1438
1439 (defvar gnus-newsgroup-unfetched nil
1440   "Sorted list of articles in the current newsgroup whose headers have
1441 not been fetched into the agent.
1442
1443 This list will always be a subset of gnus-newsgroup-undownloaded.")
1444
1445 (defvar gnus-newsgroup-undownloaded nil
1446   "List of articles in the current newsgroup that haven't been downloaded.")
1447
1448 (defvar gnus-newsgroup-unsendable nil
1449   "List of articles in the current newsgroup that won't be sent.")
1450
1451 (defvar gnus-newsgroup-bookmarks nil
1452   "List of articles in the current newsgroup that have bookmarks.")
1453
1454 (defvar gnus-newsgroup-dormant nil
1455   "Sorted list of dormant articles in the current newsgroup.")
1456
1457 (defvar gnus-newsgroup-unseen nil
1458   "List of unseen articles in the current newsgroup.")
1459
1460 (defvar gnus-newsgroup-seen nil
1461   "Range of seen articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-articles nil
1464   "List of articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-scored nil
1467   "List of scored articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-headers nil
1470   "List of article headers in the current newsgroup.")
1471
1472 (defvar gnus-newsgroup-threads nil)
1473
1474 (defvar gnus-newsgroup-prepared nil
1475   "Whether the current group has been prepared properly.")
1476
1477 (defvar gnus-newsgroup-ancient nil
1478   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1479
1480 (defvar gnus-newsgroup-sparse nil)
1481
1482 (defvar gnus-current-article nil)
1483 (defvar gnus-article-current nil)
1484 (defvar gnus-current-headers nil)
1485 (defvar gnus-have-all-headers nil)
1486 (defvar gnus-last-article nil)
1487 (defvar gnus-newsgroup-history nil)
1488 (defvar gnus-newsgroup-charset nil)
1489 (defvar gnus-newsgroup-ephemeral-charset nil)
1490 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1491
1492 (defvar gnus-article-before-search nil)
1493
1494 (defvar gnus-summary-local-variables
1495   '(gnus-newsgroup-name
1496     gnus-newsgroup-begin gnus-newsgroup-end
1497     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1498     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1499     gnus-newsgroup-last-directory
1500     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1501     gnus-newsgroup-unselected gnus-newsgroup-marked
1502     gnus-newsgroup-spam-marked
1503     gnus-newsgroup-reads gnus-newsgroup-saved
1504     gnus-newsgroup-replied gnus-newsgroup-forwarded
1505     gnus-newsgroup-recent
1506     gnus-newsgroup-expirable
1507     gnus-newsgroup-processable gnus-newsgroup-killed
1508     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1509     gnus-newsgroup-unfetched
1510     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1511     gnus-newsgroup-seen gnus-newsgroup-articles
1512     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1513     gnus-newsgroup-headers gnus-newsgroup-threads
1514     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1515     gnus-current-article gnus-current-headers gnus-have-all-headers
1516     gnus-last-article gnus-article-internal-prepare-hook
1517     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1518     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1519     gnus-thread-expunge-below
1520     gnus-score-alist gnus-current-score-file
1521     (gnus-summary-expunge-below . global)
1522     (gnus-summary-mark-below . global)
1523     (gnus-orphan-score . global)
1524     gnus-newsgroup-active gnus-scores-exclude-files
1525     gnus-newsgroup-history gnus-newsgroup-ancient
1526     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1527     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1528     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1529     (gnus-newsgroup-expunged-tally . 0)
1530     gnus-cache-removable-articles gnus-newsgroup-cached
1531     gnus-newsgroup-data gnus-newsgroup-data-reverse
1532     gnus-newsgroup-limit gnus-newsgroup-limits
1533     gnus-newsgroup-charset gnus-newsgroup-display
1534     gnus-summary-use-undownloaded-faces)
1535   "Variables that are buffer-local to the summary buffers.")
1536
1537 (defvar gnus-newsgroup-variables nil
1538   "A list of variables that have separate values in different newsgroups.
1539 A list of newsgroup (summary buffer) local variables, or cons of
1540 variables and their default expressions to be evalled (when the default
1541 values are not nil), that should be made global while the summary buffer
1542 is active.
1543
1544 Note: The default expressions will be evaluated (using function `eval')
1545 before assignment to the local variable rather than just assigned to it.
1546 If the default expression is the symbol `global', that symbol will not
1547 be evaluated but the global value of the local variable will be used
1548 instead.
1549
1550 These variables can be used to set variables in the group parameters
1551 while still allowing them to affect operations done in other buffers.
1552 For example:
1553
1554 \(setq gnus-newsgroup-variables
1555      '(message-use-followup-to
1556        (gnus-visible-headers .
1557          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1558 ")
1559
1560 ;; Byte-compiler warning.
1561 (eval-when-compile
1562   ;; Bind features so that require will believe that gnus-sum has
1563   ;; already been loaded (avoids infinite recursion)
1564   (let ((features (cons 'gnus-sum features)))
1565     ;; Several of the declarations in gnus-sum are needed to load the
1566     ;; following files. Right now, these definitions have been
1567     ;; compiled but not defined (evaluated).  We could either do a
1568     ;; eval-and-compile about all of the declarations or evaluate the
1569     ;; source file.
1570     (if (boundp 'gnus-newsgroup-variables)
1571         nil
1572       (load "gnus-sum.el" t t t))
1573     (require 'gnus)
1574     (require 'gnus-art)))
1575
1576 ;; MIME stuff.
1577
1578 (defvar gnus-decode-encoded-word-methods
1579   '(mail-decode-encoded-word-string)
1580   "List of methods used to decode encoded words.
1581
1582 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1583 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1584 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1585 whose names match REGEXP.
1586
1587 For example:
1588 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1589  mail-decode-encoded-word-string
1590  (\"chinese\" . rfc1843-decode-string))")
1591
1592 (defvar gnus-decode-encoded-word-methods-cache nil)
1593
1594 (defun gnus-multi-decode-encoded-word-string (string)
1595   "Apply the functions from `gnus-encoded-word-methods' that match."
1596   (unless (and gnus-decode-encoded-word-methods-cache
1597                (eq gnus-newsgroup-name
1598                    (car gnus-decode-encoded-word-methods-cache)))
1599     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1600     (mapcar (lambda (x)
1601               (if (symbolp x)
1602                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1603                 (if (and gnus-newsgroup-name
1604                          (string-match (car x) gnus-newsgroup-name))
1605                     (nconc gnus-decode-encoded-word-methods-cache
1606                            (list (cdr x))))))
1607             gnus-decode-encoded-word-methods))
1608   (let ((xlist gnus-decode-encoded-word-methods-cache))
1609     (pop xlist)
1610     (while xlist
1611       (setq string (funcall (pop xlist) string))))
1612   string)
1613
1614 ;; Subject simplification.
1615
1616 (defun gnus-simplify-whitespace (str)
1617   "Remove excessive whitespace from STR."
1618   ;; Multiple spaces.
1619   (while (string-match "[ \t][ \t]+" str)
1620     (setq str (concat (substring str 0 (match-beginning 0))
1621                         " "
1622                         (substring str (match-end 0)))))
1623   ;; Leading spaces.
1624   (when (string-match "^[ \t]+" str)
1625     (setq str (substring str (match-end 0))))
1626   ;; Trailing spaces.
1627   (when (string-match "[ \t]+$" str)
1628     (setq str (substring str 0 (match-beginning 0))))
1629   str)
1630
1631 (defun gnus-simplify-all-whitespace (str)
1632   "Remove all whitespace from STR."
1633   (while (string-match "[ \t\n]+" str)
1634     (setq str (replace-match "" nil nil str)))
1635   str)
1636
1637 (defsubst gnus-simplify-subject-re (subject)
1638   "Remove \"Re:\" from subject lines."
1639   (if (string-match message-subject-re-regexp subject)
1640       (substring subject (match-end 0))
1641     subject))
1642
1643 (defun gnus-simplify-subject (subject &optional re-only)
1644   "Remove `Re:' and words in parentheses.
1645 If RE-ONLY is non-nil, strip leading `Re:'s only."
1646   (let ((case-fold-search t))           ;Ignore case.
1647     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1648     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1649       (setq subject (substring subject (match-end 0))))
1650     ;; Remove uninteresting prefixes.
1651     (when (and (not re-only)
1652                gnus-simplify-ignored-prefixes
1653                (string-match gnus-simplify-ignored-prefixes subject))
1654       (setq subject (substring subject (match-end 0))))
1655     ;; Remove words in parentheses from end.
1656     (unless re-only
1657       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1658         (setq subject (substring subject 0 (match-beginning 0)))))
1659     ;; Return subject string.
1660     subject))
1661
1662 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1663 ;; all whitespace.
1664 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1665   (goto-char (point-min))
1666   (while (re-search-forward regexp nil t)
1667     (replace-match (or newtext ""))))
1668
1669 (defun gnus-simplify-buffer-fuzzy ()
1670   "Simplify string in the buffer fuzzily.
1671 The string in the accessible portion of the current buffer is simplified.
1672 It is assumed to be a single-line subject.
1673 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1674 matter is removed.  Additional things can be deleted by setting
1675 `gnus-simplify-subject-fuzzy-regexp'."
1676   (let ((case-fold-search t)
1677         (modified-tick))
1678     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1679
1680     (while (not (eq modified-tick (buffer-modified-tick)))
1681       (setq modified-tick (buffer-modified-tick))
1682       (cond
1683        ((listp gnus-simplify-subject-fuzzy-regexp)
1684         (mapcar 'gnus-simplify-buffer-fuzzy-step
1685                 gnus-simplify-subject-fuzzy-regexp))
1686        (gnus-simplify-subject-fuzzy-regexp
1687         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1688       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1689       (gnus-simplify-buffer-fuzzy-step
1690        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1691       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1692
1693     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1694     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1695     (gnus-simplify-buffer-fuzzy-step " $")
1696     (gnus-simplify-buffer-fuzzy-step "^ +")))
1697
1698 (defun gnus-simplify-subject-fuzzy (subject)
1699   "Simplify a subject string fuzzily.
1700 See `gnus-simplify-buffer-fuzzy' for details."
1701   (save-excursion
1702     (gnus-set-work-buffer)
1703     (let ((case-fold-search t))
1704       ;; Remove uninteresting prefixes.
1705       (when (and gnus-simplify-ignored-prefixes
1706                  (string-match gnus-simplify-ignored-prefixes subject))
1707         (setq subject (substring subject (match-end 0))))
1708       (insert subject)
1709       (inline (gnus-simplify-buffer-fuzzy))
1710       (buffer-string))))
1711
1712 (defsubst gnus-simplify-subject-fully (subject)
1713   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1714   (cond
1715    (gnus-simplify-subject-functions
1716     (gnus-map-function gnus-simplify-subject-functions subject))
1717    ((null gnus-summary-gather-subject-limit)
1718     (gnus-simplify-subject-re subject))
1719    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1720     (gnus-simplify-subject-fuzzy subject))
1721    ((numberp gnus-summary-gather-subject-limit)
1722     (truncate-string-to-width (gnus-simplify-subject-re subject)
1723                               gnus-summary-gather-subject-limit))
1724    (t
1725     subject)))
1726
1727 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1728   "Check whether two subjects are equal.
1729 If optional argument SIMPLE-FIRST is t, first argument is already
1730 simplified."
1731   (cond
1732    ((null simple-first)
1733     (equal (gnus-simplify-subject-fully s1)
1734            (gnus-simplify-subject-fully s2)))
1735    (t
1736     (equal s1
1737            (gnus-simplify-subject-fully s2)))))
1738
1739 (defun gnus-summary-bubble-group ()
1740   "Increase the score of the current group.
1741 This is a handy function to add to `gnus-summary-exit-hook' to
1742 increase the score of each group you read."
1743   (gnus-group-add-score gnus-newsgroup-name))
1744
1745 \f
1746 ;;;
1747 ;;; Gnus summary mode
1748 ;;;
1749
1750 (put 'gnus-summary-mode 'mode-class 'special)
1751
1752 (defvar gnus-article-commands-menu)
1753
1754 ;; Non-orthogonal keys
1755
1756 (gnus-define-keys gnus-summary-mode-map
1757   " " gnus-summary-next-page
1758   "\177" gnus-summary-prev-page
1759   [delete] gnus-summary-prev-page
1760   [backspace] gnus-summary-prev-page
1761   "\r" gnus-summary-scroll-up
1762   "\M-\r" gnus-summary-scroll-down
1763   "n" gnus-summary-next-unread-article
1764   "p" gnus-summary-prev-unread-article
1765   "N" gnus-summary-next-article
1766   "P" gnus-summary-prev-article
1767   "\M-\C-n" gnus-summary-next-same-subject
1768   "\M-\C-p" gnus-summary-prev-same-subject
1769   "\M-n" gnus-summary-next-unread-subject
1770   "\M-p" gnus-summary-prev-unread-subject
1771   "." gnus-summary-first-unread-article
1772   "," gnus-summary-best-unread-article
1773   "\M-s" gnus-summary-search-article-forward
1774   "\M-r" gnus-summary-search-article-backward
1775   "\M-S" gnus-summary-repeat-search-article-forward
1776   "\M-R" gnus-summary-repeat-search-article-backward
1777   "<" gnus-summary-beginning-of-article
1778   ">" gnus-summary-end-of-article
1779   "j" gnus-summary-goto-article
1780   "^" gnus-summary-refer-parent-article
1781   "\M-^" gnus-summary-refer-article
1782   "u" gnus-summary-tick-article-forward
1783   "!" gnus-summary-tick-article-forward
1784   "U" gnus-summary-tick-article-backward
1785   "d" gnus-summary-mark-as-read-forward
1786   "D" gnus-summary-mark-as-read-backward
1787   "E" gnus-summary-mark-as-expirable
1788   "\M-u" gnus-summary-clear-mark-forward
1789   "\M-U" gnus-summary-clear-mark-backward
1790   "k" gnus-summary-kill-same-subject-and-select
1791   "\C-k" gnus-summary-kill-same-subject
1792   "\M-\C-k" gnus-summary-kill-thread
1793   "\M-\C-l" gnus-summary-lower-thread
1794   "e" gnus-summary-edit-article
1795   "#" gnus-summary-mark-as-processable
1796   "\M-#" gnus-summary-unmark-as-processable
1797   "\M-\C-t" gnus-summary-toggle-threads
1798   "\M-\C-s" gnus-summary-show-thread
1799   "\M-\C-h" gnus-summary-hide-thread
1800   "\M-\C-f" gnus-summary-next-thread
1801   "\M-\C-b" gnus-summary-prev-thread
1802   [(meta down)] gnus-summary-next-thread
1803   [(meta up)] gnus-summary-prev-thread
1804   "\M-\C-u" gnus-summary-up-thread
1805   "\M-\C-d" gnus-summary-down-thread
1806   "&" gnus-summary-execute-command
1807   "c" gnus-summary-catchup-and-exit
1808   "\C-w" gnus-summary-mark-region-as-read
1809   "\C-t" gnus-summary-toggle-truncation
1810   "?" gnus-summary-mark-as-dormant
1811   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1812   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1813   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1814   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1815   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1816   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1817   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1818   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1819   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1820   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1821   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1822   "=" gnus-summary-expand-window
1823   "\C-x\C-s" gnus-summary-reselect-current-group
1824   "\M-g" gnus-summary-rescan-group
1825   "w" gnus-summary-stop-page-breaking
1826   "\C-c\C-r" gnus-summary-caesar-message
1827   "f" gnus-summary-followup
1828   "F" gnus-summary-followup-with-original
1829   "C" gnus-summary-cancel-article
1830   "r" gnus-summary-reply
1831   "R" gnus-summary-reply-with-original
1832   "\C-c\C-f" gnus-summary-mail-forward
1833   "o" gnus-summary-save-article
1834   "\C-o" gnus-summary-save-article-mail
1835   "|" gnus-summary-pipe-output
1836   "\M-k" gnus-summary-edit-local-kill
1837   "\M-K" gnus-summary-edit-global-kill
1838   ;; "V" gnus-version
1839   "\C-c\C-d" gnus-summary-describe-group
1840   "q" gnus-summary-exit
1841   "Q" gnus-summary-exit-no-update
1842   "\C-c\C-i" gnus-info-find-node
1843   gnus-mouse-2 gnus-mouse-pick-article
1844   [follow-link] mouse-face
1845   "m" gnus-summary-mail-other-window
1846   "a" gnus-summary-post-news
1847   "i" gnus-summary-news-other-window
1848   "x" gnus-summary-limit-to-unread
1849   "s" gnus-summary-isearch-article
1850   "t" gnus-summary-toggle-header
1851   "g" gnus-summary-show-article
1852   "l" gnus-summary-goto-last-article
1853   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1854   "\C-d" gnus-summary-enter-digest-group
1855   "\M-\C-d" gnus-summary-read-document
1856   "\M-\C-e" gnus-summary-edit-parameters
1857   "\M-\C-a" gnus-summary-customize-parameters
1858   "\C-c\C-b" gnus-bug
1859   "*" gnus-cache-enter-article
1860   "\M-*" gnus-cache-remove-article
1861   "\M-&" gnus-summary-universal-argument
1862   "\C-l" gnus-recenter
1863   "I" gnus-summary-increase-score
1864   "L" gnus-summary-lower-score
1865   "\M-i" gnus-symbolic-argument
1866   "h" gnus-summary-select-article-buffer
1867
1868   "b" gnus-article-view-part
1869   "\M-t" gnus-summary-toggle-display-buttonized
1870
1871   "V" gnus-summary-score-map
1872   "X" gnus-uu-extract-map
1873   "S" gnus-summary-send-map)
1874
1875 ;; Sort of orthogonal keymap
1876 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1877   "t" gnus-summary-tick-article-forward
1878   "!" gnus-summary-tick-article-forward
1879   "d" gnus-summary-mark-as-read-forward
1880   "r" gnus-summary-mark-as-read-forward
1881   "c" gnus-summary-clear-mark-forward
1882   " " gnus-summary-clear-mark-forward
1883   "e" gnus-summary-mark-as-expirable
1884   "x" gnus-summary-mark-as-expirable
1885   "?" gnus-summary-mark-as-dormant
1886   "b" gnus-summary-set-bookmark
1887   "B" gnus-summary-remove-bookmark
1888   "#" gnus-summary-mark-as-processable
1889   "\M-#" gnus-summary-unmark-as-processable
1890   "S" gnus-summary-limit-include-expunged
1891   "C" gnus-summary-catchup
1892   "H" gnus-summary-catchup-to-here
1893   "h" gnus-summary-catchup-from-here
1894   "\C-c" gnus-summary-catchup-all
1895   "k" gnus-summary-kill-same-subject-and-select
1896   "K" gnus-summary-kill-same-subject
1897   "P" gnus-uu-mark-map)
1898
1899 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1900   "c" gnus-summary-clear-above
1901   "u" gnus-summary-tick-above
1902   "m" gnus-summary-mark-above
1903   "k" gnus-summary-kill-below)
1904
1905 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1906   "/" gnus-summary-limit-to-subject
1907   "n" gnus-summary-limit-to-articles
1908   "b" gnus-summary-limit-to-bodies
1909   "h" gnus-summary-limit-to-headers
1910   "w" gnus-summary-pop-limit
1911   "s" gnus-summary-limit-to-subject
1912   "a" gnus-summary-limit-to-author
1913   "u" gnus-summary-limit-to-unread
1914   "m" gnus-summary-limit-to-marks
1915   "M" gnus-summary-limit-exclude-marks
1916   "v" gnus-summary-limit-to-score
1917   "*" gnus-summary-limit-include-cached
1918   "D" gnus-summary-limit-include-dormant
1919   "T" gnus-summary-limit-include-thread
1920   "d" gnus-summary-limit-exclude-dormant
1921   "t" gnus-summary-limit-to-age
1922   "." gnus-summary-limit-to-unseen
1923   "x" gnus-summary-limit-to-extra
1924   "p" gnus-summary-limit-to-display-predicate
1925   "E" gnus-summary-limit-include-expunged
1926   "c" gnus-summary-limit-exclude-childless-dormant
1927   "C" gnus-summary-limit-mark-excluded-as-read
1928   "o" gnus-summary-insert-old-articles
1929   "N" gnus-summary-insert-new-articles
1930   "S" gnus-summary-limit-to-singletons
1931   "r" gnus-summary-limit-to-replied
1932   "R" gnus-summary-limit-to-recipient
1933   "A" gnus-summary-limit-to-address)
1934
1935 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1936   "n" gnus-summary-next-unread-article
1937   "p" gnus-summary-prev-unread-article
1938   "N" gnus-summary-next-article
1939   "P" gnus-summary-prev-article
1940   "\C-n" gnus-summary-next-same-subject
1941   "\C-p" gnus-summary-prev-same-subject
1942   "\M-n" gnus-summary-next-unread-subject
1943   "\M-p" gnus-summary-prev-unread-subject
1944   "f" gnus-summary-first-unread-article
1945   "b" gnus-summary-best-unread-article
1946   "j" gnus-summary-goto-article
1947   "g" gnus-summary-goto-subject
1948   "l" gnus-summary-goto-last-article
1949   "o" gnus-summary-pop-article)
1950
1951 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1952   "k" gnus-summary-kill-thread
1953   "l" gnus-summary-lower-thread
1954   "i" gnus-summary-raise-thread
1955   "T" gnus-summary-toggle-threads
1956   "t" gnus-summary-rethread-current
1957   "^" gnus-summary-reparent-thread
1958   "\M-^" gnus-summary-reparent-children
1959   "s" gnus-summary-show-thread
1960   "S" gnus-summary-show-all-threads
1961   "h" gnus-summary-hide-thread
1962   "H" gnus-summary-hide-all-threads
1963   "n" gnus-summary-next-thread
1964   "p" gnus-summary-prev-thread
1965   "u" gnus-summary-up-thread
1966   "o" gnus-summary-top-thread
1967   "d" gnus-summary-down-thread
1968   "#" gnus-uu-mark-thread
1969   "\M-#" gnus-uu-unmark-thread)
1970
1971 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1972   "g" gnus-summary-prepare
1973   "c" gnus-summary-insert-cached-articles
1974   "d" gnus-summary-insert-dormant-articles
1975   "t" gnus-summary-insert-ticked-articles)
1976
1977 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1978   "c" gnus-summary-catchup-and-exit
1979   "C" gnus-summary-catchup-all-and-exit
1980   "E" gnus-summary-exit-no-update
1981   "Q" gnus-summary-exit
1982   "Z" gnus-summary-exit
1983   "n" gnus-summary-catchup-and-goto-next-group
1984   "p" gnus-summary-catchup-and-goto-prev-group
1985   "R" gnus-summary-reselect-current-group
1986   "G" gnus-summary-rescan-group
1987   "N" gnus-summary-next-group
1988   "s" gnus-summary-save-newsrc
1989   "P" gnus-summary-prev-group)
1990
1991 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1992   " " gnus-summary-next-page
1993   "n" gnus-summary-next-page
1994   "\177" gnus-summary-prev-page
1995   [delete] gnus-summary-prev-page
1996   "p" gnus-summary-prev-page
1997   "\r" gnus-summary-scroll-up
1998   "\M-\r" gnus-summary-scroll-down
1999   "<" gnus-summary-beginning-of-article
2000   ">" gnus-summary-end-of-article
2001   "b" gnus-summary-beginning-of-article
2002   "e" gnus-summary-end-of-article
2003   "^" gnus-summary-refer-parent-article
2004   "r" gnus-summary-refer-parent-article
2005   "D" gnus-summary-enter-digest-group
2006   "R" gnus-summary-refer-references
2007   "T" gnus-summary-refer-thread
2008   "g" gnus-summary-show-article
2009   "s" gnus-summary-isearch-article
2010   "P" gnus-summary-print-article
2011   "S" gnus-sticky-article
2012   "M" gnus-mailing-list-insinuate
2013   "t" gnus-article-babel)
2014
2015 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2016   "b" gnus-article-add-buttons
2017   "B" gnus-article-add-buttons-to-head
2018   "o" gnus-article-treat-overstrike
2019   "e" gnus-article-emphasize
2020   "w" gnus-article-fill-cited-article
2021   "Q" gnus-article-fill-long-lines
2022   "L" gnus-article-toggle-truncate-lines
2023   "C" gnus-article-capitalize-sentences
2024   "c" gnus-article-remove-cr
2025   "q" gnus-article-de-quoted-unreadable
2026   "6" gnus-article-de-base64-unreadable
2027   "Z" gnus-article-decode-HZ
2028   "A" gnus-article-treat-ansi-sequences
2029   "h" gnus-article-wash-html
2030   "u" gnus-article-unsplit-urls
2031   "s" gnus-summary-force-verify-and-decrypt
2032   "f" gnus-article-display-x-face
2033   "l" gnus-summary-stop-page-breaking
2034   "r" gnus-summary-caesar-message
2035   "m" gnus-summary-morse-message
2036   "t" gnus-summary-toggle-header
2037   "g" gnus-treat-smiley
2038   "v" gnus-summary-verbose-headers
2039   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2040   "p" gnus-article-verify-x-pgp-sig
2041   "d" gnus-article-treat-dumbquotes
2042   "i" gnus-summary-idna-message)
2043
2044 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2045   ;; mnemonic: deuglif*Y*
2046   "u" gnus-article-outlook-unwrap-lines
2047   "a" gnus-article-outlook-repair-attribution
2048   "c" gnus-article-outlook-rearrange-citation
2049   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2050
2051 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2052   "a" gnus-article-hide
2053   "h" gnus-article-hide-headers
2054   "b" gnus-article-hide-boring-headers
2055   "s" gnus-article-hide-signature
2056   "c" gnus-article-hide-citation
2057   "C" gnus-article-hide-citation-in-followups
2058   "l" gnus-article-hide-list-identifiers
2059   "B" gnus-article-strip-banner
2060   "P" gnus-article-hide-pem
2061   "\C-c" gnus-article-hide-citation-maybe)
2062
2063 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2064   "a" gnus-article-highlight
2065   "h" gnus-article-highlight-headers
2066   "c" gnus-article-highlight-citation
2067   "s" gnus-article-highlight-signature)
2068
2069 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2070   "f" gnus-article-treat-fold-headers
2071   "u" gnus-article-treat-unfold-headers
2072   "n" gnus-article-treat-fold-newsgroups)
2073
2074 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2075   "x" gnus-article-display-x-face
2076   "d" gnus-article-display-face
2077   "s" gnus-treat-smiley
2078   "D" gnus-article-remove-images
2079   "f" gnus-treat-from-picon
2080   "m" gnus-treat-mail-picon
2081   "n" gnus-treat-newsgroups-picon)
2082
2083 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2084   "w" gnus-article-decode-mime-words
2085   "c" gnus-article-decode-charset
2086   "v" gnus-mime-view-all-parts
2087   "b" gnus-article-view-part)
2088
2089 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2090   "z" gnus-article-date-ut
2091   "u" gnus-article-date-ut
2092   "l" gnus-article-date-local
2093   "p" gnus-article-date-english
2094   "e" gnus-article-date-lapsed
2095   "o" gnus-article-date-original
2096   "i" gnus-article-date-iso8601
2097   "s" gnus-article-date-user)
2098
2099 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2100   "t" gnus-article-remove-trailing-blank-lines
2101   "l" gnus-article-strip-leading-blank-lines
2102   "m" gnus-article-strip-multiple-blank-lines
2103   "a" gnus-article-strip-blank-lines
2104   "A" gnus-article-strip-all-blank-lines
2105   "s" gnus-article-strip-leading-space
2106   "e" gnus-article-strip-trailing-space
2107   "w" gnus-article-remove-leading-whitespace)
2108
2109 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2110   "v" gnus-version
2111   "f" gnus-summary-fetch-faq
2112   "d" gnus-summary-describe-group
2113   "h" gnus-summary-describe-briefly
2114   "i" gnus-info-find-node
2115   "c" gnus-group-fetch-charter
2116   "C" gnus-group-fetch-control)
2117
2118 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2119   "e" gnus-summary-expire-articles
2120   "\M-\C-e" gnus-summary-expire-articles-now
2121   "\177" gnus-summary-delete-article
2122   [delete] gnus-summary-delete-article
2123   [backspace] gnus-summary-delete-article
2124   "m" gnus-summary-move-article
2125   "r" gnus-summary-respool-article
2126   "w" gnus-summary-edit-article
2127   "c" gnus-summary-copy-article
2128   "B" gnus-summary-crosspost-article
2129   "q" gnus-summary-respool-query
2130   "t" gnus-summary-respool-trace
2131   "i" gnus-summary-import-article
2132   "I" gnus-summary-create-article
2133   "p" gnus-summary-article-posted-p)
2134
2135 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2136   "o" gnus-summary-save-article
2137   "m" gnus-summary-save-article-mail
2138   "F" gnus-summary-write-article-file
2139   "r" gnus-summary-save-article-rmail
2140   "f" gnus-summary-save-article-file
2141   "b" gnus-summary-save-article-body-file
2142   "B" gnus-summary-write-article-body-file
2143   "h" gnus-summary-save-article-folder
2144   "v" gnus-summary-save-article-vm
2145   "p" gnus-summary-pipe-output
2146   "P" gnus-summary-muttprint
2147   "s" gnus-soup-add-article)
2148
2149 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2150   "b" gnus-summary-display-buttonized
2151   "m" gnus-summary-repair-multipart
2152   "v" gnus-article-view-part
2153   "o" gnus-article-save-part
2154   "O" gnus-article-save-part-and-strip
2155   "r" gnus-article-replace-part
2156   "d" gnus-article-delete-part
2157   "t" gnus-article-view-part-as-type
2158   "j" gnus-article-jump-to-part
2159   "c" gnus-article-copy-part
2160   "C" gnus-article-view-part-as-charset
2161   "e" gnus-article-view-part-externally
2162   "H" gnus-article-browse-html-article
2163   "E" gnus-article-encrypt-body
2164   "i" gnus-article-inline-part
2165   "|" gnus-article-pipe-part)
2166
2167 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2168   "p" gnus-summary-mark-as-processable
2169   "u" gnus-summary-unmark-as-processable
2170   "U" gnus-summary-unmark-all-processable
2171   "v" gnus-uu-mark-over
2172   "s" gnus-uu-mark-series
2173   "r" gnus-uu-mark-region
2174   "g" gnus-uu-unmark-region
2175   "R" gnus-uu-mark-by-regexp
2176   "G" gnus-uu-unmark-by-regexp
2177   "t" gnus-uu-mark-thread
2178   "T" gnus-uu-unmark-thread
2179   "a" gnus-uu-mark-all
2180   "b" gnus-uu-mark-buffer
2181   "S" gnus-uu-mark-sparse
2182   "k" gnus-summary-kill-process-mark
2183   "y" gnus-summary-yank-process-mark
2184   "w" gnus-summary-save-process-mark
2185   "i" gnus-uu-invert-processable)
2186
2187 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2188   ;;"x" gnus-uu-extract-any
2189   "m" gnus-summary-save-parts
2190   "u" gnus-uu-decode-uu
2191   "U" gnus-uu-decode-uu-and-save
2192   "s" gnus-uu-decode-unshar
2193   "S" gnus-uu-decode-unshar-and-save
2194   "o" gnus-uu-decode-save
2195   "O" gnus-uu-decode-save
2196   "b" gnus-uu-decode-binhex
2197   "B" gnus-uu-decode-binhex
2198   "p" gnus-uu-decode-postscript
2199   "P" gnus-uu-decode-postscript-and-save)
2200
2201 (gnus-define-keys
2202     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2203   "u" gnus-uu-decode-uu-view
2204   "U" gnus-uu-decode-uu-and-save-view
2205   "s" gnus-uu-decode-unshar-view
2206   "S" gnus-uu-decode-unshar-and-save-view
2207   "o" gnus-uu-decode-save-view
2208   "O" gnus-uu-decode-save-view
2209   "b" gnus-uu-decode-binhex-view
2210   "B" gnus-uu-decode-binhex-view
2211   "p" gnus-uu-decode-postscript-view
2212   "P" gnus-uu-decode-postscript-and-save-view)
2213
2214 (defvar gnus-article-post-menu nil)
2215
2216 (defconst gnus-summary-menu-maxlen 20)
2217
2218 (defun gnus-summary-menu-split (menu)
2219   ;; If we have lots of elements, divide them into groups of 20
2220   ;; and make a pane (or submenu) for each one.
2221   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2222       (let ((menu menu) sublists next
2223             (i 1))
2224         (while menu
2225           ;; Pull off the next gnus-summary-menu-maxlen elements
2226           ;; and make them the next element of sublist.
2227           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2228           (if next
2229               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2230                       nil))
2231           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2232                                              (aref (car (last menu)) 0)) menu)
2233                                sublists))
2234           (setq i (1+ i))
2235           (setq menu next))
2236         (nreverse sublists))
2237     ;; Few elements--put them all in one pane.
2238     menu))
2239
2240 (defun gnus-summary-make-menu-bar ()
2241   (gnus-turn-off-edit-menu 'summary)
2242
2243   (unless (boundp 'gnus-summary-misc-menu)
2244
2245     (easy-menu-define
2246       gnus-summary-kill-menu gnus-summary-mode-map ""
2247       (cons
2248        "Score"
2249        (nconc
2250         (list
2251          ["Customize" gnus-score-customize t])
2252         (gnus-make-score-map 'increase)
2253         (gnus-make-score-map 'lower)
2254         '(("Mark"
2255            ["Kill below" gnus-summary-kill-below t]
2256            ["Mark above" gnus-summary-mark-above t]
2257            ["Tick above" gnus-summary-tick-above t]
2258            ["Clear above" gnus-summary-clear-above t])
2259           ["Current score" gnus-summary-current-score t]
2260           ["Set score" gnus-summary-set-score t]
2261           ["Switch current score file..." gnus-score-change-score-file t]
2262           ["Set mark below..." gnus-score-set-mark-below t]
2263           ["Set expunge below..." gnus-score-set-expunge-below t]
2264           ["Edit current score file" gnus-score-edit-current-scores t]
2265           ["Edit score file" gnus-score-edit-file t]
2266           ["Trace score" gnus-score-find-trace t]
2267           ["Find words" gnus-score-find-favourite-words t]
2268           ["Rescore buffer" gnus-summary-rescore t]
2269           ["Increase score..." gnus-summary-increase-score t]
2270           ["Lower score..." gnus-summary-lower-score t]))))
2271
2272     ;; Define both the Article menu in the summary buffer and the
2273     ;; equivalent Commands menu in the article buffer here for
2274     ;; consistency.
2275     (let ((innards
2276            `(("Hide"
2277               ["All" gnus-article-hide t]
2278               ["Headers" gnus-article-hide-headers t]
2279               ["Signature" gnus-article-hide-signature t]
2280               ["Citation" gnus-article-hide-citation t]
2281               ["List identifiers" gnus-article-hide-list-identifiers t]
2282               ["Banner" gnus-article-strip-banner t]
2283               ["Boring headers" gnus-article-hide-boring-headers t])
2284              ("Highlight"
2285               ["All" gnus-article-highlight t]
2286               ["Headers" gnus-article-highlight-headers t]
2287               ["Signature" gnus-article-highlight-signature t]
2288               ["Citation" gnus-article-highlight-citation t])
2289              ("MIME"
2290               ["Words" gnus-article-decode-mime-words t]
2291               ["Charset" gnus-article-decode-charset t]
2292               ["QP" gnus-article-de-quoted-unreadable t]
2293               ["Base64" gnus-article-de-base64-unreadable t]
2294               ["View MIME buttons" gnus-summary-display-buttonized t]
2295               ["View all" gnus-mime-view-all-parts t]
2296               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2297               ["Encrypt body" gnus-article-encrypt-body
2298                :active (not (gnus-group-read-only-p))
2299                ,@(if (featurep 'xemacs) nil
2300                    '(:help "Encrypt the message body on disk"))]
2301               ["Extract all parts..." gnus-summary-save-parts t]
2302               ("Multipart"
2303                ["Repair multipart" gnus-summary-repair-multipart t]
2304                ["Pipe part..." gnus-article-pipe-part t]
2305                ["Inline part" gnus-article-inline-part t]
2306                ["View part as type..." gnus-article-view-part-as-type t]
2307                ["Encrypt body" gnus-article-encrypt-body
2308                 :active (not (gnus-group-read-only-p))
2309                ,@(if (featurep 'xemacs) nil
2310                    '(:help "Encrypt the message body on disk"))]
2311                ["View part externally" gnus-article-view-part-externally t]
2312                ["View HTML parts in browser" gnus-article-browse-html-article t]
2313                ["View part with charset..." gnus-article-view-part-as-charset t]
2314                ["Copy part" gnus-article-copy-part t]
2315                ["Save part..." gnus-article-save-part t]
2316                ["View part" gnus-article-view-part t]))
2317              ("Date"
2318               ["Local" gnus-article-date-local t]
2319               ["ISO8601" gnus-article-date-iso8601 t]
2320               ["UT" gnus-article-date-ut t]
2321               ["Original" gnus-article-date-original t]
2322               ["Lapsed" gnus-article-date-lapsed t]
2323               ["User-defined" gnus-article-date-user t])
2324              ("Display"
2325               ["Remove images" gnus-article-remove-images t]
2326               ["Toggle smiley" gnus-treat-smiley t]
2327               ["Show X-Face" gnus-article-display-x-face t]
2328               ["Show picons in From" gnus-treat-from-picon t]
2329               ["Show picons in mail headers" gnus-treat-mail-picon t]
2330               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2331               ("View as different encoding"
2332                ,@(gnus-summary-menu-split
2333                   (mapcar
2334                    (lambda (cs)
2335                      ;; Since easymenu under Emacs doesn't allow
2336                      ;; lambda forms for menu commands, we should
2337                      ;; provide intern'ed function symbols.
2338                      (let ((command (intern (format "\
2339 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2340                        (fset command
2341                              `(lambda ()
2342                                 (interactive)
2343                                 (let ((gnus-summary-show-article-charset-alist
2344                                        '((1 . ,cs))))
2345                                   (gnus-summary-show-article 1))))
2346                        `[,(symbol-name cs) ,command t]))
2347                    (sort (if (fboundp 'coding-system-list)
2348                              (coding-system-list)
2349                            (mapcar 'car mm-mime-mule-charset-alist))
2350                          'string<)))))
2351              ("Washing"
2352               ("Remove Blanks"
2353                ["Leading" gnus-article-strip-leading-blank-lines t]
2354                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2355                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2356                ["All of the above" gnus-article-strip-blank-lines t]
2357                ["All" gnus-article-strip-all-blank-lines t]
2358                ["Leading space" gnus-article-strip-leading-space t]
2359                ["Trailing space" gnus-article-strip-trailing-space t]
2360                ["Leading space in headers"
2361                 gnus-article-remove-leading-whitespace t])
2362               ["Overstrike" gnus-article-treat-overstrike t]
2363               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2364               ["Emphasis" gnus-article-emphasize t]
2365               ["Word wrap" gnus-article-fill-cited-article t]
2366               ["Fill long lines" gnus-article-fill-long-lines t]
2367               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2368               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2369               ["Remove CR" gnus-article-remove-cr t]
2370               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2371               ["Base64" gnus-article-de-base64-unreadable t]
2372               ["Rot 13" gnus-summary-caesar-message
2373                ,@(if (featurep 'xemacs) '(t)
2374                    '(:help "\"Caesar rotate\" article by 13"))]
2375               ["De-IDNA" gnus-summary-idna-message t]
2376               ["Morse decode" gnus-summary-morse-message t]
2377               ["Unix pipe..." gnus-summary-pipe-message t]
2378               ["Add buttons" gnus-article-add-buttons t]
2379               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2380               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2381               ["Verbose header" gnus-summary-verbose-headers t]
2382               ["Toggle header" gnus-summary-toggle-header t]
2383               ["Unfold headers" gnus-article-treat-unfold-headers t]
2384               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2385               ["Html" gnus-article-wash-html t]
2386               ["Unsplit URLs" gnus-article-unsplit-urls t]
2387               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2388               ["Decode HZ" gnus-article-decode-HZ t]
2389               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2390               ("(Outlook) Deuglify"
2391                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2392                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2393                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2394                ["Full (Outlook) deuglify"
2395                 gnus-article-outlook-deuglify-article t])
2396               )
2397              ("Output"
2398               ["Save in default format..." gnus-summary-save-article
2399                ,@(if (featurep 'xemacs) '(t)
2400                    '(:help "Save article using default method"))]
2401               ["Save in file..." gnus-summary-save-article-file
2402                ,@(if (featurep 'xemacs) '(t)
2403                    '(:help "Save article in file"))]
2404               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2405               ["Save in MH folder..." gnus-summary-save-article-folder t]
2406               ["Save in VM folder..." gnus-summary-save-article-vm t]
2407               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2408               ["Save body in file..." gnus-summary-save-article-body-file t]
2409               ["Pipe through a filter..." gnus-summary-pipe-output t]
2410               ["Add to SOUP packet" gnus-soup-add-article t]
2411               ["Print with Muttprint..." gnus-summary-muttprint t]
2412               ["Print" gnus-summary-print-article
2413                ,@(if (featurep 'xemacs) '(t)
2414                    '(:help "Generate and print a PostScript image"))])
2415              ("Copy, move,... (Backend)"
2416               ,@(if (featurep 'xemacs) nil
2417                   '(:help "Copying, moving, expiring articles..."))
2418               ["Respool article..." gnus-summary-respool-article t]
2419               ["Move article..." gnus-summary-move-article
2420                (gnus-check-backend-function
2421                 'request-move-article gnus-newsgroup-name)]
2422               ["Copy article..." gnus-summary-copy-article t]
2423               ["Crosspost article..." gnus-summary-crosspost-article
2424                (gnus-check-backend-function
2425                 'request-replace-article gnus-newsgroup-name)]
2426               ["Import file..." gnus-summary-import-article
2427                (gnus-check-backend-function
2428                 'request-accept-article gnus-newsgroup-name)]
2429               ["Create article..." gnus-summary-create-article
2430                (gnus-check-backend-function
2431                 'request-accept-article gnus-newsgroup-name)]
2432               ["Check if posted" gnus-summary-article-posted-p t]
2433               ["Edit article" gnus-summary-edit-article
2434                (not (gnus-group-read-only-p))]
2435               ["Delete article" gnus-summary-delete-article
2436                (gnus-check-backend-function
2437                 'request-expire-articles gnus-newsgroup-name)]
2438               ["Query respool" gnus-summary-respool-query t]
2439               ["Trace respool" gnus-summary-respool-trace t]
2440               ["Delete expirable articles" gnus-summary-expire-articles-now
2441                (gnus-check-backend-function
2442                 'request-expire-articles gnus-newsgroup-name)])
2443              ("Extract"
2444               ["Uudecode" gnus-uu-decode-uu
2445                ,@(if (featurep 'xemacs) '(t)
2446                    '(:help "Decode uuencoded article(s)"))]
2447               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2448               ["Unshar" gnus-uu-decode-unshar t]
2449               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2450               ["Save" gnus-uu-decode-save t]
2451               ["Binhex" gnus-uu-decode-binhex t]
2452               ["Postscript" gnus-uu-decode-postscript t]
2453               ["All MIME parts" gnus-summary-save-parts t])
2454              ("Cache"
2455               ["Enter article" gnus-cache-enter-article t]
2456               ["Remove article" gnus-cache-remove-article t])
2457              ["Translate" gnus-article-babel t]
2458              ["Select article buffer" gnus-summary-select-article-buffer t]
2459              ["Make article buffer sticky" gnus-sticky-article t]
2460              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2461              ["Isearch article..." gnus-summary-isearch-article t]
2462              ["Beginning of the article" gnus-summary-beginning-of-article t]
2463              ["End of the article" gnus-summary-end-of-article t]
2464              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2465              ["Fetch referenced articles" gnus-summary-refer-references t]
2466              ["Fetch current thread" gnus-summary-refer-thread t]
2467              ["Fetch article with id..." gnus-summary-refer-article t]
2468              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2469              ["Redisplay" gnus-summary-show-article t]
2470              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2471       (easy-menu-define
2472         gnus-summary-article-menu gnus-summary-mode-map ""
2473         (cons "Article" innards))
2474
2475       (if (not (keymapp gnus-summary-article-menu))
2476           (easy-menu-define
2477             gnus-article-commands-menu gnus-article-mode-map ""
2478             (cons "Commands" innards))
2479         ;; in Emacs, don't share menu.
2480         (setq gnus-article-commands-menu
2481               (copy-keymap gnus-summary-article-menu))
2482         (define-key gnus-article-mode-map [menu-bar commands]
2483           (cons "Commands" gnus-article-commands-menu))))
2484
2485     (easy-menu-define
2486       gnus-summary-thread-menu gnus-summary-mode-map ""
2487       '("Threads"
2488         ["Find all messages in thread" gnus-summary-refer-thread t]
2489         ["Toggle threading" gnus-summary-toggle-threads t]
2490         ["Hide threads" gnus-summary-hide-all-threads t]
2491         ["Show threads" gnus-summary-show-all-threads t]
2492         ["Hide thread" gnus-summary-hide-thread t]
2493         ["Show thread" gnus-summary-show-thread t]
2494         ["Go to next thread" gnus-summary-next-thread t]
2495         ["Go to previous thread" gnus-summary-prev-thread t]
2496         ["Go down thread" gnus-summary-down-thread t]
2497         ["Go up thread" gnus-summary-up-thread t]
2498         ["Top of thread" gnus-summary-top-thread t]
2499         ["Mark thread as read" gnus-summary-kill-thread t]
2500         ["Lower thread score" gnus-summary-lower-thread t]
2501         ["Raise thread score" gnus-summary-raise-thread t]
2502         ["Rethread current" gnus-summary-rethread-current t]))
2503
2504     (easy-menu-define
2505       gnus-summary-post-menu gnus-summary-mode-map ""
2506       `("Post"
2507         ["Send a message (mail or news)" gnus-summary-post-news
2508          ,@(if (featurep 'xemacs) '(t)
2509              '(:help "Compose a new message (mail or news)"))]
2510         ["Followup" gnus-summary-followup
2511          ,@(if (featurep 'xemacs) '(t)
2512              '(:help "Post followup to this article"))]
2513         ["Followup and yank" gnus-summary-followup-with-original
2514          ,@(if (featurep 'xemacs) '(t)
2515              '(:help "Post followup to this article, quoting its contents"))]
2516         ["Supersede article" gnus-summary-supersede-article t]
2517         ["Cancel article" gnus-summary-cancel-article
2518          ,@(if (featurep 'xemacs) '(t)
2519              '(:help "Cancel an article you posted"))]
2520         ["Reply" gnus-summary-reply t]
2521         ["Reply and yank" gnus-summary-reply-with-original t]
2522         ["Wide reply" gnus-summary-wide-reply t]
2523         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2524          ,@(if (featurep 'xemacs) '(t)
2525              '(:help "Mail a reply, quoting this article"))]
2526         ["Very wide reply" gnus-summary-very-wide-reply t]
2527         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2528          ,@(if (featurep 'xemacs) '(t)
2529              '(:help "Mail a very wide reply, quoting this article"))]
2530         ["Mail forward" gnus-summary-mail-forward t]
2531         ["Post forward" gnus-summary-post-forward t]
2532         ["Digest and mail" gnus-uu-digest-mail-forward t]
2533         ["Digest and post" gnus-uu-digest-post-forward t]
2534         ["Resend message" gnus-summary-resend-message t]
2535         ["Resend message edit" gnus-summary-resend-message-edit t]
2536         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2537         ["Send a mail" gnus-summary-mail-other-window t]
2538         ["Create a local message" gnus-summary-news-other-window t]
2539         ["Uuencode and post" gnus-uu-post-news
2540          ,@(if (featurep 'xemacs) '(t)
2541              '(:help "Post a uuencoded article"))]
2542         ["Followup via news" gnus-summary-followup-to-mail t]
2543         ["Followup via news and yank"
2544          gnus-summary-followup-to-mail-with-original t]
2545         ;;("Draft"
2546         ;;["Send" gnus-summary-send-draft t]
2547         ;;["Send bounced" gnus-resend-bounced-mail t])
2548         ))
2549
2550     (cond
2551      ((not (keymapp gnus-summary-post-menu))
2552       (setq gnus-article-post-menu gnus-summary-post-menu))
2553      ((not gnus-article-post-menu)
2554       ;; Don't share post menu.
2555       (setq gnus-article-post-menu
2556             (copy-keymap gnus-summary-post-menu))))
2557     (define-key gnus-article-mode-map [menu-bar post]
2558       (cons "Post" gnus-article-post-menu))
2559
2560     (easy-menu-define
2561       gnus-summary-misc-menu gnus-summary-mode-map ""
2562       `("Gnus"
2563         ("Mark Read"
2564          ["Mark as read" gnus-summary-mark-as-read-forward t]
2565          ["Mark same subject and select"
2566           gnus-summary-kill-same-subject-and-select t]
2567          ["Mark same subject" gnus-summary-kill-same-subject t]
2568          ["Catchup" gnus-summary-catchup
2569           ,@(if (featurep 'xemacs) '(t)
2570               '(:help "Mark unread articles in this group as read"))]
2571          ["Catchup all" gnus-summary-catchup-all t]
2572          ["Catchup to here" gnus-summary-catchup-to-here t]
2573          ["Catchup from here" gnus-summary-catchup-from-here t]
2574          ["Catchup region" gnus-summary-mark-region-as-read
2575           (gnus-mark-active-p)]
2576          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2577         ("Mark Various"
2578          ["Tick" gnus-summary-tick-article-forward t]
2579          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2580          ["Remove marks" gnus-summary-clear-mark-forward t]
2581          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2582          ["Set bookmark" gnus-summary-set-bookmark t]
2583          ["Remove bookmark" gnus-summary-remove-bookmark t])
2584         ("Limit to"
2585          ["Marks..." gnus-summary-limit-to-marks t]
2586          ["Subject..." gnus-summary-limit-to-subject t]
2587          ["Author..." gnus-summary-limit-to-author t]
2588          ["Recipient..." gnus-summary-limit-to-recipient t]
2589          ["Address..." gnus-summary-limit-to-address t]
2590          ["Age..." gnus-summary-limit-to-age t]
2591          ["Extra..." gnus-summary-limit-to-extra t]
2592          ["Score..." gnus-summary-limit-to-score t]
2593          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2594          ["Unread" gnus-summary-limit-to-unread t]
2595          ["Unseen" gnus-summary-limit-to-unseen t]
2596          ["Singletons" gnus-summary-limit-to-singletons t]
2597          ["Replied" gnus-summary-limit-to-replied t]
2598          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2599          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2600          ["Pop limit" gnus-summary-pop-limit t]
2601          ["Show dormant" gnus-summary-limit-include-dormant t]
2602          ["Hide childless dormant"
2603           gnus-summary-limit-exclude-childless-dormant t]
2604          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2605          ["Hide marked" gnus-summary-limit-exclude-marks t]
2606          ["Show expunged" gnus-summary-limit-include-expunged t])
2607         ("Process Mark"
2608          ["Set mark" gnus-summary-mark-as-processable t]
2609          ["Remove mark" gnus-summary-unmark-as-processable t]
2610          ["Remove all marks" gnus-summary-unmark-all-processable t]
2611          ["Invert marks" gnus-uu-invert-processable t]
2612          ["Mark above" gnus-uu-mark-over t]
2613          ["Mark series" gnus-uu-mark-series t]
2614          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2615          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2616          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2617          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2618          ["Mark all" gnus-uu-mark-all t]
2619          ["Mark buffer" gnus-uu-mark-buffer t]
2620          ["Mark sparse" gnus-uu-mark-sparse t]
2621          ["Mark thread" gnus-uu-mark-thread t]
2622          ["Unmark thread" gnus-uu-unmark-thread t]
2623          ("Process Mark Sets"
2624           ["Kill" gnus-summary-kill-process-mark t]
2625           ["Yank" gnus-summary-yank-process-mark
2626            gnus-newsgroup-process-stack]
2627           ["Save" gnus-summary-save-process-mark t]
2628           ["Run command on marked..." gnus-summary-universal-argument t]))
2629         ("Scroll article"
2630          ["Page forward" gnus-summary-next-page
2631           ,@(if (featurep 'xemacs) '(t)
2632               '(:help "Show next page of article"))]
2633          ["Page backward" gnus-summary-prev-page
2634           ,@(if (featurep 'xemacs) '(t)
2635               '(:help "Show previous page of article"))]
2636          ["Line forward" gnus-summary-scroll-up t])
2637         ("Move"
2638          ["Next unread article" gnus-summary-next-unread-article t]
2639          ["Previous unread article" gnus-summary-prev-unread-article t]
2640          ["Next article" gnus-summary-next-article t]
2641          ["Previous article" gnus-summary-prev-article t]
2642          ["Next unread subject" gnus-summary-next-unread-subject t]
2643          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2644          ["Next article same subject" gnus-summary-next-same-subject t]
2645          ["Previous article same subject" gnus-summary-prev-same-subject t]
2646          ["First unread article" gnus-summary-first-unread-article t]
2647          ["Best unread article" gnus-summary-best-unread-article t]
2648          ["Go to subject number..." gnus-summary-goto-subject t]
2649          ["Go to article number..." gnus-summary-goto-article t]
2650          ["Go to the last article" gnus-summary-goto-last-article t]
2651          ["Pop article off history" gnus-summary-pop-article t])
2652         ("Sort"
2653          ["Sort by number" gnus-summary-sort-by-number t]
2654          ["Sort by author" gnus-summary-sort-by-author t]
2655          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2656          ["Sort by subject" gnus-summary-sort-by-subject t]
2657          ["Sort by date" gnus-summary-sort-by-date t]
2658          ["Sort by score" gnus-summary-sort-by-score t]
2659          ["Sort by lines" gnus-summary-sort-by-lines t]
2660          ["Sort by characters" gnus-summary-sort-by-chars t]
2661          ["Randomize" gnus-summary-sort-by-random t]
2662          ["Original sort" gnus-summary-sort-by-original t])
2663         ("Help"
2664          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2665          ["Describe group" gnus-summary-describe-group t]
2666          ["Fetch charter" gnus-group-fetch-charter
2667           ,@(if (featurep 'xemacs) nil
2668               '(:help "Display the charter of the current group"))]
2669          ["Fetch control message" gnus-group-fetch-control
2670           ,@(if (featurep 'xemacs) nil
2671               '(:help "Display the archived control message for the current group"))]
2672          ["Read manual" gnus-info-find-node t])
2673         ("Modes"
2674          ["Pick and read" gnus-pick-mode t]
2675          ["Binary" gnus-binary-mode t])
2676         ("Regeneration"
2677          ["Regenerate" gnus-summary-prepare t]
2678          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2679          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2680          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2681          ["Toggle threading" gnus-summary-toggle-threads t])
2682         ["See old articles" gnus-summary-insert-old-articles t]
2683         ["See new articles" gnus-summary-insert-new-articles t]
2684         ["Filter articles..." gnus-summary-execute-command t]
2685         ["Run command on articles..." gnus-summary-universal-argument t]
2686         ["Search articles forward..." gnus-summary-search-article-forward t]
2687         ["Search articles backward..." gnus-summary-search-article-backward t]
2688         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2689         ["Expand window" gnus-summary-expand-window t]
2690         ["Expire expirable articles" gnus-summary-expire-articles
2691          (gnus-check-backend-function
2692           'request-expire-articles gnus-newsgroup-name)]
2693         ["Edit local kill file" gnus-summary-edit-local-kill t]
2694         ["Edit main kill file" gnus-summary-edit-global-kill t]
2695         ["Edit group parameters" gnus-summary-edit-parameters t]
2696         ["Customize group parameters" gnus-summary-customize-parameters t]
2697         ["Send a bug report" gnus-bug t]
2698         ("Exit"
2699          ["Catchup and exit" gnus-summary-catchup-and-exit
2700           ,@(if (featurep 'xemacs) '(t)
2701               '(:help "Mark unread articles in this group as read, then exit"))]
2702          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2703          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2704          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2705          ["Exit group" gnus-summary-exit
2706           ,@(if (featurep 'xemacs) '(t)
2707               '(:help "Exit current group, return to group selection mode"))]
2708          ["Exit group without updating" gnus-summary-exit-no-update t]
2709          ["Exit and goto next group" gnus-summary-next-group t]
2710          ["Exit and goto prev group" gnus-summary-prev-group t]
2711          ["Reselect group" gnus-summary-reselect-current-group t]
2712          ["Rescan group" gnus-summary-rescan-group t]
2713          ["Update dribble" gnus-summary-save-newsrc t])))
2714
2715     (gnus-run-hooks 'gnus-summary-menu-hook)))
2716
2717 (defvar gnus-summary-tool-bar-map nil)
2718
2719 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2720 ;; affect _new_ message buffers.  We might add a function that walks thru all
2721 ;; summary-mode buffers and force the update.
2722 (defun gnus-summary-tool-bar-update (&optional symbol value)
2723   "Update summary mode toolbar.
2724 Setter function for custom variables."
2725   (setq-default gnus-summary-tool-bar-map nil)
2726   (when symbol
2727     ;; When used as ":set" function:
2728     (set-default symbol value))
2729   (when (gnus-buffer-live-p gnus-summary-buffer)
2730     (with-current-buffer gnus-summary-buffer
2731       (gnus-summary-make-tool-bar))))
2732
2733 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2734                                      'gnus-summary-tool-bar-gnome
2735                                    'gnus-summary-tool-bar-retro)
2736   "Specifies the Gnus summary tool bar.
2737
2738 It can be either a list or a symbol refering to a list.  See
2739 `gmm-tool-bar-from-list' for the format of the list.  The
2740 default key map is `gnus-summary-mode-map'.
2741
2742 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2743 `gnus-summary-tool-bar-retro'."
2744   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2745                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2746                  (repeat :tag "User defined list" gmm-tool-bar-item)
2747                  (symbol))
2748   :version "23.0" ;; No Gnus
2749   :initialize 'custom-initialize-default
2750   :set 'gnus-summary-tool-bar-update
2751   :group 'gnus-summary)
2752
2753 (defcustom gnus-summary-tool-bar-gnome
2754   '((gnus-summary-post-news "mail/compose" nil)
2755     (gnus-summary-insert-new-articles "mail/inbox" nil
2756                                       :visible (or (not gnus-agent)
2757                                                    gnus-plugged))
2758     (gnus-summary-reply-with-original "mail/reply")
2759     (gnus-summary-reply "mail/reply" nil :visible nil)
2760     (gnus-summary-followup-with-original "mail/reply-all")
2761     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2762     (gnus-summary-mail-forward "mail/forward")
2763     (gnus-summary-save-article "mail/save")
2764     (gnus-summary-search-article-forward "search" nil :visible nil)
2765     (gnus-summary-print-article "print")
2766     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2767     ;; Some new commands that may need more suitable icons:
2768     (gnus-summary-save-newsrc "save" nil :visible nil)
2769     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2770     (gnus-summary-prev-article "left-arrow")
2771     (gnus-summary-next-article "right-arrow")
2772     (gnus-summary-next-page "next-page")
2773     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2774     ;;
2775     ;; Maybe some sort-by-... could be added:
2776     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2777     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2778     (gnus-summary-mark-as-expirable
2779      "delete" nil
2780      :visible (gnus-check-backend-function 'request-expire-articles
2781                                            gnus-newsgroup-name))
2782     (gnus-summary-mark-as-spam
2783      "mail/spam" t
2784      :visible (and (fboundp 'spam-group-ham-contents-p)
2785                    (spam-group-ham-contents-p gnus-newsgroup-name))
2786      :help "Mark as spam")
2787     (gnus-summary-mark-as-read-forward
2788      "mail/not-spam" nil
2789      :visible (and (fboundp 'spam-group-spam-contents-p)
2790                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2791     ;;
2792     (gnus-summary-exit "exit")
2793     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2794     (gnus-info-find-node "help"))
2795   "List of functions for the summary tool bar (GNOME style).
2796
2797 See `gmm-tool-bar-from-list' for the format of the list."
2798   :type '(repeat gmm-tool-bar-item)
2799   :version "23.0" ;; No Gnus
2800   :initialize 'custom-initialize-default
2801   :set 'gnus-summary-tool-bar-update
2802   :group 'gnus-summary)
2803
2804 (defcustom gnus-summary-tool-bar-retro
2805   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2806     (gnus-summary-next-unread-article "gnus/next-ur")
2807     (gnus-summary-post-news "gnus/post")
2808     (gnus-summary-followup-with-original "gnus/fuwo")
2809     (gnus-summary-followup "gnus/followup")
2810     (gnus-summary-reply-with-original "gnus/reply-wo")
2811     (gnus-summary-reply "gnus/reply")
2812     (gnus-summary-caesar-message "gnus/rot13")
2813     (gnus-uu-decode-uu "gnus/uu-decode")
2814     (gnus-summary-save-article-file "gnus/save-aif")
2815     (gnus-summary-save-article "gnus/save-art")
2816     (gnus-uu-post-news "gnus/uu-post")
2817     (gnus-summary-catchup "gnus/catchup")
2818     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2819     (gnus-summary-exit "gnus/exit-summ")
2820     ;; Some new command that may need more suitable icons:
2821     (gnus-summary-print-article "gnus/print" nil :visible nil)
2822     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2823     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2824     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2825     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2826     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2827     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2828     ;;
2829     (gnus-info-find-node "gnus/help" nil :visible nil))
2830   "List of functions for the summary tool bar (retro look).
2831
2832 See `gmm-tool-bar-from-list' for the format of the list."
2833   :type '(repeat gmm-tool-bar-item)
2834   :version "23.0" ;; No Gnus
2835   :initialize 'custom-initialize-default
2836   :set 'gnus-summary-tool-bar-update
2837   :group 'gnus-summary)
2838
2839 (defcustom gnus-summary-tool-bar-zap-list t
2840   "List of icon items from the global tool bar.
2841 These items are not displayed in the Gnus summary mode tool bar.
2842
2843 See `gmm-tool-bar-from-list' for the format of the list."
2844   :type 'gmm-tool-bar-zap-list
2845   :version "23.0" ;; No Gnus
2846   :initialize 'custom-initialize-default
2847   :set 'gnus-summary-tool-bar-update
2848   :group 'gnus-summary)
2849
2850 (defvar image-load-path)
2851
2852 (defun gnus-summary-make-tool-bar (&optional force)
2853   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2854 When FORCE, rebuild the tool bar."
2855   (when (and (not (featurep 'xemacs))
2856              (boundp 'tool-bar-mode)
2857              tool-bar-mode
2858              (or (not gnus-summary-tool-bar-map) force))
2859     (let* ((load-path
2860             (gmm-image-load-path-for-library "gnus"
2861                                              "mail/save.xpm"
2862                                              nil t))
2863            (image-load-path (cons (car load-path)
2864                                   (when (boundp 'image-load-path)
2865                                     image-load-path)))
2866            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2867                                         gnus-summary-tool-bar-zap-list
2868                                         'gnus-summary-mode-map)))
2869       (when map
2870         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2871         ;; uses it's value.
2872         (setq gnus-summary-tool-bar-map map))))
2873   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2874
2875 (defun gnus-score-set-default (var value)
2876   "A version of set that updates the GNU Emacs menu-bar."
2877   (set var value)
2878   ;; It is the message that forces the active status to be updated.
2879   (message ""))
2880
2881 (defun gnus-make-score-map (type)
2882   "Make a summary score map of type TYPE."
2883   (if t
2884       nil
2885     (let ((headers '(("author" "from" string)
2886                      ("subject" "subject" string)
2887                      ("article body" "body" string)
2888                      ("article head" "head" string)
2889                      ("xref" "xref" string)
2890                      ("extra header" "extra" string)
2891                      ("lines" "lines" number)
2892                      ("followups to author" "followup" string)))
2893           (types '((number ("less than" <)
2894                            ("greater than" >)
2895                            ("equal" =))
2896                    (string ("substring" s)
2897                            ("exact string" e)
2898                            ("fuzzy string" f)
2899                            ("regexp" r))))
2900           (perms '(("temporary" (current-time-string))
2901                    ("permanent" nil)
2902                    ("immediate" now)))
2903           header)
2904       (list
2905        (apply
2906         'nconc
2907         (list
2908          (if (eq type 'lower)
2909              "Lower score"
2910            "Increase score"))
2911         (let (outh)
2912           (while headers
2913             (setq header (car headers))
2914             (setq outh
2915                   (cons
2916                    (apply
2917                     'nconc
2918                     (list (car header))
2919                     (let ((ts (cdr (assoc (nth 2 header) types)))
2920                           outt)
2921                       (while ts
2922                         (setq outt
2923                               (cons
2924                                (apply
2925                                 'nconc
2926                                 (list (caar ts))
2927                                 (let ((ps perms)
2928                                       outp)
2929                                   (while ps
2930                                     (setq outp
2931                                           (cons
2932                                            (vector
2933                                             (caar ps)
2934                                             (list
2935                                              'gnus-summary-score-entry
2936                                              (nth 1 header)
2937                                              (if (or (string= (nth 1 header)
2938                                                               "head")
2939                                                      (string= (nth 1 header)
2940                                                               "body"))
2941                                                  ""
2942                                                (list 'gnus-summary-header
2943                                                      (nth 1 header)))
2944                                              (list 'quote (nth 1 (car ts)))
2945                                              (list 'gnus-score-delta-default
2946                                                    nil)
2947                                              (nth 1 (car ps))
2948                                              t)
2949                                             t)
2950                                            outp))
2951                                     (setq ps (cdr ps)))
2952                                   (list (nreverse outp))))
2953                                outt))
2954                         (setq ts (cdr ts)))
2955                       (list (nreverse outt))))
2956                    outh))
2957             (setq headers (cdr headers)))
2958           (list (nreverse outh))))))))
2959
2960 \f
2961
2962 (defun gnus-summary-mode (&optional group)
2963   "Major mode for reading articles.
2964
2965 All normal editing commands are switched off.
2966 \\<gnus-summary-mode-map>
2967 Each line in this buffer represents one article.  To read an
2968 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2969 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2970 respectively.
2971
2972 You can also post articles and send mail from this buffer.  To
2973 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2974 of an article, type `\\[gnus-summary-reply]'.
2975
2976 There are approx. one gazillion commands you can execute in this
2977 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2978
2979 The following commands are available:
2980
2981 \\{gnus-summary-mode-map}"
2982   (interactive)
2983   (kill-all-local-variables)
2984   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2985     (gnus-summary-make-local-variables))
2986   (gnus-summary-make-local-variables)
2987   (setq gnus-newsgroup-name group)
2988   (when (gnus-visual-p 'summary-menu 'menu)
2989     (gnus-summary-make-menu-bar)
2990     (gnus-summary-make-tool-bar))
2991   (gnus-make-thread-indent-array)
2992   (gnus-simplify-mode-line)
2993   (setq major-mode 'gnus-summary-mode)
2994   (setq mode-name "Summary")
2995   (make-local-variable 'minor-mode-alist)
2996   (use-local-map gnus-summary-mode-map)
2997   (buffer-disable-undo)
2998   (setq buffer-read-only t              ;Disable modification
2999         show-trailing-whitespace nil)
3000   (setq truncate-lines t)
3001   (setq selective-display t)
3002   (setq selective-display-ellipses t)   ;Display `...'
3003   (gnus-summary-set-display-table)
3004   (gnus-set-default-directory)
3005   (make-local-variable 'gnus-summary-line-format)
3006   (make-local-variable 'gnus-summary-line-format-spec)
3007   (make-local-variable 'gnus-summary-dummy-line-format)
3008   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3009   (make-local-variable 'gnus-summary-mark-positions)
3010   (gnus-make-local-hook 'pre-command-hook)
3011   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3012   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3013   (turn-on-gnus-mailing-list-mode)
3014   (mm-enable-multibyte)
3015   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3016   (gnus-update-summary-mark-positions))
3017
3018 (defun gnus-summary-make-local-variables ()
3019   "Make all the local summary buffer variables."
3020   (let (global)
3021     (dolist (local gnus-summary-local-variables)
3022       (if (consp local)
3023           (progn
3024             (if (eq (cdr local) 'global)
3025                 ;; Copy the global value of the variable.
3026                 (setq global (symbol-value (car local)))
3027               ;; Use the value from the list.
3028               (setq global (eval (cdr local))))
3029             (set (make-local-variable (car local)) global))
3030         ;; Simple nil-valued local variable.
3031         (set (make-local-variable local) nil)))))
3032
3033 (defun gnus-summary-clear-local-variables ()
3034   (let ((locals gnus-summary-local-variables))
3035     (while locals
3036       (if (consp (car locals))
3037           (and (symbolp (caar locals))
3038                (set (caar locals) nil))
3039         (and (symbolp (car locals))
3040              (set (car locals) nil)))
3041       (setq locals (cdr locals)))))
3042
3043 ;; Summary data functions.
3044
3045 (defmacro gnus-data-number (data)
3046   `(car ,data))
3047
3048 (defmacro gnus-data-set-number (data number)
3049   `(setcar ,data ,number))
3050
3051 (defmacro gnus-data-mark (data)
3052   `(nth 1 ,data))
3053
3054 (defmacro gnus-data-set-mark (data mark)
3055   `(setcar (nthcdr 1 ,data) ,mark))
3056
3057 (defmacro gnus-data-pos (data)
3058   `(nth 2 ,data))
3059
3060 (defmacro gnus-data-set-pos (data pos)
3061   `(setcar (nthcdr 2 ,data) ,pos))
3062
3063 (defmacro gnus-data-header (data)
3064   `(nth 3 ,data))
3065
3066 (defmacro gnus-data-set-header (data header)
3067   `(setf (nth 3 ,data) ,header))
3068
3069 (defmacro gnus-data-level (data)
3070   `(nth 4 ,data))
3071
3072 (defmacro gnus-data-unread-p (data)
3073   `(= (nth 1 ,data) gnus-unread-mark))
3074
3075 (defmacro gnus-data-read-p (data)
3076   `(/= (nth 1 ,data) gnus-unread-mark))
3077
3078 (defmacro gnus-data-pseudo-p (data)
3079   `(consp (nth 3 ,data)))
3080
3081 (defmacro gnus-data-find (number)
3082   `(assq ,number gnus-newsgroup-data))
3083
3084 (defmacro gnus-data-find-list (number &optional data)
3085   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3086      (memq (assq ,number bdata)
3087            bdata)))
3088
3089 (defmacro gnus-data-make (number mark pos header level)
3090   `(list ,number ,mark ,pos ,header ,level))
3091
3092 (defun gnus-data-enter (after-article number mark pos header level offset)
3093   (let ((data (gnus-data-find-list after-article)))
3094     (unless data
3095       (error "No such article: %d" after-article))
3096     (setcdr data (cons (gnus-data-make number mark pos header level)
3097                        (cdr data)))
3098     (setq gnus-newsgroup-data-reverse nil)
3099     (gnus-data-update-list (cddr data) offset)))
3100
3101 (defun gnus-data-enter-list (after-article list &optional offset)
3102   (when list
3103     (let ((data (and after-article (gnus-data-find-list after-article)))
3104           (ilist list))
3105       (if (not (or data
3106                    after-article))
3107           (let ((odata gnus-newsgroup-data))
3108             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3109             (when offset
3110               (gnus-data-update-list odata offset)))
3111         ;; Find the last element in the list to be spliced into the main
3112         ;; list.
3113         (setq list (last list))
3114         (if (not data)
3115             (progn
3116               (setcdr list gnus-newsgroup-data)
3117               (setq gnus-newsgroup-data ilist)
3118               (when offset
3119                 (gnus-data-update-list (cdr list) offset)))
3120           (setcdr list (cdr data))
3121           (setcdr data ilist)
3122           (when offset
3123             (gnus-data-update-list (cdr list) offset))))
3124       (setq gnus-newsgroup-data-reverse nil))))
3125
3126 (defun gnus-data-remove (article &optional offset)
3127   (let ((data gnus-newsgroup-data))
3128     (if (= (gnus-data-number (car data)) article)
3129         (progn
3130           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3131                 gnus-newsgroup-data-reverse nil)
3132           (when offset
3133             (gnus-data-update-list gnus-newsgroup-data offset)))
3134       (while (cdr data)
3135         (when (= (gnus-data-number (cadr data)) article)
3136           (setcdr data (cddr data))
3137           (when offset
3138             (gnus-data-update-list (cdr data) offset))
3139           (setq data nil
3140                 gnus-newsgroup-data-reverse nil))
3141         (setq data (cdr data))))))
3142
3143 (defmacro gnus-data-list (backward)
3144   `(if ,backward
3145        (or gnus-newsgroup-data-reverse
3146            (setq gnus-newsgroup-data-reverse
3147                  (reverse gnus-newsgroup-data)))
3148      gnus-newsgroup-data))
3149
3150 (defun gnus-data-update-list (data offset)
3151   "Add OFFSET to the POS of all data entries in DATA."
3152   (setq gnus-newsgroup-data-reverse nil)
3153   (while data
3154     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3155     (setq data (cdr data))))
3156
3157 (defun gnus-summary-article-pseudo-p (article)
3158   "Say whether this article is a pseudo article or not."
3159   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3160
3161 (defmacro gnus-summary-article-sparse-p (article)
3162   "Say whether this article is a sparse article or not."
3163   `(memq ,article gnus-newsgroup-sparse))
3164
3165 (defmacro gnus-summary-article-ancient-p (article)
3166   "Say whether this article is a sparse article or not."
3167   `(memq ,article gnus-newsgroup-ancient))
3168
3169 (defun gnus-article-parent-p (number)
3170   "Say whether this article is a parent or not."
3171   (let ((data (gnus-data-find-list number)))
3172     (and (cdr data)              ; There has to be an article after...
3173          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3174             (gnus-data-level (nth 1 data))))))
3175
3176 (defun gnus-article-children (number)
3177   "Return a list of all children to NUMBER."
3178   (let* ((data (gnus-data-find-list number))
3179          (level (gnus-data-level (car data)))
3180          children)
3181     (setq data (cdr data))
3182     (while (and data
3183                 (= (gnus-data-level (car data)) (1+ level)))
3184       (push (gnus-data-number (car data)) children)
3185       (setq data (cdr data)))
3186     children))
3187
3188 (defmacro gnus-summary-skip-intangible ()
3189   "If the current article is intangible, then jump to a different article."
3190   '(let ((to (get-text-property (point) 'gnus-intangible)))
3191      (and to (gnus-summary-goto-subject to))))
3192
3193 (defmacro gnus-summary-article-intangible-p ()
3194   "Say whether this article is intangible or not."
3195   '(get-text-property (point) 'gnus-intangible))
3196
3197 (defun gnus-article-read-p (article)
3198   "Say whether ARTICLE is read or not."
3199   (not (or (memq article gnus-newsgroup-marked)
3200            (memq article gnus-newsgroup-spam-marked)
3201            (memq article gnus-newsgroup-unreads)
3202            (memq article gnus-newsgroup-unselected)
3203            (memq article gnus-newsgroup-dormant))))
3204
3205 ;; Some summary mode macros.
3206
3207 (defmacro gnus-summary-article-number ()
3208   "The article number of the article on the current line.
3209 If there isn't an article number here, then we return the current
3210 article number."
3211   '(progn
3212      (gnus-summary-skip-intangible)
3213      (or (get-text-property (point) 'gnus-number)
3214          (gnus-summary-last-subject))))
3215
3216 (defmacro gnus-summary-article-header (&optional number)
3217   "Return the header of article NUMBER."
3218   `(gnus-data-header (gnus-data-find
3219                       ,(or number '(gnus-summary-article-number)))))
3220
3221 (defmacro gnus-summary-thread-level (&optional number)
3222   "Return the level of thread that starts with article NUMBER."
3223   `(if (and (eq gnus-summary-make-false-root 'dummy)
3224             (get-text-property (point) 'gnus-intangible))
3225        0
3226      (gnus-data-level (gnus-data-find
3227                        ,(or number '(gnus-summary-article-number))))))
3228
3229 (defmacro gnus-summary-article-mark (&optional number)
3230   "Return the mark of article NUMBER."
3231   `(gnus-data-mark (gnus-data-find
3232                     ,(or number '(gnus-summary-article-number)))))
3233
3234 (defmacro gnus-summary-article-pos (&optional number)
3235   "Return the position of the line of article NUMBER."
3236   `(gnus-data-pos (gnus-data-find
3237                    ,(or number '(gnus-summary-article-number)))))
3238
3239 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3240 (defmacro gnus-summary-article-subject (&optional number)
3241   "Return current subject string or nil if nothing."
3242   `(let ((headers
3243           ,(if number
3244                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3245              '(gnus-data-header (assq (gnus-summary-article-number)
3246                                       gnus-newsgroup-data)))))
3247      (and headers
3248           (vectorp headers)
3249           (mail-header-subject headers))))
3250
3251 (defmacro gnus-summary-article-score (&optional number)
3252   "Return current article score."
3253   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3254                   gnus-newsgroup-scored))
3255        gnus-summary-default-score 0))
3256
3257 (defun gnus-summary-article-children (&optional number)
3258   "Return a list of article numbers that are children of article NUMBER."
3259   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3260          (level (gnus-data-level (car data)))
3261          l children)
3262     (while (and (setq data (cdr data))
3263                 (> (setq l (gnus-data-level (car data))) level))
3264       (and (= (1+ level) l)
3265            (push (gnus-data-number (car data))
3266                  children)))
3267     (nreverse children)))
3268
3269 (defun gnus-summary-article-parent (&optional number)
3270   "Return the article number of the parent of article NUMBER."
3271   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3272                                     (gnus-data-list t)))
3273          (level (gnus-data-level (car data))))
3274     (if (zerop level)
3275         ()                              ; This is a root.
3276       ;; We search until we find an article with a level less than
3277       ;; this one.  That function has to be the parent.
3278       (while (and (setq data (cdr data))
3279                   (not (< (gnus-data-level (car data)) level))))
3280       (and data (gnus-data-number (car data))))))
3281
3282 (defun gnus-unread-mark-p (mark)
3283   "Say whether MARK is the unread mark."
3284   (= mark gnus-unread-mark))
3285
3286 (defun gnus-read-mark-p (mark)
3287   "Say whether MARK is one of the marks that mark as read.
3288 This is all marks except unread, ticked, dormant, and expirable."
3289   (not (or (= mark gnus-unread-mark)
3290            (= mark gnus-ticked-mark)
3291            (= mark gnus-spam-mark)
3292            (= mark gnus-dormant-mark)
3293            (= mark gnus-expirable-mark))))
3294
3295 (defmacro gnus-article-mark (number)
3296   "Return the MARK of article NUMBER.
3297 This macro should only be used when computing the mark the \"first\"
3298 time; i.e., when generating the summary lines.  After that,
3299 `gnus-summary-article-mark' should be used to examine the
3300 marks of articles."
3301   `(cond
3302     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3303     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3304     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3305     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3306     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3307     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3308     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3309     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3310            gnus-ancient-mark))))
3311
3312 ;; Saving hidden threads.
3313
3314 (defmacro gnus-save-hidden-threads (&rest forms)
3315   "Save hidden threads, eval FORMS, and restore the hidden threads."
3316   (let ((config (make-symbol "config")))
3317     `(let ((,config (gnus-hidden-threads-configuration)))
3318        (unwind-protect
3319            (save-excursion
3320              ,@forms)
3321          (gnus-restore-hidden-threads-configuration ,config)))))
3322 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3323 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3324
3325 (defun gnus-data-compute-positions ()
3326   "Compute the positions of all articles."
3327   (setq gnus-newsgroup-data-reverse nil)
3328   (let ((data gnus-newsgroup-data))
3329     (save-excursion
3330       (gnus-save-hidden-threads
3331         (gnus-summary-show-all-threads)
3332         (goto-char (point-min))
3333         (while data
3334           (while (get-text-property (point) 'gnus-intangible)
3335             (forward-line 1))
3336           (gnus-data-set-pos (car data) (+ (point) 3))
3337           (setq data (cdr data))
3338           (forward-line 1))))))
3339
3340 (defun gnus-hidden-threads-configuration ()
3341   "Return the current hidden threads configuration."
3342   (save-excursion
3343     (let (config)
3344       (goto-char (point-min))
3345       (while (search-forward "\r" nil t)
3346         (push (1- (point)) config))
3347       config)))
3348
3349 (defun gnus-restore-hidden-threads-configuration (config)
3350   "Restore hidden threads configuration from CONFIG."
3351   (save-excursion
3352     (let (point buffer-read-only)
3353       (while (setq point (pop config))
3354         (when (and (< point (point-max))
3355                    (goto-char point)
3356                    (eq (char-after) ?\n))
3357           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3358
3359 ;; Various summary mode internalish functions.
3360
3361 (defun gnus-mouse-pick-article (e)
3362   (interactive "e")
3363   (mouse-set-point e)
3364   (gnus-summary-next-page nil t))
3365
3366 (defun gnus-summary-set-display-table ()
3367   "Change the display table.
3368 Odd characters have a tendency to mess
3369 up nicely formatted displays - we make all possible glyphs
3370 display only a single character."
3371
3372   ;; We start from the standard display table, if any.
3373   (let ((table (or (copy-sequence standard-display-table)
3374                    (make-display-table)))
3375         (i 32))
3376     ;; Nix out all the control chars...
3377     (while (>= (setq i (1- i)) 0)
3378       (aset table i [??]))
3379    ;; ... but not newline and cr, of course.  (cr is necessary for the
3380     ;; selective display).
3381     (aset table ?\n nil)
3382     (aset table ?\r nil)
3383     ;; We keep TAB as well.
3384     (aset table ?\t nil)
3385     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3386     ;; Emacs 23 (unicode), that are not set already.
3387     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3388                  160
3389                256)))
3390       (while (>= (setq i (1- i)) 127)
3391         ;; Only modify if the entry is nil.
3392         (unless (aref table i)
3393           (aset table i [??]))))
3394     (setq buffer-display-table table)))
3395
3396 (defun gnus-summary-set-article-display-arrow (pos)
3397   "Update the overlay arrow to point to line at position POS."
3398   (when (and gnus-summary-display-arrow
3399              (boundp 'overlay-arrow-position)
3400              (boundp 'overlay-arrow-string))
3401     (save-excursion
3402       (goto-char pos)
3403       (beginning-of-line)
3404       (unless overlay-arrow-position
3405         (setq overlay-arrow-position (make-marker)))
3406       (setq overlay-arrow-string "=>"
3407             overlay-arrow-position (set-marker overlay-arrow-position
3408                                                (point)
3409                                                (current-buffer))))))
3410
3411 (defun gnus-summary-setup-buffer (group)
3412   "Initialize summary buffer."
3413   (let ((buffer (gnus-summary-buffer-name group))
3414         (dead-name (concat "*Dead Summary "
3415                            (gnus-group-decoded-name group) "*")))
3416     ;; If a dead summary buffer exists, we kill it.
3417     (when (gnus-buffer-live-p dead-name)
3418       (gnus-kill-buffer dead-name))
3419     (if (get-buffer buffer)
3420         (progn
3421           (set-buffer buffer)
3422           (setq gnus-summary-buffer (current-buffer))
3423           (not gnus-newsgroup-prepared))
3424       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3425       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3426       (gnus-summary-mode group)
3427       (when gnus-carpal
3428         (gnus-carpal-setup-buffer 'summary))
3429       (when (gnus-group-quit-config group)
3430         (set (make-local-variable 'gnus-single-article-buffer) nil))
3431       (make-local-variable 'gnus-article-buffer)
3432       (make-local-variable 'gnus-article-current)
3433       (make-local-variable 'gnus-original-article-buffer)
3434       (setq gnus-newsgroup-name group)
3435       ;; Set any local variables in the group parameters.
3436       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3437       t)))
3438
3439 (defun gnus-set-global-variables ()
3440   "Set the global equivalents of the buffer-local variables.
3441 They are set to the latest values they had.  These reflect the summary
3442 buffer that was in action when the last article was fetched."
3443   (when (eq major-mode 'gnus-summary-mode)
3444     (setq gnus-summary-buffer (current-buffer))
3445     (let ((name gnus-newsgroup-name)
3446           (marked gnus-newsgroup-marked)
3447           (spam gnus-newsgroup-spam-marked)
3448           (unread gnus-newsgroup-unreads)
3449           (headers gnus-current-headers)
3450           (data gnus-newsgroup-data)
3451           (summary gnus-summary-buffer)
3452           (article-buffer gnus-article-buffer)
3453           (original gnus-original-article-buffer)
3454           (gac gnus-article-current)
3455           (reffed gnus-reffed-article-number)
3456           (score-file gnus-current-score-file)
3457           (default-charset gnus-newsgroup-charset)
3458           vlist)
3459       (let ((locals gnus-newsgroup-variables))
3460         (while locals
3461           (if (consp (car locals))
3462               (push (eval (caar locals)) vlist)
3463             (push (eval (car locals)) vlist))
3464           (setq locals (cdr locals)))
3465         (setq vlist (nreverse vlist)))
3466       (with-current-buffer gnus-group-buffer
3467         (setq gnus-newsgroup-name name
3468               gnus-newsgroup-marked marked
3469               gnus-newsgroup-spam-marked spam
3470               gnus-newsgroup-unreads unread
3471               gnus-current-headers headers
3472               gnus-newsgroup-data data
3473               gnus-article-current gac
3474               gnus-summary-buffer summary
3475               gnus-article-buffer article-buffer
3476               gnus-original-article-buffer original
3477               gnus-reffed-article-number reffed
3478               gnus-current-score-file score-file
3479               gnus-newsgroup-charset default-charset)
3480         (let ((locals gnus-newsgroup-variables))
3481           (while locals
3482             (if (consp (car locals))
3483                 (set (caar locals) (pop vlist))
3484               (set (car locals) (pop vlist)))
3485             (setq locals (cdr locals))))
3486         ;; The article buffer also has local variables.
3487         (when (gnus-buffer-live-p gnus-article-buffer)
3488           (set-buffer gnus-article-buffer)
3489           (setq gnus-summary-buffer summary))))))
3490
3491 (defun gnus-summary-article-unread-p (article)
3492   "Say whether ARTICLE is unread or not."
3493   (memq article gnus-newsgroup-unreads))
3494
3495 (defun gnus-summary-first-article-p (&optional article)
3496   "Return whether ARTICLE is the first article in the buffer."
3497   (if (not (setq article (or article (gnus-summary-article-number))))
3498       nil
3499     (eq article (caar gnus-newsgroup-data))))
3500
3501 (defun gnus-summary-last-article-p (&optional article)
3502   "Return whether ARTICLE is the last article in the buffer."
3503   (if (not (setq article (or article (gnus-summary-article-number))))
3504       ;; All non-existent numbers are the last article.  :-)
3505       t
3506     (not (cdr (gnus-data-find-list article)))))
3507
3508 (defun gnus-make-thread-indent-array (&optional n)
3509   (when (or n
3510             (progn (setq n 200) nil)
3511             (null gnus-thread-indent-array)
3512             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3513     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3514           gnus-thread-indent-array-level gnus-thread-indent-level)
3515     (while (>= n 0)
3516       (aset gnus-thread-indent-array n
3517             (make-string (* n gnus-thread-indent-level) ? ))
3518       (setq n (1- n)))))
3519
3520 (defun gnus-update-summary-mark-positions ()
3521   "Compute where the summary marks are to go."
3522   (save-excursion
3523     (when (gnus-buffer-exists-p gnus-summary-buffer)
3524       (set-buffer gnus-summary-buffer))
3525     (let ((spec gnus-summary-line-format-spec)
3526           pos)
3527       (save-excursion
3528         (gnus-set-work-buffer)
3529         (let ((gnus-tmp-unread ?Z)
3530               (gnus-replied-mark ?Z)
3531               (gnus-score-below-mark ?Z)
3532               (gnus-score-over-mark ?Z)
3533               (gnus-undownloaded-mark ?Z)
3534               (gnus-summary-line-format-spec spec)
3535               (gnus-newsgroup-downloadable '(0))
3536               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3537               case-fold-search ignores)
3538           ;; Here, all marks are bound to Z.
3539           (gnus-summary-insert-line header
3540                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3541           (goto-char (point-min))
3542           ;; Memorize the positions of the same characters as dummy marks.
3543           (while (re-search-forward "[A-D]" nil t)
3544             (push (point) ignores))
3545           (erase-buffer)
3546           ;; We use A-D as dummy marks in order to know column positions
3547           ;; where marks should be inserted.
3548           (setq gnus-tmp-unread ?A
3549                 gnus-replied-mark ?B
3550                 gnus-score-below-mark ?C
3551                 gnus-score-over-mark ?C
3552                 gnus-undownloaded-mark ?D)
3553           (gnus-summary-insert-line header
3554                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3555           ;; Ignore characters which aren't dummy marks.
3556           (dolist (p ignores)
3557             (delete-region (goto-char (1- p)) p)
3558             (insert ?Z))
3559           (goto-char (point-min))
3560           (setq pos (list (cons 'unread
3561                                 (and (search-forward "A" nil t)
3562                                      (- (point) (point-min) 1)))))
3563           (goto-char (point-min))
3564           (push (cons 'replied (and (search-forward "B" nil t)
3565                                     (- (point) (point-min) 1)))
3566                 pos)
3567           (goto-char (point-min))
3568           (push (cons 'score (and (search-forward "C" nil t)
3569                                   (- (point) (point-min) 1)))
3570                 pos)
3571           (goto-char (point-min))
3572           (push (cons 'download (and (search-forward "D" nil t)
3573                                      (- (point) (point-min) 1)))
3574                 pos)))
3575       (setq gnus-summary-mark-positions pos))))
3576
3577 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3578   "Insert a dummy root in the summary buffer."
3579   (beginning-of-line)
3580   (gnus-add-text-properties
3581    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3582    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3583
3584 (defun gnus-summary-extract-address-component (from)
3585   (or (car (funcall gnus-extract-address-components from))
3586       from))
3587
3588 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3589   (let ((mail-parse-charset gnus-newsgroup-charset)
3590         (ignored-from-addresses (gnus-ignored-from-addresses))
3591         ; Is it really necessary to do this next part for each summary line?
3592         ; Luckily, doesn't seem to slow things down much.
3593         (mail-parse-ignored-charsets
3594          (with-current-buffer gnus-summary-buffer
3595            gnus-newsgroup-ignored-charsets)))
3596     (or
3597      (and ignored-from-addresses
3598           (string-match ignored-from-addresses gnus-tmp-from)
3599           (let ((extra-headers (mail-header-extra header))
3600                 to
3601                 newsgroups)
3602             (cond
3603              ((setq to (cdr (assq 'To extra-headers)))
3604               (concat gnus-summary-to-prefix
3605                       (inline
3606                         (gnus-summary-extract-address-component
3607                          (funcall gnus-decode-encoded-address-function to)))))
3608              ((setq newsgroups
3609                     (or
3610                      (cdr (assq 'Newsgroups extra-headers))
3611                      (and
3612                       (memq 'Newsgroups gnus-extra-headers)
3613                       (eq (car (gnus-find-method-for-group
3614                                 gnus-newsgroup-name)) 'nntp)
3615                       (gnus-group-real-name gnus-newsgroup-name))))
3616               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3617      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3618
3619 (defun gnus-summary-insert-line (gnus-tmp-header
3620                                  gnus-tmp-level gnus-tmp-current
3621                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3622                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3623                                  &optional gnus-tmp-dummy gnus-tmp-score
3624                                  gnus-tmp-process)
3625   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3626       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3627                                           gnus-tmp-level)))
3628   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3629          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3630          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3631          (gnus-tmp-score-char
3632           (if (or (null gnus-summary-default-score)
3633                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3634                       gnus-summary-zcore-fuzz))
3635               ?                         ;Whitespace
3636             (if (< gnus-tmp-score gnus-summary-default-score)
3637                 gnus-score-below-mark gnus-score-over-mark)))
3638          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3639          (gnus-tmp-replied
3640           (cond (gnus-tmp-process gnus-process-mark)
3641                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3642                  gnus-cached-mark)
3643                 (gnus-tmp-replied gnus-replied-mark)
3644                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3645                  gnus-forwarded-mark)
3646                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3647                  gnus-saved-mark)
3648                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3649                  gnus-recent-mark)
3650                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3651                  gnus-unseen-mark)
3652                 (t gnus-no-mark)))
3653          (gnus-tmp-downloaded
3654           (cond (undownloaded
3655                  gnus-undownloaded-mark)
3656                 (gnus-newsgroup-agentized
3657                  gnus-downloaded-mark)
3658                 (t
3659                  gnus-no-mark)))
3660          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3661          (gnus-tmp-name
3662           (cond
3663            ((string-match "<[^>]+> *$" gnus-tmp-from)
3664             (let ((beg (match-beginning 0)))
3665               (or (and (string-match "^\".+\"" gnus-tmp-from)
3666                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3667                   (substring gnus-tmp-from 0 beg))))
3668            ((string-match "(.+)" gnus-tmp-from)
3669             (substring gnus-tmp-from
3670                        (1+ (match-beginning 0)) (1- (match-end 0))))
3671            (t gnus-tmp-from)))
3672          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3673          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3674          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3675          (buffer-read-only nil))
3676     (when (string= gnus-tmp-name "")
3677       (setq gnus-tmp-name gnus-tmp-from))
3678     (unless (numberp gnus-tmp-lines)
3679       (setq gnus-tmp-lines -1))
3680     (if (= gnus-tmp-lines -1)
3681         (setq gnus-tmp-lines "?")
3682       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3683       (gnus-put-text-property
3684      (point)
3685      (progn (eval gnus-summary-line-format-spec) (point))
3686        'gnus-number gnus-tmp-number)
3687     (when (gnus-visual-p 'summary-highlight 'highlight)
3688       (forward-line -1)
3689       (gnus-run-hooks 'gnus-summary-update-hook)
3690       (forward-line 1))))
3691
3692 (defun gnus-summary-update-line (&optional dont-update)
3693   "Update summary line after change."
3694   (when (and gnus-summary-default-score
3695              (not gnus-summary-inhibit-highlight))
3696     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3697            (article (gnus-summary-article-number))
3698            (score (gnus-summary-article-score article)))
3699       (unless dont-update
3700         (if (and gnus-summary-mark-below
3701                  (< (gnus-summary-article-score)
3702                     gnus-summary-mark-below))
3703             ;; This article has a low score, so we mark it as read.
3704             (when (memq article gnus-newsgroup-unreads)
3705               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3706           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3707             ;; This article was previously marked as read on account
3708             ;; of a low score, but now it has risen, so we mark it as
3709             ;; unread.
3710             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3711         (gnus-summary-update-mark
3712          (if (or (null gnus-summary-default-score)
3713                  (<= (abs (- score gnus-summary-default-score))
3714                      gnus-summary-zcore-fuzz))
3715              ?                          ;Whitespace
3716            (if (< score gnus-summary-default-score)
3717                gnus-score-below-mark gnus-score-over-mark))
3718          'score))
3719       ;; Do visual highlighting.
3720       (when (gnus-visual-p 'summary-highlight 'highlight)
3721         (gnus-run-hooks 'gnus-summary-update-hook)))))
3722
3723 (defvar gnus-tmp-new-adopts nil)
3724
3725 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3726   "Return the number of articles in THREAD.
3727 This may be 0 in some cases -- if none of the articles in
3728 the thread are to be displayed."
3729   (let* ((number
3730          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3731           (cond
3732            ((not (listp thread))
3733             1)
3734            ((and (consp thread) (cdr thread))
3735             (apply
3736              '+ 1 (mapcar
3737                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3738            ((null thread)
3739             1)
3740            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3741             1)
3742            (t 0))))
3743     (when (and level (zerop level) gnus-tmp-new-adopts)
3744       (incf number
3745             (apply '+ (mapcar
3746                        'gnus-summary-number-of-articles-in-thread
3747                        gnus-tmp-new-adopts))))
3748     (if char
3749         (if (> number 1) gnus-not-empty-thread-mark
3750           gnus-empty-thread-mark)
3751       number)))
3752
3753 (defsubst gnus-summary-line-message-size (head)
3754   "Return pretty-printed version of message size.
3755 This function is intended to be used in
3756 `gnus-summary-line-format-alist'."
3757   (let ((c (or (mail-header-chars head) -1)))
3758     (cond ((< c 0) "n/a")               ; chars not available
3759           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3760           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3761           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3762           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3763
3764
3765 (defun gnus-summary-set-local-parameters (group)
3766   "Go through the local params of GROUP and set all variable specs in that list."
3767   (let ((vars '(quit-config)))          ; Ignore quit-config.
3768     (dolist (elem (gnus-group-find-parameter group))
3769       (and (consp elem)                 ; Has to be a cons.
3770            (consp (cdr elem))           ; The cdr has to be a list.
3771            (symbolp (car elem))         ; Has to be a symbol in there.
3772            (not (memq (car elem) vars))
3773            (ignore-errors               ; So we set it.
3774              (push (car elem) vars)
3775              (make-local-variable (car elem))
3776              (set (car elem) (eval (nth 1 elem))))))))
3777
3778 (defun gnus-summary-read-group (group &optional show-all no-article
3779                                       kill-buffer no-display backward
3780                                       select-articles)
3781   "Start reading news in newsgroup GROUP.
3782 If SHOW-ALL is non-nil, already read articles are also listed.
3783 If NO-ARTICLE is non-nil, no article is selected initially.
3784 If NO-DISPLAY, don't generate a summary buffer."
3785   (let (result)
3786     (while (and group
3787                 (null (setq result
3788                             (let ((gnus-auto-select-next nil))
3789                               (or (gnus-summary-read-group-1
3790                                    group show-all no-article
3791                                    kill-buffer no-display
3792                                    select-articles)
3793                                   (setq show-all nil
3794                                         select-articles nil)))))
3795                 (eq gnus-auto-select-next 'quietly))
3796       (set-buffer gnus-group-buffer)
3797       ;; The entry function called above goes to the next
3798       ;; group automatically, so we go two groups back
3799       ;; if we are searching for the previous group.
3800       (when backward
3801         (gnus-group-prev-unread-group 2))
3802       (if (not (equal group (gnus-group-group-name)))
3803           (setq group (gnus-group-group-name))
3804         (setq group nil)))
3805     result))
3806
3807 (defun gnus-summary-read-group-1 (group show-all no-article
3808                                         kill-buffer no-display
3809                                         &optional select-articles)
3810   ;; Killed foreign groups can't be entered.
3811   ;;  (when (and (not (gnus-group-native-p group))
3812   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3813   ;;    (error "Dead non-native groups can't be entered"))
3814   (gnus-message 5 "Retrieving newsgroup: %s..."
3815                 (gnus-group-decoded-name group))
3816   (let* ((new-group (gnus-summary-setup-buffer group))
3817          (quit-config (gnus-group-quit-config group))
3818          (did-select (and new-group (gnus-select-newsgroup
3819                                      group show-all select-articles))))
3820     (cond
3821      ;; This summary buffer exists already, so we just select it.
3822      ((not new-group)
3823       (gnus-set-global-variables)
3824       (when kill-buffer
3825         (gnus-kill-or-deaden-summary kill-buffer))
3826       (gnus-configure-windows 'summary 'force)
3827       (gnus-set-mode-line 'summary)
3828       (gnus-summary-position-point)
3829       (message "")
3830       t)
3831      ;; We couldn't select this group.
3832      ((null did-select)
3833       (when (and (eq major-mode 'gnus-summary-mode)
3834                  (not (equal (current-buffer) kill-buffer)))
3835         (kill-buffer (current-buffer))
3836         (if (not quit-config)
3837             (progn
3838               ;; Update the info -- marks might need to be removed,
3839               ;; for instance.
3840               (gnus-summary-update-info)
3841               (set-buffer gnus-group-buffer)
3842               (gnus-group-jump-to-group group)
3843               (gnus-group-next-unread-group 1))
3844           (gnus-handle-ephemeral-exit quit-config)))
3845       (let ((grpinfo (gnus-get-info group)))
3846         (if (null (gnus-info-read grpinfo))
3847             (gnus-message 3 "Group %s contains no messages"
3848                           (gnus-group-decoded-name group))
3849           (gnus-message 3 "Can't select group")))
3850       nil)
3851      ;; The user did a `C-g' while prompting for number of articles,
3852      ;; so we exit this group.
3853      ((eq did-select 'quit)
3854       (and (eq major-mode 'gnus-summary-mode)
3855            (not (equal (current-buffer) kill-buffer))
3856            (kill-buffer (current-buffer)))
3857       (when kill-buffer
3858         (gnus-kill-or-deaden-summary kill-buffer))
3859       (if (not quit-config)
3860           (progn
3861             (set-buffer gnus-group-buffer)
3862             (gnus-group-jump-to-group group)
3863             (gnus-group-next-unread-group 1)
3864             (gnus-configure-windows 'group 'force))
3865         (gnus-handle-ephemeral-exit quit-config))
3866       ;; Finally signal the quit.
3867       (signal 'quit nil))
3868      ;; The group was successfully selected.
3869      (t
3870       (gnus-set-global-variables)
3871       ;; Save the active value in effect when the group was entered.
3872       (setq gnus-newsgroup-active
3873             (gnus-copy-sequence
3874              (gnus-active gnus-newsgroup-name)))
3875       ;; You can change the summary buffer in some way with this hook.
3876       (gnus-run-hooks 'gnus-select-group-hook)
3877       (when (memq 'summary (gnus-update-format-specifications
3878                             nil 'summary 'summary-mode 'summary-dummy))
3879         ;; The format specification for the summary line was updated,
3880         ;; so we need to update the mark positions as well.
3881         (gnus-update-summary-mark-positions))
3882       ;; Do score processing.
3883       (when gnus-use-scoring
3884         (gnus-possibly-score-headers))
3885       ;; Check whether to fill in the gaps in the threads.
3886       (when gnus-build-sparse-threads
3887         (gnus-build-sparse-threads))
3888       ;; Find the initial limit.
3889       (if show-all
3890           (let ((gnus-newsgroup-dormant nil))
3891             (gnus-summary-initial-limit show-all))
3892         (gnus-summary-initial-limit show-all))
3893       ;; Generate the summary buffer.
3894       (unless no-display
3895         (gnus-summary-prepare))
3896       (when gnus-use-trees
3897         (gnus-tree-open group)
3898         (setq gnus-summary-highlight-line-function
3899               'gnus-tree-highlight-article))
3900       ;; If the summary buffer is empty, but there are some low-scored
3901       ;; articles or some excluded dormants, we include these in the
3902       ;; buffer.
3903       (when (and (zerop (buffer-size))
3904                  (not no-display))
3905         (cond (gnus-newsgroup-dormant
3906                (gnus-summary-limit-include-dormant))
3907               ((and gnus-newsgroup-scored show-all)
3908                (gnus-summary-limit-include-expunged t))))
3909       ;; Function `gnus-apply-kill-file' must be called in this hook.
3910       (gnus-run-hooks 'gnus-apply-kill-hook)
3911       (if (and (zerop (buffer-size))
3912                (not no-display))
3913           (progn
3914             ;; This newsgroup is empty.
3915             (gnus-summary-catchup-and-exit nil t)
3916             (gnus-message 6 "No unread news")
3917             (when kill-buffer
3918               (gnus-kill-or-deaden-summary kill-buffer))
3919             ;; Return nil from this function.
3920             nil)
3921         ;; Hide conversation thread subtrees.  We cannot do this in
3922         ;; gnus-summary-prepare-hook since kill processing may not
3923         ;; work with hidden articles.
3924         (gnus-summary-maybe-hide-threads)
3925         (when kill-buffer
3926           (gnus-kill-or-deaden-summary kill-buffer))
3927         (gnus-summary-auto-select-subject)
3928         ;; Show first unread article if requested.
3929         (if (and (not no-article)
3930                  (not no-display)
3931                  gnus-newsgroup-unreads
3932                  gnus-auto-select-first)
3933             (progn
3934               (gnus-configure-windows 'summary)
3935               (let ((art (gnus-summary-article-number)))
3936                 (unless (and (not gnus-plugged)
3937                              (or (memq art gnus-newsgroup-undownloaded)
3938                                  (memq art gnus-newsgroup-downloadable)))
3939                   (gnus-summary-goto-article art))))
3940           ;; Don't select any articles.
3941           (gnus-summary-position-point)
3942           (gnus-configure-windows 'summary 'force)
3943           (gnus-set-mode-line 'summary))
3944         (when (and gnus-auto-center-group
3945                    (get-buffer-window gnus-group-buffer t))
3946           ;; Gotta use windows, because recenter does weird stuff if
3947           ;; the current buffer ain't the displayed window.
3948           (let ((owin (selected-window)))
3949             (select-window (get-buffer-window gnus-group-buffer t))
3950             (when (gnus-group-goto-group group)
3951               (recenter))
3952             (select-window owin)))
3953         ;; Mark this buffer as "prepared".
3954         (setq gnus-newsgroup-prepared t)
3955         (gnus-run-hooks 'gnus-summary-prepared-hook)
3956         (unless (gnus-ephemeral-group-p group)
3957           (gnus-group-update-group group))
3958         t)))))
3959
3960 (defun gnus-summary-auto-select-subject ()
3961   "Select the subject line on initial group entry."
3962   (goto-char (point-min))
3963   (cond
3964    ((eq gnus-auto-select-subject 'best)
3965     (gnus-summary-best-unread-subject))
3966    ((eq gnus-auto-select-subject 'unread)
3967     (gnus-summary-first-unread-subject))
3968    ((eq gnus-auto-select-subject 'unseen)
3969     (gnus-summary-first-unseen-subject))
3970    ((eq gnus-auto-select-subject 'unseen-or-unread)
3971     (gnus-summary-first-unseen-or-unread-subject))
3972    ((eq gnus-auto-select-subject 'first)
3973     ;; Do nothing.
3974     )
3975    ((functionp gnus-auto-select-subject)
3976     (funcall gnus-auto-select-subject))))
3977
3978 (defun gnus-summary-prepare ()
3979   "Generate the summary buffer."
3980   (interactive)
3981   (let ((buffer-read-only nil))
3982     (erase-buffer)
3983     (setq gnus-newsgroup-data nil
3984           gnus-newsgroup-data-reverse nil)
3985     (gnus-run-hooks 'gnus-summary-generate-hook)
3986     ;; Generate the buffer, either with threads or without.
3987     (when gnus-newsgroup-headers
3988       (gnus-summary-prepare-threads
3989        (if gnus-show-threads
3990            (gnus-sort-gathered-threads
3991             (funcall gnus-summary-thread-gathering-function
3992                      (gnus-sort-threads
3993                       (gnus-cut-threads (gnus-make-threads)))))
3994          ;; Unthreaded display.
3995          (gnus-sort-articles gnus-newsgroup-headers))))
3996     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3997     ;; Call hooks for modifying summary buffer.
3998     (goto-char (point-min))
3999     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4000
4001 (defsubst gnus-general-simplify-subject (subject)
4002   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4003   (setq subject
4004         (cond
4005          ;; Truncate the subject.
4006          (gnus-simplify-subject-functions
4007           (gnus-map-function gnus-simplify-subject-functions subject))
4008          ((numberp gnus-summary-gather-subject-limit)
4009           (setq subject (gnus-simplify-subject-re subject))
4010           (if (> (length subject) gnus-summary-gather-subject-limit)
4011               (substring subject 0 gnus-summary-gather-subject-limit)
4012             subject))
4013          ;; Fuzzily simplify it.
4014          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4015           (gnus-simplify-subject-fuzzy subject))
4016          ;; Just remove the leading "Re:".
4017          (t
4018           (gnus-simplify-subject-re subject))))
4019
4020   (if (and gnus-summary-gather-exclude-subject
4021            (string-match gnus-summary-gather-exclude-subject subject))
4022       nil                         ; This article shouldn't be gathered
4023     subject))
4024
4025 (defun gnus-summary-simplify-subject-query ()
4026   "Query where the respool algorithm would put this article."
4027   (interactive)
4028   (gnus-summary-select-article)
4029   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4030
4031 (defun gnus-gather-threads-by-subject (threads)
4032   "Gather threads by looking at Subject headers."
4033   (if (not gnus-summary-make-false-root)
4034       threads
4035     (let ((hashtb (gnus-make-hashtable 1024))
4036           (prev threads)
4037           (result threads)
4038           subject hthread whole-subject)
4039       (while threads
4040         (setq subject (gnus-general-simplify-subject
4041                        (setq whole-subject (mail-header-subject
4042                                             (caar threads)))))
4043         (when subject
4044           (if (setq hthread (gnus-gethash subject hashtb))
4045               (progn
4046                 ;; We enter a dummy root into the thread, if we
4047                 ;; haven't done that already.
4048                 (unless (stringp (caar hthread))
4049                   (setcar hthread (list whole-subject (car hthread))))
4050                 ;; We add this new gathered thread to this gathered
4051                 ;; thread.
4052                 (setcdr (car hthread)
4053                         (nconc (cdar hthread) (list (car threads))))
4054                 ;; Remove it from the list of threads.
4055                 (setcdr prev (cdr threads))
4056                 (setq threads prev))
4057             ;; Enter this thread into the hash table.
4058             (gnus-sethash subject
4059                           (if gnus-summary-make-false-root-always
4060                               (progn
4061                                 ;; If you want a dummy root above all
4062                                 ;; threads...
4063                                 (setcar threads (list whole-subject
4064                                                       (car threads)))
4065                                 threads)
4066                             threads)
4067                           hashtb)))
4068         (setq prev threads)
4069         (setq threads (cdr threads)))
4070       result)))
4071
4072 (defun gnus-gather-threads-by-references (threads)
4073   "Gather threads by looking at References headers."
4074   (let ((idhashtb (gnus-make-hashtable 1024))
4075         (thhashtb (gnus-make-hashtable 1024))
4076         (prev threads)
4077         (result threads)
4078         ids references id gthread gid entered ref)
4079     (while threads
4080       (when (setq references (mail-header-references (caar threads)))
4081         (setq id (mail-header-id (caar threads))
4082               ids (inline (gnus-split-references references))
4083               entered nil)
4084         (while (setq ref (pop ids))
4085           (setq ids (delete ref ids))
4086           (if (not (setq gid (gnus-gethash ref idhashtb)))
4087               (progn
4088                 (gnus-sethash ref id idhashtb)
4089                 (gnus-sethash id threads thhashtb))
4090             (setq gthread (gnus-gethash gid thhashtb))
4091             (unless entered
4092               ;; We enter a dummy root into the thread, if we
4093               ;; haven't done that already.
4094               (unless (stringp (caar gthread))
4095                 (setcar gthread (list (mail-header-subject (caar gthread))
4096                                       (car gthread))))
4097               ;; We add this new gathered thread to this gathered
4098               ;; thread.
4099               (setcdr (car gthread)
4100                       (nconc (cdar gthread) (list (car threads)))))
4101             ;; Add it into the thread hash table.
4102             (gnus-sethash id gthread thhashtb)
4103             (setq entered t)
4104             ;; Remove it from the list of threads.
4105             (setcdr prev (cdr threads))
4106             (setq threads prev))))
4107       (setq prev threads)
4108       (setq threads (cdr threads)))
4109     result))
4110
4111 (defun gnus-sort-gathered-threads (threads)
4112   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4113   (let ((result threads))
4114     (while threads
4115       (when (stringp (caar threads))
4116         (setcdr (car threads)
4117                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4118       (setq threads (cdr threads)))
4119     result))
4120
4121 (defun gnus-thread-loop-p (root thread)
4122   "Say whether ROOT is in THREAD."
4123   (let ((stack (list thread))
4124         (infloop 0)
4125         th)
4126     (while (setq thread (pop stack))
4127       (setq th (cdr thread))
4128       (while (and th
4129                   (not (eq (caar th) root)))
4130         (pop th))
4131       (if th
4132           ;; We have found a loop.
4133           (let (ref-dep)
4134             (setcdr thread (delq (car th) (cdr thread)))
4135             (if (boundp (setq ref-dep (intern "none"
4136                                               gnus-newsgroup-dependencies)))
4137                 (setcdr (symbol-value ref-dep)
4138                         (nconc (cdr (symbol-value ref-dep))
4139                                (list (car th))))
4140               (set ref-dep (list nil (car th))))
4141             (setq infloop 1
4142                   stack nil))
4143         ;; Push all the subthreads onto the stack.
4144         (push (cdr thread) stack)))
4145     infloop))
4146
4147 (defun gnus-make-threads ()
4148   "Go through the dependency hashtb and find the roots.  Return all threads."
4149   (let (threads)
4150     (while (catch 'infloop
4151              (mapatoms
4152               (lambda (refs)
4153                 ;; Deal with self-referencing References loops.
4154                 (when (and (car (symbol-value refs))
4155                            (not (zerop
4156                                  (apply
4157                                   '+
4158                                   (mapcar
4159                                    (lambda (thread)
4160                                      (gnus-thread-loop-p
4161                                       (car (symbol-value refs)) thread))
4162                                    (cdr (symbol-value refs)))))))
4163                   (setq threads nil)
4164                   (throw 'infloop t))
4165                 (unless (car (symbol-value refs))
4166                   ;; These threads do not refer back to any other
4167                   ;; articles, so they're roots.
4168                   (setq threads (append (cdr (symbol-value refs)) threads))))
4169               gnus-newsgroup-dependencies)))
4170     threads))
4171
4172 ;; Build the thread tree.
4173 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4174   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4175
4176 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4177 if it was already present.
4178
4179 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4180 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4181 Message-IDs will be renamed to a unique Message-ID before being
4182 entered.
4183
4184 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4185   (let* ((id (mail-header-id header))
4186          (id-dep (and id (intern id dependencies)))
4187          parent-id ref ref-dep ref-header replaced)
4188     ;; Enter this `header' in the `dependencies' table.
4189     (cond
4190      ((not id-dep)
4191       (setq header nil))
4192      ;; The first two cases do the normal part: enter a new `header'
4193      ;; in the `dependencies' table.
4194      ((not (boundp id-dep))
4195       (set id-dep (list header)))
4196      ((null (car (symbol-value id-dep)))
4197       (setcar (symbol-value id-dep) header))
4198
4199      ;; From here the `header' was already present in the
4200      ;; `dependencies' table.
4201      (force-new
4202       ;; Overrides an existing entry;
4203       ;; just set the header part of the entry.
4204       (setcar (symbol-value id-dep) header)
4205       (setq replaced t))
4206
4207      ;; Renames the existing `header' to a unique Message-ID.
4208      ((not gnus-summary-ignore-duplicates)
4209       ;; An article with this Message-ID has already been seen.
4210       ;; We rename the Message-ID.
4211       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4212            (list header))
4213       (mail-header-set-id header id))
4214
4215      ;; The last case ignores an existing entry, except it adds any
4216      ;; additional Xrefs (in case the two articles came from different
4217      ;; servers.
4218      ;; Also sets `header' to `nil' meaning that the `dependencies'
4219      ;; table was *not* modified.
4220      (t
4221       (mail-header-set-xref
4222        (car (symbol-value id-dep))
4223        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4224                    "")
4225                (or (mail-header-xref header) "")))
4226       (setq header nil)))
4227
4228     (when (and header (not replaced))
4229       ;; First check that we are not creating a References loop.
4230       (setq parent-id (gnus-parent-id (mail-header-references header)))
4231       (setq ref parent-id)
4232       (while (and ref
4233                   (setq ref-dep (intern-soft ref dependencies))
4234                   (boundp ref-dep)
4235                   (setq ref-header (car (symbol-value ref-dep))))
4236         (if (string= id ref)
4237             ;; Yuk!  This is a reference loop.  Make the article be a
4238             ;; root article.
4239             (progn
4240               (mail-header-set-references (car (symbol-value id-dep)) "none")
4241               (setq ref nil)
4242               (setq parent-id nil))
4243           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4244       (setq ref-dep (intern (or parent-id "none") dependencies))
4245       (if (boundp ref-dep)
4246           (setcdr (symbol-value ref-dep)
4247                   (nconc (cdr (symbol-value ref-dep))
4248                          (list (symbol-value id-dep))))
4249         (set ref-dep (list nil (symbol-value id-dep)))))
4250     header))
4251
4252 (defun gnus-extract-message-id-from-in-reply-to (string)
4253   (if (string-match "<[^>]+>" string)
4254       (substring string (match-beginning 0) (match-end 0))
4255     nil))
4256
4257 (defun gnus-build-sparse-threads ()
4258   (let ((headers gnus-newsgroup-headers)
4259         (mail-parse-charset gnus-newsgroup-charset)
4260         (gnus-summary-ignore-duplicates t)
4261         header references generation relations
4262         subject child end new-child date)
4263     ;; First we create an alist of generations/relations, where
4264     ;; generations is how much we trust the relation, and the relation
4265     ;; is parent/child.
4266     (gnus-message 7 "Making sparse threads...")
4267     (save-excursion
4268       (nnheader-set-temp-buffer " *gnus sparse threads*")
4269       (while (setq header (pop headers))
4270         (when (and (setq references (mail-header-references header))
4271                    (not (string= references "")))
4272           (insert references)
4273           (setq child (mail-header-id header)
4274                 subject (mail-header-subject header)
4275                 date (mail-header-date header)
4276                 generation 0)
4277           (while (search-backward ">" nil t)
4278             (setq end (1+ (point)))
4279             (when (search-backward "<" nil t)
4280               (setq new-child (buffer-substring (point) end))
4281               (push (list (incf generation)
4282                           child (setq child new-child)
4283                           subject date)
4284                     relations)))
4285           (when child
4286             (push (list (1+ generation) child nil subject) relations))
4287           (erase-buffer)))
4288       (kill-buffer (current-buffer)))
4289     ;; Sort over trustworthiness.
4290     (mapcar
4291      (lambda (relation)
4292        (when (gnus-dependencies-add-header
4293               (make-full-mail-header
4294                gnus-reffed-article-number
4295                (nth 3 relation) "" (or (nth 4 relation) "")
4296                (nth 1 relation)
4297                (or (nth 2 relation) "") 0 0 "")
4298               gnus-newsgroup-dependencies nil)
4299          (push gnus-reffed-article-number gnus-newsgroup-limit)
4300          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4301          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4302                gnus-newsgroup-reads)
4303          (decf gnus-reffed-article-number)))
4304      (sort relations 'car-less-than-car))
4305     (gnus-message 7 "Making sparse threads...done")))
4306
4307 (defun gnus-build-old-threads ()
4308   ;; Look at all the articles that refer back to old articles, and
4309   ;; fetch the headers for the articles that aren't there.  This will
4310   ;; build complete threads - if the roots haven't been expired by the
4311   ;; server, that is.
4312   (let ((mail-parse-charset gnus-newsgroup-charset)
4313         id heads)
4314     (mapatoms
4315      (lambda (refs)
4316        (when (not (car (symbol-value refs)))
4317          (setq heads (cdr (symbol-value refs)))
4318          (while heads
4319            (if (memq (mail-header-number (caar heads))
4320                      gnus-newsgroup-dormant)
4321                (setq heads (cdr heads))
4322              (setq id (symbol-name refs))
4323              (while (and (setq id (gnus-build-get-header id))
4324                          (not (car (gnus-id-to-thread id)))))
4325              (setq heads nil)))))
4326      gnus-newsgroup-dependencies)))
4327
4328 (defsubst gnus-remove-odd-characters (string)
4329   "Translate STRING into something that doesn't contain weird characters."
4330   (mm-subst-char-in-string
4331    ?\r ?\-
4332    (mm-subst-char-in-string ?\n ?\- string t) t))
4333
4334 ;; This function has to be called with point after the article number
4335 ;; on the beginning of the line.
4336 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4337   (let ((eol (point-at-eol))
4338         (buffer (current-buffer))
4339         header references in-reply-to)
4340
4341     ;; overview: [num subject from date id refs chars lines misc]
4342     (unwind-protect
4343         (let (x)
4344           (narrow-to-region (point) eol)
4345           (unless (eobp)
4346             (forward-char))
4347
4348           (setq header
4349                 (make-full-mail-header
4350                  number                 ; number
4351                  (condition-case ()     ; subject
4352                      (gnus-remove-odd-characters
4353                       (funcall gnus-decode-encoded-word-function
4354                                (setq x (nnheader-nov-field))))
4355                    (error x))
4356                  (condition-case ()     ; from
4357                      (gnus-remove-odd-characters
4358                       (funcall gnus-decode-encoded-address-function
4359                                (setq x (nnheader-nov-field))))
4360                    (error x))
4361                  (nnheader-nov-field)   ; date
4362                  (nnheader-nov-read-message-id number)  ; id
4363                  (setq references (nnheader-nov-field)) ; refs
4364                  (nnheader-nov-read-integer) ; chars
4365                  (nnheader-nov-read-integer) ; lines
4366                  (unless (eobp)
4367                    (if (looking-at "Xref: ")
4368                        (goto-char (match-end 0)))
4369                    (nnheader-nov-field)) ; Xref
4370                  (nnheader-nov-parse-extra)))) ; extra
4371
4372       (widen))
4373
4374     (when (and (string= references "")
4375                (setq in-reply-to (mail-header-extra header))
4376                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4377       (mail-header-set-references
4378        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4379
4380     (when gnus-alter-header-function
4381       (funcall gnus-alter-header-function header))
4382     (gnus-dependencies-add-header header dependencies force-new)))
4383
4384 (defun gnus-build-get-header (id)
4385   "Look through the buffer of NOV lines and find the header to ID.
4386 Enter this line into the dependencies hash table, and return
4387 the id of the parent article (if any)."
4388   (let ((deps gnus-newsgroup-dependencies)
4389         found header)
4390     (prog1
4391         (save-excursion
4392           (set-buffer nntp-server-buffer)
4393           (let ((case-fold-search nil))
4394             (goto-char (point-min))
4395             (while (and (not found)
4396                         (search-forward id nil t))
4397               (beginning-of-line)
4398               (setq found (looking-at
4399                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4400                                    (regexp-quote id))))
4401               (or found (beginning-of-line 2)))
4402             (when found
4403               (beginning-of-line)
4404               (and
4405                (setq header (gnus-nov-parse-line
4406                              (read (current-buffer)) deps))
4407                (gnus-parent-id (mail-header-references header))))))
4408       (when header
4409         (let ((number (mail-header-number header)))
4410           (push number gnus-newsgroup-limit)
4411           (push header gnus-newsgroup-headers)
4412           (if (memq number gnus-newsgroup-unselected)
4413               (progn
4414                 (setq gnus-newsgroup-unreads
4415                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4416                                                number))
4417                 (setq gnus-newsgroup-unselected
4418                       (delq number gnus-newsgroup-unselected)))
4419             (push number gnus-newsgroup-ancient)))))))
4420
4421 (defun gnus-build-all-threads ()
4422   "Read all the headers."
4423   (let ((gnus-summary-ignore-duplicates t)
4424         (mail-parse-charset gnus-newsgroup-charset)
4425         (dependencies gnus-newsgroup-dependencies)
4426         header article)
4427     (save-excursion
4428       (set-buffer nntp-server-buffer)
4429       (let ((case-fold-search nil))
4430         (goto-char (point-min))
4431         (while (not (eobp))
4432           (ignore-errors
4433             (setq article (read (current-buffer))
4434                   header (gnus-nov-parse-line article dependencies)))
4435           (when header
4436             (with-current-buffer gnus-summary-buffer
4437               (push header gnus-newsgroup-headers)
4438               (if (memq (setq article (mail-header-number header))
4439                         gnus-newsgroup-unselected)
4440                   (progn
4441                     (setq gnus-newsgroup-unreads
4442                           (gnus-add-to-sorted-list
4443                            gnus-newsgroup-unreads article))
4444                     (setq gnus-newsgroup-unselected
4445                           (delq article gnus-newsgroup-unselected)))
4446                 (push article gnus-newsgroup-ancient)))
4447             (forward-line 1)))))))
4448
4449 (defun gnus-summary-update-article-line (article header)
4450   "Update the line for ARTICLE using HEADER."
4451   (let* ((id (mail-header-id header))
4452          (thread (gnus-id-to-thread id)))
4453     (unless thread
4454       (error "Article in no thread"))
4455     ;; Update the thread.
4456     (setcar thread header)
4457     (gnus-summary-goto-subject article)
4458     (let* ((datal (gnus-data-find-list article))
4459            (data (car datal))
4460            (buffer-read-only nil)
4461            (level (gnus-summary-thread-level)))
4462       (gnus-delete-line)
4463       (let ((inserted (- (point)
4464                          (progn
4465                            (gnus-summary-insert-line
4466                             header level nil
4467                             (memq article gnus-newsgroup-undownloaded)
4468                             (gnus-article-mark article)
4469                             (memq article gnus-newsgroup-replied)
4470                             (memq article gnus-newsgroup-expirable)
4471                             ;; Only insert the Subject string when it's different
4472                             ;; from the previous Subject string.
4473                             (if (and
4474                                  gnus-show-threads
4475                                  (gnus-subject-equal
4476                                   (condition-case ()
4477                                       (mail-header-subject
4478                                        (gnus-data-header
4479                                         (cadr
4480                                          (gnus-data-find-list
4481                                           article
4482                                           (gnus-data-list t)))))
4483                                     ;; Error on the side of excessive subjects.
4484                                     (error ""))
4485                                   (mail-header-subject header)))
4486                                 ""
4487                               (mail-header-subject header))
4488                             nil (cdr (assq article gnus-newsgroup-scored))
4489                             (memq article gnus-newsgroup-processable))
4490                            (point)))))
4491         (when (cdr datal)
4492           (gnus-data-update-list
4493            (cdr datal)
4494            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4495
4496 (defun gnus-summary-update-article (article &optional iheader)
4497   "Update ARTICLE in the summary buffer."
4498   (set-buffer gnus-summary-buffer)
4499   (let* ((header (gnus-summary-article-header article))
4500          (id (mail-header-id header))
4501          (data (gnus-data-find article))
4502          (thread (gnus-id-to-thread id))
4503          (references (mail-header-references header))
4504          (parent
4505           (gnus-id-to-thread
4506            (or (gnus-parent-id
4507                 (when (and references
4508                            (not (equal "" references)))
4509                   references))
4510                "none")))
4511          (buffer-read-only nil)
4512          (old (car thread)))
4513     (when thread
4514       (unless iheader
4515         (setcar thread nil)
4516         (when parent
4517           (delq thread parent)))
4518       (if (gnus-summary-insert-subject id header)
4519           ;; Set the (possibly) new article number in the data structure.
4520           (gnus-data-set-number data (gnus-id-to-article id))
4521         (setcar thread old)
4522         nil))))
4523
4524 (defun gnus-rebuild-thread (id &optional line)
4525   "Rebuild the thread containing ID.
4526 If LINE, insert the rebuilt thread starting on line LINE."
4527   (let ((buffer-read-only nil)
4528         old-pos current thread data)
4529     (if (not gnus-show-threads)
4530         (setq thread (list (car (gnus-id-to-thread id))))
4531       ;; Get the thread this article is part of.
4532       (setq thread (gnus-remove-thread id)))
4533     (setq old-pos (point-at-bol))
4534     (setq current (save-excursion
4535                     (and (re-search-backward "[\r\n]" nil t)
4536                          (gnus-summary-article-number))))
4537     ;; If this is a gathered thread, we have to go some re-gathering.
4538     (when (stringp (car thread))
4539       (let ((subject (car thread))
4540             roots thr)
4541         (setq thread (cdr thread))
4542         (while thread
4543           (unless (memq (setq thr (gnus-id-to-thread
4544                                    (gnus-root-id
4545                                     (mail-header-id (caar thread)))))
4546                         roots)
4547             (push thr roots))
4548           (setq thread (cdr thread)))
4549         ;; We now have all (unique) roots.
4550         (if (= (length roots) 1)
4551             ;; All the loose roots are now one solid root.
4552             (setq thread (car roots))
4553           (setq thread (cons subject (gnus-sort-threads roots))))))
4554     (let (threads)
4555       ;; We then insert this thread into the summary buffer.
4556       (when line
4557         (goto-char (point-min))
4558         (forward-line (1- line)))
4559       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4560         (if gnus-show-threads
4561             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4562           (gnus-summary-prepare-unthreaded thread))
4563         (setq data (nreverse gnus-newsgroup-data))
4564         (setq threads gnus-newsgroup-threads))
4565       ;; We splice the new data into the data structure.
4566       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4567       ;;!!! then we want to insert at the beginning of the buffer.
4568       ;;!!! That happens to be true with Gnus now, but that may
4569       ;;!!! change in the future.  Perhaps.
4570       (gnus-data-enter-list
4571        (if line nil current) data (- (point) old-pos))
4572       (setq gnus-newsgroup-threads
4573             (nconc threads gnus-newsgroup-threads))
4574       (gnus-data-compute-positions))))
4575
4576 (defun gnus-number-to-header (number)
4577   "Return the header for article NUMBER."
4578   (let ((headers gnus-newsgroup-headers))
4579     (while (and headers
4580                 (not (= number (mail-header-number (car headers)))))
4581       (pop headers))
4582     (when headers
4583       (car headers))))
4584
4585 (defun gnus-parent-headers (in-headers &optional generation)
4586   "Return the headers of the GENERATIONeth parent of HEADERS."
4587   (unless generation
4588     (setq generation 1))
4589   (let ((parent t)
4590         (headers in-headers)
4591         references)
4592     (while (and parent
4593                 (not (zerop generation))
4594                 (setq references (mail-header-references headers)))
4595       (setq headers (if (and references
4596                              (setq parent (gnus-parent-id references)))
4597                         (car (gnus-id-to-thread parent))
4598                       nil))
4599       (decf generation))
4600     (and (not (eq headers in-headers))
4601          headers)))
4602
4603 (defun gnus-id-to-thread (id)
4604   "Return the (sub-)thread where ID appears."
4605   (gnus-gethash id gnus-newsgroup-dependencies))
4606
4607 (defun gnus-id-to-article (id)
4608   "Return the article number of ID."
4609   (let ((thread (gnus-id-to-thread id)))
4610     (when (and thread
4611                (car thread))
4612       (mail-header-number (car thread)))))
4613
4614 (defun gnus-id-to-header (id)
4615   "Return the article headers of ID."
4616   (car (gnus-id-to-thread id)))
4617
4618 (defun gnus-article-displayed-root-p (article)
4619   "Say whether ARTICLE is a root(ish) article."
4620   (let ((level (gnus-summary-thread-level article))
4621         (refs (mail-header-references  (gnus-summary-article-header article)))
4622         particle)
4623     (cond
4624      ((null level) nil)
4625      ((zerop level) t)
4626      ((null refs) t)
4627      ((null (gnus-parent-id refs)) t)
4628      ((and (= 1 level)
4629            (null (setq particle (gnus-id-to-article
4630                                  (gnus-parent-id refs))))
4631            (null (gnus-summary-thread-level particle)))))))
4632
4633 (defun gnus-root-id (id)
4634   "Return the id of the root of the thread where ID appears."
4635   (let (last-id prev)
4636     (while (and id (setq prev (car (gnus-id-to-thread id))))
4637       (setq last-id id
4638             id (gnus-parent-id (mail-header-references prev))))
4639     last-id))
4640
4641 (defun gnus-articles-in-thread (thread)
4642   "Return the list of articles in THREAD."
4643   (cons (mail-header-number (car thread))
4644         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4645
4646 (defun gnus-remove-thread (id &optional dont-remove)
4647   "Remove the thread that has ID in it."
4648   (let (headers thread last-id)
4649     ;; First go up in this thread until we find the root.
4650     (setq last-id (gnus-root-id id)
4651           headers (message-flatten-list (gnus-id-to-thread last-id)))
4652     ;; We have now found the real root of this thread.  It might have
4653     ;; been gathered into some loose thread, so we have to search
4654     ;; through the threads to find the thread we wanted.
4655     (let ((threads gnus-newsgroup-threads)
4656           sub)
4657       (while threads
4658         (setq sub (car threads))
4659         (if (stringp (car sub))
4660             ;; This is a gathered thread, so we look at the roots
4661             ;; below it to find whether this article is in this
4662             ;; gathered root.
4663             (progn
4664               (setq sub (cdr sub))
4665               (while sub
4666                 (when (member (caar sub) headers)
4667                   (setq thread (car threads)
4668                         threads nil
4669                         sub nil))
4670                 (setq sub (cdr sub))))
4671           ;; It's an ordinary thread, so we check it.
4672           (when (eq (car sub) (car headers))
4673             (setq thread sub
4674                   threads nil)))
4675         (setq threads (cdr threads)))
4676       ;; If this article is in no thread, then it's a root.
4677       (if thread
4678           (unless dont-remove
4679             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4680         (setq thread (gnus-id-to-thread last-id)))
4681       (when thread
4682         (prog1
4683             thread                      ; We return this thread.
4684           (unless dont-remove
4685             (if (stringp (car thread))
4686                 (progn
4687                   ;; If we use dummy roots, then we have to remove the
4688                   ;; dummy root as well.
4689                   (when (eq gnus-summary-make-false-root 'dummy)
4690                     ;; We go to the dummy root by going to
4691                     ;; the first sub-"thread", and then one line up.
4692                     (gnus-summary-goto-article
4693                      (mail-header-number (caadr thread)))
4694                     (forward-line -1)
4695                     (gnus-delete-line)
4696                     (gnus-data-compute-positions))
4697                   (setq thread (cdr thread))
4698                   (while thread
4699                     (gnus-remove-thread-1 (car thread))
4700                     (setq thread (cdr thread))))
4701               (gnus-remove-thread-1 thread))))))))
4702
4703 (defun gnus-remove-thread-1 (thread)
4704   "Remove the thread THREAD recursively."
4705   (let ((number (mail-header-number (pop thread)))
4706         d)
4707     (setq thread (reverse thread))
4708     (while thread
4709       (gnus-remove-thread-1 (pop thread)))
4710     (when (setq d (gnus-data-find number))
4711       (goto-char (gnus-data-pos d))
4712       (gnus-summary-show-thread)
4713       (gnus-data-remove
4714        number
4715        (- (point-at-bol)
4716           (prog1
4717               (1+ (point-at-eol))
4718             (gnus-delete-line)))))))
4719
4720 (defun gnus-sort-threads-recursive (threads func)
4721   (sort (mapcar (lambda (thread)
4722                   (cons (car thread)
4723                         (and (cdr thread)
4724                              (gnus-sort-threads-recursive (cdr thread) func))))
4725                 threads) func))
4726
4727 (defun gnus-sort-threads-loop (threads func)
4728   (let* ((superthread (cons nil threads))
4729          (stack (list (cons superthread threads)))
4730          remaining-threads thread)
4731     (while stack
4732       (setq remaining-threads (cdr (car stack)))
4733       (if remaining-threads
4734           (progn (setq thread (car remaining-threads))
4735                  (setcdr (car stack) (cdr remaining-threads))
4736                  (if (cdr thread)
4737                      (push (cons thread (cdr thread)) stack)))
4738         (setq thread (caar stack))
4739         (setcdr thread (sort (cdr thread) func))
4740         (pop stack)))
4741     (cdr superthread)))
4742
4743 (defun gnus-sort-threads (threads)
4744   "Sort THREADS."
4745   (if (not gnus-thread-sort-functions)
4746       threads
4747     (gnus-message 8 "Sorting threads...")
4748     (prog1
4749         (condition-case nil
4750             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4751               (gnus-sort-threads-recursive
4752                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4753           ;; Even after binding max-lisp-eval-depth, the recursive
4754           ;; sorter might fail for very long threads.  In that case,
4755           ;; try using a (less well-tested) non-recursive sorter.
4756           (error (gnus-sort-threads-loop
4757                   threads (gnus-make-sort-function
4758                            gnus-thread-sort-functions))))
4759       (gnus-message 8 "Sorting threads...done"))))
4760
4761 (defun gnus-sort-articles (articles)
4762   "Sort ARTICLES."
4763   (when gnus-article-sort-functions
4764     (gnus-message 7 "Sorting articles...")
4765     (prog1
4766         (setq gnus-newsgroup-headers
4767               (sort articles (gnus-make-sort-function
4768                               gnus-article-sort-functions)))
4769       (gnus-message 7 "Sorting articles...done"))))
4770
4771 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4772 (defmacro gnus-thread-header (thread)
4773   "Return header of first article in THREAD.
4774 Note that THREAD must never, ever be anything else than a variable -
4775 using some other form will lead to serious barfage."
4776   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4777   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4778   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4779         (vector thread) 2))
4780
4781 (defsubst gnus-article-sort-by-number (h1 h2)
4782   "Sort articles by article number."
4783   (< (mail-header-number h1)
4784      (mail-header-number h2)))
4785
4786 (defun gnus-thread-sort-by-number (h1 h2)
4787   "Sort threads by root article number."
4788   (gnus-article-sort-by-number
4789    (gnus-thread-header h1) (gnus-thread-header h2)))
4790
4791 (defsubst gnus-article-sort-by-random (h1 h2)
4792   "Sort articles by article number."
4793   (zerop (random 2)))
4794
4795 (defun gnus-thread-sort-by-random (h1 h2)
4796   "Sort threads by root article number."
4797   (gnus-article-sort-by-random
4798    (gnus-thread-header h1) (gnus-thread-header h2)))
4799
4800 (defsubst gnus-article-sort-by-lines (h1 h2)
4801   "Sort articles by article Lines header."
4802   (< (mail-header-lines h1)
4803      (mail-header-lines h2)))
4804
4805 (defun gnus-thread-sort-by-lines (h1 h2)
4806   "Sort threads by root article Lines header."
4807   (gnus-article-sort-by-lines
4808    (gnus-thread-header h1) (gnus-thread-header h2)))
4809
4810 (defsubst gnus-article-sort-by-chars (h1 h2)
4811   "Sort articles by octet length."
4812   (< (mail-header-chars h1)
4813      (mail-header-chars h2)))
4814
4815 (defun gnus-thread-sort-by-chars (h1 h2)
4816   "Sort threads by root article octet length."
4817   (gnus-article-sort-by-chars
4818    (gnus-thread-header h1) (gnus-thread-header h2)))
4819
4820 (defsubst gnus-article-sort-by-author (h1 h2)
4821   "Sort articles by root author."
4822   (string-lessp
4823    (let ((extract (funcall
4824                    gnus-extract-address-components
4825                    (mail-header-from h1))))
4826      (or (car extract) (cadr extract) ""))
4827    (let ((extract (funcall
4828                    gnus-extract-address-components
4829                    (mail-header-from h2))))
4830      (or (car extract) (cadr extract) ""))))
4831
4832 (defun gnus-thread-sort-by-author (h1 h2)
4833   "Sort threads by root author."
4834   (gnus-article-sort-by-author
4835    (gnus-thread-header h1)  (gnus-thread-header h2)))
4836
4837 (defsubst gnus-article-sort-by-recipient (h1 h2)
4838   "Sort articles by recipient."
4839   (string-lessp
4840    (let ((extract (funcall
4841                    gnus-extract-address-components
4842                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4843      (or (car extract) (cadr extract)))
4844    (let ((extract (funcall
4845                    gnus-extract-address-components
4846                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4847      (or (car extract) (cadr extract)))))
4848
4849 (defun gnus-thread-sort-by-recipient (h1 h2)
4850   "Sort threads by root recipient."
4851   (gnus-article-sort-by-recipient
4852    (gnus-thread-header h1) (gnus-thread-header h2)))
4853
4854 (defsubst gnus-article-sort-by-subject (h1 h2)
4855   "Sort articles by root subject."
4856   (string-lessp
4857    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4858    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4859
4860 (defun gnus-thread-sort-by-subject (h1 h2)
4861   "Sort threads by root subject."
4862   (gnus-article-sort-by-subject
4863    (gnus-thread-header h1) (gnus-thread-header h2)))
4864
4865 (defsubst gnus-article-sort-by-date (h1 h2)
4866   "Sort articles by root article date."
4867   (time-less-p
4868    (gnus-date-get-time (mail-header-date h1))
4869    (gnus-date-get-time (mail-header-date h2))))
4870
4871 (defun gnus-thread-sort-by-date (h1 h2)
4872   "Sort threads by root article date."
4873   (gnus-article-sort-by-date
4874    (gnus-thread-header h1) (gnus-thread-header h2)))
4875
4876 (defsubst gnus-article-sort-by-score (h1 h2)
4877   "Sort articles by root article score.
4878 Unscored articles will be counted as having a score of zero."
4879   (> (or (cdr (assq (mail-header-number h1)
4880                     gnus-newsgroup-scored))
4881          gnus-summary-default-score 0)
4882      (or (cdr (assq (mail-header-number h2)
4883                     gnus-newsgroup-scored))
4884          gnus-summary-default-score 0)))
4885
4886 (defun gnus-thread-sort-by-score (h1 h2)
4887   "Sort threads by root article score."
4888   (gnus-article-sort-by-score
4889    (gnus-thread-header h1) (gnus-thread-header h2)))
4890
4891 (defun gnus-thread-sort-by-total-score (h1 h2)
4892   "Sort threads by the sum of all scores in the thread.
4893 Unscored articles will be counted as having a score of zero."
4894   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4895
4896 (defun gnus-thread-total-score (thread)
4897   ;; This function find the total score of THREAD.
4898   (cond
4899    ((null thread)
4900     0)
4901    ((consp thread)
4902     (if (stringp (car thread))
4903         (apply gnus-thread-score-function 0
4904                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4905       (gnus-thread-total-score-1 thread)))
4906    (t
4907     (gnus-thread-total-score-1 (list thread)))))
4908
4909 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4910   "Sort threads such that the thread with the most recently arrived article comes first."
4911   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4912
4913 (defun gnus-thread-highest-number (thread)
4914   "Return the highest article number in THREAD."
4915   (apply 'max (mapcar (lambda (header)
4916                         (mail-header-number header))
4917                       (message-flatten-list thread))))
4918
4919 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4920   "Sort threads such that the thread with the most recently dated article comes first."
4921   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4922
4923 (defun gnus-thread-latest-date (thread)
4924   "Return the highest article date in THREAD."
4925   (let ((previous-time 0))
4926     (apply 'max
4927            (mapcar
4928             (lambda (header)
4929               (setq previous-time
4930                     (condition-case ()
4931                         (time-to-seconds (mail-header-parse-date
4932                                           (mail-header-date header)))
4933                       (error previous-time))))
4934             (sort
4935              (message-flatten-list thread)
4936              (lambda (h1 h2)
4937                (< (mail-header-number h1)
4938                   (mail-header-number h2))))))))
4939
4940 (defun gnus-thread-total-score-1 (root)
4941   ;; This function find the total score of the thread below ROOT.
4942   (setq root (car root))
4943   (apply gnus-thread-score-function
4944          (or (append
4945               (mapcar 'gnus-thread-total-score
4946                       (cdr (gnus-id-to-thread (mail-header-id root))))
4947               (when (> (mail-header-number root) 0)
4948                 (list (or (cdr (assq (mail-header-number root)
4949                                      gnus-newsgroup-scored))
4950                           gnus-summary-default-score 0))))
4951              (list gnus-summary-default-score)
4952              '(0))))
4953
4954 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4955 (defvar gnus-tmp-prev-subject nil)
4956 (defvar gnus-tmp-false-parent nil)
4957 (defvar gnus-tmp-root-expunged nil)
4958 (defvar gnus-tmp-dummy-line nil)
4959
4960 (eval-when-compile (defvar gnus-tmp-header))
4961 (defun gnus-extra-header (type &optional header)
4962   "Return the extra header of TYPE."
4963   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4964       ""))
4965
4966 (defvar gnus-tmp-thread-tree-header-string "")
4967
4968 (defcustom gnus-sum-thread-tree-root "> "
4969   "With %B spec, used for the root of a thread.
4970 If nil, use subject instead."
4971   :version "22.1"
4972   :type '(radio (const :format "%v  " nil) string)
4973   :group 'gnus-thread)
4974
4975 (defcustom gnus-sum-thread-tree-false-root "> "
4976   "With %B spec, used for a false root of a thread.
4977 If nil, use subject instead."
4978   :version "22.1"
4979   :type '(radio (const :format "%v  " nil) string)
4980   :group 'gnus-thread)
4981
4982 (defcustom gnus-sum-thread-tree-single-indent ""
4983   "With %B spec, used for a thread with just one message.
4984 If nil, use subject instead."
4985   :version "22.1"
4986   :type '(radio (const :format "%v  " nil) string)
4987   :group 'gnus-thread)
4988
4989 (defcustom gnus-sum-thread-tree-vertical "| "
4990   "With %B spec, used for drawing a vertical line."
4991   :version "22.1"
4992   :type 'string
4993   :group 'gnus-thread)
4994
4995 (defcustom gnus-sum-thread-tree-indent "  "
4996   "With %B spec, used for indenting."
4997   :version "22.1"
4998   :type 'string
4999   :group 'gnus-thread)
5000
5001 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5002   "With %B spec, used for a leaf with brothers."
5003   :version "22.1"
5004   :type 'string
5005   :group 'gnus-thread)
5006
5007 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5008   "With %B spec, used for a leaf without brothers."
5009   :version "22.1"
5010   :type 'string
5011   :group 'gnus-thread)
5012
5013 (defun gnus-summary-prepare-threads (threads)
5014   "Prepare summary buffer from THREADS and indentation LEVEL.
5015 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5016 or a straight list of headers."
5017   (gnus-message 7 "Generating summary...")
5018
5019   (setq gnus-newsgroup-threads threads)
5020   (beginning-of-line)
5021
5022   (let ((gnus-tmp-level 0)
5023         (default-score (or gnus-summary-default-score 0))
5024         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5025         (building-line-count gnus-summary-display-while-building)
5026         (building-count (integerp gnus-summary-display-while-building))
5027         thread number subject stack state gnus-tmp-gathered beg-match
5028         new-roots gnus-tmp-new-adopts thread-end simp-subject
5029         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5030         gnus-tmp-replied gnus-tmp-subject-or-nil
5031         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5032         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5033         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5034         tree-stack)
5035
5036     (setq gnus-tmp-prev-subject nil
5037           gnus-tmp-thread-tree-header-string "")
5038
5039     (if (vectorp (car threads))
5040         ;; If this is a straight (sic) list of headers, then a
5041         ;; threaded summary display isn't required, so we just create
5042         ;; an unthreaded one.
5043         (gnus-summary-prepare-unthreaded threads)
5044
5045       ;; Do the threaded display.
5046
5047       (if gnus-summary-display-while-building
5048           (switch-to-buffer (buffer-name)))
5049       (while (or threads stack gnus-tmp-new-adopts new-roots)
5050
5051         (if (and (= gnus-tmp-level 0)
5052                  (or (not stack)
5053                      (= (caar stack) 0))
5054                  (not gnus-tmp-false-parent)
5055                  (or gnus-tmp-new-adopts new-roots))
5056             (if gnus-tmp-new-adopts
5057                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5058                       thread (list (car gnus-tmp-new-adopts))
5059                       gnus-tmp-header (caar thread)
5060                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5061               (when new-roots
5062                 (setq thread (list (car new-roots))
5063                       gnus-tmp-header (caar thread)
5064                       new-roots (cdr new-roots))))
5065
5066           (if threads
5067               ;; If there are some threads, we do them before the
5068               ;; threads on the stack.
5069               (setq thread threads
5070                     gnus-tmp-header (caar thread))
5071             ;; There were no current threads, so we pop something off
5072             ;; the stack.
5073             (setq state (car stack)
5074                   gnus-tmp-level (car state)
5075                   tree-stack (cadr state)
5076                   thread (caddr state)
5077                   stack (cdr stack)
5078                   gnus-tmp-header (caar thread))))
5079
5080         (setq gnus-tmp-false-parent nil)
5081         (setq gnus-tmp-root-expunged nil)
5082         (setq thread-end nil)
5083
5084         (if (stringp gnus-tmp-header)
5085             ;; The header is a dummy root.
5086             (cond
5087              ((eq gnus-summary-make-false-root 'adopt)
5088               ;; We let the first article adopt the rest.
5089               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5090                                                (cddar thread)))
5091               (setq gnus-tmp-gathered
5092                     (nconc (mapcar
5093                             (lambda (h) (mail-header-number (car h)))
5094                             (cddar thread))
5095                            gnus-tmp-gathered))
5096               (setq thread (cons (list (caar thread)
5097                                        (cadar thread))
5098                                  (cdr thread)))
5099               (setq gnus-tmp-level -1
5100                     gnus-tmp-false-parent t))
5101              ((eq gnus-summary-make-false-root 'empty)
5102               ;; We print adopted articles with empty subject fields.
5103               (setq gnus-tmp-gathered
5104                     (nconc (mapcar
5105                             (lambda (h) (mail-header-number (car h)))
5106                             (cddar thread))
5107                            gnus-tmp-gathered))
5108               (setq gnus-tmp-level -1))
5109              ((eq gnus-summary-make-false-root 'dummy)
5110               ;; We remember that we probably want to output a dummy
5111               ;; root.
5112               (setq gnus-tmp-dummy-line gnus-tmp-header)
5113               (setq gnus-tmp-prev-subject gnus-tmp-header))
5114              (t
5115               ;; We do not make a root for the gathered
5116               ;; sub-threads at all.
5117               (setq gnus-tmp-level -1)))
5118
5119           (setq number (mail-header-number gnus-tmp-header)
5120                 subject (mail-header-subject gnus-tmp-header)
5121                 simp-subject (gnus-simplify-subject-fully subject))
5122
5123           (cond
5124            ;; If the thread has changed subject, we might want to make
5125            ;; this subthread into a root.
5126            ((and (null gnus-thread-ignore-subject)
5127                  (not (zerop gnus-tmp-level))
5128                  gnus-tmp-prev-subject
5129                  (not (string= gnus-tmp-prev-subject simp-subject)))
5130             (setq new-roots (nconc new-roots (list (car thread)))
5131                   thread-end t
5132                   gnus-tmp-header nil))
5133            ;; If the article lies outside the current limit,
5134            ;; then we do not display it.
5135            ((not (memq number gnus-newsgroup-limit))
5136             (setq gnus-tmp-gathered
5137                   (nconc (mapcar
5138                           (lambda (h) (mail-header-number (car h)))
5139                           (cdar thread))
5140                          gnus-tmp-gathered))
5141             (setq gnus-tmp-new-adopts (if (cdar thread)
5142                                           (append gnus-tmp-new-adopts
5143                                                   (cdar thread))
5144                                         gnus-tmp-new-adopts)
5145                   thread-end t
5146                   gnus-tmp-header nil)
5147             (when (zerop gnus-tmp-level)
5148               (setq gnus-tmp-root-expunged t)))
5149            ;; Perhaps this article is to be marked as read?
5150            ((and gnus-summary-mark-below
5151                  (< (or (cdr (assq number gnus-newsgroup-scored))
5152                         default-score)
5153                     gnus-summary-mark-below)
5154                  ;; Don't touch sparse articles.
5155                  (not (gnus-summary-article-sparse-p number))
5156                  (not (gnus-summary-article-ancient-p number)))
5157             (setq gnus-newsgroup-unreads
5158                   (delq number gnus-newsgroup-unreads))
5159             (if gnus-newsgroup-auto-expire
5160                 (setq gnus-newsgroup-expirable
5161                       (gnus-add-to-sorted-list
5162                        gnus-newsgroup-expirable number))
5163               (push (cons number gnus-low-score-mark)
5164                     gnus-newsgroup-reads))))
5165
5166           (when gnus-tmp-header
5167             ;; We may have an old dummy line to output before this
5168             ;; article.
5169             (when (and gnus-tmp-dummy-line
5170                        (gnus-subject-equal
5171                         gnus-tmp-dummy-line
5172                         (mail-header-subject gnus-tmp-header)))
5173               (gnus-summary-insert-dummy-line
5174                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5175               (setq gnus-tmp-dummy-line nil))
5176
5177             ;; Compute the mark.
5178             (setq gnus-tmp-unread (gnus-article-mark number))
5179
5180             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5181                                   gnus-tmp-header gnus-tmp-level)
5182                   gnus-newsgroup-data)
5183
5184             ;; Actually insert the line.
5185             (setq
5186              gnus-tmp-subject-or-nil
5187              (cond
5188               ((and gnus-thread-ignore-subject
5189                     gnus-tmp-prev-subject
5190                     (not (string= gnus-tmp-prev-subject simp-subject)))
5191                subject)
5192               ((zerop gnus-tmp-level)
5193                (if (and (eq gnus-summary-make-false-root 'empty)
5194                         (memq number gnus-tmp-gathered)
5195                         gnus-tmp-prev-subject
5196                         (string= gnus-tmp-prev-subject simp-subject))
5197                    gnus-summary-same-subject
5198                  subject))
5199               (t gnus-summary-same-subject)))
5200             (if (and (eq gnus-summary-make-false-root 'adopt)
5201                      (= gnus-tmp-level 1)
5202                      (memq number gnus-tmp-gathered))
5203                 (setq gnus-tmp-opening-bracket ?\<
5204                       gnus-tmp-closing-bracket ?\>)
5205               (setq gnus-tmp-opening-bracket ?\[
5206                     gnus-tmp-closing-bracket ?\]))
5207             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5208                 (gnus-make-thread-indent-array
5209                  (max (* 2 (length gnus-thread-indent-array))
5210                       gnus-tmp-level)))
5211             (setq
5212              gnus-tmp-indentation
5213              (aref gnus-thread-indent-array gnus-tmp-level)
5214              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5215              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5216                                 gnus-summary-default-score 0)
5217              gnus-tmp-score-char
5218              (if (or (null gnus-summary-default-score)
5219                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5220                          gnus-summary-zcore-fuzz))
5221                  ?                      ;Whitespace
5222                (if (< gnus-tmp-score gnus-summary-default-score)
5223                    gnus-score-below-mark gnus-score-over-mark))
5224              gnus-tmp-replied
5225              (cond ((memq number gnus-newsgroup-processable)
5226                     gnus-process-mark)
5227                    ((memq number gnus-newsgroup-cached)
5228                     gnus-cached-mark)
5229                    ((memq number gnus-newsgroup-replied)
5230                     gnus-replied-mark)
5231                    ((memq number gnus-newsgroup-forwarded)
5232                     gnus-forwarded-mark)
5233                    ((memq number gnus-newsgroup-saved)
5234                     gnus-saved-mark)
5235                    ((memq number gnus-newsgroup-recent)
5236                     gnus-recent-mark)
5237                    ((memq number gnus-newsgroup-unseen)
5238                     gnus-unseen-mark)
5239                    (t gnus-no-mark))
5240              gnus-tmp-downloaded
5241              (cond ((memq number gnus-newsgroup-undownloaded)
5242                     gnus-undownloaded-mark)
5243                    (gnus-newsgroup-agentized
5244                     gnus-downloaded-mark)
5245                    (t
5246                     gnus-no-mark))
5247              gnus-tmp-from (mail-header-from gnus-tmp-header)
5248              gnus-tmp-name
5249              (cond
5250               ((string-match "<[^>]+> *$" gnus-tmp-from)
5251                (setq beg-match (match-beginning 0))
5252                (or (and (string-match "^\".+\"" gnus-tmp-from)
5253                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5254                    (substring gnus-tmp-from 0 beg-match)))
5255               ((string-match "(.+)" gnus-tmp-from)
5256                (substring gnus-tmp-from
5257                           (1+ (match-beginning 0)) (1- (match-end 0))))
5258               (t gnus-tmp-from))
5259
5260              ;; Do the %B string
5261              gnus-tmp-thread-tree-header-string
5262              (cond
5263               ((not gnus-show-threads) "")
5264               ((zerop gnus-tmp-level)
5265                (cond ((cdar thread)
5266                       (or gnus-sum-thread-tree-root subject))
5267                      (gnus-tmp-new-adopts
5268                       (or gnus-sum-thread-tree-false-root subject))
5269                      (t
5270                       (or gnus-sum-thread-tree-single-indent subject))))
5271               (t
5272                (concat (apply 'concat
5273                               (mapcar (lambda (item)
5274                                         (if (= item 1)
5275                                             gnus-sum-thread-tree-vertical
5276                                           gnus-sum-thread-tree-indent))
5277                                       (cdr (reverse tree-stack))))
5278                        (if (nth 1 thread)
5279                            gnus-sum-thread-tree-leaf-with-other
5280                          gnus-sum-thread-tree-single-leaf)))))
5281             (when (string= gnus-tmp-name "")
5282               (setq gnus-tmp-name gnus-tmp-from))
5283             (unless (numberp gnus-tmp-lines)
5284               (setq gnus-tmp-lines -1))
5285             (if (= gnus-tmp-lines -1)
5286                 (setq gnus-tmp-lines "?")
5287               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5288               (gnus-put-text-property
5289              (point)
5290              (progn (eval gnus-summary-line-format-spec) (point))
5291                'gnus-number number)
5292             (when gnus-visual-p
5293               (forward-line -1)
5294               (gnus-run-hooks 'gnus-summary-update-hook)
5295               (forward-line 1))
5296
5297             (setq gnus-tmp-prev-subject simp-subject)))
5298
5299         (when (nth 1 thread)
5300           (push (list (max 0 gnus-tmp-level)
5301                       (copy-sequence tree-stack)
5302                       (nthcdr 1 thread))
5303                 stack))
5304         (push (if (nth 1 thread) 1 0) tree-stack)
5305         (incf gnus-tmp-level)
5306         (setq threads (if thread-end nil (cdar thread)))
5307         (if gnus-summary-display-while-building
5308             (if building-count
5309                 (progn
5310                   ;; use a set frequency
5311                   (setq building-line-count (1- building-line-count))
5312                   (when (= building-line-count 0)
5313                     (sit-for 0)
5314                     (setq building-line-count
5315                           gnus-summary-display-while-building)))
5316               ;; always
5317               (sit-for 0)))
5318         (unless threads
5319           (setq gnus-tmp-level 0)))))
5320   (gnus-message 7 "Generating summary...done"))
5321
5322 (defun gnus-summary-prepare-unthreaded (headers)
5323   "Generate an unthreaded summary buffer based on HEADERS."
5324   (let (header number mark)
5325
5326     (beginning-of-line)
5327
5328     (while headers
5329       ;; We may have to root out some bad articles...
5330       (when (memq (setq number (mail-header-number
5331                                 (setq header (pop headers))))
5332                   gnus-newsgroup-limit)
5333         ;; Mark article as read when it has a low score.
5334         (when (and gnus-summary-mark-below
5335                    (< (or (cdr (assq number gnus-newsgroup-scored))
5336                           gnus-summary-default-score 0)
5337                       gnus-summary-mark-below)
5338                    (not (gnus-summary-article-ancient-p number)))
5339           (setq gnus-newsgroup-unreads
5340                 (delq number gnus-newsgroup-unreads))
5341           (if gnus-newsgroup-auto-expire
5342               (push number gnus-newsgroup-expirable)
5343             (push (cons number gnus-low-score-mark)
5344                   gnus-newsgroup-reads)))
5345
5346         (setq mark (gnus-article-mark number))
5347         (push (gnus-data-make number mark (1+ (point)) header 0)
5348               gnus-newsgroup-data)
5349         (gnus-summary-insert-line
5350          header 0 number
5351          (memq number gnus-newsgroup-undownloaded)
5352          mark (memq number gnus-newsgroup-replied)
5353          (memq number gnus-newsgroup-expirable)
5354          (mail-header-subject header) nil
5355          (cdr (assq number gnus-newsgroup-scored))
5356          (memq number gnus-newsgroup-processable))))))
5357
5358 (defun gnus-summary-remove-list-identifiers ()
5359   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5360   (let ((regexp (if (consp gnus-list-identifiers)
5361                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5362                   gnus-list-identifiers))
5363         changed subject)
5364     (when regexp
5365       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5366       (dolist (header gnus-newsgroup-headers)
5367         (setq subject (mail-header-subject header)
5368               changed nil)
5369         (while (string-match regexp subject)
5370           (setq subject
5371                 (concat (substring subject 0 (match-beginning 1))
5372                         (substring subject (match-end 0)))
5373                 changed t))
5374         (when changed
5375           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5376             (setq subject
5377                   (concat (substring subject 0 (match-beginning 1))
5378                           (substring subject (match-end 1)))))
5379           (mail-header-set-subject header subject))))))
5380
5381 (defun gnus-fetch-headers (articles)
5382   "Fetch headers of ARTICLES."
5383   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5384     (gnus-message 5 "Fetching headers for %s..." name)
5385     (prog1
5386         (if (eq 'nov
5387                 (setq gnus-headers-retrieved-by
5388                       (gnus-retrieve-headers
5389                        articles gnus-newsgroup-name
5390                        ;; We might want to fetch old headers, but
5391                        ;; not if there is only 1 article.
5392                        (and (or (and
5393                                  (not (eq gnus-fetch-old-headers 'some))
5394                                  (not (numberp gnus-fetch-old-headers)))
5395                                 (> (length articles) 1))
5396                             gnus-fetch-old-headers))))
5397             (gnus-get-newsgroup-headers-xover
5398              articles nil nil gnus-newsgroup-name t)
5399           (gnus-get-newsgroup-headers))
5400       (gnus-message 5 "Fetching headers for %s...done" name))))
5401
5402 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5403   "Select newsgroup GROUP.
5404 If READ-ALL is non-nil, all articles in the group are selected.
5405 If SELECT-ARTICLES, only select those articles from GROUP."
5406   (let* ((entry (gnus-group-entry group))
5407          ;;!!! Dirty hack; should be removed.
5408          (gnus-summary-ignore-duplicates
5409           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5410               t
5411             gnus-summary-ignore-duplicates))
5412          (info (nth 2 entry))
5413          charset articles fetched-articles cached)
5414
5415     (unless (gnus-check-server
5416              (set (make-local-variable 'gnus-current-select-method)
5417                   (gnus-find-method-for-group group)))
5418       (error "Couldn't open server"))
5419     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5420
5421     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5422         (gnus-activate-group group)     ; Or we can activate it...
5423         (progn                          ; Or we bug out.
5424           (when (equal major-mode 'gnus-summary-mode)
5425             (gnus-kill-buffer (current-buffer)))
5426           (error
5427            "Couldn't activate group %s: %s"
5428            (mm-decode-coding-string group charset)
5429            (mm-decode-coding-string (gnus-status-message group) charset))))
5430
5431     (unless (gnus-request-group group t)
5432         (when (equal major-mode 'gnus-summary-mode)
5433           (gnus-kill-buffer (current-buffer)))
5434         (error "Couldn't request group %s: %s"
5435                (mm-decode-coding-string group charset)
5436                (mm-decode-coding-string (gnus-status-message group) charset)))
5437
5438     (when gnus-agent
5439       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5440
5441       (setq gnus-summary-use-undownloaded-faces
5442             (gnus-agent-find-parameter
5443              group
5444              'agent-enable-undownloaded-faces)))
5445
5446     (setq gnus-newsgroup-name group
5447           gnus-newsgroup-unselected nil
5448           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5449
5450     (let ((display (gnus-group-find-parameter group 'display)))
5451       (setq gnus-newsgroup-display
5452             (cond
5453              ((not (zerop (or (car-safe read-all) 0)))
5454               ;; The user entered the group with C-u SPC/RET, let's show
5455               ;; all articles.
5456               'gnus-not-ignore)
5457              ((eq display 'all)
5458               'gnus-not-ignore)
5459              ((arrayp display)
5460               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5461              ((numberp display)
5462               ;; The following is probably the "correct" solution, but
5463               ;; it makes Gnus fetch all headers and then limit the
5464               ;; articles (which is slow), so instead we hack the
5465               ;; select-articles parameter instead. -- Simon Josefsson
5466               ;; <jas@kth.se>
5467               ;;
5468               ;; (gnus-byte-compile
5469               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5470               ;;                         display)))))
5471               (setq select-articles
5472                     (gnus-uncompress-range
5473                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5474                              (if (> tmp 0)
5475                                  tmp
5476                                1))
5477                            (cdr (gnus-active group)))))
5478               nil)
5479              (t
5480               nil))))
5481
5482     (gnus-summary-setup-default-charset)
5483
5484     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5485     (when (gnus-virtual-group-p group)
5486       (setq cached gnus-newsgroup-cached))
5487
5488     (setq gnus-newsgroup-unreads
5489           (gnus-sorted-ndifference
5490            (gnus-sorted-ndifference gnus-newsgroup-unreads
5491                                     gnus-newsgroup-marked)
5492            gnus-newsgroup-dormant))
5493
5494     (setq gnus-newsgroup-processable nil)
5495
5496     (gnus-update-read-articles group gnus-newsgroup-unreads)
5497
5498     ;; Adjust and set lists of article marks.
5499     (when info
5500       (gnus-adjust-marked-articles info))
5501     (if (setq articles select-articles)
5502         (setq gnus-newsgroup-unselected
5503               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5504       (setq articles (gnus-articles-to-read group read-all)))
5505
5506     (cond
5507      ((null articles)
5508       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5509       'quit)
5510      ((eq articles 0) nil)
5511      (t
5512       ;; Init the dependencies hash table.
5513       (setq gnus-newsgroup-dependencies
5514             (gnus-make-hashtable (length articles)))
5515       (gnus-set-global-variables)
5516       ;; Retrieve the headers and read them in.
5517
5518       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5519
5520       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5521       (when cached
5522         (setq gnus-newsgroup-cached cached))
5523
5524       ;; Suppress duplicates?
5525       (when gnus-suppress-duplicates
5526         (gnus-dup-suppress-articles))
5527
5528       ;; Set the initial limit.
5529       (setq gnus-newsgroup-limit (copy-sequence articles))
5530       ;; Remove canceled articles from the list of unread articles.
5531       (setq fetched-articles
5532             (mapcar (lambda (headers) (mail-header-number headers))
5533                     gnus-newsgroup-headers))
5534       (setq gnus-newsgroup-articles fetched-articles)
5535       (setq gnus-newsgroup-unreads
5536             (gnus-sorted-nintersection
5537              gnus-newsgroup-unreads fetched-articles))
5538       (gnus-compute-unseen-list)
5539
5540       ;; Removed marked articles that do not exist.
5541       (gnus-update-missing-marks
5542        (gnus-sorted-difference articles fetched-articles))
5543       ;; We might want to build some more threads first.
5544       (when (and gnus-fetch-old-headers
5545                  (eq gnus-headers-retrieved-by 'nov))
5546         (if (eq gnus-fetch-old-headers 'invisible)
5547             (gnus-build-all-threads)
5548           (gnus-build-old-threads)))
5549       ;; Let the Gnus agent mark articles as read.
5550       (when gnus-agent
5551         (gnus-agent-get-undownloaded-list))
5552       ;; Remove list identifiers from subject
5553       (when gnus-list-identifiers
5554         (gnus-summary-remove-list-identifiers))
5555       ;; Check whether auto-expire is to be done in this group.
5556       (setq gnus-newsgroup-auto-expire
5557             (gnus-group-auto-expirable-p group))
5558       ;; Set up the article buffer now, if necessary.
5559       (unless (and gnus-single-article-buffer
5560                    (equal gnus-article-buffer "*Article*"))
5561         (gnus-article-setup-buffer))
5562       ;; First and last article in this newsgroup.
5563       (when gnus-newsgroup-headers
5564         (setq gnus-newsgroup-begin
5565               (mail-header-number (car gnus-newsgroup-headers))
5566               gnus-newsgroup-end
5567               (mail-header-number
5568                (gnus-last-element gnus-newsgroup-headers))))
5569       ;; GROUP is successfully selected.
5570       (or gnus-newsgroup-headers t)))))
5571
5572 (defun gnus-compute-unseen-list ()
5573   ;; The `seen' marks are treated specially.
5574   (if (not gnus-newsgroup-seen)
5575       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5576     (setq gnus-newsgroup-unseen
5577           (gnus-inverse-list-range-intersection
5578            gnus-newsgroup-articles gnus-newsgroup-seen))))
5579
5580 (defun gnus-summary-display-make-predicate (display)
5581   (require 'gnus-agent)
5582   (when (= (length display) 1)
5583     (setq display (car display)))
5584   (unless gnus-summary-display-cache
5585     (dolist (elem (append '((unread . unread)
5586                             (read . read)
5587                             (unseen . unseen))
5588                           gnus-article-mark-lists))
5589       (push (cons (cdr elem)
5590                   (gnus-byte-compile
5591                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5592             gnus-summary-display-cache)))
5593   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5594         (gnus-category-predicate-cache gnus-summary-display-cache))
5595     (gnus-get-predicate display)))
5596
5597 ;; Uses the dynamically bound `number' variable.
5598 (eval-when-compile
5599   (defvar number))
5600 (defun gnus-article-marked-p (type &optional article)
5601   (let ((article (or article number)))
5602     (cond
5603      ((eq type 'tick)
5604       (memq article gnus-newsgroup-marked))
5605      ((eq type 'spam)
5606       (memq article gnus-newsgroup-spam-marked))
5607      ((eq type 'unsend)
5608       (memq article gnus-newsgroup-unsendable))
5609      ((eq type 'undownload)
5610       (memq article gnus-newsgroup-undownloaded))
5611      ((eq type 'download)
5612       (memq article gnus-newsgroup-downloadable))
5613      ((eq type 'unread)
5614       (memq article gnus-newsgroup-unreads))
5615      ((eq type 'read)
5616       (memq article gnus-newsgroup-reads))
5617      ((eq type 'dormant)
5618       (memq article gnus-newsgroup-dormant) )
5619      ((eq type 'expire)
5620       (memq article gnus-newsgroup-expirable))
5621      ((eq type 'reply)
5622       (memq article gnus-newsgroup-replied))
5623      ((eq type 'killed)
5624       (memq article gnus-newsgroup-killed))
5625      ((eq type 'bookmark)
5626       (assq article gnus-newsgroup-bookmarks))
5627      ((eq type 'score)
5628       (assq article gnus-newsgroup-scored))
5629      ((eq type 'save)
5630       (memq article gnus-newsgroup-saved))
5631      ((eq type 'cache)
5632       (memq article gnus-newsgroup-cached))
5633      ((eq type 'forward)
5634       (memq article gnus-newsgroup-forwarded))
5635      ((eq type 'seen)
5636       (not (memq article gnus-newsgroup-unseen)))
5637      ((eq type 'recent)
5638       (memq article gnus-newsgroup-recent))
5639      (t t))))
5640
5641 (defun gnus-articles-to-read (group &optional read-all)
5642   "Find out what articles the user wants to read."
5643   (let* ((articles
5644           ;; Select all articles if `read-all' is non-nil, or if there
5645           ;; are no unread articles.
5646           (if (or read-all
5647                   (and (zerop (length gnus-newsgroup-marked))
5648                        (zerop (length gnus-newsgroup-unreads)))
5649                   ;; Fetch all if the predicate is non-nil.
5650                   gnus-newsgroup-display)
5651               ;; We want to select the headers for all the articles in
5652               ;; the group, so we select either all the active
5653               ;; articles in the group, or (if that's nil), the
5654               ;; articles in the cache.
5655               (or
5656                (if gnus-newsgroup-maximum-articles
5657                    (let ((active (gnus-active group)))
5658                      (gnus-uncompress-range
5659                       (cons (max (car active)
5660                                  (- (cdr active)
5661                                     gnus-newsgroup-maximum-articles
5662                                     -1))
5663                             (cdr active))))
5664                  (gnus-uncompress-range (gnus-active group)))
5665                (gnus-cache-articles-in-group group))
5666             ;; Select only the "normal" subset of articles.
5667             (gnus-sorted-nunion
5668              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5669              gnus-newsgroup-unreads)))
5670          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5671          (scored (length scored-list))
5672          (number (length articles))
5673          (marked (+ (length gnus-newsgroup-marked)
5674                     (length gnus-newsgroup-dormant)))
5675          (select
5676           (cond
5677            ((numberp read-all)
5678             read-all)
5679            ((numberp gnus-newsgroup-display)
5680             gnus-newsgroup-display)
5681            (t
5682             (condition-case ()
5683                 (cond
5684                  ((and (or (<= scored marked) (= scored number))
5685                        (numberp gnus-large-newsgroup)
5686                        (> number gnus-large-newsgroup))
5687                   (let* ((cursor-in-echo-area nil)
5688                          (initial (gnus-parameter-large-newsgroup-initial
5689                                    gnus-newsgroup-name))
5690                          (input
5691                           (read-string
5692                            (format
5693                             "How many articles from %s (%s %d): "
5694                             (gnus-group-decoded-name gnus-newsgroup-name)
5695                             (if initial "max" "default")
5696                             number)
5697                            (if initial
5698                                (cons (number-to-string initial)
5699                                      0)))))
5700                     (if (string-match "^[ \t]*$" input) number input)))
5701                  ((and (> scored marked) (< scored number)
5702                        (> (- scored number) 20))
5703                   (let ((input
5704                          (read-string
5705                           (format "%s %s (%d scored, %d total): "
5706                                   "How many articles from"
5707                                   (gnus-group-decoded-name group)
5708                                   scored number))))
5709                     (if (string-match "^[ \t]*$" input)
5710                         number input)))
5711                  (t number))
5712               (quit
5713                (message "Quit getting the articles to read")
5714                nil))))))
5715     (setq select (if (stringp select) (string-to-number select) select))
5716     (if (or (null select) (zerop select))
5717         select
5718       (if (and (not (zerop scored)) (<= (abs select) scored))
5719           (progn
5720             (setq articles (sort scored-list '<))
5721             (setq number (length articles)))
5722         (setq articles (copy-sequence articles)))
5723
5724       (when (< (abs select) number)
5725         (if (< select 0)
5726             ;; Select the N oldest articles.
5727             (setcdr (nthcdr (1- (abs select)) articles) nil)
5728           ;; Select the N most recent articles.
5729           (setq articles (nthcdr (- number select) articles))))
5730       (setq gnus-newsgroup-unselected
5731             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5732       (when gnus-alter-articles-to-read-function
5733         (setq articles
5734               (sort
5735                (funcall gnus-alter-articles-to-read-function
5736                         gnus-newsgroup-name articles)
5737                '<)))
5738       articles)))
5739
5740 (defun gnus-killed-articles (killed articles)
5741   (let (out)
5742     (while articles
5743       (when (inline (gnus-member-of-range (car articles) killed))
5744         (push (car articles) out))
5745       (setq articles (cdr articles)))
5746     out))
5747
5748 (defun gnus-uncompress-marks (marks)
5749   "Uncompress the mark ranges in MARKS."
5750   (let ((uncompressed '(score bookmark))
5751         out)
5752     (while marks
5753       (if (memq (caar marks) uncompressed)
5754           (push (car marks) out)
5755         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5756       (setq marks (cdr marks)))
5757     out))
5758
5759 (defun gnus-article-mark-to-type (mark)
5760   "Return the type of MARK."
5761   (or (cadr (assq mark gnus-article-special-mark-lists))
5762       'list))
5763
5764 (defun gnus-article-unpropagatable-p (mark)
5765   "Return whether MARK should be propagated to back end."
5766   (memq mark gnus-article-unpropagated-mark-lists))
5767
5768 (defun gnus-adjust-marked-articles (info)
5769   "Set all article lists and remove all marks that are no longer valid."
5770   (let* ((marked-lists (gnus-info-marks info))
5771          (active (gnus-active (gnus-info-group info)))
5772          (min (car active))
5773          (max (cdr active))
5774          (types gnus-article-mark-lists)
5775          marks var articles article mark mark-type
5776          bgn end)
5777
5778     (dolist (marks marked-lists)
5779       (setq mark (car marks)
5780             mark-type (gnus-article-mark-to-type mark)
5781             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5782
5783       ;; We set the variable according to the type of the marks list,
5784       ;; and then adjust the marks to a subset of the active articles.
5785       (cond
5786        ;; Adjust "simple" lists - compressed yet unsorted
5787        ((eq mark-type 'list)
5788         ;; Simultaneously uncompress and clip to active range
5789         ;; See gnus-uncompress-range for a description of possible marks
5790         (let (l lh)
5791           (if (not (cadr marks))
5792               (set var nil)
5793             (setq articles (if (numberp (cddr marks))
5794                                (list (cdr marks))
5795                              (cdr marks))
5796                   lh (cons nil nil)
5797                   l lh)
5798
5799             (while (setq article (pop articles))
5800               (cond ((consp article)
5801                      (setq bgn (max (car article) min)
5802                            end (min (cdr article) max))
5803                      (while (<= bgn end)
5804                        (setq l (setcdr l (cons bgn nil))
5805                              bgn (1+ bgn))))
5806                     ((and (<= min article)
5807                           (>= max article))
5808                      (setq l (setcdr l (cons article nil))))))
5809             (set var (cdr lh)))))
5810        ;; Adjust assocs.
5811        ((eq mark-type 'tuple)
5812         (set var (setq articles (cdr marks)))
5813         (when (not (listp (cdr (symbol-value var))))
5814           (set var (list (symbol-value var))))
5815         (when (not (listp (cdr articles)))
5816           (setq articles (list articles)))
5817         (while articles
5818           (when (or (not (consp (setq article (pop articles))))
5819                     (< (car article) min)
5820                     (> (car article) max))
5821             (set var (delq article (symbol-value var))))))
5822        ;; Adjust ranges (sloppily).
5823        ((eq mark-type 'range)
5824         (cond
5825          ((eq mark 'seen)
5826           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5827           ;; It should be (seen (NUM1 . NUM2)).
5828           (when (numberp (cddr marks))
5829             (setcdr marks (list (cdr marks))))
5830           (setq articles (cdr marks))
5831           (while (and articles
5832                       (or (and (consp (car articles))
5833                                (> min (cdar articles)))
5834                           (and (numberp (car articles))
5835                                (> min (car articles)))))
5836             (pop articles))
5837           (set var articles))))))))
5838
5839 (defun gnus-update-missing-marks (missing)
5840   "Go through the list of MISSING articles and remove them from the mark lists."
5841   (when missing
5842     (let (var m)
5843       ;; Go through all types.
5844       (dolist (elem gnus-article-mark-lists)
5845         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5846           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5847           (when (symbol-value var)
5848             ;; This list has articles.  So we delete all missing
5849             ;; articles from it.
5850             (setq m missing)
5851             (while m
5852               (set var (delq (pop m) (symbol-value var))))))))))
5853
5854 (defun gnus-update-marks ()
5855   "Enter the various lists of marked articles into the newsgroup info list."
5856   (let ((types gnus-article-mark-lists)
5857         (info (gnus-get-info gnus-newsgroup-name))
5858         type list newmarked symbol delta-marks)
5859     (when info
5860       ;; Add all marks lists to the list of marks lists.
5861       (while (setq type (pop types))
5862         (setq list (symbol-value
5863                     (setq symbol
5864                           (intern (format "gnus-newsgroup-%s" (car type))))))
5865
5866         (when list
5867           ;; Get rid of the entries of the articles that have the
5868           ;; default score.
5869           (when (and (eq (cdr type) 'score)
5870                      gnus-save-score
5871                      list)
5872             (let* ((arts list)
5873                    (prev (cons nil list))
5874                    (all prev))
5875               (while arts
5876                 (if (or (not (consp (car arts)))
5877                         (= (cdar arts) gnus-summary-default-score))
5878                     (setcdr prev (cdr arts))
5879                   (setq prev arts))
5880                 (setq arts (cdr arts)))
5881               (setq list (cdr all)))))
5882
5883         (when (eq (cdr type) 'seen)
5884           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5885
5886         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5887           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5888
5889         (when (and (gnus-check-backend-function
5890                     'request-set-mark gnus-newsgroup-name)
5891                    (not (gnus-article-unpropagatable-p (cdr type))))
5892           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5893                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5894                  (add (gnus-remove-from-range
5895                        (gnus-copy-sequence list) old)))
5896             (when add
5897               (push (list add 'add (list (cdr type))) delta-marks))
5898             (when del
5899               (push (list del 'del (list (cdr type))) delta-marks))))
5900
5901         (when list
5902           (push (cons (cdr type) list) newmarked)))
5903
5904       (when delta-marks
5905         (unless (gnus-check-group gnus-newsgroup-name)
5906           (error "Can't open server for %s" gnus-newsgroup-name))
5907         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5908
5909       ;; Enter these new marks into the info of the group.
5910       (if (nthcdr 3 info)
5911           (setcar (nthcdr 3 info) newmarked)
5912         ;; Add the marks lists to the end of the info.
5913         (when newmarked
5914           (setcdr (nthcdr 2 info) (list newmarked))))
5915
5916       ;; Cut off the end of the info if there's nothing else there.
5917       (let ((i 5))
5918         (while (and (> i 2)
5919                     (not (nth i info)))
5920           (when (nthcdr (decf i) info)
5921             (setcdr (nthcdr i info) nil)))))))
5922
5923 (defun gnus-set-mode-line (where)
5924   "Set the mode line of the article or summary buffers.
5925 If WHERE is `summary', the summary mode line format will be used."
5926   ;; Is this mode line one we keep updated?
5927   (when (and (memq where gnus-updated-mode-lines)
5928              (symbol-value
5929               (intern (format "gnus-%s-mode-line-format-spec" where))))
5930     (let (mode-string)
5931       (save-excursion
5932         ;; We evaluate this in the summary buffer since these
5933         ;; variables are buffer-local to that buffer.
5934         (set-buffer gnus-summary-buffer)
5935        ;; We bind all these variables that are used in the `eval' form
5936         ;; below.
5937         (let* ((mformat (symbol-value
5938                          (intern
5939                           (format "gnus-%s-mode-line-format-spec" where))))
5940                (gnus-tmp-group-name (gnus-mode-string-quote
5941                                      (gnus-group-decoded-name
5942                                       gnus-newsgroup-name)))
5943                (gnus-tmp-article-number (or gnus-current-article 0))
5944                (gnus-tmp-unread gnus-newsgroup-unreads)
5945                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5946                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5947                (gnus-tmp-unread-and-unselected
5948                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5949                             (zerop gnus-tmp-unselected))
5950                        "")
5951                       ((zerop gnus-tmp-unselected)
5952                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5953                       (t (format "{%d(+%d) more}"
5954                                  gnus-tmp-unread-and-unticked
5955                                  gnus-tmp-unselected))))
5956                (gnus-tmp-subject
5957                 (if (and gnus-current-headers
5958                          (vectorp gnus-current-headers))
5959                     (gnus-mode-string-quote
5960                      (mail-header-subject gnus-current-headers))
5961                   ""))
5962                bufname-length max-len
5963                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5964           (setq mode-string (eval mformat))
5965           (setq bufname-length (if (string-match "%b" mode-string)
5966                                    (- (length
5967                                        (buffer-name
5968                                         (if (eq where 'summary)
5969                                             nil
5970                                           (get-buffer gnus-article-buffer))))
5971                                       2)
5972                                  0))
5973           (setq max-len (max 4 (if gnus-mode-non-string-length
5974                                    (- (window-width)
5975                                       gnus-mode-non-string-length
5976                                       bufname-length)
5977                                  (length mode-string))))
5978           ;; We might have to chop a bit of the string off...
5979           (when (> (length mode-string) max-len)
5980             (setq mode-string
5981                   (concat (truncate-string-to-width mode-string (- max-len 3))
5982                           "...")))
5983           ;; Pad the mode string a bit.
5984           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5985       ;; Update the mode line.
5986       (setq mode-line-buffer-identification
5987             (gnus-mode-line-buffer-identification (list mode-string)))
5988       (set-buffer-modified-p t))))
5989
5990 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5991   "Go through the HEADERS list and add all Xrefs to a hash table.
5992 The resulting hash table is returned, or nil if no Xrefs were found."
5993   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5994          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5995          (xref-hashtb (gnus-make-hashtable))
5996          start group entry number xrefs header)
5997     (while headers
5998       (setq header (pop headers))
5999       (when (and (setq xrefs (mail-header-xref header))
6000                  (not (memq (setq number (mail-header-number header))
6001                             unreads)))
6002         (setq start 0)
6003         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6004           (setq start (match-end 0))
6005           (setq group (if prefix
6006                           (concat prefix (substring xrefs (match-beginning 1)
6007                                                     (match-end 1)))
6008                         (substring xrefs (match-beginning 1) (match-end 1))))
6009           (setq number
6010                 (string-to-number (substring xrefs (match-beginning 2)
6011                                           (match-end 2))))
6012           (if (setq entry (gnus-gethash group xref-hashtb))
6013               (setcdr entry (cons number (cdr entry)))
6014             (gnus-sethash group (cons number nil) xref-hashtb)))))
6015     (and start xref-hashtb)))
6016
6017 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6018   "Look through all the headers and mark the Xrefs as read."
6019   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6020         name info xref-hashtb idlist method nth4)
6021     (save-excursion
6022       (set-buffer gnus-group-buffer)
6023       (when (setq xref-hashtb
6024                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6025         (mapatoms
6026          (lambda (group)
6027            (unless (string= from-newsgroup (setq name (symbol-name group)))
6028              (setq idlist (symbol-value group))
6029              ;; Dead groups are not updated.
6030              (and (prog1
6031                       (setq info (gnus-get-info name))
6032                     (when (stringp (setq nth4 (gnus-info-method info)))
6033                       (setq nth4 (gnus-server-to-method nth4))))
6034                   ;; Only do the xrefs if the group has the same
6035                   ;; select method as the group we have just read.
6036                   (or (gnus-methods-equal-p
6037                        nth4 (gnus-find-method-for-group from-newsgroup))
6038                       virtual
6039                       (equal nth4 (setq method (gnus-find-method-for-group
6040                                                 from-newsgroup)))
6041                       (and (equal (car nth4) (car method))
6042                            (equal (nth 1 nth4) (nth 1 method))))
6043                   gnus-use-cross-reference
6044                   (or (not (eq gnus-use-cross-reference t))
6045                       virtual
6046                       ;; Only do cross-references on subscribed
6047                       ;; groups, if that is what is wanted.
6048                       (<= (gnus-info-level info) gnus-level-subscribed))
6049                   (gnus-group-make-articles-read name idlist))))
6050          xref-hashtb)))))
6051
6052 (defun gnus-compute-read-articles (group articles)
6053   (let* ((entry (gnus-group-entry group))
6054          (info (nth 2 entry))
6055          (active (gnus-active group))
6056          ninfo)
6057     (when entry
6058       ;; First peel off all invalid article numbers.
6059       (when active
6060         (let ((ids articles)
6061               id first)
6062           (while (setq id (pop ids))
6063             (when (and first (> id (cdr active)))
6064               ;; We'll end up in this situation in one particular
6065               ;; obscure situation.  If you re-scan a group and get
6066               ;; a new article that is cross-posted to a different
6067               ;; group that has not been re-scanned, you might get
6068               ;; crossposted article that has a higher number than
6069               ;; Gnus believes possible.  So we re-activate this
6070               ;; group as well.  This might mean doing the
6071               ;; crossposting thingy will *increase* the number
6072               ;; of articles in some groups.  Tsk, tsk.
6073               (setq active (or (gnus-activate-group group) active)))
6074             (when (or (> id (cdr active))
6075                       (< id (car active)))
6076               (setq articles (delq id articles))))))
6077       ;; If the read list is nil, we init it.
6078       (if (and active
6079                (null (gnus-info-read info))
6080                (> (car active) 1))
6081           (setq ninfo (cons 1 (1- (car active))))
6082         (setq ninfo (gnus-info-read info)))
6083       ;; Then we add the read articles to the range.
6084       (gnus-add-to-range
6085        ninfo (setq articles (sort articles '<))))))
6086
6087 (defun gnus-group-make-articles-read (group articles)
6088   "Update the info of GROUP to say that ARTICLES are read."
6089   (let* ((num 0)
6090          (entry (gnus-group-entry group))
6091          (info (nth 2 entry))
6092          (active (gnus-active group))
6093          range)
6094     (when entry
6095       (setq range (gnus-compute-read-articles group articles))
6096       (with-current-buffer gnus-group-buffer
6097         (gnus-undo-register
6098           `(progn
6099              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6100              (gnus-info-set-read ',info ',(gnus-info-read info))
6101              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6102              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6103              (gnus-group-update-group ,group t))))
6104       ;; Add the read articles to the range.
6105       (gnus-info-set-read info range)
6106       (gnus-request-set-mark group (list (list range 'add '(read))))
6107       ;; Then we have to re-compute how many unread
6108       ;; articles there are in this group.
6109       (when active
6110         (cond
6111          ((not range)
6112           (setq num (- (1+ (cdr active)) (car active))))
6113          ((not (listp (cdr range)))
6114           (setq num (- (cdr active) (- (1+ (cdr range))
6115                                        (car range)))))
6116          (t
6117           (while range
6118             (if (numberp (car range))
6119                 (setq num (1+ num))
6120               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6121             (setq range (cdr range)))
6122           (setq num (- (cdr active) num))))
6123         ;; Update the number of unread articles.
6124         (setcar entry num)
6125         ;; Update the group buffer.
6126         (unless (gnus-ephemeral-group-p group)
6127           (gnus-group-update-group group t))))))
6128
6129 (defvar gnus-newsgroup-none-id 0)
6130
6131 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6132   (let ((cur nntp-server-buffer)
6133         (dependencies
6134          (or dependencies
6135              (with-current-buffer gnus-summary-buffer
6136                gnus-newsgroup-dependencies)))
6137         headers id end ref number
6138         (mail-parse-charset gnus-newsgroup-charset)
6139         (mail-parse-ignored-charsets
6140          (save-excursion (condition-case nil
6141                              (set-buffer gnus-summary-buffer)
6142                            (error))
6143                          gnus-newsgroup-ignored-charsets)))
6144     (save-excursion
6145       (set-buffer nntp-server-buffer)
6146       ;; Translate all TAB characters into SPACE characters.
6147       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6148       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6149       (ietf-drums-unfold-fws)
6150       (gnus-run-hooks 'gnus-parse-headers-hook)
6151       (let ((case-fold-search t)
6152             in-reply-to header p lines chars)
6153         (goto-char (point-min))
6154         ;; Search to the beginning of the next header.  Error messages
6155         ;; do not begin with 2 or 3.
6156         (while (re-search-forward "^[23][0-9]+ " nil t)
6157           (setq id nil
6158                 ref nil)
6159           ;; This implementation of this function, with nine
6160           ;; search-forwards instead of the one re-search-forward and
6161           ;; a case (which basically was the old function) is actually
6162           ;; about twice as fast, even though it looks messier.  You
6163           ;; can't have everything, I guess.  Speed and elegance
6164           ;; doesn't always go hand in hand.
6165           (setq
6166            header
6167            (vector
6168             ;; Number.
6169             (prog1
6170                 (setq number (read cur))
6171               (end-of-line)
6172               (setq p (point))
6173               (narrow-to-region (point)
6174                                 (or (and (search-forward "\n.\n" nil t)
6175                                          (- (point) 2))
6176                                     (point))))
6177             ;; Subject.
6178             (progn
6179               (goto-char p)
6180               (if (search-forward "\nsubject:" nil t)
6181                   (funcall gnus-decode-encoded-word-function
6182                            (nnheader-header-value))
6183                 "(none)"))
6184             ;; From.
6185             (progn
6186               (goto-char p)
6187               (if (search-forward "\nfrom:" nil t)
6188                   (funcall gnus-decode-encoded-address-function
6189                            (nnheader-header-value))
6190                 "(nobody)"))
6191             ;; Date.
6192             (progn
6193               (goto-char p)
6194               (if (search-forward "\ndate:" nil t)
6195                   (nnheader-header-value) ""))
6196             ;; Message-ID.
6197             (progn
6198               (goto-char p)
6199               (setq id (if (re-search-forward
6200                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6201                            ;; We do it this way to make sure the Message-ID
6202                            ;; is (somewhat) syntactically valid.
6203                            (buffer-substring (match-beginning 1)
6204                                              (match-end 1))
6205                          ;; If there was no message-id, we just fake one
6206                          ;; to make subsequent routines simpler.
6207                          (nnheader-generate-fake-message-id number))))
6208             ;; References.
6209             (progn
6210               (goto-char p)
6211               (if (search-forward "\nreferences:" nil t)
6212                   (progn
6213                     (setq end (point))
6214                     (prog1
6215                         (nnheader-header-value)
6216                       (setq ref
6217                             (buffer-substring
6218                              (progn
6219                                (end-of-line)
6220                                (search-backward ">" end t)
6221                                (1+ (point)))
6222                              (progn
6223                                (search-backward "<" end t)
6224                                (point))))))
6225                 ;; Get the references from the in-reply-to header if there
6226                 ;; were no references and the in-reply-to header looks
6227                 ;; promising.
6228                 (if (and (search-forward "\nin-reply-to:" nil t)
6229                          (setq in-reply-to (nnheader-header-value))
6230                          (string-match "<[^>]+>" in-reply-to))
6231                     (let (ref2)
6232                       (setq ref (substring in-reply-to (match-beginning 0)
6233                                            (match-end 0)))
6234                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6235                         (setq ref2 (substring in-reply-to (match-beginning 0)
6236                                               (match-end 0)))
6237                         (when (> (length ref2) (length ref))
6238                           (setq ref ref2)))
6239                       ref)
6240                   (setq ref nil))))
6241             ;; Chars.
6242             (progn
6243               (goto-char p)
6244               (if (search-forward "\nchars: " nil t)
6245                   (if (numberp (setq chars (ignore-errors (read cur))))
6246                       chars -1)
6247                 -1))
6248             ;; Lines.
6249             (progn
6250               (goto-char p)
6251               (if (search-forward "\nlines: " nil t)
6252                   (if (numberp (setq lines (ignore-errors (read cur))))
6253                       lines -1)
6254                 -1))
6255             ;; Xref.
6256             (progn
6257               (goto-char p)
6258               (and (search-forward "\nxref:" nil t)
6259                    (nnheader-header-value)))
6260             ;; Extra.
6261             (when gnus-extra-headers
6262               (let ((extra gnus-extra-headers)
6263                     out)
6264                 (while extra
6265                   (goto-char p)
6266                   (when (search-forward
6267                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6268                     (push (cons (car extra) (nnheader-header-value))
6269                           out))
6270                   (pop extra))
6271                 out))))
6272           (when (equal id ref)
6273             (setq ref nil))
6274
6275           (when gnus-alter-header-function
6276             (funcall gnus-alter-header-function header)
6277             (setq id (mail-header-id header)
6278                   ref (gnus-parent-id (mail-header-references header))))
6279
6280           (when (setq header
6281                       (gnus-dependencies-add-header
6282                        header dependencies force-new))
6283             (push header headers))
6284           (goto-char (point-max))
6285           (widen))
6286         (nreverse headers)))))
6287
6288 ;; Goes through the xover lines and returns a list of vectors
6289 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6290                                                   force-new dependencies
6291                                                   group also-fetch-heads)
6292   "Parse the news overview data in the server buffer.
6293 Return a list of headers that match SEQUENCE (see
6294 `nntp-retrieve-headers')."
6295   ;; Get the Xref when the users reads the articles since most/some
6296   ;; NNTP servers do not include Xrefs when using XOVER.
6297   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6298   (let ((mail-parse-charset gnus-newsgroup-charset)
6299         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6300         (cur nntp-server-buffer)
6301         (dependencies (or dependencies gnus-newsgroup-dependencies))
6302         (allp (cond
6303                ((eq gnus-read-all-available-headers t)
6304                 t)
6305                ((and (stringp gnus-read-all-available-headers)
6306                      group)
6307                 (string-match gnus-read-all-available-headers group))
6308                (t
6309                 nil)))
6310         number headers header)
6311     (save-excursion
6312       (set-buffer nntp-server-buffer)
6313       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6314       ;; Allow the user to mangle the headers before parsing them.
6315       (gnus-run-hooks 'gnus-parse-headers-hook)
6316       (goto-char (point-min))
6317       (gnus-parse-without-error
6318         (while (and (or sequence allp)
6319                     (not (eobp)))
6320           (setq number (read cur))
6321           (when (not allp)
6322             (while (and sequence
6323                         (< (car sequence) number))
6324               (setq sequence (cdr sequence))))
6325           (when (and (or allp
6326                          (and sequence
6327                               (eq number (car sequence))))
6328                      (progn
6329                        (setq sequence (cdr sequence))
6330                        (setq header (inline
6331                                       (gnus-nov-parse-line
6332                                        number dependencies force-new)))))
6333             (push header headers))
6334           (forward-line 1)))
6335       ;; A common bug in inn is that if you have posted an article and
6336       ;; then retrieves the active file, it will answer correctly --
6337       ;; the new article is included.  However, a NOV entry for the
6338       ;; article may not have been generated yet, so this may fail.
6339       ;; We work around this problem by retrieving the last few
6340       ;; headers using HEAD.
6341       (if (or (not also-fetch-heads)
6342               (not sequence))
6343           ;; We (probably) got all the headers.
6344           (nreverse headers)
6345         (let ((gnus-nov-is-evil t))
6346           (nconc
6347            (nreverse headers)
6348            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6349              (gnus-get-newsgroup-headers))))))))
6350
6351 (defun gnus-article-get-xrefs ()
6352   "Fill in the Xref value in `gnus-current-headers', if necessary.
6353 This is meant to be called in `gnus-article-internal-prepare-hook'."
6354   (let ((headers (with-current-buffer gnus-summary-buffer
6355                    gnus-current-headers)))
6356     (or (not gnus-use-cross-reference)
6357         (not headers)
6358         (and (mail-header-xref headers)
6359              (not (string= (mail-header-xref headers) "")))
6360         (let ((case-fold-search t)
6361               xref)
6362           (save-restriction
6363             (nnheader-narrow-to-headers)
6364             (goto-char (point-min))
6365             (when (or (and (not (eobp))
6366                            (eq (downcase (char-after)) ?x)
6367                            (looking-at "Xref:"))
6368                       (search-forward "\nXref:" nil t))
6369               (goto-char (1+ (match-end 0)))
6370               (setq xref (buffer-substring (point) (point-at-eol)))
6371               (mail-header-set-xref headers xref)))))))
6372
6373 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6374   "Find article ID and insert the summary line for that article.
6375 OLD-HEADER can either be a header or a line number to insert
6376 the subject line on."
6377   (let* ((line (and (numberp old-header) old-header))
6378          (old-header (and (vectorp old-header) old-header))
6379          (header (cond ((and old-header use-old-header)
6380                         old-header)
6381                        ((and (numberp id)
6382                              (gnus-number-to-header id))
6383                         (gnus-number-to-header id))
6384                        (t
6385                         (gnus-read-header id))))
6386          (number (and (numberp id) id))
6387          d)
6388     (when header
6389       ;; Rebuild the thread that this article is part of and go to the
6390       ;; article we have fetched.
6391       (when (and (not gnus-show-threads)
6392                  old-header)
6393         (when (and number
6394                    (setq d (gnus-data-find (mail-header-number old-header))))
6395           (goto-char (gnus-data-pos d))
6396           (gnus-data-remove
6397            number
6398            (- (point-at-bol)
6399               (prog1
6400                   (1+ (point-at-eol))
6401                 (gnus-delete-line))))))
6402       ;; Remove list identifiers from subject.
6403       (when gnus-list-identifiers
6404         (let ((gnus-newsgroup-headers (list header)))
6405           (gnus-summary-remove-list-identifiers)))
6406       (when old-header
6407         (mail-header-set-number header (mail-header-number old-header)))
6408       (setq gnus-newsgroup-sparse
6409             (delq (setq number (mail-header-number header))
6410                   gnus-newsgroup-sparse))
6411       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6412       (push number gnus-newsgroup-limit)
6413       (gnus-rebuild-thread (mail-header-id header) line)
6414       (gnus-summary-goto-subject number nil t))
6415     (when (and (numberp number)
6416                (> number 0))
6417       ;; We have to update the boundaries even if we can't fetch the
6418       ;; article if ID is a number -- so that the next `P' or `N'
6419       ;; command will fetch the previous (or next) article even
6420       ;; if the one we tried to fetch this time has been canceled.
6421       (when (> number gnus-newsgroup-end)
6422         (setq gnus-newsgroup-end number))
6423       (when (< number gnus-newsgroup-begin)
6424         (setq gnus-newsgroup-begin number))
6425       (setq gnus-newsgroup-unselected
6426             (delq number gnus-newsgroup-unselected)))
6427     ;; Report back a success?
6428     (and header (mail-header-number header))))
6429
6430 ;;; Process/prefix in the summary buffer
6431
6432 (defun gnus-summary-work-articles (n)
6433   "Return a list of articles to be worked upon.
6434 The prefix argument, the list of process marked articles, and the
6435 current article will be taken into consideration."
6436   (save-excursion
6437     (set-buffer gnus-summary-buffer)
6438     (cond
6439      (n
6440       ;; A numerical prefix has been given.
6441       (setq n (prefix-numeric-value n))
6442       (let ((backward (< n 0))
6443             (n (abs (prefix-numeric-value n)))
6444             articles article)
6445         (save-excursion
6446           (while
6447               (and (> n 0)
6448                    (push (setq article (gnus-summary-article-number))
6449                          articles)
6450                    (if backward
6451                        (gnus-summary-find-prev nil article)
6452                      (gnus-summary-find-next nil article)))
6453             (decf n)))
6454         (nreverse articles)))
6455      ((and (gnus-region-active-p) (mark))
6456       (message "region active")
6457       ;; Work on the region between point and mark.
6458       (let ((max (max (point) (mark)))
6459             articles article)
6460         (save-excursion
6461           (goto-char (min (point) (mark)))
6462           (while
6463               (and
6464                (push (setq article (gnus-summary-article-number)) articles)
6465                (gnus-summary-find-next nil article)
6466                (< (point) max)))
6467           (nreverse articles))))
6468      (gnus-newsgroup-processable
6469       ;; There are process-marked articles present.
6470       ;; Save current state.
6471       (gnus-summary-save-process-mark)
6472       ;; Return the list.
6473       (reverse gnus-newsgroup-processable))
6474      (t
6475       ;; Just return the current article.
6476       (list (gnus-summary-article-number))))))
6477
6478 (defmacro gnus-summary-iterate (arg &rest forms)
6479   "Iterate over the process/prefixed articles and do FORMS.
6480 ARG is the interactive prefix given to the command.  FORMS will be
6481 executed with point over the summary line of the articles."
6482   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6483     `(let ((,articles (gnus-summary-work-articles ,arg)))
6484        (while ,articles
6485          (gnus-summary-goto-subject (car ,articles))
6486          ,@forms
6487          (pop ,articles)))))
6488
6489 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6490 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6491
6492 (defun gnus-summary-save-process-mark ()
6493   "Push the current set of process marked articles on the stack."
6494   (interactive)
6495   (push (copy-sequence gnus-newsgroup-processable)
6496         gnus-newsgroup-process-stack))
6497
6498 (defun gnus-summary-kill-process-mark ()
6499   "Push the current set of process marked articles on the stack and unmark."
6500   (interactive)
6501   (gnus-summary-save-process-mark)
6502   (gnus-summary-unmark-all-processable))
6503
6504 (defun gnus-summary-yank-process-mark ()
6505   "Pop the last process mark state off the stack and restore it."
6506   (interactive)
6507   (unless gnus-newsgroup-process-stack
6508     (error "Empty mark stack"))
6509   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6510
6511 (defun gnus-summary-process-mark-set (set)
6512   "Make SET into the current process marked articles."
6513   (gnus-summary-unmark-all-processable)
6514   (mapc 'gnus-summary-set-process-mark set))
6515
6516 ;;; Searching and stuff
6517
6518 (defun gnus-summary-search-group (&optional backward use-level)
6519   "Search for next unread newsgroup.
6520 If optional argument BACKWARD is non-nil, search backward instead."
6521   (save-excursion
6522     (set-buffer gnus-group-buffer)
6523     (when (gnus-group-search-forward
6524            backward nil (if use-level (gnus-group-group-level) nil))
6525       (gnus-group-group-name))))
6526
6527 (defun gnus-summary-best-group (&optional exclude-group)
6528   "Find the name of the best unread group.
6529 If EXCLUDE-GROUP, do not go to this group."
6530   (with-current-buffer gnus-group-buffer
6531     (save-excursion
6532       (gnus-group-best-unread-group exclude-group))))
6533
6534 (defun gnus-summary-find-next (&optional unread article backward)
6535   (if backward
6536       (gnus-summary-find-prev unread article)
6537     (let* ((dummy (gnus-summary-article-intangible-p))
6538            (article (or article (gnus-summary-article-number)))
6539            (data (gnus-data-find-list article))
6540            result)
6541       (when (and (not dummy)
6542                  (or (not gnus-summary-check-current)
6543                      (not unread)
6544                      (not (gnus-data-unread-p (car data)))))
6545         (setq data (cdr data)))
6546       (when (setq result
6547                   (if unread
6548                       (progn
6549                         (while data
6550                           (unless (memq (gnus-data-number (car data))
6551                                         (cond
6552                                          ((eq gnus-auto-goto-ignores
6553                                               'always-undownloaded)
6554                                           gnus-newsgroup-undownloaded)
6555                                          (gnus-plugged
6556                                           nil)
6557                                          ((eq gnus-auto-goto-ignores
6558                                               'unfetched)
6559                                           gnus-newsgroup-unfetched)
6560                                          ((eq gnus-auto-goto-ignores
6561                                               'undownloaded)
6562                                           gnus-newsgroup-undownloaded)))
6563                             (when (gnus-data-unread-p (car data))
6564                               (setq result (car data)
6565                                     data nil)))
6566                           (setq data (cdr data)))
6567                         result)
6568                     (car data)))
6569         (goto-char (gnus-data-pos result))
6570         (gnus-data-number result)))))
6571
6572 (defun gnus-summary-find-prev (&optional unread article)
6573   (let* ((eobp (eobp))
6574          (article (or article (gnus-summary-article-number)))
6575          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6576          result)
6577     (when (and (not eobp)
6578                (or (not gnus-summary-check-current)
6579                    (not unread)
6580                    (not (gnus-data-unread-p (car data)))))
6581       (setq data (cdr data)))
6582     (when (setq result
6583                 (if unread
6584                     (progn
6585                       (while data
6586                         (unless (memq (gnus-data-number (car data))
6587                                       (cond
6588                                        ((eq gnus-auto-goto-ignores
6589                                             'always-undownloaded)
6590                                         gnus-newsgroup-undownloaded)
6591                                        (gnus-plugged
6592                                         nil)
6593                                        ((eq gnus-auto-goto-ignores
6594                                             'unfetched)
6595                                         gnus-newsgroup-unfetched)
6596                                        ((eq gnus-auto-goto-ignores
6597                                             'undownloaded)
6598                                         gnus-newsgroup-undownloaded)))
6599                           (when (gnus-data-unread-p (car data))
6600                             (setq result (car data)
6601                                   data nil)))
6602                         (setq data (cdr data)))
6603                       result)
6604                   (car data)))
6605       (goto-char (gnus-data-pos result))
6606       (gnus-data-number result))))
6607
6608 (defun gnus-summary-find-subject (subject &optional unread backward article)
6609   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6610          (article (or article (gnus-summary-article-number)))
6611          (articles (gnus-data-list backward))
6612          (arts (gnus-data-find-list article articles))
6613          result)
6614     (when (or (not gnus-summary-check-current)
6615               (not unread)
6616               (not (gnus-data-unread-p (car arts))))
6617       (setq arts (cdr arts)))
6618     (while arts
6619       (and (or (not unread)
6620                (gnus-data-unread-p (car arts)))
6621            (vectorp (gnus-data-header (car arts)))
6622            (gnus-subject-equal
6623             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6624            (setq result (car arts)
6625                  arts nil))
6626       (setq arts (cdr arts)))
6627     (and result
6628          (goto-char (gnus-data-pos result))
6629          (gnus-data-number result))))
6630
6631 (defun gnus-summary-search-forward (&optional unread subject backward)
6632   "Search forward for an article.
6633 If UNREAD, look for unread articles.  If SUBJECT, look for
6634 articles with that subject.  If BACKWARD, search backward instead."
6635   (cond (subject (gnus-summary-find-subject subject unread backward))
6636         (backward (gnus-summary-find-prev unread))
6637         (t (gnus-summary-find-next unread))))
6638
6639 (defun gnus-recenter (&optional n)
6640   "Center point in window and redisplay frame.
6641 Also do horizontal recentering."
6642   (interactive "P")
6643   (when (and gnus-auto-center-summary
6644              (not (eq gnus-auto-center-summary 'vertical)))
6645     (gnus-horizontal-recenter))
6646   (recenter n))
6647
6648 (defun gnus-summary-recenter ()
6649   "Center point in the summary window.
6650 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6651 displayed, no centering will be performed."
6652   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6653   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6654   (interactive)
6655   ;; The user has to want it.
6656   (when gnus-auto-center-summary
6657     (let* ((top (cond ((< (window-height) 4) 0)
6658                       ((< (window-height) 7) 1)
6659                       (t (if (numberp gnus-auto-center-summary)
6660                              gnus-auto-center-summary
6661                            (/ (1- (window-height)) 2)))))
6662            (height (1- (window-height)))
6663            (bottom (save-excursion (goto-char (point-max))
6664                                    (forward-line (- height))
6665                                    (point)))
6666            (window (get-buffer-window (current-buffer))))
6667       (when (get-buffer-window gnus-article-buffer)
6668         ;; Only do recentering when the article buffer is displayed,
6669         ;; Set the window start to either `bottom', which is the biggest
6670         ;; possible valid number, or the second line from the top,
6671         ;; whichever is the least.
6672         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6673           (if (> bottom top-pos)
6674               ;; Keep the second line from the top visible
6675               (set-window-start window top-pos)
6676             ;; Try to keep the bottom line visible; if it's partially
6677             ;; obscured, either scroll one more line to make it fully
6678             ;; visible, or revert to using TOP-POS.
6679             (save-excursion
6680               (goto-char (point-max))
6681               (forward-line -1)
6682               (let ((last-line-start (point)))
6683                 (goto-char bottom)
6684                 (set-window-start window (point) t)
6685                 (when (not (pos-visible-in-window-p last-line-start window))
6686                   (forward-line 1)
6687                   (set-window-start window (min (point) top-pos) t)))))))
6688       ;; Do horizontal recentering while we're at it.
6689       (when (and (get-buffer-window (current-buffer) t)
6690                  (not (eq gnus-auto-center-summary 'vertical)))
6691         (let ((selected (selected-window)))
6692           (select-window (get-buffer-window (current-buffer) t))
6693           (gnus-summary-position-point)
6694           (gnus-horizontal-recenter)
6695           (select-window selected))))))
6696
6697 (defun gnus-summary-jump-to-group (newsgroup)
6698   "Move point to NEWSGROUP in group mode buffer."
6699   ;; Keep update point of group mode buffer if visible.
6700   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6701       (save-window-excursion
6702         ;; Take care of tree window mode.
6703         (when (get-buffer-window gnus-group-buffer)
6704           (pop-to-buffer gnus-group-buffer))
6705         (gnus-group-jump-to-group newsgroup))
6706     (save-excursion
6707       ;; Take care of tree window mode.
6708       (if (get-buffer-window gnus-group-buffer)
6709           (pop-to-buffer gnus-group-buffer)
6710         (set-buffer gnus-group-buffer))
6711       (gnus-group-jump-to-group newsgroup))))
6712
6713 ;; This function returns a list of article numbers based on the
6714 ;; difference between the ranges of read articles in this group and
6715 ;; the range of active articles.
6716 (defun gnus-list-of-unread-articles (group)
6717   (let* ((read (gnus-info-read (gnus-get-info group)))
6718          (active (or (gnus-active group) (gnus-activate-group group)))
6719          (last (or (cdr active)
6720                    (error "Group %s couldn't be activated " group)))
6721          (bottom (if gnus-newsgroup-maximum-articles
6722                      (max (car active)
6723                           (- last gnus-newsgroup-maximum-articles -1))
6724                    (car active)))
6725          first nlast unread)
6726     ;; If none are read, then all are unread.
6727     (if (not read)
6728         (setq first bottom)
6729       ;; If the range of read articles is a single range, then the
6730       ;; first unread article is the article after the last read
6731       ;; article.  Sounds logical, doesn't it?
6732       (if (and (not (listp (cdr read)))
6733                (or (< (car read) bottom)
6734                    (progn (setq read (list read))
6735                           nil)))
6736           (setq first (max bottom (1+ (cdr read))))
6737         ;; `read' is a list of ranges.
6738         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6739                                   (caar read)))
6740                   1)
6741           (setq first bottom))
6742         (while read
6743           (when first
6744             (while (< first nlast)
6745               (setq unread (cons first unread)
6746                     first (1+ first))))
6747           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6748           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6749           (setq read (cdr read)))))
6750     ;; And add the last unread articles.
6751     (while (<= first last)
6752       (setq unread (cons first unread)
6753             first (1+ first)))
6754     ;; Return the list of unread articles.
6755     (delq 0 (nreverse unread))))
6756
6757 (defun gnus-list-of-read-articles (group)
6758   "Return a list of unread, unticked and non-dormant articles."
6759   (let* ((info (gnus-get-info group))
6760          (marked (gnus-info-marks info))
6761          (active (gnus-active group)))
6762     (and info active
6763          (gnus-list-range-difference
6764           (gnus-list-range-difference
6765            (gnus-sorted-complement
6766             (gnus-uncompress-range
6767              (if gnus-newsgroup-maximum-articles
6768                  (cons (max (car active)
6769                             (- (cdr active)
6770                                gnus-newsgroup-maximum-articles
6771                                -1))
6772                        (cdr active))
6773                active))
6774             (gnus-list-of-unread-articles group))
6775            (cdr (assq 'dormant marked)))
6776           (cdr (assq 'tick marked))))))
6777
6778 ;; This function returns a sequence of article numbers based on the
6779 ;; difference between the ranges of read articles in this group and
6780 ;; the range of active articles.
6781 (defun gnus-sequence-of-unread-articles (group)
6782   (let* ((read (gnus-info-read (gnus-get-info group)))
6783          (active (or (gnus-active group) (gnus-activate-group group)))
6784          (last (cdr active))
6785          (bottom (if gnus-newsgroup-maximum-articles
6786                      (max (car active)
6787                           (- last gnus-newsgroup-maximum-articles -1))
6788                    (car active)))
6789          first nlast unread)
6790     ;; If none are read, then all are unread.
6791     (if (not read)
6792         (setq first bottom)
6793       ;; If the range of read articles is a single range, then the
6794       ;; first unread article is the article after the last read
6795       ;; article.  Sounds logical, doesn't it?
6796       (if (and (not (listp (cdr read)))
6797                (or (< (car read) bottom)
6798                    (progn (setq read (list read))
6799                           nil)))
6800           (setq first (max bottom (1+ (cdr read))))
6801         ;; `read' is a list of ranges.
6802         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6803                                   (caar read)))
6804                   1)
6805           (setq first bottom))
6806         (while read
6807           (when first
6808             (push (cons first nlast) unread))
6809           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6810           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6811           (setq read (cdr read)))))
6812     ;; And add the last unread articles.
6813     (cond ((not (and first last))
6814            nil)
6815           ((< first last)
6816            (push (cons first last) unread))
6817           ((= first last)
6818            (push first unread)))
6819     ;; Return the sequence of unread articles.
6820     (delq 0 (nreverse unread))))
6821
6822 ;; Various summary commands
6823
6824 (defun gnus-summary-select-article-buffer ()
6825   "Reconfigure windows to show article buffer."
6826   (interactive)
6827   (if (not (gnus-buffer-live-p gnus-article-buffer))
6828       (error "There is no article buffer for this summary buffer")
6829     (gnus-configure-windows 'article)
6830     (select-window (get-buffer-window gnus-article-buffer))))
6831
6832 (defun gnus-summary-universal-argument (arg)
6833   "Perform any operation on all articles that are process/prefixed."
6834   (interactive "P")
6835   (let ((articles (gnus-summary-work-articles arg))
6836         func article)
6837     (if (eq
6838          (setq
6839           func
6840           (key-binding
6841            (read-key-sequence
6842             (substitute-command-keys
6843              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6844          'undefined)
6845         (gnus-error 1 "Undefined key")
6846       (save-excursion
6847         (while articles
6848           (gnus-summary-goto-subject (setq article (pop articles)))
6849           (let (gnus-newsgroup-processable)
6850             (command-execute func))
6851           (gnus-summary-remove-process-mark article)))))
6852   (gnus-summary-position-point))
6853
6854 (defun gnus-summary-toggle-truncation (&optional arg)
6855   "Toggle truncation of summary lines.
6856 With ARG, turn line truncation on if ARG is positive."
6857   (interactive "P")
6858   (setq truncate-lines
6859         (if (null arg) (not truncate-lines)
6860           (> (prefix-numeric-value arg) 0)))
6861   (redraw-display))
6862
6863 (defun gnus-summary-find-for-reselect ()
6864   "Return the number of an article to stay on across a reselect.
6865 The current article is considered, then following articles, then previous
6866 articles.  An article is sought which is not cancelled and isn't a temporary
6867 insertion from another group.  If there's no such then return a dummy 0."
6868   (let (found)
6869     (dolist (rev '(nil t))
6870       (unless found      ; don't demand the reverse list if we don't need it
6871         (let ((data (gnus-data-find-list
6872                      (gnus-summary-article-number) (gnus-data-list rev))))
6873           (while (and data (not found))
6874             (if (and (< 0 (gnus-data-number (car data)))
6875                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6876                 (setq found (gnus-data-number (car data))))
6877             (setq data (cdr data))))))
6878     (or found 0)))
6879
6880 (defun gnus-summary-reselect-current-group (&optional all rescan)
6881   "Exit and then reselect the current newsgroup.
6882 The prefix argument ALL means to select all articles."
6883   (interactive "P")
6884   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6885     (error "Ephemeral groups can't be reselected"))
6886   (let ((current-subject (gnus-summary-find-for-reselect))
6887         (group gnus-newsgroup-name))
6888     (setq gnus-newsgroup-begin nil)
6889     (gnus-summary-exit nil 'leave-hidden)
6890     ;; We have to adjust the point of group mode buffer because
6891     ;; point was moved to the next unread newsgroup by exiting.
6892     (gnus-summary-jump-to-group group)
6893     (when rescan
6894       (save-excursion
6895         (gnus-group-get-new-news-this-group 1)))
6896     (gnus-group-read-group all t)
6897     (gnus-summary-goto-subject current-subject nil t)))
6898
6899 (defun gnus-summary-rescan-group (&optional all)
6900   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6901   (interactive "P")
6902   (gnus-summary-reselect-current-group all t))
6903
6904 (defun gnus-summary-update-info (&optional non-destructive)
6905   (save-excursion
6906     (let ((group gnus-newsgroup-name))
6907       (when group
6908         (when gnus-newsgroup-kill-headers
6909           (setq gnus-newsgroup-killed
6910                 (gnus-compress-sequence
6911                  (gnus-sorted-union
6912                   (gnus-list-range-intersection
6913                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6914                   gnus-newsgroup-unreads)
6915                  t)))
6916         (unless (listp (cdr gnus-newsgroup-killed))
6917           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6918         (let ((headers gnus-newsgroup-headers))
6919           ;; Set the new ranges of read articles.
6920           (with-current-buffer gnus-group-buffer
6921             (gnus-undo-force-boundary))
6922           (gnus-update-read-articles
6923            group (gnus-sorted-union
6924                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6925           ;; Set the current article marks.
6926           (let ((gnus-newsgroup-scored
6927                  (if (and (not gnus-save-score)
6928                           (not non-destructive))
6929                      nil
6930                    gnus-newsgroup-scored)))
6931             (save-excursion
6932               (gnus-update-marks)))
6933           ;; Do the cross-ref thing.
6934           (when gnus-use-cross-reference
6935             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6936           ;; Do not switch windows but change the buffer to work.
6937           (set-buffer gnus-group-buffer)
6938           (unless (gnus-ephemeral-group-p group)
6939             (gnus-group-update-group group)))))))
6940
6941 (defun gnus-summary-save-newsrc (&optional force)
6942   "Save the current number of read/marked articles in the dribble buffer.
6943 The dribble buffer will then be saved.
6944 If FORCE (the prefix), also save the .newsrc file(s)."
6945   (interactive "P")
6946   (gnus-summary-update-info t)
6947   (if force
6948       (gnus-save-newsrc-file)
6949     (gnus-dribble-save)))
6950
6951 (defun gnus-summary-exit (&optional temporary leave-hidden)
6952   "Exit reading current newsgroup, and then return to group selection mode.
6953 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6954   (interactive)
6955   (gnus-set-global-variables)
6956   (when (gnus-buffer-live-p gnus-article-buffer)
6957     (save-excursion
6958       (set-buffer gnus-article-buffer)
6959       (mm-destroy-parts gnus-article-mime-handles)
6960       ;; Set it to nil for safety reason.
6961       (setq gnus-article-mime-handle-alist nil)
6962       (setq gnus-article-mime-handles nil)))
6963   (gnus-kill-save-kill-buffer)
6964   (gnus-async-halt-prefetch)
6965   (let* ((group gnus-newsgroup-name)
6966          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6967          (gnus-group-is-exiting-p t)
6968          (mode major-mode)
6969          (group-point nil)
6970          (buf (current-buffer)))
6971     (unless quit-config
6972       ;; Do adaptive scoring, and possibly save score files.
6973       (when gnus-newsgroup-adaptive
6974         (gnus-score-adaptive))
6975       (when gnus-use-scoring
6976         (gnus-score-save)))
6977     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6978     ;; If we have several article buffers, we kill them at exit.
6979     (unless gnus-single-article-buffer
6980       (when (gnus-buffer-live-p gnus-article-buffer)
6981         (with-current-buffer gnus-article-buffer
6982           ;; Don't kill sticky article buffers
6983           (unless (eq major-mode 'gnus-sticky-article-mode)
6984             (gnus-kill-buffer gnus-article-buffer)
6985             (setq gnus-article-current nil))))
6986       (gnus-kill-buffer gnus-original-article-buffer))
6987     (when gnus-use-cache
6988       (gnus-cache-possibly-remove-articles)
6989       (gnus-cache-save-buffers))
6990     (gnus-async-prefetch-remove-group group)
6991     (when gnus-suppress-duplicates
6992       (gnus-dup-enter-articles))
6993     (when gnus-use-trees
6994       (gnus-tree-close group))
6995     (when gnus-use-cache
6996       (gnus-cache-write-active))
6997     ;; Remove entries for this group.
6998     (nnmail-purge-split-history (gnus-group-real-name group))
6999     ;; Make all changes in this group permanent.
7000     (unless quit-config
7001       (gnus-run-hooks 'gnus-exit-group-hook)
7002       (gnus-summary-update-info))
7003     (gnus-close-group group)
7004     ;; Make sure where we were, and go to next newsgroup.
7005     (set-buffer gnus-group-buffer)
7006     (unless quit-config
7007       (gnus-group-jump-to-group group))
7008     (gnus-run-hooks 'gnus-summary-exit-hook)
7009     (unless (or quit-config
7010                 (not gnus-summary-next-group-on-exit)
7011                 ;; If this group has disappeared from the summary
7012                 ;; buffer, don't skip forwards.
7013                 (not (string= group (gnus-group-group-name))))
7014       (gnus-group-next-unread-group 1))
7015     (setq group-point (point))
7016     (if temporary
7017         nil                             ;Nothing to do.
7018       (set-buffer buf)
7019       (if (not gnus-kill-summary-on-exit)
7020           (progn
7021             (gnus-deaden-summary)
7022             (setq mode nil))
7023         ;; We set all buffer-local variables to nil.  It is unclear why
7024         ;; this is needed, but if we don't, buffer-local variables are
7025         ;; not garbage-collected, it seems.  This would the lead to en
7026         ;; ever-growing Emacs.
7027         (gnus-summary-clear-local-variables)
7028         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7029           (gnus-summary-clear-local-variables))
7030         (when (get-buffer gnus-article-buffer)
7031           (bury-buffer gnus-article-buffer))
7032         ;; Return to group mode buffer.
7033         (when (eq mode 'gnus-summary-mode)
7034           (gnus-kill-buffer buf)))
7035       (setq gnus-current-select-method gnus-select-method)
7036       (set-buffer gnus-group-buffer)
7037       (if quit-config
7038           (gnus-handle-ephemeral-exit quit-config)
7039         (goto-char group-point)
7040         ;; If gnus-group-buffer is already displayed, make sure we also move
7041         ;; the cursor in the window that displays it.
7042         (let ((win (get-buffer-window (current-buffer) 0)))
7043           (if win (set-window-point win (point))))
7044         (unless leave-hidden
7045           (gnus-configure-windows 'group 'force)))
7046       ;; Clear the current group name.
7047       (unless quit-config
7048         (setq gnus-newsgroup-name nil)))))
7049
7050 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7051 (defun gnus-summary-exit-no-update (&optional no-questions)
7052   "Quit reading current newsgroup without updating read article info."
7053   (interactive)
7054   (let* ((group gnus-newsgroup-name)
7055          (gnus-group-is-exiting-p t)
7056          (gnus-group-is-exiting-without-update-p t)
7057          (quit-config (gnus-group-quit-config group)))
7058     (when (or no-questions
7059               gnus-expert-user
7060               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7061       (gnus-async-halt-prefetch)
7062       (run-hooks 'gnus-summary-prepare-exit-hook)
7063       (when (gnus-buffer-live-p gnus-article-buffer)
7064         (save-excursion
7065           (set-buffer gnus-article-buffer)
7066           (mm-destroy-parts gnus-article-mime-handles)
7067           ;; Set it to nil for safety reason.
7068           (setq gnus-article-mime-handle-alist nil)
7069           (setq gnus-article-mime-handles nil)))
7070       ;; If we have several article buffers, we kill them at exit.
7071       (unless gnus-single-article-buffer
7072         (gnus-kill-buffer gnus-article-buffer)
7073         (gnus-kill-buffer gnus-original-article-buffer)
7074         (setq gnus-article-current nil))
7075       (if (not gnus-kill-summary-on-exit)
7076           (gnus-deaden-summary)
7077         (gnus-close-group group)
7078         (gnus-summary-clear-local-variables)
7079         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7080           (gnus-summary-clear-local-variables))
7081         (gnus-kill-buffer gnus-summary-buffer))
7082       (unless gnus-single-article-buffer
7083         (setq gnus-article-current nil))
7084       (when gnus-use-trees
7085         (gnus-tree-close group))
7086       (gnus-async-prefetch-remove-group group)
7087       (when (get-buffer gnus-article-buffer)
7088         (bury-buffer gnus-article-buffer))
7089       ;; Return to the group buffer.
7090       (gnus-configure-windows 'group 'force)
7091       ;; Clear the current group name.
7092       (setq gnus-newsgroup-name nil)
7093       (unless (gnus-ephemeral-group-p group)
7094         (gnus-group-update-group group))
7095       (when (equal (gnus-group-group-name) group)
7096         (gnus-group-next-unread-group 1))
7097       (when quit-config
7098         (gnus-handle-ephemeral-exit quit-config)))))
7099
7100 (defun gnus-handle-ephemeral-exit (quit-config)
7101   "Handle movement when leaving an ephemeral group.
7102 The state which existed when entering the ephemeral is reset."
7103   (if (not (buffer-name (car quit-config)))
7104       (gnus-configure-windows 'group 'force)
7105     (set-buffer (car quit-config))
7106     (cond ((eq major-mode 'gnus-summary-mode)
7107            (gnus-set-global-variables))
7108           ((eq major-mode 'gnus-article-mode)
7109            (save-excursion
7110              ;; The `gnus-summary-buffer' variable may point
7111              ;; to the old summary buffer when using a single
7112              ;; article buffer.
7113              (unless (gnus-buffer-live-p gnus-summary-buffer)
7114                (set-buffer gnus-group-buffer))
7115              (set-buffer gnus-summary-buffer)
7116              (gnus-set-global-variables))))
7117     (if (or (eq (cdr quit-config) 'article)
7118             (eq (cdr quit-config) 'pick))
7119         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7120             (gnus-configure-windows 'pick 'force)
7121           (gnus-configure-windows (cdr quit-config) 'force))
7122       (gnus-configure-windows (cdr quit-config) 'force))
7123     (when (eq major-mode 'gnus-summary-mode)
7124       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7125                                                      next-unread-noselect))
7126           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7127                                   'next-noselect)
7128                               (gnus-summary-next-subject 1 nil t))
7129                              ((eq gnus-auto-select-on-ephemeral-exit
7130                                   'next-unread-noselect)
7131                               (gnus-summary-next-subject 1 t t))))
7132             ;; Hide the article buffer which displays the article different
7133             ;; from the one that the cursor points to in the summary buffer.
7134             (gnus-configure-windows 'summary 'force))
7135         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7136                (gnus-summary-next-subject 1))
7137               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7138                (gnus-summary-next-subject 1 t))))
7139       (gnus-summary-recenter)
7140       (gnus-summary-position-point))))
7141
7142 ;;; Dead summaries.
7143
7144 (defvar gnus-dead-summary-mode-map nil)
7145
7146 (unless gnus-dead-summary-mode-map
7147   (setq gnus-dead-summary-mode-map (make-keymap))
7148   (suppress-keymap gnus-dead-summary-mode-map)
7149   (substitute-key-definition
7150    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7151   (dolist (key '("\C-d" "\r" "\177" [delete]))
7152     (define-key gnus-dead-summary-mode-map
7153       key 'gnus-summary-wake-up-the-dead))
7154   (dolist (key '("q" "Q"))
7155     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7156
7157 (defvar gnus-dead-summary-mode nil
7158   "Minor mode for Gnus summary buffers.")
7159
7160 (defun gnus-dead-summary-mode (&optional arg)
7161   "Minor mode for Gnus summary buffers."
7162   (interactive "P")
7163   (when (eq major-mode 'gnus-summary-mode)
7164     (make-local-variable 'gnus-dead-summary-mode)
7165     (setq gnus-dead-summary-mode
7166           (if (null arg) (not gnus-dead-summary-mode)
7167             (> (prefix-numeric-value arg) 0)))
7168     (when gnus-dead-summary-mode
7169       (add-minor-mode
7170        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7171
7172 (defun gnus-deaden-summary ()
7173   "Make the current summary buffer into a dead summary buffer."
7174   ;; Kill any previous dead summary buffer.
7175   (when (and gnus-dead-summary
7176              (buffer-name gnus-dead-summary))
7177     (with-current-buffer gnus-dead-summary
7178       (when gnus-dead-summary-mode
7179         (kill-buffer (current-buffer)))))
7180   ;; Make this the current dead summary.
7181   (setq gnus-dead-summary (current-buffer))
7182   (gnus-dead-summary-mode 1)
7183   (let ((name (buffer-name)))
7184     (when (string-match "Summary" name)
7185       (rename-buffer
7186        (concat (substring name 0 (match-beginning 0)) "Dead "
7187                (substring name (match-beginning 0)))
7188        t)
7189       (bury-buffer))))
7190
7191 (defun gnus-kill-or-deaden-summary (buffer)
7192   "Kill or deaden the summary BUFFER."
7193   (save-excursion
7194     (when (and (buffer-name buffer)
7195                (not gnus-single-article-buffer))
7196       (with-current-buffer buffer
7197         (gnus-kill-buffer gnus-article-buffer)
7198         (gnus-kill-buffer gnus-original-article-buffer)))
7199     (cond
7200      ;; Kill the buffer.
7201      (gnus-kill-summary-on-exit
7202       (when (and gnus-use-trees
7203                  (gnus-buffer-exists-p buffer))
7204         (save-excursion
7205           (set-buffer buffer)
7206           (gnus-tree-close gnus-newsgroup-name)))
7207       (gnus-kill-buffer buffer))
7208      ;; Deaden the buffer.
7209      ((gnus-buffer-exists-p buffer)
7210       (save-excursion
7211         (set-buffer buffer)
7212         (gnus-deaden-summary))))))
7213
7214 (defun gnus-summary-wake-up-the-dead (&rest args)
7215   "Wake up the dead summary buffer."
7216   (interactive)
7217   (gnus-dead-summary-mode -1)
7218   (let ((name (buffer-name)))
7219     (when (string-match "Dead " name)
7220       (rename-buffer
7221        (concat (substring name 0 (match-beginning 0))
7222                (substring name (match-end 0)))
7223        t)))
7224   (gnus-message 3 "This dead summary is now alive again"))
7225
7226 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7227 (defun gnus-summary-fetch-faq (&optional faq-dir)
7228   "Fetch the FAQ for the current group.
7229 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7230 in."
7231   (interactive
7232    (list
7233     (when current-prefix-arg
7234       (completing-read
7235        "FAQ dir: " (and (listp gnus-group-faq-directory)
7236                         (mapcar 'list
7237                                 gnus-group-faq-directory))))))
7238   (let (gnus-faq-buffer)
7239     (when (setq gnus-faq-buffer
7240                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7241       (gnus-configure-windows 'summary-faq))))
7242
7243 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7244 (defun gnus-summary-describe-group (&optional force)
7245   "Describe the current newsgroup."
7246   (interactive "P")
7247   (gnus-group-describe-group force gnus-newsgroup-name))
7248
7249 (defun gnus-summary-describe-briefly ()
7250   "Describe summary mode commands briefly."
7251   (interactive)
7252   (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")))
7253
7254 ;; Walking around group mode buffer from summary mode.
7255
7256 (defun gnus-summary-next-group (&optional no-article target-group backward)
7257   "Exit current newsgroup and then select next unread newsgroup.
7258 If prefix argument NO-ARTICLE is non-nil, no article is selected
7259 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7260 previous group instead."
7261   (interactive "P")
7262   ;; Stop pre-fetching.
7263   (gnus-async-halt-prefetch)
7264   (let ((current-group gnus-newsgroup-name)
7265         (current-buffer (current-buffer))
7266         entered)
7267     ;; First we semi-exit this group to update Xrefs and all variables.
7268     ;; We can't do a real exit, because the window conf must remain
7269     ;; the same in case the user is prompted for info, and we don't
7270     ;; want the window conf to change before that...
7271     (gnus-summary-exit t)
7272     (while (not entered)
7273       ;; Then we find what group we are supposed to enter.
7274       (set-buffer gnus-group-buffer)
7275       (gnus-group-jump-to-group current-group)
7276       (setq target-group
7277             (or target-group
7278                 (if (eq gnus-keep-same-level 'best)
7279                     (gnus-summary-best-group gnus-newsgroup-name)
7280                   (gnus-summary-search-group backward gnus-keep-same-level))))
7281       (if (not target-group)
7282           ;; There are no further groups, so we return to the group
7283           ;; buffer.
7284           (progn
7285             (gnus-message 5 "Returning to the group buffer")
7286             (setq entered t)
7287             (when (gnus-buffer-live-p current-buffer)
7288               (set-buffer current-buffer)
7289               (gnus-summary-exit))
7290             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7291         ;; We try to enter the target group.
7292         (gnus-group-jump-to-group target-group)
7293         (let ((unreads (gnus-group-group-unread)))
7294           (if (and (or (eq t unreads)
7295                        (and unreads (not (zerop unreads))))
7296                    (gnus-summary-read-group
7297                     target-group nil no-article
7298                     (and (buffer-name current-buffer) current-buffer)
7299                     nil backward))
7300               (setq entered t)
7301             (setq current-group target-group
7302                   target-group nil)))))))
7303
7304 (defun gnus-summary-prev-group (&optional no-article)
7305   "Exit current newsgroup and then select previous unread newsgroup.
7306 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7307   (interactive "P")
7308   (gnus-summary-next-group no-article nil t))
7309
7310 ;; Walking around summary lines.
7311
7312 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7313   "Go to the first subject satisfying any non-nil constraint.
7314 If UNREAD is non-nil, the article should be unread.
7315 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7316 If UNSEEN is non-nil, the article should be unseen.
7317 Returns the article selected or nil if there are no matching articles."
7318   (interactive "P")
7319   (cond
7320    ;; Empty summary.
7321    ((null gnus-newsgroup-data)
7322     (gnus-message 3 "No articles in the group")
7323     nil)
7324    ;; Pick the first article.
7325    ((not (or unread undownloaded unseen))
7326     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7327     (gnus-data-number (car gnus-newsgroup-data)))
7328    ;; Find the first unread article.
7329    (t
7330     (let ((data gnus-newsgroup-data))
7331       (while (and data
7332                   (let ((num (gnus-data-number (car data))))
7333                     (or (memq num gnus-newsgroup-unfetched)
7334                         (not (or (and unread
7335                                       (memq num gnus-newsgroup-unreads))
7336                                  (and undownloaded
7337                                       (memq num gnus-newsgroup-undownloaded))
7338                                  (and unseen
7339                                       (memq num gnus-newsgroup-unseen)))))))
7340         (setq data (cdr data)))
7341       (prog1
7342           (if data
7343               (progn
7344                 (goto-char (gnus-data-pos (car data)))
7345                 (gnus-data-number (car data)))
7346             (gnus-message 3 "No more%s articles"
7347                           (let* ((r (when unread " unread"))
7348                                  (d (when undownloaded " undownloaded"))
7349                                  (s (when unseen " unseen"))
7350                                  (l (delq nil (list r d s))))
7351                             (cond ((= 3 (length l))
7352                                    (concat r "," d ", or" s))
7353                                   ((= 2 (length l))
7354                                    (concat (car l) ", or" (cadr l)))
7355                                   ((= 1 (length l))
7356                                    (car l))
7357                                   (t
7358                                    ""))))
7359             nil
7360             )
7361         (gnus-summary-position-point))))))
7362
7363 (defun gnus-summary-next-subject (n &optional unread dont-display)
7364   "Go to next N'th summary line.
7365 If N is negative, go to the previous N'th subject line.
7366 If UNREAD is non-nil, only unread articles are selected.
7367 The difference between N and the actual number of steps taken is
7368 returned."
7369   (interactive "p")
7370   (let ((backward (< n 0))
7371         (n (abs n)))
7372     (while (and (> n 0)
7373                 (if backward
7374                     (gnus-summary-find-prev unread)
7375                   (gnus-summary-find-next unread)))
7376       (unless (zerop (setq n (1- n)))
7377         (gnus-summary-show-thread)))
7378     (when (/= 0 n)
7379       (gnus-message 7 "No more%s articles"
7380                     (if unread " unread" "")))
7381     (unless dont-display
7382       (gnus-summary-recenter)
7383       (gnus-summary-position-point))
7384     n))
7385
7386 (defun gnus-summary-next-unread-subject (n)
7387   "Go to next N'th unread summary line."
7388   (interactive "p")
7389   (gnus-summary-next-subject n t))
7390
7391 (defun gnus-summary-prev-subject (n &optional unread)
7392   "Go to previous N'th summary line.
7393 If optional argument UNREAD is non-nil, only unread article is selected."
7394   (interactive "p")
7395   (gnus-summary-next-subject (- n) unread))
7396
7397 (defun gnus-summary-prev-unread-subject (n)
7398   "Go to previous N'th unread summary line."
7399   (interactive "p")
7400   (gnus-summary-next-subject (- n) t))
7401
7402 (defun gnus-summary-goto-subjects (articles)
7403   "Insert the subject header for ARTICLES in the current buffer."
7404   (save-excursion
7405     (dolist (article articles)
7406       (gnus-summary-goto-subject article t)))
7407   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7408   (gnus-summary-position-point))
7409
7410 (defun gnus-summary-goto-subject (article &optional force silent)
7411   "Go the subject line of ARTICLE.
7412 If FORCE, also allow jumping to articles not currently shown."
7413   (interactive "nArticle number: ")
7414   (unless (numberp article)
7415     (error "Article %s is not a number" article))
7416   (let ((b (point))
7417         (data (gnus-data-find article)))
7418     ;; We read in the article if we have to.
7419     (and (not data)
7420          force
7421          (gnus-summary-insert-subject
7422           article
7423           (if (or (numberp force) (vectorp force)) force)
7424           t)
7425          (setq data (gnus-data-find article)))
7426     (goto-char b)
7427     (if (not data)
7428         (progn
7429           (unless silent
7430             (gnus-message 3 "Can't find article %d" article))
7431           nil)
7432       (let ((pt (gnus-data-pos data)))
7433         (goto-char pt)
7434         (gnus-summary-set-article-display-arrow pt))
7435       (gnus-summary-position-point)
7436       article)))
7437
7438 ;; Walking around summary lines with displaying articles.
7439
7440 (defun gnus-summary-expand-window (&optional arg)
7441   "Make the summary buffer take up the entire Emacs frame.
7442 Given a prefix, will force an `article' buffer configuration."
7443   (interactive "P")
7444   (if arg
7445       (gnus-configure-windows 'article 'force)
7446     (gnus-configure-windows 'summary 'force)))
7447
7448 (defun gnus-summary-display-article (article &optional all-header)
7449   "Display ARTICLE in article buffer."
7450   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7451                (with-current-buffer gnus-article-buffer
7452                  (eq major-mode 'gnus-article-mode)))
7453     (gnus-article-setup-buffer))
7454   (gnus-set-global-variables)
7455   (with-current-buffer gnus-article-buffer
7456     (setq gnus-article-charset gnus-newsgroup-charset)
7457     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7458     (mm-enable-multibyte))
7459   (if (null article)
7460       nil
7461     (prog1
7462         (if gnus-summary-display-article-function
7463             (funcall gnus-summary-display-article-function article all-header)
7464           (gnus-article-prepare article all-header))
7465       (gnus-run-hooks 'gnus-select-article-hook)
7466       (when (and gnus-current-article
7467                  (not (zerop gnus-current-article)))
7468         (gnus-summary-goto-subject gnus-current-article))
7469       (gnus-summary-recenter)
7470       (when (and gnus-use-trees gnus-show-threads)
7471         (gnus-possibly-generate-tree article)
7472         (gnus-highlight-selected-tree article))
7473       ;; Successfully display article.
7474       (gnus-article-set-window-start
7475        (cdr (assq article gnus-newsgroup-bookmarks))))))
7476
7477 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7478   "Select the current article.
7479 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7480 non-nil, the article will be re-fetched even if it already present in
7481 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7482 be displayed."
7483   ;; Make sure we are in the summary buffer to work around bbdb bug.
7484   (unless (eq major-mode 'gnus-summary-mode)
7485     (set-buffer gnus-summary-buffer))
7486   (let ((article (or article (gnus-summary-article-number)))
7487         (all-headers (not (not all-headers))) ;Must be t or nil.
7488         gnus-summary-display-article-function)
7489     (and (not pseudo)
7490          (gnus-summary-article-pseudo-p article)
7491          (error "This is a pseudo-article"))
7492     (save-excursion
7493       (set-buffer gnus-summary-buffer)
7494       (if (or (and gnus-single-article-buffer
7495                    (or (null gnus-current-article)
7496                        (null gnus-article-current)
7497                        (null (get-buffer gnus-article-buffer))
7498                        (not (eq article (cdr gnus-article-current)))
7499                        (not (equal (car gnus-article-current)
7500                                    gnus-newsgroup-name))))
7501               (and (not gnus-single-article-buffer)
7502                    (or (null gnus-current-article)
7503                        (not (eq gnus-current-article article))))
7504               force)
7505           ;; The requested article is different from the current article.
7506           (progn
7507             (gnus-summary-display-article article all-headers)
7508             (when (gnus-buffer-live-p gnus-article-buffer)
7509               (with-current-buffer gnus-article-buffer
7510                 (if (not gnus-article-decoded-p) ;; a local variable
7511                     (mm-disable-multibyte))))
7512             (gnus-article-set-window-start
7513              (cdr (assq article gnus-newsgroup-bookmarks)))
7514             article)
7515         'old))))
7516
7517 (defun gnus-summary-force-verify-and-decrypt ()
7518   "Display buttons for signed/encrypted parts and verify/decrypt them."
7519   (interactive)
7520   (let ((mm-verify-option 'known)
7521         (mm-decrypt-option 'known)
7522         (gnus-article-emulate-mime t)
7523         (gnus-buttonized-mime-types (append (list "multipart/signed"
7524                                                   "multipart/encrypted")
7525                                             gnus-buttonized-mime-types)))
7526     (gnus-summary-select-article nil 'force)))
7527
7528 (defun gnus-summary-set-current-mark (&optional current-mark)
7529   "Obsolete function."
7530   nil)
7531
7532 (defun gnus-summary-next-article (&optional unread subject backward push)
7533   "Select the next article.
7534 If UNREAD, only unread articles are selected.
7535 If SUBJECT, only articles with SUBJECT are selected.
7536 If BACKWARD, the previous article is selected instead of the next."
7537   (interactive "P")
7538   ;; Make sure we are in the summary buffer.
7539   (unless (eq major-mode 'gnus-summary-mode)
7540     (set-buffer gnus-summary-buffer))
7541   (cond
7542    ;; Is there such an article?
7543    ((and (gnus-summary-search-forward unread subject backward)
7544          (or (gnus-summary-display-article (gnus-summary-article-number))
7545              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7546     (gnus-summary-position-point))
7547    ;; If not, we try the first unread, if that is wanted.
7548    ((and subject
7549          gnus-auto-select-same
7550          (gnus-summary-first-unread-article))
7551     (gnus-summary-position-point)
7552     (gnus-message 6 "Wrapped"))
7553    ;; Try to get next/previous article not displayed in this group.
7554    ((and gnus-auto-extend-newsgroup
7555          (not unread) (not subject))
7556     (gnus-summary-goto-article
7557      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7558      nil (count-lines (point-min) (point))))
7559    ;; Go to next/previous group.
7560    (t
7561     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7562       (gnus-summary-jump-to-group gnus-newsgroup-name))
7563     (let ((cmd last-command-char)
7564           (point
7565            (with-current-buffer gnus-group-buffer
7566              (point)))
7567           (group
7568            (if (eq gnus-keep-same-level 'best)
7569                (gnus-summary-best-group gnus-newsgroup-name)
7570              (gnus-summary-search-group backward gnus-keep-same-level))))
7571       ;; For some reason, the group window gets selected.  We change
7572       ;; it back.
7573       (select-window (get-buffer-window (current-buffer)))
7574       ;; Select next unread newsgroup automagically.
7575       (cond
7576        ((or (not gnus-auto-select-next)
7577             (not cmd))
7578         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7579        ((or (eq gnus-auto-select-next 'quietly)
7580             (and (eq gnus-auto-select-next 'slightly-quietly)
7581                  push)
7582             (and (eq gnus-auto-select-next 'almost-quietly)
7583                  (gnus-summary-last-article-p)))
7584         ;; Select quietly.
7585         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7586             (gnus-summary-exit)
7587           (gnus-message 7 "No more%s articles (%s)..."
7588                         (if unread " unread" "")
7589                         (if group (concat "selecting " group)
7590                           "exiting"))
7591           (gnus-summary-next-group nil group backward)))
7592        (t
7593         (when (gnus-key-press-event-p last-input-event)
7594           (gnus-summary-walk-group-buffer
7595            gnus-newsgroup-name cmd unread backward point))))))))
7596
7597 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7598   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7599                       (?\C-p (gnus-group-prev-unread-group 1))))
7600         (cursor-in-echo-area t)
7601         keve key group ended prompt)
7602     (save-excursion
7603       (set-buffer gnus-group-buffer)
7604       (goto-char start)
7605       (setq group
7606             (if (eq gnus-keep-same-level 'best)
7607                 (gnus-summary-best-group gnus-newsgroup-name)
7608               (gnus-summary-search-group backward gnus-keep-same-level))))
7609     (while (not ended)
7610       (setq prompt
7611             (format
7612              "No more%s articles%s " (if unread " unread" "")
7613              (if (and group
7614                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7615                  (format " (Type %s for %s [%s])"
7616                          (single-key-description cmd)
7617                          (gnus-group-decoded-name group)
7618                          (gnus-group-unread group))
7619                (format " (Type %s to exit %s)"
7620                        (single-key-description cmd)
7621                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7622       ;; Confirm auto selection.
7623       (setq key (car (setq keve (gnus-read-event-char prompt)))
7624             ended t)
7625       (cond
7626        ((assq key keystrokes)
7627         (let ((obuf (current-buffer)))
7628           (switch-to-buffer gnus-group-buffer)
7629           (when group
7630             (gnus-group-jump-to-group group))
7631           (eval (cadr (assq key keystrokes)))
7632           (setq group (gnus-group-group-name))
7633           (switch-to-buffer obuf))
7634         (setq ended nil))
7635        ((equal key cmd)
7636         (if (or (not group)
7637                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7638             (gnus-summary-exit)
7639           (gnus-summary-next-group nil group backward)))
7640        (t
7641         (push (cdr keve) unread-command-events))))))
7642
7643 (defun gnus-summary-next-unread-article ()
7644   "Select unread article after current one."
7645   (interactive)
7646   (gnus-summary-next-article
7647    (or (not (eq gnus-summary-goto-unread 'never))
7648        (gnus-summary-last-article-p (gnus-summary-article-number)))
7649    (and gnus-auto-select-same
7650         (gnus-summary-article-subject))))
7651
7652 (defun gnus-summary-prev-article (&optional unread subject)
7653   "Select the article after the current one.
7654 If UNREAD is non-nil, only unread articles are selected."
7655   (interactive "P")
7656   (gnus-summary-next-article unread subject t))
7657
7658 (defun gnus-summary-prev-unread-article ()
7659   "Select unread article before current one."
7660   (interactive)
7661   (gnus-summary-prev-article
7662    (or (not (eq gnus-summary-goto-unread 'never))
7663        (gnus-summary-first-article-p (gnus-summary-article-number)))
7664    (and gnus-auto-select-same
7665         (gnus-summary-article-subject))))
7666
7667 (defun gnus-summary-next-page (&optional lines circular stop)
7668   "Show next page of the selected article.
7669 If at the end of the current article, select the next article.
7670 LINES says how many lines should be scrolled up.
7671
7672 If CIRCULAR is non-nil, go to the start of the article instead of
7673 selecting the next article when reaching the end of the current
7674 article.
7675
7676 If STOP is non-nil, just stop when reaching the end of the message.
7677
7678 Also see the variable `gnus-article-skip-boring'."
7679   (interactive "P")
7680   (setq gnus-summary-buffer (current-buffer))
7681   (gnus-set-global-variables)
7682   (let ((article (gnus-summary-article-number))
7683         (article-window (get-buffer-window gnus-article-buffer t))
7684         endp)
7685     ;; If the buffer is empty, we have no article.
7686     (unless article
7687       (error "No article to select"))
7688     (gnus-configure-windows 'article)
7689     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7690         (if (and (eq gnus-summary-goto-unread 'never)
7691                  (not (gnus-summary-last-article-p article)))
7692             (gnus-summary-next-article)
7693           (gnus-summary-next-unread-article))
7694       (if (or (null gnus-current-article)
7695               (null gnus-article-current)
7696               (/= article (cdr gnus-article-current))
7697               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7698           ;; Selected subject is different from current article's.
7699           (gnus-summary-display-article article)
7700         (when article-window
7701           (gnus-eval-in-buffer-window gnus-article-buffer
7702             (setq endp (or (gnus-article-next-page lines)
7703                            (gnus-article-only-boring-p))))
7704           (when endp
7705             (cond (stop
7706                    (gnus-message 3 "End of message"))
7707                   (circular
7708                    (gnus-summary-beginning-of-article))
7709                   (lines
7710                    (gnus-message 3 "End of message"))
7711                   ((null lines)
7712                    (if (and (eq gnus-summary-goto-unread 'never)
7713                             (not (gnus-summary-last-article-p article)))
7714                        (gnus-summary-next-article)
7715                      (gnus-summary-next-unread-article))))))))
7716     (gnus-summary-recenter)
7717     (gnus-summary-position-point)))
7718
7719 (defun gnus-summary-prev-page (&optional lines move)
7720   "Show previous page of selected article.
7721 Argument LINES specifies lines to be scrolled down.
7722 If MOVE, move to the previous unread article if point is at
7723 the beginning of the buffer."
7724   (interactive "P")
7725   (let ((article (gnus-summary-article-number))
7726         (article-window (get-buffer-window gnus-article-buffer t))
7727         endp)
7728     (gnus-configure-windows 'article)
7729     (if (or (null gnus-current-article)
7730             (null gnus-article-current)
7731             (/= article (cdr gnus-article-current))
7732             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7733         ;; Selected subject is different from current article's.
7734         (gnus-summary-display-article article)
7735       (gnus-summary-recenter)
7736       (when article-window
7737         (gnus-eval-in-buffer-window gnus-article-buffer
7738           (setq endp (gnus-article-prev-page lines)))
7739         (when (and move endp)
7740           (cond (lines
7741                  (gnus-message 3 "Beginning of message"))
7742                 ((null lines)
7743                  (if (and (eq gnus-summary-goto-unread 'never)
7744                           (not (gnus-summary-first-article-p article)))
7745                      (gnus-summary-prev-article)
7746                    (gnus-summary-prev-unread-article))))))))
7747   (gnus-summary-position-point))
7748
7749 (defun gnus-summary-prev-page-or-article (&optional lines)
7750   "Show previous page of selected article.
7751 Argument LINES specifies lines to be scrolled down.
7752 If at the beginning of the article, go to the next article."
7753   (interactive "P")
7754   (gnus-summary-prev-page lines t))
7755
7756 (defun gnus-summary-scroll-up (lines)
7757   "Scroll up (or down) one line current article.
7758 Argument LINES specifies lines to be scrolled up (or down if negative)."
7759   (interactive "p")
7760   (gnus-configure-windows 'article)
7761   (gnus-summary-show-thread)
7762   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7763     (gnus-eval-in-buffer-window gnus-article-buffer
7764       (cond ((> lines 0)
7765              (when (gnus-article-next-page lines)
7766                (gnus-message 3 "End of message")))
7767             ((< lines 0)
7768              (gnus-article-prev-page (- lines))))))
7769   (gnus-summary-recenter)
7770   (gnus-summary-position-point))
7771
7772 (defun gnus-summary-scroll-down (lines)
7773   "Scroll down (or up) one line current article.
7774 Argument LINES specifies lines to be scrolled down (or up if negative)."
7775   (interactive "p")
7776   (gnus-summary-scroll-up (- lines)))
7777
7778 (defun gnus-summary-next-same-subject ()
7779   "Select next article which has the same subject as current one."
7780   (interactive)
7781   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7782
7783 (defun gnus-summary-prev-same-subject ()
7784   "Select previous article which has the same subject as current one."
7785   (interactive)
7786   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7787
7788 (defun gnus-summary-next-unread-same-subject ()
7789   "Select next unread article which has the same subject as current one."
7790   (interactive)
7791   (gnus-summary-next-article t (gnus-summary-article-subject)))
7792
7793 (defun gnus-summary-prev-unread-same-subject ()
7794   "Select previous unread article which has the same subject as current one."
7795   (interactive)
7796   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7797
7798 (defun gnus-summary-first-unread-article ()
7799   "Select the first unread article.
7800 Return nil if there are no unread articles."
7801   (interactive)
7802   (prog1
7803       (when (gnus-summary-first-subject t)
7804         (gnus-summary-show-thread)
7805         (gnus-summary-first-subject t)
7806         (gnus-summary-display-article (gnus-summary-article-number)))
7807     (gnus-summary-position-point)))
7808
7809 (defun gnus-summary-first-unread-subject ()
7810   "Place the point on the subject line of the first unread article.
7811 Return nil if there are no unread articles."
7812   (interactive)
7813   (prog1
7814       (when (gnus-summary-first-subject t)
7815         (gnus-summary-show-thread)
7816         (gnus-summary-first-subject t))
7817     (gnus-summary-position-point)))
7818
7819 (defun gnus-summary-first-unseen-subject ()
7820   "Place the point on the subject line of the first unseen article.
7821 Return nil if there are no unseen articles."
7822   (interactive)
7823   (prog1
7824       (when (gnus-summary-first-subject nil nil t)
7825         (gnus-summary-show-thread)
7826         (gnus-summary-first-subject nil nil t))
7827     (gnus-summary-position-point)))
7828
7829 (defun gnus-summary-first-unseen-or-unread-subject ()
7830   "Place the point on the subject line of the first unseen article or,
7831 if all article have been seen, on the subject line of the first unread
7832 article."
7833   (interactive)
7834   (prog1
7835       (unless (when (gnus-summary-first-subject nil nil t)
7836                 (gnus-summary-show-thread)
7837                 (gnus-summary-first-subject nil nil t))
7838         (when (gnus-summary-first-subject t)
7839           (gnus-summary-show-thread)
7840           (gnus-summary-first-subject t)))
7841     (gnus-summary-position-point)))
7842
7843 (defun gnus-summary-first-article ()
7844   "Select the first article.
7845 Return nil if there are no articles."
7846   (interactive)
7847   (prog1
7848       (when (gnus-summary-first-subject)
7849         (gnus-summary-show-thread)
7850         (gnus-summary-first-subject)
7851         (gnus-summary-display-article (gnus-summary-article-number)))
7852     (gnus-summary-position-point)))
7853
7854 (defun gnus-summary-best-unread-article (&optional arg)
7855   "Select the unread article with the highest score.
7856 If given a prefix argument, select the next unread article that has a
7857 score higher than the default score."
7858   (interactive "P")
7859   (let ((article (if arg
7860                      (gnus-summary-better-unread-subject)
7861                    (gnus-summary-best-unread-subject))))
7862     (if article
7863         (gnus-summary-goto-article article)
7864       (error "No unread articles"))))
7865
7866 (defun gnus-summary-best-unread-subject ()
7867   "Select the unread subject with the highest score."
7868   (interactive)
7869   (let ((best -1000000)
7870         (data gnus-newsgroup-data)
7871         article score)
7872     (while data
7873       (and (gnus-data-unread-p (car data))
7874            (> (setq score
7875                     (gnus-summary-article-score (gnus-data-number (car data))))
7876               best)
7877            (setq best score
7878                  article (gnus-data-number (car data))))
7879       (setq data (cdr data)))
7880     (when article
7881       (gnus-summary-goto-subject article))
7882     (gnus-summary-position-point)
7883     article))
7884
7885 (defun gnus-summary-better-unread-subject ()
7886   "Select the first unread subject that has a score over the default score."
7887   (interactive)
7888   (let ((data gnus-newsgroup-data)
7889         article score)
7890     (while (and (setq article (gnus-data-number (car data)))
7891                 (or (gnus-data-read-p (car data))
7892                     (not (> (gnus-summary-article-score article)
7893                             gnus-summary-default-score))))
7894       (setq data (cdr data)))
7895     (when article
7896       (gnus-summary-goto-subject article))
7897     (gnus-summary-position-point)
7898     article))
7899
7900 (defun gnus-summary-last-subject ()
7901   "Go to the last displayed subject line in the group."
7902   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7903     (when article
7904       (gnus-summary-goto-subject article))))
7905
7906 (defun gnus-summary-goto-article (article &optional all-headers force)
7907   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7908 If ALL-HEADERS is non-nil, no header lines are hidden.
7909 If FORCE, go to the article even if it isn't displayed.  If FORCE
7910 is a number, it is the line the article is to be displayed on."
7911   (interactive
7912    (list
7913     (completing-read
7914      "Article number or Message-ID: "
7915      (mapcar (lambda (number) (list (int-to-string number)))
7916              gnus-newsgroup-limit))
7917     current-prefix-arg
7918     t))
7919   (prog1
7920       (if (and (stringp article)
7921                (string-match "@\\|%40" article))
7922           (gnus-summary-refer-article article)
7923         (when (stringp article)
7924           (setq article (string-to-number article)))
7925         (if (gnus-summary-goto-subject article force)
7926             (gnus-summary-display-article article all-headers)
7927           (gnus-message 4 "Couldn't go to article %s" article) nil))
7928     (gnus-summary-position-point)))
7929
7930 (defun gnus-summary-goto-last-article ()
7931   "Go to the previously read article."
7932   (interactive)
7933   (prog1
7934       (when gnus-last-article
7935         (gnus-summary-goto-article gnus-last-article nil t))
7936     (gnus-summary-position-point)))
7937
7938 (defun gnus-summary-pop-article (number)
7939   "Pop one article off the history and go to the previous.
7940 NUMBER articles will be popped off."
7941   (interactive "p")
7942   (let (to)
7943     (setq gnus-newsgroup-history
7944           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7945     (if to
7946         (gnus-summary-goto-article (car to) nil t)
7947       (error "Article history empty")))
7948   (gnus-summary-position-point))
7949
7950 ;; Summary commands and functions for limiting the summary buffer.
7951
7952 (defun gnus-summary-limit-to-articles (n)
7953   "Limit the summary buffer to the next N articles.
7954 If not given a prefix, use the process marked articles instead."
7955   (interactive "P")
7956   (prog1
7957       (let ((articles (gnus-summary-work-articles n)))
7958         (setq gnus-newsgroup-processable nil)
7959         (gnus-summary-limit articles))
7960     (gnus-summary-position-point)))
7961
7962 (defun gnus-summary-pop-limit (&optional total)
7963   "Restore the previous limit.
7964 If given a prefix, remove all limits."
7965   (interactive "P")
7966   (when total
7967     (setq gnus-newsgroup-limits
7968           (list (mapcar (lambda (h) (mail-header-number h))
7969                         gnus-newsgroup-headers))))
7970   (unless gnus-newsgroup-limits
7971     (error "No limit to pop"))
7972   (prog1
7973       (gnus-summary-limit nil 'pop)
7974     (gnus-summary-position-point)))
7975
7976 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7977   "Limit the summary buffer to articles that have subjects that match a regexp.
7978 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7979   (interactive
7980    (list (read-string (if current-prefix-arg
7981                           "Exclude subject (regexp): "
7982                         "Limit to subject (regexp): "))
7983          nil current-prefix-arg))
7984   (unless header
7985     (setq header "subject"))
7986   (when (not (equal "" subject))
7987     (prog1
7988         (let ((articles (gnus-summary-find-matching
7989                          (or header "subject") subject 'all nil nil
7990                          not-matching)))
7991           (unless articles
7992             (error "Found no matches for \"%s\"" subject))
7993           (gnus-summary-limit articles))
7994       (gnus-summary-position-point))))
7995
7996 (defun gnus-summary-limit-to-author (from &optional not-matching)
7997   "Limit the summary buffer to articles that have authors that match a regexp.
7998 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7999   (interactive
8000    (list (read-string (if current-prefix-arg
8001                           "Exclude author (regexp): "
8002                         "Limit to author (regexp): "))
8003          current-prefix-arg))
8004   (gnus-summary-limit-to-subject from "from" not-matching))
8005
8006 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8007   "Limit the summary buffer to articles with the given RECIPIENT.
8008
8009 If NOT-MATCHING, exclude RECIPIENT.
8010
8011 To and Cc headers are checked.  You need to include them in
8012 `nnmail-extra-headers'."
8013   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8014   (interactive
8015    (list (read-string (format "%s recipient (regexp): "
8016                               (if current-prefix-arg "Exclude" "Limit to")))
8017          current-prefix-arg))
8018   (when (not (equal "" recipient))
8019     (prog1 (let* ((to
8020                    (if (memq 'To nnmail-extra-headers)
8021                        (gnus-summary-find-matching
8022                         (cons 'extra 'To) recipient 'all nil nil
8023                         not-matching)
8024                      (gnus-message
8025                       1 "`To' isn't present in `nnmail-extra-headers'")
8026                      (sit-for 1)
8027                      nil))
8028                   (cc
8029                    (if (memq 'Cc nnmail-extra-headers)
8030                        (gnus-summary-find-matching
8031                         (cons 'extra 'Cc) recipient 'all nil nil
8032                         not-matching)
8033                      (gnus-message
8034                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8035                      (sit-for 1)
8036                      nil))
8037                   (articles
8038                    (if not-matching
8039                        ;; We need the numbers that are in both lists:
8040                        (mapcar (lambda (a)
8041                                  (and (memq a to) a))
8042                                cc)
8043                      (nconc to cc))))
8044              (unless articles
8045                (error "Found no matches for \"%s\"" recipient))
8046              (gnus-summary-limit articles))
8047       (gnus-summary-position-point))))
8048
8049 (defun gnus-summary-limit-to-address (address &optional not-matching)
8050   "Limit the summary buffer to articles with the given ADDRESS.
8051
8052 If NOT-MATCHING, exclude ADDRESS.
8053
8054 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8055 in `nnmail-extra-headers'."
8056   (interactive
8057    (list (read-string (format "%s address (regexp): "
8058                               (if current-prefix-arg "Exclude" "Limit to")))
8059          current-prefix-arg))
8060   (when (not (equal "" address))
8061     (prog1 (let* ((to
8062                    (if (memq 'To nnmail-extra-headers)
8063                        (gnus-summary-find-matching
8064                         (cons 'extra 'To) address 'all nil nil
8065                         not-matching)
8066                      (gnus-message
8067                       1 "`To' isn't present in `nnmail-extra-headers'")
8068                      (sit-for 1)
8069                      t))
8070                   (cc
8071                    (if (memq 'Cc nnmail-extra-headers)
8072                        (gnus-summary-find-matching
8073                         (cons 'extra 'Cc) address 'all nil nil
8074                         not-matching)
8075                      (gnus-message
8076                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8077                      (sit-for 1)
8078                      t))
8079                   (from
8080                    (gnus-summary-find-matching "from" address
8081                                                'all nil nil not-matching))
8082                   (articles
8083                    (if not-matching
8084                        ;; We need the numbers that are in all lists:
8085                        (if (eq cc t)
8086                            (if (eq to t)
8087                                from
8088                              (mapcar (lambda (a) (car (memq a from))) to))
8089                          (if (eq to t)
8090                              (mapcar (lambda (a) (car (memq a from))) cc)
8091                            (mapcar (lambda (a) (car (memq a from)))
8092                                    (mapcar (lambda (a) (car (memq a to)))
8093                                            cc))))
8094                      (nconc (if (eq to t) nil to)
8095                             (if (eq cc t) nil cc)
8096                             from))))
8097              (unless articles
8098                (error "Found no matches for \"%s\"" address))
8099              (gnus-summary-limit articles))
8100       (gnus-summary-position-point))))
8101
8102 (defun gnus-summary-limit-strange-charsets-predicate (header)
8103   (let ((string (concat (mail-header-subject header)
8104                         (mail-header-from header)))
8105         charset found)
8106     (dotimes (i (1- (length string)))
8107       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8108       (when (string-match "unicode\\|big\\|japanese" charset)
8109         (setq found t)))
8110     found))
8111
8112 (defun gnus-summary-limit-to-predicate (predicate)
8113   "Limit to articles where PREDICATE returns non-nil.
8114 PREDICATE will be called with the header structures of the
8115 articles."
8116   (let ((articles nil)
8117         (case-fold-search t))
8118     (dolist (header gnus-newsgroup-headers)
8119       (when (funcall predicate header)
8120         (push (mail-header-number header) articles)))
8121     (gnus-summary-limit (nreverse articles))))
8122
8123 (defun gnus-summary-limit-to-age (age &optional younger-p)
8124   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8125 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8126 articles that are younger than AGE days."
8127   (interactive
8128    (let ((younger current-prefix-arg)
8129          (days-got nil)
8130          days)
8131      (while (not days-got)
8132        (setq days (if younger
8133                       (read-string "Limit to articles younger than (in days, older when negative): ")
8134                     (read-string
8135                      "Limit to articles older than (in days, younger when negative): ")))
8136        (when (> (length days) 0)
8137          (setq days (read days)))
8138        (if (numberp days)
8139            (progn
8140              (setq days-got t)
8141              (when (< days 0)
8142                (setq younger (not younger))
8143                (setq days (* days -1))))
8144          (message "Please enter a number.")
8145          (sleep-for 1)))
8146      (list days younger)))
8147   (prog1
8148       (let ((data gnus-newsgroup-data)
8149             (cutoff (days-to-time age))
8150             articles d date is-younger)
8151         (while (setq d (pop data))
8152           (when (and (vectorp (gnus-data-header d))
8153                      (setq date (mail-header-date (gnus-data-header d))))
8154             (setq is-younger (time-less-p
8155                               (time-since (condition-case ()
8156                                               (date-to-time date)
8157                                             (error '(0 0))))
8158                               cutoff))
8159             (when (if younger-p
8160                       is-younger
8161                     (not is-younger))
8162               (push (gnus-data-number d) articles))))
8163         (gnus-summary-limit (nreverse articles)))
8164     (gnus-summary-position-point)))
8165
8166 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8167   "Limit the summary buffer to articles that match an 'extra' header."
8168   (interactive
8169    (let ((header
8170           (intern
8171            (gnus-completing-read-with-default
8172             (symbol-name (car gnus-extra-headers))
8173             (if current-prefix-arg
8174                 "Exclude extra header"
8175               "Limit extra header")
8176             (mapcar (lambda (x)
8177                       (cons (symbol-name x) x))
8178                     gnus-extra-headers)
8179             nil
8180             t))))
8181      (list header
8182            (read-string (format "%s header %s (regexp): "
8183                                 (if current-prefix-arg "Exclude" "Limit to")
8184                                 header))
8185            current-prefix-arg)))
8186   (when (not (equal "" regexp))
8187     (prog1
8188         (let ((articles (gnus-summary-find-matching
8189                          (cons 'extra header) regexp 'all nil nil
8190                          not-matching)))
8191           (unless articles
8192             (error "Found no matches for \"%s\"" regexp))
8193           (gnus-summary-limit articles))
8194       (gnus-summary-position-point))))
8195
8196 (defun gnus-summary-limit-to-display-predicate ()
8197   "Limit the summary buffer to the predicated in the `display' group parameter."
8198   (interactive)
8199   (unless gnus-newsgroup-display
8200     (error "There is no `display' group parameter"))
8201   (let (articles)
8202     (dolist (number gnus-newsgroup-articles)
8203       (when (funcall gnus-newsgroup-display)
8204         (push number articles)))
8205     (gnus-summary-limit articles))
8206   (gnus-summary-position-point))
8207
8208 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8209 (make-obsolete
8210  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8211
8212 (defun gnus-summary-limit-to-unread (&optional all)
8213   "Limit the summary buffer to articles that are not marked as read.
8214 If ALL is non-nil, limit strictly to unread articles."
8215   (interactive "P")
8216   (if all
8217       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8218     (gnus-summary-limit-to-marks
8219      ;; Concat all the marks that say that an article is read and have
8220      ;; those removed.
8221      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8222            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8223            gnus-low-score-mark gnus-expirable-mark
8224            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8225            gnus-duplicate-mark gnus-souped-mark)
8226      'reverse)))
8227
8228 (defun gnus-summary-limit-to-headers (match &optional reverse)
8229   "Limit the summary buffer to articles that have headers that match MATCH.
8230 If REVERSE (the prefix), limit to articles that don't match."
8231   (interactive "sMatch headers (regexp): \nP")
8232   (gnus-summary-limit-to-bodies match reverse t))
8233
8234 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8235   "Limit the summary buffer to articles that have bodies that match MATCH.
8236 If REVERSE (the prefix), limit to articles that don't match."
8237   (interactive "sMatch body (regexp): \nP")
8238   (let ((articles nil)
8239         (gnus-select-article-hook nil)  ;Disable hook.
8240         (gnus-article-prepare-hook nil)
8241         (gnus-use-article-prefetch nil)
8242         (gnus-keep-backlog nil)
8243         (gnus-break-pages nil)
8244         (gnus-summary-display-arrow nil)
8245         (gnus-updated-mode-lines nil)
8246         (gnus-auto-center-summary nil)
8247         (gnus-display-mime-function nil))
8248     (dolist (data gnus-newsgroup-data)
8249       (let (gnus-mark-article-hook)
8250         (gnus-summary-select-article t t nil (gnus-data-number data)))
8251       (save-excursion
8252         (set-buffer gnus-article-buffer)
8253         (article-goto-body)
8254         (let* ((case-fold-search t)
8255                (found (if headersp
8256                           (re-search-backward match nil t)
8257                         (re-search-forward match nil t))))
8258           (when (or (and found
8259                          (not reverse))
8260                     (and (not found)
8261                          reverse))
8262             (push (gnus-data-number data) articles)))))
8263     (if (not articles)
8264         (message "No messages matched")
8265       (gnus-summary-limit articles)))
8266   (gnus-summary-position-point))
8267
8268 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8269   "Limit the summary buffer to articles that aren't part on any thread.
8270 If THREADSP (the prefix), limit to articles that are in threads."
8271   (interactive "P")
8272   (let ((articles nil)
8273         thread-articles
8274         threads)
8275     (dolist (thread gnus-newsgroup-threads)
8276       (if (stringp (car thread))
8277           (dolist (thread (cdr thread))
8278             (push thread threads))
8279         (push thread threads)))
8280     (dolist (thread threads)
8281       (setq thread-articles (gnus-articles-in-thread thread))
8282       (when (or (and threadsp
8283                      (> (length thread-articles) 1))
8284                 (and (not threadsp)
8285                      (= (length thread-articles) 1)))
8286         (setq articles (nconc thread-articles articles))))
8287     (if (not articles)
8288         (message "No messages matched")
8289       (gnus-summary-limit articles))
8290     (gnus-summary-position-point)))
8291
8292 (defun gnus-summary-limit-to-replied (&optional unreplied)
8293   "Limit the summary buffer to replied articles.
8294 If UNREPLIED (the prefix), limit to unreplied articles."
8295   (interactive "P")
8296   (if unreplied
8297       (gnus-summary-limit
8298        (gnus-set-difference gnus-newsgroup-articles
8299         gnus-newsgroup-replied))
8300     (gnus-summary-limit gnus-newsgroup-replied))
8301   (gnus-summary-position-point))
8302
8303 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8304 (make-obsolete 'gnus-summary-delete-marked-with
8305                'gnus-summary-limit-exclude-marks)
8306
8307 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8308   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8309 If REVERSE, limit the summary buffer to articles that are marked
8310 with MARKS.  MARKS can either be a string of marks or a list of marks.
8311 Returns how many articles were removed."
8312   (interactive "sMarks: ")
8313   (gnus-summary-limit-to-marks marks t))
8314
8315 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8316   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8317 If REVERSE (the prefix), limit the summary buffer to articles that are
8318 not marked with MARKS.  MARKS can either be a string of marks or a
8319 list of marks.
8320 Returns how many articles were removed."
8321   (interactive "sMarks: \nP")
8322   (prog1
8323       (let ((data gnus-newsgroup-data)
8324             (marks (if (listp marks) marks
8325                      (append marks nil))) ; Transform to list.
8326             articles)
8327         (while data
8328           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8329                   (memq (gnus-data-mark (car data)) marks))
8330             (push (gnus-data-number (car data)) articles))
8331           (setq data (cdr data)))
8332         (gnus-summary-limit articles))
8333     (gnus-summary-position-point)))
8334
8335 (defun gnus-summary-limit-to-score (score)
8336   "Limit to articles with score at or above SCORE."
8337   (interactive "NLimit to articles with score of at least: ")
8338   (let ((data gnus-newsgroup-data)
8339         articles)
8340     (while data
8341       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8342                 score)
8343         (push (gnus-data-number (car data)) articles))
8344       (setq data (cdr data)))
8345     (prog1
8346         (gnus-summary-limit articles)
8347       (gnus-summary-position-point))))
8348
8349 (defun gnus-summary-limit-to-unseen ()
8350   "Limit to unseen articles."
8351   (interactive)
8352   (prog1
8353       (gnus-summary-limit gnus-newsgroup-unseen)
8354     (gnus-summary-position-point)))
8355
8356 (defun gnus-summary-limit-include-thread (id)
8357   "Display all the hidden articles that is in the thread with ID in it.
8358 When called interactively, ID is the Message-ID of the current
8359 article."
8360   (interactive (list (mail-header-id (gnus-summary-article-header))))
8361   (let ((articles (gnus-articles-in-thread
8362                    (gnus-id-to-thread (gnus-root-id id)))))
8363     (prog1
8364         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8365       (gnus-summary-limit-include-matching-articles
8366        "subject"
8367        (regexp-quote (gnus-simplify-subject-re
8368                       (mail-header-subject (gnus-id-to-header id)))))
8369       (gnus-summary-position-point))))
8370
8371 (defun gnus-summary-limit-include-matching-articles (header regexp)
8372   "Display all the hidden articles that have HEADERs that match REGEXP."
8373   (interactive (list (read-string "Match on header: ")
8374                      (read-string "Regexp: ")))
8375   (let ((articles (gnus-find-matching-articles header regexp)))
8376     (prog1
8377         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8378       (gnus-summary-position-point))))
8379
8380 (defun gnus-summary-insert-dormant-articles ()
8381   "Insert all the dormant articles for this group into the current buffer."
8382   (interactive)
8383   (let ((gnus-verbose (max 6 gnus-verbose)))
8384     (if (not gnus-newsgroup-dormant)
8385         (gnus-message 3 "No dormant articles for this group")
8386       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8387
8388 (defun gnus-summary-insert-ticked-articles ()
8389   "Insert ticked articles for this group into the current buffer."
8390   (interactive)
8391   (let ((gnus-verbose (max 6 gnus-verbose)))
8392     (if (not gnus-newsgroup-marked)
8393         (gnus-message 3 "No ticked articles for this group")
8394       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8395
8396 (defun gnus-summary-limit-include-dormant ()
8397   "Display all the hidden articles that are marked as dormant.
8398 Note that this command only works on a subset of the articles currently
8399 fetched for this group."
8400   (interactive)
8401   (unless gnus-newsgroup-dormant
8402     (error "There are no dormant articles in this group"))
8403   (prog1
8404       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8405     (gnus-summary-position-point)))
8406
8407 (defun gnus-summary-limit-exclude-dormant ()
8408   "Hide all dormant articles."
8409   (interactive)
8410   (prog1
8411       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8412     (gnus-summary-position-point)))
8413
8414 (defun gnus-summary-limit-exclude-childless-dormant ()
8415   "Hide all dormant articles that have no children."
8416   (interactive)
8417   (let ((data (gnus-data-list t))
8418         articles d children)
8419     ;; Find all articles that are either not dormant or have
8420     ;; children.
8421     (while (setq d (pop data))
8422       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8423                 (and (setq children
8424                            (gnus-article-children (gnus-data-number d)))
8425                      (let (found)
8426                        (while children
8427                          (when (memq (car children) articles)
8428                            (setq children nil
8429                                  found t))
8430                          (pop children))
8431                        found)))
8432         (push (gnus-data-number d) articles)))
8433     ;; Do the limiting.
8434     (prog1
8435         (gnus-summary-limit articles)
8436       (gnus-summary-position-point))))
8437
8438 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8439   "Mark all unread excluded articles as read.
8440 If ALL, mark even excluded ticked and dormants as read."
8441   (interactive "P")
8442   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8443   (let ((articles (gnus-sorted-ndifference
8444                    (sort
8445                     (mapcar (lambda (h) (mail-header-number h))
8446                             gnus-newsgroup-headers)
8447                     '<)
8448                    gnus-newsgroup-limit))
8449         article)
8450     (setq gnus-newsgroup-unreads
8451           (gnus-sorted-intersection gnus-newsgroup-unreads
8452                                     gnus-newsgroup-limit))
8453     (if all
8454         (setq gnus-newsgroup-dormant nil
8455               gnus-newsgroup-marked nil
8456               gnus-newsgroup-reads
8457               (nconc
8458                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8459                gnus-newsgroup-reads))
8460       (while (setq article (pop articles))
8461         (unless (or (memq article gnus-newsgroup-dormant)
8462                     (memq article gnus-newsgroup-marked))
8463           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8464
8465 (defun gnus-summary-limit (articles &optional pop)
8466   (if pop
8467       ;; We pop the previous limit off the stack and use that.
8468       (setq articles (car gnus-newsgroup-limits)
8469             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8470     ;; We use the new limit, so we push the old limit on the stack.
8471     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8472   ;; Set the limit.
8473   (setq gnus-newsgroup-limit articles)
8474   (let ((total (length gnus-newsgroup-data))
8475         (data (gnus-data-find-list (gnus-summary-article-number)))
8476         (gnus-summary-mark-below nil)   ; Inhibit this.
8477         found)
8478     ;; This will do all the work of generating the new summary buffer
8479     ;; according to the new limit.
8480     (gnus-summary-prepare)
8481     ;; Hide any threads, possibly.
8482     (gnus-summary-maybe-hide-threads)
8483     ;; Try to return to the article you were at, or one in the
8484     ;; neighborhood.
8485     (when data
8486       ;; We try to find some article after the current one.
8487       (while data
8488         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8489           (setq data nil
8490                 found t))
8491         (setq data (cdr data))))
8492     (unless found
8493       ;; If there is no data, that means that we were after the last
8494       ;; article.  The same goes when we can't find any articles
8495       ;; after the current one.
8496       (goto-char (point-max))
8497       (gnus-summary-find-prev))
8498     (gnus-set-mode-line 'summary)
8499     ;; We return how many articles were removed from the summary
8500     ;; buffer as a result of the new limit.
8501     (- total (length gnus-newsgroup-data))))
8502
8503 (defsubst gnus-invisible-cut-children (threads)
8504   (let ((num 0))
8505     (while threads
8506       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8507         (incf num))
8508       (pop threads))
8509     (< num 2)))
8510
8511 (defsubst gnus-cut-thread (thread)
8512   "Go forwards in the thread until we find an article that we want to display."
8513   (when (or (eq gnus-fetch-old-headers 'some)
8514             (eq gnus-fetch-old-headers 'invisible)
8515             (numberp gnus-fetch-old-headers)
8516             (eq gnus-build-sparse-threads 'some)
8517             (eq gnus-build-sparse-threads 'more))
8518     ;; Deal with old-fetched headers and sparse threads.
8519     (while (and
8520             thread
8521             (or
8522              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8523              (gnus-summary-article-ancient-p
8524               (mail-header-number (car thread))))
8525             (if (or (<= (length (cdr thread)) 1)
8526                     (eq gnus-fetch-old-headers 'invisible))
8527                 (setq gnus-newsgroup-limit
8528                       (delq (mail-header-number (car thread))
8529                             gnus-newsgroup-limit)
8530                       thread (cadr thread))
8531               (when (gnus-invisible-cut-children (cdr thread))
8532                 (let ((th (cdr thread)))
8533                   (while th
8534                     (if (memq (mail-header-number (caar th))
8535                               gnus-newsgroup-limit)
8536                         (setq thread (car th)
8537                               th nil)
8538                       (setq th (cdr th))))))))))
8539   thread)
8540
8541 (defun gnus-cut-threads (threads)
8542   "Cut off all uninteresting articles from the beginning of THREADS."
8543   (when (or (eq gnus-fetch-old-headers 'some)
8544             (eq gnus-fetch-old-headers 'invisible)
8545             (numberp gnus-fetch-old-headers)
8546             (eq gnus-build-sparse-threads 'some)
8547             (eq gnus-build-sparse-threads 'more))
8548     (let ((th threads))
8549       (while th
8550         (setcar th (gnus-cut-thread (car th)))
8551         (setq th (cdr th)))))
8552   ;; Remove nixed out threads.
8553   (delq nil threads))
8554
8555 (defun gnus-summary-initial-limit (&optional show-if-empty)
8556   "Figure out what the initial limit is supposed to be on group entry.
8557 This entails weeding out unwanted dormants, low-scored articles,
8558 fetch-old-headers verbiage, and so on."
8559   ;; Most groups have nothing to remove.
8560   (if (or gnus-inhibit-limiting
8561           (and (null gnus-newsgroup-dormant)
8562                (eq gnus-newsgroup-display 'gnus-not-ignore)
8563                (not (eq gnus-fetch-old-headers 'some))
8564                (not (numberp gnus-fetch-old-headers))
8565                (not (eq gnus-fetch-old-headers 'invisible))
8566                (null gnus-summary-expunge-below)
8567                (not (eq gnus-build-sparse-threads 'some))
8568                (not (eq gnus-build-sparse-threads 'more))
8569                (null gnus-thread-expunge-below)
8570                (not gnus-use-nocem)))
8571       ()                                ; Do nothing.
8572     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8573     (setq gnus-newsgroup-limit nil)
8574     (mapatoms
8575      (lambda (node)
8576        (unless (car (symbol-value node))
8577          ;; These threads have no parents -- they are roots.
8578          (let ((nodes (cdr (symbol-value node)))
8579                thread)
8580            (while nodes
8581              (if (and gnus-thread-expunge-below
8582                       (< (gnus-thread-total-score (car nodes))
8583                          gnus-thread-expunge-below))
8584                  (gnus-expunge-thread (pop nodes))
8585                (setq thread (pop nodes))
8586                (gnus-summary-limit-children thread))))))
8587      gnus-newsgroup-dependencies)
8588     ;; If this limitation resulted in an empty group, we might
8589     ;; pop the previous limit and use it instead.
8590     (when (and (not gnus-newsgroup-limit)
8591                show-if-empty)
8592       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8593     gnus-newsgroup-limit))
8594
8595 (defun gnus-summary-limit-children (thread)
8596   "Return 1 if this subthread is visible and 0 if it is not."
8597   ;; First we get the number of visible children to this thread.  This
8598   ;; is done by recursing down the thread using this function, so this
8599   ;; will really go down to a leaf article first, before slowly
8600   ;; working its way up towards the root.
8601   (when thread
8602     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8603            (children
8604            (if (cdr thread)
8605                (apply '+ (mapcar 'gnus-summary-limit-children
8606                                  (cdr thread)))
8607              0))
8608           (number (mail-header-number (car thread)))
8609           score)
8610       (if (and
8611            (not (memq number gnus-newsgroup-marked))
8612            (or
8613             ;; If this article is dormant and has absolutely no visible
8614             ;; children, then this article isn't visible.
8615             (and (memq number gnus-newsgroup-dormant)
8616                  (zerop children))
8617             ;; If this is "fetch-old-headered" and there is no
8618             ;; visible children, then we don't want this article.
8619             (and (or (eq gnus-fetch-old-headers 'some)
8620                      (numberp gnus-fetch-old-headers))
8621                  (gnus-summary-article-ancient-p number)
8622                  (zerop children))
8623             ;; If this is "fetch-old-headered" and `invisible', then
8624             ;; we don't want this article.
8625             (and (eq gnus-fetch-old-headers 'invisible)
8626                  (gnus-summary-article-ancient-p number))
8627             ;; If this is a sparsely inserted article with no children,
8628             ;; we don't want it.
8629             (and (eq gnus-build-sparse-threads 'some)
8630                  (gnus-summary-article-sparse-p number)
8631                  (zerop children))
8632             ;; If we use expunging, and this article is really
8633             ;; low-scored, then we don't want this article.
8634             (when (and gnus-summary-expunge-below
8635                        (< (setq score
8636                                 (or (cdr (assq number gnus-newsgroup-scored))
8637                                     gnus-summary-default-score))
8638                           gnus-summary-expunge-below))
8639               ;; We increase the expunge-tally here, but that has
8640               ;; nothing to do with the limits, really.
8641               (incf gnus-newsgroup-expunged-tally)
8642               ;; We also mark as read here, if that's wanted.
8643               (when (and gnus-summary-mark-below
8644                          (< score gnus-summary-mark-below))
8645                 (setq gnus-newsgroup-unreads
8646                       (delq number gnus-newsgroup-unreads))
8647                 (if gnus-newsgroup-auto-expire
8648                     (push number gnus-newsgroup-expirable)
8649                   (push (cons number gnus-low-score-mark)
8650                         gnus-newsgroup-reads)))
8651               t)
8652             ;; Do the `display' group parameter.
8653             (and gnus-newsgroup-display
8654                  (not (funcall gnus-newsgroup-display)))
8655             ;; Check NoCeM things.
8656             (when (and gnus-use-nocem
8657                        (gnus-nocem-unwanted-article-p
8658                         (mail-header-id (car thread))))
8659               (setq gnus-newsgroup-unreads
8660                     (delq number gnus-newsgroup-unreads))
8661               t)))
8662           ;; Nope, invisible article.
8663           0
8664         ;; Ok, this article is to be visible, so we add it to the limit
8665         ;; and return 1.
8666         (push number gnus-newsgroup-limit)
8667         1))))
8668
8669 (defun gnus-expunge-thread (thread)
8670   "Mark all articles in THREAD as read."
8671   (let* ((number (mail-header-number (car thread))))
8672     (incf gnus-newsgroup-expunged-tally)
8673     ;; We also mark as read here, if that's wanted.
8674     (setq gnus-newsgroup-unreads
8675           (delq number gnus-newsgroup-unreads))
8676     (if gnus-newsgroup-auto-expire
8677         (push number gnus-newsgroup-expirable)
8678       (push (cons number gnus-low-score-mark)
8679             gnus-newsgroup-reads)))
8680   ;; Go recursively through all subthreads.
8681   (mapcar 'gnus-expunge-thread (cdr thread)))
8682
8683 ;; Summary article oriented commands
8684
8685 (defun gnus-summary-refer-parent-article (n)
8686   "Refer parent article N times.
8687 If N is negative, go to ancestor -N instead.
8688 The difference between N and the number of articles fetched is returned."
8689   (interactive "p")
8690   (let ((skip 1)
8691         error header ref)
8692     (when (not (natnump n))
8693       (setq skip (abs n)
8694             n 1))
8695     (while (and (> n 0)
8696                 (not error))
8697       (setq header (gnus-summary-article-header))
8698       (if (and (eq (mail-header-number header)
8699                    (cdr gnus-article-current))
8700                (equal gnus-newsgroup-name
8701                       (car gnus-article-current)))
8702           ;; If we try to find the parent of the currently
8703           ;; displayed article, then we take a look at the actual
8704           ;; References header, since this is slightly more
8705           ;; reliable than the References field we got from the
8706           ;; server.
8707           (save-excursion
8708             (set-buffer gnus-original-article-buffer)
8709             (nnheader-narrow-to-headers)
8710             (unless (setq ref (message-fetch-field "references"))
8711               (when (setq ref (message-fetch-field "in-reply-to"))
8712                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8713             (widen))
8714         (setq ref
8715               ;; It's not the current article, so we take a bet on
8716               ;; the value we got from the server.
8717               (mail-header-references header)))
8718       (if (and ref
8719                (not (equal ref "")))
8720           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8721             (gnus-message 1 "Couldn't find parent"))
8722         (gnus-message 1 "No references in article %d"
8723                       (gnus-summary-article-number))
8724         (setq error t))
8725       (decf n))
8726     (gnus-summary-position-point)
8727     n))
8728
8729 (defun gnus-summary-refer-references ()
8730   "Fetch all articles mentioned in the References header.
8731 Return the number of articles fetched."
8732   (interactive)
8733   (let ((ref (mail-header-references (gnus-summary-article-header)))
8734         (current (gnus-summary-article-number))
8735         (n 0))
8736     (if (or (not ref)
8737             (equal ref ""))
8738         (error "No References in the current article")
8739       ;; For each Message-ID in the References header...
8740       (while (string-match "<[^>]*>" ref)
8741         (incf n)
8742         ;; ... fetch that article.
8743         (gnus-summary-refer-article
8744          (prog1 (match-string 0 ref)
8745            (setq ref (substring ref (match-end 0))))))
8746       (gnus-summary-goto-subject current)
8747       (gnus-summary-position-point)
8748       n)))
8749
8750 (defun gnus-summary-refer-thread (&optional limit)
8751   "Fetch all articles in the current thread.
8752 If LIMIT (the numerical prefix), fetch that many old headers instead
8753 of what's specified by the `gnus-refer-thread-limit' variable."
8754   (interactive "P")
8755   (let ((id (mail-header-id (gnus-summary-article-header)))
8756         (limit (if limit (prefix-numeric-value limit)
8757                  gnus-refer-thread-limit)))
8758     (unless (eq gnus-fetch-old-headers 'invisible)
8759       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8760       ;; Retrieve the headers and read them in.
8761       (if (eq (if (numberp limit)
8762                   (gnus-retrieve-headers
8763                    (list (min
8764                           (+ (mail-header-number
8765                               (gnus-summary-article-header))
8766                              limit)
8767                           gnus-newsgroup-end))
8768                    gnus-newsgroup-name (* limit 2))
8769                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8770                 ;; headers.
8771                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8772                                        gnus-newsgroup-name limit))
8773               'nov)
8774           (gnus-build-all-threads)
8775         (error "Can't fetch thread from back ends that don't support NOV"))
8776       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8777     (gnus-summary-limit-include-thread id)))
8778
8779 (defun gnus-summary-refer-article (message-id)
8780   "Fetch an article specified by MESSAGE-ID."
8781   (interactive "sMessage-ID: ")
8782   (when (and (stringp message-id)
8783              (not (zerop (length message-id))))
8784     (setq message-id (gnus-replace-in-string message-id " " ""))
8785     ;; Construct the correct Message-ID if necessary.
8786     ;; Suggested by tale@pawl.rpi.edu.
8787     (unless (string-match "^<" message-id)
8788       (setq message-id (concat "<" message-id)))
8789     (unless (string-match ">$" message-id)
8790       (setq message-id (concat message-id ">")))
8791     ;; People often post MIDs from URLs, so unhex it:
8792     (unless (string-match "@" message-id)
8793       (setq message-id (gnus-url-unhex-string message-id)))
8794     (let* ((header (gnus-id-to-header message-id))
8795            (sparse (and header
8796                         (gnus-summary-article-sparse-p
8797                          (mail-header-number header))
8798                         (memq (mail-header-number header)
8799                               gnus-newsgroup-limit)))
8800            number)
8801       (cond
8802        ;; If the article is present in the buffer we just go to it.
8803        ((and header
8804              (or (not (gnus-summary-article-sparse-p
8805                        (mail-header-number header)))
8806                  sparse))
8807         (prog1
8808             (gnus-summary-goto-article
8809              (mail-header-number header) nil t)
8810           (when sparse
8811             (gnus-summary-update-article (mail-header-number header)))))
8812        (t
8813         ;; We fetch the article.
8814         (catch 'found
8815           (dolist (gnus-override-method (gnus-refer-article-methods))
8816             (when (and (gnus-check-server gnus-override-method)
8817                        ;; Fetch the header,
8818                        (setq number (gnus-summary-insert-subject message-id)))
8819               ;; and display the article.
8820               (gnus-summary-select-article nil nil nil number)
8821               (throw 'found t)))
8822           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8823
8824 (defun gnus-refer-article-methods ()
8825   "Return a list of referable methods."
8826   (cond
8827    ;; No method, so we default to current and native.
8828    ((null gnus-refer-article-method)
8829     (list gnus-current-select-method gnus-select-method))
8830    ;; Current.
8831    ((eq 'current gnus-refer-article-method)
8832     (list gnus-current-select-method))
8833    ;; List of select methods.
8834    ((not (and (symbolp (car gnus-refer-article-method))
8835               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8836     (let (out)
8837       (dolist (method gnus-refer-article-method)
8838         (push (if (eq 'current method)
8839                   gnus-current-select-method
8840                 method)
8841               out))
8842       (nreverse out)))
8843    ;; One single select method.
8844    (t
8845     (list gnus-refer-article-method))))
8846
8847 (defun gnus-summary-edit-parameters ()
8848   "Edit the group parameters of the current group."
8849   (interactive)
8850   (gnus-group-edit-group gnus-newsgroup-name 'params))
8851
8852 (defun gnus-summary-customize-parameters ()
8853   "Customize the group parameters of the current group."
8854   (interactive)
8855   (gnus-group-customize gnus-newsgroup-name))
8856
8857 (defun gnus-summary-enter-digest-group (&optional force)
8858   "Enter an nndoc group based on the current article.
8859 If FORCE, force a digest interpretation.  If not, try
8860 to guess what the document format is."
8861   (interactive "P")
8862   (let ((conf gnus-current-window-configuration))
8863     (save-window-excursion
8864       (save-excursion
8865         (let (gnus-article-prepare-hook
8866               gnus-display-mime-function
8867               gnus-break-pages)
8868           (gnus-summary-select-article))))
8869     (setq gnus-current-window-configuration conf)
8870     (let* ((name (format "%s-%d"
8871                          (gnus-group-prefixed-name
8872                           gnus-newsgroup-name (list 'nndoc ""))
8873                          (with-current-buffer gnus-summary-buffer
8874                            gnus-current-article)))
8875            (ogroup gnus-newsgroup-name)
8876            (params (append (gnus-info-params (gnus-get-info ogroup))
8877                            (list (cons 'to-group ogroup))
8878                            (list (cons 'parent-group ogroup))
8879                            (list (cons 'save-article-group ogroup))))
8880            (case-fold-search t)
8881            (buf (current-buffer))
8882            dig to-address)
8883       (save-excursion
8884         (set-buffer gnus-original-article-buffer)
8885         ;; Have the digest group inherit the main mail address of
8886         ;; the parent article.
8887         (when (setq to-address (or (gnus-fetch-field "reply-to")
8888                                    (gnus-fetch-field "from")))
8889           (setq params
8890                 (append
8891                  (list (cons 'to-address
8892                              (funcall gnus-decode-encoded-address-function
8893                                       to-address))))))
8894         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8895         (insert-buffer-substring gnus-original-article-buffer)
8896         ;; Remove lines that may lead nndoc to misinterpret the
8897         ;; document type.
8898         (narrow-to-region
8899          (goto-char (point-min))
8900          (or (search-forward "\n\n" nil t) (point)))
8901         (goto-char (point-min))
8902         (delete-matching-lines "^Path:\\|^From ")
8903         (widen))
8904       (unwind-protect
8905           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8906                     (gnus-newsgroup-ephemeral-ignored-charsets
8907                      gnus-newsgroup-ignored-charsets))
8908                 (gnus-group-read-ephemeral-group
8909                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8910                               (nndoc-article-type
8911                                ,(if force 'mbox 'guess)))
8912                  t nil nil nil
8913                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8914                                                         "ADAPT")))))
8915               ;; Make all postings to this group go to the parent group.
8916               (nconc (gnus-info-params (gnus-get-info name))
8917                      params)
8918             ;; Couldn't select this doc group.
8919             (switch-to-buffer buf)
8920             (gnus-set-global-variables)
8921             (gnus-configure-windows 'summary)
8922             (gnus-message 3 "Article couldn't be entered?"))
8923         (kill-buffer dig)))))
8924
8925 (defun gnus-summary-read-document (n)
8926   "Open a new group based on the current article(s).
8927 This will allow you to read digests and other similar
8928 documents as newsgroups.
8929 Obeys the standard process/prefix convention."
8930   (interactive "P")
8931   (let* ((ogroup gnus-newsgroup-name)
8932          (params (append (gnus-info-params (gnus-get-info ogroup))
8933                          (list (cons 'to-group ogroup))))
8934          group egroup groups vgroup)
8935     (dolist (article (gnus-summary-work-articles n))
8936       (setq group (format "%s-%d" gnus-newsgroup-name article))
8937       (gnus-summary-remove-process-mark article)
8938       (when (gnus-summary-display-article article)
8939         (save-excursion
8940           (with-temp-buffer
8941             (insert-buffer-substring gnus-original-article-buffer)
8942             ;; Remove some headers that may lead nndoc to make
8943             ;; the wrong guess.
8944             (message-narrow-to-head)
8945             (goto-char (point-min))
8946             (delete-matching-lines "^Path:\\|^From ")
8947             (widen)
8948             (if (setq egroup
8949                       (gnus-group-read-ephemeral-group
8950                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8951                                      (nndoc-article-type guess))
8952                        t nil t))
8953                 (progn
8954             ;; Make all postings to this group go to the parent group.
8955                   (nconc (gnus-info-params (gnus-get-info egroup))
8956                          params)
8957                   (push egroup groups))
8958               ;; Couldn't select this doc group.
8959               (gnus-error 3 "Article couldn't be entered"))))))
8960     ;; Now we have selected all the documents.
8961     (cond
8962      ((not groups)
8963       (error "None of the articles could be interpreted as documents"))
8964      ((gnus-group-read-ephemeral-group
8965        (setq vgroup (format
8966                      "nnvirtual:%s-%s" gnus-newsgroup-name
8967                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8968        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8969        t
8970        (cons (current-buffer) 'summary)))
8971      (t
8972       (error "Couldn't select virtual nndoc group")))))
8973
8974 (defun gnus-summary-isearch-article (&optional regexp-p)
8975   "Do incremental search forward on the current article.
8976 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8977   (interactive "P")
8978   (gnus-summary-select-article)
8979   (gnus-configure-windows 'article)
8980   (gnus-eval-in-buffer-window gnus-article-buffer
8981     (save-restriction
8982       (widen)
8983       (isearch-forward regexp-p))))
8984
8985 (defun gnus-summary-repeat-search-article-forward ()
8986   "Repeat the previous search forwards."
8987   (interactive)
8988   (unless gnus-last-search-regexp
8989     (error "No previous search"))
8990   (gnus-summary-search-article-forward gnus-last-search-regexp))
8991
8992 (defun gnus-summary-repeat-search-article-backward ()
8993   "Repeat the previous search backwards."
8994   (interactive)
8995   (unless gnus-last-search-regexp
8996     (error "No previous search"))
8997   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8998
8999 (defun gnus-summary-search-article-forward (regexp &optional backward)
9000   "Search for an article containing REGEXP forward.
9001 If BACKWARD, search backward instead."
9002   (interactive
9003    (list (read-string
9004           (format "Search article %s (regexp%s): "
9005                   (if current-prefix-arg "backward" "forward")
9006                   (if gnus-last-search-regexp
9007                       (concat ", default " gnus-last-search-regexp)
9008                     "")))
9009          current-prefix-arg))
9010   (if (string-equal regexp "")
9011       (setq regexp (or gnus-last-search-regexp ""))
9012     (setq gnus-last-search-regexp regexp)
9013     (setq gnus-article-before-search gnus-current-article))
9014   ;; Intentionally set gnus-last-article.
9015   (setq gnus-last-article gnus-article-before-search)
9016   (let ((gnus-last-article gnus-last-article))
9017     (if (gnus-summary-search-article regexp backward)
9018         (gnus-summary-show-thread)
9019       (signal 'search-failed (list regexp)))))
9020
9021 (defun gnus-summary-search-article-backward (regexp)
9022   "Search for an article containing REGEXP backward."
9023   (interactive
9024    (list (read-string
9025           (format "Search article backward (regexp%s): "
9026                   (if gnus-last-search-regexp
9027                       (concat ", default " gnus-last-search-regexp)
9028                     "")))))
9029   (gnus-summary-search-article-forward regexp 'backward))
9030
9031 (defun gnus-summary-search-article (regexp &optional backward)
9032   "Search for an article containing REGEXP.
9033 Optional argument BACKWARD means do search for backward.
9034 `gnus-select-article-hook' is not called during the search."
9035   ;; We have to require this here to make sure that the following
9036   ;; dynamic binding isn't shadowed by autoloading.
9037   (require 'gnus-async)
9038   (require 'gnus-art)
9039   (let ((gnus-select-article-hook nil)  ;Disable hook.
9040         (gnus-article-prepare-hook nil)
9041         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9042         (gnus-use-article-prefetch nil)
9043         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9044         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9045         (gnus-visual nil)
9046         (gnus-keep-backlog nil)
9047         (gnus-break-pages nil)
9048         (gnus-summary-display-arrow nil)
9049         (gnus-updated-mode-lines nil)
9050         (gnus-auto-center-summary nil)
9051         (sum (current-buffer))
9052         (gnus-display-mime-function nil)
9053         (found nil)
9054         point)
9055     (gnus-save-hidden-threads
9056       (gnus-summary-select-article)
9057       (set-buffer gnus-article-buffer)
9058       (goto-char (window-point (get-buffer-window (current-buffer))))
9059       (when backward
9060         (forward-line -1))
9061       (while (not found)
9062         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9063         (if (if backward
9064                 (re-search-backward regexp nil t)
9065               (re-search-forward regexp nil t))
9066             ;; We found the regexp.
9067             (progn
9068               (setq found 'found)
9069               (beginning-of-line)
9070               (set-window-start
9071                (get-buffer-window (current-buffer))
9072                (point))
9073               (forward-line 1)
9074               (set-window-point
9075                (get-buffer-window (current-buffer))
9076                (point))
9077               (set-buffer sum)
9078               (setq point (point)))
9079           ;; We didn't find it, so we go to the next article.
9080           (set-buffer sum)
9081           (setq found 'not)
9082           (while (eq found 'not)
9083             (if (not (if backward (gnus-summary-find-prev)
9084                        (gnus-summary-find-next)))
9085                 ;; No more articles.
9086                 (setq found t)
9087               ;; Select the next article and adjust point.
9088               (unless (gnus-summary-article-sparse-p
9089                        (gnus-summary-article-number))
9090                 (setq found nil)
9091                 (gnus-summary-select-article)
9092                 (set-buffer gnus-article-buffer)
9093                 (widen)
9094                 (goto-char (if backward (point-max) (point-min))))))))
9095       (gnus-message 7 ""))
9096     ;; Return whether we found the regexp.
9097     (when (eq found 'found)
9098       (goto-char point)
9099       (gnus-summary-show-thread)
9100       (gnus-summary-goto-subject gnus-current-article)
9101       (gnus-summary-position-point)
9102       t)))
9103
9104 (defun gnus-find-matching-articles (header regexp)
9105   "Return a list of all articles that match REGEXP on HEADER.
9106 This search includes all articles in the current group that Gnus has
9107 fetched headers for, whether they are displayed or not."
9108   (let ((articles nil)
9109         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9110         (case-fold-search t))
9111     (dolist (header gnus-newsgroup-headers)
9112       (when (string-match regexp (funcall func header))
9113         (push (mail-header-number header) articles)))
9114     (nreverse articles)))
9115
9116 (defun gnus-summary-find-matching (header regexp &optional backward unread
9117                                           not-case-fold not-matching)
9118   "Return a list of all articles that match REGEXP on HEADER.
9119 The search stars on the current article and goes forwards unless
9120 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9121 If UNREAD is non-nil, only unread articles will
9122 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9123 in the comparisons. If NOT-MATCHING, return a list of all articles that
9124 not match REGEXP on HEADER."
9125   (let ((case-fold-search (not not-case-fold))
9126         articles d func)
9127     (if (consp header)
9128         (if (eq (car header) 'extra)
9129             (setq func
9130                   `(lambda (h)
9131                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9132                          "")))
9133           (error "%s is an invalid header" header))
9134       (unless (fboundp (intern (concat "mail-header-" header)))
9135         (error "%s is not a valid header" header))
9136       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9137     (dolist (d (if (eq backward 'all)
9138                    gnus-newsgroup-data
9139                  (gnus-data-find-list
9140                   (gnus-summary-article-number)
9141                   (gnus-data-list backward))))
9142       (when (and (or (not unread)       ; We want all articles...
9143                      (gnus-data-unread-p d)) ; Or just unreads.
9144                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9145                  (if not-matching
9146                      (not (string-match
9147                            regexp
9148                            (funcall func (gnus-data-header d))))
9149                    (string-match regexp
9150                                  (funcall func (gnus-data-header d)))))
9151         (push (gnus-data-number d) articles))) ; Success!
9152     (nreverse articles)))
9153
9154 (defun gnus-summary-execute-command (header regexp command &optional backward)
9155   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9156 If HEADER is an empty string (or nil), the match is done on the entire
9157 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9158   (interactive
9159    (list (let ((completion-ignore-case t))
9160            (completing-read
9161             "Header name: "
9162             (mapcar (lambda (header) (list (format "%s" header)))
9163                     (append
9164                      '("Number" "Subject" "From" "Lines" "Date"
9165                        "Message-ID" "Xref" "References" "Body")
9166                      gnus-extra-headers))
9167             nil 'require-match))
9168          (read-string "Regexp: ")
9169          (read-key-sequence "Command: ")
9170          current-prefix-arg))
9171   (when (equal header "Body")
9172     (setq header ""))
9173   ;; Hidden thread subtrees must be searched as well.
9174   (gnus-summary-show-all-threads)
9175   ;; We don't want to change current point nor window configuration.
9176   (save-excursion
9177     (save-window-excursion
9178       (let (gnus-visual
9179             gnus-treat-strip-trailing-blank-lines
9180             gnus-treat-strip-leading-blank-lines
9181             gnus-treat-strip-multiple-blank-lines
9182             gnus-treat-hide-boring-headers
9183             gnus-treat-fold-newsgroups
9184             gnus-article-prepare-hook)
9185         (gnus-message 6 "Executing %s..." (key-description command))
9186         ;; We'd like to execute COMMAND interactively so as to give arguments.
9187         (gnus-execute header regexp
9188                       `(call-interactively ',(key-binding command))
9189                       backward)
9190         (gnus-message 6 "Executing %s...done" (key-description command))))))
9191
9192 (defun gnus-summary-beginning-of-article ()
9193   "Scroll the article back to the beginning."
9194   (interactive)
9195   (gnus-summary-select-article)
9196   (gnus-configure-windows 'article)
9197   (gnus-eval-in-buffer-window gnus-article-buffer
9198     (widen)
9199     (goto-char (point-min))
9200     (when gnus-break-pages
9201       (gnus-narrow-to-page))))
9202
9203 (defun gnus-summary-end-of-article ()
9204   "Scroll to the end of the article."
9205   (interactive)
9206   (gnus-summary-select-article)
9207   (gnus-configure-windows 'article)
9208   (gnus-eval-in-buffer-window gnus-article-buffer
9209     (widen)
9210     (goto-char (point-max))
9211     (recenter -3)
9212     (when gnus-break-pages
9213       (when (re-search-backward page-delimiter nil t)
9214         (narrow-to-region (match-end 0) (point-max)))
9215       (gnus-narrow-to-page))))
9216
9217 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9218   "Truncate to LEN and quote all \"(\"'s in STRING."
9219   (gnus-replace-in-string (if (and len (> (length string) len))
9220                               (substring string 0 len)
9221                             string)
9222                           "[()]" "\\\\\\&"))
9223
9224 (defun gnus-summary-print-article (&optional filename n)
9225   "Generate and print a PostScript image of the process-marked (mail) articles.
9226
9227 If used interactively, print the current article if none are
9228 process-marked.  With prefix arg, prompt the user for the name of the
9229 file to save in.
9230
9231 When used from Lisp, accept two optional args FILENAME and N.  N means
9232 to print the next N articles.  If N is negative, print the N previous
9233 articles.  If N is nil and articles have been marked with the process
9234 mark, print these instead.
9235
9236 If the optional first argument FILENAME is nil, send the image to the
9237 printer.  If FILENAME is a string, save the PostScript image in a file with
9238 that name.  If FILENAME is a number, prompt the user for the name of the file
9239 to save in."
9240   (interactive (list (ps-print-preprint current-prefix-arg)))
9241   (dolist (article (gnus-summary-work-articles n))
9242     (gnus-summary-select-article nil nil 'pseudo article)
9243     (gnus-eval-in-buffer-window gnus-article-buffer
9244       (gnus-print-buffer))
9245     (gnus-summary-remove-process-mark article))
9246   (ps-despool filename))
9247
9248 (defun gnus-print-buffer ()
9249   (let ((buffer (generate-new-buffer " *print*")))
9250     (unwind-protect
9251         (progn
9252           (copy-to-buffer buffer (point-min) (point-max))
9253           (set-buffer buffer)
9254           (gnus-remove-text-with-property 'gnus-decoration)
9255           (when (gnus-visual-p 'article-highlight 'highlight)
9256             ;; Copy-to-buffer doesn't copy overlay.  So redo
9257             ;; highlight.
9258             (let ((gnus-article-buffer buffer))
9259               (gnus-article-highlight-citation t)
9260               (gnus-article-highlight-signature)
9261               (gnus-article-emphasize)
9262               (gnus-article-delete-invisible-text)))
9263           (let ((ps-left-header
9264                  (list
9265                   (concat "("
9266                           (gnus-summary-print-truncate-and-quote
9267                            (mail-header-subject gnus-current-headers)
9268                            66) ")")
9269                   (concat "("
9270                           (gnus-summary-print-truncate-and-quote
9271                            (mail-header-from gnus-current-headers)
9272                            45) ")")))
9273                 (ps-right-header
9274                  (list
9275                   "/pagenumberstring load"
9276                   (concat "("
9277                           (mail-header-date gnus-current-headers) ")"))))
9278             (gnus-run-hooks 'gnus-ps-print-hook)
9279             (save-excursion
9280               (if window-system
9281                   (ps-spool-buffer-with-faces)
9282                 (ps-spool-buffer)))))
9283       (kill-buffer buffer))))
9284
9285 (defun gnus-summary-show-article (&optional arg)
9286   "Force redisplaying of the current article.
9287 If ARG (the prefix) is a number, show the article with the charset
9288 defined in `gnus-summary-show-article-charset-alist', or the charset
9289 input.
9290 If ARG (the prefix) is non-nil and not a number, show the raw article
9291 without any article massaging functions being run.  Normally, the key
9292 strokes are `C-u g'."
9293   (interactive "P")
9294   (cond
9295    ((numberp arg)
9296     (gnus-summary-show-article t)
9297     (let ((gnus-newsgroup-charset
9298            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9299                (mm-read-coding-system
9300                 "View as charset: " ;; actually it is coding system.
9301                 (with-current-buffer gnus-article-buffer
9302                   (mm-detect-coding-region (point) (point-max))))))
9303           (gnus-newsgroup-ignored-charsets 'gnus-all))
9304       (gnus-summary-select-article nil 'force)
9305       (let ((deps gnus-newsgroup-dependencies)
9306             head header lines)
9307         (save-excursion
9308           (set-buffer gnus-original-article-buffer)
9309           (save-restriction
9310             (message-narrow-to-head)
9311             (setq head (buffer-string))
9312             (goto-char (point-min))
9313             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9314               (goto-char (point-max))
9315               (widen)
9316               (setq lines (1- (count-lines (point) (point-max))))))
9317           (with-temp-buffer
9318             (insert (format "211 %d Article retrieved.\n"
9319                             (cdr gnus-article-current)))
9320             (insert head)
9321             (if lines (insert (format "Lines: %d\n" lines)))
9322             (insert ".\n")
9323             (let ((nntp-server-buffer (current-buffer)))
9324               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9325         (gnus-data-set-header
9326          (gnus-data-find (cdr gnus-article-current))
9327          header)
9328         (gnus-summary-update-article-line
9329          (cdr gnus-article-current) header)
9330         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9331           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9332    ((not arg)
9333     ;; Select the article the normal way.
9334     (gnus-summary-select-article nil 'force))
9335    (t
9336     ;; We have to require this here to make sure that the following
9337     ;; dynamic binding isn't shadowed by autoloading.
9338     (require 'gnus-async)
9339     (require 'gnus-art)
9340     ;; Bind the article treatment functions to nil.
9341     (let ((gnus-have-all-headers t)
9342           gnus-article-prepare-hook
9343           gnus-article-decode-hook
9344           gnus-display-mime-function
9345           gnus-break-pages)
9346       ;; Destroy any MIME parts.
9347       (when (gnus-buffer-live-p gnus-article-buffer)
9348         (save-excursion
9349           (set-buffer gnus-article-buffer)
9350           (mm-destroy-parts gnus-article-mime-handles)
9351           ;; Set it to nil for safety reason.
9352           (setq gnus-article-mime-handle-alist nil)
9353           (setq gnus-article-mime-handles nil)))
9354       (gnus-summary-select-article nil 'force))))
9355   (gnus-summary-goto-subject gnus-current-article)
9356   (gnus-summary-position-point))
9357
9358 (defun gnus-summary-show-raw-article ()
9359   "Show the raw article without any article massaging functions being run."
9360   (interactive)
9361   (gnus-summary-show-article t))
9362
9363 (defun gnus-summary-verbose-headers (&optional arg)
9364   "Toggle permanent full header display.
9365 If ARG is a positive number, turn header display on.
9366 If ARG is a negative number, turn header display off."
9367   (interactive "P")
9368   (setq gnus-show-all-headers
9369         (cond ((or (not (numberp arg))
9370                    (zerop arg))
9371                (not gnus-show-all-headers))
9372               ((natnump arg)
9373                t)))
9374   (gnus-summary-show-article))
9375
9376 (defun gnus-summary-toggle-header (&optional arg)
9377   "Show the headers if they are hidden, or hide them if they are shown.
9378 If ARG is a positive number, show the entire header.
9379 If ARG is a negative number, hide the unwanted header lines."
9380   (interactive "P")
9381   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9382                      (get-buffer-window gnus-article-buffer t))))
9383     (with-current-buffer gnus-article-buffer
9384       (widen)
9385       (article-narrow-to-head)
9386       (let* ((buffer-read-only nil)
9387              (inhibit-point-motion-hooks t)
9388              (hidden (if (numberp arg)
9389                          (>= arg 0)
9390                        (or (not (looking-at "[^ \t\n]+:"))
9391                            (gnus-article-hidden-text-p 'headers))))
9392              s e)
9393         (delete-region (point-min) (point-max))
9394         (with-current-buffer gnus-original-article-buffer
9395           (goto-char (setq s (point-min)))
9396           (setq e (if (search-forward "\n\n" nil t)
9397                       (1- (point))
9398                     (point-max))))
9399         (insert-buffer-substring gnus-original-article-buffer s e)
9400         (run-hooks 'gnus-article-decode-hook)
9401         (if hidden
9402             (let ((gnus-treat-hide-headers nil)
9403                   (gnus-treat-hide-boring-headers nil))
9404               (gnus-delete-wash-type 'headers)
9405               (gnus-treat-article 'head))
9406           (gnus-treat-article 'head))
9407         (widen)
9408         (if window
9409             (set-window-start window (goto-char (point-min))))
9410         (if gnus-break-pages
9411             (gnus-narrow-to-page)
9412           (when (gnus-visual-p 'page-marker)
9413             (let ((buffer-read-only nil))
9414               (gnus-remove-text-with-property 'gnus-prev)
9415               (gnus-remove-text-with-property 'gnus-next))))
9416         (gnus-set-mode-line 'article)))))
9417
9418 (defun gnus-summary-show-all-headers ()
9419   "Make all header lines visible."
9420   (interactive)
9421   (gnus-summary-toggle-header 1))
9422
9423 (defun gnus-summary-caesar-message (&optional arg)
9424   "Caesar rotate the current article by 13.
9425 With a non-numerical prefix, also rotate headers.  A numerical
9426 prefix specifies how many places to rotate each letter forward."
9427   (interactive "P")
9428   (gnus-summary-select-article)
9429   (let ((mail-header-separator ""))
9430     (gnus-eval-in-buffer-window gnus-article-buffer
9431       (save-restriction
9432         (widen)
9433         (let ((start (window-start))
9434               buffer-read-only)
9435           (if (equal arg '(4))
9436               (message-caesar-buffer-body nil t)
9437             (message-caesar-buffer-body arg))
9438           (set-window-start (get-buffer-window (current-buffer)) start)))))
9439   ;; Create buttons and stuff...
9440   (gnus-treat-article nil))
9441
9442 (defun gnus-summary-idna-message (&optional arg)
9443   "Decode IDNA encoded domain names in the current articles.
9444 IDNA encoded domain names looks like `xn--bar'.  If a string
9445 remain unencoded after running this function, it is likely an
9446 invalid IDNA string (`xn--bar' is invalid).
9447
9448 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9449 installed for this command to work."
9450   (interactive "P")
9451   (if (not (and (condition-case nil (require 'idna)
9452                   (file-error))
9453                 (mm-coding-system-p 'utf-8)
9454                 (executable-find (symbol-value 'idna-program))))
9455       (gnus-message
9456        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9457     (gnus-summary-select-article)
9458     (let ((mail-header-separator ""))
9459       (gnus-eval-in-buffer-window gnus-article-buffer
9460         (save-restriction
9461           (widen)
9462           (let ((start (window-start))
9463                 buffer-read-only)
9464             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9465               (replace-match (idna-to-unicode (match-string 1))))
9466             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9467
9468 (defun gnus-summary-morse-message (&optional arg)
9469   "Morse decode the current article."
9470   (interactive "P")
9471   (gnus-summary-select-article)
9472   (let ((mail-header-separator ""))
9473     (gnus-eval-in-buffer-window gnus-article-buffer
9474       (save-excursion
9475         (save-restriction
9476           (widen)
9477           (let ((pos (window-start))
9478                 buffer-read-only)
9479             (goto-char (point-min))
9480             (when (message-goto-body)
9481               (gnus-narrow-to-body))
9482             (goto-char (point-min))
9483             (while (search-forward "·" (point-max) t)
9484               (replace-match "."))
9485             (unmorse-region (point-min) (point-max))
9486             (widen)
9487             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9488
9489 (defun gnus-summary-stop-page-breaking ()
9490   "Stop page breaking in the current article."
9491   (interactive)
9492   (gnus-summary-select-article)
9493   (gnus-eval-in-buffer-window gnus-article-buffer
9494     (widen)
9495     (when (gnus-visual-p 'page-marker)
9496       (let ((buffer-read-only nil))
9497         (gnus-remove-text-with-property 'gnus-prev)
9498         (gnus-remove-text-with-property 'gnus-next))
9499       (setq gnus-page-broken nil))))
9500
9501 (defun gnus-summary-move-article (&optional n to-newsgroup
9502                                             select-method action)
9503   "Move the current article to a different newsgroup.
9504 If N is a positive number, move the N next articles.
9505 If N is a negative number, move the N previous articles.
9506 If N is nil and any articles have been marked with the process mark,
9507 move those articles instead.
9508 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9509 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9510 re-spool using this method.
9511
9512 When called interactively with TO-NEWSGROUP being nil, the value of
9513 the variable `gnus-move-split-methods' is used for finding a default
9514 for the target newsgroup.
9515
9516 For this function to work, both the current newsgroup and the
9517 newsgroup that you want to move to have to support the `request-move'
9518 and `request-accept' functions.
9519
9520 ACTION can be either `move' (the default), `crosspost' or `copy'."
9521   (interactive "P")
9522   (unless action
9523     (setq action 'move))
9524   ;; Check whether the source group supports the required functions.
9525   (cond ((and (eq action 'move)
9526               (not (gnus-check-backend-function
9527                     'request-move-article gnus-newsgroup-name)))
9528          (error "The current group does not support article moving"))
9529         ((and (eq action 'crosspost)
9530               (not (gnus-check-backend-function
9531                     'request-replace-article gnus-newsgroup-name)))
9532          (error "The current group does not support article editing")))
9533   (let ((articles (gnus-summary-work-articles n))
9534         (prefix (if (gnus-check-backend-function
9535                      'request-move-article gnus-newsgroup-name)
9536                     (funcall gnus-move-group-prefix-function
9537                              gnus-newsgroup-name)
9538                   ""))
9539         (names '((move "Move" "Moving")
9540                  (copy "Copy" "Copying")
9541                  (crosspost "Crosspost" "Crossposting")))
9542         (copy-buf (save-excursion
9543                     (nnheader-set-temp-buffer " *copy article*")))
9544         art-group to-method new-xref article to-groups
9545         articles-to-update-marks encoded)
9546     (unless (assq action names)
9547       (error "Unknown action %s" action))
9548     ;; Read the newsgroup name.
9549     (when (and (not to-newsgroup)
9550                (not select-method))
9551       (if (and gnus-move-split-methods
9552                (not
9553                 (and (memq gnus-current-article articles)
9554                      (gnus-buffer-live-p gnus-original-article-buffer))))
9555           ;; When `gnus-move-split-methods' is non-nil, we have to
9556           ;; select an article to give `gnus-read-move-group-name' an
9557           ;; opportunity to suggest an appropriate default.  However,
9558           ;; we needn't render or mark the article.
9559           (let ((gnus-display-mime-function nil)
9560                 (gnus-article-prepare-hook nil)
9561                 (gnus-mark-article-hook nil))
9562             (gnus-summary-select-article nil nil nil (car articles))))
9563       (setq to-newsgroup (gnus-read-move-group-name
9564                           (cadr (assq action names))
9565                           (symbol-value
9566                            (intern (format "gnus-current-%s-group" action)))
9567                           articles prefix)
9568             encoded to-newsgroup
9569             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9570       (set (intern (format "gnus-current-%s-group" action))
9571            (mm-decode-coding-string
9572             to-newsgroup
9573             (gnus-group-name-charset to-method to-newsgroup))))
9574     (unless to-method
9575       (setq to-method (or select-method
9576                           (gnus-server-to-method
9577                            (gnus-group-method to-newsgroup)))))
9578     (setq to-newsgroup
9579           (or encoded
9580               (and to-newsgroup
9581                    (mm-encode-coding-string
9582                     to-newsgroup
9583                     (gnus-group-name-charset to-method to-newsgroup)))))
9584     ;; Check the method we are to move this article to...
9585     (unless (gnus-check-backend-function
9586              'request-accept-article (car to-method))
9587       (error "%s does not support article copying" (car to-method)))
9588     (unless (gnus-check-server to-method)
9589       (error "Can't open server %s" (car to-method)))
9590     (gnus-message 6 "%s to %s: %s..."
9591                   (caddr (assq action names))
9592                   (or (car select-method)
9593                       (gnus-group-decoded-name to-newsgroup))
9594                   articles)
9595     (while articles
9596       (setq article (pop articles))
9597       (setq
9598        art-group
9599        (cond
9600         ;; Move the article.
9601         ((eq action 'move)
9602          ;; Remove this article from future suppression.
9603          (gnus-dup-unsuppress-article article)
9604          (let* ((from-method (gnus-find-method-for-group
9605                               gnus-newsgroup-name))
9606                 (to-method (or select-method
9607                                (gnus-find-method-for-group to-newsgroup)))
9608                 (move-is-internal (gnus-method-equal from-method to-method)))
9609            (gnus-request-move-article
9610             article                     ; Article to move
9611             gnus-newsgroup-name         ; From newsgroup
9612             (nth 1 (gnus-find-method-for-group
9613                     gnus-newsgroup-name)) ; Server
9614             (list 'gnus-request-accept-article
9615                   to-newsgroup (list 'quote select-method)
9616                   (not articles) t)     ; Accept form
9617             (not articles)              ; Only save nov last time
9618             move-is-internal)))         ; is this move internal?
9619         ;; Copy the article.
9620         ((eq action 'copy)
9621          (save-excursion
9622            (set-buffer copy-buf)
9623            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9624              (save-restriction
9625                (nnheader-narrow-to-headers)
9626                (dolist (hdr gnus-copy-article-ignored-headers)
9627                  (message-remove-header hdr t)))
9628              (gnus-request-accept-article
9629               to-newsgroup select-method (not articles) t))))
9630         ;; Crosspost the article.
9631         ((eq action 'crosspost)
9632          (let ((xref (message-tokenize-header
9633                       (mail-header-xref (gnus-summary-article-header article))
9634                       " ")))
9635            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9636                                   ":" (number-to-string article)))
9637            (unless xref
9638              (setq xref (list (system-name))))
9639            (setq new-xref
9640                  (concat
9641                   (mapconcat 'identity
9642                              (delete "Xref:" (delete new-xref xref))
9643                              " ")
9644                   " " new-xref))
9645            (save-excursion
9646              (set-buffer copy-buf)
9647              ;; First put the article in the destination group.
9648              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9649              (when (consp (setq art-group
9650                                 (gnus-request-accept-article
9651                                  to-newsgroup select-method (not articles) t)))
9652                (setq new-xref (concat new-xref " " (car art-group)
9653                                       ":"
9654                                       (number-to-string (cdr art-group))))
9655                ;; Now we have the new Xrefs header, so we insert
9656                ;; it and replace the new article.
9657                (nnheader-replace-header "Xref" new-xref)
9658                (gnus-request-replace-article
9659                 (cdr art-group) to-newsgroup (current-buffer) t)
9660                art-group))))))
9661       (cond
9662        ((not art-group)
9663         (gnus-message 1 "Couldn't %s article %s: %s"
9664                       (cadr (assq action names)) article
9665                       (nnheader-get-report (car to-method))))
9666        ((eq art-group 'junk)
9667         (when (eq action 'move)
9668           (gnus-summary-mark-article article gnus-canceled-mark)
9669           (gnus-message 4 "Deleted article %s" article)
9670           ;; run the delete hook
9671           (run-hook-with-args 'gnus-summary-article-delete-hook
9672                               action
9673                               (gnus-data-header
9674                                (assoc article (gnus-data-list nil)))
9675                               gnus-newsgroup-name nil
9676                               select-method)))
9677        (t
9678         (let* ((pto-group (gnus-group-prefixed-name
9679                            (car art-group) to-method))
9680                (info (gnus-get-info pto-group))
9681                (to-group (gnus-info-group info))
9682                to-marks)
9683           ;; Update the group that has been moved to.
9684           (when (and info
9685                      (memq action '(move copy)))
9686             (unless (member to-group to-groups)
9687               (push to-group to-groups))
9688
9689             (unless (memq article gnus-newsgroup-unreads)
9690               (push 'read to-marks)
9691               (gnus-info-set-read
9692                info (gnus-add-to-range (gnus-info-read info)
9693                                        (list (cdr art-group)))))
9694
9695             ;; See whether the article is to be put in the cache.
9696             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9697                              gnus-article-mark-lists
9698                            (delete '(expirable . expire)
9699                                    (copy-sequence gnus-article-mark-lists))))
9700                   (to-article (cdr art-group)))
9701
9702               ;; Enter the article into the cache in the new group,
9703               ;; if that is required.
9704               (when gnus-use-cache
9705                 (gnus-cache-possibly-enter-article
9706                  to-group to-article
9707                  (memq article gnus-newsgroup-marked)
9708                  (memq article gnus-newsgroup-dormant)
9709                  (memq article gnus-newsgroup-unreads)))
9710
9711               (when gnus-preserve-marks
9712                 ;; Copy any marks over to the new group.
9713                 (when (and (equal to-group gnus-newsgroup-name)
9714                            (not (memq article gnus-newsgroup-unreads)))
9715                   ;; Mark this article as read in this group.
9716                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9717                   (setcdr (gnus-active to-group) to-article)
9718                   (setcdr gnus-newsgroup-active to-article))
9719
9720                 (while marks
9721                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9722                     (when (memq article (symbol-value
9723                                          (intern (format "gnus-newsgroup-%s"
9724                                                          (caar marks)))))
9725                       (push (cdar marks) to-marks)
9726                       ;; If the other group is the same as this group,
9727                       ;; then we have to add the mark to the list.
9728                       (when (equal to-group gnus-newsgroup-name)
9729                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9730                              (cons to-article
9731                                    (symbol-value
9732                                     (intern (format "gnus-newsgroup-%s"
9733                                                     (caar marks)))))))
9734                       ;; Copy the marks to other group.
9735                       (gnus-add-marked-articles
9736                        to-group (cdar marks) (list to-article) info)))
9737                   (setq marks (cdr marks)))
9738
9739                 (gnus-request-set-mark
9740                  to-group (list (list (list to-article) 'add to-marks))))
9741
9742               (gnus-dribble-enter
9743                (concat "(gnus-group-set-info '"
9744                        (gnus-prin1-to-string (gnus-get-info to-group))
9745                        ")"))))
9746
9747           ;; Update the Xref header in this article to point to
9748           ;; the new crossposted article we have just created.
9749           (when (eq action 'crosspost)
9750             (save-excursion
9751               (set-buffer copy-buf)
9752               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9753               (nnheader-replace-header "Xref" new-xref)
9754               (gnus-request-replace-article
9755                article gnus-newsgroup-name (current-buffer) t)))
9756
9757           ;; run the move/copy/crosspost/respool hook
9758           (run-hook-with-args 'gnus-summary-article-move-hook
9759                               action
9760                               (gnus-data-header
9761                                (assoc article (gnus-data-list nil)))
9762                               gnus-newsgroup-name
9763                               to-newsgroup
9764                               select-method))
9765
9766         ;;;!!!Why is this necessary?
9767         (set-buffer gnus-summary-buffer)
9768
9769         (gnus-summary-goto-subject article)
9770         (when (eq action 'move)
9771           (gnus-summary-mark-article article gnus-canceled-mark))))
9772       (push article articles-to-update-marks))
9773
9774     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9775     ;; Re-activate all groups that have been moved to.
9776     (save-excursion
9777       (set-buffer gnus-group-buffer)
9778       (let ((gnus-group-marked to-groups))
9779         (gnus-group-get-new-news-this-group nil t)))
9780
9781     (gnus-kill-buffer copy-buf)
9782     (gnus-summary-position-point)
9783     (gnus-set-mode-line 'summary)))
9784
9785 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9786   "Copy the current article to some other group.
9787 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9788 When called interactively, if TO-NEWSGROUP is nil, use the value of
9789 the variable `gnus-move-split-methods' for finding a default target
9790 newsgroup.
9791 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9792 re-spool using this method."
9793   (interactive "P")
9794   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9795
9796 (defun gnus-summary-crosspost-article (&optional n)
9797   "Crosspost the current article to some other group."
9798   (interactive "P")
9799   (gnus-summary-move-article n nil nil 'crosspost))
9800
9801 (defcustom gnus-summary-respool-default-method nil
9802   "Default method type for respooling an article.
9803 If nil, use to the current newsgroup method."
9804   :type 'symbol
9805   :group 'gnus-summary-mail)
9806
9807 (defcustom gnus-summary-display-while-building nil
9808   "If non-nil, show and update the summary buffer as it's being built.
9809 If the value is t, update the buffer after every line is inserted.  If
9810 the value is an integer (N), update the display every N lines."
9811   :version "22.1"
9812   :group 'gnus-thread
9813   :type '(choice (const :tag "off" nil)
9814                  number
9815                  (const :tag "frequently" t)))
9816
9817 (defun gnus-summary-respool-article (&optional n method)
9818   "Respool the current article.
9819 The article will be squeezed through the mail spooling process again,
9820 which means that it will be put in some mail newsgroup or other
9821 depending on `nnmail-split-methods'.
9822 If N is a positive number, respool the N next articles.
9823 If N is a negative number, respool the N previous articles.
9824 If N is nil and any articles have been marked with the process mark,
9825 respool those articles instead.
9826
9827 Respooling can be done both from mail groups and \"real\" newsgroups.
9828 In the former case, the articles in question will be moved from the
9829 current group into whatever groups they are destined to.  In the
9830 latter case, they will be copied into the relevant groups."
9831   (interactive
9832    (list current-prefix-arg
9833          (let* ((methods (gnus-methods-using 'respool))
9834                 (methname
9835                  (symbol-name (or gnus-summary-respool-default-method
9836                                   (car (gnus-find-method-for-group
9837                                         gnus-newsgroup-name)))))
9838                 (method
9839                  (gnus-completing-read-with-default
9840                   methname "Backend to use when respooling"
9841                   methods nil t nil 'gnus-mail-method-history))
9842                 ms)
9843            (cond
9844             ((zerop (length (setq ms (gnus-servers-using-backend
9845                                       (intern method)))))
9846              (list (intern method) ""))
9847             ((= 1 (length ms))
9848              (car ms))
9849             (t
9850              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9851                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9852                            ms-alist))))))))
9853   (unless method
9854     (error "No method given for respooling"))
9855   (if (assoc (symbol-name
9856               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9857              (gnus-methods-using 'respool))
9858       (gnus-summary-move-article n nil method)
9859     (gnus-summary-copy-article n nil method)))
9860
9861 (defun gnus-summary-import-article (file &optional edit)
9862   "Import an arbitrary file into a mail newsgroup."
9863   (interactive "fImport file: \nP")
9864   (let ((group gnus-newsgroup-name)
9865         (now (current-time))
9866         atts lines group-art)
9867     (unless (gnus-check-backend-function 'request-accept-article group)
9868       (error "%s does not support article importing" group))
9869     (or (file-readable-p file)
9870         (not (file-regular-p file))
9871         (error "Can't read %s" file))
9872     (save-excursion
9873       (set-buffer (gnus-get-buffer-create " *import file*"))
9874       (erase-buffer)
9875       (nnheader-insert-file-contents file)
9876       (goto-char (point-min))
9877       (if (nnheader-article-p)
9878           (save-restriction
9879             (goto-char (point-min))
9880             (search-forward "\n\n" nil t)
9881             (narrow-to-region (point-min) (1- (point)))
9882             (goto-char (point-min))
9883             (unless (re-search-forward "^date:" nil t)
9884               (goto-char (point-max))
9885               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9886        ;; This doesn't look like an article, so we fudge some headers.
9887         (setq atts (file-attributes file)
9888               lines (count-lines (point-min) (point-max)))
9889         (insert "From: " (read-string "From: ") "\n"
9890                 "Subject: " (read-string "Subject: ") "\n"
9891                 "Date: " (message-make-date (nth 5 atts)) "\n"
9892                 "Message-ID: " (message-make-message-id) "\n"
9893                 "Lines: " (int-to-string lines) "\n"
9894                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9895       (setq group-art (gnus-request-accept-article group nil t))
9896       (kill-buffer (current-buffer)))
9897     (setq gnus-newsgroup-active (gnus-activate-group group))
9898     (forward-line 1)
9899     (gnus-summary-goto-article (cdr group-art) nil t)
9900     (when edit
9901       (gnus-summary-edit-article))))
9902
9903 (defun gnus-summary-create-article ()
9904   "Create an article in a mail newsgroup."
9905   (interactive)
9906   (let ((group gnus-newsgroup-name)
9907         (now (current-time))
9908         group-art)
9909     (unless (gnus-check-backend-function 'request-accept-article group)
9910       (error "%s does not support article importing" group))
9911     (save-excursion
9912       (set-buffer (gnus-get-buffer-create " *import file*"))
9913       (erase-buffer)
9914       (goto-char (point-min))
9915       ;; This doesn't look like an article, so we fudge some headers.
9916       (insert "From: " (read-string "From: ") "\n"
9917               "Subject: " (read-string "Subject: ") "\n"
9918               "Date: " (message-make-date now) "\n"
9919               "Message-ID: " (message-make-message-id) "\n")
9920       (setq group-art (gnus-request-accept-article group nil t))
9921       (kill-buffer (current-buffer)))
9922     (setq gnus-newsgroup-active (gnus-activate-group group))
9923     (forward-line 1)
9924     (gnus-summary-goto-article (cdr group-art) nil t)
9925     (gnus-summary-edit-article)))
9926
9927 (defun gnus-summary-article-posted-p ()
9928   "Say whether the current (mail) article is available from news as well.
9929 This will be the case if the article has both been mailed and posted."
9930   (interactive)
9931   (let ((id (mail-header-references (gnus-summary-article-header)))
9932         (gnus-override-method (car (gnus-refer-article-methods))))
9933     (if (gnus-request-head id "")
9934         (gnus-message 2 "The current message was found on %s"
9935                       gnus-override-method)
9936       (gnus-message 2 "The current message couldn't be found on %s"
9937                     gnus-override-method)
9938       nil)))
9939
9940 (defun gnus-summary-expire-articles (&optional now)
9941   "Expire all articles that are marked as expirable in the current group."
9942   (interactive)
9943   (when (and (not gnus-group-is-exiting-without-update-p)
9944              (gnus-check-backend-function
9945               'request-expire-articles gnus-newsgroup-name))
9946     ;; This backend supports expiry.
9947     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9948            (expirable (if total
9949                           (progn
9950                             ;; We need to update the info for
9951                             ;; this group for `gnus-list-of-read-articles'
9952                             ;; to give us the right answer.
9953                             (gnus-run-hooks 'gnus-exit-group-hook)
9954                             (gnus-summary-update-info)
9955                             (gnus-list-of-read-articles gnus-newsgroup-name))
9956                         (setq gnus-newsgroup-expirable
9957                               (sort gnus-newsgroup-expirable '<))))
9958            (expiry-wait (if now 'immediate
9959                           (gnus-group-find-parameter
9960                            gnus-newsgroup-name 'expiry-wait)))
9961            (nnmail-expiry-target
9962             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9963                 nnmail-expiry-target))
9964            es)
9965       (when expirable
9966         ;; There are expirable articles in this group, so we run them
9967         ;; through the expiry process.
9968         (gnus-message 6 "Expiring articles...")
9969         (unless (gnus-check-group gnus-newsgroup-name)
9970           (error "Can't open server for %s" gnus-newsgroup-name))
9971         ;; The list of articles that weren't expired is returned.
9972         (save-excursion
9973           (if expiry-wait
9974               (let ((nnmail-expiry-wait-function nil)
9975                     (nnmail-expiry-wait expiry-wait))
9976                 (setq es (gnus-request-expire-articles
9977                           expirable gnus-newsgroup-name)))
9978             (setq es (gnus-request-expire-articles
9979                       expirable gnus-newsgroup-name)))
9980           (unless total
9981             (setq gnus-newsgroup-expirable es))
9982           ;; We go through the old list of expirable, and mark all
9983           ;; really expired articles as nonexistent.
9984           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9985             (let ((gnus-use-cache nil))
9986               (dolist (article expirable)
9987                 (when (and (not (memq article es))
9988                            (gnus-data-find article))
9989                   (gnus-summary-mark-article article gnus-canceled-mark)
9990                   (run-hook-with-args 'gnus-summary-article-expire-hook
9991                                       'delete
9992                                       (gnus-data-header
9993                                        (assoc article (gnus-data-list nil)))
9994                                       gnus-newsgroup-name
9995                                       nil
9996                                       nil))))))
9997         (gnus-message 6 "Expiring articles...done")))))
9998
9999 (defun gnus-summary-expire-articles-now ()
10000   "Expunge all expirable articles in the current group.
10001 This means that *all* articles that are marked as expirable will be
10002 deleted forever, right now."
10003   (interactive)
10004   (or gnus-expert-user
10005       (gnus-yes-or-no-p
10006        "Are you really, really sure you want to delete all expirable messages? ")
10007       (error "Phew!"))
10008   (gnus-summary-expire-articles t))
10009
10010 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10011 (defun gnus-summary-delete-article (&optional n)
10012   "Delete the N next (mail) articles.
10013 This command actually deletes articles.  This is not a marking
10014 command.  The article will disappear forever from your life, never to
10015 return.
10016
10017 If N is negative, delete backwards.
10018 If N is nil and articles have been marked with the process mark,
10019 delete these instead.
10020
10021 If `gnus-novice-user' is non-nil you will be asked for
10022 confirmation before the articles are deleted."
10023   (interactive "P")
10024   (unless (gnus-check-backend-function 'request-expire-articles
10025                                        gnus-newsgroup-name)
10026     (error "The current newsgroup does not support article deletion"))
10027   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10028     (error "Couldn't open server"))
10029   ;; Compute the list of articles to delete.
10030   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10031         (nnmail-expiry-target 'delete)
10032         not-deleted)
10033     (if (and gnus-novice-user
10034              (not (gnus-yes-or-no-p
10035                    (format "Do you really want to delete %s forever? "
10036                            (if (> (length articles) 1)
10037                                (format "these %s articles" (length articles))
10038                              "this article")))))
10039         ()
10040       ;; Delete the articles.
10041       (setq not-deleted (gnus-request-expire-articles
10042                          articles gnus-newsgroup-name 'force))
10043       (while articles
10044         (gnus-summary-remove-process-mark (car articles))
10045         ;; The backend might not have been able to delete the article
10046         ;; after all.
10047         (unless (memq (car articles) not-deleted)
10048           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10049         (let* ((article (car articles))
10050                (ghead  (gnus-data-header
10051                                     (assoc article (gnus-data-list nil)))))
10052           (run-hook-with-args 'gnus-summary-article-delete-hook
10053                               'delete ghead gnus-newsgroup-name nil
10054                               nil))
10055         (setq articles (cdr articles)))
10056       (when not-deleted
10057         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10058     (gnus-summary-position-point)
10059     (gnus-set-mode-line 'summary)
10060     not-deleted))
10061
10062 (defun gnus-summary-edit-article (&optional arg)
10063   "Edit the current article.
10064 This will have permanent effect only in mail groups.
10065 If ARG is nil, edit the decoded articles.
10066 If ARG is 1, edit the raw articles.
10067 If ARG is 2, edit the raw articles even in read-only groups.
10068 If ARG is 3, edit the articles with the current handles.
10069 Otherwise, allow editing of articles even in read-only
10070 groups."
10071   (interactive "P")
10072   (let (force raw current-handles)
10073     (cond
10074      ((null arg))
10075      ((eq arg 1)
10076       (setq raw t))
10077      ((eq arg 2)
10078       (setq raw t
10079             force t))
10080      ((eq arg 3)
10081       (setq current-handles
10082             (and (gnus-buffer-live-p gnus-article-buffer)
10083                  (with-current-buffer gnus-article-buffer
10084                    (prog1
10085                        gnus-article-mime-handles
10086                      (setq gnus-article-mime-handles nil))))))
10087      (t
10088       (setq force t)))
10089     (when (and raw (not force)
10090                (member gnus-newsgroup-name '("nndraft:delayed"
10091                                              "nndraft:drafts"
10092                                              "nndraft:queue")))
10093       (error "Can't edit the raw article in group %s"
10094              gnus-newsgroup-name))
10095     (save-excursion
10096       (set-buffer gnus-summary-buffer)
10097       (let ((mail-parse-charset gnus-newsgroup-charset)
10098             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10099         (gnus-set-global-variables)
10100         (when (and (not force)
10101                    (gnus-group-read-only-p))
10102           (error "The current newsgroup does not support article editing"))
10103         (gnus-summary-show-article t)
10104         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10105           (with-current-buffer gnus-article-buffer
10106             (mm-enable-multibyte)))
10107         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10108             (setq raw t))
10109         (gnus-article-edit-article
10110          (if raw 'ignore
10111            `(lambda ()
10112               (let ((mbl mml-buffer-list))
10113                 (setq mml-buffer-list nil)
10114                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10115                   (mime-to-mml ,'current-handles))
10116                 (let ((mbl1 mml-buffer-list))
10117                   (setq mml-buffer-list mbl)
10118                   (set (make-local-variable 'mml-buffer-list) mbl1))
10119                 (gnus-make-local-hook 'kill-buffer-hook)
10120                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10121          `(lambda (no-highlight)
10122             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10123                   (message-options message-options)
10124                   (message-options-set-recipient)
10125                   (mail-parse-ignored-charsets
10126                    ',gnus-newsgroup-ignored-charsets)
10127                   (rfc2047-header-encoding-alist
10128                    ',(let ((charset (gnus-group-name-charset
10129                                      (gnus-find-method-for-group
10130                                       gnus-newsgroup-name)
10131                                      gnus-newsgroup-name)))
10132                        (append (list (cons "Newsgroups" charset)
10133                                      (cons "Followup-To" charset)
10134                                      (cons "Xref" charset))
10135                                rfc2047-header-encoding-alist))))
10136               ,(if (not raw) '(progn
10137                                 (mml-to-mime)
10138                                 (mml-destroy-buffers)
10139                                 (remove-hook 'kill-buffer-hook
10140                                              'mml-destroy-buffers t)
10141                                 (kill-local-variable 'mml-buffer-list)))
10142               (gnus-summary-edit-article-done
10143                ,(or (mail-header-references gnus-current-headers) "")
10144                ,(gnus-group-read-only-p)
10145                ,gnus-summary-buffer no-highlight))))))))
10146
10147 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10148
10149 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10150                                                  no-highlight)
10151   "Make edits to the current article permanent."
10152   (interactive)
10153   (save-excursion
10154    ;; The buffer restriction contains the entire article if it exists.
10155     (when (article-goto-body)
10156       (let ((lines (count-lines (point) (point-max)))
10157             (length (- (point-max) (point)))
10158             (case-fold-search t)
10159             (body (copy-marker (point))))
10160         (goto-char (point-min))
10161         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10162           (delete-region (match-beginning 1) (match-end 1))
10163           (insert (number-to-string length)))
10164         (goto-char (point-min))
10165         (when (re-search-forward
10166                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10167           (delete-region (match-beginning 1) (match-end 1))
10168           (insert (number-to-string length)))
10169         (goto-char (point-min))
10170         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10171           (delete-region (match-beginning 1) (match-end 1))
10172           (insert (number-to-string lines))))))
10173   ;; Replace the article.
10174   (let ((buf (current-buffer)))
10175     (with-temp-buffer
10176       (insert-buffer-substring buf)
10177
10178       (if (and (not read-only)
10179                (not (gnus-request-replace-article
10180                      (cdr gnus-article-current) (car gnus-article-current)
10181                      (current-buffer) t)))
10182           (error "Couldn't replace article")
10183         ;; Update the summary buffer.
10184         (if (and references
10185                  (equal (message-tokenize-header references " ")
10186                         (message-tokenize-header
10187                          (or (message-fetch-field "references") "") " ")))
10188             ;; We only have to update this line.
10189             (save-excursion
10190               (save-restriction
10191                 (message-narrow-to-head)
10192                 (let ((head (buffer-substring-no-properties
10193                              (point-min) (point-max)))
10194                       header)
10195                   (with-temp-buffer
10196                     (insert (format "211 %d Article retrieved.\n"
10197                                     (cdr gnus-article-current)))
10198                     (insert head)
10199                     (insert ".\n")
10200                     (let ((nntp-server-buffer (current-buffer)))
10201                       (setq header (car (gnus-get-newsgroup-headers
10202                                          nil t))))
10203                     (save-excursion
10204                       (set-buffer gnus-summary-buffer)
10205                       (gnus-data-set-header
10206                        (gnus-data-find (cdr gnus-article-current))
10207                        header)
10208                       (gnus-summary-update-article-line
10209                        (cdr gnus-article-current) header)
10210                       (if (gnus-summary-goto-subject
10211                            (cdr gnus-article-current) nil t)
10212                           (gnus-summary-update-secondary-mark
10213                            (cdr gnus-article-current))))))))
10214           ;; Update threads.
10215           (set-buffer (or buffer gnus-summary-buffer))
10216           (gnus-summary-update-article (cdr gnus-article-current))
10217           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10218               (gnus-summary-update-secondary-mark
10219                (cdr gnus-article-current))))
10220         ;; Prettify the article buffer again.
10221         (unless no-highlight
10222           (save-excursion
10223             (set-buffer gnus-article-buffer)
10224             ;;;!!! Fix this -- article should be rehighlighted.
10225             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10226             (set-buffer gnus-original-article-buffer)
10227             (gnus-request-article
10228              (cdr gnus-article-current)
10229              (car gnus-article-current) (current-buffer))))
10230         ;; Prettify the summary buffer line.
10231         (when (gnus-visual-p 'summary-highlight 'highlight)
10232           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10233
10234 (defun gnus-summary-edit-wash (key)
10235   "Perform editing command KEY in the article buffer."
10236   (interactive
10237    (list
10238     (progn
10239       (message "%s" (concat (this-command-keys) "- "))
10240       (read-char))))
10241   (message "")
10242   (gnus-summary-edit-article)
10243   (execute-kbd-macro (concat (this-command-keys) key))
10244   (gnus-article-edit-done))
10245
10246 ;;; Respooling
10247
10248 (defun gnus-summary-respool-query (&optional silent trace)
10249   "Query where the respool algorithm would put this article."
10250   (interactive)
10251   (let (gnus-mark-article-hook)
10252     (gnus-summary-select-article)
10253     (save-excursion
10254       (set-buffer gnus-original-article-buffer)
10255       (let ((groups (nnmail-article-group 'identity trace)))
10256         (unless silent
10257           (if groups
10258               (message "This message would go to %s"
10259                        (mapconcat 'car groups ", "))
10260             (message "This message would go to no groups"))
10261           groups)))))
10262
10263 (defun gnus-summary-respool-trace ()
10264   "Trace where the respool algorithm would put this article.
10265 Display a buffer showing all fancy splitting patterns which matched."
10266   (interactive)
10267   (gnus-summary-respool-query nil t))
10268
10269 ;; Summary marking commands.
10270
10271 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10272   "Mark articles which has the same subject as read, and then select the next.
10273 If UNMARK is positive, remove any kind of mark.
10274 If UNMARK is negative, tick articles."
10275   (interactive "P")
10276   (when unmark
10277     (setq unmark (prefix-numeric-value unmark)))
10278   (let ((count
10279          (gnus-summary-mark-same-subject
10280           (gnus-summary-article-subject) unmark)))
10281     ;; Select next unread article.  If auto-select-same mode, should
10282     ;; select the first unread article.
10283     (gnus-summary-next-article t (and gnus-auto-select-same
10284                                       (gnus-summary-article-subject)))
10285     (gnus-message 7 "%d article%s marked as %s"
10286                   count (if (= count 1) " is" "s are")
10287                   (if unmark "unread" "read"))))
10288
10289 (defun gnus-summary-kill-same-subject (&optional unmark)
10290   "Mark articles which has the same subject as read.
10291 If UNMARK is positive, remove any kind of mark.
10292 If UNMARK is negative, tick articles."
10293   (interactive "P")
10294   (when unmark
10295     (setq unmark (prefix-numeric-value unmark)))
10296   (let ((count
10297          (gnus-summary-mark-same-subject
10298           (gnus-summary-article-subject) unmark)))
10299     ;; If marked as read, go to next unread subject.
10300     (when (null unmark)
10301       ;; Go to next unread subject.
10302       (gnus-summary-next-subject 1 t))
10303     (gnus-message 7 "%d articles are marked as %s"
10304                   count (if unmark "unread" "read"))))
10305
10306 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10307   "Mark articles with same SUBJECT as read, and return marked number.
10308 If optional argument UNMARK is positive, remove any kinds of marks.
10309 If optional argument UNMARK is negative, mark articles as unread instead."
10310   (let ((count 1))
10311     (save-excursion
10312       (cond
10313        ((null unmark)                   ; Mark as read.
10314         (while (and
10315                 (progn
10316                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10317                   (gnus-summary-show-thread) t)
10318                 (gnus-summary-find-subject subject))
10319           (setq count (1+ count))))
10320        ((> unmark 0)                    ; Tick.
10321         (while (and
10322                 (progn
10323                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10324                   (gnus-summary-show-thread) t)
10325                 (gnus-summary-find-subject subject))
10326           (setq count (1+ count))))
10327        (t                               ; Mark as unread.
10328         (while (and
10329                 (progn
10330                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10331                   (gnus-summary-show-thread) t)
10332                 (gnus-summary-find-subject subject))
10333           (setq count (1+ count)))))
10334       (gnus-set-mode-line 'summary)
10335       ;; Return the number of marked articles.
10336       count)))
10337
10338 (defun gnus-summary-mark-as-processable (n &optional unmark)
10339   "Set the process mark on the next N articles.
10340 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10341 the process mark instead.  The difference between N and the actual
10342 number of articles marked is returned."
10343   (interactive "P")
10344   (if (and (null n) (gnus-region-active-p))
10345       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10346     (setq n (prefix-numeric-value n))
10347     (let ((backward (< n 0))
10348           (n (abs n)))
10349       (while (and
10350               (> n 0)
10351               (if unmark
10352                   (gnus-summary-remove-process-mark
10353                    (gnus-summary-article-number))
10354                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10355               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10356         (setq n (1- n)))
10357       (when (/= 0 n)
10358         (gnus-message 7 "No more articles"))
10359       (gnus-summary-recenter)
10360       (gnus-summary-position-point)
10361       n)))
10362
10363 (defun gnus-summary-unmark-as-processable (n)
10364   "Remove the process mark from the next N articles.
10365 If N is negative, unmark backward instead.  The difference between N and
10366 the actual number of articles unmarked is returned."
10367   (interactive "P")
10368   (gnus-summary-mark-as-processable n t))
10369
10370 (defun gnus-summary-unmark-all-processable ()
10371   "Remove the process mark from all articles."
10372   (interactive)
10373   (save-excursion
10374     (while gnus-newsgroup-processable
10375       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10376   (gnus-summary-position-point))
10377
10378 (defun gnus-summary-add-mark (article type)
10379   "Mark ARTICLE with a mark of TYPE."
10380   (let ((vtype (car (assq type gnus-article-mark-lists)))
10381         var)
10382     (if (not vtype)
10383         (error "No such mark type: %s" type)
10384       (setq var (intern (format "gnus-newsgroup-%s" type)))
10385       (set var (cons article (symbol-value var)))
10386       (if (memq type '(processable cached replied forwarded recent saved))
10387           (gnus-summary-update-secondary-mark article)
10388         ;;; !!! This is bogus.  We should find out what primary
10389         ;;; !!! mark we want to set.
10390         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10391
10392 (defun gnus-summary-mark-as-expirable (n)
10393   "Mark N articles forward as expirable.
10394 If N is negative, mark backward instead.  The difference between N and
10395 the actual number of articles marked is returned."
10396   (interactive "p")
10397   (gnus-summary-mark-forward n gnus-expirable-mark))
10398
10399 (defun gnus-summary-mark-as-spam (n)
10400   "Mark N articles forward as spam.
10401 If N is negative, mark backward instead.  The difference between N and
10402 the actual number of articles marked is returned."
10403   (interactive "p")
10404   (gnus-summary-mark-forward n gnus-spam-mark))
10405
10406 (defun gnus-summary-mark-article-as-replied (article)
10407   "Mark ARTICLE as replied to and update the summary line.
10408 ARTICLE can also be a list of articles."
10409   (interactive (list (gnus-summary-article-number)))
10410   (let ((articles (if (listp article) article (list article))))
10411     (dolist (article articles)
10412       (unless (numberp article)
10413         (error "%s is not a number" article))
10414       (push article gnus-newsgroup-replied)
10415       (let ((buffer-read-only nil))
10416         (when (gnus-summary-goto-subject article nil t)
10417           (gnus-summary-update-secondary-mark article))))))
10418
10419 (defun gnus-summary-mark-article-as-forwarded (article)
10420   "Mark ARTICLE as forwarded and update the summary line.
10421 ARTICLE can also be a list of articles."
10422   (let ((articles (if (listp article) article (list article))))
10423     (dolist (article articles)
10424       (push article gnus-newsgroup-forwarded)
10425       (let ((buffer-read-only nil))
10426         (when (gnus-summary-goto-subject article nil t)
10427           (gnus-summary-update-secondary-mark article))))))
10428
10429 (defun gnus-summary-set-bookmark (article)
10430   "Set a bookmark in current article."
10431   (interactive (list (gnus-summary-article-number)))
10432   (when (or (not (get-buffer gnus-article-buffer))
10433             (not gnus-current-article)
10434             (not gnus-article-current)
10435             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10436     (error "No current article selected"))
10437   ;; Remove old bookmark, if one exists.
10438   (gnus-pull article gnus-newsgroup-bookmarks)
10439   ;; Set the new bookmark, which is on the form
10440   ;; (article-number . line-number-in-body).
10441   (push
10442    (cons article
10443          (with-current-buffer gnus-article-buffer
10444            (count-lines
10445             (min (point)
10446                  (save-excursion
10447                    (article-goto-body)
10448                    (point)))
10449             (point))))
10450    gnus-newsgroup-bookmarks)
10451   (gnus-message 6 "A bookmark has been added to the current article."))
10452
10453 (defun gnus-summary-remove-bookmark (article)
10454   "Remove the bookmark from the current article."
10455   (interactive (list (gnus-summary-article-number)))
10456   ;; Remove old bookmark, if one exists.
10457   (if (not (assq article gnus-newsgroup-bookmarks))
10458       (gnus-message 6 "No bookmark in current article.")
10459     (gnus-pull article gnus-newsgroup-bookmarks)
10460     (gnus-message 6 "Removed bookmark.")))
10461
10462 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10463 (defun gnus-summary-mark-as-dormant (n)
10464   "Mark N articles forward as dormant.
10465 If N is negative, mark backward instead.  The difference between N and
10466 the actual number of articles marked is returned."
10467   (interactive "p")
10468   (gnus-summary-mark-forward n gnus-dormant-mark))
10469
10470 (defun gnus-summary-set-process-mark (article)
10471   "Set the process mark on ARTICLE and update the summary line."
10472   (setq gnus-newsgroup-processable
10473         (cons article
10474               (delq article gnus-newsgroup-processable)))
10475   (when (gnus-summary-goto-subject article)
10476     (gnus-summary-show-thread)
10477     (gnus-summary-goto-subject article)
10478     (gnus-summary-update-secondary-mark article)))
10479
10480 (defun gnus-summary-remove-process-mark (&rest articles)
10481   "Remove the process mark from ARTICLES and update the summary line."
10482   (dolist (article articles)
10483     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10484     (when (gnus-summary-goto-subject article)
10485       (gnus-summary-show-thread)
10486       (gnus-summary-goto-subject article)
10487       (gnus-summary-update-secondary-mark article)))
10488   t)
10489
10490 (defun gnus-summary-set-saved-mark (article)
10491   "Set the process mark on ARTICLE and update the summary line."
10492   (push article gnus-newsgroup-saved)
10493   (when (gnus-summary-goto-subject article)
10494     (gnus-summary-update-secondary-mark article)))
10495
10496 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10497   "Mark N articles as read forwards.
10498 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10499 The difference between N and the actual number of articles marked is
10500 returned.
10501 If NO-EXPIRE, auto-expiry will be inhibited."
10502   (interactive "p")
10503   (gnus-summary-show-thread)
10504   (let ((backward (< n 0))
10505         (gnus-summary-goto-unread
10506          (and gnus-summary-goto-unread
10507               (not (eq gnus-summary-goto-unread 'never))
10508               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10509                                     gnus-ticked-mark gnus-dormant-mark)))))
10510         (n (abs n))
10511         (mark (or mark gnus-del-mark)))
10512     (while (and (> n 0)
10513                 (gnus-summary-mark-article nil mark no-expire)
10514                 (zerop (gnus-summary-next-subject
10515                         (if backward -1 1)
10516                         (and gnus-summary-goto-unread
10517                              (not (eq gnus-summary-goto-unread 'never)))
10518                         t)))
10519       (setq n (1- n)))
10520     (when (/= 0 n)
10521       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10522     (gnus-summary-recenter)
10523     (gnus-summary-position-point)
10524     (gnus-set-mode-line 'summary)
10525     n))
10526
10527 (defun gnus-summary-mark-article-as-read (mark)
10528   "Mark the current article quickly as read with MARK."
10529   (let ((article (gnus-summary-article-number)))
10530     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10531     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10532     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10533     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10534     (push (cons article mark) gnus-newsgroup-reads)
10535     ;; Possibly remove from cache, if that is used.
10536     (when gnus-use-cache
10537       (gnus-cache-enter-remove-article article))
10538     ;; Allow the backend to change the mark.
10539     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10540     ;; Check for auto-expiry.
10541     (when (and gnus-newsgroup-auto-expire
10542                (memq mark gnus-auto-expirable-marks))
10543       (setq mark gnus-expirable-mark)
10544       ;; Let the backend know about the mark change.
10545       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10546       (push article gnus-newsgroup-expirable))
10547     ;; Set the mark in the buffer.
10548     (gnus-summary-update-mark mark 'unread)
10549     t))
10550
10551 (defun gnus-summary-mark-article-as-unread (mark)
10552   "Mark the current article quickly as unread with MARK."
10553   (let* ((article (gnus-summary-article-number))
10554          (old-mark (gnus-summary-article-mark article)))
10555     ;; Allow the backend to change the mark.
10556     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10557     (if (eq mark old-mark)
10558         t
10559       (if (<= article 0)
10560           (progn
10561             (gnus-error 1 "Can't mark negative article numbers")
10562             nil)
10563         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10564         (setq gnus-newsgroup-spam-marked
10565               (delq article gnus-newsgroup-spam-marked))
10566         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10567         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10568         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10569         (cond ((= mark gnus-ticked-mark)
10570                (setq gnus-newsgroup-marked
10571                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10572                                               article)))
10573               ((= mark gnus-spam-mark)
10574                (setq gnus-newsgroup-spam-marked
10575                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10576                                               article)))
10577               ((= mark gnus-dormant-mark)
10578                (setq gnus-newsgroup-dormant
10579                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10580                                               article)))
10581               (t
10582                (setq gnus-newsgroup-unreads
10583                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10584                                               article))))
10585         (gnus-pull article gnus-newsgroup-reads)
10586
10587         ;; See whether the article is to be put in the cache.
10588         (and gnus-use-cache
10589              (vectorp (gnus-summary-article-header article))
10590              (save-excursion
10591                (gnus-cache-possibly-enter-article
10592                 gnus-newsgroup-name article
10593                 (= mark gnus-ticked-mark)
10594                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10595
10596         ;; Fix the mark.
10597         (gnus-summary-update-mark mark 'unread)
10598         t))))
10599
10600 (defun gnus-summary-mark-article (&optional article mark no-expire)
10601   "Mark ARTICLE with MARK.  MARK can be any character.
10602 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10603 `??' (dormant) and `?E' (expirable).
10604 If MARK is nil, then the default character `?r' is used.
10605 If ARTICLE is nil, then the article on the current line will be
10606 marked.
10607 If NO-EXPIRE, auto-expiry will be inhibited."
10608   ;; The mark might be a string.
10609   (when (stringp mark)
10610     (setq mark (aref mark 0)))
10611   ;; If no mark is given, then we check auto-expiring.
10612   (when (null mark)
10613     (setq mark gnus-del-mark))
10614   (when (and (not no-expire)
10615              gnus-newsgroup-auto-expire
10616              (memq mark gnus-auto-expirable-marks))
10617     (setq mark gnus-expirable-mark))
10618   (let ((article (or article (gnus-summary-article-number)))
10619         (old-mark (gnus-summary-article-mark article)))
10620     ;; Allow the backend to change the mark.
10621     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10622     (if (eq mark old-mark)
10623         t
10624       (unless article
10625         (error "No article on current line"))
10626       (if (not (if (or (= mark gnus-unread-mark)
10627                        (= mark gnus-ticked-mark)
10628                        (= mark gnus-spam-mark)
10629                        (= mark gnus-dormant-mark))
10630                    (gnus-mark-article-as-unread article mark)
10631                  (gnus-mark-article-as-read article mark)))
10632           t
10633         ;; See whether the article is to be put in the cache.
10634         (and gnus-use-cache
10635              (not (= mark gnus-canceled-mark))
10636              (vectorp (gnus-summary-article-header article))
10637              (save-excursion
10638                (gnus-cache-possibly-enter-article
10639                 gnus-newsgroup-name article
10640                 (= mark gnus-ticked-mark)
10641                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10642
10643         (when (gnus-summary-goto-subject article nil t)
10644           (let ((buffer-read-only nil))
10645             (gnus-summary-show-thread)
10646             ;; Fix the mark.
10647             (gnus-summary-update-mark mark 'unread)
10648             t))))))
10649
10650 (defun gnus-summary-update-secondary-mark (article)
10651   "Update the secondary (read, process, cache) mark."
10652   (gnus-summary-update-mark
10653    (cond ((memq article gnus-newsgroup-processable)
10654           gnus-process-mark)
10655          ((memq article gnus-newsgroup-cached)
10656           gnus-cached-mark)
10657          ((memq article gnus-newsgroup-replied)
10658           gnus-replied-mark)
10659          ((memq article gnus-newsgroup-forwarded)
10660           gnus-forwarded-mark)
10661          ((memq article gnus-newsgroup-saved)
10662           gnus-saved-mark)
10663          ((memq article gnus-newsgroup-recent)
10664           gnus-recent-mark)
10665          ((memq article gnus-newsgroup-unseen)
10666           gnus-unseen-mark)
10667          (t gnus-no-mark))
10668    'replied)
10669   (when (gnus-visual-p 'summary-highlight 'highlight)
10670     (gnus-run-hooks 'gnus-summary-update-hook))
10671   t)
10672
10673 (defun gnus-summary-update-download-mark (article)
10674   "Update the download mark."
10675   (gnus-summary-update-mark
10676    (cond ((memq article gnus-newsgroup-undownloaded)
10677           gnus-undownloaded-mark)
10678          (gnus-newsgroup-agentized
10679           gnus-downloaded-mark)
10680          (t
10681           gnus-no-mark))
10682    'download)
10683   (gnus-summary-update-line t)
10684   t)
10685
10686 (defun gnus-summary-update-mark (mark type)
10687   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10688         (buffer-read-only nil))
10689     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10690     (when forward
10691       (when (looking-at "\r")
10692         (incf forward))
10693       (when (<= (+ forward (point)) (point-max))
10694         ;; Go to the right position on the line.
10695         (goto-char (+ forward (point)))
10696         ;; Replace the old mark with the new mark.
10697         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10698         ;; Optionally update the marks by some user rule.
10699         (when (eq type 'unread)
10700           (gnus-data-set-mark
10701            (gnus-data-find (gnus-summary-article-number)) mark)
10702           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10703
10704 (defun gnus-mark-article-as-read (article &optional mark)
10705   "Enter ARTICLE in the pertinent lists and remove it from others."
10706   ;; Make the article expirable.
10707   (let ((mark (or mark gnus-del-mark)))
10708     (setq gnus-newsgroup-expirable
10709           (if (= mark gnus-expirable-mark)
10710               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10711             (delq article gnus-newsgroup-expirable)))
10712     ;; Remove from unread and marked lists.
10713     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10714     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10715     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10716     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10717     (push (cons article mark) gnus-newsgroup-reads)
10718     ;; Possibly remove from cache, if that is used.
10719     (when gnus-use-cache
10720       (gnus-cache-enter-remove-article article))
10721     t))
10722
10723 (defun gnus-mark-article-as-unread (article &optional mark)
10724   "Enter ARTICLE in the pertinent lists and remove it from others."
10725   (let ((mark (or mark gnus-ticked-mark)))
10726     (if (<= article 0)
10727         (progn
10728           (gnus-error 1 "Can't mark negative article numbers")
10729           nil)
10730       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10731             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10732             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10733             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10734             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10735
10736       ;; Unsuppress duplicates?
10737       (when gnus-suppress-duplicates
10738         (gnus-dup-unsuppress-article article))
10739
10740       (cond ((= mark gnus-ticked-mark)
10741              (setq gnus-newsgroup-marked
10742                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10743             ((= mark gnus-spam-mark)
10744              (setq gnus-newsgroup-spam-marked
10745                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10746                                             article)))
10747             ((= mark gnus-dormant-mark)
10748              (setq gnus-newsgroup-dormant
10749                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10750             (t
10751              (setq gnus-newsgroup-unreads
10752                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10753       (gnus-pull article gnus-newsgroup-reads)
10754       t)))
10755
10756 (defalias 'gnus-summary-mark-as-unread-forward
10757   'gnus-summary-tick-article-forward)
10758 (make-obsolete 'gnus-summary-mark-as-unread-forward
10759                'gnus-summary-tick-article-forward)
10760 (defun gnus-summary-tick-article-forward (n)
10761   "Tick N articles forwards.
10762 If N is negative, tick backwards instead.
10763 The difference between N and the number of articles ticked is returned."
10764   (interactive "p")
10765   (gnus-summary-mark-forward n gnus-ticked-mark))
10766
10767 (defalias 'gnus-summary-mark-as-unread-backward
10768   'gnus-summary-tick-article-backward)
10769 (make-obsolete 'gnus-summary-mark-as-unread-backward
10770                'gnus-summary-tick-article-backward)
10771 (defun gnus-summary-tick-article-backward (n)
10772   "Tick N articles backwards.
10773 The difference between N and the number of articles ticked is returned."
10774   (interactive "p")
10775   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10776
10777 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10778 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10779 (defun gnus-summary-tick-article (&optional article clear-mark)
10780   "Mark current article as unread.
10781 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10782 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10783   (interactive)
10784   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10785                                        gnus-ticked-mark)))
10786
10787 (defun gnus-summary-mark-as-read-forward (n)
10788   "Mark N articles as read forwards.
10789 If N is negative, mark backwards instead.
10790 The difference between N and the actual number of articles marked is
10791 returned."
10792   (interactive "p")
10793   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10794
10795 (defun gnus-summary-mark-as-read-backward (n)
10796   "Mark the N articles as read backwards.
10797 The difference between N and the actual number of articles marked is
10798 returned."
10799   (interactive "p")
10800   (gnus-summary-mark-forward
10801    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10802
10803 (defun gnus-summary-mark-as-read (&optional article mark)
10804   "Mark current article as read.
10805 ARTICLE specifies the article to be marked as read.
10806 MARK specifies a string to be inserted at the beginning of the line."
10807   (gnus-summary-mark-article article mark))
10808
10809 (defun gnus-summary-clear-mark-forward (n)
10810   "Clear marks from N articles forward.
10811 If N is negative, clear backward instead.
10812 The difference between N and the number of marks cleared is returned."
10813   (interactive "p")
10814   (gnus-summary-mark-forward n gnus-unread-mark))
10815
10816 (defun gnus-summary-clear-mark-backward (n)
10817   "Clear marks from N articles backward.
10818 The difference between N and the number of marks cleared is returned."
10819   (interactive "p")
10820   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10821
10822 (defun gnus-summary-mark-unread-as-read ()
10823   "Intended to be used by `gnus-summary-mark-article-hook'."
10824   (when (memq gnus-current-article gnus-newsgroup-unreads)
10825     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10826
10827 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10828   "Intended to be used by `gnus-summary-mark-article-hook'."
10829   (let ((mark (gnus-summary-article-mark)))
10830     (when (or (gnus-unread-mark-p mark)
10831               (gnus-read-mark-p mark))
10832       (gnus-summary-mark-article gnus-current-article
10833                                  (or new-mark gnus-read-mark)))))
10834
10835 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10836   "Intended to be used by `gnus-summary-mark-article-hook'."
10837   (let ((mark (gnus-summary-article-mark)))
10838     (when (or (gnus-unread-mark-p mark)
10839               (gnus-read-mark-p mark))
10840       (gnus-summary-mark-article (gnus-summary-article-number)
10841                                  (or new-mark gnus-read-mark)))))
10842
10843 (defun gnus-summary-mark-unread-as-ticked ()
10844   "Intended to be used by `gnus-summary-mark-article-hook'."
10845   (when (memq gnus-current-article gnus-newsgroup-unreads)
10846     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10847
10848 (defun gnus-summary-mark-region-as-read (point mark all)
10849   "Mark all unread articles between point and mark as read.
10850 If given a prefix, mark all articles between point and mark as read,
10851 even ticked and dormant ones."
10852   (interactive "r\nP")
10853   (save-excursion
10854     (let (article)
10855       (goto-char point)
10856       (beginning-of-line)
10857       (while (and
10858               (< (point) mark)
10859               (progn
10860                 (when (or all
10861                           (memq (setq article (gnus-summary-article-number))
10862                                 gnus-newsgroup-unreads))
10863                   (gnus-summary-mark-article article gnus-del-mark))
10864                 t)
10865               (gnus-summary-find-next))))))
10866
10867 (defun gnus-summary-mark-below (score mark)
10868   "Mark articles with score less than SCORE with MARK."
10869   (interactive "P\ncMark: ")
10870   (setq score (if score
10871                   (prefix-numeric-value score)
10872                 (or gnus-summary-default-score 0)))
10873   (save-excursion
10874     (set-buffer gnus-summary-buffer)
10875     (goto-char (point-min))
10876     (while
10877         (progn
10878           (and (< (gnus-summary-article-score) score)
10879                (gnus-summary-mark-article nil mark))
10880           (gnus-summary-find-next)))))
10881
10882 (defun gnus-summary-kill-below (&optional score)
10883   "Mark articles with score below SCORE as read."
10884   (interactive "P")
10885   (gnus-summary-mark-below score gnus-killed-mark))
10886
10887 (defun gnus-summary-clear-above (&optional score)
10888   "Clear all marks from articles with score above SCORE."
10889   (interactive "P")
10890   (gnus-summary-mark-above score gnus-unread-mark))
10891
10892 (defun gnus-summary-tick-above (&optional score)
10893   "Tick all articles with score above SCORE."
10894   (interactive "P")
10895   (gnus-summary-mark-above score gnus-ticked-mark))
10896
10897 (defun gnus-summary-mark-above (score mark)
10898   "Mark articles with score over SCORE with MARK."
10899   (interactive "P\ncMark: ")
10900   (setq score (if score
10901                   (prefix-numeric-value score)
10902                 (or gnus-summary-default-score 0)))
10903   (save-excursion
10904     (set-buffer gnus-summary-buffer)
10905     (goto-char (point-min))
10906     (while (and (progn
10907                   (when (> (gnus-summary-article-score) score)
10908                     (gnus-summary-mark-article nil mark))
10909                   t)
10910                 (gnus-summary-find-next)))))
10911
10912 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10913 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10914 (defun gnus-summary-limit-include-expunged (&optional no-error)
10915   "Display all the hidden articles that were expunged for low scores."
10916   (interactive)
10917   (let ((buffer-read-only nil))
10918     (let ((scored gnus-newsgroup-scored)
10919           headers h)
10920       (while scored
10921         (unless (gnus-summary-article-header (caar scored))
10922           (and (setq h (gnus-number-to-header (caar scored)))
10923                (< (cdar scored) gnus-summary-expunge-below)
10924                (push h headers)))
10925         (setq scored (cdr scored)))
10926       (if (not headers)
10927           (when (not no-error)
10928             (error "No expunged articles hidden"))
10929         (goto-char (point-min))
10930         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10931         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10932         (mapcar (lambda (x) (push (mail-header-number x)
10933                                   gnus-newsgroup-limit))
10934                 headers)
10935         (gnus-summary-prepare-unthreaded (nreverse headers))
10936         (goto-char (point-min))
10937         (gnus-summary-position-point)
10938         t))))
10939
10940 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10941   "Mark all unread articles in this newsgroup as read.
10942 If prefix argument ALL is non-nil, ticked and dormant articles will
10943 also be marked as read.
10944 If QUIETLY is non-nil, no questions will be asked.
10945
10946 If TO-HERE is non-nil, it should be a point in the buffer.  All
10947 articles before (after, if REVERSE is set) this point will be marked
10948 as read.
10949
10950 Note that this function will only catch up the unread article
10951 in the current summary buffer limitation.
10952
10953 The number of articles marked as read is returned."
10954   (interactive "P")
10955   (prog1
10956       (save-excursion
10957         (when (or quietly
10958                   (not gnus-interactive-catchup) ;Without confirmation?
10959                   gnus-expert-user
10960                   (gnus-y-or-n-p
10961                    (if all
10962                        "Mark absolutely all articles as read? "
10963                      "Mark all unread articles as read? ")))
10964           (if (and not-mark
10965                    (not gnus-newsgroup-adaptive)
10966                    (not gnus-newsgroup-auto-expire)
10967                    (not gnus-suppress-duplicates)
10968                    (or (not gnus-use-cache)
10969                        (eq gnus-use-cache 'passive)))
10970               (progn
10971                 (when all
10972                   (setq gnus-newsgroup-marked nil
10973                         gnus-newsgroup-spam-marked nil
10974                         gnus-newsgroup-dormant nil))
10975                 (setq gnus-newsgroup-unreads
10976                       (gnus-sorted-nunion
10977                        (gnus-sorted-intersection gnus-newsgroup-unreads
10978                                                  gnus-newsgroup-downloadable)
10979                        (gnus-sorted-difference gnus-newsgroup-unfetched
10980                                                gnus-newsgroup-cached))))
10981             ;; We actually mark all articles as canceled, which we
10982             ;; have to do when using auto-expiry or adaptive scoring.
10983             (gnus-summary-show-all-threads)
10984             (if (and to-here reverse)
10985                 (progn
10986                   (goto-char to-here)
10987                   (gnus-summary-mark-current-read-and-unread-as-read
10988                    gnus-catchup-mark)
10989                   (while (gnus-summary-find-next (not all))
10990                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10991               (when (gnus-summary-first-subject (not all))
10992                 (while (and
10993                         (if to-here (< (point) to-here) t)
10994                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10995                         (gnus-summary-find-next (not all))))))
10996             (gnus-set-mode-line 'summary))
10997           t))
10998     (gnus-summary-position-point)))
10999
11000 (defun gnus-summary-catchup-to-here (&optional all)
11001   "Mark all unticked articles before the current one as read.
11002 If ALL is non-nil, also mark ticked and dormant articles as read."
11003   (interactive "P")
11004   (save-excursion
11005     (gnus-save-hidden-threads
11006       (let ((beg (point)))
11007         ;; We check that there are unread articles.
11008         (when (or all (gnus-summary-find-prev))
11009           (gnus-summary-catchup all t beg)))))
11010   (gnus-summary-position-point))
11011
11012 (defun gnus-summary-catchup-from-here (&optional all)
11013   "Mark all unticked articles after (and including) the current one as read.
11014 If ALL is non-nil, also mark ticked and dormant articles as read."
11015   (interactive "P")
11016   (save-excursion
11017     (gnus-save-hidden-threads
11018       (let ((beg (point)))
11019         ;; We check that there are unread articles.
11020         (when (or all (gnus-summary-find-next))
11021           (gnus-summary-catchup all t beg nil t)))))
11022   (gnus-summary-position-point))
11023
11024 (defun gnus-summary-catchup-all (&optional quietly)
11025   "Mark all articles in this newsgroup as read.
11026 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11027 instead, which marks only unread articles as read."
11028   (interactive "P")
11029   (gnus-summary-catchup t quietly))
11030
11031 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11032   "Mark all unread articles in this group as read, then exit.
11033 If prefix argument ALL is non-nil, all articles are marked as read.
11034 If QUIETLY is non-nil, no questions will be asked."
11035   (interactive "P")
11036   (when (gnus-summary-catchup all quietly nil 'fast)
11037     ;; Select next newsgroup or exit.
11038     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11039              (eq gnus-auto-select-next 'quietly))
11040         (gnus-summary-next-group nil)
11041       (gnus-summary-exit))))
11042
11043 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11044   "Mark all articles in this newsgroup as read, and then exit.
11045 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11046 instead, which marks only unread articles as read."
11047   (interactive "P")
11048   (gnus-summary-catchup-and-exit t quietly))
11049
11050 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11051   "Mark all articles in this group as read and select the next group.
11052 If given a prefix, mark all articles, unread as well as ticked, as
11053 read."
11054   (interactive "P")
11055   (save-excursion
11056     (gnus-summary-catchup all))
11057   (gnus-summary-next-group))
11058
11059 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11060   "Mark all articles in this group as read and select the previous group.
11061 If given a prefix, mark all articles, unread as well as ticked, as
11062 read."
11063   (interactive "P")
11064   (save-excursion
11065     (gnus-summary-catchup all))
11066   (gnus-summary-next-group nil nil t))
11067
11068 ;;;
11069 ;;; with article
11070 ;;;
11071
11072 (defmacro gnus-with-article (article &rest forms)
11073   "Select ARTICLE and perform FORMS in the original article buffer.
11074 Then replace the article with the result."
11075   `(progn
11076      ;; We don't want the article to be marked as read.
11077      (let (gnus-mark-article-hook)
11078        (gnus-summary-select-article t t nil ,article))
11079      (set-buffer gnus-original-article-buffer)
11080      ,@forms
11081      (if (not (gnus-check-backend-function
11082                'request-replace-article (car gnus-article-current)))
11083          (gnus-message 5 "Read-only group; not replacing")
11084        (unless (gnus-request-replace-article
11085                 ,article (car gnus-article-current)
11086                 (current-buffer) t)
11087          (error "Couldn't replace article")))
11088      ;; The cache and backlog have to be flushed somewhat.
11089      (when gnus-keep-backlog
11090        (gnus-backlog-remove-article
11091         (car gnus-article-current) (cdr gnus-article-current)))
11092      (when gnus-use-cache
11093        (gnus-cache-update-article
11094         (car gnus-article-current) (cdr gnus-article-current)))))
11095
11096 (put 'gnus-with-article 'lisp-indent-function 1)
11097 (put 'gnus-with-article 'edebug-form-spec '(form body))
11098
11099 ;; Thread-based commands.
11100
11101 (defun gnus-summary-articles-in-thread (&optional article)
11102   "Return a list of all articles in the current thread.
11103 If ARTICLE is non-nil, return all articles in the thread that starts
11104 with that article."
11105   (let* ((article (or article (gnus-summary-article-number)))
11106          (data (gnus-data-find-list article))
11107          (top-level (gnus-data-level (car data)))
11108          (top-subject
11109           (cond ((null gnus-thread-operation-ignore-subject)
11110                  (gnus-simplify-subject-re
11111                   (mail-header-subject (gnus-data-header (car data)))))
11112                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11113                  (gnus-simplify-subject-fuzzy
11114                   (mail-header-subject (gnus-data-header (car data)))))
11115                 (t nil)))
11116          (end-point (save-excursion
11117                       (if (gnus-summary-go-to-next-thread)
11118                           (point) (point-max))))
11119          articles)
11120     (while (and data
11121                 (< (gnus-data-pos (car data)) end-point))
11122       (when (or (not top-subject)
11123                 (string= top-subject
11124                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11125                              (gnus-simplify-subject-fuzzy
11126                               (mail-header-subject
11127                                (gnus-data-header (car data))))
11128                            (gnus-simplify-subject-re
11129                             (mail-header-subject
11130                              (gnus-data-header (car data)))))))
11131         (push (gnus-data-number (car data)) articles))
11132       (unless (and (setq data (cdr data))
11133                    (> (gnus-data-level (car data)) top-level))
11134         (setq data nil)))
11135     ;; Return the list of articles.
11136     (nreverse articles)))
11137
11138 (defun gnus-summary-rethread-current ()
11139   "Rethread the thread the current article is part of."
11140   (interactive)
11141   (let* ((gnus-show-threads t)
11142          (article (gnus-summary-article-number))
11143          (id (mail-header-id (gnus-summary-article-header)))
11144          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11145     (unless id
11146       (error "No article on the current line"))
11147     (gnus-rebuild-thread id)
11148     (gnus-summary-goto-subject article)))
11149
11150 (defun gnus-summary-reparent-thread ()
11151   "Make the current article child of the marked (or previous) article.
11152
11153 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11154 is non-nil or the Subject: of both articles are the same."
11155   (interactive)
11156   (unless (not (gnus-group-read-only-p))
11157     (error "The current newsgroup does not support article editing"))
11158   (unless (<= (length gnus-newsgroup-processable) 1)
11159     (error "No more than one article may be marked"))
11160   (let ((child (gnus-summary-article-number))
11161         ;; First grab the marked article, otherwise one line up.
11162         (parent (if (not (null gnus-newsgroup-processable))
11163                     (car gnus-newsgroup-processable)
11164                   (save-excursion
11165                     (if (eq (forward-line -1) 0)
11166                         (gnus-summary-article-number)
11167                       (error "Beginning of summary buffer"))))))
11168     (gnus-summary-reparent-children parent (list child))))
11169
11170 (defun gnus-summary-reparent-children (parent children)
11171   "Make PARENT the parent of CHILDREN.
11172 When called interactively, PARENT is the current article and CHILDREN
11173 are the process-marked articles."
11174   (interactive
11175    (list (gnus-summary-article-number)
11176          (gnus-summary-work-articles nil)))
11177   (dolist (child children)
11178     (save-window-excursion
11179       (let ((gnus-article-buffer " *reparent*"))
11180         (unless (not (eq parent child))
11181           (error "An article may not be self-referential"))
11182         (let ((message-id (mail-header-id
11183                            (gnus-summary-article-header parent))))
11184           (unless (and message-id (not (equal message-id "")))
11185             (error "No message-id in desired parent"))
11186           (gnus-with-article child
11187             (save-restriction
11188               (goto-char (point-min))
11189               (message-narrow-to-head)
11190               (if (re-search-forward "^References: " nil t)
11191                   (progn
11192                     (re-search-forward "^[^ \t]" nil t)
11193                     (forward-line -1)
11194                     (end-of-line)
11195                     (insert " " message-id))
11196                 (insert "References: " message-id "\n"))))
11197           (set-buffer gnus-summary-buffer)
11198           (gnus-summary-unmark-all-processable)
11199           (gnus-summary-update-article child)
11200           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11201             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11202           (gnus-summary-rethread-current)
11203           (gnus-message 3 "Article %d is now the child of article %d"
11204                         child parent))))))
11205
11206 (defun gnus-summary-toggle-threads (&optional arg)
11207   "Toggle showing conversation threads.
11208 If ARG is positive number, turn showing conversation threads on."
11209   (interactive "P")
11210   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11211     (setq gnus-show-threads
11212           (if (null arg) (not gnus-show-threads)
11213             (> (prefix-numeric-value arg) 0)))
11214     (gnus-summary-prepare)
11215     (gnus-summary-goto-subject current)
11216     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11217     (gnus-summary-position-point)))
11218
11219 (defun gnus-summary-show-all-threads ()
11220   "Show all threads."
11221   (interactive)
11222   (save-excursion
11223     (let ((buffer-read-only nil))
11224       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11225   (gnus-summary-position-point))
11226
11227 (defun gnus-summary-show-thread ()
11228   "Show thread subtrees.
11229 Returns nil if no thread was there to be shown."
11230   (interactive)
11231   (let ((buffer-read-only nil)
11232         (orig (point))
11233         (end (point-at-eol))
11234         ;; Leave point at bol
11235         (beg (progn (beginning-of-line) (point))))
11236     (prog1
11237         ;; Any hidden lines here?
11238         (search-forward "\r" end t)
11239       (subst-char-in-region beg end ?\^M ?\n t)
11240       (goto-char orig)
11241       (gnus-summary-position-point))))
11242
11243 (defun gnus-summary-maybe-hide-threads ()
11244   "If requested, hide the threads that should be hidden."
11245   (when (and gnus-show-threads
11246              gnus-thread-hide-subtree)
11247     (gnus-summary-hide-all-threads
11248      (if (or (consp gnus-thread-hide-subtree)
11249              (functionp gnus-thread-hide-subtree))
11250          (gnus-make-predicate gnus-thread-hide-subtree)
11251        nil))))
11252
11253 ;;; Hiding predicates.
11254
11255 (defun gnus-article-unread-p (header)
11256   (memq (mail-header-number header) gnus-newsgroup-unreads))
11257
11258 (defun gnus-article-unseen-p (header)
11259   (memq (mail-header-number header) gnus-newsgroup-unseen))
11260
11261 (defun gnus-map-articles (predicate articles)
11262   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11263   (apply 'gnus-or (mapcar predicate
11264                           (mapcar (lambda (number)
11265                                     (gnus-summary-article-header number))
11266                                   articles))))
11267
11268 (defun gnus-summary-hide-all-threads (&optional predicate)
11269   "Hide all thread subtrees.
11270 If PREDICATE is supplied, threads that satisfy this predicate
11271 will not be hidden."
11272   (interactive)
11273   (save-excursion
11274     (goto-char (point-min))
11275     (let ((end nil))
11276       (while (not end)
11277         (when (or (not predicate)
11278                   (gnus-map-articles
11279                    predicate (gnus-summary-article-children)))
11280             (gnus-summary-hide-thread))
11281         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11282   (gnus-summary-position-point))
11283
11284 (defun gnus-summary-hide-thread ()
11285   "Hide thread subtrees.
11286 If PREDICATE is supplied, threads that satisfy this predicate
11287 will not be hidden.
11288 Returns nil if no threads were there to be hidden."
11289   (interactive)
11290   (let ((buffer-read-only nil)
11291         (start (point))
11292         (article (gnus-summary-article-number)))
11293     (goto-char start)
11294     ;; Go forward until either the buffer ends or the subthread
11295     ;; ends.
11296     (when (and (not (eobp))
11297                (or (zerop (gnus-summary-next-thread 1 t))
11298                    (goto-char (point-max))))
11299       (prog1
11300           (if (and (> (point) start)
11301                    (search-backward "\n" start t))
11302               (progn
11303                 (subst-char-in-region start (point) ?\n ?\^M)
11304                 (gnus-summary-goto-subject article))
11305             (goto-char start)
11306             nil)))))
11307
11308 (defun gnus-summary-go-to-next-thread (&optional previous)
11309   "Go to the same level (or less) next thread.
11310 If PREVIOUS is non-nil, go to previous thread instead.
11311 Return the article number moved to, or nil if moving was impossible."
11312   (let ((level (gnus-summary-thread-level))
11313         (way (if previous -1 1))
11314         (beg (point)))
11315     (forward-line way)
11316     (while (and (not (eobp))
11317                 (< level (gnus-summary-thread-level)))
11318       (forward-line way))
11319     (if (eobp)
11320         (progn
11321           (goto-char beg)
11322           nil)
11323       (setq beg (point))
11324       (prog1
11325           (gnus-summary-article-number)
11326         (goto-char beg)))))
11327
11328 (defun gnus-summary-next-thread (n &optional silent)
11329   "Go to the same level next N'th thread.
11330 If N is negative, search backward instead.
11331 Returns the difference between N and the number of skips actually
11332 done.
11333
11334 If SILENT, don't output messages."
11335   (interactive "p")
11336   (let ((backward (< n 0))
11337         (n (abs n)))
11338     (while (and (> n 0)
11339                 (gnus-summary-go-to-next-thread backward))
11340       (decf n))
11341     (unless silent
11342       (gnus-summary-position-point))
11343     (when (and (not silent) (/= 0 n))
11344       (gnus-message 7 "No more threads"))
11345     n))
11346
11347 (defun gnus-summary-prev-thread (n)
11348   "Go to the same level previous N'th thread.
11349 Returns the difference between N and the number of skips actually
11350 done."
11351   (interactive "p")
11352   (gnus-summary-next-thread (- n)))
11353
11354 (defun gnus-summary-go-down-thread ()
11355   "Go down one level in the current thread."
11356   (let ((children (gnus-summary-article-children)))
11357     (when children
11358       (gnus-summary-goto-subject (car children)))))
11359
11360 (defun gnus-summary-go-up-thread ()
11361   "Go up one level in the current thread."
11362   (let ((parent (gnus-summary-article-parent)))
11363     (when parent
11364       (gnus-summary-goto-subject parent))))
11365
11366 (defun gnus-summary-down-thread (n)
11367   "Go down thread N steps.
11368 If N is negative, go up instead.
11369 Returns the difference between N and how many steps down that were
11370 taken."
11371   (interactive "p")
11372   (let ((up (< n 0))
11373         (n (abs n)))
11374     (while (and (> n 0)
11375                 (if up (gnus-summary-go-up-thread)
11376                   (gnus-summary-go-down-thread)))
11377       (setq n (1- n)))
11378     (gnus-summary-position-point)
11379     (when (/= 0 n)
11380       (gnus-message 7 "Can't go further"))
11381     n))
11382
11383 (defun gnus-summary-up-thread (n)
11384   "Go up thread N steps.
11385 If N is negative, go down instead.
11386 Returns the difference between N and how many steps down that were
11387 taken."
11388   (interactive "p")
11389   (gnus-summary-down-thread (- n)))
11390
11391 (defun gnus-summary-top-thread ()
11392   "Go to the top of the thread."
11393   (interactive)
11394   (while (gnus-summary-go-up-thread))
11395   (gnus-summary-article-number))
11396
11397 (defun gnus-summary-kill-thread (&optional unmark)
11398   "Mark articles under current thread as read.
11399 If the prefix argument is positive, remove any kinds of marks.
11400 If the prefix argument is zero, mark thread as expired.
11401 If the prefix argument is negative, tick articles instead."
11402   (interactive "P")
11403   (when unmark
11404     (setq unmark (prefix-numeric-value unmark)))
11405   (let ((articles (gnus-summary-articles-in-thread))
11406         (hide (or (null unmark) (= unmark 0))))
11407     (save-excursion
11408       ;; Expand the thread.
11409       (gnus-summary-show-thread)
11410       ;; Mark all the articles.
11411       (while articles
11412         (gnus-summary-goto-subject (car articles))
11413         (cond ((null unmark)
11414                (gnus-summary-mark-article-as-read gnus-killed-mark))
11415               ((> unmark 0)
11416                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11417               ((= unmark 0)
11418                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11419               (t
11420                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11421         (setq articles (cdr articles))))
11422     ;; Hide killed subtrees when hide is true.
11423     (and hide
11424          gnus-thread-hide-killed
11425          (gnus-summary-hide-thread))
11426     ;; If hide is t, go to next unread subject.
11427     (when hide
11428       ;; Go to next unread subject.
11429       (gnus-summary-next-subject 1 t)))
11430   (gnus-set-mode-line 'summary))
11431
11432 ;; Summary sorting commands
11433
11434 (defun gnus-summary-sort-by-number (&optional reverse)
11435   "Sort the summary buffer by article number.
11436 Argument REVERSE means reverse order."
11437   (interactive "P")
11438   (gnus-summary-sort 'number reverse))
11439
11440 (defun gnus-summary-sort-by-random (&optional reverse)
11441   "Randomize the order in the summary buffer.
11442 Argument REVERSE means to randomize in reverse order."
11443   (interactive "P")
11444   (gnus-summary-sort 'random reverse))
11445
11446 (defun gnus-summary-sort-by-author (&optional reverse)
11447   "Sort the summary buffer by author name alphabetically.
11448 If `case-fold-search' is non-nil, case of letters is ignored.
11449 Argument REVERSE means reverse order."
11450   (interactive "P")
11451   (gnus-summary-sort 'author reverse))
11452
11453 (defun gnus-summary-sort-by-recipient (&optional reverse)
11454   "Sort the summary buffer by recipient name alphabetically.
11455 If `case-fold-search' is non-nil, case of letters is ignored.
11456 Argument REVERSE means reverse order."
11457   (interactive "P")
11458   (gnus-summary-sort 'recipient reverse))
11459
11460 (defun gnus-summary-sort-by-subject (&optional reverse)
11461   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11462 If `case-fold-search' is non-nil, case of letters is ignored.
11463 Argument REVERSE means reverse order."
11464   (interactive "P")
11465   (gnus-summary-sort 'subject reverse))
11466
11467 (defun gnus-summary-sort-by-date (&optional reverse)
11468   "Sort the summary buffer by date.
11469 Argument REVERSE means reverse order."
11470   (interactive "P")
11471   (gnus-summary-sort 'date reverse))
11472
11473 (defun gnus-summary-sort-by-score (&optional reverse)
11474   "Sort the summary buffer by score.
11475 Argument REVERSE means reverse order."
11476   (interactive "P")
11477   (gnus-summary-sort 'score reverse))
11478
11479 (defun gnus-summary-sort-by-lines (&optional reverse)
11480   "Sort the summary buffer by the number of lines.
11481 Argument REVERSE means reverse order."
11482   (interactive "P")
11483   (gnus-summary-sort 'lines reverse))
11484
11485 (defun gnus-summary-sort-by-chars (&optional reverse)
11486   "Sort the summary buffer by article length.
11487 Argument REVERSE means reverse order."
11488   (interactive "P")
11489   (gnus-summary-sort 'chars reverse))
11490
11491 (defun gnus-summary-sort-by-original (&optional reverse)
11492   "Sort the summary buffer using the default sorting method.
11493 Argument REVERSE means reverse order."
11494   (interactive "P")
11495   (let* ((buffer-read-only)
11496          (gnus-summary-prepare-hook nil))
11497     ;; We do the sorting by regenerating the threads.
11498     (gnus-summary-prepare)
11499     ;; Hide subthreads if needed.
11500     (gnus-summary-maybe-hide-threads)))
11501
11502 (defun gnus-summary-sort (predicate reverse)
11503   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11504   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11505          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11506          (gnus-thread-sort-functions
11507           (if (not reverse)
11508               thread
11509             `(lambda (t1 t2)
11510                (,thread t2 t1))))
11511          (gnus-sort-gathered-threads-function
11512           gnus-thread-sort-functions)
11513          (gnus-article-sort-functions
11514           (if (not reverse)
11515               article
11516             `(lambda (t1 t2)
11517                (,article t2 t1))))
11518          (buffer-read-only)
11519          (gnus-summary-prepare-hook nil))
11520     ;; We do the sorting by regenerating the threads.
11521     (gnus-summary-prepare)
11522     ;; Hide subthreads if needed.
11523     (gnus-summary-maybe-hide-threads)))
11524
11525 ;; Summary saving commands.
11526
11527 (defun gnus-summary-save-article (&optional n not-saved)
11528   "Save the current article using the default saver function.
11529 If N is a positive number, save the N next articles.
11530 If N is a negative number, save the N previous articles.
11531 If N is nil and any articles have been marked with the process mark,
11532 save those articles instead.
11533 The variable `gnus-default-article-saver' specifies the saver function.
11534
11535 If the optional second argument NOT-SAVED is non-nil, articles saved
11536 will not be marked as saved."
11537   (interactive "P")
11538   (require 'gnus-art)
11539   (let* ((articles (gnus-summary-work-articles n))
11540          (save-buffer (save-excursion
11541                         (nnheader-set-temp-buffer " *Gnus Save*")))
11542          (num (length articles))
11543          ;; Whether to save decoded articles or raw articles.
11544          (decode (when gnus-article-save-coding-system
11545                    (get gnus-default-article-saver :decode)))
11546          ;; When saving many articles in a single file, use the other
11547          ;; function to save articles other than the first one.
11548          (saver2 (get gnus-default-article-saver :function))
11549          (gnus-prompt-before-saving (if saver2
11550                                         t
11551                                       gnus-prompt-before-saving))
11552          (gnus-default-article-saver gnus-default-article-saver)
11553          header file)
11554     (dolist (article articles)
11555       (setq header (gnus-summary-article-header article))
11556       (if (not (vectorp header))
11557           ;; This is a pseudo-article.
11558           (if (assq 'name header)
11559               (gnus-copy-file (cdr (assq 'name header)))
11560             (gnus-message 1 "Article %d is unsaveable" article))
11561         ;; This is a real article.
11562         (save-window-excursion
11563           (let ((gnus-display-mime-function (when decode
11564                                               gnus-display-mime-function))
11565                 (gnus-article-prepare-hook (when decode
11566                                              gnus-article-prepare-hook)))
11567             (gnus-summary-select-article t nil nil article)
11568             (gnus-summary-goto-subject article)))
11569         (save-excursion
11570           (set-buffer save-buffer)
11571           (erase-buffer)
11572           (insert-buffer-substring (if decode
11573                                        gnus-article-buffer
11574                                      gnus-original-article-buffer)))
11575         (setq file (gnus-article-save save-buffer file num))
11576         (gnus-summary-remove-process-mark article)
11577         (unless not-saved
11578           (gnus-summary-set-saved-mark article)))
11579       (when saver2
11580         (setq gnus-default-article-saver saver2
11581               saver2 nil)))
11582     (gnus-kill-buffer save-buffer)
11583     (gnus-summary-position-point)
11584     (gnus-set-mode-line 'summary)
11585     n))
11586
11587 (defun gnus-summary-pipe-output (&optional arg headers)
11588   "Pipe the current article to a subprocess.
11589 If N is a positive number, pipe the N next articles.
11590 If N is a negative number, pipe the N previous articles.
11591 If N is nil and any articles have been marked with the process mark,
11592 pipe those articles instead.
11593 If HEADERS (the symbolic prefix), include the headers, too."
11594   (interactive (gnus-interactive "P\ny"))
11595   (require 'gnus-art)
11596   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11597         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11598     (gnus-summary-save-article arg t))
11599   (let ((buffer (get-buffer "*Shell Command Output*")))
11600     (when (and buffer
11601                (not (zerop (buffer-size buffer))))
11602       (gnus-configure-windows 'pipe))))
11603
11604 (defun gnus-summary-save-article-mail (&optional arg)
11605   "Append the current article to a Unix mail box file.
11606 If N is a positive number, save the N next articles.
11607 If N is a negative number, save the N previous articles.
11608 If N is nil and any articles have been marked with the process mark,
11609 save those articles instead."
11610   (interactive "P")
11611   (require 'gnus-art)
11612   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11613     (gnus-summary-save-article arg)))
11614
11615 (defun gnus-summary-save-article-rmail (&optional arg)
11616   "Append the current article to an rmail file.
11617 If N is a positive number, save the N next articles.
11618 If N is a negative number, save the N previous articles.
11619 If N is nil and any articles have been marked with the process mark,
11620 save those articles instead."
11621   (interactive "P")
11622   (require 'gnus-art)
11623   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11624     (gnus-summary-save-article arg)))
11625
11626 (defun gnus-summary-save-article-file (&optional arg)
11627   "Append the current article to a file.
11628 If N is a positive number, save the N next articles.
11629 If N is a negative number, save the N previous articles.
11630 If N is nil and any articles have been marked with the process mark,
11631 save those articles instead."
11632   (interactive "P")
11633   (require 'gnus-art)
11634   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11635     (gnus-summary-save-article arg)))
11636
11637 (defun gnus-summary-write-article-file (&optional arg)
11638   "Write the current article to a file, deleting the previous file.
11639 If N is a positive number, save the N next articles.
11640 If N is a negative number, save the N previous articles.
11641 If N is nil and any articles have been marked with the process mark,
11642 save those articles instead."
11643   (interactive "P")
11644   (require 'gnus-art)
11645   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11646     (gnus-summary-save-article arg)))
11647
11648 (defun gnus-summary-save-article-body-file (&optional arg)
11649   "Append the current article body to a file.
11650 If N is a positive number, save the N next articles.
11651 If N is a negative number, save the N previous articles.
11652 If N is nil and any articles have been marked with the process mark,
11653 save those articles instead."
11654   (interactive "P")
11655   (require 'gnus-art)
11656   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11657     (gnus-summary-save-article arg)))
11658
11659 (defun gnus-summary-write-article-body-file (&optional arg)
11660   "Write the current article body to a file, deleting the previous file.
11661 If N is a positive number, save the N next articles.
11662 If N is a negative number, save the N previous articles.
11663 If N is nil and any articles have been marked with the process mark,
11664 save those articles instead."
11665   (interactive "P")
11666   (require 'gnus-art)
11667   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11668     (gnus-summary-save-article arg)))
11669
11670 (defun gnus-summary-muttprint (&optional arg)
11671   "Print the current article using Muttprint.
11672 If N is a positive number, save the N next articles.
11673 If N is a negative number, save the N previous articles.
11674 If N is nil and any articles have been marked with the process mark,
11675 save those articles instead."
11676   (interactive "P")
11677   (require 'gnus-art)
11678   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11679     (gnus-summary-save-article arg t)))
11680
11681 (defun gnus-summary-pipe-message (program)
11682   "Pipe the current article through PROGRAM."
11683   (interactive "sProgram: ")
11684   (gnus-summary-select-article)
11685   (let ((mail-header-separator ""))
11686     (gnus-eval-in-buffer-window gnus-article-buffer
11687       (save-restriction
11688         (widen)
11689         (let ((start (window-start))
11690               buffer-read-only)
11691           (message-pipe-buffer-body program)
11692           (set-window-start (get-buffer-window (current-buffer)) start))))))
11693
11694 (defun gnus-get-split-value (methods)
11695   "Return a value based on the split METHODS."
11696   (let (split-name method result match)
11697     (when methods
11698       (save-excursion
11699         (set-buffer gnus-original-article-buffer)
11700         (save-restriction
11701           (nnheader-narrow-to-headers)
11702           (while (and methods (not split-name))
11703             (goto-char (point-min))
11704             (setq method (pop methods))
11705             (setq match (car method))
11706             (when (cond
11707                    ((stringp match)
11708                     ;; Regular expression.
11709                     (ignore-errors
11710                       (re-search-forward match nil t)))
11711                    ((functionp match)
11712                     ;; Function.
11713                     (save-restriction
11714                       (widen)
11715                       (setq result (funcall match gnus-newsgroup-name))))
11716                    ((consp match)
11717                     ;; Form.
11718                     (save-restriction
11719                       (widen)
11720                       (setq result (eval match)))))
11721               (setq split-name (cdr method))
11722               (cond ((stringp result)
11723                      (push (expand-file-name
11724                             result gnus-article-save-directory)
11725                            split-name))
11726                     ((consp result)
11727                      (setq split-name (append result split-name)))))))))
11728     (nreverse split-name)))
11729
11730 (defun gnus-valid-move-group-p (group)
11731   (and (boundp group)
11732        (symbol-name group)
11733        (symbol-value group)
11734        (gnus-get-function (gnus-find-method-for-group
11735                            (symbol-name group)) 'request-accept-article t)))
11736
11737 (defun gnus-read-move-group-name (prompt default articles prefix)
11738   "Read a group name."
11739   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11740          (minibuffer-confirm-incomplete nil) ; XEmacs
11741          (prom
11742           (format "%s %s to"
11743                   prompt
11744                   (if (> (length articles) 1)
11745                       (format "these %d articles" (length articles))
11746                     "this article")))
11747          (to-newsgroup
11748           (let (active group)
11749             (when (or (null split-name) (= 1 (length split-name)))
11750               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11751               (mapatoms (lambda (symbol)
11752                           (setq group (symbol-name symbol))
11753                           (when (string-match "[^\000-\177]" group)
11754                             (setq group (gnus-group-decoded-name group)))
11755                           (set (intern group active) group))
11756                         gnus-active-hashtb))
11757             (cond
11758              ((null split-name)
11759               (gnus-completing-read-with-default
11760                default prom active 'gnus-valid-move-group-p nil prefix
11761                'gnus-group-history))
11762              ((= 1 (length split-name))
11763               (gnus-completing-read-with-default
11764                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11765                'gnus-group-history))
11766              (t
11767               (gnus-completing-read-with-default
11768                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11769                'gnus-group-history)))))
11770          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11771          encoded)
11772     (when to-newsgroup
11773       (if (or (string= to-newsgroup "")
11774               (string= to-newsgroup prefix))
11775           (setq to-newsgroup default))
11776       (unless to-newsgroup
11777         (error "No group name entered"))
11778       (setq encoded (mm-encode-coding-string
11779                      to-newsgroup
11780                      (gnus-group-name-charset to-method to-newsgroup)))
11781       (or (gnus-active encoded)
11782           (gnus-activate-group encoded nil nil to-method)
11783           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11784                                      to-newsgroup))
11785               (or (and (gnus-request-create-group encoded to-method)
11786                        (gnus-activate-group encoded nil nil to-method)
11787                        (gnus-subscribe-group encoded))
11788                   (error "Couldn't create group %s" to-newsgroup)))
11789           (error "No such group: %s" to-newsgroup))
11790       encoded)))
11791
11792 (defvar gnus-summary-save-parts-counter)
11793
11794 (defun gnus-summary-save-parts (type dir n &optional reverse)
11795   "Save parts matching TYPE to DIR.
11796 If REVERSE, save parts that do not match TYPE."
11797   (interactive
11798    (list (read-string "Save parts of type: "
11799                       (or (car gnus-summary-save-parts-type-history)
11800                           gnus-summary-save-parts-default-mime)
11801                       'gnus-summary-save-parts-type-history)
11802          (setq gnus-summary-save-parts-last-directory
11803                (read-file-name "Save to directory: "
11804                                gnus-summary-save-parts-last-directory
11805                                nil t))
11806          current-prefix-arg))
11807   (gnus-summary-iterate n
11808     (let ((gnus-display-mime-function nil)
11809           (gnus-inhibit-treatment t))
11810       (gnus-summary-select-article))
11811     (save-excursion
11812       (set-buffer gnus-article-buffer)
11813       (let ((handles (or gnus-article-mime-handles
11814                          (mm-dissect-buffer nil gnus-article-loose-mime)
11815                          (and gnus-article-emulate-mime
11816                               (mm-uu-dissect))))
11817             (gnus-summary-save-parts-counter 1))
11818         (when handles
11819           (gnus-summary-save-parts-1 type dir handles reverse)
11820           (unless gnus-article-mime-handles ;; Don't destroy this case.
11821             (mm-destroy-parts handles)))))))
11822
11823 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11824   (if (stringp (car handle))
11825       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11826               (cdr handle))
11827     (when (if reverse
11828               (not (string-match type (mm-handle-media-type handle)))
11829             (string-match type (mm-handle-media-type handle)))
11830       (let ((file (expand-file-name
11831                    (gnus-map-function
11832                     mm-file-name-rewrite-functions
11833                     (file-name-nondirectory
11834                      (or
11835                       (mail-content-type-get
11836                        (mm-handle-disposition handle) 'filename)
11837                       (mail-content-type-get
11838                        (mm-handle-type handle) 'name)
11839                       (format "%s.%d.%d" gnus-newsgroup-name
11840                               (cdr gnus-article-current)
11841                               gnus-summary-save-parts-counter))))
11842                    dir)))
11843         (incf gnus-summary-save-parts-counter)
11844         (unless (file-exists-p file)
11845           (mm-save-part-to-file handle file))))))
11846
11847 ;; Summary extract commands
11848
11849 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11850   (let ((buffer-read-only nil)
11851         (article (gnus-summary-article-number))
11852         after-article b e)
11853     (unless (gnus-summary-goto-subject article)
11854       (error "No such article: %d" article))
11855     (gnus-summary-position-point)
11856     ;; If all commands are to be bunched up on one line, we collect
11857     ;; them here.
11858     (unless gnus-view-pseudos-separately
11859       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11860             files action)
11861         (while ps
11862           (setq action (cdr (assq 'action (car ps))))
11863           (setq files (list (cdr (assq 'name (car ps)))))
11864           (while (and ps (cdr ps)
11865                       (string= (or action "1")
11866                                (or (cdr (assq 'action (cadr ps))) "2")))
11867             (push (cdr (assq 'name (cadr ps))) files)
11868             (setcdr ps (cddr ps)))
11869           (when files
11870             (when (not (string-match "%s" action))
11871               (push " " files))
11872             (push " " files)
11873             (when (assq 'execute (car ps))
11874               (setcdr (assq 'execute (car ps))
11875                       (funcall (if (string-match "%s" action)
11876                                    'format 'concat)
11877                                action
11878                                (mapconcat
11879                                 (lambda (f)
11880                                   (if (equal f " ")
11881                                       f
11882                                     (shell-quote-argument f)))
11883                                 files " ")))))
11884           (setq ps (cdr ps)))))
11885     (if (and gnus-view-pseudos (not not-view))
11886         (while pslist
11887           (when (assq 'execute (car pslist))
11888             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11889                                   (eq gnus-view-pseudos 'not-confirm)))
11890           (setq pslist (cdr pslist)))
11891       (save-excursion
11892         (while pslist
11893           (setq after-article (or (cdr (assq 'article (car pslist)))
11894                                   (gnus-summary-article-number)))
11895           (gnus-summary-goto-subject after-article)
11896           (forward-line 1)
11897           (setq b (point))
11898           (insert "    " (file-name-nondirectory
11899                           (cdr (assq 'name (car pslist))))
11900                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11901           (setq e (point))
11902           (forward-line -1)             ; back to `b'
11903           (gnus-add-text-properties
11904            b (1- e) (list 'gnus-number gnus-reffed-article-number
11905                           gnus-mouse-face-prop gnus-mouse-face))
11906           (gnus-data-enter
11907            after-article gnus-reffed-article-number
11908            gnus-unread-mark b (car pslist) 0 (- e b))
11909           (setq gnus-newsgroup-unreads
11910                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11911                                          gnus-reffed-article-number))
11912           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11913           (setq pslist (cdr pslist)))))))
11914
11915 (defun gnus-pseudos< (p1 p2)
11916   (let ((c1 (cdr (assq 'action p1)))
11917         (c2 (cdr (assq 'action p2))))
11918     (and c1 c2 (string< c1 c2))))
11919
11920 (defun gnus-request-pseudo-article (props)
11921   (cond ((assq 'execute props)
11922          (gnus-execute-command (cdr (assq 'execute props)))))
11923   (let ((gnus-current-article (gnus-summary-article-number)))
11924     (gnus-run-hooks 'gnus-mark-article-hook)))
11925
11926 (defun gnus-execute-command (command &optional automatic)
11927   (save-excursion
11928     (gnus-article-setup-buffer)
11929     (set-buffer gnus-article-buffer)
11930     (setq buffer-read-only nil)
11931     (let ((command (if automatic command
11932                      (read-string "Command: " (cons command 0)))))
11933       (erase-buffer)
11934       (insert "$ " command "\n\n")
11935       (if gnus-view-pseudo-asynchronously
11936           (start-process "gnus-execute" (current-buffer) shell-file-name
11937                          shell-command-switch command)
11938         (call-process shell-file-name nil t nil
11939                       shell-command-switch command)))))
11940
11941 ;; Summary kill commands.
11942
11943 (defun gnus-summary-edit-global-kill (article)
11944   "Edit the \"global\" kill file."
11945   (interactive (list (gnus-summary-article-number)))
11946   (gnus-group-edit-global-kill article))
11947
11948 (defun gnus-summary-edit-local-kill ()
11949   "Edit a local kill file applied to the current newsgroup."
11950   (interactive)
11951   (setq gnus-current-headers (gnus-summary-article-header))
11952   (gnus-group-edit-local-kill
11953    (gnus-summary-article-number) gnus-newsgroup-name))
11954
11955 ;;; Header reading.
11956
11957 (defun gnus-read-header (id &optional header)
11958   "Read the headers of article ID and enter them into the Gnus system."
11959   (let ((group gnus-newsgroup-name)
11960         (gnus-override-method
11961          (or
11962           gnus-override-method
11963           (and (gnus-news-group-p gnus-newsgroup-name)
11964                (car (gnus-refer-article-methods)))))
11965         where)
11966     ;; First we check to see whether the header in question is already
11967     ;; fetched.
11968     (if (stringp id)
11969         ;; This is a Message-ID.
11970         (setq header (or header (gnus-id-to-header id)))
11971       ;; This is an article number.
11972       (setq header (or header (gnus-summary-article-header id))))
11973     (if (and header
11974              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11975         ;; We have found the header.
11976         header
11977       ;; We have to really fetch the header to this article.
11978       (save-excursion
11979         (set-buffer nntp-server-buffer)
11980         (when (setq where (gnus-request-head id group))
11981           (nnheader-fold-continuation-lines)
11982           (goto-char (point-max))
11983           (insert ".\n")
11984           (goto-char (point-min))
11985           (insert "211 ")
11986           (princ (cond
11987                   ((numberp id) id)
11988                   ((cdr where) (cdr where))
11989                   (header (mail-header-number header))
11990                   (t gnus-reffed-article-number))
11991                  (current-buffer))
11992           (insert " Article retrieved.\n"))
11993         (if (or (not where)
11994                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11995             ()                          ; Malformed head.
11996           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11997             (when (and (stringp id)
11998                        (or
11999                         (not (string= (gnus-group-real-name group)
12000                                       (car where)))
12001                         (not (gnus-server-equal gnus-override-method
12002                                                 (gnus-group-method group)))))
12003               ;; If we fetched by Message-ID and the article came from
12004               ;; a different group (or server), we fudge some bogus
12005               ;; article numbers for this article.
12006               (mail-header-set-number header gnus-reffed-article-number))
12007             (save-excursion
12008               (set-buffer gnus-summary-buffer)
12009               (decf gnus-reffed-article-number)
12010               (gnus-remove-header (mail-header-number header))
12011               (push header gnus-newsgroup-headers)
12012               (setq gnus-current-headers header)
12013               (push (mail-header-number header) gnus-newsgroup-limit)))
12014           header)))))
12015
12016 (defun gnus-remove-header (number)
12017   "Remove header NUMBER from `gnus-newsgroup-headers'."
12018   (if (and gnus-newsgroup-headers
12019            (= number (mail-header-number (car gnus-newsgroup-headers))))
12020       (pop gnus-newsgroup-headers)
12021     (let ((headers gnus-newsgroup-headers))
12022       (while (and (cdr headers)
12023                   (not (= number (mail-header-number (cadr headers)))))
12024         (pop headers))
12025       (when (cdr headers)
12026         (setcdr headers (cddr headers))))))
12027
12028 ;;;
12029 ;;; summary highlights
12030 ;;;
12031
12032 (defun gnus-highlight-selected-summary ()
12033   "Highlight selected article in summary buffer."
12034   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12035   (when gnus-summary-selected-face
12036     (save-excursion
12037       (let* ((beg (point-at-bol))
12038              (end (point-at-eol))
12039              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12040              (from (if (get-text-property beg gnus-mouse-face-prop)
12041                        beg
12042                      (or (next-single-property-change
12043                           beg gnus-mouse-face-prop nil end)
12044                          beg)))
12045              (to
12046               (if (= from end)
12047                   (- from 2)
12048                 (or (next-single-property-change
12049                      from gnus-mouse-face-prop nil end)
12050                     end))))
12051         ;; If no mouse-face prop on line we will have to = from = end,
12052         ;; so we highlight the entire line instead.
12053         (when (= (+ to 2) from)
12054           (setq from beg)
12055           (setq to end))
12056         (if gnus-newsgroup-selected-overlay
12057             ;; Move old overlay.
12058             (gnus-move-overlay
12059              gnus-newsgroup-selected-overlay from to (current-buffer))
12060           ;; Create new overlay.
12061           (gnus-overlay-put
12062            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12063            'face gnus-summary-selected-face))))))
12064
12065 (defvar gnus-summary-highlight-line-cached nil)
12066 (defvar gnus-summary-highlight-line-trigger nil)
12067
12068 (defun gnus-summary-highlight-line-0 ()
12069   (if (and (eq gnus-summary-highlight-line-trigger
12070                gnus-summary-highlight)
12071            gnus-summary-highlight-line-cached)
12072       gnus-summary-highlight-line-cached
12073     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12074           gnus-summary-highlight-line-cached
12075           (let* ((cond (list 'cond))
12076                  (c cond)
12077                  (list gnus-summary-highlight))
12078             (while list
12079               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12080                               nil))
12081               (setq c (cdr c)
12082                     list (cdr list)))
12083             (gnus-byte-compile (list 'lambda nil cond))))))
12084
12085 (defun gnus-summary-highlight-line ()
12086   "Highlight current line according to `gnus-summary-highlight'."
12087   (let* ((beg (point-at-bol))
12088          (article (or (gnus-summary-article-number) gnus-current-article))
12089          (score (or (cdr (assq article
12090                                gnus-newsgroup-scored))
12091                     gnus-summary-default-score 0))
12092          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12093          (inhibit-read-only t)
12094          (default gnus-summary-default-score)
12095          (default-high gnus-summary-default-high-score)
12096          (default-low gnus-summary-default-low-score)
12097          (uncached (and gnus-summary-use-undownloaded-faces
12098                         (memq article gnus-newsgroup-undownloaded)
12099                         (not (memq article gnus-newsgroup-cached)))))
12100     (let ((face (funcall (gnus-summary-highlight-line-0))))
12101       (unless (eq face (get-text-property beg 'face))
12102         (gnus-put-text-property-excluding-characters-with-faces
12103          beg (point-at-eol) 'face
12104          (setq face (if (boundp face) (symbol-value face) face)))
12105         (when gnus-summary-highlight-line-function
12106           (funcall gnus-summary-highlight-line-function article face))))))
12107
12108 (defun gnus-update-read-articles (group unread &optional compute)
12109   "Update the list of read articles in GROUP.
12110 UNREAD is a sorted list."
12111   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12112         (info (gnus-get-info group))
12113         (prev 1)
12114         read)
12115     (if (or (not info) (not active))
12116         ;; There is no info on this group if it was, in fact,
12117         ;; killed.  Gnus stores no information on killed groups, so
12118         ;; there's nothing to be done.
12119         ;; One could store the information somewhere temporarily,
12120         ;; perhaps...  Hmmm...
12121         ()
12122       ;; Remove any negative articles numbers.
12123       (while (and unread (< (car unread) 0))
12124         (setq unread (cdr unread)))
12125       ;; Remove any expired article numbers
12126       (while (and unread (< (car unread) (car active)))
12127         (setq unread (cdr unread)))
12128       ;; Compute the ranges of read articles by looking at the list of
12129       ;; unread articles.
12130       (while unread
12131         (when (/= (car unread) prev)
12132           (push (if (= prev (1- (car unread))) prev
12133                   (cons prev (1- (car unread))))
12134                 read))
12135         (setq prev (1+ (car unread)))
12136         (setq unread (cdr unread)))
12137       (when (<= prev (cdr active))
12138         (push (cons prev (cdr active)) read))
12139       (setq read (if (> (length read) 1) (nreverse read) read))
12140       (if compute
12141           read
12142         (save-excursion
12143           (let (setmarkundo)
12144             ;; Propagate the read marks to the backend.
12145             (when (gnus-check-backend-function 'request-set-mark group)
12146               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12147                     (add (gnus-remove-from-range read (gnus-info-read info))))
12148                 (when (or add del)
12149                   (unless (gnus-check-group group)
12150                     (error "Can't open server for %s" group))
12151                   (gnus-request-set-mark
12152                    group (delq nil (list (if add (list add 'add '(read)))
12153                                          (if del (list del 'del '(read))))))
12154                   (setq setmarkundo
12155                         `(gnus-request-set-mark
12156                           ,group
12157                           ',(delq nil (list
12158                                        (if del (list del 'add '(read)))
12159                                        (if add (list add 'del '(read))))))))))
12160             (set-buffer gnus-group-buffer)
12161             (gnus-undo-register
12162               `(progn
12163                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12164                  (gnus-info-set-read ',info ',(gnus-info-read info))
12165                  (gnus-get-unread-articles-in-group ',info
12166                                                     (gnus-active ,group))
12167                  (gnus-group-update-group ,group t)
12168                  ,setmarkundo))))
12169         ;; Enter this list into the group info.
12170         (gnus-info-set-read info read)
12171         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12172         (gnus-get-unread-articles-in-group info (gnus-active group))
12173         t))))
12174
12175 (defun gnus-offer-save-summaries ()
12176   "Offer to save all active summary buffers."
12177   (let (buffers)
12178     ;; Go through all buffers and find all summaries.
12179     (dolist (buffer (buffer-list))
12180       (when (and (setq buffer (buffer-name buffer))
12181                  (string-match "Summary" buffer)
12182                  (with-current-buffer buffer
12183                    ;; We check that this is, indeed, a summary buffer.
12184                    (and (eq major-mode 'gnus-summary-mode)
12185                         ;; Also make sure this isn't bogus.
12186                         gnus-newsgroup-prepared
12187                         ;; Also make sure that this isn't a
12188                         ;; dead summary buffer.
12189                         (not gnus-dead-summary-mode))))
12190         (push buffer buffers)))
12191     ;; Go through all these summary buffers and offer to save them.
12192     (when buffers
12193       (save-excursion
12194         (map-y-or-n-p
12195          "Update summary buffer %s? "
12196          (lambda (buf)
12197            (switch-to-buffer buf)
12198            (gnus-summary-exit))
12199          buffers)))))
12200
12201 (defun gnus-summary-setup-default-charset ()
12202   "Setup newsgroup default charset."
12203   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12204       (setq gnus-newsgroup-charset nil)
12205     (let* ((ignored-charsets
12206             (or gnus-newsgroup-ephemeral-ignored-charsets
12207                 (append
12208                  (and gnus-newsgroup-name
12209                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12210                  gnus-newsgroup-ignored-charsets))))
12211       (setq gnus-newsgroup-charset
12212             (or gnus-newsgroup-ephemeral-charset
12213                 (and gnus-newsgroup-name
12214                      (gnus-parameter-charset gnus-newsgroup-name))
12215                 gnus-default-charset))
12216       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12217            ignored-charsets))))
12218
12219 ;;;
12220 ;;; Mime Commands
12221 ;;;
12222
12223 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12224   "Display the current article buffer fully MIME-buttonized.
12225 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12226 treated as multipart/mixed."
12227   (interactive "P")
12228   (require 'gnus-art)
12229   (let ((gnus-unbuttonized-mime-types nil)
12230         (gnus-mime-display-multipart-as-mixed show-all-parts))
12231     (gnus-summary-show-article)))
12232
12233 (defun gnus-summary-repair-multipart (article)
12234   "Add a Content-Type header to a multipart article without one."
12235   (interactive (list (gnus-summary-article-number)))
12236   (gnus-with-article article
12237     (message-narrow-to-head)
12238     (message-remove-header "Mime-Version")
12239     (goto-char (point-max))
12240     (insert "Mime-Version: 1.0\n")
12241     (widen)
12242     (when (search-forward "\n--" nil t)
12243       (let ((separator (buffer-substring (point) (point-at-eol))))
12244         (message-narrow-to-head)
12245         (message-remove-header "Content-Type")
12246         (goto-char (point-max))
12247         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12248                         separator))
12249         (widen))))
12250   (let (gnus-mark-article-hook)
12251     (gnus-summary-select-article t t nil article)))
12252
12253 (defun gnus-summary-toggle-display-buttonized ()
12254   "Toggle the buttonizing of the article buffer."
12255   (interactive)
12256   (require 'gnus-art)
12257   (if (setq gnus-inhibit-mime-unbuttonizing
12258             (not gnus-inhibit-mime-unbuttonizing))
12259       (let ((gnus-unbuttonized-mime-types nil))
12260         (gnus-summary-show-article))
12261     (gnus-summary-show-article)))
12262
12263 ;;;
12264 ;;; Generic summary marking commands
12265 ;;;
12266
12267 (defvar gnus-summary-marking-alist
12268   '((read gnus-del-mark "d")
12269     (unread gnus-unread-mark "u")
12270     (ticked gnus-ticked-mark "!")
12271     (dormant gnus-dormant-mark "?")
12272     (expirable gnus-expirable-mark "e"))
12273   "An alist of names/marks/keystrokes.")
12274
12275 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12276 (defvar gnus-summary-mark-map)
12277
12278 (defun gnus-summary-make-all-marking-commands ()
12279   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12280   (dolist (elem gnus-summary-marking-alist)
12281     (apply 'gnus-summary-make-marking-command elem)))
12282
12283 (defun gnus-summary-make-marking-command (name mark keystroke)
12284   (let ((map (make-sparse-keymap)))
12285     (define-key gnus-summary-generic-mark-map keystroke map)
12286     (dolist (lway `((next "next" next nil "n")
12287                     (next-unread "next unread" next t "N")
12288                     (prev "previous" prev nil "p")
12289                     (prev-unread "previous unread" prev t "P")
12290                     (nomove "" nil nil ,keystroke)))
12291       (let ((func (gnus-summary-make-marking-command-1
12292                    mark (car lway) lway name)))
12293         (setq func (eval func))
12294         (define-key map (nth 4 lway) func)))))
12295
12296 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12297   `(defun ,(intern
12298             (format "gnus-summary-put-mark-as-%s%s"
12299                     name (if (eq way 'nomove)
12300                              ""
12301                            (concat "-" (symbol-name way)))))
12302      (n)
12303      ,(format
12304        "Mark the current article as %s%s.
12305 If N, the prefix, then repeat N times.
12306 If N is negative, move in reverse order.
12307 The difference between N and the actual number of articles marked is
12308 returned."
12309        name (cadr lway))
12310      (interactive "p")
12311      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12312
12313 (defun gnus-summary-generic-mark (n mark move unread)
12314   "Mark N articles with MARK."
12315   (unless (eq major-mode 'gnus-summary-mode)
12316     (error "This command can only be used in the summary buffer"))
12317   (gnus-summary-show-thread)
12318   (let ((nummove
12319          (cond
12320           ((eq move 'next) 1)
12321           ((eq move 'prev) -1)
12322           (t 0))))
12323     (if (zerop nummove)
12324         (setq n 1)
12325       (when (< n 0)
12326         (setq n (abs n)
12327               nummove (* -1 nummove))))
12328     (while (and (> n 0)
12329                 (gnus-summary-mark-article nil mark)
12330                 (zerop (gnus-summary-next-subject nummove unread t)))
12331       (setq n (1- n)))
12332     (when (/= 0 n)
12333       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12334     (gnus-summary-recenter)
12335     (gnus-summary-position-point)
12336     (gnus-set-mode-line 'summary)
12337     n))
12338
12339 (defun gnus-summary-insert-articles (articles)
12340   (when (setq articles
12341               (gnus-sorted-difference articles
12342                                       (mapcar (lambda (h)
12343                                                 (mail-header-number h))
12344                                               gnus-newsgroup-headers)))
12345     (setq gnus-newsgroup-headers
12346           (gnus-merge 'list
12347                       gnus-newsgroup-headers
12348                       (gnus-fetch-headers articles)
12349                       'gnus-article-sort-by-number))
12350     ;; Suppress duplicates?
12351     (when gnus-suppress-duplicates
12352       (gnus-dup-suppress-articles))
12353
12354     (if (and gnus-fetch-old-headers
12355              (eq gnus-headers-retrieved-by 'nov))
12356         ;; We might want to build some more threads first.
12357         (if (eq gnus-fetch-old-headers 'invisible)
12358             (gnus-build-all-threads)
12359           (gnus-build-old-threads))
12360       ;; Mark the inserted articles that are unread as unread.
12361       (setq gnus-newsgroup-unreads
12362             (gnus-sorted-nunion
12363              gnus-newsgroup-unreads
12364              (gnus-sorted-nintersection
12365               (gnus-list-of-unread-articles gnus-newsgroup-name)
12366               articles)))
12367       ;; Mark the inserted articles as selected so that the information
12368       ;; of the marks having been changed by a user may be updated when
12369       ;; exiting this group.  See `gnus-summary-update-info'.
12370       (dolist (art articles)
12371         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12372     ;; Let the Gnus agent mark articles as read.
12373     (when gnus-agent
12374       (gnus-agent-get-undownloaded-list))
12375     ;; Remove list identifiers from subject
12376     (when gnus-list-identifiers
12377       (gnus-summary-remove-list-identifiers))
12378     ;; First and last article in this newsgroup.
12379     (when gnus-newsgroup-headers
12380       (setq gnus-newsgroup-begin
12381             (mail-header-number (car gnus-newsgroup-headers))
12382             gnus-newsgroup-end
12383             (mail-header-number
12384              (gnus-last-element gnus-newsgroup-headers))))
12385     (when gnus-use-scoring
12386       (gnus-possibly-score-headers))))
12387
12388 (defun gnus-summary-insert-old-articles (&optional all)
12389   "Insert all old articles in this group.
12390 If ALL is non-nil, already read articles become readable.
12391 If ALL is a number, fetch this number of articles."
12392   (interactive "P")
12393   (prog1
12394       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12395             older len)
12396         (setq older
12397               ;; Some nntp servers lie about their active range.  When
12398               ;; this happens, the active range can be in the millions.
12399               ;; Use a compressed range to avoid creating a huge list.
12400               (gnus-range-difference (list gnus-newsgroup-active) old))
12401         (setq len (gnus-range-length older))
12402         (cond
12403          ((null older) nil)
12404          ((numberp all)
12405           (if (< all len)
12406               (let ((older-range (nreverse older)))
12407                 (setq older nil)
12408
12409                 (while (> all 0)
12410                   (let* ((r (pop older-range))
12411                          (min (if (numberp r) r (car r)))
12412                          (max (if (numberp r) r (cdr r))))
12413                     (while (and (<= min max)
12414                                 (> all 0))
12415                       (push max older)
12416                       (setq all (1- all)
12417                             max (1- max))))))
12418             (setq older (gnus-uncompress-range older))))
12419          (all
12420           (setq older (gnus-uncompress-range older)))
12421          (t
12422           (when (and (numberp gnus-large-newsgroup)
12423                    (> len gnus-large-newsgroup))
12424               (let* ((cursor-in-echo-area nil)
12425                      (initial (gnus-parameter-large-newsgroup-initial
12426                                gnus-newsgroup-name))
12427                      (input
12428                       (read-string
12429                        (format
12430                         "How many articles from %s (%s %d): "
12431                         (gnus-group-decoded-name gnus-newsgroup-name)
12432                         (if initial "max" "default")
12433                         len)
12434                        (if initial
12435                            (cons (number-to-string initial)
12436                                  0)))))
12437                 (unless (string-match "^[ \t]*$" input)
12438                   (setq all (string-to-number input))
12439                   (if (< all len)
12440                       (let ((older-range (nreverse older)))
12441                         (setq older nil)
12442
12443                         (while (> all 0)
12444                           (let* ((r (pop older-range))
12445                                  (min (if (numberp r) r (car r)))
12446                                  (max (if (numberp r) r (cdr r))))
12447                             (while (and (<= min max)
12448                                         (> all 0))
12449                               (push max older)
12450                               (setq all (1- all)
12451                                     max (1- max))))))))))
12452           (setq older (gnus-uncompress-range older))))
12453         (if (not older)
12454             (message "No old news.")
12455           (gnus-summary-insert-articles older)
12456           (gnus-summary-limit (gnus-sorted-nunion old older))))
12457     (gnus-summary-position-point)))
12458
12459 (defun gnus-summary-insert-new-articles ()
12460   "Insert all new articles in this group."
12461   (interactive)
12462   (prog1
12463       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12464             (old-active gnus-newsgroup-active)
12465             (nnmail-fetched-sources (list t))
12466             i new)
12467         (setq gnus-newsgroup-active
12468               (gnus-activate-group gnus-newsgroup-name 'scan))
12469         (setq i (cdr gnus-newsgroup-active))
12470         (while (> i (cdr old-active))
12471           (push i new)
12472           (decf i))
12473         (if (not new)
12474             (message "No gnus is bad news")
12475           (gnus-summary-insert-articles new)
12476           (setq gnus-newsgroup-unreads
12477                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12478           (gnus-summary-limit (gnus-sorted-nunion old new))))
12479     (gnus-summary-position-point)))
12480
12481 (gnus-summary-make-all-marking-commands)
12482
12483 (gnus-ems-redefine)
12484
12485 (provide 'gnus-sum)
12486
12487 (run-hooks 'gnus-sum-load-hook)
12488
12489 ;; Local Variables:
12490 ;; coding: iso-8859-1
12491 ;; End:
12492
12493 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12494 ;;; gnus-sum.el ends here