Merge from gnus--rel--5.10
[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 3, 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 (put 'gnus-summary-highlight 'risky-local-variable t)
1084
1085 (defcustom gnus-alter-header-function nil
1086   "Function called to allow alteration of article header structures.
1087 The function is called with one parameter, the article header vector,
1088 which it may alter in any way."
1089   :type '(choice (const :tag "None" nil)
1090                  function)
1091   :group 'gnus-summary)
1092
1093 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1094   "Function used to decode a string with encoded words.")
1095
1096 (defvar gnus-decode-encoded-address-function
1097   'mail-decode-encoded-address-string
1098   "Function used to decode addresses with encoded words.")
1099
1100 (defcustom gnus-extra-headers '(To Newsgroups)
1101   "*Extra headers to parse."
1102   :version "21.1"
1103   :group 'gnus-summary
1104   :type '(repeat symbol))
1105
1106 (defcustom gnus-ignored-from-addresses
1107   (and user-mail-address
1108        (not (string= user-mail-address ""))
1109        (regexp-quote user-mail-address))
1110   "*From headers that may be suppressed in favor of To headers.
1111 This can be a regexp or a list of regexps."
1112   :version "21.1"
1113   :group 'gnus-summary
1114   :type '(choice regexp
1115                  (repeat :tag "Regexp List" regexp)))
1116
1117 (defsubst gnus-ignored-from-addresses ()
1118   (gmm-regexp-concat gnus-ignored-from-addresses))
1119
1120 (defcustom gnus-summary-to-prefix "-> "
1121   "*String prefixed to the To field in the summary line when
1122 using `gnus-ignored-from-addresses'."
1123   :version "22.1"
1124   :group 'gnus-summary
1125   :type 'string)
1126
1127 (defcustom gnus-summary-newsgroup-prefix "=> "
1128   "*String prefixed to the Newsgroup field in the summary
1129 line when using `gnus-ignored-from-addresses'."
1130   :version "22.1"
1131   :group 'gnus-summary
1132   :type 'string)
1133
1134 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1135   "List of charsets that should be ignored.
1136 When these charsets are used in the \"charset\" parameter, the
1137 default charset will be used instead."
1138   :version "21.1"
1139   :type '(repeat symbol)
1140   :group 'gnus-charset)
1141
1142 (defcustom gnus-newsgroup-maximum-articles nil
1143   "The maximum number of articles a newsgroup.
1144 If this is a number, old articles in a newsgroup exceeding this number
1145 are silently ignored.  If it is nil, no article is ignored.  Note that
1146 setting this variable to a number might prevent you from reading very
1147 old articles."
1148   :group 'gnus-group-select
1149   :version "22.2"
1150   :type '(choice (const :tag "No limit" nil)
1151                  integer))
1152
1153 (gnus-define-group-parameter
1154  ignored-charsets
1155  :type list
1156  :function-document
1157  "Return the ignored charsets of GROUP."
1158  :variable gnus-group-ignored-charsets-alist
1159  :variable-default
1160  '(("alt\\.chinese\\.text" iso-8859-1))
1161  :variable-document
1162  "Alist of regexps (to match group names) and charsets that should be ignored.
1163 When these charsets are used in the \"charset\" parameter, the
1164 default charset will be used instead."
1165  :variable-group gnus-charset
1166  :variable-type '(repeat (cons (regexp :tag "Group")
1167                                (repeat symbol)))
1168  :parameter-type '(choice :tag "Ignored charsets"
1169                           :value nil
1170                           (repeat (symbol)))
1171  :parameter-document       "\
1172 List of charsets that should be ignored.
1173
1174 When these charsets are used in the \"charset\" parameter, the
1175 default charset will be used instead.")
1176
1177 (defcustom gnus-group-highlight-words-alist nil
1178   "Alist of group regexps and highlight regexps.
1179 This variable uses the same syntax as `gnus-emphasis-alist'."
1180   :version "21.1"
1181   :type '(repeat (cons (regexp :tag "Group")
1182                        (repeat (list (regexp :tag "Highlight regexp")
1183                                      (number :tag "Group for entire word" 0)
1184                                      (number :tag "Group for displayed part" 0)
1185                                      (symbol :tag "Face"
1186                                              gnus-emphasis-highlight-words)))))
1187   :group 'gnus-summary-visual)
1188
1189 (defcustom gnus-summary-show-article-charset-alist
1190   nil
1191   "Alist of number and charset.
1192 The article will be shown with the charset corresponding to the
1193 numbered argument.
1194 For example: ((1 . cn-gb-2312) (2 . big5))."
1195   :version "21.1"
1196   :type '(repeat (cons (number :tag "Argument" 1)
1197                        (symbol :tag "Charset")))
1198   :group 'gnus-charset)
1199
1200 (defcustom gnus-preserve-marks t
1201   "Whether marks are preserved when moving, copying and respooling messages."
1202   :version "21.1"
1203   :type 'boolean
1204   :group 'gnus-summary-marks)
1205
1206 (defcustom gnus-alter-articles-to-read-function nil
1207   "Function to be called to alter the list of articles to be selected."
1208   :type '(choice (const nil) function)
1209   :group 'gnus-summary)
1210
1211 (defcustom gnus-orphan-score nil
1212   "*All orphans get this score added.  Set in the score file."
1213   :group 'gnus-score-default
1214   :type '(choice (const nil)
1215                  integer))
1216
1217 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1218   "*A regexp to match MIME parts when saving multiple parts of a
1219 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1220 This regexp will be used by default when prompting the user for which
1221 type of files to save."
1222   :group 'gnus-summary
1223   :type 'regexp)
1224
1225 (defcustom gnus-read-all-available-headers nil
1226   "Whether Gnus should parse all headers made available to it.
1227 This is mostly relevant for slow back ends where the user may
1228 wish to widen the summary buffer to include all headers
1229 that were fetched.  Say, for nnultimate groups."
1230   :version "22.1"
1231   :group 'gnus-summary
1232   :type '(choice boolean regexp))
1233
1234 (defcustom gnus-summary-muttprint-program "muttprint"
1235   "Command (and optional arguments) used to run Muttprint."
1236   :version "22.1"
1237   :group 'gnus-summary
1238   :type 'string)
1239
1240 (defcustom gnus-article-loose-mime t
1241   "If non-nil, don't require MIME-Version header.
1242 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1243 supply the MIME-Version header or deliberately strip it from the mail.
1244 If non-nil (the default), Gnus will treat some articles as MIME
1245 even if the MIME-Version header is missing."
1246   :version "22.1"
1247   :type 'boolean
1248   :group 'gnus-article-mime)
1249
1250 (defcustom gnus-article-emulate-mime t
1251   "If non-nil, use MIME emulation for uuencode and the like.
1252 This means that Gnus will search message bodies for text that look
1253 like uuencoded bits, yEncoded bits, and so on, and present that using
1254 the normal Gnus MIME machinery."
1255   :version "22.1"
1256   :type 'boolean
1257   :group 'gnus-article-mime)
1258
1259 ;;; Internal variables
1260
1261 (defvar gnus-summary-display-cache nil)
1262 (defvar gnus-article-mime-handles nil)
1263 (defvar gnus-article-decoded-p nil)
1264 (defvar gnus-article-charset nil)
1265 (defvar gnus-article-ignored-charsets nil)
1266 (defvar gnus-scores-exclude-files nil)
1267 (defvar gnus-page-broken nil)
1268
1269 (defvar gnus-original-article nil)
1270 (defvar gnus-article-internal-prepare-hook nil)
1271 (defvar gnus-newsgroup-process-stack nil)
1272
1273 (defvar gnus-thread-indent-array nil)
1274 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1275 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1276   "Function called to sort the articles within a thread after it has been gathered together.")
1277
1278 (defvar gnus-summary-save-parts-type-history nil)
1279 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1280
1281 ;; Avoid highlighting in kill files.
1282 (defvar gnus-summary-inhibit-highlight nil)
1283 (defvar gnus-newsgroup-selected-overlay nil)
1284 (defvar gnus-inhibit-limiting nil)
1285 (defvar gnus-newsgroup-adaptive-score-file nil)
1286 (defvar gnus-current-score-file nil)
1287 (defvar gnus-current-move-group nil)
1288 (defvar gnus-current-copy-group nil)
1289 (defvar gnus-current-crosspost-group nil)
1290 (defvar gnus-newsgroup-display nil)
1291
1292 (defvar gnus-newsgroup-dependencies nil)
1293 (defvar gnus-newsgroup-adaptive nil)
1294 (defvar gnus-summary-display-article-function nil)
1295 (defvar gnus-summary-highlight-line-function nil
1296   "Function called after highlighting a summary line.")
1297
1298 (defvar gnus-summary-line-format-alist
1299   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1300     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1301     (?s gnus-tmp-subject-or-nil ?s)
1302     (?n gnus-tmp-name ?s)
1303     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1304         ?s)
1305     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1306             gnus-tmp-from) ?s)
1307     (?F gnus-tmp-from ?s)
1308     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1309     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1310     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1311     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1312     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1313     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1314     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1315     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1316     (?L gnus-tmp-lines ?s)
1317     (?O gnus-tmp-downloaded ?c)
1318     (?I gnus-tmp-indentation ?s)
1319     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1320     (?R gnus-tmp-replied ?c)
1321     (?\[ gnus-tmp-opening-bracket ?c)
1322     (?\] gnus-tmp-closing-bracket ?c)
1323     (?\> (make-string gnus-tmp-level ? ) ?s)
1324     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1325     (?i gnus-tmp-score ?d)
1326     (?z gnus-tmp-score-char ?c)
1327     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1328     (?U gnus-tmp-unread ?c)
1329     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1330         ?s)
1331     (?t (gnus-summary-number-of-articles-in-thread
1332          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1333         ?d)
1334     (?e (gnus-summary-number-of-articles-in-thread
1335          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1336         ?c)
1337     (?u gnus-tmp-user-defined ?s)
1338     (?P (gnus-pick-line-number) ?d)
1339     (?B gnus-tmp-thread-tree-header-string ?s)
1340     (user-date (gnus-user-date
1341                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1342   "An alist of format specifications that can appear in summary lines.
1343 These are paired with what variables they correspond with, along with
1344 the type of the variable (string, integer, character, etc).")
1345
1346 (defvar gnus-summary-dummy-line-format-alist
1347   `((?S gnus-tmp-subject ?s)
1348     (?N gnus-tmp-number ?d)
1349     (?u gnus-tmp-user-defined ?s)))
1350
1351 (defvar gnus-summary-mode-line-format-alist
1352   `((?G gnus-tmp-group-name ?s)
1353     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1354     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1355     (?A gnus-tmp-article-number ?d)
1356     (?Z gnus-tmp-unread-and-unselected ?s)
1357     (?V gnus-version ?s)
1358     (?U gnus-tmp-unread-and-unticked ?d)
1359     (?S gnus-tmp-subject ?s)
1360     (?e gnus-tmp-unselected ?d)
1361     (?u gnus-tmp-user-defined ?s)
1362     (?d (length gnus-newsgroup-dormant) ?d)
1363     (?t (length gnus-newsgroup-marked) ?d)
1364     (?h (length gnus-newsgroup-spam-marked) ?d)
1365     (?r (length gnus-newsgroup-reads) ?d)
1366     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1367     (?E gnus-newsgroup-expunged-tally ?d)
1368     (?s (gnus-current-score-file-nondirectory) ?s)))
1369
1370 (defvar gnus-last-search-regexp nil
1371   "Default regexp for article search command.")
1372
1373 (defvar gnus-last-shell-command nil
1374   "Default shell command on article.")
1375
1376 (defvar gnus-newsgroup-agentized nil
1377   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1378 (defvar gnus-newsgroup-begin nil)
1379 (defvar gnus-newsgroup-end nil)
1380 (defvar gnus-newsgroup-last-rmail nil)
1381 (defvar gnus-newsgroup-last-mail nil)
1382 (defvar gnus-newsgroup-last-folder nil)
1383 (defvar gnus-newsgroup-last-file nil)
1384 (defvar gnus-newsgroup-last-directory nil)
1385 (defvar gnus-newsgroup-auto-expire nil)
1386 (defvar gnus-newsgroup-active nil)
1387
1388 (defvar gnus-newsgroup-data nil)
1389 (defvar gnus-newsgroup-data-reverse nil)
1390 (defvar gnus-newsgroup-limit nil)
1391 (defvar gnus-newsgroup-limits nil)
1392 (defvar gnus-summary-use-undownloaded-faces nil)
1393
1394 (defvar gnus-newsgroup-unreads nil
1395   "Sorted list of unread articles in the current newsgroup.")
1396
1397 (defvar gnus-newsgroup-unselected nil
1398   "Sorted list of unselected unread articles in the current newsgroup.")
1399
1400 (defvar gnus-newsgroup-reads nil
1401   "Alist of read articles and article marks in the current newsgroup.")
1402
1403 (defvar gnus-newsgroup-expunged-tally nil)
1404
1405 (defvar gnus-newsgroup-marked nil
1406   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1407
1408 (defvar gnus-newsgroup-spam-marked nil
1409   "List of ranges of articles that have been marked as spam.")
1410
1411 (defvar gnus-newsgroup-killed nil
1412   "List of ranges of articles that have been through the scoring process.")
1413
1414 (defvar gnus-newsgroup-cached nil
1415   "Sorted list of articles that come from the article cache.")
1416
1417 (defvar gnus-newsgroup-saved nil
1418   "List of articles that have been saved.")
1419
1420 (defvar gnus-newsgroup-kill-headers nil)
1421
1422 (defvar gnus-newsgroup-replied nil
1423   "List of articles that have been replied to in the current newsgroup.")
1424
1425 (defvar gnus-newsgroup-forwarded nil
1426   "List of articles that have been forwarded in the current newsgroup.")
1427
1428 (defvar gnus-newsgroup-recent nil
1429   "List of articles that have are recent in the current newsgroup.")
1430
1431 (defvar gnus-newsgroup-expirable nil
1432   "Sorted list of articles in the current newsgroup that can be expired.")
1433
1434 (defvar gnus-newsgroup-processable nil
1435   "List of articles in the current newsgroup that can be processed.")
1436
1437 (defvar gnus-newsgroup-downloadable nil
1438   "Sorted list of articles in the current newsgroup that can be processed.")
1439
1440 (defvar gnus-newsgroup-unfetched nil
1441   "Sorted list of articles in the current newsgroup whose headers have
1442 not been fetched into the agent.
1443
1444 This list will always be a subset of gnus-newsgroup-undownloaded.")
1445
1446 (defvar gnus-newsgroup-undownloaded nil
1447   "List of articles in the current newsgroup that haven't been downloaded.")
1448
1449 (defvar gnus-newsgroup-unsendable nil
1450   "List of articles in the current newsgroup that won't be sent.")
1451
1452 (defvar gnus-newsgroup-bookmarks nil
1453   "List of articles in the current newsgroup that have bookmarks.")
1454
1455 (defvar gnus-newsgroup-dormant nil
1456   "Sorted list of dormant articles in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-unseen nil
1459   "List of unseen articles in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-seen nil
1462   "Range of seen articles in the current newsgroup.")
1463
1464 (defvar gnus-newsgroup-articles nil
1465   "List of articles in the current newsgroup.")
1466
1467 (defvar gnus-newsgroup-scored nil
1468   "List of scored articles in the current newsgroup.")
1469
1470 (defvar gnus-newsgroup-headers nil
1471   "List of article headers in the current newsgroup.")
1472
1473 (defvar gnus-newsgroup-threads nil)
1474
1475 (defvar gnus-newsgroup-prepared nil
1476   "Whether the current group has been prepared properly.")
1477
1478 (defvar gnus-newsgroup-ancient nil
1479   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1480
1481 (defvar gnus-newsgroup-sparse nil)
1482
1483 (defvar gnus-current-article nil)
1484 (defvar gnus-article-current nil)
1485 (defvar gnus-current-headers nil)
1486 (defvar gnus-have-all-headers nil)
1487 (defvar gnus-last-article nil)
1488 (defvar gnus-newsgroup-history nil)
1489 (defvar gnus-newsgroup-charset nil)
1490 (defvar gnus-newsgroup-ephemeral-charset nil)
1491 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1492
1493 (defvar gnus-article-before-search nil)
1494
1495 (defvar gnus-summary-local-variables
1496   '(gnus-newsgroup-name
1497     gnus-newsgroup-begin gnus-newsgroup-end
1498     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1499     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1500     gnus-newsgroup-last-directory
1501     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1502     gnus-newsgroup-unselected gnus-newsgroup-marked
1503     gnus-newsgroup-spam-marked
1504     gnus-newsgroup-reads gnus-newsgroup-saved
1505     gnus-newsgroup-replied gnus-newsgroup-forwarded
1506     gnus-newsgroup-recent
1507     gnus-newsgroup-expirable
1508     gnus-newsgroup-processable gnus-newsgroup-killed
1509     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1510     gnus-newsgroup-unfetched
1511     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1512     gnus-newsgroup-seen gnus-newsgroup-articles
1513     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1514     gnus-newsgroup-headers gnus-newsgroup-threads
1515     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1516     gnus-current-article gnus-current-headers gnus-have-all-headers
1517     gnus-last-article gnus-article-internal-prepare-hook
1518     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1519     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1520     gnus-thread-expunge-below
1521     gnus-score-alist gnus-current-score-file
1522     (gnus-summary-expunge-below . global)
1523     (gnus-summary-mark-below . global)
1524     (gnus-orphan-score . global)
1525     gnus-newsgroup-active gnus-scores-exclude-files
1526     gnus-newsgroup-history gnus-newsgroup-ancient
1527     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1528     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1529     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1530     (gnus-newsgroup-expunged-tally . 0)
1531     gnus-cache-removable-articles gnus-newsgroup-cached
1532     gnus-newsgroup-data gnus-newsgroup-data-reverse
1533     gnus-newsgroup-limit gnus-newsgroup-limits
1534     gnus-newsgroup-charset gnus-newsgroup-display
1535     gnus-summary-use-undownloaded-faces)
1536   "Variables that are buffer-local to the summary buffers.")
1537
1538 (defvar gnus-newsgroup-variables nil
1539   "A list of variables that have separate values in different newsgroups.
1540 A list of newsgroup (summary buffer) local variables, or cons of
1541 variables and their default expressions to be evalled (when the default
1542 values are not nil), that should be made global while the summary buffer
1543 is active.
1544
1545 Note: The default expressions will be evaluated (using function `eval')
1546 before assignment to the local variable rather than just assigned to it.
1547 If the default expression is the symbol `global', that symbol will not
1548 be evaluated but the global value of the local variable will be used
1549 instead.
1550
1551 These variables can be used to set variables in the group parameters
1552 while still allowing them to affect operations done in other buffers.
1553 For example:
1554
1555 \(setq gnus-newsgroup-variables
1556      '(message-use-followup-to
1557        (gnus-visible-headers .
1558          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1559 ")
1560
1561 ;; Byte-compiler warning.
1562 (eval-when-compile
1563   ;; Bind features so that require will believe that gnus-sum has
1564   ;; already been loaded (avoids infinite recursion)
1565   (let ((features (cons 'gnus-sum features)))
1566     ;; Several of the declarations in gnus-sum are needed to load the
1567     ;; following files. Right now, these definitions have been
1568     ;; compiled but not defined (evaluated).  We could either do a
1569     ;; eval-and-compile about all of the declarations or evaluate the
1570     ;; source file.
1571     (if (boundp 'gnus-newsgroup-variables)
1572         nil
1573       (load "gnus-sum.el" t t t))
1574     (require 'gnus)
1575     (require 'gnus-art)))
1576
1577 ;; MIME stuff.
1578
1579 (defvar gnus-decode-encoded-word-methods
1580   '(mail-decode-encoded-word-string)
1581   "List of methods used to decode encoded words.
1582
1583 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1584 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1585 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1586 whose names match REGEXP.
1587
1588 For example:
1589 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1590  mail-decode-encoded-word-string
1591  (\"chinese\" . rfc1843-decode-string))")
1592
1593 (defvar gnus-decode-encoded-word-methods-cache nil)
1594
1595 (defun gnus-multi-decode-encoded-word-string (string)
1596   "Apply the functions from `gnus-encoded-word-methods' that match."
1597   (unless (and gnus-decode-encoded-word-methods-cache
1598                (eq gnus-newsgroup-name
1599                    (car gnus-decode-encoded-word-methods-cache)))
1600     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1601     (dolist (method gnus-decode-encoded-word-methods)
1602       (if (symbolp method)
1603           (nconc gnus-decode-encoded-word-methods-cache (list method))
1604         (if (and gnus-newsgroup-name
1605                  (string-match (car method) gnus-newsgroup-name))
1606             (nconc gnus-decode-encoded-word-methods-cache
1607                    (list (cdr method)))))))
1608   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1609     (setq string (funcall method string))))
1610
1611 ;; Subject simplification.
1612
1613 (defun gnus-simplify-whitespace (str)
1614   "Remove excessive whitespace from STR."
1615   ;; Multiple spaces.
1616   (while (string-match "[ \t][ \t]+" str)
1617     (setq str (concat (substring str 0 (match-beginning 0))
1618                         " "
1619                         (substring str (match-end 0)))))
1620   ;; Leading spaces.
1621   (when (string-match "^[ \t]+" str)
1622     (setq str (substring str (match-end 0))))
1623   ;; Trailing spaces.
1624   (when (string-match "[ \t]+$" str)
1625     (setq str (substring str 0 (match-beginning 0))))
1626   str)
1627
1628 (defun gnus-simplify-all-whitespace (str)
1629   "Remove all whitespace from STR."
1630   (while (string-match "[ \t\n]+" str)
1631     (setq str (replace-match "" nil nil str)))
1632   str)
1633
1634 (defsubst gnus-simplify-subject-re (subject)
1635   "Remove \"Re:\" from subject lines."
1636   (if (string-match message-subject-re-regexp subject)
1637       (substring subject (match-end 0))
1638     subject))
1639
1640 (defun gnus-simplify-subject (subject &optional re-only)
1641   "Remove `Re:' and words in parentheses.
1642 If RE-ONLY is non-nil, strip leading `Re:'s only."
1643   (let ((case-fold-search t))           ;Ignore case.
1644     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1645     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1646       (setq subject (substring subject (match-end 0))))
1647     ;; Remove uninteresting prefixes.
1648     (when (and (not re-only)
1649                gnus-simplify-ignored-prefixes
1650                (string-match gnus-simplify-ignored-prefixes subject))
1651       (setq subject (substring subject (match-end 0))))
1652     ;; Remove words in parentheses from end.
1653     (unless re-only
1654       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1655         (setq subject (substring subject 0 (match-beginning 0)))))
1656     ;; Return subject string.
1657     subject))
1658
1659 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1660 ;; all whitespace.
1661 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1662   (goto-char (point-min))
1663   (while (re-search-forward regexp nil t)
1664     (replace-match (or newtext ""))))
1665
1666 (defun gnus-simplify-buffer-fuzzy ()
1667   "Simplify string in the buffer fuzzily.
1668 The string in the accessible portion of the current buffer is simplified.
1669 It is assumed to be a single-line subject.
1670 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1671 matter is removed.  Additional things can be deleted by setting
1672 `gnus-simplify-subject-fuzzy-regexp'."
1673   (let ((case-fold-search t)
1674         (modified-tick))
1675     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1676
1677     (while (not (eq modified-tick (buffer-modified-tick)))
1678       (setq modified-tick (buffer-modified-tick))
1679       (cond
1680        ((listp gnus-simplify-subject-fuzzy-regexp)
1681         (mapc 'gnus-simplify-buffer-fuzzy-step
1682               gnus-simplify-subject-fuzzy-regexp))
1683        (gnus-simplify-subject-fuzzy-regexp
1684         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1685       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1686       (gnus-simplify-buffer-fuzzy-step
1687        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1688       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1689
1690     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1691     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1692     (gnus-simplify-buffer-fuzzy-step " $")
1693     (gnus-simplify-buffer-fuzzy-step "^ +")))
1694
1695 (defun gnus-simplify-subject-fuzzy (subject)
1696   "Simplify a subject string fuzzily.
1697 See `gnus-simplify-buffer-fuzzy' for details."
1698   (save-excursion
1699     (gnus-set-work-buffer)
1700     (let ((case-fold-search t))
1701       ;; Remove uninteresting prefixes.
1702       (when (and gnus-simplify-ignored-prefixes
1703                  (string-match gnus-simplify-ignored-prefixes subject))
1704         (setq subject (substring subject (match-end 0))))
1705       (insert subject)
1706       (inline (gnus-simplify-buffer-fuzzy))
1707       (buffer-string))))
1708
1709 (defsubst gnus-simplify-subject-fully (subject)
1710   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1711   (cond
1712    (gnus-simplify-subject-functions
1713     (gnus-map-function gnus-simplify-subject-functions subject))
1714    ((null gnus-summary-gather-subject-limit)
1715     (gnus-simplify-subject-re subject))
1716    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1717     (gnus-simplify-subject-fuzzy subject))
1718    ((numberp gnus-summary-gather-subject-limit)
1719     (truncate-string-to-width (gnus-simplify-subject-re subject)
1720                               gnus-summary-gather-subject-limit))
1721    (t
1722     subject)))
1723
1724 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1725   "Check whether two subjects are equal.
1726 If optional argument SIMPLE-FIRST is t, first argument is already
1727 simplified."
1728   (cond
1729    ((null simple-first)
1730     (equal (gnus-simplify-subject-fully s1)
1731            (gnus-simplify-subject-fully s2)))
1732    (t
1733     (equal s1
1734            (gnus-simplify-subject-fully s2)))))
1735
1736 (defun gnus-summary-bubble-group ()
1737   "Increase the score of the current group.
1738 This is a handy function to add to `gnus-summary-exit-hook' to
1739 increase the score of each group you read."
1740   (gnus-group-add-score gnus-newsgroup-name))
1741
1742 \f
1743 ;;;
1744 ;;; Gnus summary mode
1745 ;;;
1746
1747 (put 'gnus-summary-mode 'mode-class 'special)
1748
1749 (defvar gnus-article-commands-menu)
1750
1751 ;; Non-orthogonal keys
1752
1753 (gnus-define-keys gnus-summary-mode-map
1754   " " gnus-summary-next-page
1755   "\177" gnus-summary-prev-page
1756   [delete] gnus-summary-prev-page
1757   [backspace] gnus-summary-prev-page
1758   "\r" gnus-summary-scroll-up
1759   "\M-\r" gnus-summary-scroll-down
1760   "n" gnus-summary-next-unread-article
1761   "p" gnus-summary-prev-unread-article
1762   "N" gnus-summary-next-article
1763   "P" gnus-summary-prev-article
1764   "\M-\C-n" gnus-summary-next-same-subject
1765   "\M-\C-p" gnus-summary-prev-same-subject
1766   "\M-n" gnus-summary-next-unread-subject
1767   "\M-p" gnus-summary-prev-unread-subject
1768   "." gnus-summary-first-unread-article
1769   "," gnus-summary-best-unread-article
1770   "\M-s" gnus-summary-search-article-forward
1771   "\M-r" gnus-summary-search-article-backward
1772   "\M-S" gnus-summary-repeat-search-article-forward
1773   "\M-R" gnus-summary-repeat-search-article-backward
1774   "<" gnus-summary-beginning-of-article
1775   ">" gnus-summary-end-of-article
1776   "j" gnus-summary-goto-article
1777   "^" gnus-summary-refer-parent-article
1778   "\M-^" gnus-summary-refer-article
1779   "u" gnus-summary-tick-article-forward
1780   "!" gnus-summary-tick-article-forward
1781   "U" gnus-summary-tick-article-backward
1782   "d" gnus-summary-mark-as-read-forward
1783   "D" gnus-summary-mark-as-read-backward
1784   "E" gnus-summary-mark-as-expirable
1785   "\M-u" gnus-summary-clear-mark-forward
1786   "\M-U" gnus-summary-clear-mark-backward
1787   "k" gnus-summary-kill-same-subject-and-select
1788   "\C-k" gnus-summary-kill-same-subject
1789   "\M-\C-k" gnus-summary-kill-thread
1790   "\M-\C-l" gnus-summary-lower-thread
1791   "e" gnus-summary-edit-article
1792   "#" gnus-summary-mark-as-processable
1793   "\M-#" gnus-summary-unmark-as-processable
1794   "\M-\C-t" gnus-summary-toggle-threads
1795   "\M-\C-s" gnus-summary-show-thread
1796   "\M-\C-h" gnus-summary-hide-thread
1797   "\M-\C-f" gnus-summary-next-thread
1798   "\M-\C-b" gnus-summary-prev-thread
1799   [(meta down)] gnus-summary-next-thread
1800   [(meta up)] gnus-summary-prev-thread
1801   "\M-\C-u" gnus-summary-up-thread
1802   "\M-\C-d" gnus-summary-down-thread
1803   "&" gnus-summary-execute-command
1804   "c" gnus-summary-catchup-and-exit
1805   "\C-w" gnus-summary-mark-region-as-read
1806   "\C-t" gnus-summary-toggle-truncation
1807   "?" gnus-summary-mark-as-dormant
1808   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1809   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1810   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1811   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1812   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1813   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1814   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1815   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1816   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1817   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1818   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1819   "=" gnus-summary-expand-window
1820   "\C-x\C-s" gnus-summary-reselect-current-group
1821   "\M-g" gnus-summary-rescan-group
1822   "w" gnus-summary-stop-page-breaking
1823   "\C-c\C-r" gnus-summary-caesar-message
1824   "f" gnus-summary-followup
1825   "F" gnus-summary-followup-with-original
1826   "C" gnus-summary-cancel-article
1827   "r" gnus-summary-reply
1828   "R" gnus-summary-reply-with-original
1829   "\C-c\C-f" gnus-summary-mail-forward
1830   "o" gnus-summary-save-article
1831   "\C-o" gnus-summary-save-article-mail
1832   "|" gnus-summary-pipe-output
1833   "\M-k" gnus-summary-edit-local-kill
1834   "\M-K" gnus-summary-edit-global-kill
1835   ;; "V" gnus-version
1836   "\C-c\C-d" gnus-summary-describe-group
1837   "q" gnus-summary-exit
1838   "Q" gnus-summary-exit-no-update
1839   "\C-c\C-i" gnus-info-find-node
1840   gnus-mouse-2 gnus-mouse-pick-article
1841   [follow-link] mouse-face
1842   "m" gnus-summary-mail-other-window
1843   "a" gnus-summary-post-news
1844   "i" gnus-summary-news-other-window
1845   "x" gnus-summary-limit-to-unread
1846   "s" gnus-summary-isearch-article
1847   "t" gnus-summary-toggle-header
1848   "g" gnus-summary-show-article
1849   "l" gnus-summary-goto-last-article
1850   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1851   "\C-d" gnus-summary-enter-digest-group
1852   "\M-\C-d" gnus-summary-read-document
1853   "\M-\C-e" gnus-summary-edit-parameters
1854   "\M-\C-a" gnus-summary-customize-parameters
1855   "\C-c\C-b" gnus-bug
1856   "*" gnus-cache-enter-article
1857   "\M-*" gnus-cache-remove-article
1858   "\M-&" gnus-summary-universal-argument
1859   "\C-l" gnus-recenter
1860   "I" gnus-summary-increase-score
1861   "L" gnus-summary-lower-score
1862   "\M-i" gnus-symbolic-argument
1863   "h" gnus-summary-select-article-buffer
1864
1865   "b" gnus-article-view-part
1866   "\M-t" gnus-summary-toggle-display-buttonized
1867
1868   "V" gnus-summary-score-map
1869   "X" gnus-uu-extract-map
1870   "S" gnus-summary-send-map)
1871
1872 ;; Sort of orthogonal keymap
1873 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1874   "t" gnus-summary-tick-article-forward
1875   "!" gnus-summary-tick-article-forward
1876   "d" gnus-summary-mark-as-read-forward
1877   "r" gnus-summary-mark-as-read-forward
1878   "c" gnus-summary-clear-mark-forward
1879   " " gnus-summary-clear-mark-forward
1880   "e" gnus-summary-mark-as-expirable
1881   "x" gnus-summary-mark-as-expirable
1882   "?" gnus-summary-mark-as-dormant
1883   "b" gnus-summary-set-bookmark
1884   "B" gnus-summary-remove-bookmark
1885   "#" gnus-summary-mark-as-processable
1886   "\M-#" gnus-summary-unmark-as-processable
1887   "S" gnus-summary-limit-include-expunged
1888   "C" gnus-summary-catchup
1889   "H" gnus-summary-catchup-to-here
1890   "h" gnus-summary-catchup-from-here
1891   "\C-c" gnus-summary-catchup-all
1892   "k" gnus-summary-kill-same-subject-and-select
1893   "K" gnus-summary-kill-same-subject
1894   "P" gnus-uu-mark-map)
1895
1896 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1897   "c" gnus-summary-clear-above
1898   "u" gnus-summary-tick-above
1899   "m" gnus-summary-mark-above
1900   "k" gnus-summary-kill-below)
1901
1902 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1903   "/" gnus-summary-limit-to-subject
1904   "n" gnus-summary-limit-to-articles
1905   "b" gnus-summary-limit-to-bodies
1906   "h" gnus-summary-limit-to-headers
1907   "w" gnus-summary-pop-limit
1908   "s" gnus-summary-limit-to-subject
1909   "a" gnus-summary-limit-to-author
1910   "u" gnus-summary-limit-to-unread
1911   "m" gnus-summary-limit-to-marks
1912   "M" gnus-summary-limit-exclude-marks
1913   "v" gnus-summary-limit-to-score
1914   "*" gnus-summary-limit-include-cached
1915   "D" gnus-summary-limit-include-dormant
1916   "T" gnus-summary-limit-include-thread
1917   "d" gnus-summary-limit-exclude-dormant
1918   "t" gnus-summary-limit-to-age
1919   "." gnus-summary-limit-to-unseen
1920   "x" gnus-summary-limit-to-extra
1921   "p" gnus-summary-limit-to-display-predicate
1922   "E" gnus-summary-limit-include-expunged
1923   "c" gnus-summary-limit-exclude-childless-dormant
1924   "C" gnus-summary-limit-mark-excluded-as-read
1925   "o" gnus-summary-insert-old-articles
1926   "N" gnus-summary-insert-new-articles
1927   "S" gnus-summary-limit-to-singletons
1928   "r" gnus-summary-limit-to-replied
1929   "R" gnus-summary-limit-to-recipient
1930   "A" gnus-summary-limit-to-address)
1931
1932 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1933   "n" gnus-summary-next-unread-article
1934   "p" gnus-summary-prev-unread-article
1935   "N" gnus-summary-next-article
1936   "P" gnus-summary-prev-article
1937   "\C-n" gnus-summary-next-same-subject
1938   "\C-p" gnus-summary-prev-same-subject
1939   "\M-n" gnus-summary-next-unread-subject
1940   "\M-p" gnus-summary-prev-unread-subject
1941   "f" gnus-summary-first-unread-article
1942   "b" gnus-summary-best-unread-article
1943   "j" gnus-summary-goto-article
1944   "g" gnus-summary-goto-subject
1945   "l" gnus-summary-goto-last-article
1946   "o" gnus-summary-pop-article)
1947
1948 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1949   "k" gnus-summary-kill-thread
1950   "E" gnus-summary-expire-thread
1951   "l" gnus-summary-lower-thread
1952   "i" gnus-summary-raise-thread
1953   "T" gnus-summary-toggle-threads
1954   "t" gnus-summary-rethread-current
1955   "^" gnus-summary-reparent-thread
1956   "\M-^" gnus-summary-reparent-children
1957   "s" gnus-summary-show-thread
1958   "S" gnus-summary-show-all-threads
1959   "h" gnus-summary-hide-thread
1960   "H" gnus-summary-hide-all-threads
1961   "n" gnus-summary-next-thread
1962   "p" gnus-summary-prev-thread
1963   "u" gnus-summary-up-thread
1964   "o" gnus-summary-top-thread
1965   "d" gnus-summary-down-thread
1966   "#" gnus-uu-mark-thread
1967   "\M-#" gnus-uu-unmark-thread)
1968
1969 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1970   "g" gnus-summary-prepare
1971   "c" gnus-summary-insert-cached-articles
1972   "d" gnus-summary-insert-dormant-articles
1973   "t" gnus-summary-insert-ticked-articles)
1974
1975 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1976   "c" gnus-summary-catchup-and-exit
1977   "C" gnus-summary-catchup-all-and-exit
1978   "E" gnus-summary-exit-no-update
1979   "Q" gnus-summary-exit
1980   "Z" gnus-summary-exit
1981   "n" gnus-summary-catchup-and-goto-next-group
1982   "p" gnus-summary-catchup-and-goto-prev-group
1983   "R" gnus-summary-reselect-current-group
1984   "G" gnus-summary-rescan-group
1985   "N" gnus-summary-next-group
1986   "s" gnus-summary-save-newsrc
1987   "P" gnus-summary-prev-group)
1988
1989 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1990   " " gnus-summary-next-page
1991   "n" gnus-summary-next-page
1992   "\177" gnus-summary-prev-page
1993   [delete] gnus-summary-prev-page
1994   "p" gnus-summary-prev-page
1995   "\r" gnus-summary-scroll-up
1996   "\M-\r" gnus-summary-scroll-down
1997   "<" gnus-summary-beginning-of-article
1998   ">" gnus-summary-end-of-article
1999   "b" gnus-summary-beginning-of-article
2000   "e" gnus-summary-end-of-article
2001   "^" gnus-summary-refer-parent-article
2002   "r" gnus-summary-refer-parent-article
2003   "D" gnus-summary-enter-digest-group
2004   "R" gnus-summary-refer-references
2005   "T" gnus-summary-refer-thread
2006   "g" gnus-summary-show-article
2007   "s" gnus-summary-isearch-article
2008   "P" gnus-summary-print-article
2009   "S" gnus-sticky-article
2010   "M" gnus-mailing-list-insinuate
2011   "t" gnus-article-babel)
2012
2013 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2014   "b" gnus-article-add-buttons
2015   "B" gnus-article-add-buttons-to-head
2016   "o" gnus-article-treat-overstrike
2017   "e" gnus-article-emphasize
2018   "w" gnus-article-fill-cited-article
2019   "Q" gnus-article-fill-long-lines
2020   "L" gnus-article-toggle-truncate-lines
2021   "C" gnus-article-capitalize-sentences
2022   "c" gnus-article-remove-cr
2023   "q" gnus-article-de-quoted-unreadable
2024   "6" gnus-article-de-base64-unreadable
2025   "Z" gnus-article-decode-HZ
2026   "A" gnus-article-treat-ansi-sequences
2027   "h" gnus-article-wash-html
2028   "u" gnus-article-unsplit-urls
2029   "s" gnus-summary-force-verify-and-decrypt
2030   "f" gnus-article-display-x-face
2031   "l" gnus-summary-stop-page-breaking
2032   "r" gnus-summary-caesar-message
2033   "m" gnus-summary-morse-message
2034   "t" gnus-summary-toggle-header
2035   "g" gnus-treat-smiley
2036   "v" gnus-summary-verbose-headers
2037   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2038   "p" gnus-article-verify-x-pgp-sig
2039   "d" gnus-article-treat-dumbquotes
2040   "i" gnus-summary-idna-message)
2041
2042 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2043   ;; mnemonic: deuglif*Y*
2044   "u" gnus-article-outlook-unwrap-lines
2045   "a" gnus-article-outlook-repair-attribution
2046   "c" gnus-article-outlook-rearrange-citation
2047   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2048
2049 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2050   "a" gnus-article-hide
2051   "h" gnus-article-hide-headers
2052   "b" gnus-article-hide-boring-headers
2053   "s" gnus-article-hide-signature
2054   "c" gnus-article-hide-citation
2055   "C" gnus-article-hide-citation-in-followups
2056   "l" gnus-article-hide-list-identifiers
2057   "B" gnus-article-strip-banner
2058   "P" gnus-article-hide-pem
2059   "\C-c" gnus-article-hide-citation-maybe)
2060
2061 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2062   "a" gnus-article-highlight
2063   "h" gnus-article-highlight-headers
2064   "c" gnus-article-highlight-citation
2065   "s" gnus-article-highlight-signature)
2066
2067 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2068   "f" gnus-article-treat-fold-headers
2069   "u" gnus-article-treat-unfold-headers
2070   "n" gnus-article-treat-fold-newsgroups)
2071
2072 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2073   "x" gnus-article-display-x-face
2074   "d" gnus-article-display-face
2075   "s" gnus-treat-smiley
2076   "D" gnus-article-remove-images
2077   "f" gnus-treat-from-picon
2078   "m" gnus-treat-mail-picon
2079   "n" gnus-treat-newsgroups-picon)
2080
2081 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2082   "w" gnus-article-decode-mime-words
2083   "c" gnus-article-decode-charset
2084   "v" gnus-mime-view-all-parts
2085   "b" gnus-article-view-part)
2086
2087 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2088   "z" gnus-article-date-ut
2089   "u" gnus-article-date-ut
2090   "l" gnus-article-date-local
2091   "p" gnus-article-date-english
2092   "e" gnus-article-date-lapsed
2093   "o" gnus-article-date-original
2094   "i" gnus-article-date-iso8601
2095   "s" gnus-article-date-user)
2096
2097 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2098   "t" gnus-article-remove-trailing-blank-lines
2099   "l" gnus-article-strip-leading-blank-lines
2100   "m" gnus-article-strip-multiple-blank-lines
2101   "a" gnus-article-strip-blank-lines
2102   "A" gnus-article-strip-all-blank-lines
2103   "s" gnus-article-strip-leading-space
2104   "e" gnus-article-strip-trailing-space
2105   "w" gnus-article-remove-leading-whitespace)
2106
2107 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2108   "v" gnus-version
2109   "f" gnus-summary-fetch-faq
2110   "d" gnus-summary-describe-group
2111   "h" gnus-summary-describe-briefly
2112   "i" gnus-info-find-node
2113   "c" gnus-group-fetch-charter
2114   "C" gnus-group-fetch-control)
2115
2116 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2117   "e" gnus-summary-expire-articles
2118   "\M-\C-e" gnus-summary-expire-articles-now
2119   "\177" gnus-summary-delete-article
2120   [delete] gnus-summary-delete-article
2121   [backspace] gnus-summary-delete-article
2122   "m" gnus-summary-move-article
2123   "r" gnus-summary-respool-article
2124   "w" gnus-summary-edit-article
2125   "c" gnus-summary-copy-article
2126   "B" gnus-summary-crosspost-article
2127   "q" gnus-summary-respool-query
2128   "t" gnus-summary-respool-trace
2129   "i" gnus-summary-import-article
2130   "I" gnus-summary-create-article
2131   "p" gnus-summary-article-posted-p)
2132
2133 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2134   "o" gnus-summary-save-article
2135   "m" gnus-summary-save-article-mail
2136   "F" gnus-summary-write-article-file
2137   "r" gnus-summary-save-article-rmail
2138   "f" gnus-summary-save-article-file
2139   "b" gnus-summary-save-article-body-file
2140   "B" gnus-summary-write-article-body-file
2141   "h" gnus-summary-save-article-folder
2142   "v" gnus-summary-save-article-vm
2143   "p" gnus-summary-pipe-output
2144   "P" gnus-summary-muttprint
2145   "s" gnus-soup-add-article)
2146
2147 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2148   "b" gnus-summary-display-buttonized
2149   "m" gnus-summary-repair-multipart
2150   "v" gnus-article-view-part
2151   "o" gnus-article-save-part
2152   "O" gnus-article-save-part-and-strip
2153   "r" gnus-article-replace-part
2154   "d" gnus-article-delete-part
2155   "t" gnus-article-view-part-as-type
2156   "j" gnus-article-jump-to-part
2157   "c" gnus-article-copy-part
2158   "C" gnus-article-view-part-as-charset
2159   "e" gnus-article-view-part-externally
2160   "H" gnus-article-browse-html-article
2161   "E" gnus-article-encrypt-body
2162   "i" gnus-article-inline-part
2163   "|" gnus-article-pipe-part)
2164
2165 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2166   "p" gnus-summary-mark-as-processable
2167   "u" gnus-summary-unmark-as-processable
2168   "U" gnus-summary-unmark-all-processable
2169   "v" gnus-uu-mark-over
2170   "s" gnus-uu-mark-series
2171   "r" gnus-uu-mark-region
2172   "g" gnus-uu-unmark-region
2173   "R" gnus-uu-mark-by-regexp
2174   "G" gnus-uu-unmark-by-regexp
2175   "t" gnus-uu-mark-thread
2176   "T" gnus-uu-unmark-thread
2177   "a" gnus-uu-mark-all
2178   "b" gnus-uu-mark-buffer
2179   "S" gnus-uu-mark-sparse
2180   "k" gnus-summary-kill-process-mark
2181   "y" gnus-summary-yank-process-mark
2182   "w" gnus-summary-save-process-mark
2183   "i" gnus-uu-invert-processable)
2184
2185 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2186   ;;"x" gnus-uu-extract-any
2187   "m" gnus-summary-save-parts
2188   "u" gnus-uu-decode-uu
2189   "U" gnus-uu-decode-uu-and-save
2190   "s" gnus-uu-decode-unshar
2191   "S" gnus-uu-decode-unshar-and-save
2192   "o" gnus-uu-decode-save
2193   "O" gnus-uu-decode-save
2194   "b" gnus-uu-decode-binhex
2195   "B" gnus-uu-decode-binhex
2196   "p" gnus-uu-decode-postscript
2197   "P" gnus-uu-decode-postscript-and-save)
2198
2199 (gnus-define-keys
2200     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2201   "u" gnus-uu-decode-uu-view
2202   "U" gnus-uu-decode-uu-and-save-view
2203   "s" gnus-uu-decode-unshar-view
2204   "S" gnus-uu-decode-unshar-and-save-view
2205   "o" gnus-uu-decode-save-view
2206   "O" gnus-uu-decode-save-view
2207   "b" gnus-uu-decode-binhex-view
2208   "B" gnus-uu-decode-binhex-view
2209   "p" gnus-uu-decode-postscript-view
2210   "P" gnus-uu-decode-postscript-and-save-view)
2211
2212 (defvar gnus-article-post-menu nil)
2213
2214 (defconst gnus-summary-menu-maxlen 20)
2215
2216 (defun gnus-summary-menu-split (menu)
2217   ;; If we have lots of elements, divide them into groups of 20
2218   ;; and make a pane (or submenu) for each one.
2219   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2220       (let ((menu menu) sublists next
2221             (i 1))
2222         (while menu
2223           ;; Pull off the next gnus-summary-menu-maxlen elements
2224           ;; and make them the next element of sublist.
2225           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2226           (if next
2227               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2228                       nil))
2229           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2230                                              (aref (car (last menu)) 0)) menu)
2231                                sublists))
2232           (setq i (1+ i))
2233           (setq menu next))
2234         (nreverse sublists))
2235     ;; Few elements--put them all in one pane.
2236     menu))
2237
2238 (defun gnus-summary-make-menu-bar ()
2239   (gnus-turn-off-edit-menu 'summary)
2240
2241   (unless (boundp 'gnus-summary-misc-menu)
2242
2243     (easy-menu-define
2244       gnus-summary-kill-menu gnus-summary-mode-map ""
2245       (cons
2246        "Score"
2247        (nconc
2248         (list
2249          ["Customize" gnus-score-customize t])
2250         (gnus-make-score-map 'increase)
2251         (gnus-make-score-map 'lower)
2252         '(("Mark"
2253            ["Kill below" gnus-summary-kill-below t]
2254            ["Mark above" gnus-summary-mark-above t]
2255            ["Tick above" gnus-summary-tick-above t]
2256            ["Clear above" gnus-summary-clear-above t])
2257           ["Current score" gnus-summary-current-score t]
2258           ["Set score" gnus-summary-set-score t]
2259           ["Switch current score file..." gnus-score-change-score-file t]
2260           ["Set mark below..." gnus-score-set-mark-below t]
2261           ["Set expunge below..." gnus-score-set-expunge-below t]
2262           ["Edit current score file" gnus-score-edit-current-scores t]
2263           ["Edit score file" gnus-score-edit-file t]
2264           ["Trace score" gnus-score-find-trace t]
2265           ["Find words" gnus-score-find-favourite-words t]
2266           ["Rescore buffer" gnus-summary-rescore t]
2267           ["Increase score..." gnus-summary-increase-score t]
2268           ["Lower score..." gnus-summary-lower-score t]))))
2269
2270     ;; Define both the Article menu in the summary buffer and the
2271     ;; equivalent Commands menu in the article buffer here for
2272     ;; consistency.
2273     (let ((innards
2274            `(("Hide"
2275               ["All" gnus-article-hide t]
2276               ["Headers" gnus-article-hide-headers t]
2277               ["Signature" gnus-article-hide-signature t]
2278               ["Citation" gnus-article-hide-citation t]
2279               ["List identifiers" gnus-article-hide-list-identifiers t]
2280               ["Banner" gnus-article-strip-banner t]
2281               ["Boring headers" gnus-article-hide-boring-headers t])
2282              ("Highlight"
2283               ["All" gnus-article-highlight t]
2284               ["Headers" gnus-article-highlight-headers t]
2285               ["Signature" gnus-article-highlight-signature t]
2286               ["Citation" gnus-article-highlight-citation t])
2287              ("MIME"
2288               ["Words" gnus-article-decode-mime-words t]
2289               ["Charset" gnus-article-decode-charset t]
2290               ["QP" gnus-article-de-quoted-unreadable t]
2291               ["Base64" gnus-article-de-base64-unreadable t]
2292               ["View MIME buttons" gnus-summary-display-buttonized t]
2293               ["View all" gnus-mime-view-all-parts t]
2294               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2295               ["Encrypt body" gnus-article-encrypt-body
2296                :active (not (gnus-group-read-only-p))
2297                ,@(if (featurep 'xemacs) nil
2298                    '(:help "Encrypt the message body on disk"))]
2299               ["Extract all parts..." gnus-summary-save-parts t]
2300               ("Multipart"
2301                ["Repair multipart" gnus-summary-repair-multipart t]
2302                ["Pipe part..." gnus-article-pipe-part t]
2303                ["Inline part" gnus-article-inline-part t]
2304                ["View part as type..." gnus-article-view-part-as-type t]
2305                ["Encrypt body" gnus-article-encrypt-body
2306                 :active (not (gnus-group-read-only-p))
2307                ,@(if (featurep 'xemacs) nil
2308                    '(:help "Encrypt the message body on disk"))]
2309                ["View part externally" gnus-article-view-part-externally t]
2310                ["View HTML parts in browser" gnus-article-browse-html-article t]
2311                ["View part with charset..." gnus-article-view-part-as-charset t]
2312                ["Copy part" gnus-article-copy-part t]
2313                ["Save part..." gnus-article-save-part t]
2314                ["View part" gnus-article-view-part t]))
2315              ("Date"
2316               ["Local" gnus-article-date-local t]
2317               ["ISO8601" gnus-article-date-iso8601 t]
2318               ["UT" gnus-article-date-ut t]
2319               ["Original" gnus-article-date-original t]
2320               ["Lapsed" gnus-article-date-lapsed t]
2321               ["User-defined" gnus-article-date-user t])
2322              ("Display"
2323               ["Remove images" gnus-article-remove-images t]
2324               ["Toggle smiley" gnus-treat-smiley t]
2325               ["Show X-Face" gnus-article-display-x-face t]
2326               ["Show picons in From" gnus-treat-from-picon t]
2327               ["Show picons in mail headers" gnus-treat-mail-picon t]
2328               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2329               ("View as different encoding"
2330                ,@(gnus-summary-menu-split
2331                   (mapcar
2332                    (lambda (cs)
2333                      ;; Since easymenu under Emacs doesn't allow
2334                      ;; lambda forms for menu commands, we should
2335                      ;; provide intern'ed function symbols.
2336                      (let ((command (intern (format "\
2337 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2338                        (fset command
2339                              `(lambda ()
2340                                 (interactive)
2341                                 (let ((gnus-summary-show-article-charset-alist
2342                                        '((1 . ,cs))))
2343                                   (gnus-summary-show-article 1))))
2344                        `[,(symbol-name cs) ,command t]))
2345                    (sort (if (fboundp 'coding-system-list)
2346                              (coding-system-list)
2347                            (mapcar 'car mm-mime-mule-charset-alist))
2348                          'string<)))))
2349              ("Washing"
2350               ("Remove Blanks"
2351                ["Leading" gnus-article-strip-leading-blank-lines t]
2352                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2353                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2354                ["All of the above" gnus-article-strip-blank-lines t]
2355                ["All" gnus-article-strip-all-blank-lines t]
2356                ["Leading space" gnus-article-strip-leading-space t]
2357                ["Trailing space" gnus-article-strip-trailing-space t]
2358                ["Leading space in headers"
2359                 gnus-article-remove-leading-whitespace t])
2360               ["Overstrike" gnus-article-treat-overstrike t]
2361               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2362               ["Emphasis" gnus-article-emphasize t]
2363               ["Word wrap" gnus-article-fill-cited-article t]
2364               ["Fill long lines" gnus-article-fill-long-lines t]
2365               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2366               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2367               ["Remove CR" gnus-article-remove-cr t]
2368               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2369               ["Base64" gnus-article-de-base64-unreadable t]
2370               ["Rot 13" gnus-summary-caesar-message
2371                ,@(if (featurep 'xemacs) '(t)
2372                    '(:help "\"Caesar rotate\" article by 13"))]
2373               ["De-IDNA" gnus-summary-idna-message t]
2374               ["Morse decode" gnus-summary-morse-message t]
2375               ["Unix pipe..." gnus-summary-pipe-message t]
2376               ["Add buttons" gnus-article-add-buttons t]
2377               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2378               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2379               ["Verbose header" gnus-summary-verbose-headers t]
2380               ["Toggle header" gnus-summary-toggle-header t]
2381               ["Unfold headers" gnus-article-treat-unfold-headers t]
2382               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2383               ["Html" gnus-article-wash-html t]
2384               ["Unsplit URLs" gnus-article-unsplit-urls t]
2385               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2386               ["Decode HZ" gnus-article-decode-HZ t]
2387               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2388               ("(Outlook) Deuglify"
2389                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2390                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2391                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2392                ["Full (Outlook) deuglify"
2393                 gnus-article-outlook-deuglify-article t])
2394               )
2395              ("Output"
2396               ["Save in default format..." gnus-summary-save-article
2397                ,@(if (featurep 'xemacs) '(t)
2398                    '(:help "Save article using default method"))]
2399               ["Save in file..." gnus-summary-save-article-file
2400                ,@(if (featurep 'xemacs) '(t)
2401                    '(:help "Save article in file"))]
2402               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2403               ["Save in MH folder..." gnus-summary-save-article-folder t]
2404               ["Save in VM folder..." gnus-summary-save-article-vm t]
2405               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2406               ["Save body in file..." gnus-summary-save-article-body-file t]
2407               ["Pipe through a filter..." gnus-summary-pipe-output t]
2408               ["Add to SOUP packet" gnus-soup-add-article t]
2409               ["Print with Muttprint..." gnus-summary-muttprint t]
2410               ["Print" gnus-summary-print-article
2411                ,@(if (featurep 'xemacs) '(t)
2412                    '(:help "Generate and print a PostScript image"))])
2413              ("Copy, move,... (Backend)"
2414               ,@(if (featurep 'xemacs) nil
2415                   '(:help "Copying, moving, expiring articles..."))
2416               ["Respool article..." gnus-summary-respool-article t]
2417               ["Move article..." gnus-summary-move-article
2418                (gnus-check-backend-function
2419                 'request-move-article gnus-newsgroup-name)]
2420               ["Copy article..." gnus-summary-copy-article t]
2421               ["Crosspost article..." gnus-summary-crosspost-article
2422                (gnus-check-backend-function
2423                 'request-replace-article gnus-newsgroup-name)]
2424               ["Import file..." gnus-summary-import-article
2425                (gnus-check-backend-function
2426                 'request-accept-article gnus-newsgroup-name)]
2427               ["Create article..." gnus-summary-create-article
2428                (gnus-check-backend-function
2429                 'request-accept-article gnus-newsgroup-name)]
2430               ["Check if posted" gnus-summary-article-posted-p t]
2431               ["Edit article" gnus-summary-edit-article
2432                (not (gnus-group-read-only-p))]
2433               ["Delete article" gnus-summary-delete-article
2434                (gnus-check-backend-function
2435                 'request-expire-articles gnus-newsgroup-name)]
2436               ["Query respool" gnus-summary-respool-query t]
2437               ["Trace respool" gnus-summary-respool-trace t]
2438               ["Delete expirable articles" gnus-summary-expire-articles-now
2439                (gnus-check-backend-function
2440                 'request-expire-articles gnus-newsgroup-name)])
2441              ("Extract"
2442               ["Uudecode" gnus-uu-decode-uu
2443                ,@(if (featurep 'xemacs) '(t)
2444                    '(:help "Decode uuencoded article(s)"))]
2445               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2446               ["Unshar" gnus-uu-decode-unshar t]
2447               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2448               ["Save" gnus-uu-decode-save t]
2449               ["Binhex" gnus-uu-decode-binhex t]
2450               ["Postscript" gnus-uu-decode-postscript t]
2451               ["All MIME parts" gnus-summary-save-parts t])
2452              ("Cache"
2453               ["Enter article" gnus-cache-enter-article t]
2454               ["Remove article" gnus-cache-remove-article t])
2455              ["Translate" gnus-article-babel t]
2456              ["Select article buffer" gnus-summary-select-article-buffer t]
2457              ["Make article buffer sticky" gnus-sticky-article t]
2458              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2459              ["Isearch article..." gnus-summary-isearch-article t]
2460              ["Beginning of the article" gnus-summary-beginning-of-article t]
2461              ["End of the article" gnus-summary-end-of-article t]
2462              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2463              ["Fetch referenced articles" gnus-summary-refer-references t]
2464              ["Fetch current thread" gnus-summary-refer-thread t]
2465              ["Fetch article with id..." gnus-summary-refer-article t]
2466              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2467              ["Redisplay" gnus-summary-show-article t]
2468              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2469       (easy-menu-define
2470         gnus-summary-article-menu gnus-summary-mode-map ""
2471         (cons "Article" innards))
2472
2473       (if (not (keymapp gnus-summary-article-menu))
2474           (easy-menu-define
2475             gnus-article-commands-menu gnus-article-mode-map ""
2476             (cons "Commands" innards))
2477         ;; in Emacs, don't share menu.
2478         (setq gnus-article-commands-menu
2479               (copy-keymap gnus-summary-article-menu))
2480         (define-key gnus-article-mode-map [menu-bar commands]
2481           (cons "Commands" gnus-article-commands-menu))))
2482
2483     (easy-menu-define
2484       gnus-summary-thread-menu gnus-summary-mode-map ""
2485       '("Threads"
2486         ["Find all messages in thread" gnus-summary-refer-thread t]
2487         ["Toggle threading" gnus-summary-toggle-threads t]
2488         ["Hide threads" gnus-summary-hide-all-threads t]
2489         ["Show threads" gnus-summary-show-all-threads t]
2490         ["Hide thread" gnus-summary-hide-thread t]
2491         ["Show thread" gnus-summary-show-thread t]
2492         ["Go to next thread" gnus-summary-next-thread t]
2493         ["Go to previous thread" gnus-summary-prev-thread t]
2494         ["Go down thread" gnus-summary-down-thread t]
2495         ["Go up thread" gnus-summary-up-thread t]
2496         ["Top of thread" gnus-summary-top-thread t]
2497         ["Mark thread as read" gnus-summary-kill-thread t]
2498         ["Mark thread as expired" gnus-summary-expire-thread t]
2499         ["Lower thread score" gnus-summary-lower-thread t]
2500         ["Raise thread score" gnus-summary-raise-thread t]
2501         ["Rethread current" gnus-summary-rethread-current t]))
2502
2503     (easy-menu-define
2504       gnus-summary-post-menu gnus-summary-mode-map ""
2505       `("Post"
2506         ["Send a message (mail or news)" gnus-summary-post-news
2507          ,@(if (featurep 'xemacs) '(t)
2508              '(:help "Compose a new message (mail or news)"))]
2509         ["Followup" gnus-summary-followup
2510          ,@(if (featurep 'xemacs) '(t)
2511              '(:help "Post followup to this article"))]
2512         ["Followup and yank" gnus-summary-followup-with-original
2513          ,@(if (featurep 'xemacs) '(t)
2514              '(:help "Post followup to this article, quoting its contents"))]
2515         ["Supersede article" gnus-summary-supersede-article t]
2516         ["Cancel article" gnus-summary-cancel-article
2517          ,@(if (featurep 'xemacs) '(t)
2518              '(:help "Cancel an article you posted"))]
2519         ["Reply" gnus-summary-reply t]
2520         ["Reply and yank" gnus-summary-reply-with-original t]
2521         ["Wide reply" gnus-summary-wide-reply t]
2522         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2523          ,@(if (featurep 'xemacs) '(t)
2524              '(:help "Mail a reply, quoting this article"))]
2525         ["Very wide reply" gnus-summary-very-wide-reply t]
2526         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2527          ,@(if (featurep 'xemacs) '(t)
2528              '(:help "Mail a very wide reply, quoting this article"))]
2529         ["Mail forward" gnus-summary-mail-forward t]
2530         ["Post forward" gnus-summary-post-forward t]
2531         ["Digest and mail" gnus-uu-digest-mail-forward t]
2532         ["Digest and post" gnus-uu-digest-post-forward t]
2533         ["Resend message" gnus-summary-resend-message t]
2534         ["Resend message edit" gnus-summary-resend-message-edit t]
2535         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2536         ["Send a mail" gnus-summary-mail-other-window t]
2537         ["Create a local message" gnus-summary-news-other-window t]
2538         ["Uuencode and post" gnus-uu-post-news
2539          ,@(if (featurep 'xemacs) '(t)
2540              '(:help "Post a uuencoded article"))]
2541         ["Followup via news" gnus-summary-followup-to-mail t]
2542         ["Followup via news and yank"
2543          gnus-summary-followup-to-mail-with-original t]
2544         ;;("Draft"
2545         ;;["Send" gnus-summary-send-draft t]
2546         ;;["Send bounced" gnus-resend-bounced-mail t])
2547         ))
2548
2549     (cond
2550      ((not (keymapp gnus-summary-post-menu))
2551       (setq gnus-article-post-menu gnus-summary-post-menu))
2552      ((not gnus-article-post-menu)
2553       ;; Don't share post menu.
2554       (setq gnus-article-post-menu
2555             (copy-keymap gnus-summary-post-menu))))
2556     (define-key gnus-article-mode-map [menu-bar post]
2557       (cons "Post" gnus-article-post-menu))
2558
2559     (easy-menu-define
2560       gnus-summary-misc-menu gnus-summary-mode-map ""
2561       `("Gnus"
2562         ("Mark Read"
2563          ["Mark as read" gnus-summary-mark-as-read-forward t]
2564          ["Mark same subject and select"
2565           gnus-summary-kill-same-subject-and-select t]
2566          ["Mark same subject" gnus-summary-kill-same-subject t]
2567          ["Catchup" gnus-summary-catchup
2568           ,@(if (featurep 'xemacs) '(t)
2569               '(:help "Mark unread articles in this group as read"))]
2570          ["Catchup all" gnus-summary-catchup-all t]
2571          ["Catchup to here" gnus-summary-catchup-to-here t]
2572          ["Catchup from here" gnus-summary-catchup-from-here t]
2573          ["Catchup region" gnus-summary-mark-region-as-read
2574           (gnus-mark-active-p)]
2575          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2576         ("Mark Various"
2577          ["Tick" gnus-summary-tick-article-forward t]
2578          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2579          ["Remove marks" gnus-summary-clear-mark-forward t]
2580          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2581          ["Set bookmark" gnus-summary-set-bookmark t]
2582          ["Remove bookmark" gnus-summary-remove-bookmark t])
2583         ("Limit to"
2584          ["Marks..." gnus-summary-limit-to-marks t]
2585          ["Subject..." gnus-summary-limit-to-subject t]
2586          ["Author..." gnus-summary-limit-to-author t]
2587          ["Recipient..." gnus-summary-limit-to-recipient t]
2588          ["Address..." gnus-summary-limit-to-address t]
2589          ["Age..." gnus-summary-limit-to-age t]
2590          ["Extra..." gnus-summary-limit-to-extra t]
2591          ["Score..." gnus-summary-limit-to-score t]
2592          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2593          ["Unread" gnus-summary-limit-to-unread t]
2594          ["Unseen" gnus-summary-limit-to-unseen t]
2595          ["Singletons" gnus-summary-limit-to-singletons t]
2596          ["Replied" gnus-summary-limit-to-replied t]
2597          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2598          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2599          ["Pop limit" gnus-summary-pop-limit t]
2600          ["Show dormant" gnus-summary-limit-include-dormant t]
2601          ["Hide childless dormant"
2602           gnus-summary-limit-exclude-childless-dormant t]
2603          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2604          ["Hide marked" gnus-summary-limit-exclude-marks t]
2605          ["Show expunged" gnus-summary-limit-include-expunged t])
2606         ("Process Mark"
2607          ["Set mark" gnus-summary-mark-as-processable t]
2608          ["Remove mark" gnus-summary-unmark-as-processable t]
2609          ["Remove all marks" gnus-summary-unmark-all-processable t]
2610          ["Invert marks" gnus-uu-invert-processable t]
2611          ["Mark above" gnus-uu-mark-over t]
2612          ["Mark series" gnus-uu-mark-series t]
2613          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2614          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2615          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2616          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2617          ["Mark all" gnus-uu-mark-all t]
2618          ["Mark buffer" gnus-uu-mark-buffer t]
2619          ["Mark sparse" gnus-uu-mark-sparse t]
2620          ["Mark thread" gnus-uu-mark-thread t]
2621          ["Unmark thread" gnus-uu-unmark-thread t]
2622          ("Process Mark Sets"
2623           ["Kill" gnus-summary-kill-process-mark t]
2624           ["Yank" gnus-summary-yank-process-mark
2625            gnus-newsgroup-process-stack]
2626           ["Save" gnus-summary-save-process-mark t]
2627           ["Run command on marked..." gnus-summary-universal-argument t]))
2628         ("Scroll article"
2629          ["Page forward" gnus-summary-next-page
2630           ,@(if (featurep 'xemacs) '(t)
2631               '(:help "Show next page of article"))]
2632          ["Page backward" gnus-summary-prev-page
2633           ,@(if (featurep 'xemacs) '(t)
2634               '(:help "Show previous page of article"))]
2635          ["Line forward" gnus-summary-scroll-up t])
2636         ("Move"
2637          ["Next unread article" gnus-summary-next-unread-article t]
2638          ["Previous unread article" gnus-summary-prev-unread-article t]
2639          ["Next article" gnus-summary-next-article t]
2640          ["Previous article" gnus-summary-prev-article t]
2641          ["Next unread subject" gnus-summary-next-unread-subject t]
2642          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2643          ["Next article same subject" gnus-summary-next-same-subject t]
2644          ["Previous article same subject" gnus-summary-prev-same-subject t]
2645          ["First unread article" gnus-summary-first-unread-article t]
2646          ["Best unread article" gnus-summary-best-unread-article t]
2647          ["Go to subject number..." gnus-summary-goto-subject t]
2648          ["Go to article number..." gnus-summary-goto-article t]
2649          ["Go to the last article" gnus-summary-goto-last-article t]
2650          ["Pop article off history" gnus-summary-pop-article t])
2651         ("Sort"
2652          ["Sort by number" gnus-summary-sort-by-number t]
2653          ["Sort by author" gnus-summary-sort-by-author t]
2654          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2655          ["Sort by subject" gnus-summary-sort-by-subject t]
2656          ["Sort by date" gnus-summary-sort-by-date t]
2657          ["Sort by score" gnus-summary-sort-by-score t]
2658          ["Sort by lines" gnus-summary-sort-by-lines t]
2659          ["Sort by characters" gnus-summary-sort-by-chars t]
2660          ["Randomize" gnus-summary-sort-by-random t]
2661          ["Original sort" gnus-summary-sort-by-original t])
2662         ("Help"
2663          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2664          ["Describe group" gnus-summary-describe-group t]
2665          ["Fetch charter" gnus-group-fetch-charter
2666           ,@(if (featurep 'xemacs) nil
2667               '(:help "Display the charter of the current group"))]
2668          ["Fetch control message" gnus-group-fetch-control
2669           ,@(if (featurep 'xemacs) nil
2670               '(:help "Display the archived control message for the current group"))]
2671          ["Read manual" gnus-info-find-node t])
2672         ("Modes"
2673          ["Pick and read" gnus-pick-mode t]
2674          ["Binary" gnus-binary-mode t])
2675         ("Regeneration"
2676          ["Regenerate" gnus-summary-prepare t]
2677          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2678          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2679          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2680          ["Toggle threading" gnus-summary-toggle-threads t])
2681         ["See old articles" gnus-summary-insert-old-articles t]
2682         ["See new articles" gnus-summary-insert-new-articles t]
2683         ["Filter articles..." gnus-summary-execute-command t]
2684         ["Run command on articles..." gnus-summary-universal-argument t]
2685         ["Search articles forward..." gnus-summary-search-article-forward t]
2686         ["Search articles backward..." gnus-summary-search-article-backward t]
2687         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2688         ["Expand window" gnus-summary-expand-window t]
2689         ["Expire expirable articles" gnus-summary-expire-articles
2690          (gnus-check-backend-function
2691           'request-expire-articles gnus-newsgroup-name)]
2692         ["Edit local kill file" gnus-summary-edit-local-kill t]
2693         ["Edit main kill file" gnus-summary-edit-global-kill t]
2694         ["Edit group parameters" gnus-summary-edit-parameters t]
2695         ["Customize group parameters" gnus-summary-customize-parameters t]
2696         ["Send a bug report" gnus-bug t]
2697         ("Exit"
2698          ["Catchup and exit" gnus-summary-catchup-and-exit
2699           ,@(if (featurep 'xemacs) '(t)
2700               '(:help "Mark unread articles in this group as read, then exit"))]
2701          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2702          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2703          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2704          ["Exit group" gnus-summary-exit
2705           ,@(if (featurep 'xemacs) '(t)
2706               '(:help "Exit current group, return to group selection mode"))]
2707          ["Exit group without updating" gnus-summary-exit-no-update t]
2708          ["Exit and goto next group" gnus-summary-next-group t]
2709          ["Exit and goto prev group" gnus-summary-prev-group t]
2710          ["Reselect group" gnus-summary-reselect-current-group t]
2711          ["Rescan group" gnus-summary-rescan-group t]
2712          ["Update dribble" gnus-summary-save-newsrc t])))
2713
2714     (gnus-run-hooks 'gnus-summary-menu-hook)))
2715
2716 (defvar gnus-summary-tool-bar-map nil)
2717
2718 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2719 ;; affect _new_ message buffers.  We might add a function that walks thru all
2720 ;; summary-mode buffers and force the update.
2721 (defun gnus-summary-tool-bar-update (&optional symbol value)
2722   "Update summary mode toolbar.
2723 Setter function for custom variables."
2724   (setq-default gnus-summary-tool-bar-map nil)
2725   (when symbol
2726     ;; When used as ":set" function:
2727     (set-default symbol value))
2728   (when (gnus-buffer-live-p gnus-summary-buffer)
2729     (with-current-buffer gnus-summary-buffer
2730       (gnus-summary-make-tool-bar))))
2731
2732 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2733                                      'gnus-summary-tool-bar-gnome
2734                                    'gnus-summary-tool-bar-retro)
2735   "Specifies the Gnus summary tool bar.
2736
2737 It can be either a list or a symbol refering to a list.  See
2738 `gmm-tool-bar-from-list' for the format of the list.  The
2739 default key map is `gnus-summary-mode-map'.
2740
2741 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2742 `gnus-summary-tool-bar-retro'."
2743   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2744                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2745                  (repeat :tag "User defined list" gmm-tool-bar-item)
2746                  (symbol))
2747   :version "23.0" ;; No Gnus
2748   :initialize 'custom-initialize-default
2749   :set 'gnus-summary-tool-bar-update
2750   :group 'gnus-summary)
2751
2752 (defcustom gnus-summary-tool-bar-gnome
2753   '((gnus-summary-post-news "mail/compose" nil)
2754     (gnus-summary-insert-new-articles "mail/inbox" nil
2755                                       :visible (or (not gnus-agent)
2756                                                    gnus-plugged))
2757     (gnus-summary-reply-with-original "mail/reply")
2758     (gnus-summary-reply "mail/reply" nil :visible nil)
2759     (gnus-summary-followup-with-original "mail/reply-all")
2760     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2761     (gnus-summary-mail-forward "mail/forward")
2762     (gnus-summary-save-article "mail/save")
2763     (gnus-summary-search-article-forward "search" nil :visible nil)
2764     (gnus-summary-print-article "print")
2765     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2766     ;; Some new commands that may need more suitable icons:
2767     (gnus-summary-save-newsrc "save" nil :visible nil)
2768     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2769     (gnus-summary-prev-article "left-arrow")
2770     (gnus-summary-next-article "right-arrow")
2771     (gnus-summary-next-page "next-page")
2772     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2773     ;;
2774     ;; Maybe some sort-by-... could be added:
2775     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2776     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2777     (gnus-summary-mark-as-expirable
2778      "delete" nil
2779      :visible (gnus-check-backend-function 'request-expire-articles
2780                                            gnus-newsgroup-name))
2781     (gnus-summary-mark-as-spam
2782      "mail/spam" t
2783      :visible (and (fboundp 'spam-group-ham-contents-p)
2784                    (spam-group-ham-contents-p gnus-newsgroup-name))
2785      :help "Mark as spam")
2786     (gnus-summary-mark-as-read-forward
2787      "mail/not-spam" nil
2788      :visible (and (fboundp 'spam-group-spam-contents-p)
2789                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2790     ;;
2791     (gnus-summary-exit "exit")
2792     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2793     (gnus-info-find-node "help"))
2794   "List of functions for the summary tool bar (GNOME style).
2795
2796 See `gmm-tool-bar-from-list' for the format of the list."
2797   :type '(repeat gmm-tool-bar-item)
2798   :version "23.0" ;; No Gnus
2799   :initialize 'custom-initialize-default
2800   :set 'gnus-summary-tool-bar-update
2801   :group 'gnus-summary)
2802
2803 (defcustom gnus-summary-tool-bar-retro
2804   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2805     (gnus-summary-next-unread-article "gnus/next-ur")
2806     (gnus-summary-post-news "gnus/post")
2807     (gnus-summary-followup-with-original "gnus/fuwo")
2808     (gnus-summary-followup "gnus/followup")
2809     (gnus-summary-reply-with-original "gnus/reply-wo")
2810     (gnus-summary-reply "gnus/reply")
2811     (gnus-summary-caesar-message "gnus/rot13")
2812     (gnus-uu-decode-uu "gnus/uu-decode")
2813     (gnus-summary-save-article-file "gnus/save-aif")
2814     (gnus-summary-save-article "gnus/save-art")
2815     (gnus-uu-post-news "gnus/uu-post")
2816     (gnus-summary-catchup "gnus/catchup")
2817     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2818     (gnus-summary-exit "gnus/exit-summ")
2819     ;; Some new command that may need more suitable icons:
2820     (gnus-summary-print-article "gnus/print" nil :visible nil)
2821     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2822     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2823     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2824     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2825     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2826     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2827     ;;
2828     (gnus-info-find-node "gnus/help" nil :visible nil))
2829   "List of functions for the summary tool bar (retro look).
2830
2831 See `gmm-tool-bar-from-list' for the format of the list."
2832   :type '(repeat gmm-tool-bar-item)
2833   :version "23.0" ;; No Gnus
2834   :initialize 'custom-initialize-default
2835   :set 'gnus-summary-tool-bar-update
2836   :group 'gnus-summary)
2837
2838 (defcustom gnus-summary-tool-bar-zap-list t
2839   "List of icon items from the global tool bar.
2840 These items are not displayed in the Gnus summary mode tool bar.
2841
2842 See `gmm-tool-bar-from-list' for the format of the list."
2843   :type 'gmm-tool-bar-zap-list
2844   :version "23.0" ;; No Gnus
2845   :initialize 'custom-initialize-default
2846   :set 'gnus-summary-tool-bar-update
2847   :group 'gnus-summary)
2848
2849 (defvar image-load-path)
2850
2851 (defun gnus-summary-make-tool-bar (&optional force)
2852   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2853 When FORCE, rebuild the tool bar."
2854   (when (and (not (featurep 'xemacs))
2855              (boundp 'tool-bar-mode)
2856              tool-bar-mode
2857              (or (not gnus-summary-tool-bar-map) force))
2858     (let* ((load-path
2859             (gmm-image-load-path-for-library "gnus"
2860                                              "mail/save.xpm"
2861                                              nil t))
2862            (image-load-path (cons (car load-path)
2863                                   (when (boundp 'image-load-path)
2864                                     image-load-path)))
2865            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2866                                         gnus-summary-tool-bar-zap-list
2867                                         'gnus-summary-mode-map)))
2868       (when map
2869         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2870         ;; uses it's value.
2871         (setq gnus-summary-tool-bar-map map))))
2872   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2873
2874 (defun gnus-score-set-default (var value)
2875   "A version of set that updates the GNU Emacs menu-bar."
2876   (set var value)
2877   ;; It is the message that forces the active status to be updated.
2878   (message ""))
2879
2880 (defun gnus-make-score-map (type)
2881   "Make a summary score map of type TYPE."
2882   (if t
2883       nil
2884     (let ((headers '(("author" "from" string)
2885                      ("subject" "subject" string)
2886                      ("article body" "body" string)
2887                      ("article head" "head" string)
2888                      ("xref" "xref" string)
2889                      ("extra header" "extra" string)
2890                      ("lines" "lines" number)
2891                      ("followups to author" "followup" string)))
2892           (types '((number ("less than" <)
2893                            ("greater than" >)
2894                            ("equal" =))
2895                    (string ("substring" s)
2896                            ("exact string" e)
2897                            ("fuzzy string" f)
2898                            ("regexp" r))))
2899           (perms '(("temporary" (current-time-string))
2900                    ("permanent" nil)
2901                    ("immediate" now)))
2902           header)
2903       (list
2904        (apply
2905         'nconc
2906         (list
2907          (if (eq type 'lower)
2908              "Lower score"
2909            "Increase score"))
2910         (let (outh)
2911           (while headers
2912             (setq header (car headers))
2913             (setq outh
2914                   (cons
2915                    (apply
2916                     'nconc
2917                     (list (car header))
2918                     (let ((ts (cdr (assoc (nth 2 header) types)))
2919                           outt)
2920                       (while ts
2921                         (setq outt
2922                               (cons
2923                                (apply
2924                                 'nconc
2925                                 (list (caar ts))
2926                                 (let ((ps perms)
2927                                       outp)
2928                                   (while ps
2929                                     (setq outp
2930                                           (cons
2931                                            (vector
2932                                             (caar ps)
2933                                             (list
2934                                              'gnus-summary-score-entry
2935                                              (nth 1 header)
2936                                              (if (or (string= (nth 1 header)
2937                                                               "head")
2938                                                      (string= (nth 1 header)
2939                                                               "body"))
2940                                                  ""
2941                                                (list 'gnus-summary-header
2942                                                      (nth 1 header)))
2943                                              (list 'quote (nth 1 (car ts)))
2944                                              (list 'gnus-score-delta-default
2945                                                    nil)
2946                                              (nth 1 (car ps))
2947                                              t)
2948                                             t)
2949                                            outp))
2950                                     (setq ps (cdr ps)))
2951                                   (list (nreverse outp))))
2952                                outt))
2953                         (setq ts (cdr ts)))
2954                       (list (nreverse outt))))
2955                    outh))
2956             (setq headers (cdr headers)))
2957           (list (nreverse outh))))))))
2958
2959 \f
2960
2961 (defun gnus-summary-mode (&optional group)
2962   "Major mode for reading articles.
2963
2964 All normal editing commands are switched off.
2965 \\<gnus-summary-mode-map>
2966 Each line in this buffer represents one article.  To read an
2967 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2968 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2969 respectively.
2970
2971 You can also post articles and send mail from this buffer.  To
2972 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2973 of an article, type `\\[gnus-summary-reply]'.
2974
2975 There are approx. one gazillion commands you can execute in this
2976 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2977
2978 The following commands are available:
2979
2980 \\{gnus-summary-mode-map}"
2981   (interactive)
2982   (kill-all-local-variables)
2983   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2984     (gnus-summary-make-local-variables))
2985   (gnus-summary-make-local-variables)
2986   (setq gnus-newsgroup-name group)
2987   (when (gnus-visual-p 'summary-menu 'menu)
2988     (gnus-summary-make-menu-bar)
2989     (gnus-summary-make-tool-bar))
2990   (gnus-make-thread-indent-array)
2991   (gnus-simplify-mode-line)
2992   (setq major-mode 'gnus-summary-mode)
2993   (setq mode-name "Summary")
2994   (make-local-variable 'minor-mode-alist)
2995   (use-local-map gnus-summary-mode-map)
2996   (buffer-disable-undo)
2997   (setq buffer-read-only t              ;Disable modification
2998         show-trailing-whitespace nil)
2999   (setq truncate-lines t)
3000   (setq selective-display t)
3001   (setq selective-display-ellipses t)   ;Display `...'
3002   (gnus-summary-set-display-table)
3003   (gnus-set-default-directory)
3004   (make-local-variable 'gnus-summary-line-format)
3005   (make-local-variable 'gnus-summary-line-format-spec)
3006   (make-local-variable 'gnus-summary-dummy-line-format)
3007   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3008   (make-local-variable 'gnus-summary-mark-positions)
3009   (gnus-make-local-hook 'pre-command-hook)
3010   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3011   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3012   (turn-on-gnus-mailing-list-mode)
3013   (mm-enable-multibyte)
3014   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3015   (gnus-update-summary-mark-positions))
3016
3017 (defun gnus-summary-make-local-variables ()
3018   "Make all the local summary buffer variables."
3019   (let (global)
3020     (dolist (local gnus-summary-local-variables)
3021       (if (consp local)
3022           (progn
3023             (if (eq (cdr local) 'global)
3024                 ;; Copy the global value of the variable.
3025                 (setq global (symbol-value (car local)))
3026               ;; Use the value from the list.
3027               (setq global (eval (cdr local))))
3028             (set (make-local-variable (car local)) global))
3029         ;; Simple nil-valued local variable.
3030         (set (make-local-variable local) nil)))))
3031
3032 (defun gnus-summary-clear-local-variables ()
3033   (let ((locals gnus-summary-local-variables))
3034     (while locals
3035       (if (consp (car locals))
3036           (and (symbolp (caar locals))
3037                (set (caar locals) nil))
3038         (and (symbolp (car locals))
3039              (set (car locals) nil)))
3040       (setq locals (cdr locals)))))
3041
3042 ;; Summary data functions.
3043
3044 (defmacro gnus-data-number (data)
3045   `(car ,data))
3046
3047 (defmacro gnus-data-set-number (data number)
3048   `(setcar ,data ,number))
3049
3050 (defmacro gnus-data-mark (data)
3051   `(nth 1 ,data))
3052
3053 (defmacro gnus-data-set-mark (data mark)
3054   `(setcar (nthcdr 1 ,data) ,mark))
3055
3056 (defmacro gnus-data-pos (data)
3057   `(nth 2 ,data))
3058
3059 (defmacro gnus-data-set-pos (data pos)
3060   `(setcar (nthcdr 2 ,data) ,pos))
3061
3062 (defmacro gnus-data-header (data)
3063   `(nth 3 ,data))
3064
3065 (defmacro gnus-data-set-header (data header)
3066   `(setf (nth 3 ,data) ,header))
3067
3068 (defmacro gnus-data-level (data)
3069   `(nth 4 ,data))
3070
3071 (defmacro gnus-data-unread-p (data)
3072   `(= (nth 1 ,data) gnus-unread-mark))
3073
3074 (defmacro gnus-data-read-p (data)
3075   `(/= (nth 1 ,data) gnus-unread-mark))
3076
3077 (defmacro gnus-data-pseudo-p (data)
3078   `(consp (nth 3 ,data)))
3079
3080 (defmacro gnus-data-find (number)
3081   `(assq ,number gnus-newsgroup-data))
3082
3083 (defmacro gnus-data-find-list (number &optional data)
3084   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3085      (memq (assq ,number bdata)
3086            bdata)))
3087
3088 (defmacro gnus-data-make (number mark pos header level)
3089   `(list ,number ,mark ,pos ,header ,level))
3090
3091 (defun gnus-data-enter (after-article number mark pos header level offset)
3092   (let ((data (gnus-data-find-list after-article)))
3093     (unless data
3094       (error "No such article: %d" after-article))
3095     (setcdr data (cons (gnus-data-make number mark pos header level)
3096                        (cdr data)))
3097     (setq gnus-newsgroup-data-reverse nil)
3098     (gnus-data-update-list (cddr data) offset)))
3099
3100 (defun gnus-data-enter-list (after-article list &optional offset)
3101   (when list
3102     (let ((data (and after-article (gnus-data-find-list after-article)))
3103           (ilist list))
3104       (if (not (or data
3105                    after-article))
3106           (let ((odata gnus-newsgroup-data))
3107             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3108             (when offset
3109               (gnus-data-update-list odata offset)))
3110         ;; Find the last element in the list to be spliced into the main
3111         ;; list.
3112         (setq list (last list))
3113         (if (not data)
3114             (progn
3115               (setcdr list gnus-newsgroup-data)
3116               (setq gnus-newsgroup-data ilist)
3117               (when offset
3118                 (gnus-data-update-list (cdr list) offset)))
3119           (setcdr list (cdr data))
3120           (setcdr data ilist)
3121           (when offset
3122             (gnus-data-update-list (cdr list) offset))))
3123       (setq gnus-newsgroup-data-reverse nil))))
3124
3125 (defun gnus-data-remove (article &optional offset)
3126   (let ((data gnus-newsgroup-data))
3127     (if (= (gnus-data-number (car data)) article)
3128         (progn
3129           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3130                 gnus-newsgroup-data-reverse nil)
3131           (when offset
3132             (gnus-data-update-list gnus-newsgroup-data offset)))
3133       (while (cdr data)
3134         (when (= (gnus-data-number (cadr data)) article)
3135           (setcdr data (cddr data))
3136           (when offset
3137             (gnus-data-update-list (cdr data) offset))
3138           (setq data nil
3139                 gnus-newsgroup-data-reverse nil))
3140         (setq data (cdr data))))))
3141
3142 (defmacro gnus-data-list (backward)
3143   `(if ,backward
3144        (or gnus-newsgroup-data-reverse
3145            (setq gnus-newsgroup-data-reverse
3146                  (reverse gnus-newsgroup-data)))
3147      gnus-newsgroup-data))
3148
3149 (defun gnus-data-update-list (data offset)
3150   "Add OFFSET to the POS of all data entries in DATA."
3151   (setq gnus-newsgroup-data-reverse nil)
3152   (while data
3153     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3154     (setq data (cdr data))))
3155
3156 (defun gnus-summary-article-pseudo-p (article)
3157   "Say whether this article is a pseudo article or not."
3158   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3159
3160 (defmacro gnus-summary-article-sparse-p (article)
3161   "Say whether this article is a sparse article or not."
3162   `(memq ,article gnus-newsgroup-sparse))
3163
3164 (defmacro gnus-summary-article-ancient-p (article)
3165   "Say whether this article is a sparse article or not."
3166   `(memq ,article gnus-newsgroup-ancient))
3167
3168 (defun gnus-article-parent-p (number)
3169   "Say whether this article is a parent or not."
3170   (let ((data (gnus-data-find-list number)))
3171     (and (cdr data)              ; There has to be an article after...
3172          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3173             (gnus-data-level (nth 1 data))))))
3174
3175 (defun gnus-article-children (number)
3176   "Return a list of all children to NUMBER."
3177   (let* ((data (gnus-data-find-list number))
3178          (level (gnus-data-level (car data)))
3179          children)
3180     (setq data (cdr data))
3181     (while (and data
3182                 (= (gnus-data-level (car data)) (1+ level)))
3183       (push (gnus-data-number (car data)) children)
3184       (setq data (cdr data)))
3185     children))
3186
3187 (defmacro gnus-summary-skip-intangible ()
3188   "If the current article is intangible, then jump to a different article."
3189   '(let ((to (get-text-property (point) 'gnus-intangible)))
3190      (and to (gnus-summary-goto-subject to))))
3191
3192 (defmacro gnus-summary-article-intangible-p ()
3193   "Say whether this article is intangible or not."
3194   '(get-text-property (point) 'gnus-intangible))
3195
3196 (defun gnus-article-read-p (article)
3197   "Say whether ARTICLE is read or not."
3198   (not (or (memq article gnus-newsgroup-marked)
3199            (memq article gnus-newsgroup-spam-marked)
3200            (memq article gnus-newsgroup-unreads)
3201            (memq article gnus-newsgroup-unselected)
3202            (memq article gnus-newsgroup-dormant))))
3203
3204 ;; Some summary mode macros.
3205
3206 (defmacro gnus-summary-article-number ()
3207   "The article number of the article on the current line.
3208 If there isn't an article number here, then we return the current
3209 article number."
3210   '(progn
3211      (gnus-summary-skip-intangible)
3212      (or (get-text-property (point) 'gnus-number)
3213          (gnus-summary-last-subject))))
3214
3215 (defmacro gnus-summary-article-header (&optional number)
3216   "Return the header of article NUMBER."
3217   `(gnus-data-header (gnus-data-find
3218                       ,(or number '(gnus-summary-article-number)))))
3219
3220 (defmacro gnus-summary-thread-level (&optional number)
3221   "Return the level of thread that starts with article NUMBER."
3222   `(if (and (eq gnus-summary-make-false-root 'dummy)
3223             (get-text-property (point) 'gnus-intangible))
3224        0
3225      (gnus-data-level (gnus-data-find
3226                        ,(or number '(gnus-summary-article-number))))))
3227
3228 (defmacro gnus-summary-article-mark (&optional number)
3229   "Return the mark of article NUMBER."
3230   `(gnus-data-mark (gnus-data-find
3231                     ,(or number '(gnus-summary-article-number)))))
3232
3233 (defmacro gnus-summary-article-pos (&optional number)
3234   "Return the position of the line of article NUMBER."
3235   `(gnus-data-pos (gnus-data-find
3236                    ,(or number '(gnus-summary-article-number)))))
3237
3238 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3239 (defmacro gnus-summary-article-subject (&optional number)
3240   "Return current subject string or nil if nothing."
3241   `(let ((headers
3242           ,(if number
3243                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3244              '(gnus-data-header (assq (gnus-summary-article-number)
3245                                       gnus-newsgroup-data)))))
3246      (and headers
3247           (vectorp headers)
3248           (mail-header-subject headers))))
3249
3250 (defmacro gnus-summary-article-score (&optional number)
3251   "Return current article score."
3252   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3253                   gnus-newsgroup-scored))
3254        gnus-summary-default-score 0))
3255
3256 (defun gnus-summary-article-children (&optional number)
3257   "Return a list of article numbers that are children of article NUMBER."
3258   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3259          (level (gnus-data-level (car data)))
3260          l children)
3261     (while (and (setq data (cdr data))
3262                 (> (setq l (gnus-data-level (car data))) level))
3263       (and (= (1+ level) l)
3264            (push (gnus-data-number (car data))
3265                  children)))
3266     (nreverse children)))
3267
3268 (defun gnus-summary-article-parent (&optional number)
3269   "Return the article number of the parent of article NUMBER."
3270   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3271                                     (gnus-data-list t)))
3272          (level (gnus-data-level (car data))))
3273     (if (zerop level)
3274         ()                              ; This is a root.
3275       ;; We search until we find an article with a level less than
3276       ;; this one.  That function has to be the parent.
3277       (while (and (setq data (cdr data))
3278                   (not (< (gnus-data-level (car data)) level))))
3279       (and data (gnus-data-number (car data))))))
3280
3281 (defun gnus-unread-mark-p (mark)
3282   "Say whether MARK is the unread mark."
3283   (= mark gnus-unread-mark))
3284
3285 (defun gnus-read-mark-p (mark)
3286   "Say whether MARK is one of the marks that mark as read.
3287 This is all marks except unread, ticked, dormant, and expirable."
3288   (not (or (= mark gnus-unread-mark)
3289            (= mark gnus-ticked-mark)
3290            (= mark gnus-spam-mark)
3291            (= mark gnus-dormant-mark)
3292            (= mark gnus-expirable-mark))))
3293
3294 (defmacro gnus-article-mark (number)
3295   "Return the MARK of article NUMBER.
3296 This macro should only be used when computing the mark the \"first\"
3297 time; i.e., when generating the summary lines.  After that,
3298 `gnus-summary-article-mark' should be used to examine the
3299 marks of articles."
3300   `(cond
3301     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3302     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3303     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3304     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3305     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3306     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3307     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3308     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3309            gnus-ancient-mark))))
3310
3311 ;; Saving hidden threads.
3312
3313 (defmacro gnus-save-hidden-threads (&rest forms)
3314   "Save hidden threads, eval FORMS, and restore the hidden threads."
3315   (let ((config (make-symbol "config")))
3316     `(let ((,config (gnus-hidden-threads-configuration)))
3317        (unwind-protect
3318            (save-excursion
3319              ,@forms)
3320          (gnus-restore-hidden-threads-configuration ,config)))))
3321 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3322 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3323
3324 (defun gnus-data-compute-positions ()
3325   "Compute the positions of all articles."
3326   (setq gnus-newsgroup-data-reverse nil)
3327   (let ((data gnus-newsgroup-data))
3328     (save-excursion
3329       (gnus-save-hidden-threads
3330         (gnus-summary-show-all-threads)
3331         (goto-char (point-min))
3332         (while data
3333           (while (get-text-property (point) 'gnus-intangible)
3334             (forward-line 1))
3335           (gnus-data-set-pos (car data) (+ (point) 3))
3336           (setq data (cdr data))
3337           (forward-line 1))))))
3338
3339 (defun gnus-hidden-threads-configuration ()
3340   "Return the current hidden threads configuration."
3341   (save-excursion
3342     (let (config)
3343       (goto-char (point-min))
3344       (while (search-forward "\r" nil t)
3345         (push (1- (point)) config))
3346       config)))
3347
3348 (defun gnus-restore-hidden-threads-configuration (config)
3349   "Restore hidden threads configuration from CONFIG."
3350   (save-excursion
3351     (let (point buffer-read-only)
3352       (while (setq point (pop config))
3353         (when (and (< point (point-max))
3354                    (goto-char point)
3355                    (eq (char-after) ?\n))
3356           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3357
3358 ;; Various summary mode internalish functions.
3359
3360 (defun gnus-mouse-pick-article (e)
3361   (interactive "e")
3362   (mouse-set-point e)
3363   (gnus-summary-next-page nil t))
3364
3365 (defun gnus-summary-set-display-table ()
3366   "Change the display table.
3367 Odd characters have a tendency to mess
3368 up nicely formatted displays - we make all possible glyphs
3369 display only a single character."
3370
3371   ;; We start from the standard display table, if any.
3372   (let ((table (or (copy-sequence standard-display-table)
3373                    (make-display-table)))
3374         (i 32))
3375     ;; Nix out all the control chars...
3376     (while (>= (setq i (1- i)) 0)
3377       (aset table i [??]))
3378    ;; ... but not newline and cr, of course.  (cr is necessary for the
3379     ;; selective display).
3380     (aset table ?\n nil)
3381     (aset table ?\r nil)
3382     ;; We keep TAB as well.
3383     (aset table ?\t nil)
3384     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3385     ;; Emacs 23 (unicode), that are not set already.
3386     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3387                  160
3388                256)))
3389       (while (>= (setq i (1- i)) 127)
3390         ;; Only modify if the entry is nil.
3391         (unless (aref table i)
3392           (aset table i [??]))))
3393     (setq buffer-display-table table)))
3394
3395 (defun gnus-summary-set-article-display-arrow (pos)
3396   "Update the overlay arrow to point to line at position POS."
3397   (when (and gnus-summary-display-arrow
3398              (boundp 'overlay-arrow-position)
3399              (boundp 'overlay-arrow-string))
3400     (save-excursion
3401       (goto-char pos)
3402       (beginning-of-line)
3403       (unless overlay-arrow-position
3404         (setq overlay-arrow-position (make-marker)))
3405       (setq overlay-arrow-string "=>"
3406             overlay-arrow-position (set-marker overlay-arrow-position
3407                                                (point)
3408                                                (current-buffer))))))
3409
3410 (defun gnus-summary-setup-buffer (group)
3411   "Initialize summary buffer."
3412   (let ((buffer (gnus-summary-buffer-name group))
3413         (dead-name (concat "*Dead Summary "
3414                            (gnus-group-decoded-name group) "*")))
3415     ;; If a dead summary buffer exists, we kill it.
3416     (when (gnus-buffer-live-p dead-name)
3417       (gnus-kill-buffer dead-name))
3418     (if (get-buffer buffer)
3419         (progn
3420           (set-buffer buffer)
3421           (setq gnus-summary-buffer (current-buffer))
3422           (not gnus-newsgroup-prepared))
3423       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3424       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3425       (gnus-summary-mode group)
3426       (when gnus-carpal
3427         (gnus-carpal-setup-buffer 'summary))
3428       (when (gnus-group-quit-config group)
3429         (set (make-local-variable 'gnus-single-article-buffer) nil))
3430       (make-local-variable 'gnus-article-buffer)
3431       (make-local-variable 'gnus-article-current)
3432       (make-local-variable 'gnus-original-article-buffer)
3433       (setq gnus-newsgroup-name group)
3434       ;; Set any local variables in the group parameters.
3435       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3436       t)))
3437
3438 (defun gnus-set-global-variables ()
3439   "Set the global equivalents of the buffer-local variables.
3440 They are set to the latest values they had.  These reflect the summary
3441 buffer that was in action when the last article was fetched."
3442   (when (eq major-mode 'gnus-summary-mode)
3443     (setq gnus-summary-buffer (current-buffer))
3444     (let ((name gnus-newsgroup-name)
3445           (marked gnus-newsgroup-marked)
3446           (spam gnus-newsgroup-spam-marked)
3447           (unread gnus-newsgroup-unreads)
3448           (headers gnus-current-headers)
3449           (data gnus-newsgroup-data)
3450           (summary gnus-summary-buffer)
3451           (article-buffer gnus-article-buffer)
3452           (original gnus-original-article-buffer)
3453           (gac gnus-article-current)
3454           (reffed gnus-reffed-article-number)
3455           (score-file gnus-current-score-file)
3456           (default-charset gnus-newsgroup-charset)
3457           vlist)
3458       (let ((locals gnus-newsgroup-variables))
3459         (while locals
3460           (if (consp (car locals))
3461               (push (eval (caar locals)) vlist)
3462             (push (eval (car locals)) vlist))
3463           (setq locals (cdr locals)))
3464         (setq vlist (nreverse vlist)))
3465       (with-current-buffer gnus-group-buffer
3466         (setq gnus-newsgroup-name name
3467               gnus-newsgroup-marked marked
3468               gnus-newsgroup-spam-marked spam
3469               gnus-newsgroup-unreads unread
3470               gnus-current-headers headers
3471               gnus-newsgroup-data data
3472               gnus-article-current gac
3473               gnus-summary-buffer summary
3474               gnus-article-buffer article-buffer
3475               gnus-original-article-buffer original
3476               gnus-reffed-article-number reffed
3477               gnus-current-score-file score-file
3478               gnus-newsgroup-charset default-charset)
3479         (let ((locals gnus-newsgroup-variables))
3480           (while locals
3481             (if (consp (car locals))
3482                 (set (caar locals) (pop vlist))
3483               (set (car locals) (pop vlist)))
3484             (setq locals (cdr locals))))
3485         ;; The article buffer also has local variables.
3486         (when (gnus-buffer-live-p gnus-article-buffer)
3487           (set-buffer gnus-article-buffer)
3488           (setq gnus-summary-buffer summary))))))
3489
3490 (defun gnus-summary-article-unread-p (article)
3491   "Say whether ARTICLE is unread or not."
3492   (memq article gnus-newsgroup-unreads))
3493
3494 (defun gnus-summary-first-article-p (&optional article)
3495   "Return whether ARTICLE is the first article in the buffer."
3496   (if (not (setq article (or article (gnus-summary-article-number))))
3497       nil
3498     (eq article (caar gnus-newsgroup-data))))
3499
3500 (defun gnus-summary-last-article-p (&optional article)
3501   "Return whether ARTICLE is the last article in the buffer."
3502   (if (not (setq article (or article (gnus-summary-article-number))))
3503       ;; All non-existent numbers are the last article.  :-)
3504       t
3505     (not (cdr (gnus-data-find-list article)))))
3506
3507 (defun gnus-make-thread-indent-array (&optional n)
3508   (when (or n
3509             (progn (setq n 200) nil)
3510             (null gnus-thread-indent-array)
3511             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3512     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3513           gnus-thread-indent-array-level gnus-thread-indent-level)
3514     (while (>= n 0)
3515       (aset gnus-thread-indent-array n
3516             (make-string (* n gnus-thread-indent-level) ? ))
3517       (setq n (1- n)))))
3518
3519 (defun gnus-update-summary-mark-positions ()
3520   "Compute where the summary marks are to go."
3521   (save-excursion
3522     (when (gnus-buffer-exists-p gnus-summary-buffer)
3523       (set-buffer gnus-summary-buffer))
3524     (let ((spec gnus-summary-line-format-spec)
3525           pos)
3526       (save-excursion
3527         (gnus-set-work-buffer)
3528         (let ((gnus-tmp-unread ?Z)
3529               (gnus-replied-mark ?Z)
3530               (gnus-score-below-mark ?Z)
3531               (gnus-score-over-mark ?Z)
3532               (gnus-undownloaded-mark ?Z)
3533               (gnus-summary-line-format-spec spec)
3534               (gnus-newsgroup-downloadable '(0))
3535               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3536               case-fold-search ignores)
3537           ;; Here, all marks are bound to Z.
3538           (gnus-summary-insert-line header
3539                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3540           (goto-char (point-min))
3541           ;; Memorize the positions of the same characters as dummy marks.
3542           (while (re-search-forward "[A-D]" nil t)
3543             (push (point) ignores))
3544           (erase-buffer)
3545           ;; We use A-D as dummy marks in order to know column positions
3546           ;; where marks should be inserted.
3547           (setq gnus-tmp-unread ?A
3548                 gnus-replied-mark ?B
3549                 gnus-score-below-mark ?C
3550                 gnus-score-over-mark ?C
3551                 gnus-undownloaded-mark ?D)
3552           (gnus-summary-insert-line header
3553                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3554           ;; Ignore characters which aren't dummy marks.
3555           (dolist (p ignores)
3556             (delete-region (goto-char (1- p)) p)
3557             (insert ?Z))
3558           (goto-char (point-min))
3559           (setq pos (list (cons 'unread
3560                                 (and (search-forward "A" nil t)
3561                                      (- (point) (point-min) 1)))))
3562           (goto-char (point-min))
3563           (push (cons 'replied (and (search-forward "B" nil t)
3564                                     (- (point) (point-min) 1)))
3565                 pos)
3566           (goto-char (point-min))
3567           (push (cons 'score (and (search-forward "C" nil t)
3568                                   (- (point) (point-min) 1)))
3569                 pos)
3570           (goto-char (point-min))
3571           (push (cons 'download (and (search-forward "D" nil t)
3572                                      (- (point) (point-min) 1)))
3573                 pos)))
3574       (setq gnus-summary-mark-positions pos))))
3575
3576 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3577   "Insert a dummy root in the summary buffer."
3578   (beginning-of-line)
3579   (gnus-add-text-properties
3580    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3581    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3582
3583 (defun gnus-summary-extract-address-component (from)
3584   (or (car (funcall gnus-extract-address-components from))
3585       from))
3586
3587 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3588   (let ((mail-parse-charset gnus-newsgroup-charset)
3589         (ignored-from-addresses (gnus-ignored-from-addresses))
3590         ; Is it really necessary to do this next part for each summary line?
3591         ; Luckily, doesn't seem to slow things down much.
3592         (mail-parse-ignored-charsets
3593          (with-current-buffer gnus-summary-buffer
3594            gnus-newsgroup-ignored-charsets)))
3595     (or
3596      (and ignored-from-addresses
3597           (string-match ignored-from-addresses gnus-tmp-from)
3598           (let ((extra-headers (mail-header-extra header))
3599                 to
3600                 newsgroups)
3601             (cond
3602              ((setq to (cdr (assq 'To extra-headers)))
3603               (concat gnus-summary-to-prefix
3604                       (inline
3605                         (gnus-summary-extract-address-component
3606                          (funcall gnus-decode-encoded-address-function to)))))
3607              ((setq newsgroups
3608                     (or
3609                      (cdr (assq 'Newsgroups extra-headers))
3610                      (and
3611                       (memq 'Newsgroups gnus-extra-headers)
3612                       (eq (car (gnus-find-method-for-group
3613                                 gnus-newsgroup-name)) 'nntp)
3614                       (gnus-group-real-name gnus-newsgroup-name))))
3615               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3616      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3617
3618 (defun gnus-summary-insert-line (gnus-tmp-header
3619                                  gnus-tmp-level gnus-tmp-current
3620                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3621                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3622                                  &optional gnus-tmp-dummy gnus-tmp-score
3623                                  gnus-tmp-process)
3624   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3625       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3626                                           gnus-tmp-level)))
3627   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3628          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3629          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3630          (gnus-tmp-score-char
3631           (if (or (null gnus-summary-default-score)
3632                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3633                       gnus-summary-zcore-fuzz))
3634               ?                         ;Whitespace
3635             (if (< gnus-tmp-score gnus-summary-default-score)
3636                 gnus-score-below-mark gnus-score-over-mark)))
3637          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3638          (gnus-tmp-replied
3639           (cond (gnus-tmp-process gnus-process-mark)
3640                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3641                  gnus-cached-mark)
3642                 (gnus-tmp-replied gnus-replied-mark)
3643                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3644                  gnus-forwarded-mark)
3645                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3646                  gnus-saved-mark)
3647                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3648                  gnus-recent-mark)
3649                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3650                  gnus-unseen-mark)
3651                 (t gnus-no-mark)))
3652          (gnus-tmp-downloaded
3653           (cond (undownloaded
3654                  gnus-undownloaded-mark)
3655                 (gnus-newsgroup-agentized
3656                  gnus-downloaded-mark)
3657                 (t
3658                  gnus-no-mark)))
3659          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3660          (gnus-tmp-name
3661           (cond
3662            ((string-match "<[^>]+> *$" gnus-tmp-from)
3663             (let ((beg (match-beginning 0)))
3664               (or (and (string-match "^\".+\"" gnus-tmp-from)
3665                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3666                   (substring gnus-tmp-from 0 beg))))
3667            ((string-match "(.+)" gnus-tmp-from)
3668             (substring gnus-tmp-from
3669                        (1+ (match-beginning 0)) (1- (match-end 0))))
3670            (t gnus-tmp-from)))
3671          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3672          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3673          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3674          (buffer-read-only nil))
3675     (when (string= gnus-tmp-name "")
3676       (setq gnus-tmp-name gnus-tmp-from))
3677     (unless (numberp gnus-tmp-lines)
3678       (setq gnus-tmp-lines -1))
3679     (if (= gnus-tmp-lines -1)
3680         (setq gnus-tmp-lines "?")
3681       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3682       (gnus-put-text-property
3683      (point)
3684      (progn (eval gnus-summary-line-format-spec) (point))
3685        'gnus-number gnus-tmp-number)
3686     (when (gnus-visual-p 'summary-highlight 'highlight)
3687       (forward-line -1)
3688       (gnus-run-hooks 'gnus-summary-update-hook)
3689       (forward-line 1))))
3690
3691 (defun gnus-summary-update-line (&optional dont-update)
3692   "Update summary line after change."
3693   (when (and gnus-summary-default-score
3694              (not gnus-summary-inhibit-highlight))
3695     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3696            (article (gnus-summary-article-number))
3697            (score (gnus-summary-article-score article)))
3698       (unless dont-update
3699         (if (and gnus-summary-mark-below
3700                  (< (gnus-summary-article-score)
3701                     gnus-summary-mark-below))
3702             ;; This article has a low score, so we mark it as read.
3703             (when (memq article gnus-newsgroup-unreads)
3704               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3705           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3706             ;; This article was previously marked as read on account
3707             ;; of a low score, but now it has risen, so we mark it as
3708             ;; unread.
3709             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3710         (gnus-summary-update-mark
3711          (if (or (null gnus-summary-default-score)
3712                  (<= (abs (- score gnus-summary-default-score))
3713                      gnus-summary-zcore-fuzz))
3714              ?                          ;Whitespace
3715            (if (< score gnus-summary-default-score)
3716                gnus-score-below-mark gnus-score-over-mark))
3717          'score))
3718       ;; Do visual highlighting.
3719       (when (gnus-visual-p 'summary-highlight 'highlight)
3720         (gnus-run-hooks 'gnus-summary-update-hook)))))
3721
3722 (defvar gnus-tmp-new-adopts nil)
3723
3724 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3725   "Return the number of articles in THREAD.
3726 This may be 0 in some cases -- if none of the articles in
3727 the thread are to be displayed."
3728   (let* ((number
3729          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3730           (cond
3731            ((not (listp thread))
3732             1)
3733            ((and (consp thread) (cdr thread))
3734             (apply
3735              '+ 1 (mapcar
3736                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3737            ((null thread)
3738             1)
3739            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3740             1)
3741            (t 0))))
3742     (when (and level (zerop level) gnus-tmp-new-adopts)
3743       (incf number
3744             (apply '+ (mapcar
3745                        'gnus-summary-number-of-articles-in-thread
3746                        gnus-tmp-new-adopts))))
3747     (if char
3748         (if (> number 1) gnus-not-empty-thread-mark
3749           gnus-empty-thread-mark)
3750       number)))
3751
3752 (defsubst gnus-summary-line-message-size (head)
3753   "Return pretty-printed version of message size.
3754 This function is intended to be used in
3755 `gnus-summary-line-format-alist'."
3756   (let ((c (or (mail-header-chars head) -1)))
3757     (cond ((< c 0) "n/a")               ; chars not available
3758           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3759           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3760           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3761           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3762
3763
3764 (defun gnus-summary-set-local-parameters (group)
3765   "Go through the local params of GROUP and set all variable specs in that list."
3766   (let ((vars '(quit-config)))          ; Ignore quit-config.
3767     (dolist (elem (gnus-group-find-parameter group))
3768       (and (consp elem)                 ; Has to be a cons.
3769            (consp (cdr elem))           ; The cdr has to be a list.
3770            (symbolp (car elem))         ; Has to be a symbol in there.
3771            (not (memq (car elem) vars))
3772            (ignore-errors               ; So we set it.
3773              (push (car elem) vars)
3774              (make-local-variable (car elem))
3775              (set (car elem) (eval (nth 1 elem))))))))
3776
3777 (defun gnus-summary-read-group (group &optional show-all no-article
3778                                       kill-buffer no-display backward
3779                                       select-articles)
3780   "Start reading news in newsgroup GROUP.
3781 If SHOW-ALL is non-nil, already read articles are also listed.
3782 If NO-ARTICLE is non-nil, no article is selected initially.
3783 If NO-DISPLAY, don't generate a summary buffer."
3784   (let (result)
3785     (while (and group
3786                 (null (setq result
3787                             (let ((gnus-auto-select-next nil))
3788                               (or (gnus-summary-read-group-1
3789                                    group show-all no-article
3790                                    kill-buffer no-display
3791                                    select-articles)
3792                                   (setq show-all nil
3793                                         select-articles nil)))))
3794                 (eq gnus-auto-select-next 'quietly))
3795       (set-buffer gnus-group-buffer)
3796       ;; The entry function called above goes to the next
3797       ;; group automatically, so we go two groups back
3798       ;; if we are searching for the previous group.
3799       (when backward
3800         (gnus-group-prev-unread-group 2))
3801       (if (not (equal group (gnus-group-group-name)))
3802           (setq group (gnus-group-group-name))
3803         (setq group nil)))
3804     result))
3805
3806 (defun gnus-summary-read-group-1 (group show-all no-article
3807                                         kill-buffer no-display
3808                                         &optional select-articles)
3809   ;; Killed foreign groups can't be entered.
3810   ;;  (when (and (not (gnus-group-native-p group))
3811   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3812   ;;    (error "Dead non-native groups can't be entered"))
3813   (gnus-message 5 "Retrieving newsgroup: %s..."
3814                 (gnus-group-decoded-name group))
3815   (let* ((new-group (gnus-summary-setup-buffer group))
3816          (quit-config (gnus-group-quit-config group))
3817          (did-select (and new-group (gnus-select-newsgroup
3818                                      group show-all select-articles))))
3819     (cond
3820      ;; This summary buffer exists already, so we just select it.
3821      ((not new-group)
3822       (gnus-set-global-variables)
3823       (when kill-buffer
3824         (gnus-kill-or-deaden-summary kill-buffer))
3825       (gnus-configure-windows 'summary 'force)
3826       (gnus-set-mode-line 'summary)
3827       (gnus-summary-position-point)
3828       (message "")
3829       t)
3830      ;; We couldn't select this group.
3831      ((null did-select)
3832       (when (and (eq major-mode 'gnus-summary-mode)
3833                  (not (equal (current-buffer) kill-buffer)))
3834         (kill-buffer (current-buffer))
3835         (if (not quit-config)
3836             (progn
3837               ;; Update the info -- marks might need to be removed,
3838               ;; for instance.
3839               (gnus-summary-update-info)
3840               (set-buffer gnus-group-buffer)
3841               (gnus-group-jump-to-group group)
3842               (gnus-group-next-unread-group 1))
3843           (gnus-handle-ephemeral-exit quit-config)))
3844       (let ((grpinfo (gnus-get-info group)))
3845         (if (null (gnus-info-read grpinfo))
3846             (gnus-message 3 "Group %s contains no messages"
3847                           (gnus-group-decoded-name group))
3848           (gnus-message 3 "Can't select group")))
3849       nil)
3850      ;; The user did a `C-g' while prompting for number of articles,
3851      ;; so we exit this group.
3852      ((eq did-select 'quit)
3853       (and (eq major-mode 'gnus-summary-mode)
3854            (not (equal (current-buffer) kill-buffer))
3855            (kill-buffer (current-buffer)))
3856       (when kill-buffer
3857         (gnus-kill-or-deaden-summary kill-buffer))
3858       (if (not quit-config)
3859           (progn
3860             (set-buffer gnus-group-buffer)
3861             (gnus-group-jump-to-group group)
3862             (gnus-group-next-unread-group 1)
3863             (gnus-configure-windows 'group 'force))
3864         (gnus-handle-ephemeral-exit quit-config))
3865       ;; Finally signal the quit.
3866       (signal 'quit nil))
3867      ;; The group was successfully selected.
3868      (t
3869       (gnus-set-global-variables)
3870       ;; Save the active value in effect when the group was entered.
3871       (setq gnus-newsgroup-active
3872             (gnus-copy-sequence
3873              (gnus-active gnus-newsgroup-name)))
3874       ;; You can change the summary buffer in some way with this hook.
3875       (gnus-run-hooks 'gnus-select-group-hook)
3876       (when (memq 'summary (gnus-update-format-specifications
3877                             nil 'summary 'summary-mode 'summary-dummy))
3878         ;; The format specification for the summary line was updated,
3879         ;; so we need to update the mark positions as well.
3880         (gnus-update-summary-mark-positions))
3881       ;; Do score processing.
3882       (when gnus-use-scoring
3883         (gnus-possibly-score-headers))
3884       ;; Check whether to fill in the gaps in the threads.
3885       (when gnus-build-sparse-threads
3886         (gnus-build-sparse-threads))
3887       ;; Find the initial limit.
3888       (if show-all
3889           (let ((gnus-newsgroup-dormant nil))
3890             (gnus-summary-initial-limit show-all))
3891         (gnus-summary-initial-limit show-all))
3892       ;; Generate the summary buffer.
3893       (unless no-display
3894         (gnus-summary-prepare))
3895       (when gnus-use-trees
3896         (gnus-tree-open group)
3897         (setq gnus-summary-highlight-line-function
3898               'gnus-tree-highlight-article))
3899       ;; If the summary buffer is empty, but there are some low-scored
3900       ;; articles or some excluded dormants, we include these in the
3901       ;; buffer.
3902       (when (and (zerop (buffer-size))
3903                  (not no-display))
3904         (cond (gnus-newsgroup-dormant
3905                (gnus-summary-limit-include-dormant))
3906               ((and gnus-newsgroup-scored show-all)
3907                (gnus-summary-limit-include-expunged t))))
3908       ;; Function `gnus-apply-kill-file' must be called in this hook.
3909       (gnus-run-hooks 'gnus-apply-kill-hook)
3910       (if (and (zerop (buffer-size))
3911                (not no-display))
3912           (progn
3913             ;; This newsgroup is empty.
3914             (gnus-summary-catchup-and-exit nil t)
3915             (gnus-message 6 "No unread news")
3916             (when kill-buffer
3917               (gnus-kill-or-deaden-summary kill-buffer))
3918             ;; Return nil from this function.
3919             nil)
3920         ;; Hide conversation thread subtrees.  We cannot do this in
3921         ;; gnus-summary-prepare-hook since kill processing may not
3922         ;; work with hidden articles.
3923         (gnus-summary-maybe-hide-threads)
3924         (when kill-buffer
3925           (gnus-kill-or-deaden-summary kill-buffer))
3926         (gnus-summary-auto-select-subject)
3927         ;; Show first unread article if requested.
3928         (if (and (not no-article)
3929                  (not no-display)
3930                  gnus-newsgroup-unreads
3931                  gnus-auto-select-first)
3932             (progn
3933               (gnus-configure-windows 'summary)
3934               (let ((art (gnus-summary-article-number)))
3935                 (unless (and (not gnus-plugged)
3936                              (or (memq art gnus-newsgroup-undownloaded)
3937                                  (memq art gnus-newsgroup-downloadable)))
3938                   (gnus-summary-goto-article art))))
3939           ;; Don't select any articles.
3940           (gnus-summary-position-point)
3941           (gnus-configure-windows 'summary 'force)
3942           (gnus-set-mode-line 'summary))
3943         (when (and gnus-auto-center-group
3944                    (get-buffer-window gnus-group-buffer t))
3945           ;; Gotta use windows, because recenter does weird stuff if
3946           ;; the current buffer ain't the displayed window.
3947           (let ((owin (selected-window)))
3948             (select-window (get-buffer-window gnus-group-buffer t))
3949             (when (gnus-group-goto-group group)
3950               (recenter))
3951             (select-window owin)))
3952         ;; Mark this buffer as "prepared".
3953         (setq gnus-newsgroup-prepared t)
3954         (gnus-run-hooks 'gnus-summary-prepared-hook)
3955         (unless (gnus-ephemeral-group-p group)
3956           (gnus-group-update-group group))
3957         t)))))
3958
3959 (defun gnus-summary-auto-select-subject ()
3960   "Select the subject line on initial group entry."
3961   (goto-char (point-min))
3962   (cond
3963    ((eq gnus-auto-select-subject 'best)
3964     (gnus-summary-best-unread-subject))
3965    ((eq gnus-auto-select-subject 'unread)
3966     (gnus-summary-first-unread-subject))
3967    ((eq gnus-auto-select-subject 'unseen)
3968     (gnus-summary-first-unseen-subject))
3969    ((eq gnus-auto-select-subject 'unseen-or-unread)
3970     (gnus-summary-first-unseen-or-unread-subject))
3971    ((eq gnus-auto-select-subject 'first)
3972     ;; Do nothing.
3973     )
3974    ((functionp gnus-auto-select-subject)
3975     (funcall gnus-auto-select-subject))))
3976
3977 (defun gnus-summary-prepare ()
3978   "Generate the summary buffer."
3979   (interactive)
3980   (let ((buffer-read-only nil))
3981     (erase-buffer)
3982     (setq gnus-newsgroup-data nil
3983           gnus-newsgroup-data-reverse nil)
3984     (gnus-run-hooks 'gnus-summary-generate-hook)
3985     ;; Generate the buffer, either with threads or without.
3986     (when gnus-newsgroup-headers
3987       (gnus-summary-prepare-threads
3988        (if gnus-show-threads
3989            (gnus-sort-gathered-threads
3990             (funcall gnus-summary-thread-gathering-function
3991                      (gnus-sort-threads
3992                       (gnus-cut-threads (gnus-make-threads)))))
3993          ;; Unthreaded display.
3994          (gnus-sort-articles gnus-newsgroup-headers))))
3995     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3996     ;; Call hooks for modifying summary buffer.
3997     (goto-char (point-min))
3998     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3999
4000 (defsubst gnus-general-simplify-subject (subject)
4001   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4002   (setq subject
4003         (cond
4004          ;; Truncate the subject.
4005          (gnus-simplify-subject-functions
4006           (gnus-map-function gnus-simplify-subject-functions subject))
4007          ((numberp gnus-summary-gather-subject-limit)
4008           (setq subject (gnus-simplify-subject-re subject))
4009           (if (> (length subject) gnus-summary-gather-subject-limit)
4010               (substring subject 0 gnus-summary-gather-subject-limit)
4011             subject))
4012          ;; Fuzzily simplify it.
4013          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4014           (gnus-simplify-subject-fuzzy subject))
4015          ;; Just remove the leading "Re:".
4016          (t
4017           (gnus-simplify-subject-re subject))))
4018
4019   (if (and gnus-summary-gather-exclude-subject
4020            (string-match gnus-summary-gather-exclude-subject subject))
4021       nil                         ; This article shouldn't be gathered
4022     subject))
4023
4024 (defun gnus-summary-simplify-subject-query ()
4025   "Query where the respool algorithm would put this article."
4026   (interactive)
4027   (gnus-summary-select-article)
4028   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4029
4030 (defun gnus-gather-threads-by-subject (threads)
4031   "Gather threads by looking at Subject headers."
4032   (if (not gnus-summary-make-false-root)
4033       threads
4034     (let ((hashtb (gnus-make-hashtable 1024))
4035           (prev threads)
4036           (result threads)
4037           subject hthread whole-subject)
4038       (while threads
4039         (setq subject (gnus-general-simplify-subject
4040                        (setq whole-subject (mail-header-subject
4041                                             (caar threads)))))
4042         (when subject
4043           (if (setq hthread (gnus-gethash subject hashtb))
4044               (progn
4045                 ;; We enter a dummy root into the thread, if we
4046                 ;; haven't done that already.
4047                 (unless (stringp (caar hthread))
4048                   (setcar hthread (list whole-subject (car hthread))))
4049                 ;; We add this new gathered thread to this gathered
4050                 ;; thread.
4051                 (setcdr (car hthread)
4052                         (nconc (cdar hthread) (list (car threads))))
4053                 ;; Remove it from the list of threads.
4054                 (setcdr prev (cdr threads))
4055                 (setq threads prev))
4056             ;; Enter this thread into the hash table.
4057             (gnus-sethash subject
4058                           (if gnus-summary-make-false-root-always
4059                               (progn
4060                                 ;; If you want a dummy root above all
4061                                 ;; threads...
4062                                 (setcar threads (list whole-subject
4063                                                       (car threads)))
4064                                 threads)
4065                             threads)
4066                           hashtb)))
4067         (setq prev threads)
4068         (setq threads (cdr threads)))
4069       result)))
4070
4071 (defun gnus-gather-threads-by-references (threads)
4072   "Gather threads by looking at References headers."
4073   (let ((idhashtb (gnus-make-hashtable 1024))
4074         (thhashtb (gnus-make-hashtable 1024))
4075         (prev threads)
4076         (result threads)
4077         ids references id gthread gid entered ref)
4078     (while threads
4079       (when (setq references (mail-header-references (caar threads)))
4080         (setq id (mail-header-id (caar threads))
4081               ids (inline (gnus-split-references references))
4082               entered nil)
4083         (while (setq ref (pop ids))
4084           (setq ids (delete ref ids))
4085           (if (not (setq gid (gnus-gethash ref idhashtb)))
4086               (progn
4087                 (gnus-sethash ref id idhashtb)
4088                 (gnus-sethash id threads thhashtb))
4089             (setq gthread (gnus-gethash gid thhashtb))
4090             (unless entered
4091               ;; We enter a dummy root into the thread, if we
4092               ;; haven't done that already.
4093               (unless (stringp (caar gthread))
4094                 (setcar gthread (list (mail-header-subject (caar gthread))
4095                                       (car gthread))))
4096               ;; We add this new gathered thread to this gathered
4097               ;; thread.
4098               (setcdr (car gthread)
4099                       (nconc (cdar gthread) (list (car threads)))))
4100             ;; Add it into the thread hash table.
4101             (gnus-sethash id gthread thhashtb)
4102             (setq entered t)
4103             ;; Remove it from the list of threads.
4104             (setcdr prev (cdr threads))
4105             (setq threads prev))))
4106       (setq prev threads)
4107       (setq threads (cdr threads)))
4108     result))
4109
4110 (defun gnus-sort-gathered-threads (threads)
4111   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4112   (let ((result threads))
4113     (while threads
4114       (when (stringp (caar threads))
4115         (setcdr (car threads)
4116                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4117       (setq threads (cdr threads)))
4118     result))
4119
4120 (defun gnus-thread-loop-p (root thread)
4121   "Say whether ROOT is in THREAD."
4122   (let ((stack (list thread))
4123         (infloop 0)
4124         th)
4125     (while (setq thread (pop stack))
4126       (setq th (cdr thread))
4127       (while (and th
4128                   (not (eq (caar th) root)))
4129         (pop th))
4130       (if th
4131           ;; We have found a loop.
4132           (let (ref-dep)
4133             (setcdr thread (delq (car th) (cdr thread)))
4134             (if (boundp (setq ref-dep (intern "none"
4135                                               gnus-newsgroup-dependencies)))
4136                 (setcdr (symbol-value ref-dep)
4137                         (nconc (cdr (symbol-value ref-dep))
4138                                (list (car th))))
4139               (set ref-dep (list nil (car th))))
4140             (setq infloop 1
4141                   stack nil))
4142         ;; Push all the subthreads onto the stack.
4143         (push (cdr thread) stack)))
4144     infloop))
4145
4146 (defun gnus-make-threads ()
4147   "Go through the dependency hashtb and find the roots.  Return all threads."
4148   (let (threads)
4149     (while (catch 'infloop
4150              (mapatoms
4151               (lambda (refs)
4152                 ;; Deal with self-referencing References loops.
4153                 (when (and (car (symbol-value refs))
4154                            (not (zerop
4155                                  (apply
4156                                   '+
4157                                   (mapcar
4158                                    (lambda (thread)
4159                                      (gnus-thread-loop-p
4160                                       (car (symbol-value refs)) thread))
4161                                    (cdr (symbol-value refs)))))))
4162                   (setq threads nil)
4163                   (throw 'infloop t))
4164                 (unless (car (symbol-value refs))
4165                   ;; These threads do not refer back to any other
4166                   ;; articles, so they're roots.
4167                   (setq threads (append (cdr (symbol-value refs)) threads))))
4168               gnus-newsgroup-dependencies)))
4169     threads))
4170
4171 ;; Build the thread tree.
4172 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4173   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4174
4175 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4176 if it was already present.
4177
4178 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4179 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4180 Message-IDs will be renamed to a unique Message-ID before being
4181 entered.
4182
4183 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4184   (let* ((id (mail-header-id header))
4185          (id-dep (and id (intern id dependencies)))
4186          parent-id ref ref-dep ref-header replaced)
4187     ;; Enter this `header' in the `dependencies' table.
4188     (cond
4189      ((not id-dep)
4190       (setq header nil))
4191      ;; The first two cases do the normal part: enter a new `header'
4192      ;; in the `dependencies' table.
4193      ((not (boundp id-dep))
4194       (set id-dep (list header)))
4195      ((null (car (symbol-value id-dep)))
4196       (setcar (symbol-value id-dep) header))
4197
4198      ;; From here the `header' was already present in the
4199      ;; `dependencies' table.
4200      (force-new
4201       ;; Overrides an existing entry;
4202       ;; just set the header part of the entry.
4203       (setcar (symbol-value id-dep) header)
4204       (setq replaced t))
4205
4206      ;; Renames the existing `header' to a unique Message-ID.
4207      ((not gnus-summary-ignore-duplicates)
4208       ;; An article with this Message-ID has already been seen.
4209       ;; We rename the Message-ID.
4210       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4211            (list header))
4212       (mail-header-set-id header id))
4213
4214      ;; The last case ignores an existing entry, except it adds any
4215      ;; additional Xrefs (in case the two articles came from different
4216      ;; servers.
4217      ;; Also sets `header' to `nil' meaning that the `dependencies'
4218      ;; table was *not* modified.
4219      (t
4220       (mail-header-set-xref
4221        (car (symbol-value id-dep))
4222        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4223                    "")
4224                (or (mail-header-xref header) "")))
4225       (setq header nil)))
4226
4227     (when (and header (not replaced))
4228       ;; First check that we are not creating a References loop.
4229       (setq parent-id (gnus-parent-id (mail-header-references header)))
4230       (setq ref parent-id)
4231       (while (and ref
4232                   (setq ref-dep (intern-soft ref dependencies))
4233                   (boundp ref-dep)
4234                   (setq ref-header (car (symbol-value ref-dep))))
4235         (if (string= id ref)
4236             ;; Yuk!  This is a reference loop.  Make the article be a
4237             ;; root article.
4238             (progn
4239               (mail-header-set-references (car (symbol-value id-dep)) "none")
4240               (setq ref nil)
4241               (setq parent-id nil))
4242           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4243       (setq ref-dep (intern (or parent-id "none") dependencies))
4244       (if (boundp ref-dep)
4245           (setcdr (symbol-value ref-dep)
4246                   (nconc (cdr (symbol-value ref-dep))
4247                          (list (symbol-value id-dep))))
4248         (set ref-dep (list nil (symbol-value id-dep)))))
4249     header))
4250
4251 (defun gnus-extract-message-id-from-in-reply-to (string)
4252   (if (string-match "<[^>]+>" string)
4253       (substring string (match-beginning 0) (match-end 0))
4254     nil))
4255
4256 (defun gnus-build-sparse-threads ()
4257   (let ((headers gnus-newsgroup-headers)
4258         (mail-parse-charset gnus-newsgroup-charset)
4259         (gnus-summary-ignore-duplicates t)
4260         header references generation relations
4261         subject child end new-child date)
4262     ;; First we create an alist of generations/relations, where
4263     ;; generations is how much we trust the relation, and the relation
4264     ;; is parent/child.
4265     (gnus-message 7 "Making sparse threads...")
4266     (save-excursion
4267       (nnheader-set-temp-buffer " *gnus sparse threads*")
4268       (while (setq header (pop headers))
4269         (when (and (setq references (mail-header-references header))
4270                    (not (string= references "")))
4271           (insert references)
4272           (setq child (mail-header-id header)
4273                 subject (mail-header-subject header)
4274                 date (mail-header-date header)
4275                 generation 0)
4276           (while (search-backward ">" nil t)
4277             (setq end (1+ (point)))
4278             (when (search-backward "<" nil t)
4279               (setq new-child (buffer-substring (point) end))
4280               (push (list (incf generation)
4281                           child (setq child new-child)
4282                           subject date)
4283                     relations)))
4284           (when child
4285             (push (list (1+ generation) child nil subject) relations))
4286           (erase-buffer)))
4287       (kill-buffer (current-buffer)))
4288     ;; Sort over trustworthiness.
4289     (dolist (relation (sort relations 'car-less-than-car))
4290       (when (gnus-dependencies-add-header
4291              (make-full-mail-header
4292               gnus-reffed-article-number
4293               (nth 3 relation) "" (or (nth 4 relation) "")
4294               (nth 1 relation)
4295               (or (nth 2 relation) "") 0 0 "")
4296              gnus-newsgroup-dependencies nil)
4297         (push gnus-reffed-article-number gnus-newsgroup-limit)
4298         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4299         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4300               gnus-newsgroup-reads)
4301         (decf gnus-reffed-article-number)))
4302     (gnus-message 7 "Making sparse threads...done")))
4303
4304 (defun gnus-build-old-threads ()
4305   ;; Look at all the articles that refer back to old articles, and
4306   ;; fetch the headers for the articles that aren't there.  This will
4307   ;; build complete threads - if the roots haven't been expired by the
4308   ;; server, that is.
4309   (let ((mail-parse-charset gnus-newsgroup-charset)
4310         id heads)
4311     (mapatoms
4312      (lambda (refs)
4313        (when (not (car (symbol-value refs)))
4314          (setq heads (cdr (symbol-value refs)))
4315          (while heads
4316            (if (memq (mail-header-number (caar heads))
4317                      gnus-newsgroup-dormant)
4318                (setq heads (cdr heads))
4319              (setq id (symbol-name refs))
4320              (while (and (setq id (gnus-build-get-header id))
4321                          (not (car (gnus-id-to-thread id)))))
4322              (setq heads nil)))))
4323      gnus-newsgroup-dependencies)))
4324
4325 (defsubst gnus-remove-odd-characters (string)
4326   "Translate STRING into something that doesn't contain weird characters."
4327   (mm-subst-char-in-string
4328    ?\r ?\-
4329    (mm-subst-char-in-string ?\n ?\- string t) t))
4330
4331 ;; This function has to be called with point after the article number
4332 ;; on the beginning of the line.
4333 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4334   (let ((eol (point-at-eol))
4335         (buffer (current-buffer))
4336         header references in-reply-to)
4337
4338     ;; overview: [num subject from date id refs chars lines misc]
4339     (unwind-protect
4340         (let (x)
4341           (narrow-to-region (point) eol)
4342           (unless (eobp)
4343             (forward-char))
4344
4345           (setq header
4346                 (make-full-mail-header
4347                  number                 ; number
4348                  (condition-case ()     ; subject
4349                      (gnus-remove-odd-characters
4350                       (funcall gnus-decode-encoded-word-function
4351                                (setq x (nnheader-nov-field))))
4352                    (error x))
4353                  (condition-case ()     ; from
4354                      (gnus-remove-odd-characters
4355                       (funcall gnus-decode-encoded-address-function
4356                                (setq x (nnheader-nov-field))))
4357                    (error x))
4358                  (nnheader-nov-field)   ; date
4359                  (nnheader-nov-read-message-id number)  ; id
4360                  (setq references (nnheader-nov-field)) ; refs
4361                  (nnheader-nov-read-integer) ; chars
4362                  (nnheader-nov-read-integer) ; lines
4363                  (unless (eobp)
4364                    (if (looking-at "Xref: ")
4365                        (goto-char (match-end 0)))
4366                    (nnheader-nov-field)) ; Xref
4367                  (nnheader-nov-parse-extra)))) ; extra
4368
4369       (widen))
4370
4371     (when (and (string= references "")
4372                (setq in-reply-to (mail-header-extra header))
4373                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4374       (mail-header-set-references
4375        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4376
4377     (when gnus-alter-header-function
4378       (funcall gnus-alter-header-function header))
4379     (gnus-dependencies-add-header header dependencies force-new)))
4380
4381 (defun gnus-build-get-header (id)
4382   "Look through the buffer of NOV lines and find the header to ID.
4383 Enter this line into the dependencies hash table, and return
4384 the id of the parent article (if any)."
4385   (let ((deps gnus-newsgroup-dependencies)
4386         found header)
4387     (prog1
4388         (save-excursion
4389           (set-buffer nntp-server-buffer)
4390           (let ((case-fold-search nil))
4391             (goto-char (point-min))
4392             (while (and (not found)
4393                         (search-forward id nil t))
4394               (beginning-of-line)
4395               (setq found (looking-at
4396                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4397                                    (regexp-quote id))))
4398               (or found (beginning-of-line 2)))
4399             (when found
4400               (beginning-of-line)
4401               (and
4402                (setq header (gnus-nov-parse-line
4403                              (read (current-buffer)) deps))
4404                (gnus-parent-id (mail-header-references header))))))
4405       (when header
4406         (let ((number (mail-header-number header)))
4407           (push number gnus-newsgroup-limit)
4408           (push header gnus-newsgroup-headers)
4409           (if (memq number gnus-newsgroup-unselected)
4410               (progn
4411                 (setq gnus-newsgroup-unreads
4412                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4413                                                number))
4414                 (setq gnus-newsgroup-unselected
4415                       (delq number gnus-newsgroup-unselected)))
4416             (push number gnus-newsgroup-ancient)))))))
4417
4418 (defun gnus-build-all-threads ()
4419   "Read all the headers."
4420   (let ((gnus-summary-ignore-duplicates t)
4421         (mail-parse-charset gnus-newsgroup-charset)
4422         (dependencies gnus-newsgroup-dependencies)
4423         header article)
4424     (save-excursion
4425       (set-buffer nntp-server-buffer)
4426       (let ((case-fold-search nil))
4427         (goto-char (point-min))
4428         (while (not (eobp))
4429           (ignore-errors
4430             (setq article (read (current-buffer))
4431                   header (gnus-nov-parse-line article dependencies)))
4432           (when header
4433             (with-current-buffer gnus-summary-buffer
4434               (push header gnus-newsgroup-headers)
4435               (if (memq (setq article (mail-header-number header))
4436                         gnus-newsgroup-unselected)
4437                   (progn
4438                     (setq gnus-newsgroup-unreads
4439                           (gnus-add-to-sorted-list
4440                            gnus-newsgroup-unreads article))
4441                     (setq gnus-newsgroup-unselected
4442                           (delq article gnus-newsgroup-unselected)))
4443                 (push article gnus-newsgroup-ancient)))
4444             (forward-line 1)))))))
4445
4446 (defun gnus-summary-update-article-line (article header)
4447   "Update the line for ARTICLE using HEADER."
4448   (let* ((id (mail-header-id header))
4449          (thread (gnus-id-to-thread id)))
4450     (unless thread
4451       (error "Article in no thread"))
4452     ;; Update the thread.
4453     (setcar thread header)
4454     (gnus-summary-goto-subject article)
4455     (let* ((datal (gnus-data-find-list article))
4456            (data (car datal))
4457            (buffer-read-only nil)
4458            (level (gnus-summary-thread-level)))
4459       (gnus-delete-line)
4460       (let ((inserted (- (point)
4461                          (progn
4462                            (gnus-summary-insert-line
4463                             header level nil
4464                             (memq article gnus-newsgroup-undownloaded)
4465                             (gnus-article-mark article)
4466                             (memq article gnus-newsgroup-replied)
4467                             (memq article gnus-newsgroup-expirable)
4468                             ;; Only insert the Subject string when it's different
4469                             ;; from the previous Subject string.
4470                             (if (and
4471                                  gnus-show-threads
4472                                  (gnus-subject-equal
4473                                   (condition-case ()
4474                                       (mail-header-subject
4475                                        (gnus-data-header
4476                                         (cadr
4477                                          (gnus-data-find-list
4478                                           article
4479                                           (gnus-data-list t)))))
4480                                     ;; Error on the side of excessive subjects.
4481                                     (error ""))
4482                                   (mail-header-subject header)))
4483                                 ""
4484                               (mail-header-subject header))
4485                             nil (cdr (assq article gnus-newsgroup-scored))
4486                             (memq article gnus-newsgroup-processable))
4487                            (point)))))
4488         (when (cdr datal)
4489           (gnus-data-update-list
4490            (cdr datal)
4491            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4492
4493 (defun gnus-summary-update-article (article &optional iheader)
4494   "Update ARTICLE in the summary buffer."
4495   (set-buffer gnus-summary-buffer)
4496   (let* ((header (gnus-summary-article-header article))
4497          (id (mail-header-id header))
4498          (data (gnus-data-find article))
4499          (thread (gnus-id-to-thread id))
4500          (references (mail-header-references header))
4501          (parent
4502           (gnus-id-to-thread
4503            (or (gnus-parent-id
4504                 (when (and references
4505                            (not (equal "" references)))
4506                   references))
4507                "none")))
4508          (buffer-read-only nil)
4509          (old (car thread)))
4510     (when thread
4511       (unless iheader
4512         (setcar thread nil)
4513         (when parent
4514           (delq thread parent)))
4515       (if (gnus-summary-insert-subject id header)
4516           ;; Set the (possibly) new article number in the data structure.
4517           (gnus-data-set-number data (gnus-id-to-article id))
4518         (setcar thread old)
4519         nil))))
4520
4521 (defun gnus-rebuild-thread (id &optional line)
4522   "Rebuild the thread containing ID.
4523 If LINE, insert the rebuilt thread starting on line LINE."
4524   (let ((buffer-read-only nil)
4525         old-pos current thread data)
4526     (if (not gnus-show-threads)
4527         (setq thread (list (car (gnus-id-to-thread id))))
4528       ;; Get the thread this article is part of.
4529       (setq thread (gnus-remove-thread id)))
4530     (setq old-pos (point-at-bol))
4531     (setq current (save-excursion
4532                     (and (re-search-backward "[\r\n]" nil t)
4533                          (gnus-summary-article-number))))
4534     ;; If this is a gathered thread, we have to go some re-gathering.
4535     (when (stringp (car thread))
4536       (let ((subject (car thread))
4537             roots thr)
4538         (setq thread (cdr thread))
4539         (while thread
4540           (unless (memq (setq thr (gnus-id-to-thread
4541                                    (gnus-root-id
4542                                     (mail-header-id (caar thread)))))
4543                         roots)
4544             (push thr roots))
4545           (setq thread (cdr thread)))
4546         ;; We now have all (unique) roots.
4547         (if (= (length roots) 1)
4548             ;; All the loose roots are now one solid root.
4549             (setq thread (car roots))
4550           (setq thread (cons subject (gnus-sort-threads roots))))))
4551     (let (threads)
4552       ;; We then insert this thread into the summary buffer.
4553       (when line
4554         (goto-char (point-min))
4555         (forward-line (1- line)))
4556       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4557         (if gnus-show-threads
4558             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4559           (gnus-summary-prepare-unthreaded thread))
4560         (setq data (nreverse gnus-newsgroup-data))
4561         (setq threads gnus-newsgroup-threads))
4562       ;; We splice the new data into the data structure.
4563       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4564       ;;!!! then we want to insert at the beginning of the buffer.
4565       ;;!!! That happens to be true with Gnus now, but that may
4566       ;;!!! change in the future.  Perhaps.
4567       (gnus-data-enter-list
4568        (if line nil current) data (- (point) old-pos))
4569       (setq gnus-newsgroup-threads
4570             (nconc threads gnus-newsgroup-threads))
4571       (gnus-data-compute-positions))))
4572
4573 (defun gnus-number-to-header (number)
4574   "Return the header for article NUMBER."
4575   (let ((headers gnus-newsgroup-headers))
4576     (while (and headers
4577                 (not (= number (mail-header-number (car headers)))))
4578       (pop headers))
4579     (when headers
4580       (car headers))))
4581
4582 (defun gnus-parent-headers (in-headers &optional generation)
4583   "Return the headers of the GENERATIONeth parent of HEADERS."
4584   (unless generation
4585     (setq generation 1))
4586   (let ((parent t)
4587         (headers in-headers)
4588         references)
4589     (while (and parent
4590                 (not (zerop generation))
4591                 (setq references (mail-header-references headers)))
4592       (setq headers (if (and references
4593                              (setq parent (gnus-parent-id references)))
4594                         (car (gnus-id-to-thread parent))
4595                       nil))
4596       (decf generation))
4597     (and (not (eq headers in-headers))
4598          headers)))
4599
4600 (defun gnus-id-to-thread (id)
4601   "Return the (sub-)thread where ID appears."
4602   (gnus-gethash id gnus-newsgroup-dependencies))
4603
4604 (defun gnus-id-to-article (id)
4605   "Return the article number of ID."
4606   (let ((thread (gnus-id-to-thread id)))
4607     (when (and thread
4608                (car thread))
4609       (mail-header-number (car thread)))))
4610
4611 (defun gnus-id-to-header (id)
4612   "Return the article headers of ID."
4613   (car (gnus-id-to-thread id)))
4614
4615 (defun gnus-article-displayed-root-p (article)
4616   "Say whether ARTICLE is a root(ish) article."
4617   (let ((level (gnus-summary-thread-level article))
4618         (refs (mail-header-references  (gnus-summary-article-header article)))
4619         particle)
4620     (cond
4621      ((null level) nil)
4622      ((zerop level) t)
4623      ((null refs) t)
4624      ((null (gnus-parent-id refs)) t)
4625      ((and (= 1 level)
4626            (null (setq particle (gnus-id-to-article
4627                                  (gnus-parent-id refs))))
4628            (null (gnus-summary-thread-level particle)))))))
4629
4630 (defun gnus-root-id (id)
4631   "Return the id of the root of the thread where ID appears."
4632   (let (last-id prev)
4633     (while (and id (setq prev (car (gnus-id-to-thread id))))
4634       (setq last-id id
4635             id (gnus-parent-id (mail-header-references prev))))
4636     last-id))
4637
4638 (defun gnus-articles-in-thread (thread)
4639   "Return the list of articles in THREAD."
4640   (cons (mail-header-number (car thread))
4641         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4642
4643 (defun gnus-remove-thread (id &optional dont-remove)
4644   "Remove the thread that has ID in it."
4645   (let (headers thread last-id)
4646     ;; First go up in this thread until we find the root.
4647     (setq last-id (gnus-root-id id)
4648           headers (message-flatten-list (gnus-id-to-thread last-id)))
4649     ;; We have now found the real root of this thread.  It might have
4650     ;; been gathered into some loose thread, so we have to search
4651     ;; through the threads to find the thread we wanted.
4652     (let ((threads gnus-newsgroup-threads)
4653           sub)
4654       (while threads
4655         (setq sub (car threads))
4656         (if (stringp (car sub))
4657             ;; This is a gathered thread, so we look at the roots
4658             ;; below it to find whether this article is in this
4659             ;; gathered root.
4660             (progn
4661               (setq sub (cdr sub))
4662               (while sub
4663                 (when (member (caar sub) headers)
4664                   (setq thread (car threads)
4665                         threads nil
4666                         sub nil))
4667                 (setq sub (cdr sub))))
4668           ;; It's an ordinary thread, so we check it.
4669           (when (eq (car sub) (car headers))
4670             (setq thread sub
4671                   threads nil)))
4672         (setq threads (cdr threads)))
4673       ;; If this article is in no thread, then it's a root.
4674       (if thread
4675           (unless dont-remove
4676             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4677         (setq thread (gnus-id-to-thread last-id)))
4678       (when thread
4679         (prog1
4680             thread                      ; We return this thread.
4681           (unless dont-remove
4682             (if (stringp (car thread))
4683                 (progn
4684                   ;; If we use dummy roots, then we have to remove the
4685                   ;; dummy root as well.
4686                   (when (eq gnus-summary-make-false-root 'dummy)
4687                     ;; We go to the dummy root by going to
4688                     ;; the first sub-"thread", and then one line up.
4689                     (gnus-summary-goto-article
4690                      (mail-header-number (caadr thread)))
4691                     (forward-line -1)
4692                     (gnus-delete-line)
4693                     (gnus-data-compute-positions))
4694                   (setq thread (cdr thread))
4695                   (while thread
4696                     (gnus-remove-thread-1 (car thread))
4697                     (setq thread (cdr thread))))
4698               (gnus-remove-thread-1 thread))))))))
4699
4700 (defun gnus-remove-thread-1 (thread)
4701   "Remove the thread THREAD recursively."
4702   (let ((number (mail-header-number (pop thread)))
4703         d)
4704     (setq thread (reverse thread))
4705     (while thread
4706       (gnus-remove-thread-1 (pop thread)))
4707     (when (setq d (gnus-data-find number))
4708       (goto-char (gnus-data-pos d))
4709       (gnus-summary-show-thread)
4710       (gnus-data-remove
4711        number
4712        (- (point-at-bol)
4713           (prog1
4714               (1+ (point-at-eol))
4715             (gnus-delete-line)))))))
4716
4717 (defun gnus-sort-threads-recursive (threads func)
4718   (sort (mapcar (lambda (thread)
4719                   (cons (car thread)
4720                         (and (cdr thread)
4721                              (gnus-sort-threads-recursive (cdr thread) func))))
4722                 threads) func))
4723
4724 (defun gnus-sort-threads-loop (threads func)
4725   (let* ((superthread (cons nil threads))
4726          (stack (list (cons superthread threads)))
4727          remaining-threads thread)
4728     (while stack
4729       (setq remaining-threads (cdr (car stack)))
4730       (if remaining-threads
4731           (progn (setq thread (car remaining-threads))
4732                  (setcdr (car stack) (cdr remaining-threads))
4733                  (if (cdr thread)
4734                      (push (cons thread (cdr thread)) stack)))
4735         (setq thread (caar stack))
4736         (setcdr thread (sort (cdr thread) func))
4737         (pop stack)))
4738     (cdr superthread)))
4739
4740 (defun gnus-sort-threads (threads)
4741   "Sort THREADS."
4742   (if (not gnus-thread-sort-functions)
4743       threads
4744     (gnus-message 8 "Sorting threads...")
4745     (prog1
4746         (condition-case nil
4747             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4748               (gnus-sort-threads-recursive
4749                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4750           ;; Even after binding max-lisp-eval-depth, the recursive
4751           ;; sorter might fail for very long threads.  In that case,
4752           ;; try using a (less well-tested) non-recursive sorter.
4753           (error (gnus-sort-threads-loop
4754                   threads (gnus-make-sort-function
4755                            gnus-thread-sort-functions))))
4756       (gnus-message 8 "Sorting threads...done"))))
4757
4758 (defun gnus-sort-articles (articles)
4759   "Sort ARTICLES."
4760   (when gnus-article-sort-functions
4761     (gnus-message 7 "Sorting articles...")
4762     (prog1
4763         (setq gnus-newsgroup-headers
4764               (sort articles (gnus-make-sort-function
4765                               gnus-article-sort-functions)))
4766       (gnus-message 7 "Sorting articles...done"))))
4767
4768 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4769 (defmacro gnus-thread-header (thread)
4770   "Return header of first article in THREAD.
4771 Note that THREAD must never, ever be anything else than a variable -
4772 using some other form will lead to serious barfage."
4773   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4774   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4775   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4776         (vector thread) 2))
4777
4778 (defsubst gnus-article-sort-by-number (h1 h2)
4779   "Sort articles by article number."
4780   (< (mail-header-number h1)
4781      (mail-header-number h2)))
4782
4783 (defun gnus-thread-sort-by-number (h1 h2)
4784   "Sort threads by root article number."
4785   (gnus-article-sort-by-number
4786    (gnus-thread-header h1) (gnus-thread-header h2)))
4787
4788 (defsubst gnus-article-sort-by-random (h1 h2)
4789   "Sort articles by article number."
4790   (zerop (random 2)))
4791
4792 (defun gnus-thread-sort-by-random (h1 h2)
4793   "Sort threads by root article number."
4794   (gnus-article-sort-by-random
4795    (gnus-thread-header h1) (gnus-thread-header h2)))
4796
4797 (defsubst gnus-article-sort-by-lines (h1 h2)
4798   "Sort articles by article Lines header."
4799   (< (mail-header-lines h1)
4800      (mail-header-lines h2)))
4801
4802 (defun gnus-thread-sort-by-lines (h1 h2)
4803   "Sort threads by root article Lines header."
4804   (gnus-article-sort-by-lines
4805    (gnus-thread-header h1) (gnus-thread-header h2)))
4806
4807 (defsubst gnus-article-sort-by-chars (h1 h2)
4808   "Sort articles by octet length."
4809   (< (mail-header-chars h1)
4810      (mail-header-chars h2)))
4811
4812 (defun gnus-thread-sort-by-chars (h1 h2)
4813   "Sort threads by root article octet length."
4814   (gnus-article-sort-by-chars
4815    (gnus-thread-header h1) (gnus-thread-header h2)))
4816
4817 (defsubst gnus-article-sort-by-author (h1 h2)
4818   "Sort articles by root author."
4819   (gnus-string<
4820    (let ((extract (funcall
4821                    gnus-extract-address-components
4822                    (mail-header-from h1))))
4823      (or (car extract) (cadr extract) ""))
4824    (let ((extract (funcall
4825                    gnus-extract-address-components
4826                    (mail-header-from h2))))
4827      (or (car extract) (cadr extract) ""))))
4828
4829 (defun gnus-thread-sort-by-author (h1 h2)
4830   "Sort threads by root author."
4831   (gnus-article-sort-by-author
4832    (gnus-thread-header h1)  (gnus-thread-header h2)))
4833
4834 (defsubst gnus-article-sort-by-recipient (h1 h2)
4835   "Sort articles by recipient."
4836   (gnus-string<
4837    (let ((extract (funcall
4838                    gnus-extract-address-components
4839                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4840      (or (car extract) (cadr extract)))
4841    (let ((extract (funcall
4842                    gnus-extract-address-components
4843                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4844      (or (car extract) (cadr extract)))))
4845
4846 (defun gnus-thread-sort-by-recipient (h1 h2)
4847   "Sort threads by root recipient."
4848   (gnus-article-sort-by-recipient
4849    (gnus-thread-header h1) (gnus-thread-header h2)))
4850
4851 (defsubst gnus-article-sort-by-subject (h1 h2)
4852   "Sort articles by root subject."
4853   (gnus-string<
4854    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4855    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4856
4857 (defun gnus-thread-sort-by-subject (h1 h2)
4858   "Sort threads by root subject."
4859   (gnus-article-sort-by-subject
4860    (gnus-thread-header h1) (gnus-thread-header h2)))
4861
4862 (defsubst gnus-article-sort-by-date (h1 h2)
4863   "Sort articles by root article date."
4864   (time-less-p
4865    (gnus-date-get-time (mail-header-date h1))
4866    (gnus-date-get-time (mail-header-date h2))))
4867
4868 (defun gnus-thread-sort-by-date (h1 h2)
4869   "Sort threads by root article date."
4870   (gnus-article-sort-by-date
4871    (gnus-thread-header h1) (gnus-thread-header h2)))
4872
4873 (defsubst gnus-article-sort-by-score (h1 h2)
4874   "Sort articles by root article score.
4875 Unscored articles will be counted as having a score of zero."
4876   (> (or (cdr (assq (mail-header-number h1)
4877                     gnus-newsgroup-scored))
4878          gnus-summary-default-score 0)
4879      (or (cdr (assq (mail-header-number h2)
4880                     gnus-newsgroup-scored))
4881          gnus-summary-default-score 0)))
4882
4883 (defun gnus-thread-sort-by-score (h1 h2)
4884   "Sort threads by root article score."
4885   (gnus-article-sort-by-score
4886    (gnus-thread-header h1) (gnus-thread-header h2)))
4887
4888 (defun gnus-thread-sort-by-total-score (h1 h2)
4889   "Sort threads by the sum of all scores in the thread.
4890 Unscored articles will be counted as having a score of zero."
4891   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4892
4893 (defun gnus-thread-total-score (thread)
4894   ;; This function find the total score of THREAD.
4895   (cond
4896    ((null thread)
4897     0)
4898    ((consp thread)
4899     (if (stringp (car thread))
4900         (apply gnus-thread-score-function 0
4901                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4902       (gnus-thread-total-score-1 thread)))
4903    (t
4904     (gnus-thread-total-score-1 (list thread)))))
4905
4906 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4907   "Sort threads such that the thread with the most recently arrived article comes first."
4908   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4909
4910 (defun gnus-thread-highest-number (thread)
4911   "Return the highest article number in THREAD."
4912   (apply 'max (mapcar (lambda (header)
4913                         (mail-header-number header))
4914                       (message-flatten-list thread))))
4915
4916 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4917   "Sort threads such that the thread with the most recently dated article comes first."
4918   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4919
4920 (defun gnus-thread-latest-date (thread)
4921   "Return the highest article date in THREAD."
4922   (let ((previous-time 0))
4923     (apply 'max
4924            (mapcar
4925             (lambda (header)
4926               (setq previous-time
4927                     (condition-case ()
4928                         (time-to-seconds (mail-header-parse-date
4929                                           (mail-header-date header)))
4930                       (error previous-time))))
4931             (sort
4932              (message-flatten-list thread)
4933              (lambda (h1 h2)
4934                (< (mail-header-number h1)
4935                   (mail-header-number h2))))))))
4936
4937 (defun gnus-thread-total-score-1 (root)
4938   ;; This function find the total score of the thread below ROOT.
4939   (setq root (car root))
4940   (apply gnus-thread-score-function
4941          (or (append
4942               (mapcar 'gnus-thread-total-score
4943                       (cdr (gnus-id-to-thread (mail-header-id root))))
4944               (when (> (mail-header-number root) 0)
4945                 (list (or (cdr (assq (mail-header-number root)
4946                                      gnus-newsgroup-scored))
4947                           gnus-summary-default-score 0))))
4948              (list gnus-summary-default-score)
4949              '(0))))
4950
4951 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4952 (defvar gnus-tmp-prev-subject nil)
4953 (defvar gnus-tmp-false-parent nil)
4954 (defvar gnus-tmp-root-expunged nil)
4955 (defvar gnus-tmp-dummy-line nil)
4956
4957 (eval-when-compile (defvar gnus-tmp-header))
4958 (defun gnus-extra-header (type &optional header)
4959   "Return the extra header of TYPE."
4960   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4961       ""))
4962
4963 (defvar gnus-tmp-thread-tree-header-string "")
4964
4965 (defcustom gnus-sum-thread-tree-root "> "
4966   "With %B spec, used for the root of a thread.
4967 If nil, use subject instead."
4968   :version "22.1"
4969   :type '(radio (const :format "%v  " nil) string)
4970   :group 'gnus-thread)
4971
4972 (defcustom gnus-sum-thread-tree-false-root "> "
4973   "With %B spec, used for a false root of a thread.
4974 If nil, use subject instead."
4975   :version "22.1"
4976   :type '(radio (const :format "%v  " nil) string)
4977   :group 'gnus-thread)
4978
4979 (defcustom gnus-sum-thread-tree-single-indent ""
4980   "With %B spec, used for a thread with just one message.
4981 If nil, use subject instead."
4982   :version "22.1"
4983   :type '(radio (const :format "%v  " nil) string)
4984   :group 'gnus-thread)
4985
4986 (defcustom gnus-sum-thread-tree-vertical "| "
4987   "With %B spec, used for drawing a vertical line."
4988   :version "22.1"
4989   :type 'string
4990   :group 'gnus-thread)
4991
4992 (defcustom gnus-sum-thread-tree-indent "  "
4993   "With %B spec, used for indenting."
4994   :version "22.1"
4995   :type 'string
4996   :group 'gnus-thread)
4997
4998 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4999   "With %B spec, used for a leaf with brothers."
5000   :version "22.1"
5001   :type 'string
5002   :group 'gnus-thread)
5003
5004 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5005   "With %B spec, used for a leaf without brothers."
5006   :version "22.1"
5007   :type 'string
5008   :group 'gnus-thread)
5009
5010 (defun gnus-summary-prepare-threads (threads)
5011   "Prepare summary buffer from THREADS and indentation LEVEL.
5012 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5013 or a straight list of headers."
5014   (gnus-message 7 "Generating summary...")
5015
5016   (setq gnus-newsgroup-threads threads)
5017   (beginning-of-line)
5018
5019   (let ((gnus-tmp-level 0)
5020         (default-score (or gnus-summary-default-score 0))
5021         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5022         (building-line-count gnus-summary-display-while-building)
5023         (building-count (integerp gnus-summary-display-while-building))
5024         thread number subject stack state gnus-tmp-gathered beg-match
5025         new-roots gnus-tmp-new-adopts thread-end simp-subject
5026         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5027         gnus-tmp-replied gnus-tmp-subject-or-nil
5028         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5029         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5030         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5031         tree-stack)
5032
5033     (setq gnus-tmp-prev-subject nil
5034           gnus-tmp-thread-tree-header-string "")
5035
5036     (if (vectorp (car threads))
5037         ;; If this is a straight (sic) list of headers, then a
5038         ;; threaded summary display isn't required, so we just create
5039         ;; an unthreaded one.
5040         (gnus-summary-prepare-unthreaded threads)
5041
5042       ;; Do the threaded display.
5043
5044       (if gnus-summary-display-while-building
5045           (switch-to-buffer (buffer-name)))
5046       (while (or threads stack gnus-tmp-new-adopts new-roots)
5047
5048         (if (and (= gnus-tmp-level 0)
5049                  (or (not stack)
5050                      (= (caar stack) 0))
5051                  (not gnus-tmp-false-parent)
5052                  (or gnus-tmp-new-adopts new-roots))
5053             (if gnus-tmp-new-adopts
5054                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5055                       thread (list (car gnus-tmp-new-adopts))
5056                       gnus-tmp-header (caar thread)
5057                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5058               (when new-roots
5059                 (setq thread (list (car new-roots))
5060                       gnus-tmp-header (caar thread)
5061                       new-roots (cdr new-roots))))
5062
5063           (if threads
5064               ;; If there are some threads, we do them before the
5065               ;; threads on the stack.
5066               (setq thread threads
5067                     gnus-tmp-header (caar thread))
5068             ;; There were no current threads, so we pop something off
5069             ;; the stack.
5070             (setq state (car stack)
5071                   gnus-tmp-level (car state)
5072                   tree-stack (cadr state)
5073                   thread (caddr state)
5074                   stack (cdr stack)
5075                   gnus-tmp-header (caar thread))))
5076
5077         (setq gnus-tmp-false-parent nil)
5078         (setq gnus-tmp-root-expunged nil)
5079         (setq thread-end nil)
5080
5081         (if (stringp gnus-tmp-header)
5082             ;; The header is a dummy root.
5083             (cond
5084              ((eq gnus-summary-make-false-root 'adopt)
5085               ;; We let the first article adopt the rest.
5086               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5087                                                (cddar thread)))
5088               (setq gnus-tmp-gathered
5089                     (nconc (mapcar
5090                             (lambda (h) (mail-header-number (car h)))
5091                             (cddar thread))
5092                            gnus-tmp-gathered))
5093               (setq thread (cons (list (caar thread)
5094                                        (cadar thread))
5095                                  (cdr thread)))
5096               (setq gnus-tmp-level -1
5097                     gnus-tmp-false-parent t))
5098              ((eq gnus-summary-make-false-root 'empty)
5099               ;; We print adopted articles with empty subject fields.
5100               (setq gnus-tmp-gathered
5101                     (nconc (mapcar
5102                             (lambda (h) (mail-header-number (car h)))
5103                             (cddar thread))
5104                            gnus-tmp-gathered))
5105               (setq gnus-tmp-level -1))
5106              ((eq gnus-summary-make-false-root 'dummy)
5107               ;; We remember that we probably want to output a dummy
5108               ;; root.
5109               (setq gnus-tmp-dummy-line gnus-tmp-header)
5110               (setq gnus-tmp-prev-subject gnus-tmp-header))
5111              (t
5112               ;; We do not make a root for the gathered
5113               ;; sub-threads at all.
5114               (setq gnus-tmp-level -1)))
5115
5116           (setq number (mail-header-number gnus-tmp-header)
5117                 subject (mail-header-subject gnus-tmp-header)
5118                 simp-subject (gnus-simplify-subject-fully subject))
5119
5120           (cond
5121            ;; If the thread has changed subject, we might want to make
5122            ;; this subthread into a root.
5123            ((and (null gnus-thread-ignore-subject)
5124                  (not (zerop gnus-tmp-level))
5125                  gnus-tmp-prev-subject
5126                  (not (string= gnus-tmp-prev-subject simp-subject)))
5127             (setq new-roots (nconc new-roots (list (car thread)))
5128                   thread-end t
5129                   gnus-tmp-header nil))
5130            ;; If the article lies outside the current limit,
5131            ;; then we do not display it.
5132            ((not (memq number gnus-newsgroup-limit))
5133             (setq gnus-tmp-gathered
5134                   (nconc (mapcar
5135                           (lambda (h) (mail-header-number (car h)))
5136                           (cdar thread))
5137                          gnus-tmp-gathered))
5138             (setq gnus-tmp-new-adopts (if (cdar thread)
5139                                           (append gnus-tmp-new-adopts
5140                                                   (cdar thread))
5141                                         gnus-tmp-new-adopts)
5142                   thread-end t
5143                   gnus-tmp-header nil)
5144             (when (zerop gnus-tmp-level)
5145               (setq gnus-tmp-root-expunged t)))
5146            ;; Perhaps this article is to be marked as read?
5147            ((and gnus-summary-mark-below
5148                  (< (or (cdr (assq number gnus-newsgroup-scored))
5149                         default-score)
5150                     gnus-summary-mark-below)
5151                  ;; Don't touch sparse articles.
5152                  (not (gnus-summary-article-sparse-p number))
5153                  (not (gnus-summary-article-ancient-p number)))
5154             (setq gnus-newsgroup-unreads
5155                   (delq number gnus-newsgroup-unreads))
5156             (if gnus-newsgroup-auto-expire
5157                 (setq gnus-newsgroup-expirable
5158                       (gnus-add-to-sorted-list
5159                        gnus-newsgroup-expirable number))
5160               (push (cons number gnus-low-score-mark)
5161                     gnus-newsgroup-reads))))
5162
5163           (when gnus-tmp-header
5164             ;; We may have an old dummy line to output before this
5165             ;; article.
5166             (when (and gnus-tmp-dummy-line
5167                        (gnus-subject-equal
5168                         gnus-tmp-dummy-line
5169                         (mail-header-subject gnus-tmp-header)))
5170               (gnus-summary-insert-dummy-line
5171                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5172               (setq gnus-tmp-dummy-line nil))
5173
5174             ;; Compute the mark.
5175             (setq gnus-tmp-unread (gnus-article-mark number))
5176
5177             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5178                                   gnus-tmp-header gnus-tmp-level)
5179                   gnus-newsgroup-data)
5180
5181             ;; Actually insert the line.
5182             (setq
5183              gnus-tmp-subject-or-nil
5184              (cond
5185               ((and gnus-thread-ignore-subject
5186                     gnus-tmp-prev-subject
5187                     (not (string= gnus-tmp-prev-subject simp-subject)))
5188                subject)
5189               ((zerop gnus-tmp-level)
5190                (if (and (eq gnus-summary-make-false-root 'empty)
5191                         (memq number gnus-tmp-gathered)
5192                         gnus-tmp-prev-subject
5193                         (string= gnus-tmp-prev-subject simp-subject))
5194                    gnus-summary-same-subject
5195                  subject))
5196               (t gnus-summary-same-subject)))
5197             (if (and (eq gnus-summary-make-false-root 'adopt)
5198                      (= gnus-tmp-level 1)
5199                      (memq number gnus-tmp-gathered))
5200                 (setq gnus-tmp-opening-bracket ?\<
5201                       gnus-tmp-closing-bracket ?\>)
5202               (setq gnus-tmp-opening-bracket ?\[
5203                     gnus-tmp-closing-bracket ?\]))
5204             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5205                 (gnus-make-thread-indent-array
5206                  (max (* 2 (length gnus-thread-indent-array))
5207                       gnus-tmp-level)))
5208             (setq
5209              gnus-tmp-indentation
5210              (aref gnus-thread-indent-array gnus-tmp-level)
5211              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5212              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5213                                 gnus-summary-default-score 0)
5214              gnus-tmp-score-char
5215              (if (or (null gnus-summary-default-score)
5216                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5217                          gnus-summary-zcore-fuzz))
5218                  ?                      ;Whitespace
5219                (if (< gnus-tmp-score gnus-summary-default-score)
5220                    gnus-score-below-mark gnus-score-over-mark))
5221              gnus-tmp-replied
5222              (cond ((memq number gnus-newsgroup-processable)
5223                     gnus-process-mark)
5224                    ((memq number gnus-newsgroup-cached)
5225                     gnus-cached-mark)
5226                    ((memq number gnus-newsgroup-replied)
5227                     gnus-replied-mark)
5228                    ((memq number gnus-newsgroup-forwarded)
5229                     gnus-forwarded-mark)
5230                    ((memq number gnus-newsgroup-saved)
5231                     gnus-saved-mark)
5232                    ((memq number gnus-newsgroup-recent)
5233                     gnus-recent-mark)
5234                    ((memq number gnus-newsgroup-unseen)
5235                     gnus-unseen-mark)
5236                    (t gnus-no-mark))
5237              gnus-tmp-downloaded
5238              (cond ((memq number gnus-newsgroup-undownloaded)
5239                     gnus-undownloaded-mark)
5240                    (gnus-newsgroup-agentized
5241                     gnus-downloaded-mark)
5242                    (t
5243                     gnus-no-mark))
5244              gnus-tmp-from (mail-header-from gnus-tmp-header)
5245              gnus-tmp-name
5246              (cond
5247               ((string-match "<[^>]+> *$" gnus-tmp-from)
5248                (setq beg-match (match-beginning 0))
5249                (or (and (string-match "^\".+\"" gnus-tmp-from)
5250                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5251                    (substring gnus-tmp-from 0 beg-match)))
5252               ((string-match "(.+)" gnus-tmp-from)
5253                (substring gnus-tmp-from
5254                           (1+ (match-beginning 0)) (1- (match-end 0))))
5255               (t gnus-tmp-from))
5256
5257              ;; Do the %B string
5258              gnus-tmp-thread-tree-header-string
5259              (cond
5260               ((not gnus-show-threads) "")
5261               ((zerop gnus-tmp-level)
5262                (cond ((cdar thread)
5263                       (or gnus-sum-thread-tree-root subject))
5264                      (gnus-tmp-new-adopts
5265                       (or gnus-sum-thread-tree-false-root subject))
5266                      (t
5267                       (or gnus-sum-thread-tree-single-indent subject))))
5268               (t
5269                (concat (apply 'concat
5270                               (mapcar (lambda (item)
5271                                         (if (= item 1)
5272                                             gnus-sum-thread-tree-vertical
5273                                           gnus-sum-thread-tree-indent))
5274                                       (cdr (reverse tree-stack))))
5275                        (if (nth 1 thread)
5276                            gnus-sum-thread-tree-leaf-with-other
5277                          gnus-sum-thread-tree-single-leaf)))))
5278             (when (string= gnus-tmp-name "")
5279               (setq gnus-tmp-name gnus-tmp-from))
5280             (unless (numberp gnus-tmp-lines)
5281               (setq gnus-tmp-lines -1))
5282             (if (= gnus-tmp-lines -1)
5283                 (setq gnus-tmp-lines "?")
5284               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5285               (gnus-put-text-property
5286              (point)
5287              (progn (eval gnus-summary-line-format-spec) (point))
5288                'gnus-number number)
5289             (when gnus-visual-p
5290               (forward-line -1)
5291               (gnus-run-hooks 'gnus-summary-update-hook)
5292               (forward-line 1))
5293
5294             (setq gnus-tmp-prev-subject simp-subject)))
5295
5296         (when (nth 1 thread)
5297           (push (list (max 0 gnus-tmp-level)
5298                       (copy-sequence tree-stack)
5299                       (nthcdr 1 thread))
5300                 stack))
5301         (push (if (nth 1 thread) 1 0) tree-stack)
5302         (incf gnus-tmp-level)
5303         (setq threads (if thread-end nil (cdar thread)))
5304         (if gnus-summary-display-while-building
5305             (if building-count
5306                 (progn
5307                   ;; use a set frequency
5308                   (setq building-line-count (1- building-line-count))
5309                   (when (= building-line-count 0)
5310                     (sit-for 0)
5311                     (setq building-line-count
5312                           gnus-summary-display-while-building)))
5313               ;; always
5314               (sit-for 0)))
5315         (unless threads
5316           (setq gnus-tmp-level 0)))))
5317   (gnus-message 7 "Generating summary...done"))
5318
5319 (defun gnus-summary-prepare-unthreaded (headers)
5320   "Generate an unthreaded summary buffer based on HEADERS."
5321   (let (header number mark)
5322
5323     (beginning-of-line)
5324
5325     (while headers
5326       ;; We may have to root out some bad articles...
5327       (when (memq (setq number (mail-header-number
5328                                 (setq header (pop headers))))
5329                   gnus-newsgroup-limit)
5330         ;; Mark article as read when it has a low score.
5331         (when (and gnus-summary-mark-below
5332                    (< (or (cdr (assq number gnus-newsgroup-scored))
5333                           gnus-summary-default-score 0)
5334                       gnus-summary-mark-below)
5335                    (not (gnus-summary-article-ancient-p number)))
5336           (setq gnus-newsgroup-unreads
5337                 (delq number gnus-newsgroup-unreads))
5338           (if gnus-newsgroup-auto-expire
5339               (push number gnus-newsgroup-expirable)
5340             (push (cons number gnus-low-score-mark)
5341                   gnus-newsgroup-reads)))
5342
5343         (setq mark (gnus-article-mark number))
5344         (push (gnus-data-make number mark (1+ (point)) header 0)
5345               gnus-newsgroup-data)
5346         (gnus-summary-insert-line
5347          header 0 number
5348          (memq number gnus-newsgroup-undownloaded)
5349          mark (memq number gnus-newsgroup-replied)
5350          (memq number gnus-newsgroup-expirable)
5351          (mail-header-subject header) nil
5352          (cdr (assq number gnus-newsgroup-scored))
5353          (memq number gnus-newsgroup-processable))))))
5354
5355 (defun gnus-summary-remove-list-identifiers ()
5356   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5357   (let ((regexp (if (consp gnus-list-identifiers)
5358                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5359                   gnus-list-identifiers))
5360         changed subject)
5361     (when regexp
5362       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5363       (dolist (header gnus-newsgroup-headers)
5364         (setq subject (mail-header-subject header)
5365               changed nil)
5366         (while (string-match regexp subject)
5367           (setq subject
5368                 (concat (substring subject 0 (match-beginning 1))
5369                         (substring subject (match-end 0)))
5370                 changed t))
5371         (when changed
5372           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5373             (setq subject
5374                   (concat (substring subject 0 (match-beginning 1))
5375                           (substring subject (match-end 1)))))
5376           (mail-header-set-subject header subject))))))
5377
5378 (defun gnus-fetch-headers (articles)
5379   "Fetch headers of ARTICLES."
5380   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5381     (gnus-message 5 "Fetching headers for %s..." name)
5382     (prog1
5383         (if (eq 'nov
5384                 (setq gnus-headers-retrieved-by
5385                       (gnus-retrieve-headers
5386                        articles gnus-newsgroup-name
5387                        ;; We might want to fetch old headers, but
5388                        ;; not if there is only 1 article.
5389                        (and (or (and
5390                                  (not (eq gnus-fetch-old-headers 'some))
5391                                  (not (numberp gnus-fetch-old-headers)))
5392                                 (> (length articles) 1))
5393                             gnus-fetch-old-headers))))
5394             (gnus-get-newsgroup-headers-xover
5395              articles nil nil gnus-newsgroup-name t)
5396           (gnus-get-newsgroup-headers))
5397       (gnus-message 5 "Fetching headers for %s...done" name))))
5398
5399 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5400   "Select newsgroup GROUP.
5401 If READ-ALL is non-nil, all articles in the group are selected.
5402 If SELECT-ARTICLES, only select those articles from GROUP."
5403   (let* ((entry (gnus-group-entry group))
5404          ;;!!! Dirty hack; should be removed.
5405          (gnus-summary-ignore-duplicates
5406           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5407               t
5408             gnus-summary-ignore-duplicates))
5409          (info (nth 2 entry))
5410          charset articles fetched-articles cached)
5411
5412     (unless (gnus-check-server
5413              (set (make-local-variable 'gnus-current-select-method)
5414                   (gnus-find-method-for-group group)))
5415       (error "Couldn't open server"))
5416     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5417
5418     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5419         (gnus-activate-group group)     ; Or we can activate it...
5420         (progn                          ; Or we bug out.
5421           (when (equal major-mode 'gnus-summary-mode)
5422             (gnus-kill-buffer (current-buffer)))
5423           (error
5424            "Couldn't activate group %s: %s"
5425            (mm-decode-coding-string group charset)
5426            (mm-decode-coding-string (gnus-status-message group) charset))))
5427
5428     (unless (gnus-request-group group t)
5429         (when (equal major-mode 'gnus-summary-mode)
5430           (gnus-kill-buffer (current-buffer)))
5431         (error "Couldn't request group %s: %s"
5432                (mm-decode-coding-string group charset)
5433                (mm-decode-coding-string (gnus-status-message group) charset)))
5434
5435     (when gnus-agent
5436       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5437
5438       (setq gnus-summary-use-undownloaded-faces
5439             (gnus-agent-find-parameter
5440              group
5441              'agent-enable-undownloaded-faces)))
5442
5443     (setq gnus-newsgroup-name group
5444           gnus-newsgroup-unselected nil
5445           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5446
5447     (let ((display (gnus-group-find-parameter group 'display)))
5448       (setq gnus-newsgroup-display
5449             (cond
5450              ((not (zerop (or (car-safe read-all) 0)))
5451               ;; The user entered the group with C-u SPC/RET, let's show
5452               ;; all articles.
5453               'gnus-not-ignore)
5454              ((eq display 'all)
5455               'gnus-not-ignore)
5456              ((arrayp display)
5457               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5458              ((numberp display)
5459               ;; The following is probably the "correct" solution, but
5460               ;; it makes Gnus fetch all headers and then limit the
5461               ;; articles (which is slow), so instead we hack the
5462               ;; select-articles parameter instead. -- Simon Josefsson
5463               ;; <jas@kth.se>
5464               ;;
5465               ;; (gnus-byte-compile
5466               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5467               ;;                         display)))))
5468               (setq select-articles
5469                     (gnus-uncompress-range
5470                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5471                              (if (> tmp 0)
5472                                  tmp
5473                                1))
5474                            (cdr (gnus-active group)))))
5475               nil)
5476              (t
5477               nil))))
5478
5479     (gnus-summary-setup-default-charset)
5480
5481     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5482     (when (gnus-virtual-group-p group)
5483       (setq cached gnus-newsgroup-cached))
5484
5485     (setq gnus-newsgroup-unreads
5486           (gnus-sorted-ndifference
5487            (gnus-sorted-ndifference gnus-newsgroup-unreads
5488                                     gnus-newsgroup-marked)
5489            gnus-newsgroup-dormant))
5490
5491     (setq gnus-newsgroup-processable nil)
5492
5493     (gnus-update-read-articles group gnus-newsgroup-unreads)
5494
5495     ;; Adjust and set lists of article marks.
5496     (when info
5497       (gnus-adjust-marked-articles info))
5498     (if (setq articles select-articles)
5499         (setq gnus-newsgroup-unselected
5500               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5501       (setq articles (gnus-articles-to-read group read-all)))
5502
5503     (cond
5504      ((null articles)
5505       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5506       'quit)
5507      ((eq articles 0) nil)
5508      (t
5509       ;; Init the dependencies hash table.
5510       (setq gnus-newsgroup-dependencies
5511             (gnus-make-hashtable (length articles)))
5512       (gnus-set-global-variables)
5513       ;; Retrieve the headers and read them in.
5514
5515       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5516
5517       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5518       (when cached
5519         (setq gnus-newsgroup-cached cached))
5520
5521       ;; Suppress duplicates?
5522       (when gnus-suppress-duplicates
5523         (gnus-dup-suppress-articles))
5524
5525       ;; Set the initial limit.
5526       (setq gnus-newsgroup-limit (copy-sequence articles))
5527       ;; Remove canceled articles from the list of unread articles.
5528       (setq fetched-articles
5529             (mapcar (lambda (headers) (mail-header-number headers))
5530                     gnus-newsgroup-headers))
5531       (setq gnus-newsgroup-articles fetched-articles)
5532       (setq gnus-newsgroup-unreads
5533             (gnus-sorted-nintersection
5534              gnus-newsgroup-unreads fetched-articles))
5535       (gnus-compute-unseen-list)
5536
5537       ;; Removed marked articles that do not exist.
5538       (gnus-update-missing-marks
5539        (gnus-sorted-difference articles fetched-articles))
5540       ;; We might want to build some more threads first.
5541       (when (and gnus-fetch-old-headers
5542                  (eq gnus-headers-retrieved-by 'nov))
5543         (if (eq gnus-fetch-old-headers 'invisible)
5544             (gnus-build-all-threads)
5545           (gnus-build-old-threads)))
5546       ;; Let the Gnus agent mark articles as read.
5547       (when gnus-agent
5548         (gnus-agent-get-undownloaded-list))
5549       ;; Remove list identifiers from subject
5550       (when gnus-list-identifiers
5551         (gnus-summary-remove-list-identifiers))
5552       ;; Check whether auto-expire is to be done in this group.
5553       (setq gnus-newsgroup-auto-expire
5554             (gnus-group-auto-expirable-p group))
5555       ;; Set up the article buffer now, if necessary.
5556       (unless (and gnus-single-article-buffer
5557                    (equal gnus-article-buffer "*Article*"))
5558         (gnus-article-setup-buffer))
5559       ;; First and last article in this newsgroup.
5560       (when gnus-newsgroup-headers
5561         (setq gnus-newsgroup-begin
5562               (mail-header-number (car gnus-newsgroup-headers))
5563               gnus-newsgroup-end
5564               (mail-header-number
5565                (gnus-last-element gnus-newsgroup-headers))))
5566       ;; GROUP is successfully selected.
5567       (or gnus-newsgroup-headers t)))))
5568
5569 (defun gnus-compute-unseen-list ()
5570   ;; The `seen' marks are treated specially.
5571   (if (not gnus-newsgroup-seen)
5572       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5573     (setq gnus-newsgroup-unseen
5574           (gnus-inverse-list-range-intersection
5575            gnus-newsgroup-articles gnus-newsgroup-seen))))
5576
5577 (defun gnus-summary-display-make-predicate (display)
5578   (require 'gnus-agent)
5579   (when (= (length display) 1)
5580     (setq display (car display)))
5581   (unless gnus-summary-display-cache
5582     (dolist (elem (append '((unread . unread)
5583                             (read . read)
5584                             (unseen . unseen))
5585                           gnus-article-mark-lists))
5586       (push (cons (cdr elem)
5587                   (gnus-byte-compile
5588                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5589             gnus-summary-display-cache)))
5590   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5591         (gnus-category-predicate-cache gnus-summary-display-cache))
5592     (gnus-get-predicate display)))
5593
5594 ;; Uses the dynamically bound `number' variable.
5595 (eval-when-compile
5596   (defvar number))
5597 (defun gnus-article-marked-p (type &optional article)
5598   (let ((article (or article number)))
5599     (cond
5600      ((eq type 'tick)
5601       (memq article gnus-newsgroup-marked))
5602      ((eq type 'spam)
5603       (memq article gnus-newsgroup-spam-marked))
5604      ((eq type 'unsend)
5605       (memq article gnus-newsgroup-unsendable))
5606      ((eq type 'undownload)
5607       (memq article gnus-newsgroup-undownloaded))
5608      ((eq type 'download)
5609       (memq article gnus-newsgroup-downloadable))
5610      ((eq type 'unread)
5611       (memq article gnus-newsgroup-unreads))
5612      ((eq type 'read)
5613       (memq article gnus-newsgroup-reads))
5614      ((eq type 'dormant)
5615       (memq article gnus-newsgroup-dormant) )
5616      ((eq type 'expire)
5617       (memq article gnus-newsgroup-expirable))
5618      ((eq type 'reply)
5619       (memq article gnus-newsgroup-replied))
5620      ((eq type 'killed)
5621       (memq article gnus-newsgroup-killed))
5622      ((eq type 'bookmark)
5623       (assq article gnus-newsgroup-bookmarks))
5624      ((eq type 'score)
5625       (assq article gnus-newsgroup-scored))
5626      ((eq type 'save)
5627       (memq article gnus-newsgroup-saved))
5628      ((eq type 'cache)
5629       (memq article gnus-newsgroup-cached))
5630      ((eq type 'forward)
5631       (memq article gnus-newsgroup-forwarded))
5632      ((eq type 'seen)
5633       (not (memq article gnus-newsgroup-unseen)))
5634      ((eq type 'recent)
5635       (memq article gnus-newsgroup-recent))
5636      (t t))))
5637
5638 (defun gnus-articles-to-read (group &optional read-all)
5639   "Find out what articles the user wants to read."
5640   (let* ((articles
5641           ;; Select all articles if `read-all' is non-nil, or if there
5642           ;; are no unread articles.
5643           (if (or read-all
5644                   (and (zerop (length gnus-newsgroup-marked))
5645                        (zerop (length gnus-newsgroup-unreads)))
5646                   ;; Fetch all if the predicate is non-nil.
5647                   gnus-newsgroup-display)
5648               ;; We want to select the headers for all the articles in
5649               ;; the group, so we select either all the active
5650               ;; articles in the group, or (if that's nil), the
5651               ;; articles in the cache.
5652               (or
5653                (if gnus-newsgroup-maximum-articles
5654                    (let ((active (gnus-active group)))
5655                      (gnus-uncompress-range
5656                       (cons (max (car active)
5657                                  (- (cdr active)
5658                                     gnus-newsgroup-maximum-articles
5659                                     -1))
5660                             (cdr active))))
5661                  (gnus-uncompress-range (gnus-active group)))
5662                (gnus-cache-articles-in-group group))
5663             ;; Select only the "normal" subset of articles.
5664             (gnus-sorted-nunion
5665              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5666              gnus-newsgroup-unreads)))
5667          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5668          (scored (length scored-list))
5669          (number (length articles))
5670          (marked (+ (length gnus-newsgroup-marked)
5671                     (length gnus-newsgroup-dormant)))
5672          (select
5673           (cond
5674            ((numberp read-all)
5675             read-all)
5676            ((numberp gnus-newsgroup-display)
5677             gnus-newsgroup-display)
5678            (t
5679             (condition-case ()
5680                 (cond
5681                  ((and (or (<= scored marked) (= scored number))
5682                        (numberp gnus-large-newsgroup)
5683                        (> number gnus-large-newsgroup))
5684                   (let* ((cursor-in-echo-area nil)
5685                          (initial (gnus-parameter-large-newsgroup-initial
5686                                    gnus-newsgroup-name))
5687                          (input
5688                           (read-string
5689                            (format
5690                             "How many articles from %s (%s %d): "
5691                             (gnus-group-decoded-name gnus-newsgroup-name)
5692                             (if initial "max" "default")
5693                             number)
5694                            (if initial
5695                                (cons (number-to-string initial)
5696                                      0)))))
5697                     (if (string-match "^[ \t]*$" input) number input)))
5698                  ((and (> scored marked) (< scored number)
5699                        (> (- scored number) 20))
5700                   (let ((input
5701                          (read-string
5702                           (format "%s %s (%d scored, %d total): "
5703                                   "How many articles from"
5704                                   (gnus-group-decoded-name group)
5705                                   scored number))))
5706                     (if (string-match "^[ \t]*$" input)
5707                         number input)))
5708                  (t number))
5709               (quit
5710                (message "Quit getting the articles to read")
5711                nil))))))
5712     (setq select (if (stringp select) (string-to-number select) select))
5713     (if (or (null select) (zerop select))
5714         select
5715       (if (and (not (zerop scored)) (<= (abs select) scored))
5716           (progn
5717             (setq articles (sort scored-list '<))
5718             (setq number (length articles)))
5719         (setq articles (copy-sequence articles)))
5720
5721       (when (< (abs select) number)
5722         (if (< select 0)
5723             ;; Select the N oldest articles.
5724             (setcdr (nthcdr (1- (abs select)) articles) nil)
5725           ;; Select the N most recent articles.
5726           (setq articles (nthcdr (- number select) articles))))
5727       (setq gnus-newsgroup-unselected
5728             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5729       (when gnus-alter-articles-to-read-function
5730         (setq articles
5731               (sort
5732                (funcall gnus-alter-articles-to-read-function
5733                         gnus-newsgroup-name articles)
5734                '<)))
5735       articles)))
5736
5737 (defun gnus-killed-articles (killed articles)
5738   (let (out)
5739     (while articles
5740       (when (inline (gnus-member-of-range (car articles) killed))
5741         (push (car articles) out))
5742       (setq articles (cdr articles)))
5743     out))
5744
5745 (defun gnus-uncompress-marks (marks)
5746   "Uncompress the mark ranges in MARKS."
5747   (let ((uncompressed '(score bookmark))
5748         out)
5749     (while marks
5750       (if (memq (caar marks) uncompressed)
5751           (push (car marks) out)
5752         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5753       (setq marks (cdr marks)))
5754     out))
5755
5756 (defun gnus-article-mark-to-type (mark)
5757   "Return the type of MARK."
5758   (or (cadr (assq mark gnus-article-special-mark-lists))
5759       'list))
5760
5761 (defun gnus-article-unpropagatable-p (mark)
5762   "Return whether MARK should be propagated to back end."
5763   (memq mark gnus-article-unpropagated-mark-lists))
5764
5765 (defun gnus-adjust-marked-articles (info)
5766   "Set all article lists and remove all marks that are no longer valid."
5767   (let* ((marked-lists (gnus-info-marks info))
5768          (active (gnus-active (gnus-info-group info)))
5769          (min (car active))
5770          (max (cdr active))
5771          (types gnus-article-mark-lists)
5772          marks var articles article mark mark-type
5773          bgn end)
5774
5775     (dolist (marks marked-lists)
5776       (setq mark (car marks)
5777             mark-type (gnus-article-mark-to-type mark)
5778             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5779
5780       ;; We set the variable according to the type of the marks list,
5781       ;; and then adjust the marks to a subset of the active articles.
5782       (cond
5783        ;; Adjust "simple" lists - compressed yet unsorted
5784        ((eq mark-type 'list)
5785         ;; Simultaneously uncompress and clip to active range
5786         ;; See gnus-uncompress-range for a description of possible marks
5787         (let (l lh)
5788           (if (not (cadr marks))
5789               (set var nil)
5790             (setq articles (if (numberp (cddr marks))
5791                                (list (cdr marks))
5792                              (cdr marks))
5793                   lh (cons nil nil)
5794                   l lh)
5795
5796             (while (setq article (pop articles))
5797               (cond ((consp article)
5798                      (setq bgn (max (car article) min)
5799                            end (min (cdr article) max))
5800                      (while (<= bgn end)
5801                        (setq l (setcdr l (cons bgn nil))
5802                              bgn (1+ bgn))))
5803                     ((and (<= min article)
5804                           (>= max article))
5805                      (setq l (setcdr l (cons article nil))))))
5806             (set var (cdr lh)))))
5807        ;; Adjust assocs.
5808        ((eq mark-type 'tuple)
5809         (set var (setq articles (cdr marks)))
5810         (when (not (listp (cdr (symbol-value var))))
5811           (set var (list (symbol-value var))))
5812         (when (not (listp (cdr articles)))
5813           (setq articles (list articles)))
5814         (while articles
5815           (when (or (not (consp (setq article (pop articles))))
5816                     (< (car article) min)
5817                     (> (car article) max))
5818             (set var (delq article (symbol-value var))))))
5819        ;; Adjust ranges (sloppily).
5820        ((eq mark-type 'range)
5821         (cond
5822          ((eq mark 'seen)
5823           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5824           ;; It should be (seen (NUM1 . NUM2)).
5825           (when (numberp (cddr marks))
5826             (setcdr marks (list (cdr marks))))
5827           (setq articles (cdr marks))
5828           (while (and articles
5829                       (or (and (consp (car articles))
5830                                (> min (cdar articles)))
5831                           (and (numberp (car articles))
5832                                (> min (car articles)))))
5833             (pop articles))
5834           (set var articles))))))))
5835
5836 (defun gnus-update-missing-marks (missing)
5837   "Go through the list of MISSING articles and remove them from the mark lists."
5838   (when missing
5839     (let (var m)
5840       ;; Go through all types.
5841       (dolist (elem gnus-article-mark-lists)
5842         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5843           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5844           (when (symbol-value var)
5845             ;; This list has articles.  So we delete all missing
5846             ;; articles from it.
5847             (setq m missing)
5848             (while m
5849               (set var (delq (pop m) (symbol-value var))))))))))
5850
5851 (defun gnus-update-marks ()
5852   "Enter the various lists of marked articles into the newsgroup info list."
5853   (let ((types gnus-article-mark-lists)
5854         (info (gnus-get-info gnus-newsgroup-name))
5855         type list newmarked symbol delta-marks)
5856     (when info
5857       ;; Add all marks lists to the list of marks lists.
5858       (while (setq type (pop types))
5859         (setq list (symbol-value
5860                     (setq symbol
5861                           (intern (format "gnus-newsgroup-%s" (car type))))))
5862
5863         (when list
5864           ;; Get rid of the entries of the articles that have the
5865           ;; default score.
5866           (when (and (eq (cdr type) 'score)
5867                      gnus-save-score
5868                      list)
5869             (let* ((arts list)
5870                    (prev (cons nil list))
5871                    (all prev))
5872               (while arts
5873                 (if (or (not (consp (car arts)))
5874                         (= (cdar arts) gnus-summary-default-score))
5875                     (setcdr prev (cdr arts))
5876                   (setq prev arts))
5877                 (setq arts (cdr arts)))
5878               (setq list (cdr all)))))
5879
5880         (when (eq (cdr type) 'seen)
5881           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5882
5883         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5884           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5885
5886         (when (and (gnus-check-backend-function
5887                     'request-set-mark gnus-newsgroup-name)
5888                    (not (gnus-article-unpropagatable-p (cdr type))))
5889           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5890                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5891                  (add (gnus-remove-from-range
5892                        (gnus-copy-sequence list) old)))
5893             (when add
5894               (push (list add 'add (list (cdr type))) delta-marks))
5895             (when del
5896               (push (list del 'del (list (cdr type))) delta-marks))))
5897
5898         (when list
5899           (push (cons (cdr type) list) newmarked)))
5900
5901       (when delta-marks
5902         (unless (gnus-check-group gnus-newsgroup-name)
5903           (error "Can't open server for %s" gnus-newsgroup-name))
5904         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5905
5906       ;; Enter these new marks into the info of the group.
5907       (if (nthcdr 3 info)
5908           (setcar (nthcdr 3 info) newmarked)
5909         ;; Add the marks lists to the end of the info.
5910         (when newmarked
5911           (setcdr (nthcdr 2 info) (list newmarked))))
5912
5913       ;; Cut off the end of the info if there's nothing else there.
5914       (let ((i 5))
5915         (while (and (> i 2)
5916                     (not (nth i info)))
5917           (when (nthcdr (decf i) info)
5918             (setcdr (nthcdr i info) nil)))))))
5919
5920 (defun gnus-set-mode-line (where)
5921   "Set the mode line of the article or summary buffers.
5922 If WHERE is `summary', the summary mode line format will be used."
5923   ;; Is this mode line one we keep updated?
5924   (when (and (memq where gnus-updated-mode-lines)
5925              (symbol-value
5926               (intern (format "gnus-%s-mode-line-format-spec" where))))
5927     (let (mode-string)
5928       (save-excursion
5929         ;; We evaluate this in the summary buffer since these
5930         ;; variables are buffer-local to that buffer.
5931         (set-buffer gnus-summary-buffer)
5932        ;; We bind all these variables that are used in the `eval' form
5933         ;; below.
5934         (let* ((mformat (symbol-value
5935                          (intern
5936                           (format "gnus-%s-mode-line-format-spec" where))))
5937                (gnus-tmp-group-name (gnus-mode-string-quote
5938                                      (gnus-group-decoded-name
5939                                       gnus-newsgroup-name)))
5940                (gnus-tmp-article-number (or gnus-current-article 0))
5941                (gnus-tmp-unread gnus-newsgroup-unreads)
5942                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5943                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5944                (gnus-tmp-unread-and-unselected
5945                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5946                             (zerop gnus-tmp-unselected))
5947                        "")
5948                       ((zerop gnus-tmp-unselected)
5949                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5950                       (t (format "{%d(+%d) more}"
5951                                  gnus-tmp-unread-and-unticked
5952                                  gnus-tmp-unselected))))
5953                (gnus-tmp-subject
5954                 (if (and gnus-current-headers
5955                          (vectorp gnus-current-headers))
5956                     (gnus-mode-string-quote
5957                      (mail-header-subject gnus-current-headers))
5958                   ""))
5959                bufname-length max-len
5960                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5961           (setq mode-string (eval mformat))
5962           (setq bufname-length (if (string-match "%b" mode-string)
5963                                    (- (length
5964                                        (buffer-name
5965                                         (if (eq where 'summary)
5966                                             nil
5967                                           (get-buffer gnus-article-buffer))))
5968                                       2)
5969                                  0))
5970           (setq max-len (max 4 (if gnus-mode-non-string-length
5971                                    (- (window-width)
5972                                       gnus-mode-non-string-length
5973                                       bufname-length)
5974                                  (length mode-string))))
5975           ;; We might have to chop a bit of the string off...
5976           (when (> (length mode-string) max-len)
5977             (setq mode-string
5978                   (concat (truncate-string-to-width mode-string (- max-len 3))
5979                           "...")))
5980           ;; Pad the mode string a bit.
5981           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5982       ;; Update the mode line.
5983       (setq mode-line-buffer-identification
5984             (gnus-mode-line-buffer-identification (list mode-string)))
5985       (set-buffer-modified-p t))))
5986
5987 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5988   "Go through the HEADERS list and add all Xrefs to a hash table.
5989 The resulting hash table is returned, or nil if no Xrefs were found."
5990   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5991          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5992          (xref-hashtb (gnus-make-hashtable))
5993          start group entry number xrefs header)
5994     (while headers
5995       (setq header (pop headers))
5996       (when (and (setq xrefs (mail-header-xref header))
5997                  (not (memq (setq number (mail-header-number header))
5998                             unreads)))
5999         (setq start 0)
6000         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6001           (setq start (match-end 0))
6002           (setq group (if prefix
6003                           (concat prefix (substring xrefs (match-beginning 1)
6004                                                     (match-end 1)))
6005                         (substring xrefs (match-beginning 1) (match-end 1))))
6006           (setq number
6007                 (string-to-number (substring xrefs (match-beginning 2)
6008                                           (match-end 2))))
6009           (if (setq entry (gnus-gethash group xref-hashtb))
6010               (setcdr entry (cons number (cdr entry)))
6011             (gnus-sethash group (cons number nil) xref-hashtb)))))
6012     (and start xref-hashtb)))
6013
6014 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6015   "Look through all the headers and mark the Xrefs as read."
6016   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6017         name info xref-hashtb idlist method nth4)
6018     (save-excursion
6019       (set-buffer gnus-group-buffer)
6020       (when (setq xref-hashtb
6021                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6022         (mapatoms
6023          (lambda (group)
6024            (unless (string= from-newsgroup (setq name (symbol-name group)))
6025              (setq idlist (symbol-value group))
6026              ;; Dead groups are not updated.
6027              (and (prog1
6028                       (setq info (gnus-get-info name))
6029                     (when (stringp (setq nth4 (gnus-info-method info)))
6030                       (setq nth4 (gnus-server-to-method nth4))))
6031                   ;; Only do the xrefs if the group has the same
6032                   ;; select method as the group we have just read.
6033                   (or (gnus-methods-equal-p
6034                        nth4 (gnus-find-method-for-group from-newsgroup))
6035                       virtual
6036                       (equal nth4 (setq method (gnus-find-method-for-group
6037                                                 from-newsgroup)))
6038                       (and (equal (car nth4) (car method))
6039                            (equal (nth 1 nth4) (nth 1 method))))
6040                   gnus-use-cross-reference
6041                   (or (not (eq gnus-use-cross-reference t))
6042                       virtual
6043                       ;; Only do cross-references on subscribed
6044                       ;; groups, if that is what is wanted.
6045                       (<= (gnus-info-level info) gnus-level-subscribed))
6046                   (gnus-group-make-articles-read name idlist))))
6047          xref-hashtb)))))
6048
6049 (defun gnus-compute-read-articles (group articles)
6050   (let* ((entry (gnus-group-entry group))
6051          (info (nth 2 entry))
6052          (active (gnus-active group))
6053          ninfo)
6054     (when entry
6055       ;; First peel off all invalid article numbers.
6056       (when active
6057         (let ((ids articles)
6058               id first)
6059           (while (setq id (pop ids))
6060             (when (and first (> id (cdr active)))
6061               ;; We'll end up in this situation in one particular
6062               ;; obscure situation.  If you re-scan a group and get
6063               ;; a new article that is cross-posted to a different
6064               ;; group that has not been re-scanned, you might get
6065               ;; crossposted article that has a higher number than
6066               ;; Gnus believes possible.  So we re-activate this
6067               ;; group as well.  This might mean doing the
6068               ;; crossposting thingy will *increase* the number
6069               ;; of articles in some groups.  Tsk, tsk.
6070               (setq active (or (gnus-activate-group group) active)))
6071             (when (or (> id (cdr active))
6072                       (< id (car active)))
6073               (setq articles (delq id articles))))))
6074       ;; If the read list is nil, we init it.
6075       (if (and active
6076                (null (gnus-info-read info))
6077                (> (car active) 1))
6078           (setq ninfo (cons 1 (1- (car active))))
6079         (setq ninfo (gnus-info-read info)))
6080       ;; Then we add the read articles to the range.
6081       (gnus-add-to-range
6082        ninfo (setq articles (sort articles '<))))))
6083
6084 (defun gnus-group-make-articles-read (group articles)
6085   "Update the info of GROUP to say that ARTICLES are read."
6086   (let* ((num 0)
6087          (entry (gnus-group-entry group))
6088          (info (nth 2 entry))
6089          (active (gnus-active group))
6090          range)
6091     (when entry
6092       (setq range (gnus-compute-read-articles group articles))
6093       (with-current-buffer gnus-group-buffer
6094         (gnus-undo-register
6095           `(progn
6096              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6097              (gnus-info-set-read ',info ',(gnus-info-read info))
6098              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6099              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6100              (gnus-group-update-group ,group t))))
6101       ;; Add the read articles to the range.
6102       (gnus-info-set-read info range)
6103       (gnus-request-set-mark group (list (list range 'add '(read))))
6104       ;; Then we have to re-compute how many unread
6105       ;; articles there are in this group.
6106       (when active
6107         (cond
6108          ((not range)
6109           (setq num (- (1+ (cdr active)) (car active))))
6110          ((not (listp (cdr range)))
6111           (setq num (- (cdr active) (- (1+ (cdr range))
6112                                        (car range)))))
6113          (t
6114           (while range
6115             (if (numberp (car range))
6116                 (setq num (1+ num))
6117               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6118             (setq range (cdr range)))
6119           (setq num (- (cdr active) num))))
6120         ;; Update the number of unread articles.
6121         (setcar entry num)
6122         ;; Update the group buffer.
6123         (unless (gnus-ephemeral-group-p group)
6124           (gnus-group-update-group group t))))))
6125
6126 (defvar gnus-newsgroup-none-id 0)
6127
6128 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6129   (let ((cur nntp-server-buffer)
6130         (dependencies
6131          (or dependencies
6132              (with-current-buffer gnus-summary-buffer
6133                gnus-newsgroup-dependencies)))
6134         headers id end ref number
6135         (mail-parse-charset gnus-newsgroup-charset)
6136         (mail-parse-ignored-charsets
6137          (save-excursion (condition-case nil
6138                              (set-buffer gnus-summary-buffer)
6139                            (error))
6140                          gnus-newsgroup-ignored-charsets)))
6141     (save-excursion
6142       (set-buffer nntp-server-buffer)
6143       ;; Translate all TAB characters into SPACE characters.
6144       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6145       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6146       (ietf-drums-unfold-fws)
6147       (gnus-run-hooks 'gnus-parse-headers-hook)
6148       (let ((case-fold-search t)
6149             in-reply-to header p lines chars)
6150         (goto-char (point-min))
6151         ;; Search to the beginning of the next header.  Error messages
6152         ;; do not begin with 2 or 3.
6153         (while (re-search-forward "^[23][0-9]+ " nil t)
6154           (setq id nil
6155                 ref nil)
6156           ;; This implementation of this function, with nine
6157           ;; search-forwards instead of the one re-search-forward and
6158           ;; a case (which basically was the old function) is actually
6159           ;; about twice as fast, even though it looks messier.  You
6160           ;; can't have everything, I guess.  Speed and elegance
6161           ;; doesn't always go hand in hand.
6162           (setq
6163            header
6164            (vector
6165             ;; Number.
6166             (prog1
6167                 (setq number (read cur))
6168               (end-of-line)
6169               (setq p (point))
6170               (narrow-to-region (point)
6171                                 (or (and (search-forward "\n.\n" nil t)
6172                                          (- (point) 2))
6173                                     (point))))
6174             ;; Subject.
6175             (progn
6176               (goto-char p)
6177               (if (search-forward "\nsubject:" nil t)
6178                   (funcall gnus-decode-encoded-word-function
6179                            (nnheader-header-value))
6180                 "(none)"))
6181             ;; From.
6182             (progn
6183               (goto-char p)
6184               (if (search-forward "\nfrom:" nil t)
6185                   (funcall gnus-decode-encoded-address-function
6186                            (nnheader-header-value))
6187                 "(nobody)"))
6188             ;; Date.
6189             (progn
6190               (goto-char p)
6191               (if (search-forward "\ndate:" nil t)
6192                   (nnheader-header-value) ""))
6193             ;; Message-ID.
6194             (progn
6195               (goto-char p)
6196               (setq id (if (re-search-forward
6197                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6198                            ;; We do it this way to make sure the Message-ID
6199                            ;; is (somewhat) syntactically valid.
6200                            (buffer-substring (match-beginning 1)
6201                                              (match-end 1))
6202                          ;; If there was no message-id, we just fake one
6203                          ;; to make subsequent routines simpler.
6204                          (nnheader-generate-fake-message-id number))))
6205             ;; References.
6206             (progn
6207               (goto-char p)
6208               (if (search-forward "\nreferences:" nil t)
6209                   (progn
6210                     (setq end (point))
6211                     (prog1
6212                         (nnheader-header-value)
6213                       (setq ref
6214                             (buffer-substring
6215                              (progn
6216                                (end-of-line)
6217                                (search-backward ">" end t)
6218                                (1+ (point)))
6219                              (progn
6220                                (search-backward "<" end t)
6221                                (point))))))
6222                 ;; Get the references from the in-reply-to header if there
6223                 ;; were no references and the in-reply-to header looks
6224                 ;; promising.
6225                 (if (and (search-forward "\nin-reply-to:" nil t)
6226                          (setq in-reply-to (nnheader-header-value))
6227                          (string-match "<[^>]+>" in-reply-to))
6228                     (let (ref2)
6229                       (setq ref (substring in-reply-to (match-beginning 0)
6230                                            (match-end 0)))
6231                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6232                         (setq ref2 (substring in-reply-to (match-beginning 0)
6233                                               (match-end 0)))
6234                         (when (> (length ref2) (length ref))
6235                           (setq ref ref2)))
6236                       ref)
6237                   (setq ref nil))))
6238             ;; Chars.
6239             (progn
6240               (goto-char p)
6241               (if (search-forward "\nchars: " nil t)
6242                   (if (numberp (setq chars (ignore-errors (read cur))))
6243                       chars -1)
6244                 -1))
6245             ;; Lines.
6246             (progn
6247               (goto-char p)
6248               (if (search-forward "\nlines: " nil t)
6249                   (if (numberp (setq lines (ignore-errors (read cur))))
6250                       lines -1)
6251                 -1))
6252             ;; Xref.
6253             (progn
6254               (goto-char p)
6255               (and (search-forward "\nxref:" nil t)
6256                    (nnheader-header-value)))
6257             ;; Extra.
6258             (when gnus-extra-headers
6259               (let ((extra gnus-extra-headers)
6260                     out)
6261                 (while extra
6262                   (goto-char p)
6263                   (when (search-forward
6264                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6265                     (push (cons (car extra) (nnheader-header-value))
6266                           out))
6267                   (pop extra))
6268                 out))))
6269           (when (equal id ref)
6270             (setq ref nil))
6271
6272           (when gnus-alter-header-function
6273             (funcall gnus-alter-header-function header)
6274             (setq id (mail-header-id header)
6275                   ref (gnus-parent-id (mail-header-references header))))
6276
6277           (when (setq header
6278                       (gnus-dependencies-add-header
6279                        header dependencies force-new))
6280             (push header headers))
6281           (goto-char (point-max))
6282           (widen))
6283         (nreverse headers)))))
6284
6285 ;; Goes through the xover lines and returns a list of vectors
6286 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6287                                                   force-new dependencies
6288                                                   group also-fetch-heads)
6289   "Parse the news overview data in the server buffer.
6290 Return a list of headers that match SEQUENCE (see
6291 `nntp-retrieve-headers')."
6292   ;; Get the Xref when the users reads the articles since most/some
6293   ;; NNTP servers do not include Xrefs when using XOVER.
6294   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6295   (let ((mail-parse-charset gnus-newsgroup-charset)
6296         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6297         (cur nntp-server-buffer)
6298         (dependencies (or dependencies gnus-newsgroup-dependencies))
6299         (allp (cond
6300                ((eq gnus-read-all-available-headers t)
6301                 t)
6302                ((and (stringp gnus-read-all-available-headers)
6303                      group)
6304                 (string-match gnus-read-all-available-headers group))
6305                (t
6306                 nil)))
6307         number headers header)
6308     (save-excursion
6309       (set-buffer nntp-server-buffer)
6310       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6311       ;; Allow the user to mangle the headers before parsing them.
6312       (gnus-run-hooks 'gnus-parse-headers-hook)
6313       (goto-char (point-min))
6314       (gnus-parse-without-error
6315         (while (and (or sequence allp)
6316                     (not (eobp)))
6317           (setq number (read cur))
6318           (when (not allp)
6319             (while (and sequence
6320                         (< (car sequence) number))
6321               (setq sequence (cdr sequence))))
6322           (when (and (or allp
6323                          (and sequence
6324                               (eq number (car sequence))))
6325                      (progn
6326                        (setq sequence (cdr sequence))
6327                        (setq header (inline
6328                                       (gnus-nov-parse-line
6329                                        number dependencies force-new)))))
6330             (push header headers))
6331           (forward-line 1)))
6332       ;; A common bug in inn is that if you have posted an article and
6333       ;; then retrieves the active file, it will answer correctly --
6334       ;; the new article is included.  However, a NOV entry for the
6335       ;; article may not have been generated yet, so this may fail.
6336       ;; We work around this problem by retrieving the last few
6337       ;; headers using HEAD.
6338       (if (or (not also-fetch-heads)
6339               (not sequence))
6340           ;; We (probably) got all the headers.
6341           (nreverse headers)
6342         (let ((gnus-nov-is-evil t))
6343           (nconc
6344            (nreverse headers)
6345            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6346              (gnus-get-newsgroup-headers))))))))
6347
6348 (defun gnus-article-get-xrefs ()
6349   "Fill in the Xref value in `gnus-current-headers', if necessary.
6350 This is meant to be called in `gnus-article-internal-prepare-hook'."
6351   (let ((headers (with-current-buffer gnus-summary-buffer
6352                    gnus-current-headers)))
6353     (or (not gnus-use-cross-reference)
6354         (not headers)
6355         (and (mail-header-xref headers)
6356              (not (string= (mail-header-xref headers) "")))
6357         (let ((case-fold-search t)
6358               xref)
6359           (save-restriction
6360             (nnheader-narrow-to-headers)
6361             (goto-char (point-min))
6362             (when (or (and (not (eobp))
6363                            (eq (downcase (char-after)) ?x)
6364                            (looking-at "Xref:"))
6365                       (search-forward "\nXref:" nil t))
6366               (goto-char (1+ (match-end 0)))
6367               (setq xref (buffer-substring (point) (point-at-eol)))
6368               (mail-header-set-xref headers xref)))))))
6369
6370 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6371   "Find article ID and insert the summary line for that article.
6372 OLD-HEADER can either be a header or a line number to insert
6373 the subject line on."
6374   (let* ((line (and (numberp old-header) old-header))
6375          (old-header (and (vectorp old-header) old-header))
6376          (header (cond ((and old-header use-old-header)
6377                         old-header)
6378                        ((and (numberp id)
6379                              (gnus-number-to-header id))
6380                         (gnus-number-to-header id))
6381                        (t
6382                         (gnus-read-header id))))
6383          (number (and (numberp id) id))
6384          d)
6385     (when header
6386       ;; Rebuild the thread that this article is part of and go to the
6387       ;; article we have fetched.
6388       (when (and (not gnus-show-threads)
6389                  old-header)
6390         (when (and number
6391                    (setq d (gnus-data-find (mail-header-number old-header))))
6392           (goto-char (gnus-data-pos d))
6393           (gnus-data-remove
6394            number
6395            (- (point-at-bol)
6396               (prog1
6397                   (1+ (point-at-eol))
6398                 (gnus-delete-line))))))
6399       ;; Remove list identifiers from subject.
6400       (when gnus-list-identifiers
6401         (let ((gnus-newsgroup-headers (list header)))
6402           (gnus-summary-remove-list-identifiers)))
6403       (when old-header
6404         (mail-header-set-number header (mail-header-number old-header)))
6405       (setq gnus-newsgroup-sparse
6406             (delq (setq number (mail-header-number header))
6407                   gnus-newsgroup-sparse))
6408       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6409       (push number gnus-newsgroup-limit)
6410       (gnus-rebuild-thread (mail-header-id header) line)
6411       (gnus-summary-goto-subject number nil t))
6412     (when (and (numberp number)
6413                (> number 0))
6414       ;; We have to update the boundaries even if we can't fetch the
6415       ;; article if ID is a number -- so that the next `P' or `N'
6416       ;; command will fetch the previous (or next) article even
6417       ;; if the one we tried to fetch this time has been canceled.
6418       (when (> number gnus-newsgroup-end)
6419         (setq gnus-newsgroup-end number))
6420       (when (< number gnus-newsgroup-begin)
6421         (setq gnus-newsgroup-begin number))
6422       (setq gnus-newsgroup-unselected
6423             (delq number gnus-newsgroup-unselected)))
6424     ;; Report back a success?
6425     (and header (mail-header-number header))))
6426
6427 ;;; Process/prefix in the summary buffer
6428
6429 (defun gnus-summary-work-articles (n)
6430   "Return a list of articles to be worked upon.
6431 The prefix argument, the list of process marked articles, and the
6432 current article will be taken into consideration."
6433   (save-excursion
6434     (set-buffer gnus-summary-buffer)
6435     (cond
6436      (n
6437       ;; A numerical prefix has been given.
6438       (setq n (prefix-numeric-value n))
6439       (let ((backward (< n 0))
6440             (n (abs (prefix-numeric-value n)))
6441             articles article)
6442         (save-excursion
6443           (while
6444               (and (> n 0)
6445                    (push (setq article (gnus-summary-article-number))
6446                          articles)
6447                    (if backward
6448                        (gnus-summary-find-prev nil article)
6449                      (gnus-summary-find-next nil article)))
6450             (decf n)))
6451         (nreverse articles)))
6452      ((and (gnus-region-active-p) (mark))
6453       (message "region active")
6454       ;; Work on the region between point and mark.
6455       (let ((max (max (point) (mark)))
6456             articles article)
6457         (save-excursion
6458           (goto-char (min (point) (mark)))
6459           (while
6460               (and
6461                (push (setq article (gnus-summary-article-number)) articles)
6462                (gnus-summary-find-next nil article)
6463                (< (point) max)))
6464           (nreverse articles))))
6465      (gnus-newsgroup-processable
6466       ;; There are process-marked articles present.
6467       ;; Save current state.
6468       (gnus-summary-save-process-mark)
6469       ;; Return the list.
6470       (reverse gnus-newsgroup-processable))
6471      (t
6472       ;; Just return the current article.
6473       (list (gnus-summary-article-number))))))
6474
6475 (defmacro gnus-summary-iterate (arg &rest forms)
6476   "Iterate over the process/prefixed articles and do FORMS.
6477 ARG is the interactive prefix given to the command.  FORMS will be
6478 executed with point over the summary line of the articles."
6479   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6480     `(let ((,articles (gnus-summary-work-articles ,arg)))
6481        (while ,articles
6482          (gnus-summary-goto-subject (car ,articles))
6483          ,@forms
6484          (pop ,articles)))))
6485
6486 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6487 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6488
6489 (defun gnus-summary-save-process-mark ()
6490   "Push the current set of process marked articles on the stack."
6491   (interactive)
6492   (push (copy-sequence gnus-newsgroup-processable)
6493         gnus-newsgroup-process-stack))
6494
6495 (defun gnus-summary-kill-process-mark ()
6496   "Push the current set of process marked articles on the stack and unmark."
6497   (interactive)
6498   (gnus-summary-save-process-mark)
6499   (gnus-summary-unmark-all-processable))
6500
6501 (defun gnus-summary-yank-process-mark ()
6502   "Pop the last process mark state off the stack and restore it."
6503   (interactive)
6504   (unless gnus-newsgroup-process-stack
6505     (error "Empty mark stack"))
6506   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6507
6508 (defun gnus-summary-process-mark-set (set)
6509   "Make SET into the current process marked articles."
6510   (gnus-summary-unmark-all-processable)
6511   (mapc 'gnus-summary-set-process-mark set))
6512
6513 ;;; Searching and stuff
6514
6515 (defun gnus-summary-search-group (&optional backward use-level)
6516   "Search for next unread newsgroup.
6517 If optional argument BACKWARD is non-nil, search backward instead."
6518   (save-excursion
6519     (set-buffer gnus-group-buffer)
6520     (when (gnus-group-search-forward
6521            backward nil (if use-level (gnus-group-group-level) nil))
6522       (gnus-group-group-name))))
6523
6524 (defun gnus-summary-best-group (&optional exclude-group)
6525   "Find the name of the best unread group.
6526 If EXCLUDE-GROUP, do not go to this group."
6527   (with-current-buffer gnus-group-buffer
6528     (save-excursion
6529       (gnus-group-best-unread-group exclude-group))))
6530
6531 (defun gnus-summary-find-next (&optional unread article backward)
6532   (if backward
6533       (gnus-summary-find-prev unread article)
6534     (let* ((dummy (gnus-summary-article-intangible-p))
6535            (article (or article (gnus-summary-article-number)))
6536            (data (gnus-data-find-list article))
6537            result)
6538       (when (and (not dummy)
6539                  (or (not gnus-summary-check-current)
6540                      (not unread)
6541                      (not (gnus-data-unread-p (car data)))))
6542         (setq data (cdr data)))
6543       (when (setq result
6544                   (if unread
6545                       (progn
6546                         (while data
6547                           (unless (memq (gnus-data-number (car data))
6548                                         (cond
6549                                          ((eq gnus-auto-goto-ignores
6550                                               'always-undownloaded)
6551                                           gnus-newsgroup-undownloaded)
6552                                          (gnus-plugged
6553                                           nil)
6554                                          ((eq gnus-auto-goto-ignores
6555                                               'unfetched)
6556                                           gnus-newsgroup-unfetched)
6557                                          ((eq gnus-auto-goto-ignores
6558                                               'undownloaded)
6559                                           gnus-newsgroup-undownloaded)))
6560                             (when (gnus-data-unread-p (car data))
6561                               (setq result (car data)
6562                                     data nil)))
6563                           (setq data (cdr data)))
6564                         result)
6565                     (car data)))
6566         (goto-char (gnus-data-pos result))
6567         (gnus-data-number result)))))
6568
6569 (defun gnus-summary-find-prev (&optional unread article)
6570   (let* ((eobp (eobp))
6571          (article (or article (gnus-summary-article-number)))
6572          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6573          result)
6574     (when (and (not eobp)
6575                (or (not gnus-summary-check-current)
6576                    (not unread)
6577                    (not (gnus-data-unread-p (car data)))))
6578       (setq data (cdr data)))
6579     (when (setq result
6580                 (if unread
6581                     (progn
6582                       (while data
6583                         (unless (memq (gnus-data-number (car data))
6584                                       (cond
6585                                        ((eq gnus-auto-goto-ignores
6586                                             'always-undownloaded)
6587                                         gnus-newsgroup-undownloaded)
6588                                        (gnus-plugged
6589                                         nil)
6590                                        ((eq gnus-auto-goto-ignores
6591                                             'unfetched)
6592                                         gnus-newsgroup-unfetched)
6593                                        ((eq gnus-auto-goto-ignores
6594                                             'undownloaded)
6595                                         gnus-newsgroup-undownloaded)))
6596                           (when (gnus-data-unread-p (car data))
6597                             (setq result (car data)
6598                                   data nil)))
6599                         (setq data (cdr data)))
6600                       result)
6601                   (car data)))
6602       (goto-char (gnus-data-pos result))
6603       (gnus-data-number result))))
6604
6605 (defun gnus-summary-find-subject (subject &optional unread backward article)
6606   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6607          (article (or article (gnus-summary-article-number)))
6608          (articles (gnus-data-list backward))
6609          (arts (gnus-data-find-list article articles))
6610          result)
6611     (when (or (not gnus-summary-check-current)
6612               (not unread)
6613               (not (gnus-data-unread-p (car arts))))
6614       (setq arts (cdr arts)))
6615     (while arts
6616       (and (or (not unread)
6617                (gnus-data-unread-p (car arts)))
6618            (vectorp (gnus-data-header (car arts)))
6619            (gnus-subject-equal
6620             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6621            (setq result (car arts)
6622                  arts nil))
6623       (setq arts (cdr arts)))
6624     (and result
6625          (goto-char (gnus-data-pos result))
6626          (gnus-data-number result))))
6627
6628 (defun gnus-summary-search-forward (&optional unread subject backward)
6629   "Search forward for an article.
6630 If UNREAD, look for unread articles.  If SUBJECT, look for
6631 articles with that subject.  If BACKWARD, search backward instead."
6632   (cond (subject (gnus-summary-find-subject subject unread backward))
6633         (backward (gnus-summary-find-prev unread))
6634         (t (gnus-summary-find-next unread))))
6635
6636 (defun gnus-recenter (&optional n)
6637   "Center point in window and redisplay frame.
6638 Also do horizontal recentering."
6639   (interactive "P")
6640   (when (and gnus-auto-center-summary
6641              (not (eq gnus-auto-center-summary 'vertical)))
6642     (gnus-horizontal-recenter))
6643   (recenter n))
6644
6645 (defun gnus-summary-recenter ()
6646   "Center point in the summary window.
6647 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6648 displayed, no centering will be performed."
6649   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6650   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6651   (interactive)
6652   ;; The user has to want it.
6653   (when gnus-auto-center-summary
6654     (let* ((top (cond ((< (window-height) 4) 0)
6655                       ((< (window-height) 7) 1)
6656                       (t (if (numberp gnus-auto-center-summary)
6657                              gnus-auto-center-summary
6658                            (/ (1- (window-height)) 2)))))
6659            (height (1- (window-height)))
6660            (bottom (save-excursion (goto-char (point-max))
6661                                    (forward-line (- height))
6662                                    (point)))
6663            (window (get-buffer-window (current-buffer))))
6664       (when (get-buffer-window gnus-article-buffer)
6665         ;; Only do recentering when the article buffer is displayed,
6666         ;; Set the window start to either `bottom', which is the biggest
6667         ;; possible valid number, or the second line from the top,
6668         ;; whichever is the least.
6669         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6670           (if (> bottom top-pos)
6671               ;; Keep the second line from the top visible
6672               (set-window-start window top-pos)
6673             ;; Try to keep the bottom line visible; if it's partially
6674             ;; obscured, either scroll one more line to make it fully
6675             ;; visible, or revert to using TOP-POS.
6676             (save-excursion
6677               (goto-char (point-max))
6678               (forward-line -1)
6679               (let ((last-line-start (point)))
6680                 (goto-char bottom)
6681                 (set-window-start window (point) t)
6682                 (when (not (pos-visible-in-window-p last-line-start window))
6683                   (forward-line 1)
6684                   (set-window-start window (min (point) top-pos) t)))))))
6685       ;; Do horizontal recentering while we're at it.
6686       (when (and (get-buffer-window (current-buffer) t)
6687                  (not (eq gnus-auto-center-summary 'vertical)))
6688         (let ((selected (selected-window)))
6689           (select-window (get-buffer-window (current-buffer) t))
6690           (gnus-summary-position-point)
6691           (gnus-horizontal-recenter)
6692           (select-window selected))))))
6693
6694 (defun gnus-summary-jump-to-group (newsgroup)
6695   "Move point to NEWSGROUP in group mode buffer."
6696   ;; Keep update point of group mode buffer if visible.
6697   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6698       (save-window-excursion
6699         ;; Take care of tree window mode.
6700         (when (get-buffer-window gnus-group-buffer)
6701           (pop-to-buffer gnus-group-buffer))
6702         (gnus-group-jump-to-group newsgroup))
6703     (save-excursion
6704       ;; Take care of tree window mode.
6705       (if (get-buffer-window gnus-group-buffer)
6706           (pop-to-buffer gnus-group-buffer)
6707         (set-buffer gnus-group-buffer))
6708       (gnus-group-jump-to-group newsgroup))))
6709
6710 ;; This function returns a list of article numbers based on the
6711 ;; difference between the ranges of read articles in this group and
6712 ;; the range of active articles.
6713 (defun gnus-list-of-unread-articles (group)
6714   (let* ((read (gnus-info-read (gnus-get-info group)))
6715          (active (or (gnus-active group) (gnus-activate-group group)))
6716          (last (or (cdr active)
6717                    (error "Group %s couldn't be activated " group)))
6718          (bottom (if gnus-newsgroup-maximum-articles
6719                      (max (car active)
6720                           (- last gnus-newsgroup-maximum-articles -1))
6721                    (car active)))
6722          first nlast unread)
6723     ;; If none are read, then all are unread.
6724     (if (not read)
6725         (setq first bottom)
6726       ;; If the range of read articles is a single range, then the
6727       ;; first unread article is the article after the last read
6728       ;; article.  Sounds logical, doesn't it?
6729       (if (and (not (listp (cdr read)))
6730                (or (< (car read) bottom)
6731                    (progn (setq read (list read))
6732                           nil)))
6733           (setq first (max bottom (1+ (cdr read))))
6734         ;; `read' is a list of ranges.
6735         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6736                                   (caar read)))
6737                   1)
6738           (setq first bottom))
6739         (while read
6740           (when first
6741             (while (< first nlast)
6742               (setq unread (cons first unread)
6743                     first (1+ first))))
6744           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6745           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6746           (setq read (cdr read)))))
6747     ;; And add the last unread articles.
6748     (while (<= first last)
6749       (setq unread (cons first unread)
6750             first (1+ first)))
6751     ;; Return the list of unread articles.
6752     (delq 0 (nreverse unread))))
6753
6754 (defun gnus-list-of-read-articles (group)
6755   "Return a list of unread, unticked and non-dormant articles."
6756   (let* ((info (gnus-get-info group))
6757          (marked (gnus-info-marks info))
6758          (active (gnus-active group)))
6759     (and info active
6760          (gnus-list-range-difference
6761           (gnus-list-range-difference
6762            (gnus-sorted-complement
6763             (gnus-uncompress-range
6764              (if gnus-newsgroup-maximum-articles
6765                  (cons (max (car active)
6766                             (- (cdr active)
6767                                gnus-newsgroup-maximum-articles
6768                                -1))
6769                        (cdr active))
6770                active))
6771             (gnus-list-of-unread-articles group))
6772            (cdr (assq 'dormant marked)))
6773           (cdr (assq 'tick marked))))))
6774
6775 ;; This function returns a sequence of article numbers based on the
6776 ;; difference between the ranges of read articles in this group and
6777 ;; the range of active articles.
6778 (defun gnus-sequence-of-unread-articles (group)
6779   (let* ((read (gnus-info-read (gnus-get-info group)))
6780          (active (or (gnus-active group) (gnus-activate-group group)))
6781          (last (cdr active))
6782          (bottom (if gnus-newsgroup-maximum-articles
6783                      (max (car active)
6784                           (- last gnus-newsgroup-maximum-articles -1))
6785                    (car active)))
6786          first nlast unread)
6787     ;; If none are read, then all are unread.
6788     (if (not read)
6789         (setq first bottom)
6790       ;; If the range of read articles is a single range, then the
6791       ;; first unread article is the article after the last read
6792       ;; article.  Sounds logical, doesn't it?
6793       (if (and (not (listp (cdr read)))
6794                (or (< (car read) bottom)
6795                    (progn (setq read (list read))
6796                           nil)))
6797           (setq first (max bottom (1+ (cdr read))))
6798         ;; `read' is a list of ranges.
6799         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6800                                   (caar read)))
6801                   1)
6802           (setq first bottom))
6803         (while read
6804           (when first
6805             (push (cons first nlast) unread))
6806           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6807           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6808           (setq read (cdr read)))))
6809     ;; And add the last unread articles.
6810     (cond ((not (and first last))
6811            nil)
6812           ((< first last)
6813            (push (cons first last) unread))
6814           ((= first last)
6815            (push first unread)))
6816     ;; Return the sequence of unread articles.
6817     (delq 0 (nreverse unread))))
6818
6819 ;; Various summary commands
6820
6821 (defun gnus-summary-select-article-buffer ()
6822   "Reconfigure windows to show article buffer."
6823   (interactive)
6824   (if (not (gnus-buffer-live-p gnus-article-buffer))
6825       (error "There is no article buffer for this summary buffer")
6826     (gnus-configure-windows 'article)
6827     (select-window (get-buffer-window gnus-article-buffer))))
6828
6829 (defun gnus-summary-universal-argument (arg)
6830   "Perform any operation on all articles that are process/prefixed."
6831   (interactive "P")
6832   (let ((articles (gnus-summary-work-articles arg))
6833         func article)
6834     (if (eq
6835          (setq
6836           func
6837           (key-binding
6838            (read-key-sequence
6839             (substitute-command-keys
6840              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6841          'undefined)
6842         (gnus-error 1 "Undefined key")
6843       (save-excursion
6844         (while articles
6845           (gnus-summary-goto-subject (setq article (pop articles)))
6846           (let (gnus-newsgroup-processable)
6847             (command-execute func))
6848           (gnus-summary-remove-process-mark article)))))
6849   (gnus-summary-position-point))
6850
6851 (defun gnus-summary-toggle-truncation (&optional arg)
6852   "Toggle truncation of summary lines.
6853 With ARG, turn line truncation on if ARG is positive."
6854   (interactive "P")
6855   (setq truncate-lines
6856         (if (null arg) (not truncate-lines)
6857           (> (prefix-numeric-value arg) 0)))
6858   (redraw-display))
6859
6860 (defun gnus-summary-find-for-reselect ()
6861   "Return the number of an article to stay on across a reselect.
6862 The current article is considered, then following articles, then previous
6863 articles.  An article is sought which is not cancelled and isn't a temporary
6864 insertion from another group.  If there's no such then return a dummy 0."
6865   (let (found)
6866     (dolist (rev '(nil t))
6867       (unless found      ; don't demand the reverse list if we don't need it
6868         (let ((data (gnus-data-find-list
6869                      (gnus-summary-article-number) (gnus-data-list rev))))
6870           (while (and data (not found))
6871             (if (and (< 0 (gnus-data-number (car data)))
6872                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6873                 (setq found (gnus-data-number (car data))))
6874             (setq data (cdr data))))))
6875     (or found 0)))
6876
6877 (defun gnus-summary-reselect-current-group (&optional all rescan)
6878   "Exit and then reselect the current newsgroup.
6879 The prefix argument ALL means to select all articles."
6880   (interactive "P")
6881   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6882     (error "Ephemeral groups can't be reselected"))
6883   (let ((current-subject (gnus-summary-find-for-reselect))
6884         (group gnus-newsgroup-name))
6885     (setq gnus-newsgroup-begin nil)
6886     (gnus-summary-exit nil 'leave-hidden)
6887     ;; We have to adjust the point of group mode buffer because
6888     ;; point was moved to the next unread newsgroup by exiting.
6889     (gnus-summary-jump-to-group group)
6890     (when rescan
6891       (save-excursion
6892         (gnus-group-get-new-news-this-group 1)))
6893     (gnus-group-read-group all t)
6894     (gnus-summary-goto-subject current-subject nil t)))
6895
6896 (defun gnus-summary-rescan-group (&optional all)
6897   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6898   (interactive "P")
6899   (gnus-summary-reselect-current-group all t))
6900
6901 (defun gnus-summary-update-info (&optional non-destructive)
6902   (save-excursion
6903     (let ((group gnus-newsgroup-name))
6904       (when group
6905         (when gnus-newsgroup-kill-headers
6906           (setq gnus-newsgroup-killed
6907                 (gnus-compress-sequence
6908                  (gnus-sorted-union
6909                   (gnus-list-range-intersection
6910                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6911                   gnus-newsgroup-unreads)
6912                  t)))
6913         (unless (listp (cdr gnus-newsgroup-killed))
6914           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6915         (let ((headers gnus-newsgroup-headers))
6916           ;; Set the new ranges of read articles.
6917           (with-current-buffer gnus-group-buffer
6918             (gnus-undo-force-boundary))
6919           (gnus-update-read-articles
6920            group (gnus-sorted-union
6921                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6922           ;; Set the current article marks.
6923           (let ((gnus-newsgroup-scored
6924                  (if (and (not gnus-save-score)
6925                           (not non-destructive))
6926                      nil
6927                    gnus-newsgroup-scored)))
6928             (save-excursion
6929               (gnus-update-marks)))
6930           ;; Do the cross-ref thing.
6931           (when gnus-use-cross-reference
6932             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6933           ;; Do not switch windows but change the buffer to work.
6934           (set-buffer gnus-group-buffer)
6935           (unless (gnus-ephemeral-group-p group)
6936             (gnus-group-update-group group)))))))
6937
6938 (defun gnus-summary-save-newsrc (&optional force)
6939   "Save the current number of read/marked articles in the dribble buffer.
6940 The dribble buffer will then be saved.
6941 If FORCE (the prefix), also save the .newsrc file(s)."
6942   (interactive "P")
6943   (gnus-summary-update-info t)
6944   (if force
6945       (gnus-save-newsrc-file)
6946     (gnus-dribble-save)))
6947
6948 (defun gnus-summary-exit (&optional temporary leave-hidden)
6949   "Exit reading current newsgroup, and then return to group selection mode.
6950 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6951   (interactive)
6952   (gnus-set-global-variables)
6953   (when (gnus-buffer-live-p gnus-article-buffer)
6954     (save-excursion
6955       (set-buffer gnus-article-buffer)
6956       (mm-destroy-parts gnus-article-mime-handles)
6957       ;; Set it to nil for safety reason.
6958       (setq gnus-article-mime-handle-alist nil)
6959       (setq gnus-article-mime-handles nil)))
6960   (gnus-kill-save-kill-buffer)
6961   (gnus-async-halt-prefetch)
6962   (let* ((group gnus-newsgroup-name)
6963          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6964          (gnus-group-is-exiting-p t)
6965          (mode major-mode)
6966          (group-point nil)
6967          (buf (current-buffer)))
6968     (unless quit-config
6969       ;; Do adaptive scoring, and possibly save score files.
6970       (when gnus-newsgroup-adaptive
6971         (gnus-score-adaptive))
6972       (when gnus-use-scoring
6973         (gnus-score-save)))
6974     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6975     ;; If we have several article buffers, we kill them at exit.
6976     (unless gnus-single-article-buffer
6977       (when (gnus-buffer-live-p gnus-article-buffer)
6978         (with-current-buffer gnus-article-buffer
6979           ;; Don't kill sticky article buffers
6980           (unless (eq major-mode 'gnus-sticky-article-mode)
6981             (gnus-kill-buffer gnus-article-buffer)
6982             (setq gnus-article-current nil))))
6983       (gnus-kill-buffer gnus-original-article-buffer))
6984     (when gnus-use-cache
6985       (gnus-cache-possibly-remove-articles)
6986       (gnus-cache-save-buffers))
6987     (gnus-async-prefetch-remove-group group)
6988     (when gnus-suppress-duplicates
6989       (gnus-dup-enter-articles))
6990     (when gnus-use-trees
6991       (gnus-tree-close group))
6992     (when gnus-use-cache
6993       (gnus-cache-write-active))
6994     ;; Remove entries for this group.
6995     (nnmail-purge-split-history (gnus-group-real-name group))
6996     ;; Make all changes in this group permanent.
6997     (unless quit-config
6998       (gnus-run-hooks 'gnus-exit-group-hook)
6999       (gnus-summary-update-info))
7000     (gnus-close-group group)
7001     ;; Make sure where we were, and go to next newsgroup.
7002     (set-buffer gnus-group-buffer)
7003     (unless quit-config
7004       (gnus-group-jump-to-group group))
7005     (gnus-run-hooks 'gnus-summary-exit-hook)
7006     (unless (or quit-config
7007                 (not gnus-summary-next-group-on-exit)
7008                 ;; If this group has disappeared from the summary
7009                 ;; buffer, don't skip forwards.
7010                 (not (string= group (gnus-group-group-name))))
7011       (gnus-group-next-unread-group 1))
7012     (setq group-point (point))
7013     (if temporary
7014         nil                             ;Nothing to do.
7015       (set-buffer buf)
7016       (if (not gnus-kill-summary-on-exit)
7017           (progn
7018             (gnus-deaden-summary)
7019             (setq mode nil))
7020         ;; We set all buffer-local variables to nil.  It is unclear why
7021         ;; this is needed, but if we don't, buffer-local variables are
7022         ;; not garbage-collected, it seems.  This would the lead to en
7023         ;; ever-growing Emacs.
7024         (gnus-summary-clear-local-variables)
7025         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7026           (gnus-summary-clear-local-variables))
7027         (when (get-buffer gnus-article-buffer)
7028           (bury-buffer gnus-article-buffer))
7029         ;; Return to group mode buffer.
7030         (when (eq mode 'gnus-summary-mode)
7031           (gnus-kill-buffer buf)))
7032       (setq gnus-current-select-method gnus-select-method)
7033       (set-buffer gnus-group-buffer)
7034       (if quit-config
7035           (gnus-handle-ephemeral-exit quit-config)
7036         (goto-char group-point)
7037         ;; If gnus-group-buffer is already displayed, make sure we also move
7038         ;; the cursor in the window that displays it.
7039         (let ((win (get-buffer-window (current-buffer) 0)))
7040           (if win (set-window-point win (point))))
7041         (unless leave-hidden
7042           (gnus-configure-windows 'group 'force)))
7043       ;; Clear the current group name.
7044       (unless quit-config
7045         (setq gnus-newsgroup-name nil)))))
7046
7047 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7048 (defun gnus-summary-exit-no-update (&optional no-questions)
7049   "Quit reading current newsgroup without updating read article info."
7050   (interactive)
7051   (let* ((group gnus-newsgroup-name)
7052          (gnus-group-is-exiting-p t)
7053          (gnus-group-is-exiting-without-update-p t)
7054          (quit-config (gnus-group-quit-config group)))
7055     (when (or no-questions
7056               gnus-expert-user
7057               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7058       (gnus-async-halt-prefetch)
7059       (run-hooks 'gnus-summary-prepare-exit-hook)
7060       (when (gnus-buffer-live-p gnus-article-buffer)
7061         (save-excursion
7062           (set-buffer gnus-article-buffer)
7063           (mm-destroy-parts gnus-article-mime-handles)
7064           ;; Set it to nil for safety reason.
7065           (setq gnus-article-mime-handle-alist nil)
7066           (setq gnus-article-mime-handles nil)))
7067       ;; If we have several article buffers, we kill them at exit.
7068       (unless gnus-single-article-buffer
7069         (gnus-kill-buffer gnus-article-buffer)
7070         (gnus-kill-buffer gnus-original-article-buffer)
7071         (setq gnus-article-current nil))
7072       (if (not gnus-kill-summary-on-exit)
7073           (gnus-deaden-summary)
7074         (gnus-close-group group)
7075         (gnus-summary-clear-local-variables)
7076         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7077           (gnus-summary-clear-local-variables))
7078         (gnus-kill-buffer gnus-summary-buffer))
7079       (unless gnus-single-article-buffer
7080         (setq gnus-article-current nil))
7081       (when gnus-use-trees
7082         (gnus-tree-close group))
7083       (gnus-async-prefetch-remove-group group)
7084       (when (get-buffer gnus-article-buffer)
7085         (bury-buffer gnus-article-buffer))
7086       ;; Return to the group buffer.
7087       (gnus-configure-windows 'group 'force)
7088       ;; Clear the current group name.
7089       (setq gnus-newsgroup-name nil)
7090       (unless (gnus-ephemeral-group-p group)
7091         (gnus-group-update-group group))
7092       (when (equal (gnus-group-group-name) group)
7093         (gnus-group-next-unread-group 1))
7094       (when quit-config
7095         (gnus-handle-ephemeral-exit quit-config)))))
7096
7097 (defun gnus-handle-ephemeral-exit (quit-config)
7098   "Handle movement when leaving an ephemeral group.
7099 The state which existed when entering the ephemeral is reset."
7100   (if (not (buffer-name (car quit-config)))
7101       (gnus-configure-windows 'group 'force)
7102     (set-buffer (car quit-config))
7103     (cond ((eq major-mode 'gnus-summary-mode)
7104            (gnus-set-global-variables))
7105           ((eq major-mode 'gnus-article-mode)
7106            (save-excursion
7107              ;; The `gnus-summary-buffer' variable may point
7108              ;; to the old summary buffer when using a single
7109              ;; article buffer.
7110              (unless (gnus-buffer-live-p gnus-summary-buffer)
7111                (set-buffer gnus-group-buffer))
7112              (set-buffer gnus-summary-buffer)
7113              (gnus-set-global-variables))))
7114     (if (or (eq (cdr quit-config) 'article)
7115             (eq (cdr quit-config) 'pick))
7116         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7117             (gnus-configure-windows 'pick 'force)
7118           (gnus-configure-windows (cdr quit-config) 'force))
7119       (gnus-configure-windows (cdr quit-config) 'force))
7120     (when (eq major-mode 'gnus-summary-mode)
7121       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7122                                                      next-unread-noselect))
7123           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7124                                   'next-noselect)
7125                               (gnus-summary-next-subject 1 nil t))
7126                              ((eq gnus-auto-select-on-ephemeral-exit
7127                                   'next-unread-noselect)
7128                               (gnus-summary-next-subject 1 t t))))
7129             ;; Hide the article buffer which displays the article different
7130             ;; from the one that the cursor points to in the summary buffer.
7131             (gnus-configure-windows 'summary 'force))
7132         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7133                (gnus-summary-next-subject 1))
7134               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7135                (gnus-summary-next-subject 1 t))))
7136       (gnus-summary-recenter)
7137       (gnus-summary-position-point))))
7138
7139 ;;; Dead summaries.
7140
7141 (defvar gnus-dead-summary-mode-map nil)
7142
7143 (unless gnus-dead-summary-mode-map
7144   (setq gnus-dead-summary-mode-map (make-keymap))
7145   (suppress-keymap gnus-dead-summary-mode-map)
7146   (substitute-key-definition
7147    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7148   (dolist (key '("\C-d" "\r" "\177" [delete]))
7149     (define-key gnus-dead-summary-mode-map
7150       key 'gnus-summary-wake-up-the-dead))
7151   (dolist (key '("q" "Q"))
7152     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7153
7154 (defvar gnus-dead-summary-mode nil
7155   "Minor mode for Gnus summary buffers.")
7156
7157 (defun gnus-dead-summary-mode (&optional arg)
7158   "Minor mode for Gnus summary buffers."
7159   (interactive "P")
7160   (when (eq major-mode 'gnus-summary-mode)
7161     (make-local-variable 'gnus-dead-summary-mode)
7162     (setq gnus-dead-summary-mode
7163           (if (null arg) (not gnus-dead-summary-mode)
7164             (> (prefix-numeric-value arg) 0)))
7165     (when gnus-dead-summary-mode
7166       (add-minor-mode
7167        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7168
7169 (defun gnus-deaden-summary ()
7170   "Make the current summary buffer into a dead summary buffer."
7171   ;; Kill any previous dead summary buffer.
7172   (when (and gnus-dead-summary
7173              (buffer-name gnus-dead-summary))
7174     (with-current-buffer gnus-dead-summary
7175       (when gnus-dead-summary-mode
7176         (kill-buffer (current-buffer)))))
7177   ;; Make this the current dead summary.
7178   (setq gnus-dead-summary (current-buffer))
7179   (gnus-dead-summary-mode 1)
7180   (let ((name (buffer-name)))
7181     (when (string-match "Summary" name)
7182       (rename-buffer
7183        (concat (substring name 0 (match-beginning 0)) "Dead "
7184                (substring name (match-beginning 0)))
7185        t)
7186       (bury-buffer))))
7187
7188 (defun gnus-kill-or-deaden-summary (buffer)
7189   "Kill or deaden the summary BUFFER."
7190   (save-excursion
7191     (when (and (buffer-name buffer)
7192                (not gnus-single-article-buffer))
7193       (with-current-buffer buffer
7194         (gnus-kill-buffer gnus-article-buffer)
7195         (gnus-kill-buffer gnus-original-article-buffer)))
7196     (cond
7197      ;; Kill the buffer.
7198      (gnus-kill-summary-on-exit
7199       (when (and gnus-use-trees
7200                  (gnus-buffer-exists-p buffer))
7201         (save-excursion
7202           (set-buffer buffer)
7203           (gnus-tree-close gnus-newsgroup-name)))
7204       (gnus-kill-buffer buffer))
7205      ;; Deaden the buffer.
7206      ((gnus-buffer-exists-p buffer)
7207       (save-excursion
7208         (set-buffer buffer)
7209         (gnus-deaden-summary))))))
7210
7211 (defun gnus-summary-wake-up-the-dead (&rest args)
7212   "Wake up the dead summary buffer."
7213   (interactive)
7214   (gnus-dead-summary-mode -1)
7215   (let ((name (buffer-name)))
7216     (when (string-match "Dead " name)
7217       (rename-buffer
7218        (concat (substring name 0 (match-beginning 0))
7219                (substring name (match-end 0)))
7220        t)))
7221   (gnus-message 3 "This dead summary is now alive again"))
7222
7223 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7224 (defun gnus-summary-fetch-faq (&optional faq-dir)
7225   "Fetch the FAQ for the current group.
7226 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7227 in."
7228   (interactive
7229    (list
7230     (when current-prefix-arg
7231       (completing-read
7232        "FAQ dir: " (and (listp gnus-group-faq-directory)
7233                         (mapcar 'list
7234                                 gnus-group-faq-directory))))))
7235   (let (gnus-faq-buffer)
7236     (when (setq gnus-faq-buffer
7237                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7238       (gnus-configure-windows 'summary-faq))))
7239
7240 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7241 (defun gnus-summary-describe-group (&optional force)
7242   "Describe the current newsgroup."
7243   (interactive "P")
7244   (gnus-group-describe-group force gnus-newsgroup-name))
7245
7246 (defun gnus-summary-describe-briefly ()
7247   "Describe summary mode commands briefly."
7248   (interactive)
7249   (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")))
7250
7251 ;; Walking around group mode buffer from summary mode.
7252
7253 (defun gnus-summary-next-group (&optional no-article target-group backward)
7254   "Exit current newsgroup and then select next unread newsgroup.
7255 If prefix argument NO-ARTICLE is non-nil, no article is selected
7256 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7257 previous group instead."
7258   (interactive "P")
7259   ;; Stop pre-fetching.
7260   (gnus-async-halt-prefetch)
7261   (let ((current-group gnus-newsgroup-name)
7262         (current-buffer (current-buffer))
7263         entered)
7264     ;; First we semi-exit this group to update Xrefs and all variables.
7265     ;; We can't do a real exit, because the window conf must remain
7266     ;; the same in case the user is prompted for info, and we don't
7267     ;; want the window conf to change before that...
7268     (gnus-summary-exit t)
7269     (while (not entered)
7270       ;; Then we find what group we are supposed to enter.
7271       (set-buffer gnus-group-buffer)
7272       (gnus-group-jump-to-group current-group)
7273       (setq target-group
7274             (or target-group
7275                 (if (eq gnus-keep-same-level 'best)
7276                     (gnus-summary-best-group gnus-newsgroup-name)
7277                   (gnus-summary-search-group backward gnus-keep-same-level))))
7278       (if (not target-group)
7279           ;; There are no further groups, so we return to the group
7280           ;; buffer.
7281           (progn
7282             (gnus-message 5 "Returning to the group buffer")
7283             (setq entered t)
7284             (when (gnus-buffer-live-p current-buffer)
7285               (set-buffer current-buffer)
7286               (gnus-summary-exit))
7287             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7288         ;; We try to enter the target group.
7289         (gnus-group-jump-to-group target-group)
7290         (let ((unreads (gnus-group-group-unread)))
7291           (if (and (or (eq t unreads)
7292                        (and unreads (not (zerop unreads))))
7293                    (gnus-summary-read-group
7294                     target-group nil no-article
7295                     (and (buffer-name current-buffer) current-buffer)
7296                     nil backward))
7297               (setq entered t)
7298             (setq current-group target-group
7299                   target-group nil)))))))
7300
7301 (defun gnus-summary-prev-group (&optional no-article)
7302   "Exit current newsgroup and then select previous unread newsgroup.
7303 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7304   (interactive "P")
7305   (gnus-summary-next-group no-article nil t))
7306
7307 ;; Walking around summary lines.
7308
7309 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7310   "Go to the first subject satisfying any non-nil constraint.
7311 If UNREAD is non-nil, the article should be unread.
7312 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7313 If UNSEEN is non-nil, the article should be unseen.
7314 Returns the article selected or nil if there are no matching articles."
7315   (interactive "P")
7316   (cond
7317    ;; Empty summary.
7318    ((null gnus-newsgroup-data)
7319     (gnus-message 3 "No articles in the group")
7320     nil)
7321    ;; Pick the first article.
7322    ((not (or unread undownloaded unseen))
7323     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7324     (gnus-data-number (car gnus-newsgroup-data)))
7325    ;; Find the first unread article.
7326    (t
7327     (let ((data gnus-newsgroup-data))
7328       (while (and data
7329                   (let ((num (gnus-data-number (car data))))
7330                     (or (memq num gnus-newsgroup-unfetched)
7331                         (not (or (and unread
7332                                       (memq num gnus-newsgroup-unreads))
7333                                  (and undownloaded
7334                                       (memq num gnus-newsgroup-undownloaded))
7335                                  (and unseen
7336                                       (memq num gnus-newsgroup-unseen)))))))
7337         (setq data (cdr data)))
7338       (prog1
7339           (if data
7340               (progn
7341                 (goto-char (gnus-data-pos (car data)))
7342                 (gnus-data-number (car data)))
7343             (gnus-message 3 "No more%s articles"
7344                           (let* ((r (when unread " unread"))
7345                                  (d (when undownloaded " undownloaded"))
7346                                  (s (when unseen " unseen"))
7347                                  (l (delq nil (list r d s))))
7348                             (cond ((= 3 (length l))
7349                                    (concat r "," d ", or" s))
7350                                   ((= 2 (length l))
7351                                    (concat (car l) ", or" (cadr l)))
7352                                   ((= 1 (length l))
7353                                    (car l))
7354                                   (t
7355                                    ""))))
7356             nil
7357             )
7358         (gnus-summary-position-point))))))
7359
7360 (defun gnus-summary-next-subject (n &optional unread dont-display)
7361   "Go to next N'th summary line.
7362 If N is negative, go to the previous N'th subject line.
7363 If UNREAD is non-nil, only unread articles are selected.
7364 The difference between N and the actual number of steps taken is
7365 returned."
7366   (interactive "p")
7367   (let ((backward (< n 0))
7368         (n (abs n)))
7369     (while (and (> n 0)
7370                 (if backward
7371                     (gnus-summary-find-prev unread)
7372                   (gnus-summary-find-next unread)))
7373       (unless (zerop (setq n (1- n)))
7374         (gnus-summary-show-thread)))
7375     (when (/= 0 n)
7376       (gnus-message 7 "No more%s articles"
7377                     (if unread " unread" "")))
7378     (unless dont-display
7379       (gnus-summary-recenter)
7380       (gnus-summary-position-point))
7381     n))
7382
7383 (defun gnus-summary-next-unread-subject (n)
7384   "Go to next N'th unread summary line."
7385   (interactive "p")
7386   (gnus-summary-next-subject n t))
7387
7388 (defun gnus-summary-prev-subject (n &optional unread)
7389   "Go to previous N'th summary line.
7390 If optional argument UNREAD is non-nil, only unread article is selected."
7391   (interactive "p")
7392   (gnus-summary-next-subject (- n) unread))
7393
7394 (defun gnus-summary-prev-unread-subject (n)
7395   "Go to previous N'th unread summary line."
7396   (interactive "p")
7397   (gnus-summary-next-subject (- n) t))
7398
7399 (defun gnus-summary-goto-subjects (articles)
7400   "Insert the subject header for ARTICLES in the current buffer."
7401   (save-excursion
7402     (dolist (article articles)
7403       (gnus-summary-goto-subject article t)))
7404   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7405   (gnus-summary-position-point))
7406
7407 (defun gnus-summary-goto-subject (article &optional force silent)
7408   "Go the subject line of ARTICLE.
7409 If FORCE, also allow jumping to articles not currently shown."
7410   (interactive "nArticle number: ")
7411   (unless (numberp article)
7412     (error "Article %s is not a number" article))
7413   (let ((b (point))
7414         (data (gnus-data-find article)))
7415     ;; We read in the article if we have to.
7416     (and (not data)
7417          force
7418          (gnus-summary-insert-subject
7419           article
7420           (if (or (numberp force) (vectorp force)) force)
7421           t)
7422          (setq data (gnus-data-find article)))
7423     (goto-char b)
7424     (if (not data)
7425         (progn
7426           (unless silent
7427             (gnus-message 3 "Can't find article %d" article))
7428           nil)
7429       (let ((pt (gnus-data-pos data)))
7430         (goto-char pt)
7431         (gnus-summary-set-article-display-arrow pt))
7432       (gnus-summary-position-point)
7433       article)))
7434
7435 ;; Walking around summary lines with displaying articles.
7436
7437 (defun gnus-summary-expand-window (&optional arg)
7438   "Make the summary buffer take up the entire Emacs frame.
7439 Given a prefix, will force an `article' buffer configuration."
7440   (interactive "P")
7441   (if arg
7442       (gnus-configure-windows 'article 'force)
7443     (gnus-configure-windows 'summary 'force)))
7444
7445 (defun gnus-summary-display-article (article &optional all-header)
7446   "Display ARTICLE in article buffer."
7447   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7448                (with-current-buffer gnus-article-buffer
7449                  (eq major-mode 'gnus-article-mode)))
7450     (gnus-article-setup-buffer))
7451   (gnus-set-global-variables)
7452   (with-current-buffer gnus-article-buffer
7453     (setq gnus-article-charset gnus-newsgroup-charset)
7454     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7455     (mm-enable-multibyte))
7456   (if (null article)
7457       nil
7458     (prog1
7459         (if gnus-summary-display-article-function
7460             (funcall gnus-summary-display-article-function article all-header)
7461           (gnus-article-prepare article all-header))
7462       (gnus-run-hooks 'gnus-select-article-hook)
7463       (when (and gnus-current-article
7464                  (not (zerop gnus-current-article)))
7465         (gnus-summary-goto-subject gnus-current-article))
7466       (gnus-summary-recenter)
7467       (when (and gnus-use-trees gnus-show-threads)
7468         (gnus-possibly-generate-tree article)
7469         (gnus-highlight-selected-tree article))
7470       ;; Successfully display article.
7471       (gnus-article-set-window-start
7472        (cdr (assq article gnus-newsgroup-bookmarks))))))
7473
7474 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7475   "Select the current article.
7476 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7477 non-nil, the article will be re-fetched even if it already present in
7478 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7479 be displayed."
7480   ;; Make sure we are in the summary buffer to work around bbdb bug.
7481   (unless (eq major-mode 'gnus-summary-mode)
7482     (set-buffer gnus-summary-buffer))
7483   (let ((article (or article (gnus-summary-article-number)))
7484         (all-headers (not (not all-headers))) ;Must be t or nil.
7485         gnus-summary-display-article-function)
7486     (and (not pseudo)
7487          (gnus-summary-article-pseudo-p article)
7488          (error "This is a pseudo-article"))
7489     (save-excursion
7490       (set-buffer gnus-summary-buffer)
7491       (if (or (and gnus-single-article-buffer
7492                    (or (null gnus-current-article)
7493                        (null gnus-article-current)
7494                        (null (get-buffer gnus-article-buffer))
7495                        (not (eq article (cdr gnus-article-current)))
7496                        (not (equal (car gnus-article-current)
7497                                    gnus-newsgroup-name))))
7498               (and (not gnus-single-article-buffer)
7499                    (or (null gnus-current-article)
7500                        (not (eq gnus-current-article article))))
7501               force)
7502           ;; The requested article is different from the current article.
7503           (progn
7504             (gnus-summary-display-article article all-headers)
7505             (when (gnus-buffer-live-p gnus-article-buffer)
7506               (with-current-buffer gnus-article-buffer
7507                 (if (not gnus-article-decoded-p) ;; a local variable
7508                     (mm-disable-multibyte))))
7509             (gnus-article-set-window-start
7510              (cdr (assq article gnus-newsgroup-bookmarks)))
7511             article)
7512         'old))))
7513
7514 (defun gnus-summary-force-verify-and-decrypt ()
7515   "Display buttons for signed/encrypted parts and verify/decrypt them."
7516   (interactive)
7517   (let ((mm-verify-option 'known)
7518         (mm-decrypt-option 'known)
7519         (gnus-article-emulate-mime t)
7520         (gnus-buttonized-mime-types (append (list "multipart/signed"
7521                                                   "multipart/encrypted")
7522                                             gnus-buttonized-mime-types)))
7523     (gnus-summary-select-article nil 'force)))
7524
7525 (defun gnus-summary-set-current-mark (&optional current-mark)
7526   "Obsolete function."
7527   nil)
7528
7529 (defun gnus-summary-next-article (&optional unread subject backward push)
7530   "Select the next article.
7531 If UNREAD, only unread articles are selected.
7532 If SUBJECT, only articles with SUBJECT are selected.
7533 If BACKWARD, the previous article is selected instead of the next."
7534   (interactive "P")
7535   ;; Make sure we are in the summary buffer.
7536   (unless (eq major-mode 'gnus-summary-mode)
7537     (set-buffer gnus-summary-buffer))
7538   (cond
7539    ;; Is there such an article?
7540    ((and (gnus-summary-search-forward unread subject backward)
7541          (or (gnus-summary-display-article (gnus-summary-article-number))
7542              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7543     (gnus-summary-position-point))
7544    ;; If not, we try the first unread, if that is wanted.
7545    ((and subject
7546          gnus-auto-select-same
7547          (gnus-summary-first-unread-article))
7548     (gnus-summary-position-point)
7549     (gnus-message 6 "Wrapped"))
7550    ;; Try to get next/previous article not displayed in this group.
7551    ((and gnus-auto-extend-newsgroup
7552          (not unread) (not subject))
7553     (gnus-summary-goto-article
7554      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7555      nil (count-lines (point-min) (point))))
7556    ;; Go to next/previous group.
7557    (t
7558     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7559       (gnus-summary-jump-to-group gnus-newsgroup-name))
7560     (let ((cmd last-command-char)
7561           (point
7562            (with-current-buffer gnus-group-buffer
7563              (point)))
7564           (group
7565            (if (eq gnus-keep-same-level 'best)
7566                (gnus-summary-best-group gnus-newsgroup-name)
7567              (gnus-summary-search-group backward gnus-keep-same-level))))
7568       ;; For some reason, the group window gets selected.  We change
7569       ;; it back.
7570       (select-window (get-buffer-window (current-buffer)))
7571       ;; Select next unread newsgroup automagically.
7572       (cond
7573        ((or (not gnus-auto-select-next)
7574             (not cmd))
7575         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7576        ((or (eq gnus-auto-select-next 'quietly)
7577             (and (eq gnus-auto-select-next 'slightly-quietly)
7578                  push)
7579             (and (eq gnus-auto-select-next 'almost-quietly)
7580                  (gnus-summary-last-article-p)))
7581         ;; Select quietly.
7582         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7583             (gnus-summary-exit)
7584           (gnus-message 7 "No more%s articles (%s)..."
7585                         (if unread " unread" "")
7586                         (if group (concat "selecting " group)
7587                           "exiting"))
7588           (gnus-summary-next-group nil group backward)))
7589        (t
7590         (when (gnus-key-press-event-p last-input-event)
7591           (gnus-summary-walk-group-buffer
7592            gnus-newsgroup-name cmd unread backward point))))))))
7593
7594 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7595   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7596                       (?\C-p (gnus-group-prev-unread-group 1))))
7597         (cursor-in-echo-area t)
7598         keve key group ended prompt)
7599     (save-excursion
7600       (set-buffer gnus-group-buffer)
7601       (goto-char start)
7602       (setq group
7603             (if (eq gnus-keep-same-level 'best)
7604                 (gnus-summary-best-group gnus-newsgroup-name)
7605               (gnus-summary-search-group backward gnus-keep-same-level))))
7606     (while (not ended)
7607       (setq prompt
7608             (format
7609              "No more%s articles%s " (if unread " unread" "")
7610              (if (and group
7611                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7612                  (format " (Type %s for %s [%s])"
7613                          (single-key-description cmd)
7614                          (gnus-group-decoded-name group)
7615                          (gnus-group-unread group))
7616                (format " (Type %s to exit %s)"
7617                        (single-key-description cmd)
7618                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7619       ;; Confirm auto selection.
7620       (setq key (car (setq keve (gnus-read-event-char prompt)))
7621             ended t)
7622       (cond
7623        ((assq key keystrokes)
7624         (let ((obuf (current-buffer)))
7625           (switch-to-buffer gnus-group-buffer)
7626           (when group
7627             (gnus-group-jump-to-group group))
7628           (eval (cadr (assq key keystrokes)))
7629           (setq group (gnus-group-group-name))
7630           (switch-to-buffer obuf))
7631         (setq ended nil))
7632        ((equal key cmd)
7633         (if (or (not group)
7634                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7635             (gnus-summary-exit)
7636           (gnus-summary-next-group nil group backward)))
7637        (t
7638         (push (cdr keve) unread-command-events))))))
7639
7640 (defun gnus-summary-next-unread-article ()
7641   "Select unread article after current one."
7642   (interactive)
7643   (gnus-summary-next-article
7644    (or (not (eq gnus-summary-goto-unread 'never))
7645        (gnus-summary-last-article-p (gnus-summary-article-number)))
7646    (and gnus-auto-select-same
7647         (gnus-summary-article-subject))))
7648
7649 (defun gnus-summary-prev-article (&optional unread subject)
7650   "Select the article after the current one.
7651 If UNREAD is non-nil, only unread articles are selected."
7652   (interactive "P")
7653   (gnus-summary-next-article unread subject t))
7654
7655 (defun gnus-summary-prev-unread-article ()
7656   "Select unread article before current one."
7657   (interactive)
7658   (gnus-summary-prev-article
7659    (or (not (eq gnus-summary-goto-unread 'never))
7660        (gnus-summary-first-article-p (gnus-summary-article-number)))
7661    (and gnus-auto-select-same
7662         (gnus-summary-article-subject))))
7663
7664 (defun gnus-summary-next-page (&optional lines circular stop)
7665   "Show next page of the selected article.
7666 If at the end of the current article, select the next article.
7667 LINES says how many lines should be scrolled up.
7668
7669 If CIRCULAR is non-nil, go to the start of the article instead of
7670 selecting the next article when reaching the end of the current
7671 article.
7672
7673 If STOP is non-nil, just stop when reaching the end of the message.
7674
7675 Also see the variable `gnus-article-skip-boring'."
7676   (interactive "P")
7677   (setq gnus-summary-buffer (current-buffer))
7678   (gnus-set-global-variables)
7679   (let ((article (gnus-summary-article-number))
7680         (article-window (get-buffer-window gnus-article-buffer t))
7681         endp)
7682     ;; If the buffer is empty, we have no article.
7683     (unless article
7684       (error "No article to select"))
7685     (gnus-configure-windows 'article)
7686     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7687         (if (and (eq gnus-summary-goto-unread 'never)
7688                  (not (gnus-summary-last-article-p article)))
7689             (gnus-summary-next-article)
7690           (gnus-summary-next-unread-article))
7691       (if (or (null gnus-current-article)
7692               (null gnus-article-current)
7693               (/= article (cdr gnus-article-current))
7694               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7695           ;; Selected subject is different from current article's.
7696           (gnus-summary-display-article article)
7697         (when article-window
7698           (gnus-eval-in-buffer-window gnus-article-buffer
7699             (setq endp (or (gnus-article-next-page lines)
7700                            (gnus-article-only-boring-p))))
7701           (when endp
7702             (cond (stop
7703                    (gnus-message 3 "End of message"))
7704                   (circular
7705                    (gnus-summary-beginning-of-article))
7706                   (lines
7707                    (gnus-message 3 "End of message"))
7708                   ((null lines)
7709                    (if (and (eq gnus-summary-goto-unread 'never)
7710                             (not (gnus-summary-last-article-p article)))
7711                        (gnus-summary-next-article)
7712                      (gnus-summary-next-unread-article))))))))
7713     (gnus-summary-recenter)
7714     (gnus-summary-position-point)))
7715
7716 (defun gnus-summary-prev-page (&optional lines move)
7717   "Show previous page of selected article.
7718 Argument LINES specifies lines to be scrolled down.
7719 If MOVE, move to the previous unread article if point is at
7720 the beginning of the buffer."
7721   (interactive "P")
7722   (let ((article (gnus-summary-article-number))
7723         (article-window (get-buffer-window gnus-article-buffer t))
7724         endp)
7725     (gnus-configure-windows 'article)
7726     (if (or (null gnus-current-article)
7727             (null gnus-article-current)
7728             (/= article (cdr gnus-article-current))
7729             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7730         ;; Selected subject is different from current article's.
7731         (gnus-summary-display-article article)
7732       (gnus-summary-recenter)
7733       (when article-window
7734         (gnus-eval-in-buffer-window gnus-article-buffer
7735           (setq endp (gnus-article-prev-page lines)))
7736         (when (and move endp)
7737           (cond (lines
7738                  (gnus-message 3 "Beginning of message"))
7739                 ((null lines)
7740                  (if (and (eq gnus-summary-goto-unread 'never)
7741                           (not (gnus-summary-first-article-p article)))
7742                      (gnus-summary-prev-article)
7743                    (gnus-summary-prev-unread-article))))))))
7744   (gnus-summary-position-point))
7745
7746 (defun gnus-summary-prev-page-or-article (&optional lines)
7747   "Show previous page of selected article.
7748 Argument LINES specifies lines to be scrolled down.
7749 If at the beginning of the article, go to the next article."
7750   (interactive "P")
7751   (gnus-summary-prev-page lines t))
7752
7753 (defun gnus-summary-scroll-up (lines)
7754   "Scroll up (or down) one line current article.
7755 Argument LINES specifies lines to be scrolled up (or down if negative)."
7756   (interactive "p")
7757   (gnus-configure-windows 'article)
7758   (gnus-summary-show-thread)
7759   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7760     (gnus-eval-in-buffer-window gnus-article-buffer
7761       (cond ((> lines 0)
7762              (when (gnus-article-next-page lines)
7763                (gnus-message 3 "End of message")))
7764             ((< lines 0)
7765              (gnus-article-prev-page (- lines))))))
7766   (gnus-summary-recenter)
7767   (gnus-summary-position-point))
7768
7769 (defun gnus-summary-scroll-down (lines)
7770   "Scroll down (or up) one line current article.
7771 Argument LINES specifies lines to be scrolled down (or up if negative)."
7772   (interactive "p")
7773   (gnus-summary-scroll-up (- lines)))
7774
7775 (defun gnus-summary-next-same-subject ()
7776   "Select next article which has the same subject as current one."
7777   (interactive)
7778   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7779
7780 (defun gnus-summary-prev-same-subject ()
7781   "Select previous article which has the same subject as current one."
7782   (interactive)
7783   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7784
7785 (defun gnus-summary-next-unread-same-subject ()
7786   "Select next unread article which has the same subject as current one."
7787   (interactive)
7788   (gnus-summary-next-article t (gnus-summary-article-subject)))
7789
7790 (defun gnus-summary-prev-unread-same-subject ()
7791   "Select previous unread article which has the same subject as current one."
7792   (interactive)
7793   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7794
7795 (defun gnus-summary-first-unread-article ()
7796   "Select the first unread article.
7797 Return nil if there are no unread articles."
7798   (interactive)
7799   (prog1
7800       (when (gnus-summary-first-subject t)
7801         (gnus-summary-show-thread)
7802         (gnus-summary-first-subject t)
7803         (gnus-summary-display-article (gnus-summary-article-number)))
7804     (gnus-summary-position-point)))
7805
7806 (defun gnus-summary-first-unread-subject ()
7807   "Place the point on the subject line of the first unread article.
7808 Return nil if there are no unread articles."
7809   (interactive)
7810   (prog1
7811       (when (gnus-summary-first-subject t)
7812         (gnus-summary-show-thread)
7813         (gnus-summary-first-subject t))
7814     (gnus-summary-position-point)))
7815
7816 (defun gnus-summary-first-unseen-subject ()
7817   "Place the point on the subject line of the first unseen article.
7818 Return nil if there are no unseen articles."
7819   (interactive)
7820   (prog1
7821       (when (gnus-summary-first-subject nil nil t)
7822         (gnus-summary-show-thread)
7823         (gnus-summary-first-subject nil nil t))
7824     (gnus-summary-position-point)))
7825
7826 (defun gnus-summary-first-unseen-or-unread-subject ()
7827   "Place the point on the subject line of the first unseen article or,
7828 if all article have been seen, on the subject line of the first unread
7829 article."
7830   (interactive)
7831   (prog1
7832       (unless (when (gnus-summary-first-subject nil nil t)
7833                 (gnus-summary-show-thread)
7834                 (gnus-summary-first-subject nil nil t))
7835         (when (gnus-summary-first-subject t)
7836           (gnus-summary-show-thread)
7837           (gnus-summary-first-subject t)))
7838     (gnus-summary-position-point)))
7839
7840 (defun gnus-summary-first-article ()
7841   "Select the first article.
7842 Return nil if there are no articles."
7843   (interactive)
7844   (prog1
7845       (when (gnus-summary-first-subject)
7846         (gnus-summary-show-thread)
7847         (gnus-summary-first-subject)
7848         (gnus-summary-display-article (gnus-summary-article-number)))
7849     (gnus-summary-position-point)))
7850
7851 (defun gnus-summary-best-unread-article (&optional arg)
7852   "Select the unread article with the highest score.
7853 If given a prefix argument, select the next unread article that has a
7854 score higher than the default score."
7855   (interactive "P")
7856   (let ((article (if arg
7857                      (gnus-summary-better-unread-subject)
7858                    (gnus-summary-best-unread-subject))))
7859     (if article
7860         (gnus-summary-goto-article article)
7861       (error "No unread articles"))))
7862
7863 (defun gnus-summary-best-unread-subject ()
7864   "Select the unread subject with the highest score."
7865   (interactive)
7866   (let ((best -1000000)
7867         (data gnus-newsgroup-data)
7868         article score)
7869     (while data
7870       (and (gnus-data-unread-p (car data))
7871            (> (setq score
7872                     (gnus-summary-article-score (gnus-data-number (car data))))
7873               best)
7874            (setq best score
7875                  article (gnus-data-number (car data))))
7876       (setq data (cdr data)))
7877     (when article
7878       (gnus-summary-goto-subject article))
7879     (gnus-summary-position-point)
7880     article))
7881
7882 (defun gnus-summary-better-unread-subject ()
7883   "Select the first unread subject that has a score over the default score."
7884   (interactive)
7885   (let ((data gnus-newsgroup-data)
7886         article score)
7887     (while (and (setq article (gnus-data-number (car data)))
7888                 (or (gnus-data-read-p (car data))
7889                     (not (> (gnus-summary-article-score article)
7890                             gnus-summary-default-score))))
7891       (setq data (cdr data)))
7892     (when article
7893       (gnus-summary-goto-subject article))
7894     (gnus-summary-position-point)
7895     article))
7896
7897 (defun gnus-summary-last-subject ()
7898   "Go to the last displayed subject line in the group."
7899   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7900     (when article
7901       (gnus-summary-goto-subject article))))
7902
7903 (defun gnus-summary-goto-article (article &optional all-headers force)
7904   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7905 If ALL-HEADERS is non-nil, no header lines are hidden.
7906 If FORCE, go to the article even if it isn't displayed.  If FORCE
7907 is a number, it is the line the article is to be displayed on."
7908   (interactive
7909    (list
7910     (completing-read
7911      "Article number or Message-ID: "
7912      (mapcar (lambda (number) (list (int-to-string number)))
7913              gnus-newsgroup-limit))
7914     current-prefix-arg
7915     t))
7916   (prog1
7917       (if (and (stringp article)
7918                (string-match "@\\|%40" article))
7919           (gnus-summary-refer-article article)
7920         (when (stringp article)
7921           (setq article (string-to-number article)))
7922         (if (gnus-summary-goto-subject article force)
7923             (gnus-summary-display-article article all-headers)
7924           (gnus-message 4 "Couldn't go to article %s" article) nil))
7925     (gnus-summary-position-point)))
7926
7927 (defun gnus-summary-goto-last-article ()
7928   "Go to the previously read article."
7929   (interactive)
7930   (prog1
7931       (when gnus-last-article
7932         (gnus-summary-goto-article gnus-last-article nil t))
7933     (gnus-summary-position-point)))
7934
7935 (defun gnus-summary-pop-article (number)
7936   "Pop one article off the history and go to the previous.
7937 NUMBER articles will be popped off."
7938   (interactive "p")
7939   (let (to)
7940     (setq gnus-newsgroup-history
7941           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7942     (if to
7943         (gnus-summary-goto-article (car to) nil t)
7944       (error "Article history empty")))
7945   (gnus-summary-position-point))
7946
7947 ;; Summary commands and functions for limiting the summary buffer.
7948
7949 (defun gnus-summary-limit-to-articles (n)
7950   "Limit the summary buffer to the next N articles.
7951 If not given a prefix, use the process marked articles instead."
7952   (interactive "P")
7953   (prog1
7954       (let ((articles (gnus-summary-work-articles n)))
7955         (setq gnus-newsgroup-processable nil)
7956         (gnus-summary-limit articles))
7957     (gnus-summary-position-point)))
7958
7959 (defun gnus-summary-pop-limit (&optional total)
7960   "Restore the previous limit.
7961 If given a prefix, remove all limits."
7962   (interactive "P")
7963   (when total
7964     (setq gnus-newsgroup-limits
7965           (list (mapcar (lambda (h) (mail-header-number h))
7966                         gnus-newsgroup-headers))))
7967   (unless gnus-newsgroup-limits
7968     (error "No limit to pop"))
7969   (prog1
7970       (gnus-summary-limit nil 'pop)
7971     (gnus-summary-position-point)))
7972
7973 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7974   "Limit the summary buffer to articles that have subjects that match a regexp.
7975 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7976   (interactive
7977    (list (read-string (if current-prefix-arg
7978                           "Exclude subject (regexp): "
7979                         "Limit to subject (regexp): "))
7980          nil current-prefix-arg))
7981   (unless header
7982     (setq header "subject"))
7983   (when (not (equal "" subject))
7984     (prog1
7985         (let ((articles (gnus-summary-find-matching
7986                          (or header "subject") subject 'all nil nil
7987                          not-matching)))
7988           (unless articles
7989             (error "Found no matches for \"%s\"" subject))
7990           (gnus-summary-limit articles))
7991       (gnus-summary-position-point))))
7992
7993 (defun gnus-summary-limit-to-author (from &optional not-matching)
7994   "Limit the summary buffer to articles that have authors that match a regexp.
7995 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7996   (interactive
7997    (list (read-string (if current-prefix-arg
7998                           "Exclude author (regexp): "
7999                         "Limit to author (regexp): "))
8000          current-prefix-arg))
8001   (gnus-summary-limit-to-subject from "from" not-matching))
8002
8003 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8004   "Limit the summary buffer to articles with the given RECIPIENT.
8005
8006 If NOT-MATCHING, exclude RECIPIENT.
8007
8008 To and Cc headers are checked.  You need to include them in
8009 `nnmail-extra-headers'."
8010   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8011   (interactive
8012    (list (read-string (format "%s recipient (regexp): "
8013                               (if current-prefix-arg "Exclude" "Limit to")))
8014          current-prefix-arg))
8015   (when (not (equal "" recipient))
8016     (prog1 (let* ((to
8017                    (if (memq 'To nnmail-extra-headers)
8018                        (gnus-summary-find-matching
8019                         (cons 'extra 'To) recipient 'all nil nil
8020                         not-matching)
8021                      (gnus-message
8022                       1 "`To' isn't present in `nnmail-extra-headers'")
8023                      (sit-for 1)
8024                      nil))
8025                   (cc
8026                    (if (memq 'Cc nnmail-extra-headers)
8027                        (gnus-summary-find-matching
8028                         (cons 'extra 'Cc) recipient 'all nil nil
8029                         not-matching)
8030                      (gnus-message
8031                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8032                      (sit-for 1)
8033                      nil))
8034                   (articles
8035                    (if not-matching
8036                        ;; We need the numbers that are in both lists:
8037                        (mapcar (lambda (a)
8038                                  (and (memq a to) a))
8039                                cc)
8040                      (nconc to cc))))
8041              (unless articles
8042                (error "Found no matches for \"%s\"" recipient))
8043              (gnus-summary-limit articles))
8044       (gnus-summary-position-point))))
8045
8046 (defun gnus-summary-limit-to-address (address &optional not-matching)
8047   "Limit the summary buffer to articles with the given ADDRESS.
8048
8049 If NOT-MATCHING, exclude ADDRESS.
8050
8051 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8052 in `nnmail-extra-headers'."
8053   (interactive
8054    (list (read-string (format "%s address (regexp): "
8055                               (if current-prefix-arg "Exclude" "Limit to")))
8056          current-prefix-arg))
8057   (when (not (equal "" address))
8058     (prog1 (let* ((to
8059                    (if (memq 'To nnmail-extra-headers)
8060                        (gnus-summary-find-matching
8061                         (cons 'extra 'To) address 'all nil nil
8062                         not-matching)
8063                      (gnus-message
8064                       1 "`To' isn't present in `nnmail-extra-headers'")
8065                      (sit-for 1)
8066                      t))
8067                   (cc
8068                    (if (memq 'Cc nnmail-extra-headers)
8069                        (gnus-summary-find-matching
8070                         (cons 'extra 'Cc) address 'all nil nil
8071                         not-matching)
8072                      (gnus-message
8073                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8074                      (sit-for 1)
8075                      t))
8076                   (from
8077                    (gnus-summary-find-matching "from" address
8078                                                'all nil nil not-matching))
8079                   (articles
8080                    (if not-matching
8081                        ;; We need the numbers that are in all lists:
8082                        (if (eq cc t)
8083                            (if (eq to t)
8084                                from
8085                              (mapcar (lambda (a) (car (memq a from))) to))
8086                          (if (eq to t)
8087                              (mapcar (lambda (a) (car (memq a from))) cc)
8088                            (mapcar (lambda (a) (car (memq a from)))
8089                                    (mapcar (lambda (a) (car (memq a to)))
8090                                            cc))))
8091                      (nconc (if (eq to t) nil to)
8092                             (if (eq cc t) nil cc)
8093                             from))))
8094              (unless articles
8095                (error "Found no matches for \"%s\"" address))
8096              (gnus-summary-limit articles))
8097       (gnus-summary-position-point))))
8098
8099 (defun gnus-summary-limit-strange-charsets-predicate (header)
8100   (let ((string (concat (mail-header-subject header)
8101                         (mail-header-from header)))
8102         charset found)
8103     (dotimes (i (1- (length string)))
8104       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8105       (when (string-match "unicode\\|big\\|japanese" charset)
8106         (setq found t)))
8107     found))
8108
8109 (defun gnus-summary-limit-to-predicate (predicate)
8110   "Limit to articles where PREDICATE returns non-nil.
8111 PREDICATE will be called with the header structures of the
8112 articles."
8113   (let ((articles nil)
8114         (case-fold-search t))
8115     (dolist (header gnus-newsgroup-headers)
8116       (when (funcall predicate header)
8117         (push (mail-header-number header) articles)))
8118     (gnus-summary-limit (nreverse articles))))
8119
8120 (defun gnus-summary-limit-to-age (age &optional younger-p)
8121   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8122 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8123 articles that are younger than AGE days."
8124   (interactive
8125    (let ((younger current-prefix-arg)
8126          (days-got nil)
8127          days)
8128      (while (not days-got)
8129        (setq days (if younger
8130                       (read-string "Limit to articles younger than (in days, older when negative): ")
8131                     (read-string
8132                      "Limit to articles older than (in days, younger when negative): ")))
8133        (when (> (length days) 0)
8134          (setq days (read days)))
8135        (if (numberp days)
8136            (progn
8137              (setq days-got t)
8138              (when (< days 0)
8139                (setq younger (not younger))
8140                (setq days (* days -1))))
8141          (message "Please enter a number.")
8142          (sleep-for 1)))
8143      (list days younger)))
8144   (prog1
8145       (let ((data gnus-newsgroup-data)
8146             (cutoff (days-to-time age))
8147             articles d date is-younger)
8148         (while (setq d (pop data))
8149           (when (and (vectorp (gnus-data-header d))
8150                      (setq date (mail-header-date (gnus-data-header d))))
8151             (setq is-younger (time-less-p
8152                               (time-since (condition-case ()
8153                                               (date-to-time date)
8154                                             (error '(0 0))))
8155                               cutoff))
8156             (when (if younger-p
8157                       is-younger
8158                     (not is-younger))
8159               (push (gnus-data-number d) articles))))
8160         (gnus-summary-limit (nreverse articles)))
8161     (gnus-summary-position-point)))
8162
8163 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8164   "Limit the summary buffer to articles that match an 'extra' header."
8165   (interactive
8166    (let ((header
8167           (intern
8168            (gnus-completing-read-with-default
8169             (symbol-name (car gnus-extra-headers))
8170             (if current-prefix-arg
8171                 "Exclude extra header"
8172               "Limit extra header")
8173             (mapcar (lambda (x)
8174                       (cons (symbol-name x) x))
8175                     gnus-extra-headers)
8176             nil
8177             t))))
8178      (list header
8179            (read-string (format "%s header %s (regexp): "
8180                                 (if current-prefix-arg "Exclude" "Limit to")
8181                                 header))
8182            current-prefix-arg)))
8183   (when (not (equal "" regexp))
8184     (prog1
8185         (let ((articles (gnus-summary-find-matching
8186                          (cons 'extra header) regexp 'all nil nil
8187                          not-matching)))
8188           (unless articles
8189             (error "Found no matches for \"%s\"" regexp))
8190           (gnus-summary-limit articles))
8191       (gnus-summary-position-point))))
8192
8193 (defun gnus-summary-limit-to-display-predicate ()
8194   "Limit the summary buffer to the predicated in the `display' group parameter."
8195   (interactive)
8196   (unless gnus-newsgroup-display
8197     (error "There is no `display' group parameter"))
8198   (let (articles)
8199     (dolist (number gnus-newsgroup-articles)
8200       (when (funcall gnus-newsgroup-display)
8201         (push number articles)))
8202     (gnus-summary-limit articles))
8203   (gnus-summary-position-point))
8204
8205 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8206 (make-obsolete
8207  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8208
8209 (defun gnus-summary-limit-to-unread (&optional all)
8210   "Limit the summary buffer to articles that are not marked as read.
8211 If ALL is non-nil, limit strictly to unread articles."
8212   (interactive "P")
8213   (if all
8214       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8215     (gnus-summary-limit-to-marks
8216      ;; Concat all the marks that say that an article is read and have
8217      ;; those removed.
8218      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8219            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8220            gnus-low-score-mark gnus-expirable-mark
8221            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8222            gnus-duplicate-mark gnus-souped-mark)
8223      'reverse)))
8224
8225 (defun gnus-summary-limit-to-headers (match &optional reverse)
8226   "Limit the summary buffer to articles that have headers that match MATCH.
8227 If REVERSE (the prefix), limit to articles that don't match."
8228   (interactive "sMatch headers (regexp): \nP")
8229   (gnus-summary-limit-to-bodies match reverse t))
8230
8231 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8232   "Limit the summary buffer to articles that have bodies that match MATCH.
8233 If REVERSE (the prefix), limit to articles that don't match."
8234   (interactive "sMatch body (regexp): \nP")
8235   (let ((articles nil)
8236         (gnus-select-article-hook nil)  ;Disable hook.
8237         (gnus-article-prepare-hook nil)
8238         (gnus-use-article-prefetch nil)
8239         (gnus-keep-backlog nil)
8240         (gnus-break-pages nil)
8241         (gnus-summary-display-arrow nil)
8242         (gnus-updated-mode-lines nil)
8243         (gnus-auto-center-summary nil)
8244         (gnus-display-mime-function nil))
8245     (dolist (data gnus-newsgroup-data)
8246       (let (gnus-mark-article-hook)
8247         (gnus-summary-select-article t t nil (gnus-data-number data)))
8248       (save-excursion
8249         (set-buffer gnus-article-buffer)
8250         (article-goto-body)
8251         (let* ((case-fold-search t)
8252                (found (if headersp
8253                           (re-search-backward match nil t)
8254                         (re-search-forward match nil t))))
8255           (when (or (and found
8256                          (not reverse))
8257                     (and (not found)
8258                          reverse))
8259             (push (gnus-data-number data) articles)))))
8260     (if (not articles)
8261         (message "No messages matched")
8262       (gnus-summary-limit articles)))
8263   (gnus-summary-position-point))
8264
8265 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8266   "Limit the summary buffer to articles that aren't part on any thread.
8267 If THREADSP (the prefix), limit to articles that are in threads."
8268   (interactive "P")
8269   (let ((articles nil)
8270         thread-articles
8271         threads)
8272     (dolist (thread gnus-newsgroup-threads)
8273       (if (stringp (car thread))
8274           (dolist (thread (cdr thread))
8275             (push thread threads))
8276         (push thread threads)))
8277     (dolist (thread threads)
8278       (setq thread-articles (gnus-articles-in-thread thread))
8279       (when (or (and threadsp
8280                      (> (length thread-articles) 1))
8281                 (and (not threadsp)
8282                      (= (length thread-articles) 1)))
8283         (setq articles (nconc thread-articles articles))))
8284     (if (not articles)
8285         (message "No messages matched")
8286       (gnus-summary-limit articles))
8287     (gnus-summary-position-point)))
8288
8289 (defun gnus-summary-limit-to-replied (&optional unreplied)
8290   "Limit the summary buffer to replied articles.
8291 If UNREPLIED (the prefix), limit to unreplied articles."
8292   (interactive "P")
8293   (if unreplied
8294       (gnus-summary-limit
8295        (gnus-set-difference gnus-newsgroup-articles
8296         gnus-newsgroup-replied))
8297     (gnus-summary-limit gnus-newsgroup-replied))
8298   (gnus-summary-position-point))
8299
8300 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8301 (make-obsolete 'gnus-summary-delete-marked-with
8302                'gnus-summary-limit-exclude-marks)
8303
8304 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8305   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8306 If REVERSE, limit the summary buffer to articles that are marked
8307 with MARKS.  MARKS can either be a string of marks or a list of marks.
8308 Returns how many articles were removed."
8309   (interactive "sMarks: ")
8310   (gnus-summary-limit-to-marks marks t))
8311
8312 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8313   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8314 If REVERSE (the prefix), limit the summary buffer to articles that are
8315 not marked with MARKS.  MARKS can either be a string of marks or a
8316 list of marks.
8317 Returns how many articles were removed."
8318   (interactive "sMarks: \nP")
8319   (prog1
8320       (let ((data gnus-newsgroup-data)
8321             (marks (if (listp marks) marks
8322                      (append marks nil))) ; Transform to list.
8323             articles)
8324         (while data
8325           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8326                   (memq (gnus-data-mark (car data)) marks))
8327             (push (gnus-data-number (car data)) articles))
8328           (setq data (cdr data)))
8329         (gnus-summary-limit articles))
8330     (gnus-summary-position-point)))
8331
8332 (defun gnus-summary-limit-to-score (score)
8333   "Limit to articles with score at or above SCORE."
8334   (interactive "NLimit to articles with score of at least: ")
8335   (let ((data gnus-newsgroup-data)
8336         articles)
8337     (while data
8338       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8339                 score)
8340         (push (gnus-data-number (car data)) articles))
8341       (setq data (cdr data)))
8342     (prog1
8343         (gnus-summary-limit articles)
8344       (gnus-summary-position-point))))
8345
8346 (defun gnus-summary-limit-to-unseen ()
8347   "Limit to unseen articles."
8348   (interactive)
8349   (prog1
8350       (gnus-summary-limit gnus-newsgroup-unseen)
8351     (gnus-summary-position-point)))
8352
8353 (defun gnus-summary-limit-include-thread (id)
8354   "Display all the hidden articles that is in the thread with ID in it.
8355 When called interactively, ID is the Message-ID of the current
8356 article."
8357   (interactive (list (mail-header-id (gnus-summary-article-header))))
8358   (let ((articles (gnus-articles-in-thread
8359                    (gnus-id-to-thread (gnus-root-id id)))))
8360     (prog1
8361         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8362       (gnus-summary-limit-include-matching-articles
8363        "subject"
8364        (regexp-quote (gnus-simplify-subject-re
8365                       (mail-header-subject (gnus-id-to-header id)))))
8366       (gnus-summary-position-point))))
8367
8368 (defun gnus-summary-limit-include-matching-articles (header regexp)
8369   "Display all the hidden articles that have HEADERs that match REGEXP."
8370   (interactive (list (read-string "Match on header: ")
8371                      (read-string "Regexp: ")))
8372   (let ((articles (gnus-find-matching-articles header regexp)))
8373     (prog1
8374         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8375       (gnus-summary-position-point))))
8376
8377 (defun gnus-summary-insert-dormant-articles ()
8378   "Insert all the dormant articles for this group into the current buffer."
8379   (interactive)
8380   (let ((gnus-verbose (max 6 gnus-verbose)))
8381     (if (not gnus-newsgroup-dormant)
8382         (gnus-message 3 "No dormant articles for this group")
8383       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8384
8385 (defun gnus-summary-insert-ticked-articles ()
8386   "Insert ticked articles for this group into the current buffer."
8387   (interactive)
8388   (let ((gnus-verbose (max 6 gnus-verbose)))
8389     (if (not gnus-newsgroup-marked)
8390         (gnus-message 3 "No ticked articles for this group")
8391       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8392
8393 (defun gnus-summary-limit-include-dormant ()
8394   "Display all the hidden articles that are marked as dormant.
8395 Note that this command only works on a subset of the articles currently
8396 fetched for this group."
8397   (interactive)
8398   (unless gnus-newsgroup-dormant
8399     (error "There are no dormant articles in this group"))
8400   (prog1
8401       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8402     (gnus-summary-position-point)))
8403
8404 (defun gnus-summary-limit-exclude-dormant ()
8405   "Hide all dormant articles."
8406   (interactive)
8407   (prog1
8408       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8409     (gnus-summary-position-point)))
8410
8411 (defun gnus-summary-limit-exclude-childless-dormant ()
8412   "Hide all dormant articles that have no children."
8413   (interactive)
8414   (let ((data (gnus-data-list t))
8415         articles d children)
8416     ;; Find all articles that are either not dormant or have
8417     ;; children.
8418     (while (setq d (pop data))
8419       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8420                 (and (setq children
8421                            (gnus-article-children (gnus-data-number d)))
8422                      (let (found)
8423                        (while children
8424                          (when (memq (car children) articles)
8425                            (setq children nil
8426                                  found t))
8427                          (pop children))
8428                        found)))
8429         (push (gnus-data-number d) articles)))
8430     ;; Do the limiting.
8431     (prog1
8432         (gnus-summary-limit articles)
8433       (gnus-summary-position-point))))
8434
8435 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8436   "Mark all unread excluded articles as read.
8437 If ALL, mark even excluded ticked and dormants as read."
8438   (interactive "P")
8439   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8440   (let ((articles (gnus-sorted-ndifference
8441                    (sort
8442                     (mapcar (lambda (h) (mail-header-number h))
8443                             gnus-newsgroup-headers)
8444                     '<)
8445                    gnus-newsgroup-limit))
8446         article)
8447     (setq gnus-newsgroup-unreads
8448           (gnus-sorted-intersection gnus-newsgroup-unreads
8449                                     gnus-newsgroup-limit))
8450     (if all
8451         (setq gnus-newsgroup-dormant nil
8452               gnus-newsgroup-marked nil
8453               gnus-newsgroup-reads
8454               (nconc
8455                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8456                gnus-newsgroup-reads))
8457       (while (setq article (pop articles))
8458         (unless (or (memq article gnus-newsgroup-dormant)
8459                     (memq article gnus-newsgroup-marked))
8460           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8461
8462 (defun gnus-summary-limit (articles &optional pop)
8463   (if pop
8464       ;; We pop the previous limit off the stack and use that.
8465       (setq articles (car gnus-newsgroup-limits)
8466             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8467     ;; We use the new limit, so we push the old limit on the stack.
8468     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8469   ;; Set the limit.
8470   (setq gnus-newsgroup-limit articles)
8471   (let ((total (length gnus-newsgroup-data))
8472         (data (gnus-data-find-list (gnus-summary-article-number)))
8473         (gnus-summary-mark-below nil)   ; Inhibit this.
8474         found)
8475     ;; This will do all the work of generating the new summary buffer
8476     ;; according to the new limit.
8477     (gnus-summary-prepare)
8478     ;; Hide any threads, possibly.
8479     (gnus-summary-maybe-hide-threads)
8480     ;; Try to return to the article you were at, or one in the
8481     ;; neighborhood.
8482     (when data
8483       ;; We try to find some article after the current one.
8484       (while data
8485         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8486           (setq data nil
8487                 found t))
8488         (setq data (cdr data))))
8489     (unless found
8490       ;; If there is no data, that means that we were after the last
8491       ;; article.  The same goes when we can't find any articles
8492       ;; after the current one.
8493       (goto-char (point-max))
8494       (gnus-summary-find-prev))
8495     (gnus-set-mode-line 'summary)
8496     ;; We return how many articles were removed from the summary
8497     ;; buffer as a result of the new limit.
8498     (- total (length gnus-newsgroup-data))))
8499
8500 (defsubst gnus-invisible-cut-children (threads)
8501   (let ((num 0))
8502     (while threads
8503       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8504         (incf num))
8505       (pop threads))
8506     (< num 2)))
8507
8508 (defsubst gnus-cut-thread (thread)
8509   "Go forwards in the thread until we find an article that we want to display."
8510   (when (or (eq gnus-fetch-old-headers 'some)
8511             (eq gnus-fetch-old-headers 'invisible)
8512             (numberp gnus-fetch-old-headers)
8513             (eq gnus-build-sparse-threads 'some)
8514             (eq gnus-build-sparse-threads 'more))
8515     ;; Deal with old-fetched headers and sparse threads.
8516     (while (and
8517             thread
8518             (or
8519              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8520              (gnus-summary-article-ancient-p
8521               (mail-header-number (car thread))))
8522             (if (or (<= (length (cdr thread)) 1)
8523                     (eq gnus-fetch-old-headers 'invisible))
8524                 (setq gnus-newsgroup-limit
8525                       (delq (mail-header-number (car thread))
8526                             gnus-newsgroup-limit)
8527                       thread (cadr thread))
8528               (when (gnus-invisible-cut-children (cdr thread))
8529                 (let ((th (cdr thread)))
8530                   (while th
8531                     (if (memq (mail-header-number (caar th))
8532                               gnus-newsgroup-limit)
8533                         (setq thread (car th)
8534                               th nil)
8535                       (setq th (cdr th))))))))))
8536   thread)
8537
8538 (defun gnus-cut-threads (threads)
8539   "Cut off all uninteresting articles from the beginning of THREADS."
8540   (when (or (eq gnus-fetch-old-headers 'some)
8541             (eq gnus-fetch-old-headers 'invisible)
8542             (numberp gnus-fetch-old-headers)
8543             (eq gnus-build-sparse-threads 'some)
8544             (eq gnus-build-sparse-threads 'more))
8545     (let ((th threads))
8546       (while th
8547         (setcar th (gnus-cut-thread (car th)))
8548         (setq th (cdr th)))))
8549   ;; Remove nixed out threads.
8550   (delq nil threads))
8551
8552 (defun gnus-summary-initial-limit (&optional show-if-empty)
8553   "Figure out what the initial limit is supposed to be on group entry.
8554 This entails weeding out unwanted dormants, low-scored articles,
8555 fetch-old-headers verbiage, and so on."
8556   ;; Most groups have nothing to remove.
8557   (if (or gnus-inhibit-limiting
8558           (and (null gnus-newsgroup-dormant)
8559                (eq gnus-newsgroup-display 'gnus-not-ignore)
8560                (not (eq gnus-fetch-old-headers 'some))
8561                (not (numberp gnus-fetch-old-headers))
8562                (not (eq gnus-fetch-old-headers 'invisible))
8563                (null gnus-summary-expunge-below)
8564                (not (eq gnus-build-sparse-threads 'some))
8565                (not (eq gnus-build-sparse-threads 'more))
8566                (null gnus-thread-expunge-below)
8567                (not gnus-use-nocem)))
8568       ()                                ; Do nothing.
8569     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8570     (setq gnus-newsgroup-limit nil)
8571     (mapatoms
8572      (lambda (node)
8573        (unless (car (symbol-value node))
8574          ;; These threads have no parents -- they are roots.
8575          (let ((nodes (cdr (symbol-value node)))
8576                thread)
8577            (while nodes
8578              (if (and gnus-thread-expunge-below
8579                       (< (gnus-thread-total-score (car nodes))
8580                          gnus-thread-expunge-below))
8581                  (gnus-expunge-thread (pop nodes))
8582                (setq thread (pop nodes))
8583                (gnus-summary-limit-children thread))))))
8584      gnus-newsgroup-dependencies)
8585     ;; If this limitation resulted in an empty group, we might
8586     ;; pop the previous limit and use it instead.
8587     (when (and (not gnus-newsgroup-limit)
8588                show-if-empty)
8589       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8590     gnus-newsgroup-limit))
8591
8592 (defun gnus-summary-limit-children (thread)
8593   "Return 1 if this subthread is visible and 0 if it is not."
8594   ;; First we get the number of visible children to this thread.  This
8595   ;; is done by recursing down the thread using this function, so this
8596   ;; will really go down to a leaf article first, before slowly
8597   ;; working its way up towards the root.
8598   (when thread
8599     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8600            (children
8601            (if (cdr thread)
8602                (apply '+ (mapcar 'gnus-summary-limit-children
8603                                  (cdr thread)))
8604              0))
8605           (number (mail-header-number (car thread)))
8606           score)
8607       (if (and
8608            (not (memq number gnus-newsgroup-marked))
8609            (or
8610             ;; If this article is dormant and has absolutely no visible
8611             ;; children, then this article isn't visible.
8612             (and (memq number gnus-newsgroup-dormant)
8613                  (zerop children))
8614             ;; If this is "fetch-old-headered" and there is no
8615             ;; visible children, then we don't want this article.
8616             (and (or (eq gnus-fetch-old-headers 'some)
8617                      (numberp gnus-fetch-old-headers))
8618                  (gnus-summary-article-ancient-p number)
8619                  (zerop children))
8620             ;; If this is "fetch-old-headered" and `invisible', then
8621             ;; we don't want this article.
8622             (and (eq gnus-fetch-old-headers 'invisible)
8623                  (gnus-summary-article-ancient-p number))
8624             ;; If this is a sparsely inserted article with no children,
8625             ;; we don't want it.
8626             (and (eq gnus-build-sparse-threads 'some)
8627                  (gnus-summary-article-sparse-p number)
8628                  (zerop children))
8629             ;; If we use expunging, and this article is really
8630             ;; low-scored, then we don't want this article.
8631             (when (and gnus-summary-expunge-below
8632                        (< (setq score
8633                                 (or (cdr (assq number gnus-newsgroup-scored))
8634                                     gnus-summary-default-score))
8635                           gnus-summary-expunge-below))
8636               ;; We increase the expunge-tally here, but that has
8637               ;; nothing to do with the limits, really.
8638               (incf gnus-newsgroup-expunged-tally)
8639               ;; We also mark as read here, if that's wanted.
8640               (when (and gnus-summary-mark-below
8641                          (< score gnus-summary-mark-below))
8642                 (setq gnus-newsgroup-unreads
8643                       (delq number gnus-newsgroup-unreads))
8644                 (if gnus-newsgroup-auto-expire
8645                     (push number gnus-newsgroup-expirable)
8646                   (push (cons number gnus-low-score-mark)
8647                         gnus-newsgroup-reads)))
8648               t)
8649             ;; Do the `display' group parameter.
8650             (and gnus-newsgroup-display
8651                  (not (funcall gnus-newsgroup-display)))
8652             ;; Check NoCeM things.
8653             (when (and gnus-use-nocem
8654                        (gnus-nocem-unwanted-article-p
8655                         (mail-header-id (car thread))))
8656               (setq gnus-newsgroup-unreads
8657                     (delq number gnus-newsgroup-unreads))
8658               t)))
8659           ;; Nope, invisible article.
8660           0
8661         ;; Ok, this article is to be visible, so we add it to the limit
8662         ;; and return 1.
8663         (push number gnus-newsgroup-limit)
8664         1))))
8665
8666 (defun gnus-expunge-thread (thread)
8667   "Mark all articles in THREAD as read."
8668   (let* ((number (mail-header-number (car thread))))
8669     (incf gnus-newsgroup-expunged-tally)
8670     ;; We also mark as read here, if that's wanted.
8671     (setq gnus-newsgroup-unreads
8672           (delq number gnus-newsgroup-unreads))
8673     (if gnus-newsgroup-auto-expire
8674         (push number gnus-newsgroup-expirable)
8675       (push (cons number gnus-low-score-mark)
8676             gnus-newsgroup-reads)))
8677   ;; Go recursively through all subthreads.
8678   (mapcar 'gnus-expunge-thread (cdr thread)))
8679
8680 ;; Summary article oriented commands
8681
8682 (defun gnus-summary-refer-parent-article (n)
8683   "Refer parent article N times.
8684 If N is negative, go to ancestor -N instead.
8685 The difference between N and the number of articles fetched is returned."
8686   (interactive "p")
8687   (let ((skip 1)
8688         error header ref)
8689     (when (not (natnump n))
8690       (setq skip (abs n)
8691             n 1))
8692     (while (and (> n 0)
8693                 (not error))
8694       (setq header (gnus-summary-article-header))
8695       (if (and (eq (mail-header-number header)
8696                    (cdr gnus-article-current))
8697                (equal gnus-newsgroup-name
8698                       (car gnus-article-current)))
8699           ;; If we try to find the parent of the currently
8700           ;; displayed article, then we take a look at the actual
8701           ;; References header, since this is slightly more
8702           ;; reliable than the References field we got from the
8703           ;; server.
8704           (save-excursion
8705             (set-buffer gnus-original-article-buffer)
8706             (nnheader-narrow-to-headers)
8707             (unless (setq ref (message-fetch-field "references"))
8708               (when (setq ref (message-fetch-field "in-reply-to"))
8709                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8710             (widen))
8711         (setq ref
8712               ;; It's not the current article, so we take a bet on
8713               ;; the value we got from the server.
8714               (mail-header-references header)))
8715       (if (and ref
8716                (not (equal ref "")))
8717           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8718             (gnus-message 1 "Couldn't find parent"))
8719         (gnus-message 1 "No references in article %d"
8720                       (gnus-summary-article-number))
8721         (setq error t))
8722       (decf n))
8723     (gnus-summary-position-point)
8724     n))
8725
8726 (defun gnus-summary-refer-references ()
8727   "Fetch all articles mentioned in the References header.
8728 Return the number of articles fetched."
8729   (interactive)
8730   (let ((ref (mail-header-references (gnus-summary-article-header)))
8731         (current (gnus-summary-article-number))
8732         (n 0))
8733     (if (or (not ref)
8734             (equal ref ""))
8735         (error "No References in the current article")
8736       ;; For each Message-ID in the References header...
8737       (while (string-match "<[^>]*>" ref)
8738         (incf n)
8739         ;; ... fetch that article.
8740         (gnus-summary-refer-article
8741          (prog1 (match-string 0 ref)
8742            (setq ref (substring ref (match-end 0))))))
8743       (gnus-summary-goto-subject current)
8744       (gnus-summary-position-point)
8745       n)))
8746
8747 (defun gnus-summary-refer-thread (&optional limit)
8748   "Fetch all articles in the current thread.
8749 If LIMIT (the numerical prefix), fetch that many old headers instead
8750 of what's specified by the `gnus-refer-thread-limit' variable."
8751   (interactive "P")
8752   (let ((id (mail-header-id (gnus-summary-article-header)))
8753         (limit (if limit (prefix-numeric-value limit)
8754                  gnus-refer-thread-limit)))
8755     (unless (eq gnus-fetch-old-headers 'invisible)
8756       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8757       ;; Retrieve the headers and read them in.
8758       (if (eq (if (numberp limit)
8759                   (gnus-retrieve-headers
8760                    (list (min
8761                           (+ (mail-header-number
8762                               (gnus-summary-article-header))
8763                              limit)
8764                           gnus-newsgroup-end))
8765                    gnus-newsgroup-name (* limit 2))
8766                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8767                 ;; headers.
8768                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8769                                        gnus-newsgroup-name limit))
8770               'nov)
8771           (gnus-build-all-threads)
8772         (error "Can't fetch thread from back ends that don't support NOV"))
8773       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8774     (gnus-summary-limit-include-thread id)))
8775
8776 (defun gnus-summary-refer-article (message-id)
8777   "Fetch an article specified by MESSAGE-ID."
8778   (interactive "sMessage-ID: ")
8779   (when (and (stringp message-id)
8780              (not (zerop (length message-id))))
8781     (setq message-id (gnus-replace-in-string message-id " " ""))
8782     ;; Construct the correct Message-ID if necessary.
8783     ;; Suggested by tale@pawl.rpi.edu.
8784     (unless (string-match "^<" message-id)
8785       (setq message-id (concat "<" message-id)))
8786     (unless (string-match ">$" message-id)
8787       (setq message-id (concat message-id ">")))
8788     ;; People often post MIDs from URLs, so unhex it:
8789     (unless (string-match "@" message-id)
8790       (setq message-id (gnus-url-unhex-string message-id)))
8791     (let* ((header (gnus-id-to-header message-id))
8792            (sparse (and header
8793                         (gnus-summary-article-sparse-p
8794                          (mail-header-number header))
8795                         (memq (mail-header-number header)
8796                               gnus-newsgroup-limit)))
8797            number)
8798       (cond
8799        ;; If the article is present in the buffer we just go to it.
8800        ((and header
8801              (or (not (gnus-summary-article-sparse-p
8802                        (mail-header-number header)))
8803                  sparse))
8804         (prog1
8805             (gnus-summary-goto-article
8806              (mail-header-number header) nil t)
8807           (when sparse
8808             (gnus-summary-update-article (mail-header-number header)))))
8809        (t
8810         ;; We fetch the article.
8811         (catch 'found
8812           (dolist (gnus-override-method (gnus-refer-article-methods))
8813             (when (and (gnus-check-server gnus-override-method)
8814                        ;; Fetch the header,
8815                        (setq number (gnus-summary-insert-subject message-id)))
8816               ;; and display the article.
8817               (gnus-summary-select-article nil nil nil number)
8818               (throw 'found t)))
8819           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8820
8821 (defun gnus-refer-article-methods ()
8822   "Return a list of referable methods."
8823   (cond
8824    ;; No method, so we default to current and native.
8825    ((null gnus-refer-article-method)
8826     (list gnus-current-select-method gnus-select-method))
8827    ;; Current.
8828    ((eq 'current gnus-refer-article-method)
8829     (list gnus-current-select-method))
8830    ;; List of select methods.
8831    ((not (and (symbolp (car gnus-refer-article-method))
8832               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8833     (let (out)
8834       (dolist (method gnus-refer-article-method)
8835         (push (if (eq 'current method)
8836                   gnus-current-select-method
8837                 method)
8838               out))
8839       (nreverse out)))
8840    ;; One single select method.
8841    (t
8842     (list gnus-refer-article-method))))
8843
8844 (defun gnus-summary-edit-parameters ()
8845   "Edit the group parameters of the current group."
8846   (interactive)
8847   (gnus-group-edit-group gnus-newsgroup-name 'params))
8848
8849 (defun gnus-summary-customize-parameters ()
8850   "Customize the group parameters of the current group."
8851   (interactive)
8852   (gnus-group-customize gnus-newsgroup-name))
8853
8854 (defun gnus-summary-enter-digest-group (&optional force)
8855   "Enter an nndoc group based on the current article.
8856 If FORCE, force a digest interpretation.  If not, try
8857 to guess what the document format is."
8858   (interactive "P")
8859   (let ((conf gnus-current-window-configuration))
8860     (save-window-excursion
8861       (save-excursion
8862         (let (gnus-article-prepare-hook
8863               gnus-display-mime-function
8864               gnus-break-pages)
8865           (gnus-summary-select-article))))
8866     (setq gnus-current-window-configuration conf)
8867     (let* ((name (format "%s-%d"
8868                          (gnus-group-prefixed-name
8869                           gnus-newsgroup-name (list 'nndoc ""))
8870                          (with-current-buffer gnus-summary-buffer
8871                            gnus-current-article)))
8872            (ogroup gnus-newsgroup-name)
8873            (params (append (gnus-info-params (gnus-get-info ogroup))
8874                            (list (cons 'to-group ogroup))
8875                            (list (cons 'parent-group ogroup))
8876                            (list (cons 'save-article-group ogroup))))
8877            (case-fold-search t)
8878            (buf (current-buffer))
8879            dig to-address)
8880       (save-excursion
8881         (set-buffer gnus-original-article-buffer)
8882         ;; Have the digest group inherit the main mail address of
8883         ;; the parent article.
8884         (when (setq to-address (or (gnus-fetch-field "reply-to")
8885                                    (gnus-fetch-field "from")))
8886           (setq params
8887                 (append
8888                  (list (cons 'to-address
8889                              (funcall gnus-decode-encoded-address-function
8890                                       to-address))))))
8891         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8892         (insert-buffer-substring gnus-original-article-buffer)
8893         ;; Remove lines that may lead nndoc to misinterpret the
8894         ;; document type.
8895         (narrow-to-region
8896          (goto-char (point-min))
8897          (or (search-forward "\n\n" nil t) (point)))
8898         (goto-char (point-min))
8899         (delete-matching-lines "^Path:\\|^From ")
8900         (widen))
8901       (unwind-protect
8902           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8903                     (gnus-newsgroup-ephemeral-ignored-charsets
8904                      gnus-newsgroup-ignored-charsets))
8905                 (gnus-group-read-ephemeral-group
8906                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8907                               (nndoc-article-type
8908                                ,(if force 'mbox 'guess)))
8909                  t nil nil nil
8910                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8911                                                         "ADAPT")))))
8912               ;; Make all postings to this group go to the parent group.
8913               (nconc (gnus-info-params (gnus-get-info name))
8914                      params)
8915             ;; Couldn't select this doc group.
8916             (switch-to-buffer buf)
8917             (gnus-set-global-variables)
8918             (gnus-configure-windows 'summary)
8919             (gnus-message 3 "Article couldn't be entered?"))
8920         (kill-buffer dig)))))
8921
8922 (defun gnus-summary-read-document (n)
8923   "Open a new group based on the current article(s).
8924 This will allow you to read digests and other similar
8925 documents as newsgroups.
8926 Obeys the standard process/prefix convention."
8927   (interactive "P")
8928   (let* ((ogroup gnus-newsgroup-name)
8929          (params (append (gnus-info-params (gnus-get-info ogroup))
8930                          (list (cons 'to-group ogroup))))
8931          group egroup groups vgroup)
8932     (dolist (article (gnus-summary-work-articles n))
8933       (setq group (format "%s-%d" gnus-newsgroup-name article))
8934       (gnus-summary-remove-process-mark article)
8935       (when (gnus-summary-display-article article)
8936         (save-excursion
8937           (with-temp-buffer
8938             (insert-buffer-substring gnus-original-article-buffer)
8939             ;; Remove some headers that may lead nndoc to make
8940             ;; the wrong guess.
8941             (message-narrow-to-head)
8942             (goto-char (point-min))
8943             (delete-matching-lines "^Path:\\|^From ")
8944             (widen)
8945             (if (setq egroup
8946                       (gnus-group-read-ephemeral-group
8947                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8948                                      (nndoc-article-type guess))
8949                        t nil t))
8950                 (progn
8951             ;; Make all postings to this group go to the parent group.
8952                   (nconc (gnus-info-params (gnus-get-info egroup))
8953                          params)
8954                   (push egroup groups))
8955               ;; Couldn't select this doc group.
8956               (gnus-error 3 "Article couldn't be entered"))))))
8957     ;; Now we have selected all the documents.
8958     (cond
8959      ((not groups)
8960       (error "None of the articles could be interpreted as documents"))
8961      ((gnus-group-read-ephemeral-group
8962        (setq vgroup (format
8963                      "nnvirtual:%s-%s" gnus-newsgroup-name
8964                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8965        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8966        t
8967        (cons (current-buffer) 'summary)))
8968      (t
8969       (error "Couldn't select virtual nndoc group")))))
8970
8971 (defun gnus-summary-isearch-article (&optional regexp-p)
8972   "Do incremental search forward on the current article.
8973 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8974   (interactive "P")
8975   (gnus-summary-select-article)
8976   (gnus-configure-windows 'article)
8977   (gnus-eval-in-buffer-window gnus-article-buffer
8978     (save-restriction
8979       (widen)
8980       (isearch-forward regexp-p))))
8981
8982 (defun gnus-summary-repeat-search-article-forward ()
8983   "Repeat the previous search forwards."
8984   (interactive)
8985   (unless gnus-last-search-regexp
8986     (error "No previous search"))
8987   (gnus-summary-search-article-forward gnus-last-search-regexp))
8988
8989 (defun gnus-summary-repeat-search-article-backward ()
8990   "Repeat the previous search backwards."
8991   (interactive)
8992   (unless gnus-last-search-regexp
8993     (error "No previous search"))
8994   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8995
8996 (defun gnus-summary-search-article-forward (regexp &optional backward)
8997   "Search for an article containing REGEXP forward.
8998 If BACKWARD, search backward instead."
8999   (interactive
9000    (list (read-string
9001           (format "Search article %s (regexp%s): "
9002                   (if current-prefix-arg "backward" "forward")
9003                   (if gnus-last-search-regexp
9004                       (concat ", default " gnus-last-search-regexp)
9005                     "")))
9006          current-prefix-arg))
9007   (if (string-equal regexp "")
9008       (setq regexp (or gnus-last-search-regexp ""))
9009     (setq gnus-last-search-regexp regexp)
9010     (setq gnus-article-before-search gnus-current-article))
9011   ;; Intentionally set gnus-last-article.
9012   (setq gnus-last-article gnus-article-before-search)
9013   (let ((gnus-last-article gnus-last-article))
9014     (if (gnus-summary-search-article regexp backward)
9015         (gnus-summary-show-thread)
9016       (signal 'search-failed (list regexp)))))
9017
9018 (defun gnus-summary-search-article-backward (regexp)
9019   "Search for an article containing REGEXP backward."
9020   (interactive
9021    (list (read-string
9022           (format "Search article backward (regexp%s): "
9023                   (if gnus-last-search-regexp
9024                       (concat ", default " gnus-last-search-regexp)
9025                     "")))))
9026   (gnus-summary-search-article-forward regexp 'backward))
9027
9028 (defun gnus-summary-search-article (regexp &optional backward)
9029   "Search for an article containing REGEXP.
9030 Optional argument BACKWARD means do search for backward.
9031 `gnus-select-article-hook' is not called during the search."
9032   ;; We have to require this here to make sure that the following
9033   ;; dynamic binding isn't shadowed by autoloading.
9034   (require 'gnus-async)
9035   (require 'gnus-art)
9036   (let ((gnus-select-article-hook nil)  ;Disable hook.
9037         (gnus-article-prepare-hook nil)
9038         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9039         (gnus-use-article-prefetch nil)
9040         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9041         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9042         (gnus-visual nil)
9043         (gnus-keep-backlog nil)
9044         (gnus-break-pages nil)
9045         (gnus-summary-display-arrow nil)
9046         (gnus-updated-mode-lines nil)
9047         (gnus-auto-center-summary nil)
9048         (sum (current-buffer))
9049         (gnus-display-mime-function nil)
9050         (found nil)
9051         point)
9052     (gnus-save-hidden-threads
9053       (gnus-summary-select-article)
9054       (set-buffer gnus-article-buffer)
9055       (goto-char (window-point (get-buffer-window (current-buffer))))
9056       (when backward
9057         (forward-line -1))
9058       (while (not found)
9059         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9060         (if (if backward
9061                 (re-search-backward regexp nil t)
9062               (re-search-forward regexp nil t))
9063             ;; We found the regexp.
9064             (progn
9065               (setq found 'found)
9066               (beginning-of-line)
9067               (set-window-start
9068                (get-buffer-window (current-buffer))
9069                (point))
9070               (forward-line 1)
9071               (set-window-point
9072                (get-buffer-window (current-buffer))
9073                (point))
9074               (set-buffer sum)
9075               (setq point (point)))
9076           ;; We didn't find it, so we go to the next article.
9077           (set-buffer sum)
9078           (setq found 'not)
9079           (while (eq found 'not)
9080             (if (not (if backward (gnus-summary-find-prev)
9081                        (gnus-summary-find-next)))
9082                 ;; No more articles.
9083                 (setq found t)
9084               ;; Select the next article and adjust point.
9085               (unless (gnus-summary-article-sparse-p
9086                        (gnus-summary-article-number))
9087                 (setq found nil)
9088                 (gnus-summary-select-article)
9089                 (set-buffer gnus-article-buffer)
9090                 (widen)
9091                 (goto-char (if backward (point-max) (point-min))))))))
9092       (gnus-message 7 ""))
9093     ;; Return whether we found the regexp.
9094     (when (eq found 'found)
9095       (goto-char point)
9096       (gnus-summary-show-thread)
9097       (gnus-summary-goto-subject gnus-current-article)
9098       (gnus-summary-position-point)
9099       t)))
9100
9101 (defun gnus-find-matching-articles (header regexp)
9102   "Return a list of all articles that match REGEXP on HEADER.
9103 This search includes all articles in the current group that Gnus has
9104 fetched headers for, whether they are displayed or not."
9105   (let ((articles nil)
9106         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9107         (case-fold-search t))
9108     (dolist (header gnus-newsgroup-headers)
9109       (when (string-match regexp (funcall func header))
9110         (push (mail-header-number header) articles)))
9111     (nreverse articles)))
9112
9113 (defun gnus-summary-find-matching (header regexp &optional backward unread
9114                                           not-case-fold not-matching)
9115   "Return a list of all articles that match REGEXP on HEADER.
9116 The search stars on the current article and goes forwards unless
9117 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9118 If UNREAD is non-nil, only unread articles will
9119 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9120 in the comparisons. If NOT-MATCHING, return a list of all articles that
9121 not match REGEXP on HEADER."
9122   (let ((case-fold-search (not not-case-fold))
9123         articles d func)
9124     (if (consp header)
9125         (if (eq (car header) 'extra)
9126             (setq func
9127                   `(lambda (h)
9128                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9129                          "")))
9130           (error "%s is an invalid header" header))
9131       (unless (fboundp (intern (concat "mail-header-" header)))
9132         (error "%s is not a valid header" header))
9133       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9134     (dolist (d (if (eq backward 'all)
9135                    gnus-newsgroup-data
9136                  (gnus-data-find-list
9137                   (gnus-summary-article-number)
9138                   (gnus-data-list backward))))
9139       (when (and (or (not unread)       ; We want all articles...
9140                      (gnus-data-unread-p d)) ; Or just unreads.
9141                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9142                  (if not-matching
9143                      (not (string-match
9144                            regexp
9145                            (funcall func (gnus-data-header d))))
9146                    (string-match regexp
9147                                  (funcall func (gnus-data-header d)))))
9148         (push (gnus-data-number d) articles))) ; Success!
9149     (nreverse articles)))
9150
9151 (defun gnus-summary-execute-command (header regexp command &optional backward)
9152   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9153 If HEADER is an empty string (or nil), the match is done on the entire
9154 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9155   (interactive
9156    (list (let ((completion-ignore-case t))
9157            (completing-read
9158             "Header name: "
9159             (mapcar (lambda (header) (list (format "%s" header)))
9160                     (append
9161                      '("Number" "Subject" "From" "Lines" "Date"
9162                        "Message-ID" "Xref" "References" "Body")
9163                      gnus-extra-headers))
9164             nil 'require-match))
9165          (read-string "Regexp: ")
9166          (read-key-sequence "Command: ")
9167          current-prefix-arg))
9168   (when (equal header "Body")
9169     (setq header ""))
9170   ;; Hidden thread subtrees must be searched as well.
9171   (gnus-summary-show-all-threads)
9172   ;; We don't want to change current point nor window configuration.
9173   (save-excursion
9174     (save-window-excursion
9175       (let (gnus-visual
9176             gnus-treat-strip-trailing-blank-lines
9177             gnus-treat-strip-leading-blank-lines
9178             gnus-treat-strip-multiple-blank-lines
9179             gnus-treat-hide-boring-headers
9180             gnus-treat-fold-newsgroups
9181             gnus-article-prepare-hook)
9182         (gnus-message 6 "Executing %s..." (key-description command))
9183         ;; We'd like to execute COMMAND interactively so as to give arguments.
9184         (gnus-execute header regexp
9185                       `(call-interactively ',(key-binding command))
9186                       backward)
9187         (gnus-message 6 "Executing %s...done" (key-description command))))))
9188
9189 (defun gnus-summary-beginning-of-article ()
9190   "Scroll the article back to the beginning."
9191   (interactive)
9192   (gnus-summary-select-article)
9193   (gnus-configure-windows 'article)
9194   (gnus-eval-in-buffer-window gnus-article-buffer
9195     (widen)
9196     (goto-char (point-min))
9197     (when gnus-break-pages
9198       (gnus-narrow-to-page))))
9199
9200 (defun gnus-summary-end-of-article ()
9201   "Scroll to the end of the article."
9202   (interactive)
9203   (gnus-summary-select-article)
9204   (gnus-configure-windows 'article)
9205   (gnus-eval-in-buffer-window gnus-article-buffer
9206     (widen)
9207     (goto-char (point-max))
9208     (recenter -3)
9209     (when gnus-break-pages
9210       (when (re-search-backward page-delimiter nil t)
9211         (narrow-to-region (match-end 0) (point-max)))
9212       (gnus-narrow-to-page))))
9213
9214 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9215   "Truncate to LEN and quote all \"(\"'s in STRING."
9216   (gnus-replace-in-string (if (and len (> (length string) len))
9217                               (substring string 0 len)
9218                             string)
9219                           "[()]" "\\\\\\&"))
9220
9221 (defun gnus-summary-print-article (&optional filename n)
9222   "Generate and print a PostScript image of the process-marked (mail) articles.
9223
9224 If used interactively, print the current article if none are
9225 process-marked.  With prefix arg, prompt the user for the name of the
9226 file to save in.
9227
9228 When used from Lisp, accept two optional args FILENAME and N.  N means
9229 to print the next N articles.  If N is negative, print the N previous
9230 articles.  If N is nil and articles have been marked with the process
9231 mark, print these instead.
9232
9233 If the optional first argument FILENAME is nil, send the image to the
9234 printer.  If FILENAME is a string, save the PostScript image in a file with
9235 that name.  If FILENAME is a number, prompt the user for the name of the file
9236 to save in."
9237   (interactive (list (ps-print-preprint current-prefix-arg)))
9238   (dolist (article (gnus-summary-work-articles n))
9239     (gnus-summary-select-article nil nil 'pseudo article)
9240     (gnus-eval-in-buffer-window gnus-article-buffer
9241       (gnus-print-buffer))
9242     (gnus-summary-remove-process-mark article))
9243   (ps-despool filename))
9244
9245 (defun gnus-print-buffer ()
9246   (let ((buffer (generate-new-buffer " *print*")))
9247     (unwind-protect
9248         (progn
9249           (copy-to-buffer buffer (point-min) (point-max))
9250           (set-buffer buffer)
9251           (gnus-remove-text-with-property 'gnus-decoration)
9252           (when (gnus-visual-p 'article-highlight 'highlight)
9253             ;; Copy-to-buffer doesn't copy overlay.  So redo
9254             ;; highlight.
9255             (let ((gnus-article-buffer buffer))
9256               (gnus-article-highlight-citation t)
9257               (gnus-article-highlight-signature)
9258               (gnus-article-emphasize)
9259               (gnus-article-delete-invisible-text)))
9260           (let ((ps-left-header
9261                  (list
9262                   (concat "("
9263                           (gnus-summary-print-truncate-and-quote
9264                            (mail-header-subject gnus-current-headers)
9265                            66) ")")
9266                   (concat "("
9267                           (gnus-summary-print-truncate-and-quote
9268                            (mail-header-from gnus-current-headers)
9269                            45) ")")))
9270                 (ps-right-header
9271                  (list
9272                   "/pagenumberstring load"
9273                   (concat "("
9274                           (mail-header-date gnus-current-headers) ")"))))
9275             (gnus-run-hooks 'gnus-ps-print-hook)
9276             (save-excursion
9277               (if window-system
9278                   (ps-spool-buffer-with-faces)
9279                 (ps-spool-buffer)))))
9280       (kill-buffer buffer))))
9281
9282 (defun gnus-summary-show-article (&optional arg)
9283   "Force redisplaying of the current article.
9284 If ARG (the prefix) is a number, show the article with the charset
9285 defined in `gnus-summary-show-article-charset-alist', or the charset
9286 input.
9287 If ARG (the prefix) is non-nil and not a number, show the raw article
9288 without any article massaging functions being run.  Normally, the key
9289 strokes are `C-u g'."
9290   (interactive "P")
9291   (cond
9292    ((numberp arg)
9293     (gnus-summary-show-article t)
9294     (let ((gnus-newsgroup-charset
9295            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9296                (mm-read-coding-system
9297                 "View as charset: " ;; actually it is coding system.
9298                 (with-current-buffer gnus-article-buffer
9299                   (mm-detect-coding-region (point) (point-max))))))
9300           (gnus-newsgroup-ignored-charsets 'gnus-all))
9301       (gnus-summary-select-article nil 'force)
9302       (let ((deps gnus-newsgroup-dependencies)
9303             head header lines)
9304         (save-excursion
9305           (set-buffer gnus-original-article-buffer)
9306           (save-restriction
9307             (message-narrow-to-head)
9308             (setq head (buffer-string))
9309             (goto-char (point-min))
9310             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9311               (goto-char (point-max))
9312               (widen)
9313               (setq lines (1- (count-lines (point) (point-max))))))
9314           (with-temp-buffer
9315             (insert (format "211 %d Article retrieved.\n"
9316                             (cdr gnus-article-current)))
9317             (insert head)
9318             (if lines (insert (format "Lines: %d\n" lines)))
9319             (insert ".\n")
9320             (let ((nntp-server-buffer (current-buffer)))
9321               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9322         (gnus-data-set-header
9323          (gnus-data-find (cdr gnus-article-current))
9324          header)
9325         (gnus-summary-update-article-line
9326          (cdr gnus-article-current) header)
9327         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9328           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9329    ((not arg)
9330     ;; Select the article the normal way.
9331     (gnus-summary-select-article nil 'force))
9332    (t
9333     ;; We have to require this here to make sure that the following
9334     ;; dynamic binding isn't shadowed by autoloading.
9335     (require 'gnus-async)
9336     (require 'gnus-art)
9337     ;; Bind the article treatment functions to nil.
9338     (let ((gnus-have-all-headers t)
9339           gnus-article-prepare-hook
9340           gnus-article-decode-hook
9341           gnus-display-mime-function
9342           gnus-break-pages)
9343       ;; Destroy any MIME parts.
9344       (when (gnus-buffer-live-p gnus-article-buffer)
9345         (save-excursion
9346           (set-buffer gnus-article-buffer)
9347           (mm-destroy-parts gnus-article-mime-handles)
9348           ;; Set it to nil for safety reason.
9349           (setq gnus-article-mime-handle-alist nil)
9350           (setq gnus-article-mime-handles nil)))
9351       (gnus-summary-select-article nil 'force))))
9352   (gnus-summary-goto-subject gnus-current-article)
9353   (gnus-summary-position-point))
9354
9355 (defun gnus-summary-show-raw-article ()
9356   "Show the raw article without any article massaging functions being run."
9357   (interactive)
9358   (gnus-summary-show-article t))
9359
9360 (defun gnus-summary-verbose-headers (&optional arg)
9361   "Toggle permanent full header display.
9362 If ARG is a positive number, turn header display on.
9363 If ARG is a negative number, turn header display off."
9364   (interactive "P")
9365   (setq gnus-show-all-headers
9366         (cond ((or (not (numberp arg))
9367                    (zerop arg))
9368                (not gnus-show-all-headers))
9369               ((natnump arg)
9370                t)))
9371   (gnus-summary-show-article))
9372
9373 (defun gnus-summary-toggle-header (&optional arg)
9374   "Show the headers if they are hidden, or hide them if they are shown.
9375 If ARG is a positive number, show the entire header.
9376 If ARG is a negative number, hide the unwanted header lines."
9377   (interactive "P")
9378   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9379                      (get-buffer-window gnus-article-buffer t))))
9380     (with-current-buffer gnus-article-buffer
9381       (widen)
9382       (article-narrow-to-head)
9383       (let* ((buffer-read-only nil)
9384              (inhibit-point-motion-hooks t)
9385              (hidden (if (numberp arg)
9386                          (>= arg 0)
9387                        (or (not (looking-at "[^ \t\n]+:"))
9388                            (gnus-article-hidden-text-p 'headers))))
9389              s e)
9390         (delete-region (point-min) (point-max))
9391         (with-current-buffer gnus-original-article-buffer
9392           (goto-char (setq s (point-min)))
9393           (setq e (if (search-forward "\n\n" nil t)
9394                       (1- (point))
9395                     (point-max))))
9396         (insert-buffer-substring gnus-original-article-buffer s e)
9397         (run-hooks 'gnus-article-decode-hook)
9398         (if hidden
9399             (let ((gnus-treat-hide-headers nil)
9400                   (gnus-treat-hide-boring-headers nil))
9401               (gnus-delete-wash-type 'headers)
9402               (gnus-treat-article 'head))
9403           (gnus-treat-article 'head))
9404         (widen)
9405         (if window
9406             (set-window-start window (goto-char (point-min))))
9407         (if gnus-break-pages
9408             (gnus-narrow-to-page)
9409           (when (gnus-visual-p 'page-marker)
9410             (let ((buffer-read-only nil))
9411               (gnus-remove-text-with-property 'gnus-prev)
9412               (gnus-remove-text-with-property 'gnus-next))))
9413         (gnus-set-mode-line 'article)))))
9414
9415 (defun gnus-summary-show-all-headers ()
9416   "Make all header lines visible."
9417   (interactive)
9418   (gnus-summary-toggle-header 1))
9419
9420 (defun gnus-summary-caesar-message (&optional arg)
9421   "Caesar rotate the current article by 13.
9422 With a non-numerical prefix, also rotate headers.  A numerical
9423 prefix specifies how many places to rotate each letter forward."
9424   (interactive "P")
9425   (gnus-summary-select-article)
9426   (let ((mail-header-separator ""))
9427     (gnus-eval-in-buffer-window gnus-article-buffer
9428       (save-restriction
9429         (widen)
9430         (let ((start (window-start))
9431               buffer-read-only)
9432           (if (equal arg '(4))
9433               (message-caesar-buffer-body nil t)
9434             (message-caesar-buffer-body arg))
9435           (set-window-start (get-buffer-window (current-buffer)) start)))))
9436   ;; Create buttons and stuff...
9437   (gnus-treat-article nil))
9438
9439 (defun gnus-summary-idna-message (&optional arg)
9440   "Decode IDNA encoded domain names in the current articles.
9441 IDNA encoded domain names looks like `xn--bar'.  If a string
9442 remain unencoded after running this function, it is likely an
9443 invalid IDNA string (`xn--bar' is invalid).
9444
9445 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9446 installed for this command to work."
9447   (interactive "P")
9448   (if (not (and (condition-case nil (require 'idna)
9449                   (file-error))
9450                 (mm-coding-system-p 'utf-8)
9451                 (executable-find (symbol-value 'idna-program))))
9452       (gnus-message
9453        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9454     (gnus-summary-select-article)
9455     (let ((mail-header-separator ""))
9456       (gnus-eval-in-buffer-window gnus-article-buffer
9457         (save-restriction
9458           (widen)
9459           (let ((start (window-start))
9460                 buffer-read-only)
9461             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9462               (replace-match (idna-to-unicode (match-string 1))))
9463             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9464
9465 (defun gnus-summary-morse-message (&optional arg)
9466   "Morse decode the current article."
9467   (interactive "P")
9468   (gnus-summary-select-article)
9469   (let ((mail-header-separator ""))
9470     (gnus-eval-in-buffer-window gnus-article-buffer
9471       (save-excursion
9472         (save-restriction
9473           (widen)
9474           (let ((pos (window-start))
9475                 buffer-read-only)
9476             (goto-char (point-min))
9477             (when (message-goto-body)
9478               (gnus-narrow-to-body))
9479             (goto-char (point-min))
9480             (while (search-forward "·" (point-max) t)
9481               (replace-match "."))
9482             (unmorse-region (point-min) (point-max))
9483             (widen)
9484             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9485
9486 (defun gnus-summary-stop-page-breaking ()
9487   "Stop page breaking in the current article."
9488   (interactive)
9489   (gnus-summary-select-article)
9490   (gnus-eval-in-buffer-window gnus-article-buffer
9491     (widen)
9492     (when (gnus-visual-p 'page-marker)
9493       (let ((buffer-read-only nil))
9494         (gnus-remove-text-with-property 'gnus-prev)
9495         (gnus-remove-text-with-property 'gnus-next))
9496       (setq gnus-page-broken nil))))
9497
9498 (defun gnus-summary-move-article (&optional n to-newsgroup
9499                                             select-method action)
9500   "Move the current article to a different newsgroup.
9501 If N is a positive number, move the N next articles.
9502 If N is a negative number, move the N previous articles.
9503 If N is nil and any articles have been marked with the process mark,
9504 move those articles instead.
9505 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9506 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9507 re-spool using this method.
9508
9509 When called interactively with TO-NEWSGROUP being nil, the value of
9510 the variable `gnus-move-split-methods' is used for finding a default
9511 for the target newsgroup.
9512
9513 For this function to work, both the current newsgroup and the
9514 newsgroup that you want to move to have to support the `request-move'
9515 and `request-accept' functions.
9516
9517 ACTION can be either `move' (the default), `crosspost' or `copy'."
9518   (interactive "P")
9519   (unless action
9520     (setq action 'move))
9521   ;; Check whether the source group supports the required functions.
9522   (cond ((and (eq action 'move)
9523               (not (gnus-check-backend-function
9524                     'request-move-article gnus-newsgroup-name)))
9525          (error "The current group does not support article moving"))
9526         ((and (eq action 'crosspost)
9527               (not (gnus-check-backend-function
9528                     'request-replace-article gnus-newsgroup-name)))
9529          (error "The current group does not support article editing")))
9530   (let ((articles (gnus-summary-work-articles n))
9531         (prefix (if (gnus-check-backend-function
9532                      'request-move-article gnus-newsgroup-name)
9533                     (funcall gnus-move-group-prefix-function
9534                              gnus-newsgroup-name)
9535                   ""))
9536         (names '((move "Move" "Moving")
9537                  (copy "Copy" "Copying")
9538                  (crosspost "Crosspost" "Crossposting")))
9539         (copy-buf (save-excursion
9540                     (nnheader-set-temp-buffer " *copy article*")))
9541         art-group to-method new-xref article to-groups
9542         articles-to-update-marks encoded)
9543     (unless (assq action names)
9544       (error "Unknown action %s" action))
9545     ;; Read the newsgroup name.
9546     (when (and (not to-newsgroup)
9547                (not select-method))
9548       (if (and gnus-move-split-methods
9549                (not
9550                 (and (memq gnus-current-article articles)
9551                      (gnus-buffer-live-p gnus-original-article-buffer))))
9552           ;; When `gnus-move-split-methods' is non-nil, we have to
9553           ;; select an article to give `gnus-read-move-group-name' an
9554           ;; opportunity to suggest an appropriate default.  However,
9555           ;; we needn't render or mark the article.
9556           (let ((gnus-display-mime-function nil)
9557                 (gnus-article-prepare-hook nil)
9558                 (gnus-mark-article-hook nil))
9559             (gnus-summary-select-article nil nil nil (car articles))))
9560       (setq to-newsgroup (gnus-read-move-group-name
9561                           (cadr (assq action names))
9562                           (symbol-value
9563                            (intern (format "gnus-current-%s-group" action)))
9564                           articles prefix)
9565             encoded to-newsgroup
9566             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9567       (set (intern (format "gnus-current-%s-group" action))
9568            (mm-decode-coding-string
9569             to-newsgroup
9570             (gnus-group-name-charset to-method to-newsgroup))))
9571     (unless to-method
9572       (setq to-method (or select-method
9573                           (gnus-server-to-method
9574                            (gnus-group-method to-newsgroup)))))
9575     (setq to-newsgroup
9576           (or encoded
9577               (and to-newsgroup
9578                    (mm-encode-coding-string
9579                     to-newsgroup
9580                     (gnus-group-name-charset to-method to-newsgroup)))))
9581     ;; Check the method we are to move this article to...
9582     (unless (gnus-check-backend-function
9583              'request-accept-article (car to-method))
9584       (error "%s does not support article copying" (car to-method)))
9585     (unless (gnus-check-server to-method)
9586       (error "Can't open server %s" (car to-method)))
9587     (gnus-message 6 "%s to %s: %s..."
9588                   (caddr (assq action names))
9589                   (or (car select-method)
9590                       (gnus-group-decoded-name to-newsgroup))
9591                   articles)
9592     (while articles
9593       (setq article (pop articles))
9594       (setq
9595        art-group
9596        (cond
9597         ;; Move the article.
9598         ((eq action 'move)
9599          ;; Remove this article from future suppression.
9600          (gnus-dup-unsuppress-article article)
9601          (let* ((from-method (gnus-find-method-for-group
9602                               gnus-newsgroup-name))
9603                 (to-method (or select-method
9604                                (gnus-find-method-for-group to-newsgroup)))
9605                 (move-is-internal (gnus-method-equal from-method to-method)))
9606            (gnus-request-move-article
9607             article                     ; Article to move
9608             gnus-newsgroup-name         ; From newsgroup
9609             (nth 1 (gnus-find-method-for-group
9610                     gnus-newsgroup-name)) ; Server
9611             (list 'gnus-request-accept-article
9612                   to-newsgroup (list 'quote select-method)
9613                   (not articles) t)     ; Accept form
9614             (not articles)              ; Only save nov last time
9615             move-is-internal)))         ; is this move internal?
9616         ;; Copy the article.
9617         ((eq action 'copy)
9618          (save-excursion
9619            (set-buffer copy-buf)
9620            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9621              (save-restriction
9622                (nnheader-narrow-to-headers)
9623                (dolist (hdr gnus-copy-article-ignored-headers)
9624                  (message-remove-header hdr t)))
9625              (gnus-request-accept-article
9626               to-newsgroup select-method (not articles) t))))
9627         ;; Crosspost the article.
9628         ((eq action 'crosspost)
9629          (let ((xref (message-tokenize-header
9630                       (mail-header-xref (gnus-summary-article-header article))
9631                       " ")))
9632            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9633                                   ":" (number-to-string article)))
9634            (unless xref
9635              (setq xref (list (system-name))))
9636            (setq new-xref
9637                  (concat
9638                   (mapconcat 'identity
9639                              (delete "Xref:" (delete new-xref xref))
9640                              " ")
9641                   " " new-xref))
9642            (save-excursion
9643              (set-buffer copy-buf)
9644              ;; First put the article in the destination group.
9645              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9646              (when (consp (setq art-group
9647                                 (gnus-request-accept-article
9648                                  to-newsgroup select-method (not articles) t)))
9649                (setq new-xref (concat new-xref " " (car art-group)
9650                                       ":"
9651                                       (number-to-string (cdr art-group))))
9652                ;; Now we have the new Xrefs header, so we insert
9653                ;; it and replace the new article.
9654                (nnheader-replace-header "Xref" new-xref)
9655                (gnus-request-replace-article
9656                 (cdr art-group) to-newsgroup (current-buffer) t)
9657                art-group))))))
9658       (cond
9659        ((not art-group)
9660         (gnus-message 1 "Couldn't %s article %s: %s"
9661                       (cadr (assq action names)) article
9662                       (nnheader-get-report (car to-method))))
9663        ((eq art-group 'junk)
9664         (when (eq action 'move)
9665           (gnus-summary-mark-article article gnus-canceled-mark)
9666           (gnus-message 4 "Deleted article %s" article)
9667           ;; run the delete hook
9668           (run-hook-with-args 'gnus-summary-article-delete-hook
9669                               action
9670                               (gnus-data-header
9671                                (assoc article (gnus-data-list nil)))
9672                               gnus-newsgroup-name nil
9673                               select-method)))
9674        (t
9675         (let* ((pto-group (gnus-group-prefixed-name
9676                            (car art-group) to-method))
9677                (info (gnus-get-info pto-group))
9678                (to-group (gnus-info-group info))
9679                to-marks)
9680           ;; Update the group that has been moved to.
9681           (when (and info
9682                      (memq action '(move copy)))
9683             (unless (member to-group to-groups)
9684               (push to-group to-groups))
9685
9686             (unless (memq article gnus-newsgroup-unreads)
9687               (push 'read to-marks)
9688               (gnus-info-set-read
9689                info (gnus-add-to-range (gnus-info-read info)
9690                                        (list (cdr art-group)))))
9691
9692             ;; See whether the article is to be put in the cache.
9693             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9694                              gnus-article-mark-lists
9695                            (delete '(expirable . expire)
9696                                    (copy-sequence gnus-article-mark-lists))))
9697                   (to-article (cdr art-group)))
9698
9699               ;; Enter the article into the cache in the new group,
9700               ;; if that is required.
9701               (when gnus-use-cache
9702                 (gnus-cache-possibly-enter-article
9703                  to-group to-article
9704                  (memq article gnus-newsgroup-marked)
9705                  (memq article gnus-newsgroup-dormant)
9706                  (memq article gnus-newsgroup-unreads)))
9707
9708               (when gnus-preserve-marks
9709                 ;; Copy any marks over to the new group.
9710                 (when (and (equal to-group gnus-newsgroup-name)
9711                            (not (memq article gnus-newsgroup-unreads)))
9712                   ;; Mark this article as read in this group.
9713                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9714                   (setcdr (gnus-active to-group) to-article)
9715                   (setcdr gnus-newsgroup-active to-article))
9716
9717                 (while marks
9718                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9719                     (when (memq article (symbol-value
9720                                          (intern (format "gnus-newsgroup-%s"
9721                                                          (caar marks)))))
9722                       (push (cdar marks) to-marks)
9723                       ;; If the other group is the same as this group,
9724                       ;; then we have to add the mark to the list.
9725                       (when (equal to-group gnus-newsgroup-name)
9726                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9727                              (cons to-article
9728                                    (symbol-value
9729                                     (intern (format "gnus-newsgroup-%s"
9730                                                     (caar marks)))))))
9731                       ;; Copy the marks to other group.
9732                       (gnus-add-marked-articles
9733                        to-group (cdar marks) (list to-article) info)))
9734                   (setq marks (cdr marks)))
9735
9736                 (gnus-request-set-mark
9737                  to-group (list (list (list to-article) 'add to-marks))))
9738
9739               (gnus-dribble-enter
9740                (concat "(gnus-group-set-info '"
9741                        (gnus-prin1-to-string (gnus-get-info to-group))
9742                        ")"))))
9743
9744           ;; Update the Xref header in this article to point to
9745           ;; the new crossposted article we have just created.
9746           (when (eq action 'crosspost)
9747             (save-excursion
9748               (set-buffer copy-buf)
9749               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9750               (nnheader-replace-header "Xref" new-xref)
9751               (gnus-request-replace-article
9752                article gnus-newsgroup-name (current-buffer) t)))
9753
9754           ;; run the move/copy/crosspost/respool hook
9755           (run-hook-with-args 'gnus-summary-article-move-hook
9756                               action
9757                               (gnus-data-header
9758                                (assoc article (gnus-data-list nil)))
9759                               gnus-newsgroup-name
9760                               to-newsgroup
9761                               select-method))
9762
9763         ;;;!!!Why is this necessary?
9764         (set-buffer gnus-summary-buffer)
9765
9766         (gnus-summary-goto-subject article)
9767         (when (eq action 'move)
9768           (gnus-summary-mark-article article gnus-canceled-mark))))
9769       (push article articles-to-update-marks))
9770
9771     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9772     ;; Re-activate all groups that have been moved to.
9773     (save-excursion
9774       (set-buffer gnus-group-buffer)
9775       (let ((gnus-group-marked to-groups))
9776         (gnus-group-get-new-news-this-group nil t)))
9777
9778     (gnus-kill-buffer copy-buf)
9779     (gnus-summary-position-point)
9780     (gnus-set-mode-line 'summary)))
9781
9782 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9783   "Copy the current article to some other group.
9784 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9785 When called interactively, if TO-NEWSGROUP is nil, use the value of
9786 the variable `gnus-move-split-methods' for finding a default target
9787 newsgroup.
9788 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9789 re-spool using this method."
9790   (interactive "P")
9791   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9792
9793 (defun gnus-summary-crosspost-article (&optional n)
9794   "Crosspost the current article to some other group."
9795   (interactive "P")
9796   (gnus-summary-move-article n nil nil 'crosspost))
9797
9798 (defcustom gnus-summary-respool-default-method nil
9799   "Default method type for respooling an article.
9800 If nil, use to the current newsgroup method."
9801   :type 'symbol
9802   :group 'gnus-summary-mail)
9803
9804 (defcustom gnus-summary-display-while-building nil
9805   "If non-nil, show and update the summary buffer as it's being built.
9806 If the value is t, update the buffer after every line is inserted.  If
9807 the value is an integer (N), update the display every N lines."
9808   :version "22.1"
9809   :group 'gnus-thread
9810   :type '(choice (const :tag "off" nil)
9811                  number
9812                  (const :tag "frequently" t)))
9813
9814 (defun gnus-summary-respool-article (&optional n method)
9815   "Respool the current article.
9816 The article will be squeezed through the mail spooling process again,
9817 which means that it will be put in some mail newsgroup or other
9818 depending on `nnmail-split-methods'.
9819 If N is a positive number, respool the N next articles.
9820 If N is a negative number, respool the N previous articles.
9821 If N is nil and any articles have been marked with the process mark,
9822 respool those articles instead.
9823
9824 Respooling can be done both from mail groups and \"real\" newsgroups.
9825 In the former case, the articles in question will be moved from the
9826 current group into whatever groups they are destined to.  In the
9827 latter case, they will be copied into the relevant groups."
9828   (interactive
9829    (list current-prefix-arg
9830          (let* ((methods (gnus-methods-using 'respool))
9831                 (methname
9832                  (symbol-name (or gnus-summary-respool-default-method
9833                                   (car (gnus-find-method-for-group
9834                                         gnus-newsgroup-name)))))
9835                 (method
9836                  (gnus-completing-read-with-default
9837                   methname "Backend to use when respooling"
9838                   methods nil t nil 'gnus-mail-method-history))
9839                 ms)
9840            (cond
9841             ((zerop (length (setq ms (gnus-servers-using-backend
9842                                       (intern method)))))
9843              (list (intern method) ""))
9844             ((= 1 (length ms))
9845              (car ms))
9846             (t
9847              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9848                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9849                            ms-alist))))))))
9850   (unless method
9851     (error "No method given for respooling"))
9852   (if (assoc (symbol-name
9853               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9854              (gnus-methods-using 'respool))
9855       (gnus-summary-move-article n nil method)
9856     (gnus-summary-copy-article n nil method)))
9857
9858 (defun gnus-summary-import-article (file &optional edit)
9859   "Import an arbitrary file into a mail newsgroup."
9860   (interactive "fImport file: \nP")
9861   (let ((group gnus-newsgroup-name)
9862         (now (current-time))
9863         atts lines group-art)
9864     (unless (gnus-check-backend-function 'request-accept-article group)
9865       (error "%s does not support article importing" group))
9866     (or (file-readable-p file)
9867         (not (file-regular-p file))
9868         (error "Can't read %s" file))
9869     (save-excursion
9870       (set-buffer (gnus-get-buffer-create " *import file*"))
9871       (erase-buffer)
9872       (nnheader-insert-file-contents file)
9873       (goto-char (point-min))
9874       (if (nnheader-article-p)
9875           (save-restriction
9876             (goto-char (point-min))
9877             (search-forward "\n\n" nil t)
9878             (narrow-to-region (point-min) (1- (point)))
9879             (goto-char (point-min))
9880             (unless (re-search-forward "^date:" nil t)
9881               (goto-char (point-max))
9882               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9883        ;; This doesn't look like an article, so we fudge some headers.
9884         (setq atts (file-attributes file)
9885               lines (count-lines (point-min) (point-max)))
9886         (insert "From: " (read-string "From: ") "\n"
9887                 "Subject: " (read-string "Subject: ") "\n"
9888                 "Date: " (message-make-date (nth 5 atts)) "\n"
9889                 "Message-ID: " (message-make-message-id) "\n"
9890                 "Lines: " (int-to-string lines) "\n"
9891                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9892       (setq group-art (gnus-request-accept-article group nil t))
9893       (kill-buffer (current-buffer)))
9894     (setq gnus-newsgroup-active (gnus-activate-group group))
9895     (forward-line 1)
9896     (gnus-summary-goto-article (cdr group-art) nil t)
9897     (when edit
9898       (gnus-summary-edit-article))))
9899
9900 (defun gnus-summary-create-article ()
9901   "Create an article in a mail newsgroup."
9902   (interactive)
9903   (let ((group gnus-newsgroup-name)
9904         (now (current-time))
9905         group-art)
9906     (unless (gnus-check-backend-function 'request-accept-article group)
9907       (error "%s does not support article importing" group))
9908     (save-excursion
9909       (set-buffer (gnus-get-buffer-create " *import file*"))
9910       (erase-buffer)
9911       (goto-char (point-min))
9912       ;; This doesn't look like an article, so we fudge some headers.
9913       (insert "From: " (read-string "From: ") "\n"
9914               "Subject: " (read-string "Subject: ") "\n"
9915               "Date: " (message-make-date now) "\n"
9916               "Message-ID: " (message-make-message-id) "\n")
9917       (setq group-art (gnus-request-accept-article group nil t))
9918       (kill-buffer (current-buffer)))
9919     (setq gnus-newsgroup-active (gnus-activate-group group))
9920     (forward-line 1)
9921     (gnus-summary-goto-article (cdr group-art) nil t)
9922     (gnus-summary-edit-article)))
9923
9924 (defun gnus-summary-article-posted-p ()
9925   "Say whether the current (mail) article is available from news as well.
9926 This will be the case if the article has both been mailed and posted."
9927   (interactive)
9928   (let ((id (mail-header-references (gnus-summary-article-header)))
9929         (gnus-override-method (car (gnus-refer-article-methods))))
9930     (if (gnus-request-head id "")
9931         (gnus-message 2 "The current message was found on %s"
9932                       gnus-override-method)
9933       (gnus-message 2 "The current message couldn't be found on %s"
9934                     gnus-override-method)
9935       nil)))
9936
9937 (defun gnus-summary-expire-articles (&optional now)
9938   "Expire all articles that are marked as expirable in the current group."
9939   (interactive)
9940   (when (and (not gnus-group-is-exiting-without-update-p)
9941              (gnus-check-backend-function
9942               'request-expire-articles gnus-newsgroup-name))
9943     ;; This backend supports expiry.
9944     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9945            (expirable (if total
9946                           (progn
9947                             ;; We need to update the info for
9948                             ;; this group for `gnus-list-of-read-articles'
9949                             ;; to give us the right answer.
9950                             (gnus-run-hooks 'gnus-exit-group-hook)
9951                             (gnus-summary-update-info)
9952                             (gnus-list-of-read-articles gnus-newsgroup-name))
9953                         (setq gnus-newsgroup-expirable
9954                               (sort gnus-newsgroup-expirable '<))))
9955            (expiry-wait (if now 'immediate
9956                           (gnus-group-find-parameter
9957                            gnus-newsgroup-name 'expiry-wait)))
9958            (nnmail-expiry-target
9959             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9960                 nnmail-expiry-target))
9961            es)
9962       (when expirable
9963         ;; There are expirable articles in this group, so we run them
9964         ;; through the expiry process.
9965         (gnus-message 6 "Expiring articles...")
9966         (unless (gnus-check-group gnus-newsgroup-name)
9967           (error "Can't open server for %s" gnus-newsgroup-name))
9968         ;; The list of articles that weren't expired is returned.
9969         (save-excursion
9970           (if expiry-wait
9971               (let ((nnmail-expiry-wait-function nil)
9972                     (nnmail-expiry-wait expiry-wait))
9973                 (setq es (gnus-request-expire-articles
9974                           expirable gnus-newsgroup-name)))
9975             (setq es (gnus-request-expire-articles
9976                       expirable gnus-newsgroup-name)))
9977           (unless total
9978             (setq gnus-newsgroup-expirable es))
9979           ;; We go through the old list of expirable, and mark all
9980           ;; really expired articles as nonexistent.
9981           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9982             (let ((gnus-use-cache nil))
9983               (dolist (article expirable)
9984                 (when (and (not (memq article es))
9985                            (gnus-data-find article))
9986                   (gnus-summary-mark-article article gnus-canceled-mark)
9987                   (run-hook-with-args 'gnus-summary-article-expire-hook
9988                                       'delete
9989                                       (gnus-data-header
9990                                        (assoc article (gnus-data-list nil)))
9991                                       gnus-newsgroup-name
9992                                       nil
9993                                       nil))))))
9994         (gnus-message 6 "Expiring articles...done")))))
9995
9996 (defun gnus-summary-expire-articles-now ()
9997   "Expunge all expirable articles in the current group.
9998 This means that *all* articles that are marked as expirable will be
9999 deleted forever, right now."
10000   (interactive)
10001   (or gnus-expert-user
10002       (gnus-yes-or-no-p
10003        "Are you really, really sure you want to delete all expirable messages? ")
10004       (error "Phew!"))
10005   (gnus-summary-expire-articles t))
10006
10007 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10008 (defun gnus-summary-delete-article (&optional n)
10009   "Delete the N next (mail) articles.
10010 This command actually deletes articles.  This is not a marking
10011 command.  The article will disappear forever from your life, never to
10012 return.
10013
10014 If N is negative, delete backwards.
10015 If N is nil and articles have been marked with the process mark,
10016 delete these instead.
10017
10018 If `gnus-novice-user' is non-nil you will be asked for
10019 confirmation before the articles are deleted."
10020   (interactive "P")
10021   (unless (gnus-check-backend-function 'request-expire-articles
10022                                        gnus-newsgroup-name)
10023     (error "The current newsgroup does not support article deletion"))
10024   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10025     (error "Couldn't open server"))
10026   ;; Compute the list of articles to delete.
10027   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10028         (nnmail-expiry-target 'delete)
10029         not-deleted)
10030     (if (and gnus-novice-user
10031              (not (gnus-yes-or-no-p
10032                    (format "Do you really want to delete %s forever? "
10033                            (if (> (length articles) 1)
10034                                (format "these %s articles" (length articles))
10035                              "this article")))))
10036         ()
10037       ;; Delete the articles.
10038       (setq not-deleted (gnus-request-expire-articles
10039                          articles gnus-newsgroup-name 'force))
10040       (while articles
10041         (gnus-summary-remove-process-mark (car articles))
10042         ;; The backend might not have been able to delete the article
10043         ;; after all.
10044         (unless (memq (car articles) not-deleted)
10045           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10046         (let* ((article (car articles))
10047                (ghead  (gnus-data-header
10048                                     (assoc article (gnus-data-list nil)))))
10049           (run-hook-with-args 'gnus-summary-article-delete-hook
10050                               'delete ghead gnus-newsgroup-name nil
10051                               nil))
10052         (setq articles (cdr articles)))
10053       (when not-deleted
10054         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10055     (gnus-summary-position-point)
10056     (gnus-set-mode-line 'summary)
10057     not-deleted))
10058
10059 (defun gnus-summary-edit-article (&optional arg)
10060   "Edit the current article.
10061 This will have permanent effect only in mail groups.
10062 If ARG is nil, edit the decoded articles.
10063 If ARG is 1, edit the raw articles.
10064 If ARG is 2, edit the raw articles even in read-only groups.
10065 If ARG is 3, edit the articles with the current handles.
10066 Otherwise, allow editing of articles even in read-only
10067 groups."
10068   (interactive "P")
10069   (let (force raw current-handles)
10070     (cond
10071      ((null arg))
10072      ((eq arg 1)
10073       (setq raw t))
10074      ((eq arg 2)
10075       (setq raw t
10076             force t))
10077      ((eq arg 3)
10078       (setq current-handles
10079             (and (gnus-buffer-live-p gnus-article-buffer)
10080                  (with-current-buffer gnus-article-buffer
10081                    (prog1
10082                        gnus-article-mime-handles
10083                      (setq gnus-article-mime-handles nil))))))
10084      (t
10085       (setq force t)))
10086     (when (and raw (not force)
10087                (member gnus-newsgroup-name '("nndraft:delayed"
10088                                              "nndraft:drafts"
10089                                              "nndraft:queue")))
10090       (error "Can't edit the raw article in group %s"
10091              gnus-newsgroup-name))
10092     (save-excursion
10093       (set-buffer gnus-summary-buffer)
10094       (let ((mail-parse-charset gnus-newsgroup-charset)
10095             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10096         (gnus-set-global-variables)
10097         (when (and (not force)
10098                    (gnus-group-read-only-p))
10099           (error "The current newsgroup does not support article editing"))
10100         (gnus-summary-show-article t)
10101         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10102           (with-current-buffer gnus-article-buffer
10103             (mm-enable-multibyte)))
10104         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10105             (setq raw t))
10106         (gnus-article-edit-article
10107          (if raw 'ignore
10108            `(lambda ()
10109               (let ((mbl mml-buffer-list))
10110                 (setq mml-buffer-list nil)
10111                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10112                   (mime-to-mml ,'current-handles))
10113                 (let ((mbl1 mml-buffer-list))
10114                   (setq mml-buffer-list mbl)
10115                   (set (make-local-variable 'mml-buffer-list) mbl1))
10116                 (gnus-make-local-hook 'kill-buffer-hook)
10117                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10118          `(lambda (no-highlight)
10119             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10120                   (message-options message-options)
10121                   (message-options-set-recipient)
10122                   (mail-parse-ignored-charsets
10123                    ',gnus-newsgroup-ignored-charsets)
10124                   (rfc2047-header-encoding-alist
10125                    ',(let ((charset (gnus-group-name-charset
10126                                      (gnus-find-method-for-group
10127                                       gnus-newsgroup-name)
10128                                      gnus-newsgroup-name)))
10129                        (append (list (cons "Newsgroups" charset)
10130                                      (cons "Followup-To" charset)
10131                                      (cons "Xref" charset))
10132                                rfc2047-header-encoding-alist))))
10133               ,(if (not raw) '(progn
10134                                 (mml-to-mime)
10135                                 (mml-destroy-buffers)
10136                                 (remove-hook 'kill-buffer-hook
10137                                              'mml-destroy-buffers t)
10138                                 (kill-local-variable 'mml-buffer-list)))
10139               (gnus-summary-edit-article-done
10140                ,(or (mail-header-references gnus-current-headers) "")
10141                ,(gnus-group-read-only-p)
10142                ,gnus-summary-buffer no-highlight))))))))
10143
10144 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10145
10146 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10147                                                  no-highlight)
10148   "Make edits to the current article permanent."
10149   (interactive)
10150   (save-excursion
10151    ;; The buffer restriction contains the entire article if it exists.
10152     (when (article-goto-body)
10153       (let ((lines (count-lines (point) (point-max)))
10154             (length (- (point-max) (point)))
10155             (case-fold-search t)
10156             (body (copy-marker (point))))
10157         (goto-char (point-min))
10158         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10159           (delete-region (match-beginning 1) (match-end 1))
10160           (insert (number-to-string length)))
10161         (goto-char (point-min))
10162         (when (re-search-forward
10163                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10164           (delete-region (match-beginning 1) (match-end 1))
10165           (insert (number-to-string length)))
10166         (goto-char (point-min))
10167         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10168           (delete-region (match-beginning 1) (match-end 1))
10169           (insert (number-to-string lines))))))
10170   ;; Replace the article.
10171   (let ((buf (current-buffer)))
10172     (with-temp-buffer
10173       (insert-buffer-substring buf)
10174
10175       (if (and (not read-only)
10176                (not (gnus-request-replace-article
10177                      (cdr gnus-article-current) (car gnus-article-current)
10178                      (current-buffer) t)))
10179           (error "Couldn't replace article")
10180         ;; Update the summary buffer.
10181         (if (and references
10182                  (equal (message-tokenize-header references " ")
10183                         (message-tokenize-header
10184                          (or (message-fetch-field "references") "") " ")))
10185             ;; We only have to update this line.
10186             (save-excursion
10187               (save-restriction
10188                 (message-narrow-to-head)
10189                 (let ((head (buffer-substring-no-properties
10190                              (point-min) (point-max)))
10191                       header)
10192                   (with-temp-buffer
10193                     (insert (format "211 %d Article retrieved.\n"
10194                                     (cdr gnus-article-current)))
10195                     (insert head)
10196                     (insert ".\n")
10197                     (let ((nntp-server-buffer (current-buffer)))
10198                       (setq header (car (gnus-get-newsgroup-headers
10199                                          nil t))))
10200                     (save-excursion
10201                       (set-buffer gnus-summary-buffer)
10202                       (gnus-data-set-header
10203                        (gnus-data-find (cdr gnus-article-current))
10204                        header)
10205                       (gnus-summary-update-article-line
10206                        (cdr gnus-article-current) header)
10207                       (if (gnus-summary-goto-subject
10208                            (cdr gnus-article-current) nil t)
10209                           (gnus-summary-update-secondary-mark
10210                            (cdr gnus-article-current))))))))
10211           ;; Update threads.
10212           (set-buffer (or buffer gnus-summary-buffer))
10213           (gnus-summary-update-article (cdr gnus-article-current))
10214           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10215               (gnus-summary-update-secondary-mark
10216                (cdr gnus-article-current))))
10217         ;; Prettify the article buffer again.
10218         (unless no-highlight
10219           (save-excursion
10220             (set-buffer gnus-article-buffer)
10221             ;;;!!! Fix this -- article should be rehighlighted.
10222             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10223             (set-buffer gnus-original-article-buffer)
10224             (gnus-request-article
10225              (cdr gnus-article-current)
10226              (car gnus-article-current) (current-buffer))))
10227         ;; Prettify the summary buffer line.
10228         (when (gnus-visual-p 'summary-highlight 'highlight)
10229           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10230
10231 (defun gnus-summary-edit-wash (key)
10232   "Perform editing command KEY in the article buffer."
10233   (interactive
10234    (list
10235     (progn
10236       (message "%s" (concat (this-command-keys) "- "))
10237       (read-char))))
10238   (message "")
10239   (gnus-summary-edit-article)
10240   (execute-kbd-macro (concat (this-command-keys) key))
10241   (gnus-article-edit-done))
10242
10243 ;;; Respooling
10244
10245 (defun gnus-summary-respool-query (&optional silent trace)
10246   "Query where the respool algorithm would put this article."
10247   (interactive)
10248   (let (gnus-mark-article-hook)
10249     (gnus-summary-select-article)
10250     (save-excursion
10251       (set-buffer gnus-original-article-buffer)
10252       (let ((groups (nnmail-article-group 'identity trace)))
10253         (unless silent
10254           (if groups
10255               (message "This message would go to %s"
10256                        (mapconcat 'car groups ", "))
10257             (message "This message would go to no groups"))
10258           groups)))))
10259
10260 (defun gnus-summary-respool-trace ()
10261   "Trace where the respool algorithm would put this article.
10262 Display a buffer showing all fancy splitting patterns which matched."
10263   (interactive)
10264   (gnus-summary-respool-query nil t))
10265
10266 ;; Summary marking commands.
10267
10268 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10269   "Mark articles which has the same subject as read, and then select the next.
10270 If UNMARK is positive, remove any kind of mark.
10271 If UNMARK is negative, tick articles."
10272   (interactive "P")
10273   (when unmark
10274     (setq unmark (prefix-numeric-value unmark)))
10275   (let ((count
10276          (gnus-summary-mark-same-subject
10277           (gnus-summary-article-subject) unmark)))
10278     ;; Select next unread article.  If auto-select-same mode, should
10279     ;; select the first unread article.
10280     (gnus-summary-next-article t (and gnus-auto-select-same
10281                                       (gnus-summary-article-subject)))
10282     (gnus-message 7 "%d article%s marked as %s"
10283                   count (if (= count 1) " is" "s are")
10284                   (if unmark "unread" "read"))))
10285
10286 (defun gnus-summary-kill-same-subject (&optional unmark)
10287   "Mark articles which has the same subject as read.
10288 If UNMARK is positive, remove any kind of mark.
10289 If UNMARK is negative, tick articles."
10290   (interactive "P")
10291   (when unmark
10292     (setq unmark (prefix-numeric-value unmark)))
10293   (let ((count
10294          (gnus-summary-mark-same-subject
10295           (gnus-summary-article-subject) unmark)))
10296     ;; If marked as read, go to next unread subject.
10297     (when (null unmark)
10298       ;; Go to next unread subject.
10299       (gnus-summary-next-subject 1 t))
10300     (gnus-message 7 "%d articles are marked as %s"
10301                   count (if unmark "unread" "read"))))
10302
10303 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10304   "Mark articles with same SUBJECT as read, and return marked number.
10305 If optional argument UNMARK is positive, remove any kinds of marks.
10306 If optional argument UNMARK is negative, mark articles as unread instead."
10307   (let ((count 1))
10308     (save-excursion
10309       (cond
10310        ((null unmark)                   ; Mark as read.
10311         (while (and
10312                 (progn
10313                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10314                   (gnus-summary-show-thread) t)
10315                 (gnus-summary-find-subject subject))
10316           (setq count (1+ count))))
10317        ((> unmark 0)                    ; Tick.
10318         (while (and
10319                 (progn
10320                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10321                   (gnus-summary-show-thread) t)
10322                 (gnus-summary-find-subject subject))
10323           (setq count (1+ count))))
10324        (t                               ; Mark as unread.
10325         (while (and
10326                 (progn
10327                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10328                   (gnus-summary-show-thread) t)
10329                 (gnus-summary-find-subject subject))
10330           (setq count (1+ count)))))
10331       (gnus-set-mode-line 'summary)
10332       ;; Return the number of marked articles.
10333       count)))
10334
10335 (defun gnus-summary-mark-as-processable (n &optional unmark)
10336   "Set the process mark on the next N articles.
10337 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10338 the process mark instead.  The difference between N and the actual
10339 number of articles marked is returned."
10340   (interactive "P")
10341   (if (and (null n) (gnus-region-active-p))
10342       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10343     (setq n (prefix-numeric-value n))
10344     (let ((backward (< n 0))
10345           (n (abs n)))
10346       (while (and
10347               (> n 0)
10348               (if unmark
10349                   (gnus-summary-remove-process-mark
10350                    (gnus-summary-article-number))
10351                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10352               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10353         (setq n (1- n)))
10354       (when (/= 0 n)
10355         (gnus-message 7 "No more articles"))
10356       (gnus-summary-recenter)
10357       (gnus-summary-position-point)
10358       n)))
10359
10360 (defun gnus-summary-unmark-as-processable (n)
10361   "Remove the process mark from the next N articles.
10362 If N is negative, unmark backward instead.  The difference between N and
10363 the actual number of articles unmarked is returned."
10364   (interactive "P")
10365   (gnus-summary-mark-as-processable n t))
10366
10367 (defun gnus-summary-unmark-all-processable ()
10368   "Remove the process mark from all articles."
10369   (interactive)
10370   (save-excursion
10371     (while gnus-newsgroup-processable
10372       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10373   (gnus-summary-position-point))
10374
10375 (defun gnus-summary-add-mark (article type)
10376   "Mark ARTICLE with a mark of TYPE."
10377   (let ((vtype (car (assq type gnus-article-mark-lists)))
10378         var)
10379     (if (not vtype)
10380         (error "No such mark type: %s" type)
10381       (setq var (intern (format "gnus-newsgroup-%s" type)))
10382       (set var (cons article (symbol-value var)))
10383       (if (memq type '(processable cached replied forwarded recent saved))
10384           (gnus-summary-update-secondary-mark article)
10385         ;;; !!! This is bogus.  We should find out what primary
10386         ;;; !!! mark we want to set.
10387         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10388
10389 (defun gnus-summary-mark-as-expirable (n)
10390   "Mark N articles forward as expirable.
10391 If N is negative, mark backward instead.  The difference between N and
10392 the actual number of articles marked is returned."
10393   (interactive "p")
10394   (gnus-summary-mark-forward n gnus-expirable-mark))
10395
10396 (defun gnus-summary-mark-as-spam (n)
10397   "Mark N articles forward as spam.
10398 If N is negative, mark backward instead.  The difference between N and
10399 the actual number of articles marked is returned."
10400   (interactive "p")
10401   (gnus-summary-mark-forward n gnus-spam-mark))
10402
10403 (defun gnus-summary-mark-article-as-replied (article)
10404   "Mark ARTICLE as replied to and update the summary line.
10405 ARTICLE can also be a list of articles."
10406   (interactive (list (gnus-summary-article-number)))
10407   (let ((articles (if (listp article) article (list article))))
10408     (dolist (article articles)
10409       (unless (numberp article)
10410         (error "%s is not a number" article))
10411       (push article gnus-newsgroup-replied)
10412       (let ((buffer-read-only nil))
10413         (when (gnus-summary-goto-subject article nil t)
10414           (gnus-summary-update-secondary-mark article))))))
10415
10416 (defun gnus-summary-mark-article-as-forwarded (article)
10417   "Mark ARTICLE as forwarded and update the summary line.
10418 ARTICLE can also be a list of articles."
10419   (let ((articles (if (listp article) article (list article))))
10420     (dolist (article articles)
10421       (push article gnus-newsgroup-forwarded)
10422       (let ((buffer-read-only nil))
10423         (when (gnus-summary-goto-subject article nil t)
10424           (gnus-summary-update-secondary-mark article))))))
10425
10426 (defun gnus-summary-set-bookmark (article)
10427   "Set a bookmark in current article."
10428   (interactive (list (gnus-summary-article-number)))
10429   (when (or (not (get-buffer gnus-article-buffer))
10430             (not gnus-current-article)
10431             (not gnus-article-current)
10432             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10433     (error "No current article selected"))
10434   ;; Remove old bookmark, if one exists.
10435   (gnus-pull article gnus-newsgroup-bookmarks)
10436   ;; Set the new bookmark, which is on the form
10437   ;; (article-number . line-number-in-body).
10438   (push
10439    (cons article
10440          (with-current-buffer gnus-article-buffer
10441            (count-lines
10442             (min (point)
10443                  (save-excursion
10444                    (article-goto-body)
10445                    (point)))
10446             (point))))
10447    gnus-newsgroup-bookmarks)
10448   (gnus-message 6 "A bookmark has been added to the current article."))
10449
10450 (defun gnus-summary-remove-bookmark (article)
10451   "Remove the bookmark from the current article."
10452   (interactive (list (gnus-summary-article-number)))
10453   ;; Remove old bookmark, if one exists.
10454   (if (not (assq article gnus-newsgroup-bookmarks))
10455       (gnus-message 6 "No bookmark in current article.")
10456     (gnus-pull article gnus-newsgroup-bookmarks)
10457     (gnus-message 6 "Removed bookmark.")))
10458
10459 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10460 (defun gnus-summary-mark-as-dormant (n)
10461   "Mark N articles forward as dormant.
10462 If N is negative, mark backward instead.  The difference between N and
10463 the actual number of articles marked is returned."
10464   (interactive "p")
10465   (gnus-summary-mark-forward n gnus-dormant-mark))
10466
10467 (defun gnus-summary-set-process-mark (article)
10468   "Set the process mark on ARTICLE and update the summary line."
10469   (setq gnus-newsgroup-processable
10470         (cons article
10471               (delq article gnus-newsgroup-processable)))
10472   (when (gnus-summary-goto-subject article)
10473     (gnus-summary-show-thread)
10474     (gnus-summary-goto-subject article)
10475     (gnus-summary-update-secondary-mark article)))
10476
10477 (defun gnus-summary-remove-process-mark (&rest articles)
10478   "Remove the process mark from ARTICLES and update the summary line."
10479   (dolist (article articles)
10480     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10481     (when (gnus-summary-goto-subject article)
10482       (gnus-summary-show-thread)
10483       (gnus-summary-goto-subject article)
10484       (gnus-summary-update-secondary-mark article)))
10485   t)
10486
10487 (defun gnus-summary-set-saved-mark (article)
10488   "Set the process mark on ARTICLE and update the summary line."
10489   (push article gnus-newsgroup-saved)
10490   (when (gnus-summary-goto-subject article)
10491     (gnus-summary-update-secondary-mark article)))
10492
10493 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10494   "Mark N articles as read forwards.
10495 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10496 The difference between N and the actual number of articles marked is
10497 returned.
10498 If NO-EXPIRE, auto-expiry will be inhibited."
10499   (interactive "p")
10500   (gnus-summary-show-thread)
10501   (let ((backward (< n 0))
10502         (gnus-summary-goto-unread
10503          (and gnus-summary-goto-unread
10504               (not (eq gnus-summary-goto-unread 'never))
10505               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10506                                     gnus-ticked-mark gnus-dormant-mark)))))
10507         (n (abs n))
10508         (mark (or mark gnus-del-mark)))
10509     (while (and (> n 0)
10510                 (gnus-summary-mark-article nil mark no-expire)
10511                 (zerop (gnus-summary-next-subject
10512                         (if backward -1 1)
10513                         (and gnus-summary-goto-unread
10514                              (not (eq gnus-summary-goto-unread 'never)))
10515                         t)))
10516       (setq n (1- n)))
10517     (when (/= 0 n)
10518       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10519     (gnus-summary-recenter)
10520     (gnus-summary-position-point)
10521     (gnus-set-mode-line 'summary)
10522     n))
10523
10524 (defun gnus-summary-mark-article-as-read (mark)
10525   "Mark the current article quickly as read with MARK."
10526   (let ((article (gnus-summary-article-number)))
10527     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10528     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10529     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10530     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10531     (push (cons article mark) gnus-newsgroup-reads)
10532     ;; Possibly remove from cache, if that is used.
10533     (when gnus-use-cache
10534       (gnus-cache-enter-remove-article article))
10535     ;; Allow the backend to change the mark.
10536     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10537     ;; Check for auto-expiry.
10538     (when (and gnus-newsgroup-auto-expire
10539                (memq mark gnus-auto-expirable-marks))
10540       (setq mark gnus-expirable-mark)
10541       ;; Let the backend know about the mark change.
10542       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10543       (push article gnus-newsgroup-expirable))
10544     ;; Set the mark in the buffer.
10545     (gnus-summary-update-mark mark 'unread)
10546     t))
10547
10548 (defun gnus-summary-mark-article-as-unread (mark)
10549   "Mark the current article quickly as unread with MARK."
10550   (let* ((article (gnus-summary-article-number))
10551          (old-mark (gnus-summary-article-mark article)))
10552     ;; Allow the backend to change the mark.
10553     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10554     (if (eq mark old-mark)
10555         t
10556       (if (<= article 0)
10557           (progn
10558             (gnus-error 1 "Can't mark negative article numbers")
10559             nil)
10560         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10561         (setq gnus-newsgroup-spam-marked
10562               (delq article gnus-newsgroup-spam-marked))
10563         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10564         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10565         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10566         (cond ((= mark gnus-ticked-mark)
10567                (setq gnus-newsgroup-marked
10568                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10569                                               article)))
10570               ((= mark gnus-spam-mark)
10571                (setq gnus-newsgroup-spam-marked
10572                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10573                                               article)))
10574               ((= mark gnus-dormant-mark)
10575                (setq gnus-newsgroup-dormant
10576                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10577                                               article)))
10578               (t
10579                (setq gnus-newsgroup-unreads
10580                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10581                                               article))))
10582         (gnus-pull article gnus-newsgroup-reads)
10583
10584         ;; See whether the article is to be put in the cache.
10585         (and gnus-use-cache
10586              (vectorp (gnus-summary-article-header article))
10587              (save-excursion
10588                (gnus-cache-possibly-enter-article
10589                 gnus-newsgroup-name article
10590                 (= mark gnus-ticked-mark)
10591                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10592
10593         ;; Fix the mark.
10594         (gnus-summary-update-mark mark 'unread)
10595         t))))
10596
10597 (defun gnus-summary-mark-article (&optional article mark no-expire)
10598   "Mark ARTICLE with MARK.  MARK can be any character.
10599 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10600 `??' (dormant) and `?E' (expirable).
10601 If MARK is nil, then the default character `?r' is used.
10602 If ARTICLE is nil, then the article on the current line will be
10603 marked.
10604 If NO-EXPIRE, auto-expiry will be inhibited."
10605   ;; The mark might be a string.
10606   (when (stringp mark)
10607     (setq mark (aref mark 0)))
10608   ;; If no mark is given, then we check auto-expiring.
10609   (when (null mark)
10610     (setq mark gnus-del-mark))
10611   (when (and (not no-expire)
10612              gnus-newsgroup-auto-expire
10613              (memq mark gnus-auto-expirable-marks))
10614     (setq mark gnus-expirable-mark))
10615   (let ((article (or article (gnus-summary-article-number)))
10616         (old-mark (gnus-summary-article-mark article)))
10617     ;; Allow the backend to change the mark.
10618     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10619     (if (eq mark old-mark)
10620         t
10621       (unless article
10622         (error "No article on current line"))
10623       (if (not (if (or (= mark gnus-unread-mark)
10624                        (= mark gnus-ticked-mark)
10625                        (= mark gnus-spam-mark)
10626                        (= mark gnus-dormant-mark))
10627                    (gnus-mark-article-as-unread article mark)
10628                  (gnus-mark-article-as-read article mark)))
10629           t
10630         ;; See whether the article is to be put in the cache.
10631         (and gnus-use-cache
10632              (not (= mark gnus-canceled-mark))
10633              (vectorp (gnus-summary-article-header article))
10634              (save-excursion
10635                (gnus-cache-possibly-enter-article
10636                 gnus-newsgroup-name article
10637                 (= mark gnus-ticked-mark)
10638                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10639
10640         (when (gnus-summary-goto-subject article nil t)
10641           (let ((buffer-read-only nil))
10642             (gnus-summary-show-thread)
10643             ;; Fix the mark.
10644             (gnus-summary-update-mark mark 'unread)
10645             t))))))
10646
10647 (defun gnus-summary-update-secondary-mark (article)
10648   "Update the secondary (read, process, cache) mark."
10649   (gnus-summary-update-mark
10650    (cond ((memq article gnus-newsgroup-processable)
10651           gnus-process-mark)
10652          ((memq article gnus-newsgroup-cached)
10653           gnus-cached-mark)
10654          ((memq article gnus-newsgroup-replied)
10655           gnus-replied-mark)
10656          ((memq article gnus-newsgroup-forwarded)
10657           gnus-forwarded-mark)
10658          ((memq article gnus-newsgroup-saved)
10659           gnus-saved-mark)
10660          ((memq article gnus-newsgroup-recent)
10661           gnus-recent-mark)
10662          ((memq article gnus-newsgroup-unseen)
10663           gnus-unseen-mark)
10664          (t gnus-no-mark))
10665    'replied)
10666   (when (gnus-visual-p 'summary-highlight 'highlight)
10667     (gnus-run-hooks 'gnus-summary-update-hook))
10668   t)
10669
10670 (defun gnus-summary-update-download-mark (article)
10671   "Update the download mark."
10672   (gnus-summary-update-mark
10673    (cond ((memq article gnus-newsgroup-undownloaded)
10674           gnus-undownloaded-mark)
10675          (gnus-newsgroup-agentized
10676           gnus-downloaded-mark)
10677          (t
10678           gnus-no-mark))
10679    'download)
10680   (gnus-summary-update-line t)
10681   t)
10682
10683 (defun gnus-summary-update-mark (mark type)
10684   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10685         (buffer-read-only nil))
10686     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10687     (when forward
10688       (when (looking-at "\r")
10689         (incf forward))
10690       (when (<= (+ forward (point)) (point-max))
10691         ;; Go to the right position on the line.
10692         (goto-char (+ forward (point)))
10693         ;; Replace the old mark with the new mark.
10694         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10695         ;; Optionally update the marks by some user rule.
10696         (when (eq type 'unread)
10697           (gnus-data-set-mark
10698            (gnus-data-find (gnus-summary-article-number)) mark)
10699           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10700
10701 (defun gnus-mark-article-as-read (article &optional mark)
10702   "Enter ARTICLE in the pertinent lists and remove it from others."
10703   ;; Make the article expirable.
10704   (let ((mark (or mark gnus-del-mark)))
10705     (setq gnus-newsgroup-expirable
10706           (if (= mark gnus-expirable-mark)
10707               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10708             (delq article gnus-newsgroup-expirable)))
10709     ;; Remove from unread and marked lists.
10710     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10711     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10712     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10713     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10714     (push (cons article mark) gnus-newsgroup-reads)
10715     ;; Possibly remove from cache, if that is used.
10716     (when gnus-use-cache
10717       (gnus-cache-enter-remove-article article))
10718     t))
10719
10720 (defun gnus-mark-article-as-unread (article &optional mark)
10721   "Enter ARTICLE in the pertinent lists and remove it from others."
10722   (let ((mark (or mark gnus-ticked-mark)))
10723     (if (<= article 0)
10724         (progn
10725           (gnus-error 1 "Can't mark negative article numbers")
10726           nil)
10727       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10728             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10729             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10730             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10731             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10732
10733       ;; Unsuppress duplicates?
10734       (when gnus-suppress-duplicates
10735         (gnus-dup-unsuppress-article article))
10736
10737       (cond ((= mark gnus-ticked-mark)
10738              (setq gnus-newsgroup-marked
10739                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10740             ((= mark gnus-spam-mark)
10741              (setq gnus-newsgroup-spam-marked
10742                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10743                                             article)))
10744             ((= mark gnus-dormant-mark)
10745              (setq gnus-newsgroup-dormant
10746                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10747             (t
10748              (setq gnus-newsgroup-unreads
10749                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10750       (gnus-pull article gnus-newsgroup-reads)
10751       t)))
10752
10753 (defalias 'gnus-summary-mark-as-unread-forward
10754   'gnus-summary-tick-article-forward)
10755 (make-obsolete 'gnus-summary-mark-as-unread-forward
10756                'gnus-summary-tick-article-forward)
10757 (defun gnus-summary-tick-article-forward (n)
10758   "Tick N articles forwards.
10759 If N is negative, tick backwards instead.
10760 The difference between N and the number of articles ticked is returned."
10761   (interactive "p")
10762   (gnus-summary-mark-forward n gnus-ticked-mark))
10763
10764 (defalias 'gnus-summary-mark-as-unread-backward
10765   'gnus-summary-tick-article-backward)
10766 (make-obsolete 'gnus-summary-mark-as-unread-backward
10767                'gnus-summary-tick-article-backward)
10768 (defun gnus-summary-tick-article-backward (n)
10769   "Tick N articles backwards.
10770 The difference between N and the number of articles ticked is returned."
10771   (interactive "p")
10772   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10773
10774 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10775 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10776 (defun gnus-summary-tick-article (&optional article clear-mark)
10777   "Mark current article as unread.
10778 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10779 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10780   (interactive)
10781   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10782                                        gnus-ticked-mark)))
10783
10784 (defun gnus-summary-mark-as-read-forward (n)
10785   "Mark N articles as read forwards.
10786 If N is negative, mark backwards instead.
10787 The difference between N and the actual number of articles marked is
10788 returned."
10789   (interactive "p")
10790   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10791
10792 (defun gnus-summary-mark-as-read-backward (n)
10793   "Mark the N articles as read backwards.
10794 The difference between N and the actual number of articles marked is
10795 returned."
10796   (interactive "p")
10797   (gnus-summary-mark-forward
10798    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10799
10800 (defun gnus-summary-mark-as-read (&optional article mark)
10801   "Mark current article as read.
10802 ARTICLE specifies the article to be marked as read.
10803 MARK specifies a string to be inserted at the beginning of the line."
10804   (gnus-summary-mark-article article mark))
10805
10806 (defun gnus-summary-clear-mark-forward (n)
10807   "Clear marks from N articles forward.
10808 If N is negative, clear backward instead.
10809 The difference between N and the number of marks cleared is returned."
10810   (interactive "p")
10811   (gnus-summary-mark-forward n gnus-unread-mark))
10812
10813 (defun gnus-summary-clear-mark-backward (n)
10814   "Clear marks from N articles backward.
10815 The difference between N and the number of marks cleared is returned."
10816   (interactive "p")
10817   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10818
10819 (defun gnus-summary-mark-unread-as-read ()
10820   "Intended to be used by `gnus-summary-mark-article-hook'."
10821   (when (memq gnus-current-article gnus-newsgroup-unreads)
10822     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10823
10824 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10825   "Intended to be used by `gnus-summary-mark-article-hook'."
10826   (let ((mark (gnus-summary-article-mark)))
10827     (when (or (gnus-unread-mark-p mark)
10828               (gnus-read-mark-p mark))
10829       (gnus-summary-mark-article gnus-current-article
10830                                  (or new-mark gnus-read-mark)))))
10831
10832 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10833   "Intended to be used by `gnus-summary-mark-article-hook'."
10834   (let ((mark (gnus-summary-article-mark)))
10835     (when (or (gnus-unread-mark-p mark)
10836               (gnus-read-mark-p mark))
10837       (gnus-summary-mark-article (gnus-summary-article-number)
10838                                  (or new-mark gnus-read-mark)))))
10839
10840 (defun gnus-summary-mark-unread-as-ticked ()
10841   "Intended to be used by `gnus-summary-mark-article-hook'."
10842   (when (memq gnus-current-article gnus-newsgroup-unreads)
10843     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10844
10845 (defun gnus-summary-mark-region-as-read (point mark all)
10846   "Mark all unread articles between point and mark as read.
10847 If given a prefix, mark all articles between point and mark as read,
10848 even ticked and dormant ones."
10849   (interactive "r\nP")
10850   (save-excursion
10851     (let (article)
10852       (goto-char point)
10853       (beginning-of-line)
10854       (while (and
10855               (< (point) mark)
10856               (progn
10857                 (when (or all
10858                           (memq (setq article (gnus-summary-article-number))
10859                                 gnus-newsgroup-unreads))
10860                   (gnus-summary-mark-article article gnus-del-mark))
10861                 t)
10862               (gnus-summary-find-next))))))
10863
10864 (defun gnus-summary-mark-below (score mark)
10865   "Mark articles with score less than SCORE with MARK."
10866   (interactive "P\ncMark: ")
10867   (setq score (if score
10868                   (prefix-numeric-value score)
10869                 (or gnus-summary-default-score 0)))
10870   (save-excursion
10871     (set-buffer gnus-summary-buffer)
10872     (goto-char (point-min))
10873     (while
10874         (progn
10875           (and (< (gnus-summary-article-score) score)
10876                (gnus-summary-mark-article nil mark))
10877           (gnus-summary-find-next)))))
10878
10879 (defun gnus-summary-kill-below (&optional score)
10880   "Mark articles with score below SCORE as read."
10881   (interactive "P")
10882   (gnus-summary-mark-below score gnus-killed-mark))
10883
10884 (defun gnus-summary-clear-above (&optional score)
10885   "Clear all marks from articles with score above SCORE."
10886   (interactive "P")
10887   (gnus-summary-mark-above score gnus-unread-mark))
10888
10889 (defun gnus-summary-tick-above (&optional score)
10890   "Tick all articles with score above SCORE."
10891   (interactive "P")
10892   (gnus-summary-mark-above score gnus-ticked-mark))
10893
10894 (defun gnus-summary-mark-above (score mark)
10895   "Mark articles with score over SCORE with MARK."
10896   (interactive "P\ncMark: ")
10897   (setq score (if score
10898                   (prefix-numeric-value score)
10899                 (or gnus-summary-default-score 0)))
10900   (save-excursion
10901     (set-buffer gnus-summary-buffer)
10902     (goto-char (point-min))
10903     (while (and (progn
10904                   (when (> (gnus-summary-article-score) score)
10905                     (gnus-summary-mark-article nil mark))
10906                   t)
10907                 (gnus-summary-find-next)))))
10908
10909 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10910 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10911 (defun gnus-summary-limit-include-expunged (&optional no-error)
10912   "Display all the hidden articles that were expunged for low scores."
10913   (interactive)
10914   (let ((buffer-read-only nil))
10915     (let ((scored gnus-newsgroup-scored)
10916           headers h)
10917       (while scored
10918         (unless (gnus-summary-article-header (caar scored))
10919           (and (setq h (gnus-number-to-header (caar scored)))
10920                (< (cdar scored) gnus-summary-expunge-below)
10921                (push h headers)))
10922         (setq scored (cdr scored)))
10923       (if (not headers)
10924           (when (not no-error)
10925             (error "No expunged articles hidden"))
10926         (goto-char (point-min))
10927         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10928         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10929         (dolist (x headers)
10930           (push (mail-header-number x) gnus-newsgroup-limit))
10931         (gnus-summary-prepare-unthreaded (nreverse headers))
10932         (goto-char (point-min))
10933         (gnus-summary-position-point)
10934         t))))
10935
10936 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10937   "Mark all unread articles in this newsgroup as read.
10938 If prefix argument ALL is non-nil, ticked and dormant articles will
10939 also be marked as read.
10940 If QUIETLY is non-nil, no questions will be asked.
10941
10942 If TO-HERE is non-nil, it should be a point in the buffer.  All
10943 articles before (after, if REVERSE is set) this point will be marked
10944 as read.
10945
10946 Note that this function will only catch up the unread article
10947 in the current summary buffer limitation.
10948
10949 The number of articles marked as read is returned."
10950   (interactive "P")
10951   (prog1
10952       (save-excursion
10953         (when (or quietly
10954                   (not gnus-interactive-catchup) ;Without confirmation?
10955                   gnus-expert-user
10956                   (gnus-y-or-n-p
10957                    (if all
10958                        "Mark absolutely all articles as read? "
10959                      "Mark all unread articles as read? ")))
10960           (if (and not-mark
10961                    (not gnus-newsgroup-adaptive)
10962                    (not gnus-newsgroup-auto-expire)
10963                    (not gnus-suppress-duplicates)
10964                    (or (not gnus-use-cache)
10965                        (eq gnus-use-cache 'passive)))
10966               (progn
10967                 (when all
10968                   (setq gnus-newsgroup-marked nil
10969                         gnus-newsgroup-spam-marked nil
10970                         gnus-newsgroup-dormant nil))
10971                 (setq gnus-newsgroup-unreads
10972                       (gnus-sorted-nunion
10973                        (gnus-sorted-intersection gnus-newsgroup-unreads
10974                                                  gnus-newsgroup-downloadable)
10975                        (gnus-sorted-difference gnus-newsgroup-unfetched
10976                                                gnus-newsgroup-cached))))
10977             ;; We actually mark all articles as canceled, which we
10978             ;; have to do when using auto-expiry or adaptive scoring.
10979             (gnus-summary-show-all-threads)
10980             (if (and to-here reverse)
10981                 (progn
10982                   (goto-char to-here)
10983                   (gnus-summary-mark-current-read-and-unread-as-read
10984                    gnus-catchup-mark)
10985                   (while (gnus-summary-find-next (not all))
10986                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10987               (when (gnus-summary-first-subject (not all))
10988                 (while (and
10989                         (if to-here (< (point) to-here) t)
10990                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10991                         (gnus-summary-find-next (not all))))))
10992             (gnus-set-mode-line 'summary))
10993           t))
10994     (gnus-summary-position-point)))
10995
10996 (defun gnus-summary-catchup-to-here (&optional all)
10997   "Mark all unticked articles before the current one as read.
10998 If ALL is non-nil, also mark ticked and dormant articles as read."
10999   (interactive "P")
11000   (save-excursion
11001     (gnus-save-hidden-threads
11002       (let ((beg (point)))
11003         ;; We check that there are unread articles.
11004         (when (or all (gnus-summary-find-prev))
11005           (gnus-summary-catchup all t beg)))))
11006   (gnus-summary-position-point))
11007
11008 (defun gnus-summary-catchup-from-here (&optional all)
11009   "Mark all unticked articles after (and including) the current one as read.
11010 If ALL is non-nil, also mark ticked and dormant articles as read."
11011   (interactive "P")
11012   (save-excursion
11013     (gnus-save-hidden-threads
11014       (let ((beg (point)))
11015         ;; We check that there are unread articles.
11016         (when (or all (gnus-summary-find-next))
11017           (gnus-summary-catchup all t beg nil t)))))
11018   (gnus-summary-position-point))
11019
11020 (defun gnus-summary-catchup-all (&optional quietly)
11021   "Mark all articles in this newsgroup as read.
11022 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11023 instead, which marks only unread articles as read."
11024   (interactive "P")
11025   (gnus-summary-catchup t quietly))
11026
11027 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11028   "Mark all unread articles in this group as read, then exit.
11029 If prefix argument ALL is non-nil, all articles are marked as read.
11030 If QUIETLY is non-nil, no questions will be asked."
11031   (interactive "P")
11032   (when (gnus-summary-catchup all quietly nil 'fast)
11033     ;; Select next newsgroup or exit.
11034     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11035              (eq gnus-auto-select-next 'quietly))
11036         (gnus-summary-next-group nil)
11037       (gnus-summary-exit))))
11038
11039 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11040   "Mark all articles in this newsgroup as read, and then exit.
11041 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11042 instead, which marks only unread articles as read."
11043   (interactive "P")
11044   (gnus-summary-catchup-and-exit t quietly))
11045
11046 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11047   "Mark all articles in this group as read and select the next group.
11048 If given a prefix, mark all articles, unread as well as ticked, as
11049 read."
11050   (interactive "P")
11051   (save-excursion
11052     (gnus-summary-catchup all))
11053   (gnus-summary-next-group))
11054
11055 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11056   "Mark all articles in this group as read and select the previous group.
11057 If given a prefix, mark all articles, unread as well as ticked, as
11058 read."
11059   (interactive "P")
11060   (save-excursion
11061     (gnus-summary-catchup all))
11062   (gnus-summary-next-group nil nil t))
11063
11064 ;;;
11065 ;;; with article
11066 ;;;
11067
11068 (defmacro gnus-with-article (article &rest forms)
11069   "Select ARTICLE and perform FORMS in the original article buffer.
11070 Then replace the article with the result."
11071   `(progn
11072      ;; We don't want the article to be marked as read.
11073      (let (gnus-mark-article-hook)
11074        (gnus-summary-select-article t t nil ,article))
11075      (set-buffer gnus-original-article-buffer)
11076      ,@forms
11077      (if (not (gnus-check-backend-function
11078                'request-replace-article (car gnus-article-current)))
11079          (gnus-message 5 "Read-only group; not replacing")
11080        (unless (gnus-request-replace-article
11081                 ,article (car gnus-article-current)
11082                 (current-buffer) t)
11083          (error "Couldn't replace article")))
11084      ;; The cache and backlog have to be flushed somewhat.
11085      (when gnus-keep-backlog
11086        (gnus-backlog-remove-article
11087         (car gnus-article-current) (cdr gnus-article-current)))
11088      (when gnus-use-cache
11089        (gnus-cache-update-article
11090         (car gnus-article-current) (cdr gnus-article-current)))))
11091
11092 (put 'gnus-with-article 'lisp-indent-function 1)
11093 (put 'gnus-with-article 'edebug-form-spec '(form body))
11094
11095 ;; Thread-based commands.
11096
11097 (defun gnus-summary-articles-in-thread (&optional article)
11098   "Return a list of all articles in the current thread.
11099 If ARTICLE is non-nil, return all articles in the thread that starts
11100 with that article."
11101   (let* ((article (or article (gnus-summary-article-number)))
11102          (data (gnus-data-find-list article))
11103          (top-level (gnus-data-level (car data)))
11104          (top-subject
11105           (cond ((null gnus-thread-operation-ignore-subject)
11106                  (gnus-simplify-subject-re
11107                   (mail-header-subject (gnus-data-header (car data)))))
11108                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11109                  (gnus-simplify-subject-fuzzy
11110                   (mail-header-subject (gnus-data-header (car data)))))
11111                 (t nil)))
11112          (end-point (save-excursion
11113                       (if (gnus-summary-go-to-next-thread)
11114                           (point) (point-max))))
11115          articles)
11116     (while (and data
11117                 (< (gnus-data-pos (car data)) end-point))
11118       (when (or (not top-subject)
11119                 (string= top-subject
11120                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11121                              (gnus-simplify-subject-fuzzy
11122                               (mail-header-subject
11123                                (gnus-data-header (car data))))
11124                            (gnus-simplify-subject-re
11125                             (mail-header-subject
11126                              (gnus-data-header (car data)))))))
11127         (push (gnus-data-number (car data)) articles))
11128       (unless (and (setq data (cdr data))
11129                    (> (gnus-data-level (car data)) top-level))
11130         (setq data nil)))
11131     ;; Return the list of articles.
11132     (nreverse articles)))
11133
11134 (defun gnus-summary-rethread-current ()
11135   "Rethread the thread the current article is part of."
11136   (interactive)
11137   (let* ((gnus-show-threads t)
11138          (article (gnus-summary-article-number))
11139          (id (mail-header-id (gnus-summary-article-header)))
11140          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11141     (unless id
11142       (error "No article on the current line"))
11143     (gnus-rebuild-thread id)
11144     (gnus-summary-goto-subject article)))
11145
11146 (defun gnus-summary-reparent-thread ()
11147   "Make the current article child of the marked (or previous) article.
11148
11149 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11150 is non-nil or the Subject: of both articles are the same."
11151   (interactive)
11152   (unless (not (gnus-group-read-only-p))
11153     (error "The current newsgroup does not support article editing"))
11154   (unless (<= (length gnus-newsgroup-processable) 1)
11155     (error "No more than one article may be marked"))
11156   (let ((child (gnus-summary-article-number))
11157         ;; First grab the marked article, otherwise one line up.
11158         (parent (if (not (null gnus-newsgroup-processable))
11159                     (car gnus-newsgroup-processable)
11160                   (save-excursion
11161                     (if (eq (forward-line -1) 0)
11162                         (gnus-summary-article-number)
11163                       (error "Beginning of summary buffer"))))))
11164     (gnus-summary-reparent-children parent (list child))))
11165
11166 (defun gnus-summary-reparent-children (parent children)
11167   "Make PARENT the parent of CHILDREN.
11168 When called interactively, PARENT is the current article and CHILDREN
11169 are the process-marked articles."
11170   (interactive
11171    (list (gnus-summary-article-number)
11172          (gnus-summary-work-articles nil)))
11173   (dolist (child children)
11174     (save-window-excursion
11175       (let ((gnus-article-buffer " *reparent*"))
11176         (unless (not (eq parent child))
11177           (error "An article may not be self-referential"))
11178         (let ((message-id (mail-header-id
11179                            (gnus-summary-article-header parent))))
11180           (unless (and message-id (not (equal message-id "")))
11181             (error "No message-id in desired parent"))
11182           (gnus-with-article child
11183             (save-restriction
11184               (goto-char (point-min))
11185               (message-narrow-to-head)
11186               (if (re-search-forward "^References: " nil t)
11187                   (progn
11188                     (re-search-forward "^[^ \t]" nil t)
11189                     (forward-line -1)
11190                     (end-of-line)
11191                     (insert " " message-id))
11192                 (insert "References: " message-id "\n"))))
11193           (set-buffer gnus-summary-buffer)
11194           (gnus-summary-unmark-all-processable)
11195           (gnus-summary-update-article child)
11196           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11197             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11198           (gnus-summary-rethread-current)
11199           (gnus-message 3 "Article %d is now the child of article %d"
11200                         child parent))))))
11201
11202 (defun gnus-summary-toggle-threads (&optional arg)
11203   "Toggle showing conversation threads.
11204 If ARG is positive number, turn showing conversation threads on."
11205   (interactive "P")
11206   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11207     (setq gnus-show-threads
11208           (if (null arg) (not gnus-show-threads)
11209             (> (prefix-numeric-value arg) 0)))
11210     (gnus-summary-prepare)
11211     (gnus-summary-goto-subject current)
11212     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11213     (gnus-summary-position-point)))
11214
11215 (defun gnus-summary-show-all-threads ()
11216   "Show all threads."
11217   (interactive)
11218   (save-excursion
11219     (let ((buffer-read-only nil))
11220       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11221   (gnus-summary-position-point))
11222
11223 (defun gnus-summary-show-thread ()
11224   "Show thread subtrees.
11225 Returns nil if no thread was there to be shown."
11226   (interactive)
11227   (let ((buffer-read-only nil)
11228         (orig (point))
11229         (end (point-at-eol))
11230         ;; Leave point at bol
11231         (beg (progn (beginning-of-line) (point))))
11232     (prog1
11233         ;; Any hidden lines here?
11234         (search-forward "\r" end t)
11235       (subst-char-in-region beg end ?\^M ?\n t)
11236       (goto-char orig)
11237       (gnus-summary-position-point))))
11238
11239 (defun gnus-summary-maybe-hide-threads ()
11240   "If requested, hide the threads that should be hidden."
11241   (when (and gnus-show-threads
11242              gnus-thread-hide-subtree)
11243     (gnus-summary-hide-all-threads
11244      (if (or (consp gnus-thread-hide-subtree)
11245              (functionp gnus-thread-hide-subtree))
11246          (gnus-make-predicate gnus-thread-hide-subtree)
11247        nil))))
11248
11249 ;;; Hiding predicates.
11250
11251 (defun gnus-article-unread-p (header)
11252   (memq (mail-header-number header) gnus-newsgroup-unreads))
11253
11254 (defun gnus-article-unseen-p (header)
11255   (memq (mail-header-number header) gnus-newsgroup-unseen))
11256
11257 (defun gnus-map-articles (predicate articles)
11258   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11259   (apply 'gnus-or (mapcar predicate
11260                           (mapcar (lambda (number)
11261                                     (gnus-summary-article-header number))
11262                                   articles))))
11263
11264 (defun gnus-summary-hide-all-threads (&optional predicate)
11265   "Hide all thread subtrees.
11266 If PREDICATE is supplied, threads that satisfy this predicate
11267 will not be hidden."
11268   (interactive)
11269   (save-excursion
11270     (goto-char (point-min))
11271     (let ((end nil))
11272       (while (not end)
11273         (when (or (not predicate)
11274                   (gnus-map-articles
11275                    predicate (gnus-summary-article-children)))
11276             (gnus-summary-hide-thread))
11277         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11278   (gnus-summary-position-point))
11279
11280 (defun gnus-summary-hide-thread ()
11281   "Hide thread subtrees.
11282 If PREDICATE is supplied, threads that satisfy this predicate
11283 will not be hidden.
11284 Returns nil if no threads were there to be hidden."
11285   (interactive)
11286   (let ((buffer-read-only nil)
11287         (start (point))
11288         (article (gnus-summary-article-number)))
11289     (goto-char start)
11290     ;; Go forward until either the buffer ends or the subthread
11291     ;; ends.
11292     (when (and (not (eobp))
11293                (or (zerop (gnus-summary-next-thread 1 t))
11294                    (goto-char (point-max))))
11295       (prog1
11296           (if (and (> (point) start)
11297                    (search-backward "\n" start t))
11298               (progn
11299                 (subst-char-in-region start (point) ?\n ?\^M)
11300                 (gnus-summary-goto-subject article))
11301             (goto-char start)
11302             nil)))))
11303
11304 (defun gnus-summary-go-to-next-thread (&optional previous)
11305   "Go to the same level (or less) next thread.
11306 If PREVIOUS is non-nil, go to previous thread instead.
11307 Return the article number moved to, or nil if moving was impossible."
11308   (let ((level (gnus-summary-thread-level))
11309         (way (if previous -1 1))
11310         (beg (point)))
11311     (forward-line way)
11312     (while (and (not (eobp))
11313                 (< level (gnus-summary-thread-level)))
11314       (forward-line way))
11315     (if (eobp)
11316         (progn
11317           (goto-char beg)
11318           nil)
11319       (setq beg (point))
11320       (prog1
11321           (gnus-summary-article-number)
11322         (goto-char beg)))))
11323
11324 (defun gnus-summary-next-thread (n &optional silent)
11325   "Go to the same level next N'th thread.
11326 If N is negative, search backward instead.
11327 Returns the difference between N and the number of skips actually
11328 done.
11329
11330 If SILENT, don't output messages."
11331   (interactive "p")
11332   (let ((backward (< n 0))
11333         (n (abs n)))
11334     (while (and (> n 0)
11335                 (gnus-summary-go-to-next-thread backward))
11336       (decf n))
11337     (unless silent
11338       (gnus-summary-position-point))
11339     (when (and (not silent) (/= 0 n))
11340       (gnus-message 7 "No more threads"))
11341     n))
11342
11343 (defun gnus-summary-prev-thread (n)
11344   "Go to the same level previous N'th thread.
11345 Returns the difference between N and the number of skips actually
11346 done."
11347   (interactive "p")
11348   (gnus-summary-next-thread (- n)))
11349
11350 (defun gnus-summary-go-down-thread ()
11351   "Go down one level in the current thread."
11352   (let ((children (gnus-summary-article-children)))
11353     (when children
11354       (gnus-summary-goto-subject (car children)))))
11355
11356 (defun gnus-summary-go-up-thread ()
11357   "Go up one level in the current thread."
11358   (let ((parent (gnus-summary-article-parent)))
11359     (when parent
11360       (gnus-summary-goto-subject parent))))
11361
11362 (defun gnus-summary-down-thread (n)
11363   "Go down thread N steps.
11364 If N is negative, go up instead.
11365 Returns the difference between N and how many steps down that were
11366 taken."
11367   (interactive "p")
11368   (let ((up (< n 0))
11369         (n (abs n)))
11370     (while (and (> n 0)
11371                 (if up (gnus-summary-go-up-thread)
11372                   (gnus-summary-go-down-thread)))
11373       (setq n (1- n)))
11374     (gnus-summary-position-point)
11375     (when (/= 0 n)
11376       (gnus-message 7 "Can't go further"))
11377     n))
11378
11379 (defun gnus-summary-up-thread (n)
11380   "Go up thread N steps.
11381 If N is negative, go down instead.
11382 Returns the difference between N and how many steps down that were
11383 taken."
11384   (interactive "p")
11385   (gnus-summary-down-thread (- n)))
11386
11387 (defun gnus-summary-top-thread ()
11388   "Go to the top of the thread."
11389   (interactive)
11390   (while (gnus-summary-go-up-thread))
11391   (gnus-summary-article-number))
11392
11393 (defun gnus-summary-expire-thread ()
11394   "Mark articles under current thread as expired."
11395   (interactive)
11396   (gnus-summary-kill-thread 0))
11397
11398 (defun gnus-summary-kill-thread (&optional unmark)
11399   "Mark articles under current thread as read.
11400 If the prefix argument is positive, remove any kinds of marks.
11401 If the prefix argument is zero, mark thread as expired.
11402 If the prefix argument is negative, tick articles instead."
11403   (interactive "P")
11404   (when unmark
11405     (setq unmark (prefix-numeric-value unmark)))
11406   (let ((articles (gnus-summary-articles-in-thread))
11407         (hide (or (null unmark) (= unmark 0))))
11408     (save-excursion
11409       ;; Expand the thread.
11410       (gnus-summary-show-thread)
11411       ;; Mark all the articles.
11412       (while articles
11413         (gnus-summary-goto-subject (car articles))
11414         (cond ((null unmark)
11415                (gnus-summary-mark-article-as-read gnus-killed-mark))
11416               ((> unmark 0)
11417                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11418               ((= unmark 0)
11419                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11420               (t
11421                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11422         (setq articles (cdr articles))))
11423     ;; Hide killed subtrees when hide is true.
11424     (and hide
11425          gnus-thread-hide-killed
11426          (gnus-summary-hide-thread))
11427     ;; If hide is t, go to next unread subject.
11428     (when hide
11429       ;; Go to next unread subject.
11430       (gnus-summary-next-subject 1 t)))
11431   (gnus-set-mode-line 'summary))
11432
11433 ;; Summary sorting commands
11434
11435 (defun gnus-summary-sort-by-number (&optional reverse)
11436   "Sort the summary buffer by article number.
11437 Argument REVERSE means reverse order."
11438   (interactive "P")
11439   (gnus-summary-sort 'number reverse))
11440
11441 (defun gnus-summary-sort-by-random (&optional reverse)
11442   "Randomize the order in the summary buffer.
11443 Argument REVERSE means to randomize in reverse order."
11444   (interactive "P")
11445   (gnus-summary-sort 'random reverse))
11446
11447 (defun gnus-summary-sort-by-author (&optional reverse)
11448   "Sort the summary buffer by author name alphabetically.
11449 If `case-fold-search' is non-nil, case of letters is ignored.
11450 Argument REVERSE means reverse order."
11451   (interactive "P")
11452   (gnus-summary-sort 'author reverse))
11453
11454 (defun gnus-summary-sort-by-recipient (&optional reverse)
11455   "Sort the summary buffer by recipient name alphabetically.
11456 If `case-fold-search' is non-nil, case of letters is ignored.
11457 Argument REVERSE means reverse order."
11458   (interactive "P")
11459   (gnus-summary-sort 'recipient reverse))
11460
11461 (defun gnus-summary-sort-by-subject (&optional reverse)
11462   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11463 If `case-fold-search' is non-nil, case of letters is ignored.
11464 Argument REVERSE means reverse order."
11465   (interactive "P")
11466   (gnus-summary-sort 'subject reverse))
11467
11468 (defun gnus-summary-sort-by-date (&optional reverse)
11469   "Sort the summary buffer by date.
11470 Argument REVERSE means reverse order."
11471   (interactive "P")
11472   (gnus-summary-sort 'date reverse))
11473
11474 (defun gnus-summary-sort-by-score (&optional reverse)
11475   "Sort the summary buffer by score.
11476 Argument REVERSE means reverse order."
11477   (interactive "P")
11478   (gnus-summary-sort 'score reverse))
11479
11480 (defun gnus-summary-sort-by-lines (&optional reverse)
11481   "Sort the summary buffer by the number of lines.
11482 Argument REVERSE means reverse order."
11483   (interactive "P")
11484   (gnus-summary-sort 'lines reverse))
11485
11486 (defun gnus-summary-sort-by-chars (&optional reverse)
11487   "Sort the summary buffer by article length.
11488 Argument REVERSE means reverse order."
11489   (interactive "P")
11490   (gnus-summary-sort 'chars reverse))
11491
11492 (defun gnus-summary-sort-by-original (&optional reverse)
11493   "Sort the summary buffer using the default sorting method.
11494 Argument REVERSE means reverse order."
11495   (interactive "P")
11496   (let* ((buffer-read-only)
11497          (gnus-summary-prepare-hook nil))
11498     ;; We do the sorting by regenerating the threads.
11499     (gnus-summary-prepare)
11500     ;; Hide subthreads if needed.
11501     (gnus-summary-maybe-hide-threads)))
11502
11503 (defun gnus-summary-sort (predicate reverse)
11504   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11505   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11506          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11507          (gnus-thread-sort-functions
11508           (if (not reverse)
11509               thread
11510             `(lambda (t1 t2)
11511                (,thread t2 t1))))
11512          (gnus-sort-gathered-threads-function
11513           gnus-thread-sort-functions)
11514          (gnus-article-sort-functions
11515           (if (not reverse)
11516               article
11517             `(lambda (t1 t2)
11518                (,article t2 t1))))
11519          (buffer-read-only)
11520          (gnus-summary-prepare-hook nil))
11521     ;; We do the sorting by regenerating the threads.
11522     (gnus-summary-prepare)
11523     ;; Hide subthreads if needed.
11524     (gnus-summary-maybe-hide-threads)))
11525
11526 ;; Summary saving commands.
11527
11528 (defun gnus-summary-save-article (&optional n not-saved)
11529   "Save the current article using the default saver function.
11530 If N is a positive number, save the N next articles.
11531 If N is a negative number, save the N previous articles.
11532 If N is nil and any articles have been marked with the process mark,
11533 save those articles instead.
11534 The variable `gnus-default-article-saver' specifies the saver function.
11535
11536 If the optional second argument NOT-SAVED is non-nil, articles saved
11537 will not be marked as saved."
11538   (interactive "P")
11539   (require 'gnus-art)
11540   (let* ((articles (gnus-summary-work-articles n))
11541          (save-buffer (save-excursion
11542                         (nnheader-set-temp-buffer " *Gnus Save*")))
11543          (num (length articles))
11544          ;; Whether to save decoded articles or raw articles.
11545          (decode (when gnus-article-save-coding-system
11546                    (get gnus-default-article-saver :decode)))
11547          ;; When saving many articles in a single file, use the other
11548          ;; function to save articles other than the first one.
11549          (saver2 (get gnus-default-article-saver :function))
11550          (gnus-prompt-before-saving (if saver2
11551                                         t
11552                                       gnus-prompt-before-saving))
11553          (gnus-default-article-saver gnus-default-article-saver)
11554          header file)
11555     (dolist (article articles)
11556       (setq header (gnus-summary-article-header article))
11557       (if (not (vectorp header))
11558           ;; This is a pseudo-article.
11559           (if (assq 'name header)
11560               (gnus-copy-file (cdr (assq 'name header)))
11561             (gnus-message 1 "Article %d is unsaveable" article))
11562         ;; This is a real article.
11563         (save-window-excursion
11564           (let ((gnus-display-mime-function (when decode
11565                                               gnus-display-mime-function))
11566                 (gnus-article-prepare-hook (when decode
11567                                              gnus-article-prepare-hook)))
11568             (gnus-summary-select-article t nil nil article)
11569             (gnus-summary-goto-subject article)))
11570         (save-excursion
11571           (set-buffer save-buffer)
11572           (erase-buffer)
11573           (insert-buffer-substring (if decode
11574                                        gnus-article-buffer
11575                                      gnus-original-article-buffer)))
11576         (setq file (gnus-article-save save-buffer file num))
11577         (gnus-summary-remove-process-mark article)
11578         (unless not-saved
11579           (gnus-summary-set-saved-mark article)))
11580       (when saver2
11581         (setq gnus-default-article-saver saver2
11582               saver2 nil)))
11583     (gnus-kill-buffer save-buffer)
11584     (gnus-summary-position-point)
11585     (gnus-set-mode-line 'summary)
11586     n))
11587
11588 (defun gnus-summary-pipe-output (&optional arg headers)
11589   "Pipe the current article to a subprocess.
11590 If N is a positive number, pipe the N next articles.
11591 If N is a negative number, pipe the N previous articles.
11592 If N is nil and any articles have been marked with the process mark,
11593 pipe those articles instead.
11594 If HEADERS (the symbolic prefix), include the headers, too."
11595   (interactive (gnus-interactive "P\ny"))
11596   (require 'gnus-art)
11597   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11598         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11599     (gnus-summary-save-article arg t))
11600   (let ((buffer (get-buffer "*Shell Command Output*")))
11601     (when (and buffer
11602                (not (zerop (buffer-size buffer))))
11603       (gnus-configure-windows 'pipe))))
11604
11605 (defun gnus-summary-save-article-mail (&optional arg)
11606   "Append the current article to a Unix mail box file.
11607 If N is a positive number, save the N next articles.
11608 If N is a negative number, save the N previous articles.
11609 If N is nil and any articles have been marked with the process mark,
11610 save those articles instead."
11611   (interactive "P")
11612   (require 'gnus-art)
11613   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11614     (gnus-summary-save-article arg)))
11615
11616 (defun gnus-summary-save-article-rmail (&optional arg)
11617   "Append the current article to an rmail file.
11618 If N is a positive number, save the N next articles.
11619 If N is a negative number, save the N previous articles.
11620 If N is nil and any articles have been marked with the process mark,
11621 save those articles instead."
11622   (interactive "P")
11623   (require 'gnus-art)
11624   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11625     (gnus-summary-save-article arg)))
11626
11627 (defun gnus-summary-save-article-file (&optional arg)
11628   "Append the current article to a file.
11629 If N is a positive number, save the N next articles.
11630 If N is a negative number, save the N previous articles.
11631 If N is nil and any articles have been marked with the process mark,
11632 save those articles instead."
11633   (interactive "P")
11634   (require 'gnus-art)
11635   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11636     (gnus-summary-save-article arg)))
11637
11638 (defun gnus-summary-write-article-file (&optional arg)
11639   "Write the current article to a file, deleting the previous file.
11640 If N is a positive number, save the N next articles.
11641 If N is a negative number, save the N previous articles.
11642 If N is nil and any articles have been marked with the process mark,
11643 save those articles instead."
11644   (interactive "P")
11645   (require 'gnus-art)
11646   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11647     (gnus-summary-save-article arg)))
11648
11649 (defun gnus-summary-save-article-body-file (&optional arg)
11650   "Append the current article body to a file.
11651 If N is a positive number, save the N next articles.
11652 If N is a negative number, save the N previous articles.
11653 If N is nil and any articles have been marked with the process mark,
11654 save those articles instead."
11655   (interactive "P")
11656   (require 'gnus-art)
11657   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11658     (gnus-summary-save-article arg)))
11659
11660 (defun gnus-summary-write-article-body-file (&optional arg)
11661   "Write the current article body to a file, deleting the previous file.
11662 If N is a positive number, save the N next articles.
11663 If N is a negative number, save the N previous articles.
11664 If N is nil and any articles have been marked with the process mark,
11665 save those articles instead."
11666   (interactive "P")
11667   (require 'gnus-art)
11668   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11669     (gnus-summary-save-article arg)))
11670
11671 (defun gnus-summary-muttprint (&optional arg)
11672   "Print the current article using Muttprint.
11673 If N is a positive number, save the N next articles.
11674 If N is a negative number, save the N previous articles.
11675 If N is nil and any articles have been marked with the process mark,
11676 save those articles instead."
11677   (interactive "P")
11678   (require 'gnus-art)
11679   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11680     (gnus-summary-save-article arg t)))
11681
11682 (defun gnus-summary-pipe-message (program)
11683   "Pipe the current article through PROGRAM."
11684   (interactive "sProgram: ")
11685   (gnus-summary-select-article)
11686   (let ((mail-header-separator ""))
11687     (gnus-eval-in-buffer-window gnus-article-buffer
11688       (save-restriction
11689         (widen)
11690         (let ((start (window-start))
11691               buffer-read-only)
11692           (message-pipe-buffer-body program)
11693           (set-window-start (get-buffer-window (current-buffer)) start))))))
11694
11695 (defun gnus-get-split-value (methods)
11696   "Return a value based on the split METHODS."
11697   (let (split-name method result match)
11698     (when methods
11699       (save-excursion
11700         (set-buffer gnus-original-article-buffer)
11701         (save-restriction
11702           (nnheader-narrow-to-headers)
11703           (while (and methods (not split-name))
11704             (goto-char (point-min))
11705             (setq method (pop methods))
11706             (setq match (car method))
11707             (when (cond
11708                    ((stringp match)
11709                     ;; Regular expression.
11710                     (ignore-errors
11711                       (re-search-forward match nil t)))
11712                    ((functionp match)
11713                     ;; Function.
11714                     (save-restriction
11715                       (widen)
11716                       (setq result (funcall match gnus-newsgroup-name))))
11717                    ((consp match)
11718                     ;; Form.
11719                     (save-restriction
11720                       (widen)
11721                       (setq result (eval match)))))
11722               (setq split-name (cdr method))
11723               (cond ((stringp result)
11724                      (push (expand-file-name
11725                             result gnus-article-save-directory)
11726                            split-name))
11727                     ((consp result)
11728                      (setq split-name (append result split-name)))))))))
11729     (nreverse split-name)))
11730
11731 (defun gnus-valid-move-group-p (group)
11732   (and (boundp group)
11733        (symbol-name group)
11734        (symbol-value group)
11735        (gnus-get-function (gnus-find-method-for-group
11736                            (symbol-name group)) 'request-accept-article t)))
11737
11738 (defun gnus-read-move-group-name (prompt default articles prefix)
11739   "Read a group name."
11740   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11741          (minibuffer-confirm-incomplete nil) ; XEmacs
11742          (prom
11743           (format "%s %s to"
11744                   prompt
11745                   (if (> (length articles) 1)
11746                       (format "these %d articles" (length articles))
11747                     "this article")))
11748          (to-newsgroup
11749           (let (active group)
11750             (when (or (null split-name) (= 1 (length split-name)))
11751               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11752               (mapatoms (lambda (symbol)
11753                           (setq group (symbol-name symbol))
11754                           (when (string-match "[^\000-\177]" group)
11755                             (setq group (gnus-group-decoded-name group)))
11756                           (set (intern group active) group))
11757                         gnus-active-hashtb))
11758             (cond
11759              ((null split-name)
11760               (gnus-completing-read-with-default
11761                default prom active 'gnus-valid-move-group-p nil prefix
11762                'gnus-group-history))
11763              ((= 1 (length split-name))
11764               (gnus-completing-read-with-default
11765                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11766                'gnus-group-history))
11767              (t
11768               (gnus-completing-read-with-default
11769                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11770                'gnus-group-history)))))
11771          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11772          encoded)
11773     (when to-newsgroup
11774       (if (or (string= to-newsgroup "")
11775               (string= to-newsgroup prefix))
11776           (setq to-newsgroup default))
11777       (unless to-newsgroup
11778         (error "No group name entered"))
11779       (setq encoded (mm-encode-coding-string
11780                      to-newsgroup
11781                      (gnus-group-name-charset to-method to-newsgroup)))
11782       (or (gnus-active encoded)
11783           (gnus-activate-group encoded nil nil to-method)
11784           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11785                                      to-newsgroup))
11786               (or (and (gnus-request-create-group encoded to-method)
11787                        (gnus-activate-group encoded nil nil to-method)
11788                        (gnus-subscribe-group encoded))
11789                   (error "Couldn't create group %s" to-newsgroup)))
11790           (error "No such group: %s" to-newsgroup))
11791       encoded)))
11792
11793 (defvar gnus-summary-save-parts-counter)
11794
11795 (defun gnus-summary-save-parts (type dir n &optional reverse)
11796   "Save parts matching TYPE to DIR.
11797 If REVERSE, save parts that do not match TYPE."
11798   (interactive
11799    (list (read-string "Save parts of type: "
11800                       (or (car gnus-summary-save-parts-type-history)
11801                           gnus-summary-save-parts-default-mime)
11802                       'gnus-summary-save-parts-type-history)
11803          (setq gnus-summary-save-parts-last-directory
11804                (read-file-name "Save to directory: "
11805                                gnus-summary-save-parts-last-directory
11806                                nil t))
11807          current-prefix-arg))
11808   (gnus-summary-iterate n
11809     (let ((gnus-display-mime-function nil)
11810           (gnus-inhibit-treatment t))
11811       (gnus-summary-select-article))
11812     (save-excursion
11813       (set-buffer gnus-article-buffer)
11814       (let ((handles (or gnus-article-mime-handles
11815                          (mm-dissect-buffer nil gnus-article-loose-mime)
11816                          (and gnus-article-emulate-mime
11817                               (mm-uu-dissect))))
11818             (gnus-summary-save-parts-counter 1))
11819         (when handles
11820           (gnus-summary-save-parts-1 type dir handles reverse)
11821           (unless gnus-article-mime-handles ;; Don't destroy this case.
11822             (mm-destroy-parts handles)))))))
11823
11824 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11825   (if (stringp (car handle))
11826       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11827               (cdr handle))
11828     (when (if reverse
11829               (not (string-match type (mm-handle-media-type handle)))
11830             (string-match type (mm-handle-media-type handle)))
11831       (let ((file (expand-file-name
11832                    (gnus-map-function
11833                     mm-file-name-rewrite-functions
11834                     (file-name-nondirectory
11835                      (or
11836                       (mail-content-type-get
11837                        (mm-handle-disposition handle) 'filename)
11838                       (mail-content-type-get
11839                        (mm-handle-type handle) 'name)
11840                       (format "%s.%d.%d" gnus-newsgroup-name
11841                               (cdr gnus-article-current)
11842                               gnus-summary-save-parts-counter))))
11843                    dir)))
11844         (incf gnus-summary-save-parts-counter)
11845         (unless (file-exists-p file)
11846           (mm-save-part-to-file handle file))))))
11847
11848 ;; Summary extract commands
11849
11850 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11851   (let ((buffer-read-only nil)
11852         (article (gnus-summary-article-number))
11853         after-article b e)
11854     (unless (gnus-summary-goto-subject article)
11855       (error "No such article: %d" article))
11856     (gnus-summary-position-point)
11857     ;; If all commands are to be bunched up on one line, we collect
11858     ;; them here.
11859     (unless gnus-view-pseudos-separately
11860       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11861             files action)
11862         (while ps
11863           (setq action (cdr (assq 'action (car ps))))
11864           (setq files (list (cdr (assq 'name (car ps)))))
11865           (while (and ps (cdr ps)
11866                       (string= (or action "1")
11867                                (or (cdr (assq 'action (cadr ps))) "2")))
11868             (push (cdr (assq 'name (cadr ps))) files)
11869             (setcdr ps (cddr ps)))
11870           (when files
11871             (when (not (string-match "%s" action))
11872               (push " " files))
11873             (push " " files)
11874             (when (assq 'execute (car ps))
11875               (setcdr (assq 'execute (car ps))
11876                       (funcall (if (string-match "%s" action)
11877                                    'format 'concat)
11878                                action
11879                                (mapconcat
11880                                 (lambda (f)
11881                                   (if (equal f " ")
11882                                       f
11883                                     (shell-quote-argument f)))
11884                                 files " ")))))
11885           (setq ps (cdr ps)))))
11886     (if (and gnus-view-pseudos (not not-view))
11887         (while pslist
11888           (when (assq 'execute (car pslist))
11889             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11890                                   (eq gnus-view-pseudos 'not-confirm)))
11891           (setq pslist (cdr pslist)))
11892       (save-excursion
11893         (while pslist
11894           (setq after-article (or (cdr (assq 'article (car pslist)))
11895                                   (gnus-summary-article-number)))
11896           (gnus-summary-goto-subject after-article)
11897           (forward-line 1)
11898           (setq b (point))
11899           (insert "    " (file-name-nondirectory
11900                           (cdr (assq 'name (car pslist))))
11901                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11902           (setq e (point))
11903           (forward-line -1)             ; back to `b'
11904           (gnus-add-text-properties
11905            b (1- e) (list 'gnus-number gnus-reffed-article-number
11906                           gnus-mouse-face-prop gnus-mouse-face))
11907           (gnus-data-enter
11908            after-article gnus-reffed-article-number
11909            gnus-unread-mark b (car pslist) 0 (- e b))
11910           (setq gnus-newsgroup-unreads
11911                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11912                                          gnus-reffed-article-number))
11913           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11914           (setq pslist (cdr pslist)))))))
11915
11916 (defun gnus-pseudos< (p1 p2)
11917   (let ((c1 (cdr (assq 'action p1)))
11918         (c2 (cdr (assq 'action p2))))
11919     (and c1 c2 (string< c1 c2))))
11920
11921 (defun gnus-request-pseudo-article (props)
11922   (cond ((assq 'execute props)
11923          (gnus-execute-command (cdr (assq 'execute props)))))
11924   (let ((gnus-current-article (gnus-summary-article-number)))
11925     (gnus-run-hooks 'gnus-mark-article-hook)))
11926
11927 (defun gnus-execute-command (command &optional automatic)
11928   (save-excursion
11929     (gnus-article-setup-buffer)
11930     (set-buffer gnus-article-buffer)
11931     (setq buffer-read-only nil)
11932     (let ((command (if automatic command
11933                      (read-string "Command: " (cons command 0)))))
11934       (erase-buffer)
11935       (insert "$ " command "\n\n")
11936       (if gnus-view-pseudo-asynchronously
11937           (start-process "gnus-execute" (current-buffer) shell-file-name
11938                          shell-command-switch command)
11939         (call-process shell-file-name nil t nil
11940                       shell-command-switch command)))))
11941
11942 ;; Summary kill commands.
11943
11944 (defun gnus-summary-edit-global-kill (article)
11945   "Edit the \"global\" kill file."
11946   (interactive (list (gnus-summary-article-number)))
11947   (gnus-group-edit-global-kill article))
11948
11949 (defun gnus-summary-edit-local-kill ()
11950   "Edit a local kill file applied to the current newsgroup."
11951   (interactive)
11952   (setq gnus-current-headers (gnus-summary-article-header))
11953   (gnus-group-edit-local-kill
11954    (gnus-summary-article-number) gnus-newsgroup-name))
11955
11956 ;;; Header reading.
11957
11958 (defun gnus-read-header (id &optional header)
11959   "Read the headers of article ID and enter them into the Gnus system."
11960   (let ((group gnus-newsgroup-name)
11961         (gnus-override-method
11962          (or
11963           gnus-override-method
11964           (and (gnus-news-group-p gnus-newsgroup-name)
11965                (car (gnus-refer-article-methods)))))
11966         where)
11967     ;; First we check to see whether the header in question is already
11968     ;; fetched.
11969     (if (stringp id)
11970         ;; This is a Message-ID.
11971         (setq header (or header (gnus-id-to-header id)))
11972       ;; This is an article number.
11973       (setq header (or header (gnus-summary-article-header id))))
11974     (if (and header
11975              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11976         ;; We have found the header.
11977         header
11978       ;; We have to really fetch the header to this article.
11979       (save-excursion
11980         (set-buffer nntp-server-buffer)
11981         (when (setq where (gnus-request-head id group))
11982           (nnheader-fold-continuation-lines)
11983           (goto-char (point-max))
11984           (insert ".\n")
11985           (goto-char (point-min))
11986           (insert "211 ")
11987           (princ (cond
11988                   ((numberp id) id)
11989                   ((cdr where) (cdr where))
11990                   (header (mail-header-number header))
11991                   (t gnus-reffed-article-number))
11992                  (current-buffer))
11993           (insert " Article retrieved.\n"))
11994         (if (or (not where)
11995                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11996             ()                          ; Malformed head.
11997           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11998             (when (and (stringp id)
11999                        (or
12000                         (not (string= (gnus-group-real-name group)
12001                                       (car where)))
12002                         (not (gnus-server-equal gnus-override-method
12003                                                 (gnus-group-method group)))))
12004               ;; If we fetched by Message-ID and the article came from
12005               ;; a different group (or server), we fudge some bogus
12006               ;; article numbers for this article.
12007               (mail-header-set-number header gnus-reffed-article-number))
12008             (save-excursion
12009               (set-buffer gnus-summary-buffer)
12010               (decf gnus-reffed-article-number)
12011               (gnus-remove-header (mail-header-number header))
12012               (push header gnus-newsgroup-headers)
12013               (setq gnus-current-headers header)
12014               (push (mail-header-number header) gnus-newsgroup-limit)))
12015           header)))))
12016
12017 (defun gnus-remove-header (number)
12018   "Remove header NUMBER from `gnus-newsgroup-headers'."
12019   (if (and gnus-newsgroup-headers
12020            (= number (mail-header-number (car gnus-newsgroup-headers))))
12021       (pop gnus-newsgroup-headers)
12022     (let ((headers gnus-newsgroup-headers))
12023       (while (and (cdr headers)
12024                   (not (= number (mail-header-number (cadr headers)))))
12025         (pop headers))
12026       (when (cdr headers)
12027         (setcdr headers (cddr headers))))))
12028
12029 ;;;
12030 ;;; summary highlights
12031 ;;;
12032
12033 (defun gnus-highlight-selected-summary ()
12034   "Highlight selected article in summary buffer."
12035   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12036   (when gnus-summary-selected-face
12037     (save-excursion
12038       (let* ((beg (point-at-bol))
12039              (end (point-at-eol))
12040              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12041              (from (if (get-text-property beg gnus-mouse-face-prop)
12042                        beg
12043                      (or (next-single-property-change
12044                           beg gnus-mouse-face-prop nil end)
12045                          beg)))
12046              (to
12047               (if (= from end)
12048                   (- from 2)
12049                 (or (next-single-property-change
12050                      from gnus-mouse-face-prop nil end)
12051                     end))))
12052         ;; If no mouse-face prop on line we will have to = from = end,
12053         ;; so we highlight the entire line instead.
12054         (when (= (+ to 2) from)
12055           (setq from beg)
12056           (setq to end))
12057         (if gnus-newsgroup-selected-overlay
12058             ;; Move old overlay.
12059             (gnus-move-overlay
12060              gnus-newsgroup-selected-overlay from to (current-buffer))
12061           ;; Create new overlay.
12062           (gnus-overlay-put
12063            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12064            'face gnus-summary-selected-face))))))
12065
12066 (defvar gnus-summary-highlight-line-cached nil)
12067 (defvar gnus-summary-highlight-line-trigger nil)
12068
12069 (defun gnus-summary-highlight-line-0 ()
12070   (if (and (eq gnus-summary-highlight-line-trigger
12071                gnus-summary-highlight)
12072            gnus-summary-highlight-line-cached)
12073       gnus-summary-highlight-line-cached
12074     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12075           gnus-summary-highlight-line-cached
12076           (let* ((cond (list 'cond))
12077                  (c cond)
12078                  (list gnus-summary-highlight))
12079             (while list
12080               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12081                               nil))
12082               (setq c (cdr c)
12083                     list (cdr list)))
12084             (gnus-byte-compile (list 'lambda nil cond))))))
12085
12086 (defun gnus-summary-highlight-line ()
12087   "Highlight current line according to `gnus-summary-highlight'."
12088   (let* ((beg (point-at-bol))
12089          (article (or (gnus-summary-article-number) gnus-current-article))
12090          (score (or (cdr (assq article
12091                                gnus-newsgroup-scored))
12092                     gnus-summary-default-score 0))
12093          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12094          (inhibit-read-only t)
12095          (default gnus-summary-default-score)
12096          (default-high gnus-summary-default-high-score)
12097          (default-low gnus-summary-default-low-score)
12098          (uncached (and gnus-summary-use-undownloaded-faces
12099                         (memq article gnus-newsgroup-undownloaded)
12100                         (not (memq article gnus-newsgroup-cached)))))
12101     (let ((face (funcall (gnus-summary-highlight-line-0))))
12102       (unless (eq face (get-text-property beg 'face))
12103         (gnus-put-text-property-excluding-characters-with-faces
12104          beg (point-at-eol) 'face
12105          (setq face (if (boundp face) (symbol-value face) face)))
12106         (when gnus-summary-highlight-line-function
12107           (funcall gnus-summary-highlight-line-function article face))))))
12108
12109 (defun gnus-update-read-articles (group unread &optional compute)
12110   "Update the list of read articles in GROUP.
12111 UNREAD is a sorted list."
12112   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12113         (info (gnus-get-info group))
12114         (prev 1)
12115         read)
12116     (if (or (not info) (not active))
12117         ;; There is no info on this group if it was, in fact,
12118         ;; killed.  Gnus stores no information on killed groups, so
12119         ;; there's nothing to be done.
12120         ;; One could store the information somewhere temporarily,
12121         ;; perhaps...  Hmmm...
12122         ()
12123       ;; Remove any negative articles numbers.
12124       (while (and unread (< (car unread) 0))
12125         (setq unread (cdr unread)))
12126       ;; Remove any expired article numbers
12127       (while (and unread (< (car unread) (car active)))
12128         (setq unread (cdr unread)))
12129       ;; Compute the ranges of read articles by looking at the list of
12130       ;; unread articles.
12131       (while unread
12132         (when (/= (car unread) prev)
12133           (push (if (= prev (1- (car unread))) prev
12134                   (cons prev (1- (car unread))))
12135                 read))
12136         (setq prev (1+ (car unread)))
12137         (setq unread (cdr unread)))
12138       (when (<= prev (cdr active))
12139         (push (cons prev (cdr active)) read))
12140       (setq read (if (> (length read) 1) (nreverse read) read))
12141       (if compute
12142           read
12143         (save-excursion
12144           (let (setmarkundo)
12145             ;; Propagate the read marks to the backend.
12146             (when (gnus-check-backend-function 'request-set-mark group)
12147               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12148                     (add (gnus-remove-from-range read (gnus-info-read info))))
12149                 (when (or add del)
12150                   (unless (gnus-check-group group)
12151                     (error "Can't open server for %s" group))
12152                   (gnus-request-set-mark
12153                    group (delq nil (list (if add (list add 'add '(read)))
12154                                          (if del (list del 'del '(read))))))
12155                   (setq setmarkundo
12156                         `(gnus-request-set-mark
12157                           ,group
12158                           ',(delq nil (list
12159                                        (if del (list del 'add '(read)))
12160                                        (if add (list add 'del '(read))))))))))
12161             (set-buffer gnus-group-buffer)
12162             (gnus-undo-register
12163               `(progn
12164                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12165                  (gnus-info-set-read ',info ',(gnus-info-read info))
12166                  (gnus-get-unread-articles-in-group ',info
12167                                                     (gnus-active ,group))
12168                  (gnus-group-update-group ,group t)
12169                  ,setmarkundo))))
12170         ;; Enter this list into the group info.
12171         (gnus-info-set-read info read)
12172         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12173         (gnus-get-unread-articles-in-group info (gnus-active group))
12174         t))))
12175
12176 (defun gnus-offer-save-summaries ()
12177   "Offer to save all active summary buffers."
12178   (let (buffers)
12179     ;; Go through all buffers and find all summaries.
12180     (dolist (buffer (buffer-list))
12181       (when (and (setq buffer (buffer-name buffer))
12182                  (string-match "Summary" buffer)
12183                  (with-current-buffer buffer
12184                    ;; We check that this is, indeed, a summary buffer.
12185                    (and (eq major-mode 'gnus-summary-mode)
12186                         ;; Also make sure this isn't bogus.
12187                         gnus-newsgroup-prepared
12188                         ;; Also make sure that this isn't a
12189                         ;; dead summary buffer.
12190                         (not gnus-dead-summary-mode))))
12191         (push buffer buffers)))
12192     ;; Go through all these summary buffers and offer to save them.
12193     (when buffers
12194       (save-excursion
12195         (map-y-or-n-p
12196          "Update summary buffer %s? "
12197          (lambda (buf)
12198            (switch-to-buffer buf)
12199            (gnus-summary-exit))
12200          buffers)))))
12201
12202 (defun gnus-summary-setup-default-charset ()
12203   "Setup newsgroup default charset."
12204   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12205       (setq gnus-newsgroup-charset nil)
12206     (let* ((ignored-charsets
12207             (or gnus-newsgroup-ephemeral-ignored-charsets
12208                 (append
12209                  (and gnus-newsgroup-name
12210                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12211                  gnus-newsgroup-ignored-charsets))))
12212       (setq gnus-newsgroup-charset
12213             (or gnus-newsgroup-ephemeral-charset
12214                 (and gnus-newsgroup-name
12215                      (gnus-parameter-charset gnus-newsgroup-name))
12216                 gnus-default-charset))
12217       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12218            ignored-charsets))))
12219
12220 ;;;
12221 ;;; Mime Commands
12222 ;;;
12223
12224 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12225   "Display the current article buffer fully MIME-buttonized.
12226 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12227 treated as multipart/mixed."
12228   (interactive "P")
12229   (require 'gnus-art)
12230   (let ((gnus-unbuttonized-mime-types nil)
12231         (gnus-mime-display-multipart-as-mixed show-all-parts))
12232     (gnus-summary-show-article)))
12233
12234 (defun gnus-summary-repair-multipart (article)
12235   "Add a Content-Type header to a multipart article without one."
12236   (interactive (list (gnus-summary-article-number)))
12237   (gnus-with-article article
12238     (message-narrow-to-head)
12239     (message-remove-header "Mime-Version")
12240     (goto-char (point-max))
12241     (insert "Mime-Version: 1.0\n")
12242     (widen)
12243     (when (search-forward "\n--" nil t)
12244       (let ((separator (buffer-substring (point) (point-at-eol))))
12245         (message-narrow-to-head)
12246         (message-remove-header "Content-Type")
12247         (goto-char (point-max))
12248         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12249                         separator))
12250         (widen))))
12251   (let (gnus-mark-article-hook)
12252     (gnus-summary-select-article t t nil article)))
12253
12254 (defun gnus-summary-toggle-display-buttonized ()
12255   "Toggle the buttonizing of the article buffer."
12256   (interactive)
12257   (require 'gnus-art)
12258   (if (setq gnus-inhibit-mime-unbuttonizing
12259             (not gnus-inhibit-mime-unbuttonizing))
12260       (let ((gnus-unbuttonized-mime-types nil))
12261         (gnus-summary-show-article))
12262     (gnus-summary-show-article)))
12263
12264 ;;;
12265 ;;; Generic summary marking commands
12266 ;;;
12267
12268 (defvar gnus-summary-marking-alist
12269   '((read gnus-del-mark "d")
12270     (unread gnus-unread-mark "u")
12271     (ticked gnus-ticked-mark "!")
12272     (dormant gnus-dormant-mark "?")
12273     (expirable gnus-expirable-mark "e"))
12274   "An alist of names/marks/keystrokes.")
12275
12276 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12277 (defvar gnus-summary-mark-map)
12278
12279 (defun gnus-summary-make-all-marking-commands ()
12280   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12281   (dolist (elem gnus-summary-marking-alist)
12282     (apply 'gnus-summary-make-marking-command elem)))
12283
12284 (defun gnus-summary-make-marking-command (name mark keystroke)
12285   (let ((map (make-sparse-keymap)))
12286     (define-key gnus-summary-generic-mark-map keystroke map)
12287     (dolist (lway `((next "next" next nil "n")
12288                     (next-unread "next unread" next t "N")
12289                     (prev "previous" prev nil "p")
12290                     (prev-unread "previous unread" prev t "P")
12291                     (nomove "" nil nil ,keystroke)))
12292       (let ((func (gnus-summary-make-marking-command-1
12293                    mark (car lway) lway name)))
12294         (setq func (eval func))
12295         (define-key map (nth 4 lway) func)))))
12296
12297 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12298   `(defun ,(intern
12299             (format "gnus-summary-put-mark-as-%s%s"
12300                     name (if (eq way 'nomove)
12301                              ""
12302                            (concat "-" (symbol-name way)))))
12303      (n)
12304      ,(format
12305        "Mark the current article as %s%s.
12306 If N, the prefix, then repeat N times.
12307 If N is negative, move in reverse order.
12308 The difference between N and the actual number of articles marked is
12309 returned."
12310        name (cadr lway))
12311      (interactive "p")
12312      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12313
12314 (defun gnus-summary-generic-mark (n mark move unread)
12315   "Mark N articles with MARK."
12316   (unless (eq major-mode 'gnus-summary-mode)
12317     (error "This command can only be used in the summary buffer"))
12318   (gnus-summary-show-thread)
12319   (let ((nummove
12320          (cond
12321           ((eq move 'next) 1)
12322           ((eq move 'prev) -1)
12323           (t 0))))
12324     (if (zerop nummove)
12325         (setq n 1)
12326       (when (< n 0)
12327         (setq n (abs n)
12328               nummove (* -1 nummove))))
12329     (while (and (> n 0)
12330                 (gnus-summary-mark-article nil mark)
12331                 (zerop (gnus-summary-next-subject nummove unread t)))
12332       (setq n (1- n)))
12333     (when (/= 0 n)
12334       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12335     (gnus-summary-recenter)
12336     (gnus-summary-position-point)
12337     (gnus-set-mode-line 'summary)
12338     n))
12339
12340 (defun gnus-summary-insert-articles (articles)
12341   (when (setq articles
12342               (gnus-sorted-difference articles
12343                                       (mapcar (lambda (h)
12344                                                 (mail-header-number h))
12345                                               gnus-newsgroup-headers)))
12346     (setq gnus-newsgroup-headers
12347           (gnus-merge 'list
12348                       gnus-newsgroup-headers
12349                       (gnus-fetch-headers articles)
12350                       'gnus-article-sort-by-number))
12351     ;; Suppress duplicates?
12352     (when gnus-suppress-duplicates
12353       (gnus-dup-suppress-articles))
12354
12355     (if (and gnus-fetch-old-headers
12356              (eq gnus-headers-retrieved-by 'nov))
12357         ;; We might want to build some more threads first.
12358         (if (eq gnus-fetch-old-headers 'invisible)
12359             (gnus-build-all-threads)
12360           (gnus-build-old-threads))
12361       ;; Mark the inserted articles that are unread as unread.
12362       (setq gnus-newsgroup-unreads
12363             (gnus-sorted-nunion
12364              gnus-newsgroup-unreads
12365              (gnus-sorted-nintersection
12366               (gnus-list-of-unread-articles gnus-newsgroup-name)
12367               articles)))
12368       ;; Mark the inserted articles as selected so that the information
12369       ;; of the marks having been changed by a user may be updated when
12370       ;; exiting this group.  See `gnus-summary-update-info'.
12371       (dolist (art articles)
12372         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12373     ;; Let the Gnus agent mark articles as read.
12374     (when gnus-agent
12375       (gnus-agent-get-undownloaded-list))
12376     ;; Remove list identifiers from subject
12377     (when gnus-list-identifiers
12378       (gnus-summary-remove-list-identifiers))
12379     ;; First and last article in this newsgroup.
12380     (when gnus-newsgroup-headers
12381       (setq gnus-newsgroup-begin
12382             (mail-header-number (car gnus-newsgroup-headers))
12383             gnus-newsgroup-end
12384             (mail-header-number
12385              (gnus-last-element gnus-newsgroup-headers))))
12386     (when gnus-use-scoring
12387       (gnus-possibly-score-headers))))
12388
12389 (defun gnus-summary-insert-old-articles (&optional all)
12390   "Insert all old articles in this group.
12391 If ALL is non-nil, already read articles become readable.
12392 If ALL is a number, fetch this number of articles."
12393   (interactive "P")
12394   (prog1
12395       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12396             older len)
12397         (setq older
12398               ;; Some nntp servers lie about their active range.  When
12399               ;; this happens, the active range can be in the millions.
12400               ;; Use a compressed range to avoid creating a huge list.
12401               (gnus-range-difference (list gnus-newsgroup-active) old))
12402         (setq len (gnus-range-length older))
12403         (cond
12404          ((null older) nil)
12405          ((numberp all)
12406           (if (< all len)
12407               (let ((older-range (nreverse older)))
12408                 (setq older nil)
12409
12410                 (while (> all 0)
12411                   (let* ((r (pop older-range))
12412                          (min (if (numberp r) r (car r)))
12413                          (max (if (numberp r) r (cdr r))))
12414                     (while (and (<= min max)
12415                                 (> all 0))
12416                       (push max older)
12417                       (setq all (1- all)
12418                             max (1- max))))))
12419             (setq older (gnus-uncompress-range older))))
12420          (all
12421           (setq older (gnus-uncompress-range older)))
12422          (t
12423           (when (and (numberp gnus-large-newsgroup)
12424                    (> len gnus-large-newsgroup))
12425               (let* ((cursor-in-echo-area nil)
12426                      (initial (gnus-parameter-large-newsgroup-initial
12427                                gnus-newsgroup-name))
12428                      (input
12429                       (read-string
12430                        (format
12431                         "How many articles from %s (%s %d): "
12432                         (gnus-group-decoded-name gnus-newsgroup-name)
12433                         (if initial "max" "default")
12434                         len)
12435                        (if initial
12436                            (cons (number-to-string initial)
12437                                  0)))))
12438                 (unless (string-match "^[ \t]*$" input)
12439                   (setq all (string-to-number input))
12440                   (if (< all len)
12441                       (let ((older-range (nreverse older)))
12442                         (setq older nil)
12443
12444                         (while (> all 0)
12445                           (let* ((r (pop older-range))
12446                                  (min (if (numberp r) r (car r)))
12447                                  (max (if (numberp r) r (cdr r))))
12448                             (while (and (<= min max)
12449                                         (> all 0))
12450                               (push max older)
12451                               (setq all (1- all)
12452                                     max (1- max))))))))))
12453           (setq older (gnus-uncompress-range older))))
12454         (if (not older)
12455             (message "No old news.")
12456           (gnus-summary-insert-articles older)
12457           (gnus-summary-limit (gnus-sorted-nunion old older))))
12458     (gnus-summary-position-point)))
12459
12460 (defun gnus-summary-insert-new-articles ()
12461   "Insert all new articles in this group."
12462   (interactive)
12463   (prog1
12464       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12465             (old-active gnus-newsgroup-active)
12466             (nnmail-fetched-sources (list t))
12467             i new)
12468         (setq gnus-newsgroup-active
12469               (gnus-activate-group gnus-newsgroup-name 'scan))
12470         (setq i (cdr gnus-newsgroup-active))
12471         (while (> i (cdr old-active))
12472           (push i new)
12473           (decf i))
12474         (if (not new)
12475             (message "No gnus is bad news")
12476           (gnus-summary-insert-articles new)
12477           (setq gnus-newsgroup-unreads
12478                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12479           (gnus-summary-limit (gnus-sorted-nunion old new))))
12480     (gnus-summary-position-point)))
12481
12482 (gnus-summary-make-all-marking-commands)
12483
12484 (gnus-ems-redefine)
12485
12486 (provide 'gnus-sum)
12487
12488 (run-hooks 'gnus-sum-load-hook)
12489
12490 ;; Local Variables:
12491 ;; coding: iso-8859-1
12492 ;; End:
12493
12494 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12495 ;;; gnus-sum.el ends here