* gnus-art.el (gnus-header-from, gnus-header-subject, gnus-header-name)
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-summary-next-group-on-exit t
66   "If non-nil, go to the next unread newsgroup on summary exit.
67 See `gnus-group-goto-unread'."
68   :link '(custom-manual "(gnus)Group Maneuvering")
69   :group 'gnus-summary-exit
70   :version "23.0" ;; No Gnus
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already
76 read (or just marked as read) article, the old article will not
77 normally be displayed in the Summary buffer.  If this variable is
78 t, Gnus will attempt to grab the headers to the old articles, and
79 thereby build complete threads.  If it has the value `some', all
80 old headers will be fetched but only enough headers to connect
81 otherwise loose threads will be displayed.  This variable can
82 also be a number.  In that case, no more than that number of old
83 headers will be fetched.  If it has the value `invisible', all
84 old headers will be fetched, but none will be displayed.
85
86 The server has to support NOV for any of this to work.
87
88 This feature can seriously impact performance it ignores all
89 locally cached header entries."
90   :group 'gnus-thread
91   :type '(choice (const :tag "off" nil)
92                  (const :tag "on" t)
93                  (const some)
94                  (const invisible)
95                  number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-refer-thread-limit 500
99   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
100 If t, fetch all the available old headers."
101   :group 'gnus-thread
102   :type '(choice number
103                  (sexp :menu-tag "other" t)))
104
105 (defcustom gnus-summary-make-false-root 'adopt
106   "*nil means that Gnus won't gather loose threads.
107 If the root of a thread has expired or been read in a previous
108 session, the information necessary to build a complete thread has been
109 lost.  Instead of having many small sub-threads from this original thread
110 scattered all over the summary buffer, Gnus can gather them.
111
112 If non-nil, Gnus will try to gather all loose sub-threads from an
113 original thread into one large thread.
114
115 If this variable is non-nil, it should be one of `none', `adopt',
116 `dummy' or `empty'.
117
118 If this variable is `none', Gnus will not make a false root, but just
119 present the sub-threads after another.
120 If this variable is `dummy', Gnus will create a dummy root that will
121 have all the sub-threads as children.
122 If this variable is `adopt', Gnus will make one of the \"children\"
123 the parent and mark all the step-children as such.
124 If this variable is `empty', the \"children\" are printed with empty
125 subject fields.  (Or rather, they will be printed with a string
126 given by the `gnus-summary-same-subject' variable.)"
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const none)
130                  (const dummy)
131                  (const adopt)
132                  (const empty)))
133
134 (defcustom gnus-summary-make-false-root-always nil
135   "Always make a false dummy root."
136   :version "22.1"
137   :group 'gnus-thread
138   :type 'boolean)
139
140 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
141   "*A regexp to match subjects to be excluded from loose thread gathering.
142 As loose thread gathering is done on subjects only, that means that
143 there can be many false gatherings performed.  By rooting out certain
144 common subjects, gathering might become saner."
145   :group 'gnus-thread
146   :type 'regexp)
147
148 (defcustom gnus-summary-gather-subject-limit nil
149   "*Maximum length of subject comparisons when gathering loose threads.
150 Use nil to compare full subjects.  Setting this variable to a low
151 number will help gather threads that have been corrupted by
152 newsreaders chopping off subject lines, but it might also mean that
153 unrelated articles that have subject that happen to begin with the
154 same few characters will be incorrectly gathered.
155
156 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
157 comparing subjects."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  (const fuzzy)
161                  (sexp :menu-tag "on" t)))
162
163 (defcustom gnus-simplify-subject-functions nil
164   "List of functions taking a string argument that simplify subjects.
165 The functions are applied recursively.
166
167 Useful functions to put in this list include:
168 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
169 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
170   :group 'gnus-thread
171   :type '(repeat function))
172
173 (defcustom gnus-simplify-ignored-prefixes nil
174   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  regexp))
178
179 (defcustom gnus-build-sparse-threads nil
180   "*If non-nil, fill in the gaps in threads.
181 If `some', only fill in the gaps that are needed to tie loose threads
182 together.  If `more', fill in all leaf nodes that Gnus can find.  If
183 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
184   :group 'gnus-thread
185   :type '(choice (const :tag "off" nil)
186                  (const some)
187                  (const more)
188                  (sexp :menu-tag "all" t)))
189
190 (defcustom gnus-summary-thread-gathering-function
191   'gnus-gather-threads-by-subject
192   "*Function used for gathering loose threads.
193 There are two pre-defined functions: `gnus-gather-threads-by-subject',
194 which only takes Subjects into consideration; and
195 `gnus-gather-threads-by-references', which compared the References
196 headers of the articles to find matches."
197   :group 'gnus-thread
198   :type '(radio (function-item gnus-gather-threads-by-subject)
199                 (function-item gnus-gather-threads-by-references)
200                 (function :tag "other")))
201
202 (defcustom gnus-summary-same-subject ""
203   "*String indicating that the current article has the same subject as the previous.
204 This variable will only be used if the value of
205 `gnus-summary-make-false-root' is `empty'."
206   :group 'gnus-summary-format
207   :type 'string)
208
209 (defcustom gnus-summary-goto-unread t
210   "*If t, many commands will go to the next unread article.
211 This applies to marking commands as well as other commands that
212 \"naturally\" select the next article, like, for instance, `SPC' at
213 the end of an article.
214
215 If nil, the marking commands do NOT go to the next unread article
216 \(they go to the next article instead).  If `never', commands that
217 usually go to the next unread article, will go to the next article,
218 whether it is read or not."
219   :group 'gnus-summary-marks
220   :link '(custom-manual "(gnus)Setting Marks")
221   :type '(choice (const :tag "off" nil)
222                  (const never)
223                  (sexp :menu-tag "on" t)))
224
225 (defcustom gnus-summary-default-score 0
226   "*Default article score level.
227 All scores generated by the score files will be added to this score.
228 If this variable is nil, scoring will be disabled."
229   :group 'gnus-score-default
230   :type '(choice (const :tag "disable")
231                  integer))
232
233 (defcustom gnus-summary-default-high-score 0
234   "*Default threshold for a high scored article.
235 An article will be highlighted as high scored if its score is greater
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-default-low-score 0
242   "*Default threshold for a low scored article.
243 An article will be highlighted as low scored if its score is smaller
244 than this score."
245   :version "22.1"
246   :group 'gnus-score-default
247   :type 'integer)
248
249 (defcustom gnus-summary-zcore-fuzz 0
250   "*Fuzziness factor for the zcore in the summary buffer.
251 Articles with scores closer than this to `gnus-summary-default-score'
252 will not be marked."
253   :group 'gnus-summary-format
254   :type 'integer)
255
256 (defcustom gnus-simplify-subject-fuzzy-regexp nil
257   "*Strings to be removed when doing fuzzy matches.
258 This can either be a regular expression or list of regular expressions
259 that will be removed from subject strings if fuzzy subject
260 simplification is selected."
261   :group 'gnus-thread
262   :type '(repeat regexp))
263
264 (defcustom gnus-show-threads t
265   "*If non-nil, display threads in summary mode."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-subtree nil
270   "*If non-nil, hide all threads initially.
271 This can be a predicate specifier which says which threads to hide.
272 If threads are hidden, you have to run the command
273 `gnus-summary-show-thread' by hand or select an article."
274   :group 'gnus-thread
275   :type '(radio (sexp :format "Non-nil\n"
276                       :match (lambda (widget value)
277                                (not (or (consp value) (functionp value))))
278                       :value t)
279                 (const nil)
280                 (sexp :tag "Predicate specifier")))
281
282 (defcustom gnus-thread-hide-killed t
283   "*If non-nil, hide killed threads automatically."
284   :group 'gnus-thread
285   :type 'boolean)
286
287 (defcustom gnus-thread-ignore-subject t
288   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
289 If nil, articles that have different subjects from their parents will
290 start separate threads."
291   :group 'gnus-thread
292   :type 'boolean)
293
294 (defcustom gnus-thread-operation-ignore-subject t
295   "*If non-nil, subjects will be ignored when doing thread commands.
296 This affects commands like `gnus-summary-kill-thread' and
297 `gnus-summary-lower-thread'.
298
299 If this variable is nil, articles in the same thread with different
300 subjects will not be included in the operation in question.  If this
301 variable is `fuzzy', only articles that have subjects that are fuzzily
302 equal will be included."
303   :group 'gnus-thread
304   :type '(choice (const :tag "off" nil)
305                  (const fuzzy)
306                  (sexp :tag "on" t)))
307
308 (defcustom gnus-thread-indent-level 4
309   "*Number that says how much each sub-thread should be indented."
310   :group 'gnus-thread
311   :type 'integer)
312
313 (defcustom gnus-auto-extend-newsgroup t
314   "*If non-nil, extend newsgroup forward and backward when requested."
315   :group 'gnus-summary-choose
316   :type 'boolean)
317
318 (defcustom gnus-auto-select-first t
319   "If non-nil, select an article on group entry.
320 An article is selected automatically when entering a group
321 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
322 `gnus-summary-catchup-and-goto-next-group'.
323
324 Which article is selected is controlled by the variable
325 `gnus-auto-select-subject'.
326
327 If you want to prevent automatic selection of articles in some
328 newsgroups, set the variable to nil in `gnus-select-group-hook'."
329   ;; Commands include...
330   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
331   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
332   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
333   :group 'gnus-group-select
334   :type '(choice (const :tag "none" nil)
335                  (sexp :menu-tag "first" t)))
336
337 (defcustom gnus-auto-select-subject 'unread
338   "*Says what subject to place under point when entering a group.
339
340 This variable can either be the symbols `first' (place point on the
341 first subject), `unread' (place point on the subject line of the first
342 unread article), `best' (place point on the subject line of the
343 higest-scored article), `unseen' (place point on the subject line of
344 the first unseen article), `unseen-or-unread' (place point on the subject
345 line of the first unseen article or, if all article have been seen, on the
346 subject line of the first unread article), or a function to be called to
347 place point on some subject line."
348   :version "22.1"
349   :group 'gnus-group-select
350   :type '(choice (const best)
351                  (const unread)
352                  (const first)
353                  (const unseen)
354                  (const unseen-or-unread)))
355
356 (defcustom gnus-auto-select-next t
357   "*If non-nil, offer to go to the next group from the end of the previous.
358 If the value is t and the next newsgroup is empty, Gnus will exit
359 summary mode and go back to group mode.  If the value is neither nil
360 nor t, Gnus will select the following unread newsgroup.  In
361 particular, if the value is the symbol `quietly', the next unread
362 newsgroup will be selected without any confirmation, and if it is
363 `almost-quietly', the next group will be selected without any
364 confirmation if you are located on the last article in the group.
365 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
366 will go to the next group without confirmation."
367   :group 'gnus-summary-maneuvering
368   :type '(choice (const :tag "off" nil)
369                  (const quietly)
370                  (const almost-quietly)
371                  (const slightly-quietly)
372                  (sexp :menu-tag "on" t)))
373
374 (defcustom gnus-auto-select-same nil
375   "*If non-nil, select the next article with the same subject.
376 If there are no more articles with the same subject, go to
377 the first unread article."
378   :group 'gnus-summary-maneuvering
379   :type 'boolean)
380
381 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
382   "What article should be selected after exiting an ephemeral group.
383 Valid values include:
384
385 `next'
386   Select the next article.
387 `next-unread'
388   Select the next unread article.
389 `next-noselect'
390   Move the cursor to the next article.  This is the default.
391 `next-unread-noselect'
392   Move the cursor to the next unread article.
393
394 If it has any other value or there is no next (unread) article, the
395 article selected before entering to the ephemeral group will appear."
396   :version "23.0" ;; No Gnus
397   :group 'gnus-summary-maneuvering
398   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
399                  (const next) (const next-unread)
400                  (const next-noselect) (const next-unread-noselect)
401                  (sexp :tag "other" :value nil)))
402
403 (defcustom gnus-auto-goto-ignores 'unfetched
404   "*Says how to handle unfetched articles when maneuvering.
405
406 This variable can either be the symbols nil (maneuver to any
407 article), `undownloaded' (maneuvering while unplugged ignores articles
408 that have not been fetched), `always-undownloaded' (maneuvering always
409 ignores articles that have not been fetched), `unfetched' (maneuvering
410 ignores articles whose headers have not been fetched).
411
412 NOTE: The list of unfetched articles will always be nil when plugged
413 and, when unplugged, a subset of the undownloaded article list."
414   :version "22.1"
415   :group 'gnus-summary-maneuvering
416   :type '(choice (const :tag "None" nil)
417                  (const :tag "Undownloaded when unplugged" undownloaded)
418                  (const :tag "Undownloaded" always-undownloaded)
419                  (const :tag "Unfetched" unfetched)))
420
421 (defcustom gnus-summary-check-current nil
422   "*If non-nil, consider the current article when moving.
423 The \"unread\" movement commands will stay on the same line if the
424 current article is unread."
425   :group 'gnus-summary-maneuvering
426   :type 'boolean)
427
428 (defcustom gnus-auto-center-summary 2
429   "*If non-nil, always center the current summary buffer.
430 In particular, if `vertical' do only vertical recentering.  If non-nil
431 and non-`vertical', do both horizontal and vertical recentering."
432   :group 'gnus-summary-maneuvering
433   :type '(choice (const :tag "none" nil)
434                  (const vertical)
435                  (integer :tag "height")
436                  (sexp :menu-tag "both" t)))
437
438 (defvar gnus-auto-center-group t
439   "*If non-nil, always center the group buffer.")
440
441 (defcustom gnus-show-all-headers nil
442   "*If non-nil, don't hide any headers."
443   :group 'gnus-article-hiding
444   :group 'gnus-article-headers
445   :type 'boolean)
446
447 (defcustom gnus-summary-ignore-duplicates nil
448   "*If non-nil, ignore articles with identical Message-ID headers."
449   :group 'gnus-summary
450   :type 'boolean)
451
452 (defcustom gnus-single-article-buffer t
453   "*If non-nil, display all articles in the same buffer.
454 If nil, each group will get its own article buffer."
455   :group 'gnus-article-various
456   :type 'boolean)
457
458 (defcustom gnus-break-pages t
459   "*If non-nil, do page breaking on articles.
460 The page delimiter is specified by the `gnus-page-delimiter'
461 variable."
462   :group 'gnus-article-various
463   :type 'boolean)
464
465 (defcustom gnus-move-split-methods nil
466   "*Variable used to suggest where articles are to be moved to.
467 It uses the same syntax as the `gnus-split-methods' variable.
468 However, whereas `gnus-split-methods' specifies file names as targets,
469 this variable specifies group names."
470   :group 'gnus-summary-mail
471   :type '(repeat (choice (list :value (fun) function)
472                          (cons :value ("" "") regexp (repeat string))
473                          (sexp :value nil))))
474
475 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
476   "Function used to compute default prefix for article move/copy/etc prompts.
477 The function should take one argument, a group name, and return a
478 string with the suggested prefix."
479   :group 'gnus-summary-mail
480   :type 'function)
481
482 ;; FIXME: Although the custom type is `character' for the following variables,
483 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
484
485 (defcustom gnus-unread-mark ?           ;Whitespace
486   "*Mark used for unread articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-ticked-mark ?!
491   "*Mark used for ticked articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-dormant-mark ??
496   "*Mark used for dormant articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-del-mark ?r
501   "*Mark used for del'd articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-read-mark ?R
506   "*Mark used for read articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-expirable-mark ?E
511   "*Mark used for expirable articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-killed-mark ?K
516   "*Mark used for killed articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-spam-mark ?$
521   "*Mark used for spam articles."
522   :version "22.1"
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-souped-mark ?F
527   "*Mark used for souped articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-kill-file-mark ?X
532   "*Mark used for articles killed by kill files."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-low-score-mark ?Y
537   "*Mark used for articles with a low score."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-catchup-mark ?C
542   "*Mark used for articles that are caught up."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-replied-mark ?A
547   "*Mark used for articles that have been replied to."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-forwarded-mark ?F
552   "*Mark used for articles that have been forwarded."
553   :version "22.1"
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-recent-mark ?N
558   "*Mark used for articles that are recent."
559   :version "22.1"
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-cached-mark ?*
564   "*Mark used for articles that are in the cache."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-saved-mark ?S
569   "*Mark used for articles that have been saved."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-unseen-mark ?.
574   "*Mark used for articles that haven't been seen."
575   :version "22.1"
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-no-mark ?               ;Whitespace
580   "*Mark used for articles that have no other secondary mark."
581   :version "22.1"
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-ancient-mark ?O
586   "*Mark used for ancient articles."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-sparse-mark ?Q
591   "*Mark used for sparsely reffed articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-canceled-mark ?G
596   "*Mark used for canceled articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-duplicate-mark ?M
601   "*Mark used for duplicate articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-undownloaded-mark ?-
606   "*Mark used for articles that weren't downloaded."
607   :version "22.1"
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-downloaded-mark ?+
612   "*Mark used for articles that were downloaded."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloadable-mark ?%
617   "*Mark used for articles that are to be downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-unsendable-mark ?=
622   "*Mark used for articles that won't be sent."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-score-over-mark ?+
627   "*Score mark used for articles with high scores."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-below-mark ?-
632   "*Score mark used for articles with low scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-empty-thread-mark ?     ;Whitespace
637   "*There is no thread under the article."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-not-empty-thread-mark ?=
642   "*There is a thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-view-pseudo-asynchronously nil
647   "*If non-nil, Gnus will view pseudo-articles asynchronously."
648   :group 'gnus-extract-view
649   :type 'boolean)
650
651 (defcustom gnus-auto-expirable-marks
652   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
653         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
654         gnus-souped-mark gnus-duplicate-mark)
655   "*The list of marks converted into expiration if a group is auto-expirable."
656   :version "21.1"
657   :group 'gnus-summary
658   :type '(repeat character))
659
660 (defcustom gnus-inhibit-user-auto-expire t
661   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
662   :version "21.1"
663   :group 'gnus-summary
664   :type 'boolean)
665
666 (defcustom gnus-view-pseudos nil
667   "*If `automatic', pseudo-articles will be viewed automatically.
668 If `not-confirm', pseudos will be viewed automatically, and the user
669 will not be asked to confirm the command."
670   :group 'gnus-extract-view
671   :type '(choice (const :tag "off" nil)
672                  (const automatic)
673                  (const not-confirm)))
674
675 (defcustom gnus-view-pseudos-separately t
676   "*If non-nil, one pseudo-article will be created for each file to be viewed.
677 If nil, all files that use the same viewing command will be given as a
678 list of parameters to that command."
679   :group 'gnus-extract-view
680   :type 'boolean)
681
682 (defcustom gnus-insert-pseudo-articles t
683   "*If non-nil, insert pseudo-articles when decoding articles."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-summary-dummy-line-format
688   "   %(:                             :%) %S\n"
689   "*The format specification for the dummy roots in the summary buffer.
690 It works along the same lines as a normal formatting string,
691 with some simple extensions.
692
693 %S  The subject
694
695 General format specifiers can also be used.
696 See `(gnus)Formatting Variables'."
697   :link '(custom-manual "(gnus)Formatting Variables")
698   :group 'gnus-threading
699   :type 'string)
700
701 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
702   "*The format specification for the summary mode line.
703 It works along the same lines as a normal formatting string,
704 with some simple extensions:
705
706 %G  Group name
707 %p  Unprefixed group name
708 %A  Current article number
709 %z  Current article score
710 %V  Gnus version
711 %U  Number of unread articles in the group
712 %e  Number of unselected articles in the group
713 %Z  A string with unread/unselected article counts
714 %g  Shortish group name
715 %S  Subject of the current article
716 %u  User-defined spec
717 %s  Current score file name
718 %d  Number of dormant articles
719 %r  Number of articles that have been marked as read in this session
720 %E  Number of articles expunged by the score files"
721   :group 'gnus-summary-format
722   :type 'string)
723
724 (defcustom gnus-list-identifiers nil
725   "Regexp that matches list identifiers to be removed from subject.
726 This can also be a list of regexps."
727   :version "21.1"
728   :group 'gnus-summary-format
729   :group 'gnus-article-hiding
730   :type '(choice (const :tag "none" nil)
731                  (regexp :value ".*")
732                  (repeat :value (".*") regexp)))
733
734 (defcustom gnus-summary-mark-below 0
735   "*Mark all articles with a score below this variable as read.
736 This variable is local to each summary buffer and usually set by the
737 score file."
738   :group 'gnus-score-default
739   :type 'integer)
740
741 (defun gnus-widget-reversible-match (widget value)
742   "Ignoring WIDGET, convert VALUE to internal form.
743 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
744   ;; (debug value)
745   (or (symbolp value)
746       (and (listp value)
747            (eq (length value) 2)
748            (eq (nth 0 value) 'not)
749            (symbolp (nth 1 value)))))
750
751 (defun gnus-widget-reversible-to-internal (widget value)
752   "Ignoring WIDGET, convert VALUE to internal form.
753 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
754 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
755   ;; (debug value)
756   (if (atom value)
757       (list value nil)
758     (list (nth 1 value) t)))
759
760 (defun gnus-widget-reversible-to-external (widget value)
761   "Ignoring WIDGET, convert VALUE to external form.
762 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
763 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
764   ;; (debug value)
765   (if (nth 1 value)
766       (list 'not (nth 0 value))
767     (nth 0 value)))
768
769 (define-widget 'gnus-widget-reversible 'group
770   "A `group' that convert values."
771   :match 'gnus-widget-reversible-match
772   :value-to-internal 'gnus-widget-reversible-to-internal
773   :value-to-external 'gnus-widget-reversible-to-external)
774
775 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
776   "*List of functions used for sorting articles in the summary buffer.
777
778 Each function takes two articles and returns non-nil if the first
779 article should be sorted before the other.  If you use more than one
780 function, the primary sort function should be the last.  You should
781 probably always include `gnus-article-sort-by-number' in the list of
782 sorting functions -- preferably first.  Also note that sorting by date
783 is often much slower than sorting by number, and the sorting order is
784 very similar.  (Sorting by date means sorting by the time the message
785 was sent, sorting by number means sorting by arrival time.)
786
787 Each item can also be a list `(not F)' where F is a function;
788 this reverses the sort order.
789
790 Ready-made functions include `gnus-article-sort-by-number',
791 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
792 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
793 and `gnus-article-sort-by-score'.
794
795 When threading is turned on, the variable `gnus-thread-sort-functions'
796 controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat (gnus-widget-reversible
799                   (choice (function-item gnus-article-sort-by-number)
800                           (function-item gnus-article-sort-by-author)
801                           (function-item gnus-article-sort-by-subject)
802                           (function-item gnus-article-sort-by-date)
803                           (function-item gnus-article-sort-by-score)
804                           (function-item gnus-article-sort-by-random)
805                           (function :tag "other"))
806                   (boolean :tag "Reverse order"))))
807
808
809 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
810   "*List of functions used for sorting threads in the summary buffer.
811 By default, threads are sorted by article number.
812
813 Each function takes two threads and returns non-nil if the first
814 thread should be sorted before the other.  If you use more than one
815 function, the primary sort function should be the last.  You should
816 probably always include `gnus-thread-sort-by-number' in the list of
817 sorting functions -- preferably first.  Also note that sorting by date
818 is often much slower than sorting by number, and the sorting order is
819 very similar.  (Sorting by date means sorting by the time the message
820 was sent, sorting by number means sorting by arrival time.)
821
822 Each list item can also be a list `(not F)' where F is a
823 function; this specifies reversed sort order.
824
825 Ready-made functions include `gnus-thread-sort-by-number',
826 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
827 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
828 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
829 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
830 and `gnus-thread-sort-by-total-score' (see
831 `gnus-thread-score-function').
832
833 When threading is turned off, the variable
834 `gnus-article-sort-functions' controls how articles are sorted."
835   :group 'gnus-summary-sort
836   :type '(repeat
837           (gnus-widget-reversible
838            (choice (function-item gnus-thread-sort-by-number)
839                    (function-item gnus-thread-sort-by-author)
840                    (function-item gnus-thread-sort-by-recipient)
841                    (function-item gnus-thread-sort-by-subject)
842                    (function-item gnus-thread-sort-by-date)
843                    (function-item gnus-thread-sort-by-score)
844                    (function-item gnus-thread-sort-by-most-recent-number)
845                    (function-item gnus-thread-sort-by-most-recent-date)
846                    (function-item gnus-thread-sort-by-random)
847                    (function-item gnus-thread-sort-by-total-score)
848                    (function :tag "other"))
849            (boolean :tag "Reverse order"))))
850
851 (defcustom gnus-thread-score-function '+
852   "*Function used for calculating the total score of a thread.
853
854 The function is called with the scores of the article and each
855 subthread and should then return the score of the thread.
856
857 Some functions you can use are `+', `max', or `min'."
858   :group 'gnus-summary-sort
859   :type 'function)
860
861 (defcustom gnus-summary-expunge-below nil
862   "All articles that have a score less than this variable will be expunged.
863 This variable is local to the summary buffers."
864   :group 'gnus-score-default
865   :type '(choice (const :tag "off" nil)
866                  integer))
867
868 (defcustom gnus-thread-expunge-below nil
869   "All threads that have a total score less than this variable will be expunged.
870 See `gnus-thread-score-function' for en explanation of what a
871 \"thread score\" is.
872
873 This variable is local to the summary buffers."
874   :group 'gnus-threading
875   :group 'gnus-score-default
876   :type '(choice (const :tag "off" nil)
877                  integer))
878
879 (defcustom gnus-summary-mode-hook nil
880   "*A hook for Gnus summary mode.
881 This hook is run before any variables are set in the summary buffer."
882   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
883   :group 'gnus-summary-various
884   :type 'hook)
885
886 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
887 (when (featurep 'xemacs)
888   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
889   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
890   (add-hook 'gnus-summary-mode-hook
891             'gnus-xmas-switch-horizontal-scrollbar-off))
892
893 (defcustom gnus-summary-menu-hook nil
894   "*Hook run after the creation of the summary mode menu."
895   :group 'gnus-summary-visual
896   :type 'hook)
897
898 (defcustom gnus-summary-exit-hook nil
899   "*A hook called on exit from the summary buffer.
900 It will be called with point in the group buffer."
901   :group 'gnus-summary-exit
902   :type 'hook)
903
904 (defcustom gnus-summary-prepare-hook nil
905   "*A hook called after the summary buffer has been generated.
906 If you want to modify the summary buffer, you can use this hook."
907   :group 'gnus-summary-various
908   :type 'hook)
909
910 (defcustom gnus-summary-prepared-hook nil
911   "*A hook called as the last thing after the summary buffer has been generated."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-generate-hook nil
916   "*A hook run just before generating the summary buffer.
917 This hook is commonly used to customize threading variables and the
918 like."
919   :group 'gnus-summary-various
920   :type 'hook)
921
922 (defcustom gnus-select-group-hook nil
923   "*A hook called when a newsgroup is selected.
924
925 If you'd like to simplify subjects like the
926 `gnus-summary-next-same-subject' command does, you can use the
927 following hook:
928
929  (add-hook gnus-select-group-hook
930            (lambda ()
931              (mapcar (lambda (header)
932                        (mail-header-set-subject
933                         header
934                         (gnus-simplify-subject
935                          (mail-header-subject header) 're-only)))
936                      gnus-newsgroup-headers)))"
937   :group 'gnus-group-select
938   :type 'hook)
939
940 (defcustom gnus-select-article-hook nil
941   "*A hook called when an article is selected."
942   :group 'gnus-summary-choose
943   :options '(gnus-agent-fetch-selected-article)
944   :type 'hook)
945
946 (defcustom gnus-visual-mark-article-hook
947   (list 'gnus-highlight-selected-summary)
948   "*Hook run after selecting an article in the summary buffer.
949 It is meant to be used for highlighting the article in some way.  It
950 is not run if `gnus-visual' is nil."
951   :group 'gnus-summary-visual
952   :type 'hook)
953
954 (defcustom gnus-parse-headers-hook nil
955   "*A hook called before parsing the headers."
956   :group 'gnus-various
957   :type 'hook)
958
959 (defcustom gnus-exit-group-hook nil
960   "*A hook called when exiting summary mode.
961 This hook is not called from the non-updating exit commands like `Q'."
962   :group 'gnus-various
963   :type 'hook)
964
965 (defcustom gnus-summary-update-hook
966   (list 'gnus-summary-highlight-line)
967   "*A hook called when a summary line is changed.
968 The hook will not be called if `gnus-visual' is nil.
969
970 The default function `gnus-summary-highlight-line' will
971 highlight the line according to the `gnus-summary-highlight'
972 variable."
973   :group 'gnus-summary-visual
974   :type 'hook)
975
976 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
977   "*A hook called when an article is selected for the first time.
978 The hook is intended to mark an article as read (or unread)
979 automatically when it is selected."
980   :group 'gnus-summary-choose
981   :type 'hook)
982
983 (defcustom gnus-group-no-more-groups-hook nil
984   "*A hook run when returning to group mode having no more (unread) groups."
985   :group 'gnus-group-select
986   :type 'hook)
987
988 (defcustom gnus-ps-print-hook nil
989   "*A hook run before ps-printing something from Gnus."
990   :group 'gnus-summary
991   :type 'hook)
992
993 (defcustom gnus-summary-article-move-hook nil
994   "*A hook called after an article is moved, copied, respooled, or crossposted."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'hook)
998
999 (defcustom gnus-summary-article-delete-hook nil
1000   "*A hook called after an article is deleted."
1001   :version "22.1"
1002   :group 'gnus-summary
1003   :type 'hook)
1004
1005 (defcustom gnus-summary-article-expire-hook nil
1006   "*A hook called after an article is expired."
1007   :version "22.1"
1008   :group 'gnus-summary
1009   :type 'hook)
1010
1011 (defcustom gnus-summary-display-arrow
1012   (and (fboundp 'display-graphic-p)
1013        (display-graphic-p))
1014   "*If non-nil, display an arrow highlighting the current article."
1015   :version "22.1"
1016   :group 'gnus-summary
1017   :type 'boolean)
1018
1019 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1020   "Face used for highlighting the current article in the summary buffer."
1021   :group 'gnus-summary-visual
1022   :type 'face)
1023
1024 (defvar gnus-tmp-downloaded nil)
1025
1026 (defcustom gnus-summary-highlight
1027   '(((eq mark gnus-canceled-mark)
1028      . gnus-summary-cancelled)
1029     ((and uncached (> score default-high))
1030      . gnus-summary-high-undownloaded)
1031     ((and uncached (< score default-low))
1032      . gnus-summary-low-undownloaded)
1033     (uncached
1034      . gnus-summary-normal-undownloaded)
1035     ((and (> score default-high)
1036           (or (eq mark gnus-dormant-mark)
1037               (eq mark gnus-ticked-mark)))
1038      . gnus-summary-high-ticked)
1039     ((and (< score default-low)
1040           (or (eq mark gnus-dormant-mark)
1041               (eq mark gnus-ticked-mark)))
1042      . gnus-summary-low-ticked)
1043     ((or (eq mark gnus-dormant-mark)
1044          (eq mark gnus-ticked-mark))
1045      . gnus-summary-normal-ticked)
1046     ((and (> score default-high) (eq mark gnus-ancient-mark))
1047      . gnus-summary-high-ancient)
1048     ((and (< score default-low) (eq mark gnus-ancient-mark))
1049      . gnus-summary-low-ancient)
1050     ((eq mark gnus-ancient-mark)
1051      . gnus-summary-normal-ancient)
1052     ((and (> score default-high) (eq mark gnus-unread-mark))
1053      . gnus-summary-high-unread)
1054     ((and (< score default-low) (eq mark gnus-unread-mark))
1055      . gnus-summary-low-unread)
1056     ((eq mark gnus-unread-mark)
1057      . gnus-summary-normal-unread)
1058     ((> score default-high)
1059      . gnus-summary-high-read)
1060     ((< score default-low)
1061      . gnus-summary-low-read)
1062     (t
1063      . gnus-summary-normal-read))
1064   "*Controls the highlighting of summary buffer lines.
1065
1066 A list of (FORM . FACE) pairs.  When deciding how a a particular
1067 summary line should be displayed, each form is evaluated.  The content
1068 of the face field after the first true form is used.  You can change
1069 how those summary lines are displayed, by editing the face field.
1070
1071 You can use the following variables in the FORM field.
1072
1073 score:        The article's score
1074 default:      The default article score.
1075 default-high: The default score for high scored articles.
1076 default-low:  The default score for low scored articles.
1077 below:        The score below which articles are automatically marked as read.
1078 mark:         The article's mark.
1079 uncached:     Non-nil if the article is uncached."
1080   :group 'gnus-summary-visual
1081   :type '(repeat (cons (sexp :tag "Form" nil)
1082                        face)))
1083
1084 (defcustom gnus-alter-header-function nil
1085   "Function called to allow alteration of article header structures.
1086 The function is called with one parameter, the article header vector,
1087 which it may alter in any way."
1088   :type '(choice (const :tag "None" nil)
1089                  function)
1090   :group 'gnus-summary)
1091
1092 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1093   "Function used to decode a string with encoded words.")
1094
1095 (defvar gnus-decode-encoded-address-function
1096   'mail-decode-encoded-address-string
1097   "Function used to decode addresses with encoded words.")
1098
1099 (defcustom gnus-extra-headers '(To Newsgroups)
1100   "*Extra headers to parse."
1101   :version "21.1"
1102   :group 'gnus-summary
1103   :type '(repeat symbol))
1104
1105 (defcustom gnus-ignored-from-addresses
1106   (and user-mail-address
1107        (not (string= user-mail-address ""))
1108        (regexp-quote user-mail-address))
1109   "*From headers that may be suppressed in favor of To headers.
1110 This can be a regexp or a list of regexps."
1111   :version "21.1"
1112   :group 'gnus-summary
1113   :type '(choice regexp
1114                  (repeat :tag "Regexp List" regexp)))
1115
1116 (defsubst gnus-ignored-from-addresses ()
1117   (gmm-regexp-concat gnus-ignored-from-addresses))
1118
1119 (defcustom gnus-summary-to-prefix "-> "
1120   "*String prefixed to the To field in the summary line when
1121 using `gnus-ignored-from-addresses'."
1122   :version "22.1"
1123   :group 'gnus-summary
1124   :type 'string)
1125
1126 (defcustom gnus-summary-newsgroup-prefix "=> "
1127   "*String prefixed to the Newsgroup field in the summary
1128 line when using `gnus-ignored-from-addresses'."
1129   :version "22.1"
1130   :group 'gnus-summary
1131   :type 'string)
1132
1133 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1134   "List of charsets that should be ignored.
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead."
1137   :version "21.1"
1138   :type '(repeat symbol)
1139   :group 'gnus-charset)
1140
1141 (gnus-define-group-parameter
1142  ignored-charsets
1143  :type list
1144  :function-document
1145  "Return the ignored charsets of GROUP."
1146  :variable gnus-group-ignored-charsets-alist
1147  :variable-default
1148  '(("alt\\.chinese\\.text" iso-8859-1))
1149  :variable-document
1150  "Alist of regexps (to match group names) and charsets that should be ignored.
1151 When these charsets are used in the \"charset\" parameter, the
1152 default charset will be used instead."
1153  :variable-group gnus-charset
1154  :variable-type '(repeat (cons (regexp :tag "Group")
1155                                (repeat symbol)))
1156  :parameter-type '(choice :tag "Ignored charsets"
1157                           :value nil
1158                           (repeat (symbol)))
1159  :parameter-document       "\
1160 List of charsets that should be ignored.
1161
1162 When these charsets are used in the \"charset\" parameter, the
1163 default charset will be used instead.")
1164
1165 (defcustom gnus-group-highlight-words-alist nil
1166   "Alist of group regexps and highlight regexps.
1167 This variable uses the same syntax as `gnus-emphasis-alist'."
1168   :version "21.1"
1169   :type '(repeat (cons (regexp :tag "Group")
1170                        (repeat (list (regexp :tag "Highlight regexp")
1171                                      (number :tag "Group for entire word" 0)
1172                                      (number :tag "Group for displayed part" 0)
1173                                      (symbol :tag "Face"
1174                                              gnus-emphasis-highlight-words)))))
1175   :group 'gnus-summary-visual)
1176
1177 (defcustom gnus-summary-show-article-charset-alist
1178   nil
1179   "Alist of number and charset.
1180 The article will be shown with the charset corresponding to the
1181 numbered argument.
1182 For example: ((1 . cn-gb-2312) (2 . big5))."
1183   :version "21.1"
1184   :type '(repeat (cons (number :tag "Argument" 1)
1185                        (symbol :tag "Charset")))
1186   :group 'gnus-charset)
1187
1188 (defcustom gnus-preserve-marks t
1189   "Whether marks are preserved when moving, copying and respooling messages."
1190   :version "21.1"
1191   :type 'boolean
1192   :group 'gnus-summary-marks)
1193
1194 (defcustom gnus-alter-articles-to-read-function nil
1195   "Function to be called to alter the list of articles to be selected."
1196   :type '(choice (const nil) function)
1197   :group 'gnus-summary)
1198
1199 (defcustom gnus-orphan-score nil
1200   "*All orphans get this score added.  Set in the score file."
1201   :group 'gnus-score-default
1202   :type '(choice (const nil)
1203                  integer))
1204
1205 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1206   "*A regexp to match MIME parts when saving multiple parts of a
1207 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1208 This regexp will be used by default when prompting the user for which
1209 type of files to save."
1210   :group 'gnus-summary
1211   :type 'regexp)
1212
1213 (defcustom gnus-read-all-available-headers nil
1214   "Whether Gnus should parse all headers made available to it.
1215 This is mostly relevant for slow back ends where the user may
1216 wish to widen the summary buffer to include all headers
1217 that were fetched.  Say, for nnultimate groups."
1218   :version "22.1"
1219   :group 'gnus-summary
1220   :type '(choice boolean regexp))
1221
1222 (defcustom gnus-summary-muttprint-program "muttprint"
1223   "Command (and optional arguments) used to run Muttprint."
1224   :version "22.1"
1225   :group 'gnus-summary
1226   :type 'string)
1227
1228 (defcustom gnus-article-loose-mime t
1229   "If non-nil, don't require MIME-Version header.
1230 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1231 supply the MIME-Version header or deliberately strip it from the mail.
1232 If non-nil (the default), Gnus will treat some articles as MIME
1233 even if the MIME-Version header is missing."
1234   :version "22.1"
1235   :type 'boolean
1236   :group 'gnus-article-mime)
1237
1238 (defcustom gnus-article-emulate-mime t
1239   "If non-nil, use MIME emulation for uuencode and the like.
1240 This means that Gnus will search message bodies for text that look
1241 like uuencoded bits, yEncoded bits, and so on, and present that using
1242 the normal Gnus MIME machinery."
1243   :version "22.1"
1244   :type 'boolean
1245   :group 'gnus-article-mime)
1246
1247 ;;; Internal variables
1248
1249 (defvar gnus-summary-display-cache nil)
1250 (defvar gnus-article-mime-handles nil)
1251 (defvar gnus-article-decoded-p nil)
1252 (defvar gnus-article-charset nil)
1253 (defvar gnus-article-ignored-charsets nil)
1254 (defvar gnus-scores-exclude-files nil)
1255 (defvar gnus-page-broken nil)
1256
1257 (defvar gnus-original-article nil)
1258 (defvar gnus-article-internal-prepare-hook nil)
1259 (defvar gnus-newsgroup-process-stack nil)
1260
1261 (defvar gnus-thread-indent-array nil)
1262 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1263 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1264   "Function called to sort the articles within a thread after it has been gathered together.")
1265
1266 (defvar gnus-summary-save-parts-type-history nil)
1267 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1268
1269 ;; Avoid highlighting in kill files.
1270 (defvar gnus-summary-inhibit-highlight nil)
1271 (defvar gnus-newsgroup-selected-overlay nil)
1272 (defvar gnus-inhibit-limiting nil)
1273 (defvar gnus-newsgroup-adaptive-score-file nil)
1274 (defvar gnus-current-score-file nil)
1275 (defvar gnus-current-move-group nil)
1276 (defvar gnus-current-copy-group nil)
1277 (defvar gnus-current-crosspost-group nil)
1278 (defvar gnus-newsgroup-display nil)
1279
1280 (defvar gnus-newsgroup-dependencies nil)
1281 (defvar gnus-newsgroup-adaptive nil)
1282 (defvar gnus-summary-display-article-function nil)
1283 (defvar gnus-summary-highlight-line-function nil
1284   "Function called after highlighting a summary line.")
1285
1286 (defvar gnus-summary-line-format-alist
1287   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1288     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1289     (?s gnus-tmp-subject-or-nil ?s)
1290     (?n gnus-tmp-name ?s)
1291     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1292         ?s)
1293     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1294             gnus-tmp-from) ?s)
1295     (?F gnus-tmp-from ?s)
1296     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1297     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1298     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1299     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1300     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1301     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1302     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1303     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1304     (?L gnus-tmp-lines ?s)
1305     (?O gnus-tmp-downloaded ?c)
1306     (?I gnus-tmp-indentation ?s)
1307     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1308     (?R gnus-tmp-replied ?c)
1309     (?\[ gnus-tmp-opening-bracket ?c)
1310     (?\] gnus-tmp-closing-bracket ?c)
1311     (?\> (make-string gnus-tmp-level ? ) ?s)
1312     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1313     (?i gnus-tmp-score ?d)
1314     (?z gnus-tmp-score-char ?c)
1315     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1316     (?U gnus-tmp-unread ?c)
1317     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1318         ?s)
1319     (?t (gnus-summary-number-of-articles-in-thread
1320          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1321         ?d)
1322     (?e (gnus-summary-number-of-articles-in-thread
1323          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1324         ?c)
1325     (?u gnus-tmp-user-defined ?s)
1326     (?P (gnus-pick-line-number) ?d)
1327     (?B gnus-tmp-thread-tree-header-string ?s)
1328     (user-date (gnus-user-date
1329                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1330   "An alist of format specifications that can appear in summary lines.
1331 These are paired with what variables they correspond with, along with
1332 the type of the variable (string, integer, character, etc).")
1333
1334 (defvar gnus-summary-dummy-line-format-alist
1335   `((?S gnus-tmp-subject ?s)
1336     (?N gnus-tmp-number ?d)
1337     (?u gnus-tmp-user-defined ?s)))
1338
1339 (defvar gnus-summary-mode-line-format-alist
1340   `((?G gnus-tmp-group-name ?s)
1341     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1342     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1343     (?A gnus-tmp-article-number ?d)
1344     (?Z gnus-tmp-unread-and-unselected ?s)
1345     (?V gnus-version ?s)
1346     (?U gnus-tmp-unread-and-unticked ?d)
1347     (?S gnus-tmp-subject ?s)
1348     (?e gnus-tmp-unselected ?d)
1349     (?u gnus-tmp-user-defined ?s)
1350     (?d (length gnus-newsgroup-dormant) ?d)
1351     (?t (length gnus-newsgroup-marked) ?d)
1352     (?h (length gnus-newsgroup-spam-marked) ?d)
1353     (?r (length gnus-newsgroup-reads) ?d)
1354     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1355     (?E gnus-newsgroup-expunged-tally ?d)
1356     (?s (gnus-current-score-file-nondirectory) ?s)))
1357
1358 (defvar gnus-last-search-regexp nil
1359   "Default regexp for article search command.")
1360
1361 (defvar gnus-last-shell-command nil
1362   "Default shell command on article.")
1363
1364 (defvar gnus-newsgroup-agentized nil
1365   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1366 (defvar gnus-newsgroup-begin nil)
1367 (defvar gnus-newsgroup-end nil)
1368 (defvar gnus-newsgroup-last-rmail nil)
1369 (defvar gnus-newsgroup-last-mail nil)
1370 (defvar gnus-newsgroup-last-folder nil)
1371 (defvar gnus-newsgroup-last-file nil)
1372 (defvar gnus-newsgroup-last-directory nil)
1373 (defvar gnus-newsgroup-auto-expire nil)
1374 (defvar gnus-newsgroup-active nil)
1375
1376 (defvar gnus-newsgroup-data nil)
1377 (defvar gnus-newsgroup-data-reverse nil)
1378 (defvar gnus-newsgroup-limit nil)
1379 (defvar gnus-newsgroup-limits nil)
1380 (defvar gnus-summary-use-undownloaded-faces nil)
1381
1382 (defvar gnus-newsgroup-unreads nil
1383   "Sorted list of unread articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-unselected nil
1386   "Sorted list of unselected unread articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-reads nil
1389   "Alist of read articles and article marks in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-expunged-tally nil)
1392
1393 (defvar gnus-newsgroup-marked nil
1394   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1395
1396 (defvar gnus-newsgroup-spam-marked nil
1397   "List of ranges of articles that have been marked as spam.")
1398
1399 (defvar gnus-newsgroup-killed nil
1400   "List of ranges of articles that have been through the scoring process.")
1401
1402 (defvar gnus-newsgroup-cached nil
1403   "Sorted list of articles that come from the article cache.")
1404
1405 (defvar gnus-newsgroup-saved nil
1406   "List of articles that have been saved.")
1407
1408 (defvar gnus-newsgroup-kill-headers nil)
1409
1410 (defvar gnus-newsgroup-replied nil
1411   "List of articles that have been replied to in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-forwarded nil
1414   "List of articles that have been forwarded in the current newsgroup.")
1415
1416 (defvar gnus-newsgroup-recent nil
1417   "List of articles that have are recent in the current newsgroup.")
1418
1419 (defvar gnus-newsgroup-expirable nil
1420   "Sorted list of articles in the current newsgroup that can be expired.")
1421
1422 (defvar gnus-newsgroup-processable nil
1423   "List of articles in the current newsgroup that can be processed.")
1424
1425 (defvar gnus-newsgroup-downloadable nil
1426   "Sorted list of articles in the current newsgroup that can be processed.")
1427
1428 (defvar gnus-newsgroup-unfetched nil
1429   "Sorted list of articles in the current newsgroup whose headers have
1430 not been fetched into the agent.
1431
1432 This list will always be a subset of gnus-newsgroup-undownloaded.")
1433
1434 (defvar gnus-newsgroup-undownloaded nil
1435   "List of articles in the current newsgroup that haven't been downloaded.")
1436
1437 (defvar gnus-newsgroup-unsendable nil
1438   "List of articles in the current newsgroup that won't be sent.")
1439
1440 (defvar gnus-newsgroup-bookmarks nil
1441   "List of articles in the current newsgroup that have bookmarks.")
1442
1443 (defvar gnus-newsgroup-dormant nil
1444   "Sorted list of dormant articles in the current newsgroup.")
1445
1446 (defvar gnus-newsgroup-unseen nil
1447   "List of unseen articles in the current newsgroup.")
1448
1449 (defvar gnus-newsgroup-seen nil
1450   "Range of seen articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-articles nil
1453   "List of articles in the current newsgroup.")
1454
1455 (defvar gnus-newsgroup-scored nil
1456   "List of scored articles in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-headers nil
1459   "List of article headers in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-threads nil)
1462
1463 (defvar gnus-newsgroup-prepared nil
1464   "Whether the current group has been prepared properly.")
1465
1466 (defvar gnus-newsgroup-ancient nil
1467   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-sparse nil)
1470
1471 (defvar gnus-current-article nil)
1472 (defvar gnus-article-current nil)
1473 (defvar gnus-current-headers nil)
1474 (defvar gnus-have-all-headers nil)
1475 (defvar gnus-last-article nil)
1476 (defvar gnus-newsgroup-history nil)
1477 (defvar gnus-newsgroup-charset nil)
1478 (defvar gnus-newsgroup-ephemeral-charset nil)
1479 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1480
1481 (defvar gnus-article-before-search nil)
1482
1483 (defvar gnus-summary-local-variables
1484   '(gnus-newsgroup-name
1485     gnus-newsgroup-begin gnus-newsgroup-end
1486     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1487     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1488     gnus-newsgroup-last-directory
1489     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1490     gnus-newsgroup-unselected gnus-newsgroup-marked
1491     gnus-newsgroup-spam-marked
1492     gnus-newsgroup-reads gnus-newsgroup-saved
1493     gnus-newsgroup-replied gnus-newsgroup-forwarded
1494     gnus-newsgroup-recent
1495     gnus-newsgroup-expirable
1496     gnus-newsgroup-processable gnus-newsgroup-killed
1497     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1498     gnus-newsgroup-unfetched
1499     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1500     gnus-newsgroup-seen gnus-newsgroup-articles
1501     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1502     gnus-newsgroup-headers gnus-newsgroup-threads
1503     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1504     gnus-current-article gnus-current-headers gnus-have-all-headers
1505     gnus-last-article gnus-article-internal-prepare-hook
1506     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1507     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1508     gnus-thread-expunge-below
1509     gnus-score-alist gnus-current-score-file
1510     (gnus-summary-expunge-below . global)
1511     (gnus-summary-mark-below . global)
1512     (gnus-orphan-score . global)
1513     gnus-newsgroup-active gnus-scores-exclude-files
1514     gnus-newsgroup-history gnus-newsgroup-ancient
1515     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1516     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1517     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1518     (gnus-newsgroup-expunged-tally . 0)
1519     gnus-cache-removable-articles gnus-newsgroup-cached
1520     gnus-newsgroup-data gnus-newsgroup-data-reverse
1521     gnus-newsgroup-limit gnus-newsgroup-limits
1522     gnus-newsgroup-charset gnus-newsgroup-display
1523     gnus-summary-use-undownloaded-faces)
1524   "Variables that are buffer-local to the summary buffers.")
1525
1526 (defvar gnus-newsgroup-variables nil
1527   "A list of variables that have separate values in different newsgroups.
1528 A list of newsgroup (summary buffer) local variables, or cons of
1529 variables and their default expressions to be evalled (when the default
1530 values are not nil), that should be made global while the summary buffer
1531 is active.
1532
1533 Note: The default expressions will be evaluated (using function `eval')
1534 before assignment to the local variable rather than just assigned to it.
1535 If the default expression is the symbol `global', that symbol will not
1536 be evaluated but the global value of the local variable will be used
1537 instead.
1538
1539 These variables can be used to set variables in the group parameters
1540 while still allowing them to affect operations done in other buffers.
1541 For example:
1542
1543 \(setq gnus-newsgroup-variables
1544      '(message-use-followup-to
1545        (gnus-visible-headers .
1546          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1547 ")
1548
1549 ;; Byte-compiler warning.
1550 (eval-when-compile
1551   ;; Bind features so that require will believe that gnus-sum has
1552   ;; already been loaded (avoids infinite recursion)
1553   (let ((features (cons 'gnus-sum features)))
1554     ;; Several of the declarations in gnus-sum are needed to load the
1555     ;; following files. Right now, these definitions have been
1556     ;; compiled but not defined (evaluated).  We could either do a
1557     ;; eval-and-compile about all of the declarations or evaluate the
1558     ;; source file.
1559     (if (boundp 'gnus-newsgroup-variables)
1560         nil
1561       (load "gnus-sum.el" t t t))
1562     (require 'gnus)
1563     (require 'gnus-art)))
1564
1565 ;; MIME stuff.
1566
1567 (defvar gnus-decode-encoded-word-methods
1568   '(mail-decode-encoded-word-string)
1569   "List of methods used to decode encoded words.
1570
1571 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1572 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1573 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1574 whose names match REGEXP.
1575
1576 For example:
1577 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1578  mail-decode-encoded-word-string
1579  (\"chinese\" . rfc1843-decode-string))")
1580
1581 (defvar gnus-decode-encoded-word-methods-cache nil)
1582
1583 (defun gnus-multi-decode-encoded-word-string (string)
1584   "Apply the functions from `gnus-encoded-word-methods' that match."
1585   (unless (and gnus-decode-encoded-word-methods-cache
1586                (eq gnus-newsgroup-name
1587                    (car gnus-decode-encoded-word-methods-cache)))
1588     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1589     (mapcar (lambda (x)
1590               (if (symbolp x)
1591                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1592                 (if (and gnus-newsgroup-name
1593                          (string-match (car x) gnus-newsgroup-name))
1594                     (nconc gnus-decode-encoded-word-methods-cache
1595                            (list (cdr x))))))
1596             gnus-decode-encoded-word-methods))
1597   (let ((xlist gnus-decode-encoded-word-methods-cache))
1598     (pop xlist)
1599     (while xlist
1600       (setq string (funcall (pop xlist) string))))
1601   string)
1602
1603 ;; Subject simplification.
1604
1605 (defun gnus-simplify-whitespace (str)
1606   "Remove excessive whitespace from STR."
1607   ;; Multiple spaces.
1608   (while (string-match "[ \t][ \t]+" str)
1609     (setq str (concat (substring str 0 (match-beginning 0))
1610                         " "
1611                         (substring str (match-end 0)))))
1612   ;; Leading spaces.
1613   (when (string-match "^[ \t]+" str)
1614     (setq str (substring str (match-end 0))))
1615   ;; Trailing spaces.
1616   (when (string-match "[ \t]+$" str)
1617     (setq str (substring str 0 (match-beginning 0))))
1618   str)
1619
1620 (defun gnus-simplify-all-whitespace (str)
1621   "Remove all whitespace from STR."
1622   (while (string-match "[ \t\n]+" str)
1623     (setq str (replace-match "" nil nil str)))
1624   str)
1625
1626 (defsubst gnus-simplify-subject-re (subject)
1627   "Remove \"Re:\" from subject lines."
1628   (if (string-match message-subject-re-regexp subject)
1629       (substring subject (match-end 0))
1630     subject))
1631
1632 (defun gnus-simplify-subject (subject &optional re-only)
1633   "Remove `Re:' and words in parentheses.
1634 If RE-ONLY is non-nil, strip leading `Re:'s only."
1635   (let ((case-fold-search t))           ;Ignore case.
1636     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1637     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1638       (setq subject (substring subject (match-end 0))))
1639     ;; Remove uninteresting prefixes.
1640     (when (and (not re-only)
1641                gnus-simplify-ignored-prefixes
1642                (string-match gnus-simplify-ignored-prefixes subject))
1643       (setq subject (substring subject (match-end 0))))
1644     ;; Remove words in parentheses from end.
1645     (unless re-only
1646       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1647         (setq subject (substring subject 0 (match-beginning 0)))))
1648     ;; Return subject string.
1649     subject))
1650
1651 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1652 ;; all whitespace.
1653 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1654   (goto-char (point-min))
1655   (while (re-search-forward regexp nil t)
1656     (replace-match (or newtext ""))))
1657
1658 (defun gnus-simplify-buffer-fuzzy ()
1659   "Simplify string in the buffer fuzzily.
1660 The string in the accessible portion of the current buffer is simplified.
1661 It is assumed to be a single-line subject.
1662 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1663 matter is removed.  Additional things can be deleted by setting
1664 `gnus-simplify-subject-fuzzy-regexp'."
1665   (let ((case-fold-search t)
1666         (modified-tick))
1667     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1668
1669     (while (not (eq modified-tick (buffer-modified-tick)))
1670       (setq modified-tick (buffer-modified-tick))
1671       (cond
1672        ((listp gnus-simplify-subject-fuzzy-regexp)
1673         (mapcar 'gnus-simplify-buffer-fuzzy-step
1674                 gnus-simplify-subject-fuzzy-regexp))
1675        (gnus-simplify-subject-fuzzy-regexp
1676         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1677       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1678       (gnus-simplify-buffer-fuzzy-step
1679        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1680       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1681
1682     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1683     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1684     (gnus-simplify-buffer-fuzzy-step " $")
1685     (gnus-simplify-buffer-fuzzy-step "^ +")))
1686
1687 (defun gnus-simplify-subject-fuzzy (subject)
1688   "Simplify a subject string fuzzily.
1689 See `gnus-simplify-buffer-fuzzy' for details."
1690   (save-excursion
1691     (gnus-set-work-buffer)
1692     (let ((case-fold-search t))
1693       ;; Remove uninteresting prefixes.
1694       (when (and gnus-simplify-ignored-prefixes
1695                  (string-match gnus-simplify-ignored-prefixes subject))
1696         (setq subject (substring subject (match-end 0))))
1697       (insert subject)
1698       (inline (gnus-simplify-buffer-fuzzy))
1699       (buffer-string))))
1700
1701 (defsubst gnus-simplify-subject-fully (subject)
1702   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1703   (cond
1704    (gnus-simplify-subject-functions
1705     (gnus-map-function gnus-simplify-subject-functions subject))
1706    ((null gnus-summary-gather-subject-limit)
1707     (gnus-simplify-subject-re subject))
1708    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1709     (gnus-simplify-subject-fuzzy subject))
1710    ((numberp gnus-summary-gather-subject-limit)
1711     (truncate-string-to-width (gnus-simplify-subject-re subject)
1712                               gnus-summary-gather-subject-limit))
1713    (t
1714     subject)))
1715
1716 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1717   "Check whether two subjects are equal.
1718 If optional argument SIMPLE-FIRST is t, first argument is already
1719 simplified."
1720   (cond
1721    ((null simple-first)
1722     (equal (gnus-simplify-subject-fully s1)
1723            (gnus-simplify-subject-fully s2)))
1724    (t
1725     (equal s1
1726            (gnus-simplify-subject-fully s2)))))
1727
1728 (defun gnus-summary-bubble-group ()
1729   "Increase the score of the current group.
1730 This is a handy function to add to `gnus-summary-exit-hook' to
1731 increase the score of each group you read."
1732   (gnus-group-add-score gnus-newsgroup-name))
1733
1734 \f
1735 ;;;
1736 ;;; Gnus summary mode
1737 ;;;
1738
1739 (put 'gnus-summary-mode 'mode-class 'special)
1740
1741 (defvar gnus-article-commands-menu)
1742
1743 ;; Non-orthogonal keys
1744
1745 (gnus-define-keys gnus-summary-mode-map
1746   " " gnus-summary-next-page
1747   "\177" gnus-summary-prev-page
1748   [delete] gnus-summary-prev-page
1749   [backspace] gnus-summary-prev-page
1750   "\r" gnus-summary-scroll-up
1751   "\M-\r" gnus-summary-scroll-down
1752   "n" gnus-summary-next-unread-article
1753   "p" gnus-summary-prev-unread-article
1754   "N" gnus-summary-next-article
1755   "P" gnus-summary-prev-article
1756   "\M-\C-n" gnus-summary-next-same-subject
1757   "\M-\C-p" gnus-summary-prev-same-subject
1758   "\M-n" gnus-summary-next-unread-subject
1759   "\M-p" gnus-summary-prev-unread-subject
1760   "." gnus-summary-first-unread-article
1761   "," gnus-summary-best-unread-article
1762   "\M-s" gnus-summary-search-article-forward
1763   "\M-r" gnus-summary-search-article-backward
1764   "\M-S" gnus-summary-repeat-search-article-forward
1765   "\M-R" gnus-summary-repeat-search-article-backward
1766   "<" gnus-summary-beginning-of-article
1767   ">" gnus-summary-end-of-article
1768   "j" gnus-summary-goto-article
1769   "^" gnus-summary-refer-parent-article
1770   "\M-^" gnus-summary-refer-article
1771   "u" gnus-summary-tick-article-forward
1772   "!" gnus-summary-tick-article-forward
1773   "U" gnus-summary-tick-article-backward
1774   "d" gnus-summary-mark-as-read-forward
1775   "D" gnus-summary-mark-as-read-backward
1776   "E" gnus-summary-mark-as-expirable
1777   "\M-u" gnus-summary-clear-mark-forward
1778   "\M-U" gnus-summary-clear-mark-backward
1779   "k" gnus-summary-kill-same-subject-and-select
1780   "\C-k" gnus-summary-kill-same-subject
1781   "\M-\C-k" gnus-summary-kill-thread
1782   "\M-\C-l" gnus-summary-lower-thread
1783   "e" gnus-summary-edit-article
1784   "#" gnus-summary-mark-as-processable
1785   "\M-#" gnus-summary-unmark-as-processable
1786   "\M-\C-t" gnus-summary-toggle-threads
1787   "\M-\C-s" gnus-summary-show-thread
1788   "\M-\C-h" gnus-summary-hide-thread
1789   "\M-\C-f" gnus-summary-next-thread
1790   "\M-\C-b" gnus-summary-prev-thread
1791   [(meta down)] gnus-summary-next-thread
1792   [(meta up)] gnus-summary-prev-thread
1793   "\M-\C-u" gnus-summary-up-thread
1794   "\M-\C-d" gnus-summary-down-thread
1795   "&" gnus-summary-execute-command
1796   "c" gnus-summary-catchup-and-exit
1797   "\C-w" gnus-summary-mark-region-as-read
1798   "\C-t" gnus-summary-toggle-truncation
1799   "?" gnus-summary-mark-as-dormant
1800   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1801   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1802   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1803   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1804   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1805   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1806   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1807   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1808   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1809   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1810   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1811   "=" gnus-summary-expand-window
1812   "\C-x\C-s" gnus-summary-reselect-current-group
1813   "\M-g" gnus-summary-rescan-group
1814   "w" gnus-summary-stop-page-breaking
1815   "\C-c\C-r" gnus-summary-caesar-message
1816   "f" gnus-summary-followup
1817   "F" gnus-summary-followup-with-original
1818   "C" gnus-summary-cancel-article
1819   "r" gnus-summary-reply
1820   "R" gnus-summary-reply-with-original
1821   "\C-c\C-f" gnus-summary-mail-forward
1822   "o" gnus-summary-save-article
1823   "\C-o" gnus-summary-save-article-mail
1824   "|" gnus-summary-pipe-output
1825   "\M-k" gnus-summary-edit-local-kill
1826   "\M-K" gnus-summary-edit-global-kill
1827   ;; "V" gnus-version
1828   "\C-c\C-d" gnus-summary-describe-group
1829   "q" gnus-summary-exit
1830   "Q" gnus-summary-exit-no-update
1831   "\C-c\C-i" gnus-info-find-node
1832   gnus-mouse-2 gnus-mouse-pick-article
1833   [follow-link] mouse-face
1834   "m" gnus-summary-mail-other-window
1835   "a" gnus-summary-post-news
1836   "i" gnus-summary-news-other-window
1837   "x" gnus-summary-limit-to-unread
1838   "s" gnus-summary-isearch-article
1839   "t" gnus-summary-toggle-header
1840   "g" gnus-summary-show-article
1841   "l" gnus-summary-goto-last-article
1842   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1843   "\C-d" gnus-summary-enter-digest-group
1844   "\M-\C-d" gnus-summary-read-document
1845   "\M-\C-e" gnus-summary-edit-parameters
1846   "\M-\C-a" gnus-summary-customize-parameters
1847   "\C-c\C-b" gnus-bug
1848   "*" gnus-cache-enter-article
1849   "\M-*" gnus-cache-remove-article
1850   "\M-&" gnus-summary-universal-argument
1851   "\C-l" gnus-recenter
1852   "I" gnus-summary-increase-score
1853   "L" gnus-summary-lower-score
1854   "\M-i" gnus-symbolic-argument
1855   "h" gnus-summary-select-article-buffer
1856
1857   "b" gnus-article-view-part
1858   "\M-t" gnus-summary-toggle-display-buttonized
1859
1860   "V" gnus-summary-score-map
1861   "X" gnus-uu-extract-map
1862   "S" gnus-summary-send-map)
1863
1864 ;; Sort of orthogonal keymap
1865 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1866   "t" gnus-summary-tick-article-forward
1867   "!" gnus-summary-tick-article-forward
1868   "d" gnus-summary-mark-as-read-forward
1869   "r" gnus-summary-mark-as-read-forward
1870   "c" gnus-summary-clear-mark-forward
1871   " " gnus-summary-clear-mark-forward
1872   "e" gnus-summary-mark-as-expirable
1873   "x" gnus-summary-mark-as-expirable
1874   "?" gnus-summary-mark-as-dormant
1875   "b" gnus-summary-set-bookmark
1876   "B" gnus-summary-remove-bookmark
1877   "#" gnus-summary-mark-as-processable
1878   "\M-#" gnus-summary-unmark-as-processable
1879   "S" gnus-summary-limit-include-expunged
1880   "C" gnus-summary-catchup
1881   "H" gnus-summary-catchup-to-here
1882   "h" gnus-summary-catchup-from-here
1883   "\C-c" gnus-summary-catchup-all
1884   "k" gnus-summary-kill-same-subject-and-select
1885   "K" gnus-summary-kill-same-subject
1886   "P" gnus-uu-mark-map)
1887
1888 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1889   "c" gnus-summary-clear-above
1890   "u" gnus-summary-tick-above
1891   "m" gnus-summary-mark-above
1892   "k" gnus-summary-kill-below)
1893
1894 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1895   "/" gnus-summary-limit-to-subject
1896   "n" gnus-summary-limit-to-articles
1897   "b" gnus-summary-limit-to-bodies
1898   "h" gnus-summary-limit-to-headers
1899   "w" gnus-summary-pop-limit
1900   "s" gnus-summary-limit-to-subject
1901   "a" gnus-summary-limit-to-author
1902   "u" gnus-summary-limit-to-unread
1903   "m" gnus-summary-limit-to-marks
1904   "M" gnus-summary-limit-exclude-marks
1905   "v" gnus-summary-limit-to-score
1906   "*" gnus-summary-limit-include-cached
1907   "D" gnus-summary-limit-include-dormant
1908   "T" gnus-summary-limit-include-thread
1909   "d" gnus-summary-limit-exclude-dormant
1910   "t" gnus-summary-limit-to-age
1911   "." gnus-summary-limit-to-unseen
1912   "x" gnus-summary-limit-to-extra
1913   "p" gnus-summary-limit-to-display-predicate
1914   "E" gnus-summary-limit-include-expunged
1915   "c" gnus-summary-limit-exclude-childless-dormant
1916   "C" gnus-summary-limit-mark-excluded-as-read
1917   "o" gnus-summary-insert-old-articles
1918   "N" gnus-summary-insert-new-articles
1919   "S" gnus-summary-limit-to-singletons
1920   "r" gnus-summary-limit-to-replied
1921   "R" gnus-summary-limit-to-recipient)
1922
1923 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1924   "n" gnus-summary-next-unread-article
1925   "p" gnus-summary-prev-unread-article
1926   "N" gnus-summary-next-article
1927   "P" gnus-summary-prev-article
1928   "\C-n" gnus-summary-next-same-subject
1929   "\C-p" gnus-summary-prev-same-subject
1930   "\M-n" gnus-summary-next-unread-subject
1931   "\M-p" gnus-summary-prev-unread-subject
1932   "f" gnus-summary-first-unread-article
1933   "b" gnus-summary-best-unread-article
1934   "j" gnus-summary-goto-article
1935   "g" gnus-summary-goto-subject
1936   "l" gnus-summary-goto-last-article
1937   "o" gnus-summary-pop-article)
1938
1939 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1940   "k" gnus-summary-kill-thread
1941   "l" gnus-summary-lower-thread
1942   "i" gnus-summary-raise-thread
1943   "T" gnus-summary-toggle-threads
1944   "t" gnus-summary-rethread-current
1945   "^" gnus-summary-reparent-thread
1946   "\M-^" gnus-summary-reparent-children
1947   "s" gnus-summary-show-thread
1948   "S" gnus-summary-show-all-threads
1949   "h" gnus-summary-hide-thread
1950   "H" gnus-summary-hide-all-threads
1951   "n" gnus-summary-next-thread
1952   "p" gnus-summary-prev-thread
1953   "u" gnus-summary-up-thread
1954   "o" gnus-summary-top-thread
1955   "d" gnus-summary-down-thread
1956   "#" gnus-uu-mark-thread
1957   "\M-#" gnus-uu-unmark-thread)
1958
1959 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1960   "g" gnus-summary-prepare
1961   "c" gnus-summary-insert-cached-articles
1962   "d" gnus-summary-insert-dormant-articles
1963   "t" gnus-summary-insert-ticked-articles)
1964
1965 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1966   "c" gnus-summary-catchup-and-exit
1967   "C" gnus-summary-catchup-all-and-exit
1968   "E" gnus-summary-exit-no-update
1969   "Q" gnus-summary-exit
1970   "Z" gnus-summary-exit
1971   "n" gnus-summary-catchup-and-goto-next-group
1972   "p" gnus-summary-catchup-and-goto-prev-group
1973   "R" gnus-summary-reselect-current-group
1974   "G" gnus-summary-rescan-group
1975   "N" gnus-summary-next-group
1976   "s" gnus-summary-save-newsrc
1977   "P" gnus-summary-prev-group)
1978
1979 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1980   " " gnus-summary-next-page
1981   "n" gnus-summary-next-page
1982   "\177" gnus-summary-prev-page
1983   [delete] gnus-summary-prev-page
1984   "p" gnus-summary-prev-page
1985   "\r" gnus-summary-scroll-up
1986   "\M-\r" gnus-summary-scroll-down
1987   "<" gnus-summary-beginning-of-article
1988   ">" gnus-summary-end-of-article
1989   "b" gnus-summary-beginning-of-article
1990   "e" gnus-summary-end-of-article
1991   "^" gnus-summary-refer-parent-article
1992   "r" gnus-summary-refer-parent-article
1993   "D" gnus-summary-enter-digest-group
1994   "R" gnus-summary-refer-references
1995   "T" gnus-summary-refer-thread
1996   "g" gnus-summary-show-article
1997   "s" gnus-summary-isearch-article
1998   "P" gnus-summary-print-article
1999   "M" gnus-mailing-list-insinuate
2000   "t" gnus-article-babel)
2001
2002 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2003   "b" gnus-article-add-buttons
2004   "B" gnus-article-add-buttons-to-head
2005   "o" gnus-article-treat-overstrike
2006   "e" gnus-article-emphasize
2007   "w" gnus-article-fill-cited-article
2008   "Q" gnus-article-fill-long-lines
2009   "L" gnus-article-toggle-truncate-lines
2010   "C" gnus-article-capitalize-sentences
2011   "c" gnus-article-remove-cr
2012   "q" gnus-article-de-quoted-unreadable
2013   "6" gnus-article-de-base64-unreadable
2014   "Z" gnus-article-decode-HZ
2015   "A" gnus-article-treat-ansi-sequences
2016   "h" gnus-article-wash-html
2017   "u" gnus-article-unsplit-urls
2018   "s" gnus-summary-force-verify-and-decrypt
2019   "f" gnus-article-display-x-face
2020   "l" gnus-summary-stop-page-breaking
2021   "r" gnus-summary-caesar-message
2022   "m" gnus-summary-morse-message
2023   "t" gnus-summary-toggle-header
2024   "g" gnus-treat-smiley
2025   "v" gnus-summary-verbose-headers
2026   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2027   "p" gnus-article-verify-x-pgp-sig
2028   "d" gnus-article-treat-dumbquotes
2029   "i" gnus-summary-idna-message)
2030
2031 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2032   ;; mnemonic: deuglif*Y*
2033   "u" gnus-article-outlook-unwrap-lines
2034   "a" gnus-article-outlook-repair-attribution
2035   "c" gnus-article-outlook-rearrange-citation
2036   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2037
2038 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2039   "a" gnus-article-hide
2040   "h" gnus-article-hide-headers
2041   "b" gnus-article-hide-boring-headers
2042   "s" gnus-article-hide-signature
2043   "c" gnus-article-hide-citation
2044   "C" gnus-article-hide-citation-in-followups
2045   "l" gnus-article-hide-list-identifiers
2046   "B" gnus-article-strip-banner
2047   "P" gnus-article-hide-pem
2048   "\C-c" gnus-article-hide-citation-maybe)
2049
2050 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2051   "a" gnus-article-highlight
2052   "h" gnus-article-highlight-headers
2053   "c" gnus-article-highlight-citation
2054   "s" gnus-article-highlight-signature)
2055
2056 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2057   "f" gnus-article-treat-fold-headers
2058   "u" gnus-article-treat-unfold-headers
2059   "n" gnus-article-treat-fold-newsgroups)
2060
2061 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2062   "x" gnus-article-display-x-face
2063   "d" gnus-article-display-face
2064   "s" gnus-treat-smiley
2065   "D" gnus-article-remove-images
2066   "f" gnus-treat-from-picon
2067   "m" gnus-treat-mail-picon
2068   "n" gnus-treat-newsgroups-picon)
2069
2070 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2071   "w" gnus-article-decode-mime-words
2072   "c" gnus-article-decode-charset
2073   "v" gnus-mime-view-all-parts
2074   "b" gnus-article-view-part)
2075
2076 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2077   "z" gnus-article-date-ut
2078   "u" gnus-article-date-ut
2079   "l" gnus-article-date-local
2080   "p" gnus-article-date-english
2081   "e" gnus-article-date-lapsed
2082   "o" gnus-article-date-original
2083   "i" gnus-article-date-iso8601
2084   "s" gnus-article-date-user)
2085
2086 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2087   "t" gnus-article-remove-trailing-blank-lines
2088   "l" gnus-article-strip-leading-blank-lines
2089   "m" gnus-article-strip-multiple-blank-lines
2090   "a" gnus-article-strip-blank-lines
2091   "A" gnus-article-strip-all-blank-lines
2092   "s" gnus-article-strip-leading-space
2093   "e" gnus-article-strip-trailing-space
2094   "w" gnus-article-remove-leading-whitespace)
2095
2096 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2097   "v" gnus-version
2098   "f" gnus-summary-fetch-faq
2099   "d" gnus-summary-describe-group
2100   "h" gnus-summary-describe-briefly
2101   "i" gnus-info-find-node
2102   "c" gnus-group-fetch-charter
2103   "C" gnus-group-fetch-control)
2104
2105 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2106   "e" gnus-summary-expire-articles
2107   "\M-\C-e" gnus-summary-expire-articles-now
2108   "\177" gnus-summary-delete-article
2109   [delete] gnus-summary-delete-article
2110   [backspace] gnus-summary-delete-article
2111   "m" gnus-summary-move-article
2112   "r" gnus-summary-respool-article
2113   "w" gnus-summary-edit-article
2114   "c" gnus-summary-copy-article
2115   "B" gnus-summary-crosspost-article
2116   "q" gnus-summary-respool-query
2117   "t" gnus-summary-respool-trace
2118   "i" gnus-summary-import-article
2119   "I" gnus-summary-create-article
2120   "p" gnus-summary-article-posted-p)
2121
2122 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2123   "o" gnus-summary-save-article
2124   "m" gnus-summary-save-article-mail
2125   "F" gnus-summary-write-article-file
2126   "r" gnus-summary-save-article-rmail
2127   "f" gnus-summary-save-article-file
2128   "b" gnus-summary-save-article-body-file
2129   "B" gnus-summary-write-article-body-file
2130   "h" gnus-summary-save-article-folder
2131   "v" gnus-summary-save-article-vm
2132   "p" gnus-summary-pipe-output
2133   "P" gnus-summary-muttprint
2134   "s" gnus-soup-add-article)
2135
2136 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2137   "b" gnus-summary-display-buttonized
2138   "m" gnus-summary-repair-multipart
2139   "v" gnus-article-view-part
2140   "o" gnus-article-save-part
2141   "O" gnus-article-save-part-and-strip
2142   "r" gnus-article-replace-part
2143   "d" gnus-article-delete-part
2144   "t" gnus-article-view-part-as-type
2145   "j" gnus-article-jump-to-part
2146   "c" gnus-article-copy-part
2147   "C" gnus-article-view-part-as-charset
2148   "e" gnus-article-view-part-externally
2149   "H" gnus-article-browse-html-article
2150   "E" gnus-article-encrypt-body
2151   "i" gnus-article-inline-part
2152   "|" gnus-article-pipe-part)
2153
2154 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2155   "p" gnus-summary-mark-as-processable
2156   "u" gnus-summary-unmark-as-processable
2157   "U" gnus-summary-unmark-all-processable
2158   "v" gnus-uu-mark-over
2159   "s" gnus-uu-mark-series
2160   "r" gnus-uu-mark-region
2161   "g" gnus-uu-unmark-region
2162   "R" gnus-uu-mark-by-regexp
2163   "G" gnus-uu-unmark-by-regexp
2164   "t" gnus-uu-mark-thread
2165   "T" gnus-uu-unmark-thread
2166   "a" gnus-uu-mark-all
2167   "b" gnus-uu-mark-buffer
2168   "S" gnus-uu-mark-sparse
2169   "k" gnus-summary-kill-process-mark
2170   "y" gnus-summary-yank-process-mark
2171   "w" gnus-summary-save-process-mark
2172   "i" gnus-uu-invert-processable)
2173
2174 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2175   ;;"x" gnus-uu-extract-any
2176   "m" gnus-summary-save-parts
2177   "u" gnus-uu-decode-uu
2178   "U" gnus-uu-decode-uu-and-save
2179   "s" gnus-uu-decode-unshar
2180   "S" gnus-uu-decode-unshar-and-save
2181   "o" gnus-uu-decode-save
2182   "O" gnus-uu-decode-save
2183   "b" gnus-uu-decode-binhex
2184   "B" gnus-uu-decode-binhex
2185   "p" gnus-uu-decode-postscript
2186   "P" gnus-uu-decode-postscript-and-save)
2187
2188 (gnus-define-keys
2189     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2190   "u" gnus-uu-decode-uu-view
2191   "U" gnus-uu-decode-uu-and-save-view
2192   "s" gnus-uu-decode-unshar-view
2193   "S" gnus-uu-decode-unshar-and-save-view
2194   "o" gnus-uu-decode-save-view
2195   "O" gnus-uu-decode-save-view
2196   "b" gnus-uu-decode-binhex-view
2197   "B" gnus-uu-decode-binhex-view
2198   "p" gnus-uu-decode-postscript-view
2199   "P" gnus-uu-decode-postscript-and-save-view)
2200
2201 (defvar gnus-article-post-menu nil)
2202
2203 (defconst gnus-summary-menu-maxlen 20)
2204
2205 (defun gnus-summary-menu-split (menu)
2206   ;; If we have lots of elements, divide them into groups of 20
2207   ;; and make a pane (or submenu) for each one.
2208   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2209       (let ((menu menu) sublists next
2210             (i 1))
2211         (while menu
2212           ;; Pull off the next gnus-summary-menu-maxlen elements
2213           ;; and make them the next element of sublist.
2214           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2215           (if next
2216               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2217                       nil))
2218           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2219                                              (aref (car (last menu)) 0)) menu)
2220                                sublists))
2221           (setq i (1+ i))
2222           (setq menu next))
2223         (nreverse sublists))
2224     ;; Few elements--put them all in one pane.
2225     menu))
2226
2227 (defun gnus-summary-make-menu-bar ()
2228   (gnus-turn-off-edit-menu 'summary)
2229
2230   (unless (boundp 'gnus-summary-misc-menu)
2231
2232     (easy-menu-define
2233       gnus-summary-kill-menu gnus-summary-mode-map ""
2234       (cons
2235        "Score"
2236        (nconc
2237         (list
2238          ["Customize" gnus-score-customize t])
2239         (gnus-make-score-map 'increase)
2240         (gnus-make-score-map 'lower)
2241         '(("Mark"
2242            ["Kill below" gnus-summary-kill-below t]
2243            ["Mark above" gnus-summary-mark-above t]
2244            ["Tick above" gnus-summary-tick-above t]
2245            ["Clear above" gnus-summary-clear-above t])
2246           ["Current score" gnus-summary-current-score t]
2247           ["Set score" gnus-summary-set-score t]
2248           ["Switch current score file..." gnus-score-change-score-file t]
2249           ["Set mark below..." gnus-score-set-mark-below t]
2250           ["Set expunge below..." gnus-score-set-expunge-below t]
2251           ["Edit current score file" gnus-score-edit-current-scores t]
2252           ["Edit score file" gnus-score-edit-file t]
2253           ["Trace score" gnus-score-find-trace t]
2254           ["Find words" gnus-score-find-favourite-words t]
2255           ["Rescore buffer" gnus-summary-rescore t]
2256           ["Increase score..." gnus-summary-increase-score t]
2257           ["Lower score..." gnus-summary-lower-score t]))))
2258
2259     ;; Define both the Article menu in the summary buffer and the
2260     ;; equivalent Commands menu in the article buffer here for
2261     ;; consistency.
2262     (let ((innards
2263            `(("Hide"
2264               ["All" gnus-article-hide t]
2265               ["Headers" gnus-article-hide-headers t]
2266               ["Signature" gnus-article-hide-signature t]
2267               ["Citation" gnus-article-hide-citation t]
2268               ["List identifiers" gnus-article-hide-list-identifiers t]
2269               ["Banner" gnus-article-strip-banner t]
2270               ["Boring headers" gnus-article-hide-boring-headers t])
2271              ("Highlight"
2272               ["All" gnus-article-highlight t]
2273               ["Headers" gnus-article-highlight-headers t]
2274               ["Signature" gnus-article-highlight-signature t]
2275               ["Citation" gnus-article-highlight-citation t])
2276              ("MIME"
2277               ["Words" gnus-article-decode-mime-words t]
2278               ["Charset" gnus-article-decode-charset t]
2279               ["QP" gnus-article-de-quoted-unreadable t]
2280               ["Base64" gnus-article-de-base64-unreadable t]
2281               ["View MIME buttons" gnus-summary-display-buttonized t]
2282               ["View all" gnus-mime-view-all-parts t]
2283               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2284               ["Encrypt body" gnus-article-encrypt-body
2285                :active (not (gnus-group-read-only-p))
2286                ,@(if (featurep 'xemacs) nil
2287                    '(:help "Encrypt the message body on disk"))]
2288               ["Extract all parts..." gnus-summary-save-parts t]
2289               ("Multipart"
2290                ["Repair multipart" gnus-summary-repair-multipart t]
2291                ["Pipe part..." gnus-article-pipe-part t]
2292                ["Inline part" gnus-article-inline-part t]
2293                ["View part as type..." gnus-article-view-part-as-type t]
2294                ["Encrypt body" gnus-article-encrypt-body
2295                 :active (not (gnus-group-read-only-p))
2296                ,@(if (featurep 'xemacs) nil
2297                    '(:help "Encrypt the message body on disk"))]
2298                ["View part externally" gnus-article-view-part-externally t]
2299                ["View HTML parts in browser" gnus-article-browse-html-article t]
2300                ["View part with charset..." gnus-article-view-part-as-charset t]
2301                ["Copy part" gnus-article-copy-part t]
2302                ["Save part..." gnus-article-save-part t]
2303                ["View part" gnus-article-view-part t]))
2304              ("Date"
2305               ["Local" gnus-article-date-local t]
2306               ["ISO8601" gnus-article-date-iso8601 t]
2307               ["UT" gnus-article-date-ut t]
2308               ["Original" gnus-article-date-original t]
2309               ["Lapsed" gnus-article-date-lapsed t]
2310               ["User-defined" gnus-article-date-user t])
2311              ("Display"
2312               ["Remove images" gnus-article-remove-images t]
2313               ["Toggle smiley" gnus-treat-smiley t]
2314               ["Show X-Face" gnus-article-display-x-face t]
2315               ["Show picons in From" gnus-treat-from-picon t]
2316               ["Show picons in mail headers" gnus-treat-mail-picon t]
2317               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2318               ("View as different encoding"
2319                ,@(gnus-summary-menu-split
2320                   (mapcar
2321                    (lambda (cs)
2322                      ;; Since easymenu under Emacs doesn't allow
2323                      ;; lambda forms for menu commands, we should
2324                      ;; provide intern'ed function symbols.
2325                      (let ((command (intern (format "\
2326 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2327                        (fset command
2328                              `(lambda ()
2329                                 (interactive)
2330                                 (let ((gnus-summary-show-article-charset-alist
2331                                        '((1 . ,cs))))
2332                                   (gnus-summary-show-article 1))))
2333                        `[,(symbol-name cs) ,command t]))
2334                    (sort (if (fboundp 'coding-system-list)
2335                              (coding-system-list)
2336                            (mapcar 'car mm-mime-mule-charset-alist))
2337                          'string<)))))
2338              ("Washing"
2339               ("Remove Blanks"
2340                ["Leading" gnus-article-strip-leading-blank-lines t]
2341                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2342                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2343                ["All of the above" gnus-article-strip-blank-lines t]
2344                ["All" gnus-article-strip-all-blank-lines t]
2345                ["Leading space" gnus-article-strip-leading-space t]
2346                ["Trailing space" gnus-article-strip-trailing-space t]
2347                ["Leading space in headers"
2348                 gnus-article-remove-leading-whitespace t])
2349               ["Overstrike" gnus-article-treat-overstrike t]
2350               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2351               ["Emphasis" gnus-article-emphasize t]
2352               ["Word wrap" gnus-article-fill-cited-article t]
2353               ["Fill long lines" gnus-article-fill-long-lines t]
2354               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2355               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2356               ["Remove CR" gnus-article-remove-cr t]
2357               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2358               ["Base64" gnus-article-de-base64-unreadable t]
2359               ["Rot 13" gnus-summary-caesar-message
2360                ,@(if (featurep 'xemacs) '(t)
2361                    '(:help "\"Caesar rotate\" article by 13"))]
2362               ["De-IDNA" gnus-summary-idna-message t]
2363               ["Morse decode" gnus-summary-morse-message t]
2364               ["Unix pipe..." gnus-summary-pipe-message t]
2365               ["Add buttons" gnus-article-add-buttons t]
2366               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2367               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2368               ["Verbose header" gnus-summary-verbose-headers t]
2369               ["Toggle header" gnus-summary-toggle-header t]
2370               ["Unfold headers" gnus-article-treat-unfold-headers t]
2371               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2372               ["Html" gnus-article-wash-html t]
2373               ["Unsplit URLs" gnus-article-unsplit-urls t]
2374               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2375               ["Decode HZ" gnus-article-decode-HZ t]
2376               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2377               ("(Outlook) Deuglify"
2378                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2379                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2380                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2381                ["Full (Outlook) deuglify"
2382                 gnus-article-outlook-deuglify-article t])
2383               )
2384              ("Output"
2385               ["Save in default format..." gnus-summary-save-article
2386                ,@(if (featurep 'xemacs) '(t)
2387                    '(:help "Save article using default method"))]
2388               ["Save in file..." gnus-summary-save-article-file
2389                ,@(if (featurep 'xemacs) '(t)
2390                    '(:help "Save article in file"))]
2391               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2392               ["Save in MH folder..." gnus-summary-save-article-folder t]
2393               ["Save in VM folder..." gnus-summary-save-article-vm t]
2394               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2395               ["Save body in file..." gnus-summary-save-article-body-file t]
2396               ["Pipe through a filter..." gnus-summary-pipe-output t]
2397               ["Add to SOUP packet" gnus-soup-add-article t]
2398               ["Print with Muttprint..." gnus-summary-muttprint t]
2399               ["Print" gnus-summary-print-article
2400                ,@(if (featurep 'xemacs) '(t)
2401                    '(:help "Generate and print a PostScript image"))])
2402              ("Copy, move,... (Backend)"
2403               ,@(if (featurep 'xemacs) nil
2404                   '(:help "Copying, moving, expiring articles..."))
2405               ["Respool article..." gnus-summary-respool-article t]
2406               ["Move article..." gnus-summary-move-article
2407                (gnus-check-backend-function
2408                 'request-move-article gnus-newsgroup-name)]
2409               ["Copy article..." gnus-summary-copy-article t]
2410               ["Crosspost article..." gnus-summary-crosspost-article
2411                (gnus-check-backend-function
2412                 'request-replace-article gnus-newsgroup-name)]
2413               ["Import file..." gnus-summary-import-article
2414                (gnus-check-backend-function
2415                 'request-accept-article gnus-newsgroup-name)]
2416               ["Create article..." gnus-summary-create-article
2417                (gnus-check-backend-function
2418                 'request-accept-article gnus-newsgroup-name)]
2419               ["Check if posted" gnus-summary-article-posted-p t]
2420               ["Edit article" gnus-summary-edit-article
2421                (not (gnus-group-read-only-p))]
2422               ["Delete article" gnus-summary-delete-article
2423                (gnus-check-backend-function
2424                 'request-expire-articles gnus-newsgroup-name)]
2425               ["Query respool" gnus-summary-respool-query t]
2426               ["Trace respool" gnus-summary-respool-trace t]
2427               ["Delete expirable articles" gnus-summary-expire-articles-now
2428                (gnus-check-backend-function
2429                 'request-expire-articles gnus-newsgroup-name)])
2430              ("Extract"
2431               ["Uudecode" gnus-uu-decode-uu
2432                ,@(if (featurep 'xemacs) '(t)
2433                    '(:help "Decode uuencoded article(s)"))]
2434               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2435               ["Unshar" gnus-uu-decode-unshar t]
2436               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2437               ["Save" gnus-uu-decode-save t]
2438               ["Binhex" gnus-uu-decode-binhex t]
2439               ["Postscript" gnus-uu-decode-postscript t]
2440               ["All MIME parts" gnus-summary-save-parts t])
2441              ("Cache"
2442               ["Enter article" gnus-cache-enter-article t]
2443               ["Remove article" gnus-cache-remove-article t])
2444              ["Translate" gnus-article-babel t]
2445              ["Select article buffer" gnus-summary-select-article-buffer t]
2446              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2447              ["Isearch article..." gnus-summary-isearch-article t]
2448              ["Beginning of the article" gnus-summary-beginning-of-article t]
2449              ["End of the article" gnus-summary-end-of-article t]
2450              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2451              ["Fetch referenced articles" gnus-summary-refer-references t]
2452              ["Fetch current thread" gnus-summary-refer-thread t]
2453              ["Fetch article with id..." gnus-summary-refer-article t]
2454              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2455              ["Redisplay" gnus-summary-show-article t]
2456              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2457       (easy-menu-define
2458         gnus-summary-article-menu gnus-summary-mode-map ""
2459         (cons "Article" innards))
2460
2461       (if (not (keymapp gnus-summary-article-menu))
2462           (easy-menu-define
2463             gnus-article-commands-menu gnus-article-mode-map ""
2464             (cons "Commands" innards))
2465         ;; in Emacs, don't share menu.
2466         (setq gnus-article-commands-menu
2467               (copy-keymap gnus-summary-article-menu))
2468         (define-key gnus-article-mode-map [menu-bar commands]
2469           (cons "Commands" gnus-article-commands-menu))))
2470
2471     (easy-menu-define
2472       gnus-summary-thread-menu gnus-summary-mode-map ""
2473       '("Threads"
2474         ["Find all messages in thread" gnus-summary-refer-thread t]
2475         ["Toggle threading" gnus-summary-toggle-threads t]
2476         ["Hide threads" gnus-summary-hide-all-threads t]
2477         ["Show threads" gnus-summary-show-all-threads t]
2478         ["Hide thread" gnus-summary-hide-thread t]
2479         ["Show thread" gnus-summary-show-thread t]
2480         ["Go to next thread" gnus-summary-next-thread t]
2481         ["Go to previous thread" gnus-summary-prev-thread t]
2482         ["Go down thread" gnus-summary-down-thread t]
2483         ["Go up thread" gnus-summary-up-thread t]
2484         ["Top of thread" gnus-summary-top-thread t]
2485         ["Mark thread as read" gnus-summary-kill-thread t]
2486         ["Lower thread score" gnus-summary-lower-thread t]
2487         ["Raise thread score" gnus-summary-raise-thread t]
2488         ["Rethread current" gnus-summary-rethread-current t]))
2489
2490     (easy-menu-define
2491       gnus-summary-post-menu gnus-summary-mode-map ""
2492       `("Post"
2493         ["Send a message (mail or news)" gnus-summary-post-news
2494          ,@(if (featurep 'xemacs) '(t)
2495              '(:help "Compose a new message (mail or news)"))]
2496         ["Followup" gnus-summary-followup
2497          ,@(if (featurep 'xemacs) '(t)
2498              '(:help "Post followup to this article"))]
2499         ["Followup and yank" gnus-summary-followup-with-original
2500          ,@(if (featurep 'xemacs) '(t)
2501              '(:help "Post followup to this article, quoting its contents"))]
2502         ["Supersede article" gnus-summary-supersede-article t]
2503         ["Cancel article" gnus-summary-cancel-article
2504          ,@(if (featurep 'xemacs) '(t)
2505              '(:help "Cancel an article you posted"))]
2506         ["Reply" gnus-summary-reply t]
2507         ["Reply and yank" gnus-summary-reply-with-original t]
2508         ["Wide reply" gnus-summary-wide-reply t]
2509         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2510          ,@(if (featurep 'xemacs) '(t)
2511              '(:help "Mail a reply, quoting this article"))]
2512         ["Very wide reply" gnus-summary-very-wide-reply t]
2513         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2514          ,@(if (featurep 'xemacs) '(t)
2515              '(:help "Mail a very wide reply, quoting this article"))]
2516         ["Mail forward" gnus-summary-mail-forward t]
2517         ["Post forward" gnus-summary-post-forward t]
2518         ["Digest and mail" gnus-uu-digest-mail-forward t]
2519         ["Digest and post" gnus-uu-digest-post-forward t]
2520         ["Resend message" gnus-summary-resend-message t]
2521         ["Resend message edit" gnus-summary-resend-message-edit t]
2522         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2523         ["Send a mail" gnus-summary-mail-other-window t]
2524         ["Create a local message" gnus-summary-news-other-window t]
2525         ["Uuencode and post" gnus-uu-post-news
2526          ,@(if (featurep 'xemacs) '(t)
2527              '(:help "Post a uuencoded article"))]
2528         ["Followup via news" gnus-summary-followup-to-mail t]
2529         ["Followup via news and yank"
2530          gnus-summary-followup-to-mail-with-original t]
2531         ;;("Draft"
2532         ;;["Send" gnus-summary-send-draft t]
2533         ;;["Send bounced" gnus-resend-bounced-mail t])
2534         ))
2535
2536     (cond
2537      ((not (keymapp gnus-summary-post-menu))
2538       (setq gnus-article-post-menu gnus-summary-post-menu))
2539      ((not gnus-article-post-menu)
2540       ;; Don't share post menu.
2541       (setq gnus-article-post-menu
2542             (copy-keymap gnus-summary-post-menu))))
2543     (define-key gnus-article-mode-map [menu-bar post]
2544       (cons "Post" gnus-article-post-menu))
2545
2546     (easy-menu-define
2547       gnus-summary-misc-menu gnus-summary-mode-map ""
2548       `("Gnus"
2549         ("Mark Read"
2550          ["Mark as read" gnus-summary-mark-as-read-forward t]
2551          ["Mark same subject and select"
2552           gnus-summary-kill-same-subject-and-select t]
2553          ["Mark same subject" gnus-summary-kill-same-subject t]
2554          ["Catchup" gnus-summary-catchup
2555           ,@(if (featurep 'xemacs) '(t)
2556               '(:help "Mark unread articles in this group as read"))]
2557          ["Catchup all" gnus-summary-catchup-all t]
2558          ["Catchup to here" gnus-summary-catchup-to-here t]
2559          ["Catchup from here" gnus-summary-catchup-from-here t]
2560          ["Catchup region" gnus-summary-mark-region-as-read
2561           (gnus-mark-active-p)]
2562          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2563         ("Mark Various"
2564          ["Tick" gnus-summary-tick-article-forward t]
2565          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2566          ["Remove marks" gnus-summary-clear-mark-forward t]
2567          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2568          ["Set bookmark" gnus-summary-set-bookmark t]
2569          ["Remove bookmark" gnus-summary-remove-bookmark t])
2570         ("Limit to"
2571          ["Marks..." gnus-summary-limit-to-marks t]
2572          ["Subject..." gnus-summary-limit-to-subject t]
2573          ["Author..." gnus-summary-limit-to-author t]
2574          ["Recipient..." gnus-summary-limit-to-recipient t]
2575          ["Age..." gnus-summary-limit-to-age t]
2576          ["Extra..." gnus-summary-limit-to-extra t]
2577          ["Score..." gnus-summary-limit-to-score t]
2578          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2579          ["Unread" gnus-summary-limit-to-unread t]
2580          ["Unseen" gnus-summary-limit-to-unseen t]
2581          ["Singletons" gnus-summary-limit-to-singletons t]
2582          ["Replied" gnus-summary-limit-to-replied t]
2583          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2584          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2585          ["Pop limit" gnus-summary-pop-limit t]
2586          ["Show dormant" gnus-summary-limit-include-dormant t]
2587          ["Hide childless dormant"
2588           gnus-summary-limit-exclude-childless-dormant t]
2589          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2590          ["Hide marked" gnus-summary-limit-exclude-marks t]
2591          ["Show expunged" gnus-summary-limit-include-expunged t])
2592         ("Process Mark"
2593          ["Set mark" gnus-summary-mark-as-processable t]
2594          ["Remove mark" gnus-summary-unmark-as-processable t]
2595          ["Remove all marks" gnus-summary-unmark-all-processable t]
2596          ["Invert marks" gnus-uu-invert-processable t]
2597          ["Mark above" gnus-uu-mark-over t]
2598          ["Mark series" gnus-uu-mark-series t]
2599          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2600          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2601          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2602          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2603          ["Mark all" gnus-uu-mark-all t]
2604          ["Mark buffer" gnus-uu-mark-buffer t]
2605          ["Mark sparse" gnus-uu-mark-sparse t]
2606          ["Mark thread" gnus-uu-mark-thread t]
2607          ["Unmark thread" gnus-uu-unmark-thread t]
2608          ("Process Mark Sets"
2609           ["Kill" gnus-summary-kill-process-mark t]
2610           ["Yank" gnus-summary-yank-process-mark
2611            gnus-newsgroup-process-stack]
2612           ["Save" gnus-summary-save-process-mark t]
2613           ["Run command on marked..." gnus-summary-universal-argument t]))
2614         ("Scroll article"
2615          ["Page forward" gnus-summary-next-page
2616           ,@(if (featurep 'xemacs) '(t)
2617               '(:help "Show next page of article"))]
2618          ["Page backward" gnus-summary-prev-page
2619           ,@(if (featurep 'xemacs) '(t)
2620               '(:help "Show previous page of article"))]
2621          ["Line forward" gnus-summary-scroll-up t])
2622         ("Move"
2623          ["Next unread article" gnus-summary-next-unread-article t]
2624          ["Previous unread article" gnus-summary-prev-unread-article t]
2625          ["Next article" gnus-summary-next-article t]
2626          ["Previous article" gnus-summary-prev-article t]
2627          ["Next unread subject" gnus-summary-next-unread-subject t]
2628          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2629          ["Next article same subject" gnus-summary-next-same-subject t]
2630          ["Previous article same subject" gnus-summary-prev-same-subject t]
2631          ["First unread article" gnus-summary-first-unread-article t]
2632          ["Best unread article" gnus-summary-best-unread-article t]
2633          ["Go to subject number..." gnus-summary-goto-subject t]
2634          ["Go to article number..." gnus-summary-goto-article t]
2635          ["Go to the last article" gnus-summary-goto-last-article t]
2636          ["Pop article off history" gnus-summary-pop-article t])
2637         ("Sort"
2638          ["Sort by number" gnus-summary-sort-by-number t]
2639          ["Sort by author" gnus-summary-sort-by-author t]
2640          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2641          ["Sort by subject" gnus-summary-sort-by-subject t]
2642          ["Sort by date" gnus-summary-sort-by-date t]
2643          ["Sort by score" gnus-summary-sort-by-score t]
2644          ["Sort by lines" gnus-summary-sort-by-lines t]
2645          ["Sort by characters" gnus-summary-sort-by-chars t]
2646          ["Randomize" gnus-summary-sort-by-random t]
2647          ["Original sort" gnus-summary-sort-by-original t])
2648         ("Help"
2649          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2650          ["Describe group" gnus-summary-describe-group t]
2651          ["Fetch charter" gnus-group-fetch-charter
2652           ,@(if (featurep 'xemacs) nil
2653               '(:help "Display the charter of the current group"))]
2654          ["Fetch control message" gnus-group-fetch-control
2655           ,@(if (featurep 'xemacs) nil
2656               '(:help "Display the archived control message for the current group"))]
2657          ["Read manual" gnus-info-find-node t])
2658         ("Modes"
2659          ["Pick and read" gnus-pick-mode t]
2660          ["Binary" gnus-binary-mode t])
2661         ("Regeneration"
2662          ["Regenerate" gnus-summary-prepare t]
2663          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2664          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2665          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2666          ["Toggle threading" gnus-summary-toggle-threads t])
2667         ["See old articles" gnus-summary-insert-old-articles t]
2668         ["See new articles" gnus-summary-insert-new-articles t]
2669         ["Filter articles..." gnus-summary-execute-command t]
2670         ["Run command on articles..." gnus-summary-universal-argument t]
2671         ["Search articles forward..." gnus-summary-search-article-forward t]
2672         ["Search articles backward..." gnus-summary-search-article-backward t]
2673         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2674         ["Expand window" gnus-summary-expand-window t]
2675         ["Expire expirable articles" gnus-summary-expire-articles
2676          (gnus-check-backend-function
2677           'request-expire-articles gnus-newsgroup-name)]
2678         ["Edit local kill file" gnus-summary-edit-local-kill t]
2679         ["Edit main kill file" gnus-summary-edit-global-kill t]
2680         ["Edit group parameters" gnus-summary-edit-parameters t]
2681         ["Customize group parameters" gnus-summary-customize-parameters t]
2682         ["Send a bug report" gnus-bug t]
2683         ("Exit"
2684          ["Catchup and exit" gnus-summary-catchup-and-exit
2685           ,@(if (featurep 'xemacs) '(t)
2686               '(:help "Mark unread articles in this group as read, then exit"))]
2687          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2688          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2689          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2690          ["Exit group" gnus-summary-exit
2691           ,@(if (featurep 'xemacs) '(t)
2692               '(:help "Exit current group, return to group selection mode"))]
2693          ["Exit group without updating" gnus-summary-exit-no-update t]
2694          ["Exit and goto next group" gnus-summary-next-group t]
2695          ["Exit and goto prev group" gnus-summary-prev-group t]
2696          ["Reselect group" gnus-summary-reselect-current-group t]
2697          ["Rescan group" gnus-summary-rescan-group t]
2698          ["Update dribble" gnus-summary-save-newsrc t])))
2699
2700     (gnus-run-hooks 'gnus-summary-menu-hook)))
2701
2702 (defvar gnus-summary-tool-bar-map nil)
2703
2704 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2705 ;; affect _new_ message buffers.  We might add a function that walks thru all
2706 ;; summary-mode buffers and force the update.
2707 (defun gnus-summary-tool-bar-update (&optional symbol value)
2708   "Update summary mode toolbar.
2709 Setter function for custom variables."
2710   (setq-default gnus-summary-tool-bar-map nil)
2711   (when symbol
2712     ;; When used as ":set" function:
2713     (set-default symbol value))
2714   (when (gnus-buffer-live-p gnus-summary-buffer)
2715     (with-current-buffer gnus-summary-buffer
2716       (gnus-summary-make-tool-bar))))
2717
2718 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2719                                      'gnus-summary-tool-bar-gnome
2720                                    'gnus-summary-tool-bar-retro)
2721   "Specifies the Gnus summary tool bar.
2722
2723 It can be either a list or a symbol refering to a list.  See
2724 `gmm-tool-bar-from-list' for the format of the list.  The
2725 default key map is `gnus-summary-mode-map'.
2726
2727 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2728 `gnus-summary-tool-bar-retro'."
2729   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2730                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2731                  (repeat :tag "User defined list" gmm-tool-bar-item)
2732                  (symbol))
2733   :version "23.0" ;; No Gnus
2734   :initialize 'custom-initialize-default
2735   :set 'gnus-summary-tool-bar-update
2736   :group 'gnus-summary)
2737
2738 (defcustom gnus-summary-tool-bar-gnome
2739   '((gnus-summary-post-news "mail/compose" nil)
2740     (gnus-summary-insert-new-articles "mail/inbox" nil
2741                                       :visible (or (not gnus-agent)
2742                                                    gnus-plugged))
2743     (gnus-summary-reply-with-original "mail/reply")
2744     (gnus-summary-reply "mail/reply" nil :visible nil)
2745     (gnus-summary-followup-with-original "mail/reply-all")
2746     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2747     (gnus-summary-mail-forward "mail/forward")
2748     (gnus-summary-save-article "mail/save")
2749     (gnus-summary-search-article-forward "search" nil :visible nil)
2750     (gnus-summary-print-article "print")
2751     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2752     ;; Some new commands that may need more suitable icons:
2753     (gnus-summary-save-newsrc "save" nil :visible nil)
2754     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2755     (gnus-summary-prev-article "left-arrow")
2756     (gnus-summary-next-article "right-arrow")
2757     (gnus-summary-next-page "next-page")
2758     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2759     ;;
2760     ;; Maybe some sort-by-... could be added:
2761     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2762     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2763     (gnus-summary-mark-as-expirable
2764      "delete" nil
2765      :visible (gnus-check-backend-function 'request-expire-articles
2766                                            gnus-newsgroup-name))
2767     (gnus-summary-mark-as-spam
2768      "mail/spam" t
2769      :visible (and (fboundp 'spam-group-ham-contents-p)
2770                    (spam-group-ham-contents-p gnus-newsgroup-name))
2771      :help "Mark as spam")
2772     (gnus-summary-mark-as-read-forward
2773      "mail/not-spam" nil
2774      :visible (and (fboundp 'spam-group-spam-contents-p)
2775                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2776     ;;
2777     (gnus-summary-exit "exit")
2778     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2779     (gnus-info-find-node "help"))
2780   "List of functions for the summary tool bar (GNOME style).
2781
2782 See `gmm-tool-bar-from-list' for the format of the list."
2783   :type '(repeat gmm-tool-bar-item)
2784   :version "23.0" ;; No Gnus
2785   :initialize 'custom-initialize-default
2786   :set 'gnus-summary-tool-bar-update
2787   :group 'gnus-summary)
2788
2789 (defcustom gnus-summary-tool-bar-retro
2790   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2791     (gnus-summary-next-unread-article "gnus/next-ur")
2792     (gnus-summary-post-news "gnus/post")
2793     (gnus-summary-followup-with-original "gnus/fuwo")
2794     (gnus-summary-followup "gnus/followup")
2795     (gnus-summary-reply-with-original "gnus/reply-wo")
2796     (gnus-summary-reply "gnus/reply")
2797     (gnus-summary-caesar-message "gnus/rot13")
2798     (gnus-uu-decode-uu "gnus/uu-decode")
2799     (gnus-summary-save-article-file "gnus/save-aif")
2800     (gnus-summary-save-article "gnus/save-art")
2801     (gnus-uu-post-news "gnus/uu-post")
2802     (gnus-summary-catchup "gnus/catchup")
2803     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2804     (gnus-summary-exit "gnus/exit-summ")
2805     ;; Some new command that may need more suitable icons:
2806     (gnus-summary-print-article "gnus/print" nil :visible nil)
2807     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2808     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2809     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2810     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2811     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2812     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2813     ;;
2814     (gnus-info-find-node "gnus/help" nil :visible nil))
2815   "List of functions for the summary tool bar (retro look).
2816
2817 See `gmm-tool-bar-from-list' for the format of the list."
2818   :type '(repeat gmm-tool-bar-item)
2819   :version "23.0" ;; No Gnus
2820   :initialize 'custom-initialize-default
2821   :set 'gnus-summary-tool-bar-update
2822   :group 'gnus-summary)
2823
2824 (defcustom gnus-summary-tool-bar-zap-list t
2825   "List of icon items from the global tool bar.
2826 These items are not displayed in the Gnus summary mode tool bar.
2827
2828 See `gmm-tool-bar-from-list' for the format of the list."
2829   :type 'gmm-tool-bar-zap-list
2830   :version "23.0" ;; No Gnus
2831   :initialize 'custom-initialize-default
2832   :set 'gnus-summary-tool-bar-update
2833   :group 'gnus-summary)
2834
2835 (defvar image-load-path)
2836
2837 (defun gnus-summary-make-tool-bar (&optional force)
2838   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2839 When FORCE, rebuild the tool bar."
2840   (when (and (not (featurep 'xemacs))
2841              (boundp 'tool-bar-mode)
2842              tool-bar-mode
2843              (or (not gnus-summary-tool-bar-map) force))
2844     (let* ((load-path
2845             (gmm-image-load-path-for-library "gnus"
2846                                              "mail/save.xpm"
2847                                              nil t))
2848            (image-load-path (cons (car load-path)
2849                                   (when (boundp 'image-load-path)
2850                                     image-load-path)))
2851            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2852                                         gnus-summary-tool-bar-zap-list
2853                                         'gnus-summary-mode-map)))
2854       (when map
2855         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2856         ;; uses it's value.
2857         (setq gnus-summary-tool-bar-map map))))
2858   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2859
2860 (defun gnus-score-set-default (var value)
2861   "A version of set that updates the GNU Emacs menu-bar."
2862   (set var value)
2863   ;; It is the message that forces the active status to be updated.
2864   (message ""))
2865
2866 (defun gnus-make-score-map (type)
2867   "Make a summary score map of type TYPE."
2868   (if t
2869       nil
2870     (let ((headers '(("author" "from" string)
2871                      ("subject" "subject" string)
2872                      ("article body" "body" string)
2873                      ("article head" "head" string)
2874                      ("xref" "xref" string)
2875                      ("extra header" "extra" string)
2876                      ("lines" "lines" number)
2877                      ("followups to author" "followup" string)))
2878           (types '((number ("less than" <)
2879                            ("greater than" >)
2880                            ("equal" =))
2881                    (string ("substring" s)
2882                            ("exact string" e)
2883                            ("fuzzy string" f)
2884                            ("regexp" r))))
2885           (perms '(("temporary" (current-time-string))
2886                    ("permanent" nil)
2887                    ("immediate" now)))
2888           header)
2889       (list
2890        (apply
2891         'nconc
2892         (list
2893          (if (eq type 'lower)
2894              "Lower score"
2895            "Increase score"))
2896         (let (outh)
2897           (while headers
2898             (setq header (car headers))
2899             (setq outh
2900                   (cons
2901                    (apply
2902                     'nconc
2903                     (list (car header))
2904                     (let ((ts (cdr (assoc (nth 2 header) types)))
2905                           outt)
2906                       (while ts
2907                         (setq outt
2908                               (cons
2909                                (apply
2910                                 'nconc
2911                                 (list (caar ts))
2912                                 (let ((ps perms)
2913                                       outp)
2914                                   (while ps
2915                                     (setq outp
2916                                           (cons
2917                                            (vector
2918                                             (caar ps)
2919                                             (list
2920                                              'gnus-summary-score-entry
2921                                              (nth 1 header)
2922                                              (if (or (string= (nth 1 header)
2923                                                               "head")
2924                                                      (string= (nth 1 header)
2925                                                               "body"))
2926                                                  ""
2927                                                (list 'gnus-summary-header
2928                                                      (nth 1 header)))
2929                                              (list 'quote (nth 1 (car ts)))
2930                                              (list 'gnus-score-delta-default
2931                                                    nil)
2932                                              (nth 1 (car ps))
2933                                              t)
2934                                             t)
2935                                            outp))
2936                                     (setq ps (cdr ps)))
2937                                   (list (nreverse outp))))
2938                                outt))
2939                         (setq ts (cdr ts)))
2940                       (list (nreverse outt))))
2941                    outh))
2942             (setq headers (cdr headers)))
2943           (list (nreverse outh))))))))
2944
2945 \f
2946
2947 (defun gnus-summary-mode (&optional group)
2948   "Major mode for reading articles.
2949
2950 All normal editing commands are switched off.
2951 \\<gnus-summary-mode-map>
2952 Each line in this buffer represents one article.  To read an
2953 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2954 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2955 respectively.
2956
2957 You can also post articles and send mail from this buffer.  To
2958 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2959 of an article, type `\\[gnus-summary-reply]'.
2960
2961 There are approx. one gazillion commands you can execute in this
2962 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2963
2964 The following commands are available:
2965
2966 \\{gnus-summary-mode-map}"
2967   (interactive)
2968   (kill-all-local-variables)
2969   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2970     (gnus-summary-make-local-variables))
2971   (gnus-summary-make-local-variables)
2972   (setq gnus-newsgroup-name group)
2973   (when (gnus-visual-p 'summary-menu 'menu)
2974     (gnus-summary-make-menu-bar)
2975     (gnus-summary-make-tool-bar))
2976   (gnus-make-thread-indent-array)
2977   (gnus-simplify-mode-line)
2978   (setq major-mode 'gnus-summary-mode)
2979   (setq mode-name "Summary")
2980   (make-local-variable 'minor-mode-alist)
2981   (use-local-map gnus-summary-mode-map)
2982   (buffer-disable-undo)
2983   (setq buffer-read-only t              ;Disable modification
2984         show-trailing-whitespace nil)
2985   (setq truncate-lines t)
2986   (setq selective-display t)
2987   (setq selective-display-ellipses t)   ;Display `...'
2988   (gnus-summary-set-display-table)
2989   (gnus-set-default-directory)
2990   (make-local-variable 'gnus-summary-line-format)
2991   (make-local-variable 'gnus-summary-line-format-spec)
2992   (make-local-variable 'gnus-summary-dummy-line-format)
2993   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2994   (make-local-variable 'gnus-summary-mark-positions)
2995   (gnus-make-local-hook 'pre-command-hook)
2996   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2997   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2998   (turn-on-gnus-mailing-list-mode)
2999   (mm-enable-multibyte)
3000   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3001   (gnus-update-summary-mark-positions))
3002
3003 (defun gnus-summary-make-local-variables ()
3004   "Make all the local summary buffer variables."
3005   (let (global)
3006     (dolist (local gnus-summary-local-variables)
3007       (if (consp local)
3008           (progn
3009             (if (eq (cdr local) 'global)
3010                 ;; Copy the global value of the variable.
3011                 (setq global (symbol-value (car local)))
3012               ;; Use the value from the list.
3013               (setq global (eval (cdr local))))
3014             (set (make-local-variable (car local)) global))
3015         ;; Simple nil-valued local variable.
3016         (set (make-local-variable local) nil)))))
3017
3018 (defun gnus-summary-clear-local-variables ()
3019   (let ((locals gnus-summary-local-variables))
3020     (while locals
3021       (if (consp (car locals))
3022           (and (symbolp (caar locals))
3023                (set (caar locals) nil))
3024         (and (symbolp (car locals))
3025              (set (car locals) nil)))
3026       (setq locals (cdr locals)))))
3027
3028 ;; Summary data functions.
3029
3030 (defmacro gnus-data-number (data)
3031   `(car ,data))
3032
3033 (defmacro gnus-data-set-number (data number)
3034   `(setcar ,data ,number))
3035
3036 (defmacro gnus-data-mark (data)
3037   `(nth 1 ,data))
3038
3039 (defmacro gnus-data-set-mark (data mark)
3040   `(setcar (nthcdr 1 ,data) ,mark))
3041
3042 (defmacro gnus-data-pos (data)
3043   `(nth 2 ,data))
3044
3045 (defmacro gnus-data-set-pos (data pos)
3046   `(setcar (nthcdr 2 ,data) ,pos))
3047
3048 (defmacro gnus-data-header (data)
3049   `(nth 3 ,data))
3050
3051 (defmacro gnus-data-set-header (data header)
3052   `(setf (nth 3 ,data) ,header))
3053
3054 (defmacro gnus-data-level (data)
3055   `(nth 4 ,data))
3056
3057 (defmacro gnus-data-unread-p (data)
3058   `(= (nth 1 ,data) gnus-unread-mark))
3059
3060 (defmacro gnus-data-read-p (data)
3061   `(/= (nth 1 ,data) gnus-unread-mark))
3062
3063 (defmacro gnus-data-pseudo-p (data)
3064   `(consp (nth 3 ,data)))
3065
3066 (defmacro gnus-data-find (number)
3067   `(assq ,number gnus-newsgroup-data))
3068
3069 (defmacro gnus-data-find-list (number &optional data)
3070   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3071      (memq (assq ,number bdata)
3072            bdata)))
3073
3074 (defmacro gnus-data-make (number mark pos header level)
3075   `(list ,number ,mark ,pos ,header ,level))
3076
3077 (defun gnus-data-enter (after-article number mark pos header level offset)
3078   (let ((data (gnus-data-find-list after-article)))
3079     (unless data
3080       (error "No such article: %d" after-article))
3081     (setcdr data (cons (gnus-data-make number mark pos header level)
3082                        (cdr data)))
3083     (setq gnus-newsgroup-data-reverse nil)
3084     (gnus-data-update-list (cddr data) offset)))
3085
3086 (defun gnus-data-enter-list (after-article list &optional offset)
3087   (when list
3088     (let ((data (and after-article (gnus-data-find-list after-article)))
3089           (ilist list))
3090       (if (not (or data
3091                    after-article))
3092           (let ((odata gnus-newsgroup-data))
3093             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3094             (when offset
3095               (gnus-data-update-list odata offset)))
3096         ;; Find the last element in the list to be spliced into the main
3097         ;; list.
3098         (setq list (last list))
3099         (if (not data)
3100             (progn
3101               (setcdr list gnus-newsgroup-data)
3102               (setq gnus-newsgroup-data ilist)
3103               (when offset
3104                 (gnus-data-update-list (cdr list) offset)))
3105           (setcdr list (cdr data))
3106           (setcdr data ilist)
3107           (when offset
3108             (gnus-data-update-list (cdr list) offset))))
3109       (setq gnus-newsgroup-data-reverse nil))))
3110
3111 (defun gnus-data-remove (article &optional offset)
3112   (let ((data gnus-newsgroup-data))
3113     (if (= (gnus-data-number (car data)) article)
3114         (progn
3115           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3116                 gnus-newsgroup-data-reverse nil)
3117           (when offset
3118             (gnus-data-update-list gnus-newsgroup-data offset)))
3119       (while (cdr data)
3120         (when (= (gnus-data-number (cadr data)) article)
3121           (setcdr data (cddr data))
3122           (when offset
3123             (gnus-data-update-list (cdr data) offset))
3124           (setq data nil
3125                 gnus-newsgroup-data-reverse nil))
3126         (setq data (cdr data))))))
3127
3128 (defmacro gnus-data-list (backward)
3129   `(if ,backward
3130        (or gnus-newsgroup-data-reverse
3131            (setq gnus-newsgroup-data-reverse
3132                  (reverse gnus-newsgroup-data)))
3133      gnus-newsgroup-data))
3134
3135 (defun gnus-data-update-list (data offset)
3136   "Add OFFSET to the POS of all data entries in DATA."
3137   (setq gnus-newsgroup-data-reverse nil)
3138   (while data
3139     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3140     (setq data (cdr data))))
3141
3142 (defun gnus-summary-article-pseudo-p (article)
3143   "Say whether this article is a pseudo article or not."
3144   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3145
3146 (defmacro gnus-summary-article-sparse-p (article)
3147   "Say whether this article is a sparse article or not."
3148   `(memq ,article gnus-newsgroup-sparse))
3149
3150 (defmacro gnus-summary-article-ancient-p (article)
3151   "Say whether this article is a sparse article or not."
3152   `(memq ,article gnus-newsgroup-ancient))
3153
3154 (defun gnus-article-parent-p (number)
3155   "Say whether this article is a parent or not."
3156   (let ((data (gnus-data-find-list number)))
3157     (and (cdr data)              ; There has to be an article after...
3158          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3159             (gnus-data-level (nth 1 data))))))
3160
3161 (defun gnus-article-children (number)
3162   "Return a list of all children to NUMBER."
3163   (let* ((data (gnus-data-find-list number))
3164          (level (gnus-data-level (car data)))
3165          children)
3166     (setq data (cdr data))
3167     (while (and data
3168                 (= (gnus-data-level (car data)) (1+ level)))
3169       (push (gnus-data-number (car data)) children)
3170       (setq data (cdr data)))
3171     children))
3172
3173 (defmacro gnus-summary-skip-intangible ()
3174   "If the current article is intangible, then jump to a different article."
3175   '(let ((to (get-text-property (point) 'gnus-intangible)))
3176      (and to (gnus-summary-goto-subject to))))
3177
3178 (defmacro gnus-summary-article-intangible-p ()
3179   "Say whether this article is intangible or not."
3180   '(get-text-property (point) 'gnus-intangible))
3181
3182 (defun gnus-article-read-p (article)
3183   "Say whether ARTICLE is read or not."
3184   (not (or (memq article gnus-newsgroup-marked)
3185            (memq article gnus-newsgroup-spam-marked)
3186            (memq article gnus-newsgroup-unreads)
3187            (memq article gnus-newsgroup-unselected)
3188            (memq article gnus-newsgroup-dormant))))
3189
3190 ;; Some summary mode macros.
3191
3192 (defmacro gnus-summary-article-number ()
3193   "The article number of the article on the current line.
3194 If there isn't an article number here, then we return the current
3195 article number."
3196   '(progn
3197      (gnus-summary-skip-intangible)
3198      (or (get-text-property (point) 'gnus-number)
3199          (gnus-summary-last-subject))))
3200
3201 (defmacro gnus-summary-article-header (&optional number)
3202   "Return the header of article NUMBER."
3203   `(gnus-data-header (gnus-data-find
3204                       ,(or number '(gnus-summary-article-number)))))
3205
3206 (defmacro gnus-summary-thread-level (&optional number)
3207   "Return the level of thread that starts with article NUMBER."
3208   `(if (and (eq gnus-summary-make-false-root 'dummy)
3209             (get-text-property (point) 'gnus-intangible))
3210        0
3211      (gnus-data-level (gnus-data-find
3212                        ,(or number '(gnus-summary-article-number))))))
3213
3214 (defmacro gnus-summary-article-mark (&optional number)
3215   "Return the mark of article NUMBER."
3216   `(gnus-data-mark (gnus-data-find
3217                     ,(or number '(gnus-summary-article-number)))))
3218
3219 (defmacro gnus-summary-article-pos (&optional number)
3220   "Return the position of the line of article NUMBER."
3221   `(gnus-data-pos (gnus-data-find
3222                    ,(or number '(gnus-summary-article-number)))))
3223
3224 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3225 (defmacro gnus-summary-article-subject (&optional number)
3226   "Return current subject string or nil if nothing."
3227   `(let ((headers
3228           ,(if number
3229                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3230              '(gnus-data-header (assq (gnus-summary-article-number)
3231                                       gnus-newsgroup-data)))))
3232      (and headers
3233           (vectorp headers)
3234           (mail-header-subject headers))))
3235
3236 (defmacro gnus-summary-article-score (&optional number)
3237   "Return current article score."
3238   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3239                   gnus-newsgroup-scored))
3240        gnus-summary-default-score 0))
3241
3242 (defun gnus-summary-article-children (&optional number)
3243   "Return a list of article numbers that are children of article NUMBER."
3244   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3245          (level (gnus-data-level (car data)))
3246          l children)
3247     (while (and (setq data (cdr data))
3248                 (> (setq l (gnus-data-level (car data))) level))
3249       (and (= (1+ level) l)
3250            (push (gnus-data-number (car data))
3251                  children)))
3252     (nreverse children)))
3253
3254 (defun gnus-summary-article-parent (&optional number)
3255   "Return the article number of the parent of article NUMBER."
3256   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3257                                     (gnus-data-list t)))
3258          (level (gnus-data-level (car data))))
3259     (if (zerop level)
3260         ()                              ; This is a root.
3261       ;; We search until we find an article with a level less than
3262       ;; this one.  That function has to be the parent.
3263       (while (and (setq data (cdr data))
3264                   (not (< (gnus-data-level (car data)) level))))
3265       (and data (gnus-data-number (car data))))))
3266
3267 (defun gnus-unread-mark-p (mark)
3268   "Say whether MARK is the unread mark."
3269   (= mark gnus-unread-mark))
3270
3271 (defun gnus-read-mark-p (mark)
3272   "Say whether MARK is one of the marks that mark as read.
3273 This is all marks except unread, ticked, dormant, and expirable."
3274   (not (or (= mark gnus-unread-mark)
3275            (= mark gnus-ticked-mark)
3276            (= mark gnus-spam-mark)
3277            (= mark gnus-dormant-mark)
3278            (= mark gnus-expirable-mark))))
3279
3280 (defmacro gnus-article-mark (number)
3281   "Return the MARK of article NUMBER.
3282 This macro should only be used when computing the mark the \"first\"
3283 time; i.e., when generating the summary lines.  After that,
3284 `gnus-summary-article-mark' should be used to examine the
3285 marks of articles."
3286   `(cond
3287     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3288     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3289     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3290     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3291     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3292     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3293     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3294     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3295            gnus-ancient-mark))))
3296
3297 ;; Saving hidden threads.
3298
3299 (defmacro gnus-save-hidden-threads (&rest forms)
3300   "Save hidden threads, eval FORMS, and restore the hidden threads."
3301   (let ((config (make-symbol "config")))
3302     `(let ((,config (gnus-hidden-threads-configuration)))
3303        (unwind-protect
3304            (save-excursion
3305              ,@forms)
3306          (gnus-restore-hidden-threads-configuration ,config)))))
3307 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3308 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3309
3310 (defun gnus-data-compute-positions ()
3311   "Compute the positions of all articles."
3312   (setq gnus-newsgroup-data-reverse nil)
3313   (let ((data gnus-newsgroup-data))
3314     (save-excursion
3315       (gnus-save-hidden-threads
3316         (gnus-summary-show-all-threads)
3317         (goto-char (point-min))
3318         (while data
3319           (while (get-text-property (point) 'gnus-intangible)
3320             (forward-line 1))
3321           (gnus-data-set-pos (car data) (+ (point) 3))
3322           (setq data (cdr data))
3323           (forward-line 1))))))
3324
3325 (defun gnus-hidden-threads-configuration ()
3326   "Return the current hidden threads configuration."
3327   (save-excursion
3328     (let (config)
3329       (goto-char (point-min))
3330       (while (search-forward "\r" nil t)
3331         (push (1- (point)) config))
3332       config)))
3333
3334 (defun gnus-restore-hidden-threads-configuration (config)
3335   "Restore hidden threads configuration from CONFIG."
3336   (save-excursion
3337     (let (point buffer-read-only)
3338       (while (setq point (pop config))
3339         (when (and (< point (point-max))
3340                    (goto-char point)
3341                    (eq (char-after) ?\n))
3342           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3343
3344 ;; Various summary mode internalish functions.
3345
3346 (defun gnus-mouse-pick-article (e)
3347   (interactive "e")
3348   (mouse-set-point e)
3349   (gnus-summary-next-page nil t))
3350
3351 (defun gnus-summary-set-display-table ()
3352   "Change the display table.
3353 Odd characters have a tendency to mess
3354 up nicely formatted displays - we make all possible glyphs
3355 display only a single character."
3356
3357   ;; We start from the standard display table, if any.
3358   (let ((table (or (copy-sequence standard-display-table)
3359                    (make-display-table)))
3360         (i 32))
3361     ;; Nix out all the control chars...
3362     (while (>= (setq i (1- i)) 0)
3363       (aset table i [??]))
3364    ;; ... but not newline and cr, of course.  (cr is necessary for the
3365     ;; selective display).
3366     (aset table ?\n nil)
3367     (aset table ?\r nil)
3368     ;; We keep TAB as well.
3369     (aset table ?\t nil)
3370     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3371     ;; Emacs 23 (unicode), that are not set already.
3372     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3373                  160
3374                256)))
3375       (while (>= (setq i (1- i)) 127)
3376         ;; Only modify if the entry is nil.
3377         (unless (aref table i)
3378           (aset table i [??]))))
3379     (setq buffer-display-table table)))
3380
3381 (defun gnus-summary-set-article-display-arrow (pos)
3382   "Update the overlay arrow to point to line at position POS."
3383   (when (and gnus-summary-display-arrow
3384              (boundp 'overlay-arrow-position)
3385              (boundp 'overlay-arrow-string))
3386     (save-excursion
3387       (goto-char pos)
3388       (beginning-of-line)
3389       (unless overlay-arrow-position
3390         (setq overlay-arrow-position (make-marker)))
3391       (setq overlay-arrow-string "=>"
3392             overlay-arrow-position (set-marker overlay-arrow-position
3393                                                (point)
3394                                                (current-buffer))))))
3395
3396 (defun gnus-summary-setup-buffer (group)
3397   "Initialize summary buffer."
3398   (let ((buffer (gnus-summary-buffer-name group))
3399         (dead-name (concat "*Dead Summary "
3400                            (gnus-group-decoded-name group) "*")))
3401     ;; If a dead summary buffer exists, we kill it.
3402     (when (gnus-buffer-live-p dead-name)
3403       (gnus-kill-buffer dead-name))
3404     (if (get-buffer buffer)
3405         (progn
3406           (set-buffer buffer)
3407           (setq gnus-summary-buffer (current-buffer))
3408           (not gnus-newsgroup-prepared))
3409       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3410       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3411       (gnus-summary-mode group)
3412       (when gnus-carpal
3413         (gnus-carpal-setup-buffer 'summary))
3414       (when (gnus-group-quit-config group)
3415         (set (make-local-variable 'gnus-single-article-buffer) nil))
3416       (make-local-variable 'gnus-article-buffer)
3417       (make-local-variable 'gnus-article-current)
3418       (make-local-variable 'gnus-original-article-buffer)
3419       (setq gnus-newsgroup-name group)
3420       ;; Set any local variables in the group parameters.
3421       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3422       t)))
3423
3424 (defun gnus-set-global-variables ()
3425   "Set the global equivalents of the buffer-local variables.
3426 They are set to the latest values they had.  These reflect the summary
3427 buffer that was in action when the last article was fetched."
3428   (when (eq major-mode 'gnus-summary-mode)
3429     (setq gnus-summary-buffer (current-buffer))
3430     (let ((name gnus-newsgroup-name)
3431           (marked gnus-newsgroup-marked)
3432           (spam gnus-newsgroup-spam-marked)
3433           (unread gnus-newsgroup-unreads)
3434           (headers gnus-current-headers)
3435           (data gnus-newsgroup-data)
3436           (summary gnus-summary-buffer)
3437           (article-buffer gnus-article-buffer)
3438           (original gnus-original-article-buffer)
3439           (gac gnus-article-current)
3440           (reffed gnus-reffed-article-number)
3441           (score-file gnus-current-score-file)
3442           (default-charset gnus-newsgroup-charset)
3443           vlist)
3444       (let ((locals gnus-newsgroup-variables))
3445         (while locals
3446           (if (consp (car locals))
3447               (push (eval (caar locals)) vlist)
3448             (push (eval (car locals)) vlist))
3449           (setq locals (cdr locals)))
3450         (setq vlist (nreverse vlist)))
3451       (with-current-buffer gnus-group-buffer
3452         (setq gnus-newsgroup-name name
3453               gnus-newsgroup-marked marked
3454               gnus-newsgroup-spam-marked spam
3455               gnus-newsgroup-unreads unread
3456               gnus-current-headers headers
3457               gnus-newsgroup-data data
3458               gnus-article-current gac
3459               gnus-summary-buffer summary
3460               gnus-article-buffer article-buffer
3461               gnus-original-article-buffer original
3462               gnus-reffed-article-number reffed
3463               gnus-current-score-file score-file
3464               gnus-newsgroup-charset default-charset)
3465         (let ((locals gnus-newsgroup-variables))
3466           (while locals
3467             (if (consp (car locals))
3468                 (set (caar locals) (pop vlist))
3469               (set (car locals) (pop vlist)))
3470             (setq locals (cdr locals))))
3471         ;; The article buffer also has local variables.
3472         (when (gnus-buffer-live-p gnus-article-buffer)
3473           (set-buffer gnus-article-buffer)
3474           (setq gnus-summary-buffer summary))))))
3475
3476 (defun gnus-summary-article-unread-p (article)
3477   "Say whether ARTICLE is unread or not."
3478   (memq article gnus-newsgroup-unreads))
3479
3480 (defun gnus-summary-first-article-p (&optional article)
3481   "Return whether ARTICLE is the first article in the buffer."
3482   (if (not (setq article (or article (gnus-summary-article-number))))
3483       nil
3484     (eq article (caar gnus-newsgroup-data))))
3485
3486 (defun gnus-summary-last-article-p (&optional article)
3487   "Return whether ARTICLE is the last article in the buffer."
3488   (if (not (setq article (or article (gnus-summary-article-number))))
3489       ;; All non-existent numbers are the last article.  :-)
3490       t
3491     (not (cdr (gnus-data-find-list article)))))
3492
3493 (defun gnus-make-thread-indent-array (&optional n)
3494   (when (or n
3495             (progn (setq n 200) nil)
3496             (null gnus-thread-indent-array)
3497             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3498     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3499           gnus-thread-indent-array-level gnus-thread-indent-level)
3500     (while (>= n 0)
3501       (aset gnus-thread-indent-array n
3502             (make-string (* n gnus-thread-indent-level) ? ))
3503       (setq n (1- n)))))
3504
3505 (defun gnus-update-summary-mark-positions ()
3506   "Compute where the summary marks are to go."
3507   (save-excursion
3508     (when (gnus-buffer-exists-p gnus-summary-buffer)
3509       (set-buffer gnus-summary-buffer))
3510     (let ((spec gnus-summary-line-format-spec)
3511           pos)
3512       (save-excursion
3513         (gnus-set-work-buffer)
3514         (let ((gnus-tmp-unread ?Z)
3515               (gnus-replied-mark ?Z)
3516               (gnus-score-below-mark ?Z)
3517               (gnus-score-over-mark ?Z)
3518               (gnus-undownloaded-mark ?Z)
3519               (gnus-summary-line-format-spec spec)
3520               (gnus-newsgroup-downloadable '(0))
3521               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3522               case-fold-search ignores)
3523           ;; Here, all marks are bound to Z.
3524           (gnus-summary-insert-line header
3525                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3526           (goto-char (point-min))
3527           ;; Memorize the positions of the same characters as dummy marks.
3528           (while (re-search-forward "[A-D]" nil t)
3529             (push (point) ignores))
3530           (erase-buffer)
3531           ;; We use A-D as dummy marks in order to know column positions
3532           ;; where marks should be inserted.
3533           (setq gnus-tmp-unread ?A
3534                 gnus-replied-mark ?B
3535                 gnus-score-below-mark ?C
3536                 gnus-score-over-mark ?C
3537                 gnus-undownloaded-mark ?D)
3538           (gnus-summary-insert-line header
3539                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3540           ;; Ignore characters which aren't dummy marks.
3541           (dolist (p ignores)
3542             (delete-region (goto-char (1- p)) p)
3543             (insert ?Z))
3544           (goto-char (point-min))
3545           (setq pos (list (cons 'unread
3546                                 (and (search-forward "A" nil t)
3547                                      (- (point) (point-min) 1)))))
3548           (goto-char (point-min))
3549           (push (cons 'replied (and (search-forward "B" nil t)
3550                                     (- (point) (point-min) 1)))
3551                 pos)
3552           (goto-char (point-min))
3553           (push (cons 'score (and (search-forward "C" nil t)
3554                                   (- (point) (point-min) 1)))
3555                 pos)
3556           (goto-char (point-min))
3557           (push (cons 'download (and (search-forward "D" nil t)
3558                                      (- (point) (point-min) 1)))
3559                 pos)))
3560       (setq gnus-summary-mark-positions pos))))
3561
3562 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3563   "Insert a dummy root in the summary buffer."
3564   (beginning-of-line)
3565   (gnus-add-text-properties
3566    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3567    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3568
3569 (defun gnus-summary-extract-address-component (from)
3570   (or (car (funcall gnus-extract-address-components from))
3571       from))
3572
3573 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3574   (let ((mail-parse-charset gnus-newsgroup-charset)
3575         (ignored-from-addresses (gnus-ignored-from-addresses))
3576         ; Is it really necessary to do this next part for each summary line?
3577         ; Luckily, doesn't seem to slow things down much.
3578         (mail-parse-ignored-charsets
3579          (with-current-buffer gnus-summary-buffer
3580            gnus-newsgroup-ignored-charsets)))
3581     (or
3582      (and ignored-from-addresses
3583           (string-match ignored-from-addresses gnus-tmp-from)
3584           (let ((extra-headers (mail-header-extra header))
3585                 to
3586                 newsgroups)
3587             (cond
3588              ((setq to (cdr (assq 'To extra-headers)))
3589               (concat gnus-summary-to-prefix
3590                       (inline
3591                         (gnus-summary-extract-address-component
3592                          (funcall gnus-decode-encoded-address-function to)))))
3593              ((setq newsgroups
3594                     (or
3595                      (cdr (assq 'Newsgroups extra-headers))
3596                      (and
3597                       (memq 'Newsgroups gnus-extra-headers)
3598                       (eq (car (gnus-find-method-for-group
3599                                 gnus-newsgroup-name)) 'nntp)
3600                       (gnus-group-real-name gnus-newsgroup-name))))
3601               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3602      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3603
3604 (defun gnus-summary-insert-line (gnus-tmp-header
3605                                  gnus-tmp-level gnus-tmp-current
3606                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3607                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3608                                  &optional gnus-tmp-dummy gnus-tmp-score
3609                                  gnus-tmp-process)
3610   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3611       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3612                                           gnus-tmp-level)))
3613   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3614          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3615          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3616          (gnus-tmp-score-char
3617           (if (or (null gnus-summary-default-score)
3618                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3619                       gnus-summary-zcore-fuzz))
3620               ?                         ;Whitespace
3621             (if (< gnus-tmp-score gnus-summary-default-score)
3622                 gnus-score-below-mark gnus-score-over-mark)))
3623          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3624          (gnus-tmp-replied
3625           (cond (gnus-tmp-process gnus-process-mark)
3626                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3627                  gnus-cached-mark)
3628                 (gnus-tmp-replied gnus-replied-mark)
3629                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3630                  gnus-forwarded-mark)
3631                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3632                  gnus-saved-mark)
3633                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3634                  gnus-recent-mark)
3635                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3636                  gnus-unseen-mark)
3637                 (t gnus-no-mark)))
3638          (gnus-tmp-downloaded
3639           (cond (undownloaded
3640                  gnus-undownloaded-mark)
3641                 (gnus-newsgroup-agentized
3642                  gnus-downloaded-mark)
3643                 (t
3644                  gnus-no-mark)))
3645          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3646          (gnus-tmp-name
3647           (cond
3648            ((string-match "<[^>]+> *$" gnus-tmp-from)
3649             (let ((beg (match-beginning 0)))
3650               (or (and (string-match "^\".+\"" gnus-tmp-from)
3651                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3652                   (substring gnus-tmp-from 0 beg))))
3653            ((string-match "(.+)" gnus-tmp-from)
3654             (substring gnus-tmp-from
3655                        (1+ (match-beginning 0)) (1- (match-end 0))))
3656            (t gnus-tmp-from)))
3657          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3658          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3659          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3660          (buffer-read-only nil))
3661     (when (string= gnus-tmp-name "")
3662       (setq gnus-tmp-name gnus-tmp-from))
3663     (unless (numberp gnus-tmp-lines)
3664       (setq gnus-tmp-lines -1))
3665     (if (= gnus-tmp-lines -1)
3666         (setq gnus-tmp-lines "?")
3667       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3668       (gnus-put-text-property
3669      (point)
3670      (progn (eval gnus-summary-line-format-spec) (point))
3671        'gnus-number gnus-tmp-number)
3672     (when (gnus-visual-p 'summary-highlight 'highlight)
3673       (forward-line -1)
3674       (gnus-run-hooks 'gnus-summary-update-hook)
3675       (forward-line 1))))
3676
3677 (defun gnus-summary-update-line (&optional dont-update)
3678   "Update summary line after change."
3679   (when (and gnus-summary-default-score
3680              (not gnus-summary-inhibit-highlight))
3681     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3682            (article (gnus-summary-article-number))
3683            (score (gnus-summary-article-score article)))
3684       (unless dont-update
3685         (if (and gnus-summary-mark-below
3686                  (< (gnus-summary-article-score)
3687                     gnus-summary-mark-below))
3688             ;; This article has a low score, so we mark it as read.
3689             (when (memq article gnus-newsgroup-unreads)
3690               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3691           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3692             ;; This article was previously marked as read on account
3693             ;; of a low score, but now it has risen, so we mark it as
3694             ;; unread.
3695             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3696         (gnus-summary-update-mark
3697          (if (or (null gnus-summary-default-score)
3698                  (<= (abs (- score gnus-summary-default-score))
3699                      gnus-summary-zcore-fuzz))
3700              ?                          ;Whitespace
3701            (if (< score gnus-summary-default-score)
3702                gnus-score-below-mark gnus-score-over-mark))
3703          'score))
3704       ;; Do visual highlighting.
3705       (when (gnus-visual-p 'summary-highlight 'highlight)
3706         (gnus-run-hooks 'gnus-summary-update-hook)))))
3707
3708 (defvar gnus-tmp-new-adopts nil)
3709
3710 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3711   "Return the number of articles in THREAD.
3712 This may be 0 in some cases -- if none of the articles in
3713 the thread are to be displayed."
3714   (let* ((number
3715          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3716           (cond
3717            ((not (listp thread))
3718             1)
3719            ((and (consp thread) (cdr thread))
3720             (apply
3721              '+ 1 (mapcar
3722                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3723            ((null thread)
3724             1)
3725            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3726             1)
3727            (t 0))))
3728     (when (and level (zerop level) gnus-tmp-new-adopts)
3729       (incf number
3730             (apply '+ (mapcar
3731                        'gnus-summary-number-of-articles-in-thread
3732                        gnus-tmp-new-adopts))))
3733     (if char
3734         (if (> number 1) gnus-not-empty-thread-mark
3735           gnus-empty-thread-mark)
3736       number)))
3737
3738 (defsubst gnus-summary-line-message-size (head)
3739   "Return pretty-printed version of message size.
3740 This function is intended to be used in
3741 `gnus-summary-line-format-alist'."
3742   (let ((c (or (mail-header-chars head) -1)))
3743     (cond ((< c 0) "n/a")               ; chars not available
3744           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3745           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3746           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3747           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3748
3749
3750 (defun gnus-summary-set-local-parameters (group)
3751   "Go through the local params of GROUP and set all variable specs in that list."
3752   (let ((vars '(quit-config)))          ; Ignore quit-config.
3753     (dolist (elem (gnus-group-find-parameter group))
3754       (and (consp elem)                 ; Has to be a cons.
3755            (consp (cdr elem))           ; The cdr has to be a list.
3756            (symbolp (car elem))         ; Has to be a symbol in there.
3757            (not (memq (car elem) vars))
3758            (ignore-errors               ; So we set it.
3759              (push (car elem) vars)
3760              (make-local-variable (car elem))
3761              (set (car elem) (eval (nth 1 elem))))))))
3762
3763 (defun gnus-summary-read-group (group &optional show-all no-article
3764                                       kill-buffer no-display backward
3765                                       select-articles)
3766   "Start reading news in newsgroup GROUP.
3767 If SHOW-ALL is non-nil, already read articles are also listed.
3768 If NO-ARTICLE is non-nil, no article is selected initially.
3769 If NO-DISPLAY, don't generate a summary buffer."
3770   (let (result)
3771     (while (and group
3772                 (null (setq result
3773                             (let ((gnus-auto-select-next nil))
3774                               (or (gnus-summary-read-group-1
3775                                    group show-all no-article
3776                                    kill-buffer no-display
3777                                    select-articles)
3778                                   (setq show-all nil
3779                                         select-articles nil)))))
3780                 (eq gnus-auto-select-next 'quietly))
3781       (set-buffer gnus-group-buffer)
3782       ;; The entry function called above goes to the next
3783       ;; group automatically, so we go two groups back
3784       ;; if we are searching for the previous group.
3785       (when backward
3786         (gnus-group-prev-unread-group 2))
3787       (if (not (equal group (gnus-group-group-name)))
3788           (setq group (gnus-group-group-name))
3789         (setq group nil)))
3790     result))
3791
3792 (defun gnus-summary-read-group-1 (group show-all no-article
3793                                         kill-buffer no-display
3794                                         &optional select-articles)
3795   ;; Killed foreign groups can't be entered.
3796   ;;  (when (and (not (gnus-group-native-p group))
3797   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3798   ;;    (error "Dead non-native groups can't be entered"))
3799   (gnus-message 5 "Retrieving newsgroup: %s..."
3800                 (gnus-group-decoded-name group))
3801   (let* ((new-group (gnus-summary-setup-buffer group))
3802          (quit-config (gnus-group-quit-config group))
3803          (did-select (and new-group (gnus-select-newsgroup
3804                                      group show-all select-articles))))
3805     (cond
3806      ;; This summary buffer exists already, so we just select it.
3807      ((not new-group)
3808       (gnus-set-global-variables)
3809       (when kill-buffer
3810         (gnus-kill-or-deaden-summary kill-buffer))
3811       (gnus-configure-windows 'summary 'force)
3812       (gnus-set-mode-line 'summary)
3813       (gnus-summary-position-point)
3814       (message "")
3815       t)
3816      ;; We couldn't select this group.
3817      ((null did-select)
3818       (when (and (eq major-mode 'gnus-summary-mode)
3819                  (not (equal (current-buffer) kill-buffer)))
3820         (kill-buffer (current-buffer))
3821         (if (not quit-config)
3822             (progn
3823               ;; Update the info -- marks might need to be removed,
3824               ;; for instance.
3825               (gnus-summary-update-info)
3826               (set-buffer gnus-group-buffer)
3827               (gnus-group-jump-to-group group)
3828               (gnus-group-next-unread-group 1))
3829           (gnus-handle-ephemeral-exit quit-config)))
3830       (let ((grpinfo (gnus-get-info group)))
3831         (if (null (gnus-info-read grpinfo))
3832             (gnus-message 3 "Group %s contains no messages"
3833                           (gnus-group-decoded-name group))
3834           (gnus-message 3 "Can't select group")))
3835       nil)
3836      ;; The user did a `C-g' while prompting for number of articles,
3837      ;; so we exit this group.
3838      ((eq did-select 'quit)
3839       (and (eq major-mode 'gnus-summary-mode)
3840            (not (equal (current-buffer) kill-buffer))
3841            (kill-buffer (current-buffer)))
3842       (when kill-buffer
3843         (gnus-kill-or-deaden-summary kill-buffer))
3844       (if (not quit-config)
3845           (progn
3846             (set-buffer gnus-group-buffer)
3847             (gnus-group-jump-to-group group)
3848             (gnus-group-next-unread-group 1)
3849             (gnus-configure-windows 'group 'force))
3850         (gnus-handle-ephemeral-exit quit-config))
3851       ;; Finally signal the quit.
3852       (signal 'quit nil))
3853      ;; The group was successfully selected.
3854      (t
3855       (gnus-set-global-variables)
3856       ;; Save the active value in effect when the group was entered.
3857       (setq gnus-newsgroup-active
3858             (gnus-copy-sequence
3859              (gnus-active gnus-newsgroup-name)))
3860       ;; You can change the summary buffer in some way with this hook.
3861       (gnus-run-hooks 'gnus-select-group-hook)
3862       (when (memq 'summary (gnus-update-format-specifications
3863                             nil 'summary 'summary-mode 'summary-dummy))
3864         ;; The format specification for the summary line was updated,
3865         ;; so we need to update the mark positions as well.
3866         (gnus-update-summary-mark-positions))
3867       ;; Do score processing.
3868       (when gnus-use-scoring
3869         (gnus-possibly-score-headers))
3870       ;; Check whether to fill in the gaps in the threads.
3871       (when gnus-build-sparse-threads
3872         (gnus-build-sparse-threads))
3873       ;; Find the initial limit.
3874       (if show-all
3875           (let ((gnus-newsgroup-dormant nil))
3876             (gnus-summary-initial-limit show-all))
3877         (gnus-summary-initial-limit show-all))
3878       ;; Generate the summary buffer.
3879       (unless no-display
3880         (gnus-summary-prepare))
3881       (when gnus-use-trees
3882         (gnus-tree-open group)
3883         (setq gnus-summary-highlight-line-function
3884               'gnus-tree-highlight-article))
3885       ;; If the summary buffer is empty, but there are some low-scored
3886       ;; articles or some excluded dormants, we include these in the
3887       ;; buffer.
3888       (when (and (zerop (buffer-size))
3889                  (not no-display))
3890         (cond (gnus-newsgroup-dormant
3891                (gnus-summary-limit-include-dormant))
3892               ((and gnus-newsgroup-scored show-all)
3893                (gnus-summary-limit-include-expunged t))))
3894       ;; Function `gnus-apply-kill-file' must be called in this hook.
3895       (gnus-run-hooks 'gnus-apply-kill-hook)
3896       (if (and (zerop (buffer-size))
3897                (not no-display))
3898           (progn
3899             ;; This newsgroup is empty.
3900             (gnus-summary-catchup-and-exit nil t)
3901             (gnus-message 6 "No unread news")
3902             (when kill-buffer
3903               (gnus-kill-or-deaden-summary kill-buffer))
3904             ;; Return nil from this function.
3905             nil)
3906         ;; Hide conversation thread subtrees.  We cannot do this in
3907         ;; gnus-summary-prepare-hook since kill processing may not
3908         ;; work with hidden articles.
3909         (gnus-summary-maybe-hide-threads)
3910         (when kill-buffer
3911           (gnus-kill-or-deaden-summary kill-buffer))
3912         (gnus-summary-auto-select-subject)
3913         ;; Show first unread article if requested.
3914         (if (and (not no-article)
3915                  (not no-display)
3916                  gnus-newsgroup-unreads
3917                  gnus-auto-select-first)
3918             (progn
3919               (gnus-configure-windows 'summary)
3920               (let ((art (gnus-summary-article-number)))
3921                 (unless (and (not gnus-plugged)
3922                              (or (memq art gnus-newsgroup-undownloaded)
3923                                  (memq art gnus-newsgroup-downloadable)))
3924                   (gnus-summary-goto-article art))))
3925           ;; Don't select any articles.
3926           (gnus-summary-position-point)
3927           (gnus-configure-windows 'summary 'force)
3928           (gnus-set-mode-line 'summary))
3929         (when (and gnus-auto-center-group
3930                    (get-buffer-window gnus-group-buffer t))
3931           ;; Gotta use windows, because recenter does weird stuff if
3932           ;; the current buffer ain't the displayed window.
3933           (let ((owin (selected-window)))
3934             (select-window (get-buffer-window gnus-group-buffer t))
3935             (when (gnus-group-goto-group group)
3936               (recenter))
3937             (select-window owin)))
3938         ;; Mark this buffer as "prepared".
3939         (setq gnus-newsgroup-prepared t)
3940         (gnus-run-hooks 'gnus-summary-prepared-hook)
3941         (unless (gnus-ephemeral-group-p group)
3942           (gnus-group-update-group group))
3943         t)))))
3944
3945 (defun gnus-summary-auto-select-subject ()
3946   "Select the subject line on initial group entry."
3947   (goto-char (point-min))
3948   (cond
3949    ((eq gnus-auto-select-subject 'best)
3950     (gnus-summary-best-unread-subject))
3951    ((eq gnus-auto-select-subject 'unread)
3952     (gnus-summary-first-unread-subject))
3953    ((eq gnus-auto-select-subject 'unseen)
3954     (gnus-summary-first-unseen-subject))
3955    ((eq gnus-auto-select-subject 'unseen-or-unread)
3956     (gnus-summary-first-unseen-or-unread-subject))
3957    ((eq gnus-auto-select-subject 'first)
3958     ;; Do nothing.
3959     )
3960    ((functionp gnus-auto-select-subject)
3961     (funcall gnus-auto-select-subject))))
3962
3963 (defun gnus-summary-prepare ()
3964   "Generate the summary buffer."
3965   (interactive)
3966   (let ((buffer-read-only nil))
3967     (erase-buffer)
3968     (setq gnus-newsgroup-data nil
3969           gnus-newsgroup-data-reverse nil)
3970     (gnus-run-hooks 'gnus-summary-generate-hook)
3971     ;; Generate the buffer, either with threads or without.
3972     (when gnus-newsgroup-headers
3973       (gnus-summary-prepare-threads
3974        (if gnus-show-threads
3975            (gnus-sort-gathered-threads
3976             (funcall gnus-summary-thread-gathering-function
3977                      (gnus-sort-threads
3978                       (gnus-cut-threads (gnus-make-threads)))))
3979          ;; Unthreaded display.
3980          (gnus-sort-articles gnus-newsgroup-headers))))
3981     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3982     ;; Call hooks for modifying summary buffer.
3983     (goto-char (point-min))
3984     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3985
3986 (defsubst gnus-general-simplify-subject (subject)
3987   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3988   (setq subject
3989         (cond
3990          ;; Truncate the subject.
3991          (gnus-simplify-subject-functions
3992           (gnus-map-function gnus-simplify-subject-functions subject))
3993          ((numberp gnus-summary-gather-subject-limit)
3994           (setq subject (gnus-simplify-subject-re subject))
3995           (if (> (length subject) gnus-summary-gather-subject-limit)
3996               (substring subject 0 gnus-summary-gather-subject-limit)
3997             subject))
3998          ;; Fuzzily simplify it.
3999          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4000           (gnus-simplify-subject-fuzzy subject))
4001          ;; Just remove the leading "Re:".
4002          (t
4003           (gnus-simplify-subject-re subject))))
4004
4005   (if (and gnus-summary-gather-exclude-subject
4006            (string-match gnus-summary-gather-exclude-subject subject))
4007       nil                         ; This article shouldn't be gathered
4008     subject))
4009
4010 (defun gnus-summary-simplify-subject-query ()
4011   "Query where the respool algorithm would put this article."
4012   (interactive)
4013   (gnus-summary-select-article)
4014   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4015
4016 (defun gnus-gather-threads-by-subject (threads)
4017   "Gather threads by looking at Subject headers."
4018   (if (not gnus-summary-make-false-root)
4019       threads
4020     (let ((hashtb (gnus-make-hashtable 1024))
4021           (prev threads)
4022           (result threads)
4023           subject hthread whole-subject)
4024       (while threads
4025         (setq subject (gnus-general-simplify-subject
4026                        (setq whole-subject (mail-header-subject
4027                                             (caar threads)))))
4028         (when subject
4029           (if (setq hthread (gnus-gethash subject hashtb))
4030               (progn
4031                 ;; We enter a dummy root into the thread, if we
4032                 ;; haven't done that already.
4033                 (unless (stringp (caar hthread))
4034                   (setcar hthread (list whole-subject (car hthread))))
4035                 ;; We add this new gathered thread to this gathered
4036                 ;; thread.
4037                 (setcdr (car hthread)
4038                         (nconc (cdar hthread) (list (car threads))))
4039                 ;; Remove it from the list of threads.
4040                 (setcdr prev (cdr threads))
4041                 (setq threads prev))
4042             ;; Enter this thread into the hash table.
4043             (gnus-sethash subject
4044                           (if gnus-summary-make-false-root-always
4045                               (progn
4046                                 ;; If you want a dummy root above all
4047                                 ;; threads...
4048                                 (setcar threads (list whole-subject
4049                                                       (car threads)))
4050                                 threads)
4051                             threads)
4052                           hashtb)))
4053         (setq prev threads)
4054         (setq threads (cdr threads)))
4055       result)))
4056
4057 (defun gnus-gather-threads-by-references (threads)
4058   "Gather threads by looking at References headers."
4059   (let ((idhashtb (gnus-make-hashtable 1024))
4060         (thhashtb (gnus-make-hashtable 1024))
4061         (prev threads)
4062         (result threads)
4063         ids references id gthread gid entered ref)
4064     (while threads
4065       (when (setq references (mail-header-references (caar threads)))
4066         (setq id (mail-header-id (caar threads))
4067               ids (inline (gnus-split-references references))
4068               entered nil)
4069         (while (setq ref (pop ids))
4070           (setq ids (delete ref ids))
4071           (if (not (setq gid (gnus-gethash ref idhashtb)))
4072               (progn
4073                 (gnus-sethash ref id idhashtb)
4074                 (gnus-sethash id threads thhashtb))
4075             (setq gthread (gnus-gethash gid thhashtb))
4076             (unless entered
4077               ;; We enter a dummy root into the thread, if we
4078               ;; haven't done that already.
4079               (unless (stringp (caar gthread))
4080                 (setcar gthread (list (mail-header-subject (caar gthread))
4081                                       (car gthread))))
4082               ;; We add this new gathered thread to this gathered
4083               ;; thread.
4084               (setcdr (car gthread)
4085                       (nconc (cdar gthread) (list (car threads)))))
4086             ;; Add it into the thread hash table.
4087             (gnus-sethash id gthread thhashtb)
4088             (setq entered t)
4089             ;; Remove it from the list of threads.
4090             (setcdr prev (cdr threads))
4091             (setq threads prev))))
4092       (setq prev threads)
4093       (setq threads (cdr threads)))
4094     result))
4095
4096 (defun gnus-sort-gathered-threads (threads)
4097   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4098   (let ((result threads))
4099     (while threads
4100       (when (stringp (caar threads))
4101         (setcdr (car threads)
4102                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4103       (setq threads (cdr threads)))
4104     result))
4105
4106 (defun gnus-thread-loop-p (root thread)
4107   "Say whether ROOT is in THREAD."
4108   (let ((stack (list thread))
4109         (infloop 0)
4110         th)
4111     (while (setq thread (pop stack))
4112       (setq th (cdr thread))
4113       (while (and th
4114                   (not (eq (caar th) root)))
4115         (pop th))
4116       (if th
4117           ;; We have found a loop.
4118           (let (ref-dep)
4119             (setcdr thread (delq (car th) (cdr thread)))
4120             (if (boundp (setq ref-dep (intern "none"
4121                                               gnus-newsgroup-dependencies)))
4122                 (setcdr (symbol-value ref-dep)
4123                         (nconc (cdr (symbol-value ref-dep))
4124                                (list (car th))))
4125               (set ref-dep (list nil (car th))))
4126             (setq infloop 1
4127                   stack nil))
4128         ;; Push all the subthreads onto the stack.
4129         (push (cdr thread) stack)))
4130     infloop))
4131
4132 (defun gnus-make-threads ()
4133   "Go through the dependency hashtb and find the roots.  Return all threads."
4134   (let (threads)
4135     (while (catch 'infloop
4136              (mapatoms
4137               (lambda (refs)
4138                 ;; Deal with self-referencing References loops.
4139                 (when (and (car (symbol-value refs))
4140                            (not (zerop
4141                                  (apply
4142                                   '+
4143                                   (mapcar
4144                                    (lambda (thread)
4145                                      (gnus-thread-loop-p
4146                                       (car (symbol-value refs)) thread))
4147                                    (cdr (symbol-value refs)))))))
4148                   (setq threads nil)
4149                   (throw 'infloop t))
4150                 (unless (car (symbol-value refs))
4151                   ;; These threads do not refer back to any other
4152                   ;; articles, so they're roots.
4153                   (setq threads (append (cdr (symbol-value refs)) threads))))
4154               gnus-newsgroup-dependencies)))
4155     threads))
4156
4157 ;; Build the thread tree.
4158 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4159   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4160
4161 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4162 if it was already present.
4163
4164 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4165 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4166 Message-IDs will be renamed to a unique Message-ID before being
4167 entered.
4168
4169 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4170   (let* ((id (mail-header-id header))
4171          (id-dep (and id (intern id dependencies)))
4172          parent-id ref ref-dep ref-header replaced)
4173     ;; Enter this `header' in the `dependencies' table.
4174     (cond
4175      ((not id-dep)
4176       (setq header nil))
4177      ;; The first two cases do the normal part: enter a new `header'
4178      ;; in the `dependencies' table.
4179      ((not (boundp id-dep))
4180       (set id-dep (list header)))
4181      ((null (car (symbol-value id-dep)))
4182       (setcar (symbol-value id-dep) header))
4183
4184      ;; From here the `header' was already present in the
4185      ;; `dependencies' table.
4186      (force-new
4187       ;; Overrides an existing entry;
4188       ;; just set the header part of the entry.
4189       (setcar (symbol-value id-dep) header)
4190       (setq replaced t))
4191
4192      ;; Renames the existing `header' to a unique Message-ID.
4193      ((not gnus-summary-ignore-duplicates)
4194       ;; An article with this Message-ID has already been seen.
4195       ;; We rename the Message-ID.
4196       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4197            (list header))
4198       (mail-header-set-id header id))
4199
4200      ;; The last case ignores an existing entry, except it adds any
4201      ;; additional Xrefs (in case the two articles came from different
4202      ;; servers.
4203      ;; Also sets `header' to `nil' meaning that the `dependencies'
4204      ;; table was *not* modified.
4205      (t
4206       (mail-header-set-xref
4207        (car (symbol-value id-dep))
4208        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4209                    "")
4210                (or (mail-header-xref header) "")))
4211       (setq header nil)))
4212
4213     (when (and header (not replaced))
4214       ;; First check that we are not creating a References loop.
4215       (setq parent-id (gnus-parent-id (mail-header-references header)))
4216       (setq ref parent-id)
4217       (while (and ref
4218                   (setq ref-dep (intern-soft ref dependencies))
4219                   (boundp ref-dep)
4220                   (setq ref-header (car (symbol-value ref-dep))))
4221         (if (string= id ref)
4222             ;; Yuk!  This is a reference loop.  Make the article be a
4223             ;; root article.
4224             (progn
4225               (mail-header-set-references (car (symbol-value id-dep)) "none")
4226               (setq ref nil)
4227               (setq parent-id nil))
4228           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4229       (setq ref-dep (intern (or parent-id "none") dependencies))
4230       (if (boundp ref-dep)
4231           (setcdr (symbol-value ref-dep)
4232                   (nconc (cdr (symbol-value ref-dep))
4233                          (list (symbol-value id-dep))))
4234         (set ref-dep (list nil (symbol-value id-dep)))))
4235     header))
4236
4237 (defun gnus-extract-message-id-from-in-reply-to (string)
4238   (if (string-match "<[^>]+>" string)
4239       (substring string (match-beginning 0) (match-end 0))
4240     nil))
4241
4242 (defun gnus-build-sparse-threads ()
4243   (let ((headers gnus-newsgroup-headers)
4244         (mail-parse-charset gnus-newsgroup-charset)
4245         (gnus-summary-ignore-duplicates t)
4246         header references generation relations
4247         subject child end new-child date)
4248     ;; First we create an alist of generations/relations, where
4249     ;; generations is how much we trust the relation, and the relation
4250     ;; is parent/child.
4251     (gnus-message 7 "Making sparse threads...")
4252     (save-excursion
4253       (nnheader-set-temp-buffer " *gnus sparse threads*")
4254       (while (setq header (pop headers))
4255         (when (and (setq references (mail-header-references header))
4256                    (not (string= references "")))
4257           (insert references)
4258           (setq child (mail-header-id header)
4259                 subject (mail-header-subject header)
4260                 date (mail-header-date header)
4261                 generation 0)
4262           (while (search-backward ">" nil t)
4263             (setq end (1+ (point)))
4264             (when (search-backward "<" nil t)
4265               (setq new-child (buffer-substring (point) end))
4266               (push (list (incf generation)
4267                           child (setq child new-child)
4268                           subject date)
4269                     relations)))
4270           (when child
4271             (push (list (1+ generation) child nil subject) relations))
4272           (erase-buffer)))
4273       (kill-buffer (current-buffer)))
4274     ;; Sort over trustworthiness.
4275     (mapcar
4276      (lambda (relation)
4277        (when (gnus-dependencies-add-header
4278               (make-full-mail-header
4279                gnus-reffed-article-number
4280                (nth 3 relation) "" (or (nth 4 relation) "")
4281                (nth 1 relation)
4282                (or (nth 2 relation) "") 0 0 "")
4283               gnus-newsgroup-dependencies nil)
4284          (push gnus-reffed-article-number gnus-newsgroup-limit)
4285          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4286          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4287                gnus-newsgroup-reads)
4288          (decf gnus-reffed-article-number)))
4289      (sort relations 'car-less-than-car))
4290     (gnus-message 7 "Making sparse threads...done")))
4291
4292 (defun gnus-build-old-threads ()
4293   ;; Look at all the articles that refer back to old articles, and
4294   ;; fetch the headers for the articles that aren't there.  This will
4295   ;; build complete threads - if the roots haven't been expired by the
4296   ;; server, that is.
4297   (let ((mail-parse-charset gnus-newsgroup-charset)
4298         id heads)
4299     (mapatoms
4300      (lambda (refs)
4301        (when (not (car (symbol-value refs)))
4302          (setq heads (cdr (symbol-value refs)))
4303          (while heads
4304            (if (memq (mail-header-number (caar heads))
4305                      gnus-newsgroup-dormant)
4306                (setq heads (cdr heads))
4307              (setq id (symbol-name refs))
4308              (while (and (setq id (gnus-build-get-header id))
4309                          (not (car (gnus-id-to-thread id)))))
4310              (setq heads nil)))))
4311      gnus-newsgroup-dependencies)))
4312
4313 (defsubst gnus-remove-odd-characters (string)
4314   "Translate STRING into something that doesn't contain weird characters."
4315   (mm-subst-char-in-string
4316    ?\r ?\-
4317    (mm-subst-char-in-string ?\n ?\- string t) t))
4318
4319 ;; This function has to be called with point after the article number
4320 ;; on the beginning of the line.
4321 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4322   (let ((eol (point-at-eol))
4323         (buffer (current-buffer))
4324         header references in-reply-to)
4325
4326     ;; overview: [num subject from date id refs chars lines misc]
4327     (unwind-protect
4328         (let (x)
4329           (narrow-to-region (point) eol)
4330           (unless (eobp)
4331             (forward-char))
4332
4333           (setq header
4334                 (make-full-mail-header
4335                  number                 ; number
4336                  (condition-case ()     ; subject
4337                      (gnus-remove-odd-characters
4338                       (funcall gnus-decode-encoded-word-function
4339                                (setq x (nnheader-nov-field))))
4340                    (error x))
4341                  (condition-case ()     ; from
4342                      (gnus-remove-odd-characters
4343                       (funcall gnus-decode-encoded-address-function
4344                                (setq x (nnheader-nov-field))))
4345                    (error x))
4346                  (nnheader-nov-field)   ; date
4347                  (nnheader-nov-read-message-id number)  ; id
4348                  (setq references (nnheader-nov-field)) ; refs
4349                  (nnheader-nov-read-integer) ; chars
4350                  (nnheader-nov-read-integer) ; lines
4351                  (unless (eobp)
4352                    (if (looking-at "Xref: ")
4353                        (goto-char (match-end 0)))
4354                    (nnheader-nov-field)) ; Xref
4355                  (nnheader-nov-parse-extra)))) ; extra
4356
4357       (widen))
4358
4359     (when (and (string= references "")
4360                (setq in-reply-to (mail-header-extra header))
4361                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4362       (mail-header-set-references
4363        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4364
4365     (when gnus-alter-header-function
4366       (funcall gnus-alter-header-function header))
4367     (gnus-dependencies-add-header header dependencies force-new)))
4368
4369 (defun gnus-build-get-header (id)
4370   "Look through the buffer of NOV lines and find the header to ID.
4371 Enter this line into the dependencies hash table, and return
4372 the id of the parent article (if any)."
4373   (let ((deps gnus-newsgroup-dependencies)
4374         found header)
4375     (prog1
4376         (save-excursion
4377           (set-buffer nntp-server-buffer)
4378           (let ((case-fold-search nil))
4379             (goto-char (point-min))
4380             (while (and (not found)
4381                         (search-forward id nil t))
4382               (beginning-of-line)
4383               (setq found (looking-at
4384                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4385                                    (regexp-quote id))))
4386               (or found (beginning-of-line 2)))
4387             (when found
4388               (beginning-of-line)
4389               (and
4390                (setq header (gnus-nov-parse-line
4391                              (read (current-buffer)) deps))
4392                (gnus-parent-id (mail-header-references header))))))
4393       (when header
4394         (let ((number (mail-header-number header)))
4395           (push number gnus-newsgroup-limit)
4396           (push header gnus-newsgroup-headers)
4397           (if (memq number gnus-newsgroup-unselected)
4398               (progn
4399                 (setq gnus-newsgroup-unreads
4400                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4401                                                number))
4402                 (setq gnus-newsgroup-unselected
4403                       (delq number gnus-newsgroup-unselected)))
4404             (push number gnus-newsgroup-ancient)))))))
4405
4406 (defun gnus-build-all-threads ()
4407   "Read all the headers."
4408   (let ((gnus-summary-ignore-duplicates t)
4409         (mail-parse-charset gnus-newsgroup-charset)
4410         (dependencies gnus-newsgroup-dependencies)
4411         header article)
4412     (save-excursion
4413       (set-buffer nntp-server-buffer)
4414       (let ((case-fold-search nil))
4415         (goto-char (point-min))
4416         (while (not (eobp))
4417           (ignore-errors
4418             (setq article (read (current-buffer))
4419                   header (gnus-nov-parse-line article dependencies)))
4420           (when header
4421             (with-current-buffer gnus-summary-buffer
4422               (push header gnus-newsgroup-headers)
4423               (if (memq (setq article (mail-header-number header))
4424                         gnus-newsgroup-unselected)
4425                   (progn
4426                     (setq gnus-newsgroup-unreads
4427                           (gnus-add-to-sorted-list
4428                            gnus-newsgroup-unreads article))
4429                     (setq gnus-newsgroup-unselected
4430                           (delq article gnus-newsgroup-unselected)))
4431                 (push article gnus-newsgroup-ancient)))
4432             (forward-line 1)))))))
4433
4434 (defun gnus-summary-update-article-line (article header)
4435   "Update the line for ARTICLE using HEADER."
4436   (let* ((id (mail-header-id header))
4437          (thread (gnus-id-to-thread id)))
4438     (unless thread
4439       (error "Article in no thread"))
4440     ;; Update the thread.
4441     (setcar thread header)
4442     (gnus-summary-goto-subject article)
4443     (let* ((datal (gnus-data-find-list article))
4444            (data (car datal))
4445            (buffer-read-only nil)
4446            (level (gnus-summary-thread-level)))
4447       (gnus-delete-line)
4448       (let ((inserted (- (point)
4449                          (progn
4450                            (gnus-summary-insert-line
4451                             header level nil
4452                             (memq article gnus-newsgroup-undownloaded)
4453                             (gnus-article-mark article)
4454                             (memq article gnus-newsgroup-replied)
4455                             (memq article gnus-newsgroup-expirable)
4456                             ;; Only insert the Subject string when it's different
4457                             ;; from the previous Subject string.
4458                             (if (and
4459                                  gnus-show-threads
4460                                  (gnus-subject-equal
4461                                   (condition-case ()
4462                                       (mail-header-subject
4463                                        (gnus-data-header
4464                                         (cadr
4465                                          (gnus-data-find-list
4466                                           article
4467                                           (gnus-data-list t)))))
4468                                     ;; Error on the side of excessive subjects.
4469                                     (error ""))
4470                                   (mail-header-subject header)))
4471                                 ""
4472                               (mail-header-subject header))
4473                             nil (cdr (assq article gnus-newsgroup-scored))
4474                             (memq article gnus-newsgroup-processable))
4475                            (point)))))
4476         (when (cdr datal)
4477           (gnus-data-update-list
4478            (cdr datal)
4479            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4480
4481 (defun gnus-summary-update-article (article &optional iheader)
4482   "Update ARTICLE in the summary buffer."
4483   (set-buffer gnus-summary-buffer)
4484   (let* ((header (gnus-summary-article-header article))
4485          (id (mail-header-id header))
4486          (data (gnus-data-find article))
4487          (thread (gnus-id-to-thread id))
4488          (references (mail-header-references header))
4489          (parent
4490           (gnus-id-to-thread
4491            (or (gnus-parent-id
4492                 (when (and references
4493                            (not (equal "" references)))
4494                   references))
4495                "none")))
4496          (buffer-read-only nil)
4497          (old (car thread)))
4498     (when thread
4499       (unless iheader
4500         (setcar thread nil)
4501         (when parent
4502           (delq thread parent)))
4503       (if (gnus-summary-insert-subject id header)
4504           ;; Set the (possibly) new article number in the data structure.
4505           (gnus-data-set-number data (gnus-id-to-article id))
4506         (setcar thread old)
4507         nil))))
4508
4509 (defun gnus-rebuild-thread (id &optional line)
4510   "Rebuild the thread containing ID.
4511 If LINE, insert the rebuilt thread starting on line LINE."
4512   (let ((buffer-read-only nil)
4513         old-pos current thread data)
4514     (if (not gnus-show-threads)
4515         (setq thread (list (car (gnus-id-to-thread id))))
4516       ;; Get the thread this article is part of.
4517       (setq thread (gnus-remove-thread id)))
4518     (setq old-pos (point-at-bol))
4519     (setq current (save-excursion
4520                     (and (re-search-backward "[\r\n]" nil t)
4521                          (gnus-summary-article-number))))
4522     ;; If this is a gathered thread, we have to go some re-gathering.
4523     (when (stringp (car thread))
4524       (let ((subject (car thread))
4525             roots thr)
4526         (setq thread (cdr thread))
4527         (while thread
4528           (unless (memq (setq thr (gnus-id-to-thread
4529                                    (gnus-root-id
4530                                     (mail-header-id (caar thread)))))
4531                         roots)
4532             (push thr roots))
4533           (setq thread (cdr thread)))
4534         ;; We now have all (unique) roots.
4535         (if (= (length roots) 1)
4536             ;; All the loose roots are now one solid root.
4537             (setq thread (car roots))
4538           (setq thread (cons subject (gnus-sort-threads roots))))))
4539     (let (threads)
4540       ;; We then insert this thread into the summary buffer.
4541       (when line
4542         (goto-char (point-min))
4543         (forward-line (1- line)))
4544       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4545         (if gnus-show-threads
4546             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4547           (gnus-summary-prepare-unthreaded thread))
4548         (setq data (nreverse gnus-newsgroup-data))
4549         (setq threads gnus-newsgroup-threads))
4550       ;; We splice the new data into the data structure.
4551       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4552       ;;!!! then we want to insert at the beginning of the buffer.
4553       ;;!!! That happens to be true with Gnus now, but that may
4554       ;;!!! change in the future.  Perhaps.
4555       (gnus-data-enter-list
4556        (if line nil current) data (- (point) old-pos))
4557       (setq gnus-newsgroup-threads
4558             (nconc threads gnus-newsgroup-threads))
4559       (gnus-data-compute-positions))))
4560
4561 (defun gnus-number-to-header (number)
4562   "Return the header for article NUMBER."
4563   (let ((headers gnus-newsgroup-headers))
4564     (while (and headers
4565                 (not (= number (mail-header-number (car headers)))))
4566       (pop headers))
4567     (when headers
4568       (car headers))))
4569
4570 (defun gnus-parent-headers (in-headers &optional generation)
4571   "Return the headers of the GENERATIONeth parent of HEADERS."
4572   (unless generation
4573     (setq generation 1))
4574   (let ((parent t)
4575         (headers in-headers)
4576         references)
4577     (while (and parent
4578                 (not (zerop generation))
4579                 (setq references (mail-header-references headers)))
4580       (setq headers (if (and references
4581                              (setq parent (gnus-parent-id references)))
4582                         (car (gnus-id-to-thread parent))
4583                       nil))
4584       (decf generation))
4585     (and (not (eq headers in-headers))
4586          headers)))
4587
4588 (defun gnus-id-to-thread (id)
4589   "Return the (sub-)thread where ID appears."
4590   (gnus-gethash id gnus-newsgroup-dependencies))
4591
4592 (defun gnus-id-to-article (id)
4593   "Return the article number of ID."
4594   (let ((thread (gnus-id-to-thread id)))
4595     (when (and thread
4596                (car thread))
4597       (mail-header-number (car thread)))))
4598
4599 (defun gnus-id-to-header (id)
4600   "Return the article headers of ID."
4601   (car (gnus-id-to-thread id)))
4602
4603 (defun gnus-article-displayed-root-p (article)
4604   "Say whether ARTICLE is a root(ish) article."
4605   (let ((level (gnus-summary-thread-level article))
4606         (refs (mail-header-references  (gnus-summary-article-header article)))
4607         particle)
4608     (cond
4609      ((null level) nil)
4610      ((zerop level) t)
4611      ((null refs) t)
4612      ((null (gnus-parent-id refs)) t)
4613      ((and (= 1 level)
4614            (null (setq particle (gnus-id-to-article
4615                                  (gnus-parent-id refs))))
4616            (null (gnus-summary-thread-level particle)))))))
4617
4618 (defun gnus-root-id (id)
4619   "Return the id of the root of the thread where ID appears."
4620   (let (last-id prev)
4621     (while (and id (setq prev (car (gnus-id-to-thread id))))
4622       (setq last-id id
4623             id (gnus-parent-id (mail-header-references prev))))
4624     last-id))
4625
4626 (defun gnus-articles-in-thread (thread)
4627   "Return the list of articles in THREAD."
4628   (cons (mail-header-number (car thread))
4629         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4630
4631 (defun gnus-remove-thread (id &optional dont-remove)
4632   "Remove the thread that has ID in it."
4633   (let (headers thread last-id)
4634     ;; First go up in this thread until we find the root.
4635     (setq last-id (gnus-root-id id)
4636           headers (message-flatten-list (gnus-id-to-thread last-id)))
4637     ;; We have now found the real root of this thread.  It might have
4638     ;; been gathered into some loose thread, so we have to search
4639     ;; through the threads to find the thread we wanted.
4640     (let ((threads gnus-newsgroup-threads)
4641           sub)
4642       (while threads
4643         (setq sub (car threads))
4644         (if (stringp (car sub))
4645             ;; This is a gathered thread, so we look at the roots
4646             ;; below it to find whether this article is in this
4647             ;; gathered root.
4648             (progn
4649               (setq sub (cdr sub))
4650               (while sub
4651                 (when (member (caar sub) headers)
4652                   (setq thread (car threads)
4653                         threads nil
4654                         sub nil))
4655                 (setq sub (cdr sub))))
4656           ;; It's an ordinary thread, so we check it.
4657           (when (eq (car sub) (car headers))
4658             (setq thread sub
4659                   threads nil)))
4660         (setq threads (cdr threads)))
4661       ;; If this article is in no thread, then it's a root.
4662       (if thread
4663           (unless dont-remove
4664             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4665         (setq thread (gnus-id-to-thread last-id)))
4666       (when thread
4667         (prog1
4668             thread                      ; We return this thread.
4669           (unless dont-remove
4670             (if (stringp (car thread))
4671                 (progn
4672                   ;; If we use dummy roots, then we have to remove the
4673                   ;; dummy root as well.
4674                   (when (eq gnus-summary-make-false-root 'dummy)
4675                     ;; We go to the dummy root by going to
4676                     ;; the first sub-"thread", and then one line up.
4677                     (gnus-summary-goto-article
4678                      (mail-header-number (caadr thread)))
4679                     (forward-line -1)
4680                     (gnus-delete-line)
4681                     (gnus-data-compute-positions))
4682                   (setq thread (cdr thread))
4683                   (while thread
4684                     (gnus-remove-thread-1 (car thread))
4685                     (setq thread (cdr thread))))
4686               (gnus-remove-thread-1 thread))))))))
4687
4688 (defun gnus-remove-thread-1 (thread)
4689   "Remove the thread THREAD recursively."
4690   (let ((number (mail-header-number (pop thread)))
4691         d)
4692     (setq thread (reverse thread))
4693     (while thread
4694       (gnus-remove-thread-1 (pop thread)))
4695     (when (setq d (gnus-data-find number))
4696       (goto-char (gnus-data-pos d))
4697       (gnus-summary-show-thread)
4698       (gnus-data-remove
4699        number
4700        (- (point-at-bol)
4701           (prog1
4702               (1+ (point-at-eol))
4703             (gnus-delete-line)))))))
4704
4705 (defun gnus-sort-threads-recursive (threads func)
4706   (sort (mapcar (lambda (thread)
4707                   (cons (car thread)
4708                         (and (cdr thread)
4709                              (gnus-sort-threads-recursive (cdr thread) func))))
4710                 threads) func))
4711
4712 (defun gnus-sort-threads-loop (threads func)
4713   (let* ((superthread (cons nil threads))
4714          (stack (list (cons superthread threads)))
4715          remaining-threads thread)
4716     (while stack
4717       (setq remaining-threads (cdr (car stack)))
4718       (if remaining-threads
4719           (progn (setq thread (car remaining-threads))
4720                  (setcdr (car stack) (cdr remaining-threads))
4721                  (if (cdr thread)
4722                      (push (cons thread (cdr thread)) stack)))
4723         (setq thread (caar stack))
4724         (setcdr thread (sort (cdr thread) func))
4725         (pop stack)))
4726     (cdr superthread)))
4727
4728 (defun gnus-sort-threads (threads)
4729   "Sort THREADS."
4730   (if (not gnus-thread-sort-functions)
4731       threads
4732     (gnus-message 8 "Sorting threads...")
4733     (prog1
4734         (condition-case nil
4735             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4736               (gnus-sort-threads-recursive
4737                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4738           ;; Even after binding max-lisp-eval-depth, the recursive
4739           ;; sorter might fail for very long threads.  In that case,
4740           ;; try using a (less well-tested) non-recursive sorter.
4741           (error (gnus-sort-threads-loop
4742                   threads (gnus-make-sort-function
4743                            gnus-thread-sort-functions))))
4744       (gnus-message 8 "Sorting threads...done"))))
4745
4746 (defun gnus-sort-articles (articles)
4747   "Sort ARTICLES."
4748   (when gnus-article-sort-functions
4749     (gnus-message 7 "Sorting articles...")
4750     (prog1
4751         (setq gnus-newsgroup-headers
4752               (sort articles (gnus-make-sort-function
4753                               gnus-article-sort-functions)))
4754       (gnus-message 7 "Sorting articles...done"))))
4755
4756 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4757 (defmacro gnus-thread-header (thread)
4758   "Return header of first article in THREAD.
4759 Note that THREAD must never, ever be anything else than a variable -
4760 using some other form will lead to serious barfage."
4761   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4762   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4763   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4764         (vector thread) 2))
4765
4766 (defsubst gnus-article-sort-by-number (h1 h2)
4767   "Sort articles by article number."
4768   (< (mail-header-number h1)
4769      (mail-header-number h2)))
4770
4771 (defun gnus-thread-sort-by-number (h1 h2)
4772   "Sort threads by root article number."
4773   (gnus-article-sort-by-number
4774    (gnus-thread-header h1) (gnus-thread-header h2)))
4775
4776 (defsubst gnus-article-sort-by-random (h1 h2)
4777   "Sort articles by article number."
4778   (zerop (random 2)))
4779
4780 (defun gnus-thread-sort-by-random (h1 h2)
4781   "Sort threads by root article number."
4782   (gnus-article-sort-by-random
4783    (gnus-thread-header h1) (gnus-thread-header h2)))
4784
4785 (defsubst gnus-article-sort-by-lines (h1 h2)
4786   "Sort articles by article Lines header."
4787   (< (mail-header-lines h1)
4788      (mail-header-lines h2)))
4789
4790 (defun gnus-thread-sort-by-lines (h1 h2)
4791   "Sort threads by root article Lines header."
4792   (gnus-article-sort-by-lines
4793    (gnus-thread-header h1) (gnus-thread-header h2)))
4794
4795 (defsubst gnus-article-sort-by-chars (h1 h2)
4796   "Sort articles by octet length."
4797   (< (mail-header-chars h1)
4798      (mail-header-chars h2)))
4799
4800 (defun gnus-thread-sort-by-chars (h1 h2)
4801   "Sort threads by root article octet length."
4802   (gnus-article-sort-by-chars
4803    (gnus-thread-header h1) (gnus-thread-header h2)))
4804
4805 (defsubst gnus-article-sort-by-author (h1 h2)
4806   "Sort articles by root author."
4807   (string-lessp
4808    (let ((extract (funcall
4809                    gnus-extract-address-components
4810                    (mail-header-from h1))))
4811      (or (car extract) (cadr extract) ""))
4812    (let ((extract (funcall
4813                    gnus-extract-address-components
4814                    (mail-header-from h2))))
4815      (or (car extract) (cadr extract) ""))))
4816
4817 (defun gnus-thread-sort-by-author (h1 h2)
4818   "Sort threads by root author."
4819   (gnus-article-sort-by-author
4820    (gnus-thread-header h1)  (gnus-thread-header h2)))
4821
4822 (defsubst gnus-article-sort-by-recipient (h1 h2)
4823   "Sort articles by recipient."
4824   (string-lessp
4825    (let ((extract (funcall
4826                    gnus-extract-address-components
4827                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4828      (or (car extract) (cadr extract)))
4829    (let ((extract (funcall
4830                    gnus-extract-address-components
4831                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4832      (or (car extract) (cadr extract)))))
4833
4834 (defun gnus-thread-sort-by-recipient (h1 h2)
4835   "Sort threads by root recipient."
4836   (gnus-article-sort-by-recipient
4837    (gnus-thread-header h1) (gnus-thread-header h2)))
4838
4839 (defsubst gnus-article-sort-by-subject (h1 h2)
4840   "Sort articles by root subject."
4841   (string-lessp
4842    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4843    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4844
4845 (defun gnus-thread-sort-by-subject (h1 h2)
4846   "Sort threads by root subject."
4847   (gnus-article-sort-by-subject
4848    (gnus-thread-header h1) (gnus-thread-header h2)))
4849
4850 (defsubst gnus-article-sort-by-date (h1 h2)
4851   "Sort articles by root article date."
4852   (time-less-p
4853    (gnus-date-get-time (mail-header-date h1))
4854    (gnus-date-get-time (mail-header-date h2))))
4855
4856 (defun gnus-thread-sort-by-date (h1 h2)
4857   "Sort threads by root article date."
4858   (gnus-article-sort-by-date
4859    (gnus-thread-header h1) (gnus-thread-header h2)))
4860
4861 (defsubst gnus-article-sort-by-score (h1 h2)
4862   "Sort articles by root article score.
4863 Unscored articles will be counted as having a score of zero."
4864   (> (or (cdr (assq (mail-header-number h1)
4865                     gnus-newsgroup-scored))
4866          gnus-summary-default-score 0)
4867      (or (cdr (assq (mail-header-number h2)
4868                     gnus-newsgroup-scored))
4869          gnus-summary-default-score 0)))
4870
4871 (defun gnus-thread-sort-by-score (h1 h2)
4872   "Sort threads by root article score."
4873   (gnus-article-sort-by-score
4874    (gnus-thread-header h1) (gnus-thread-header h2)))
4875
4876 (defun gnus-thread-sort-by-total-score (h1 h2)
4877   "Sort threads by the sum of all scores in the thread.
4878 Unscored articles will be counted as having a score of zero."
4879   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4880
4881 (defun gnus-thread-total-score (thread)
4882   ;; This function find the total score of THREAD.
4883   (cond
4884    ((null thread)
4885     0)
4886    ((consp thread)
4887     (if (stringp (car thread))
4888         (apply gnus-thread-score-function 0
4889                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4890       (gnus-thread-total-score-1 thread)))
4891    (t
4892     (gnus-thread-total-score-1 (list thread)))))
4893
4894 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4895   "Sort threads such that the thread with the most recently arrived article comes first."
4896   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4897
4898 (defun gnus-thread-highest-number (thread)
4899   "Return the highest article number in THREAD."
4900   (apply 'max (mapcar (lambda (header)
4901                         (mail-header-number header))
4902                       (message-flatten-list thread))))
4903
4904 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4905   "Sort threads such that the thread with the most recently dated article comes first."
4906   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4907
4908 (defun gnus-thread-latest-date (thread)
4909   "Return the highest article date in THREAD."
4910   (let ((previous-time 0))
4911     (apply 'max
4912            (mapcar
4913             (lambda (header)
4914               (setq previous-time
4915                     (condition-case ()
4916                         (time-to-seconds (mail-header-parse-date
4917                                           (mail-header-date header)))
4918                       (error previous-time))))
4919             (sort
4920              (message-flatten-list thread)
4921              (lambda (h1 h2)
4922                (< (mail-header-number h1)
4923                   (mail-header-number h2))))))))
4924
4925 (defun gnus-thread-total-score-1 (root)
4926   ;; This function find the total score of the thread below ROOT.
4927   (setq root (car root))
4928   (apply gnus-thread-score-function
4929          (or (append
4930               (mapcar 'gnus-thread-total-score
4931                       (cdr (gnus-id-to-thread (mail-header-id root))))
4932               (when (> (mail-header-number root) 0)
4933                 (list (or (cdr (assq (mail-header-number root)
4934                                      gnus-newsgroup-scored))
4935                           gnus-summary-default-score 0))))
4936              (list gnus-summary-default-score)
4937              '(0))))
4938
4939 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4940 (defvar gnus-tmp-prev-subject nil)
4941 (defvar gnus-tmp-false-parent nil)
4942 (defvar gnus-tmp-root-expunged nil)
4943 (defvar gnus-tmp-dummy-line nil)
4944
4945 (eval-when-compile (defvar gnus-tmp-header))
4946 (defun gnus-extra-header (type &optional header)
4947   "Return the extra header of TYPE."
4948   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4949       ""))
4950
4951 (defvar gnus-tmp-thread-tree-header-string "")
4952
4953 (defcustom gnus-sum-thread-tree-root "> "
4954   "With %B spec, used for the root of a thread.
4955 If nil, use subject instead."
4956   :version "22.1"
4957   :type '(radio (const :format "%v  " nil) string)
4958   :group 'gnus-thread)
4959
4960 (defcustom gnus-sum-thread-tree-false-root "> "
4961   "With %B spec, used for a false root of a thread.
4962 If nil, use subject instead."
4963   :version "22.1"
4964   :type '(radio (const :format "%v  " nil) string)
4965   :group 'gnus-thread)
4966
4967 (defcustom gnus-sum-thread-tree-single-indent ""
4968   "With %B spec, used for a thread with just one message.
4969 If nil, use subject instead."
4970   :version "22.1"
4971   :type '(radio (const :format "%v  " nil) string)
4972   :group 'gnus-thread)
4973
4974 (defcustom gnus-sum-thread-tree-vertical "| "
4975   "With %B spec, used for drawing a vertical line."
4976   :version "22.1"
4977   :type 'string
4978   :group 'gnus-thread)
4979
4980 (defcustom gnus-sum-thread-tree-indent "  "
4981   "With %B spec, used for indenting."
4982   :version "22.1"
4983   :type 'string
4984   :group 'gnus-thread)
4985
4986 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4987   "With %B spec, used for a leaf with brothers."
4988   :version "22.1"
4989   :type 'string
4990   :group 'gnus-thread)
4991
4992 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4993   "With %B spec, used for a leaf without brothers."
4994   :version "22.1"
4995   :type 'string
4996   :group 'gnus-thread)
4997
4998 (defun gnus-summary-prepare-threads (threads)
4999   "Prepare summary buffer from THREADS and indentation LEVEL.
5000 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5001 or a straight list of headers."
5002   (gnus-message 7 "Generating summary...")
5003
5004   (setq gnus-newsgroup-threads threads)
5005   (beginning-of-line)
5006
5007   (let ((gnus-tmp-level 0)
5008         (default-score (or gnus-summary-default-score 0))
5009         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5010         (building-line-count gnus-summary-display-while-building)
5011         (building-count (integerp gnus-summary-display-while-building))
5012         thread number subject stack state gnus-tmp-gathered beg-match
5013         new-roots gnus-tmp-new-adopts thread-end simp-subject
5014         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5015         gnus-tmp-replied gnus-tmp-subject-or-nil
5016         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5017         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5018         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5019         tree-stack)
5020
5021     (setq gnus-tmp-prev-subject nil
5022           gnus-tmp-thread-tree-header-string "")
5023
5024     (if (vectorp (car threads))
5025         ;; If this is a straight (sic) list of headers, then a
5026         ;; threaded summary display isn't required, so we just create
5027         ;; an unthreaded one.
5028         (gnus-summary-prepare-unthreaded threads)
5029
5030       ;; Do the threaded display.
5031
5032       (if gnus-summary-display-while-building
5033           (switch-to-buffer (buffer-name)))
5034       (while (or threads stack gnus-tmp-new-adopts new-roots)
5035
5036         (if (and (= gnus-tmp-level 0)
5037                  (or (not stack)
5038                      (= (caar stack) 0))
5039                  (not gnus-tmp-false-parent)
5040                  (or gnus-tmp-new-adopts new-roots))
5041             (if gnus-tmp-new-adopts
5042                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5043                       thread (list (car gnus-tmp-new-adopts))
5044                       gnus-tmp-header (caar thread)
5045                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5046               (when new-roots
5047                 (setq thread (list (car new-roots))
5048                       gnus-tmp-header (caar thread)
5049                       new-roots (cdr new-roots))))
5050
5051           (if threads
5052               ;; If there are some threads, we do them before the
5053               ;; threads on the stack.
5054               (setq thread threads
5055                     gnus-tmp-header (caar thread))
5056             ;; There were no current threads, so we pop something off
5057             ;; the stack.
5058             (setq state (car stack)
5059                   gnus-tmp-level (car state)
5060                   tree-stack (cadr state)
5061                   thread (caddr state)
5062                   stack (cdr stack)
5063                   gnus-tmp-header (caar thread))))
5064
5065         (setq gnus-tmp-false-parent nil)
5066         (setq gnus-tmp-root-expunged nil)
5067         (setq thread-end nil)
5068
5069         (if (stringp gnus-tmp-header)
5070             ;; The header is a dummy root.
5071             (cond
5072              ((eq gnus-summary-make-false-root 'adopt)
5073               ;; We let the first article adopt the rest.
5074               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5075                                                (cddar thread)))
5076               (setq gnus-tmp-gathered
5077                     (nconc (mapcar
5078                             (lambda (h) (mail-header-number (car h)))
5079                             (cddar thread))
5080                            gnus-tmp-gathered))
5081               (setq thread (cons (list (caar thread)
5082                                        (cadar thread))
5083                                  (cdr thread)))
5084               (setq gnus-tmp-level -1
5085                     gnus-tmp-false-parent t))
5086              ((eq gnus-summary-make-false-root 'empty)
5087               ;; We print adopted articles with empty subject fields.
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 gnus-tmp-level -1))
5094              ((eq gnus-summary-make-false-root 'dummy)
5095               ;; We remember that we probably want to output a dummy
5096               ;; root.
5097               (setq gnus-tmp-dummy-line gnus-tmp-header)
5098               (setq gnus-tmp-prev-subject gnus-tmp-header))
5099              (t
5100               ;; We do not make a root for the gathered
5101               ;; sub-threads at all.
5102               (setq gnus-tmp-level -1)))
5103
5104           (setq number (mail-header-number gnus-tmp-header)
5105                 subject (mail-header-subject gnus-tmp-header)
5106                 simp-subject (gnus-simplify-subject-fully subject))
5107
5108           (cond
5109            ;; If the thread has changed subject, we might want to make
5110            ;; this subthread into a root.
5111            ((and (null gnus-thread-ignore-subject)
5112                  (not (zerop gnus-tmp-level))
5113                  gnus-tmp-prev-subject
5114                  (not (string= gnus-tmp-prev-subject simp-subject)))
5115             (setq new-roots (nconc new-roots (list (car thread)))
5116                   thread-end t
5117                   gnus-tmp-header nil))
5118            ;; If the article lies outside the current limit,
5119            ;; then we do not display it.
5120            ((not (memq number gnus-newsgroup-limit))
5121             (setq gnus-tmp-gathered
5122                   (nconc (mapcar
5123                           (lambda (h) (mail-header-number (car h)))
5124                           (cdar thread))
5125                          gnus-tmp-gathered))
5126             (setq gnus-tmp-new-adopts (if (cdar thread)
5127                                           (append gnus-tmp-new-adopts
5128                                                   (cdar thread))
5129                                         gnus-tmp-new-adopts)
5130                   thread-end t
5131                   gnus-tmp-header nil)
5132             (when (zerop gnus-tmp-level)
5133               (setq gnus-tmp-root-expunged t)))
5134            ;; Perhaps this article is to be marked as read?
5135            ((and gnus-summary-mark-below
5136                  (< (or (cdr (assq number gnus-newsgroup-scored))
5137                         default-score)
5138                     gnus-summary-mark-below)
5139                  ;; Don't touch sparse articles.
5140                  (not (gnus-summary-article-sparse-p number))
5141                  (not (gnus-summary-article-ancient-p number)))
5142             (setq gnus-newsgroup-unreads
5143                   (delq number gnus-newsgroup-unreads))
5144             (if gnus-newsgroup-auto-expire
5145                 (setq gnus-newsgroup-expirable
5146                       (gnus-add-to-sorted-list
5147                        gnus-newsgroup-expirable number))
5148               (push (cons number gnus-low-score-mark)
5149                     gnus-newsgroup-reads))))
5150
5151           (when gnus-tmp-header
5152             ;; We may have an old dummy line to output before this
5153             ;; article.
5154             (when (and gnus-tmp-dummy-line
5155                        (gnus-subject-equal
5156                         gnus-tmp-dummy-line
5157                         (mail-header-subject gnus-tmp-header)))
5158               (gnus-summary-insert-dummy-line
5159                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5160               (setq gnus-tmp-dummy-line nil))
5161
5162             ;; Compute the mark.
5163             (setq gnus-tmp-unread (gnus-article-mark number))
5164
5165             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5166                                   gnus-tmp-header gnus-tmp-level)
5167                   gnus-newsgroup-data)
5168
5169             ;; Actually insert the line.
5170             (setq
5171              gnus-tmp-subject-or-nil
5172              (cond
5173               ((and gnus-thread-ignore-subject
5174                     gnus-tmp-prev-subject
5175                     (not (string= gnus-tmp-prev-subject simp-subject)))
5176                subject)
5177               ((zerop gnus-tmp-level)
5178                (if (and (eq gnus-summary-make-false-root 'empty)
5179                         (memq number gnus-tmp-gathered)
5180                         gnus-tmp-prev-subject
5181                         (string= gnus-tmp-prev-subject simp-subject))
5182                    gnus-summary-same-subject
5183                  subject))
5184               (t gnus-summary-same-subject)))
5185             (if (and (eq gnus-summary-make-false-root 'adopt)
5186                      (= gnus-tmp-level 1)
5187                      (memq number gnus-tmp-gathered))
5188                 (setq gnus-tmp-opening-bracket ?\<
5189                       gnus-tmp-closing-bracket ?\>)
5190               (setq gnus-tmp-opening-bracket ?\[
5191                     gnus-tmp-closing-bracket ?\]))
5192             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5193                 (gnus-make-thread-indent-array
5194                  (max (* 2 (length gnus-thread-indent-array))
5195                       gnus-tmp-level)))
5196             (setq
5197              gnus-tmp-indentation
5198              (aref gnus-thread-indent-array gnus-tmp-level)
5199              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5200              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5201                                 gnus-summary-default-score 0)
5202              gnus-tmp-score-char
5203              (if (or (null gnus-summary-default-score)
5204                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5205                          gnus-summary-zcore-fuzz))
5206                  ?                      ;Whitespace
5207                (if (< gnus-tmp-score gnus-summary-default-score)
5208                    gnus-score-below-mark gnus-score-over-mark))
5209              gnus-tmp-replied
5210              (cond ((memq number gnus-newsgroup-processable)
5211                     gnus-process-mark)
5212                    ((memq number gnus-newsgroup-cached)
5213                     gnus-cached-mark)
5214                    ((memq number gnus-newsgroup-replied)
5215                     gnus-replied-mark)
5216                    ((memq number gnus-newsgroup-forwarded)
5217                     gnus-forwarded-mark)
5218                    ((memq number gnus-newsgroup-saved)
5219                     gnus-saved-mark)
5220                    ((memq number gnus-newsgroup-recent)
5221                     gnus-recent-mark)
5222                    ((memq number gnus-newsgroup-unseen)
5223                     gnus-unseen-mark)
5224                    (t gnus-no-mark))
5225              gnus-tmp-downloaded
5226              (cond ((memq number gnus-newsgroup-undownloaded)
5227                     gnus-undownloaded-mark)
5228                    (gnus-newsgroup-agentized
5229                     gnus-downloaded-mark)
5230                    (t
5231                     gnus-no-mark))
5232              gnus-tmp-from (mail-header-from gnus-tmp-header)
5233              gnus-tmp-name
5234              (cond
5235               ((string-match "<[^>]+> *$" gnus-tmp-from)
5236                (setq beg-match (match-beginning 0))
5237                (or (and (string-match "^\".+\"" gnus-tmp-from)
5238                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5239                    (substring gnus-tmp-from 0 beg-match)))
5240               ((string-match "(.+)" gnus-tmp-from)
5241                (substring gnus-tmp-from
5242                           (1+ (match-beginning 0)) (1- (match-end 0))))
5243               (t gnus-tmp-from))
5244
5245              ;; Do the %B string
5246              gnus-tmp-thread-tree-header-string
5247              (cond
5248               ((not gnus-show-threads) "")
5249               ((zerop gnus-tmp-level)
5250                (cond ((cdar thread)
5251                       (or gnus-sum-thread-tree-root subject))
5252                      (gnus-tmp-new-adopts
5253                       (or gnus-sum-thread-tree-false-root subject))
5254                      (t
5255                       (or gnus-sum-thread-tree-single-indent subject))))
5256               (t
5257                (concat (apply 'concat
5258                               (mapcar (lambda (item)
5259                                         (if (= item 1)
5260                                             gnus-sum-thread-tree-vertical
5261                                           gnus-sum-thread-tree-indent))
5262                                       (cdr (reverse tree-stack))))
5263                        (if (nth 1 thread)
5264                            gnus-sum-thread-tree-leaf-with-other
5265                          gnus-sum-thread-tree-single-leaf)))))
5266             (when (string= gnus-tmp-name "")
5267               (setq gnus-tmp-name gnus-tmp-from))
5268             (unless (numberp gnus-tmp-lines)
5269               (setq gnus-tmp-lines -1))
5270             (if (= gnus-tmp-lines -1)
5271                 (setq gnus-tmp-lines "?")
5272               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5273               (gnus-put-text-property
5274              (point)
5275              (progn (eval gnus-summary-line-format-spec) (point))
5276                'gnus-number number)
5277             (when gnus-visual-p
5278               (forward-line -1)
5279               (gnus-run-hooks 'gnus-summary-update-hook)
5280               (forward-line 1))
5281
5282             (setq gnus-tmp-prev-subject simp-subject)))
5283
5284         (when (nth 1 thread)
5285           (push (list (max 0 gnus-tmp-level)
5286                       (copy-sequence tree-stack)
5287                       (nthcdr 1 thread))
5288                 stack))
5289         (push (if (nth 1 thread) 1 0) tree-stack)
5290         (incf gnus-tmp-level)
5291         (setq threads (if thread-end nil (cdar thread)))
5292         (if gnus-summary-display-while-building
5293             (if building-count
5294                 (progn
5295                   ;; use a set frequency
5296                   (setq building-line-count (1- building-line-count))
5297                   (when (= building-line-count 0)
5298                     (sit-for 0)
5299                     (setq building-line-count
5300                           gnus-summary-display-while-building)))
5301               ;; always
5302               (sit-for 0)))
5303         (unless threads
5304           (setq gnus-tmp-level 0)))))
5305   (gnus-message 7 "Generating summary...done"))
5306
5307 (defun gnus-summary-prepare-unthreaded (headers)
5308   "Generate an unthreaded summary buffer based on HEADERS."
5309   (let (header number mark)
5310
5311     (beginning-of-line)
5312
5313     (while headers
5314       ;; We may have to root out some bad articles...
5315       (when (memq (setq number (mail-header-number
5316                                 (setq header (pop headers))))
5317                   gnus-newsgroup-limit)
5318         ;; Mark article as read when it has a low score.
5319         (when (and gnus-summary-mark-below
5320                    (< (or (cdr (assq number gnus-newsgroup-scored))
5321                           gnus-summary-default-score 0)
5322                       gnus-summary-mark-below)
5323                    (not (gnus-summary-article-ancient-p number)))
5324           (setq gnus-newsgroup-unreads
5325                 (delq number gnus-newsgroup-unreads))
5326           (if gnus-newsgroup-auto-expire
5327               (push number gnus-newsgroup-expirable)
5328             (push (cons number gnus-low-score-mark)
5329                   gnus-newsgroup-reads)))
5330
5331         (setq mark (gnus-article-mark number))
5332         (push (gnus-data-make number mark (1+ (point)) header 0)
5333               gnus-newsgroup-data)
5334         (gnus-summary-insert-line
5335          header 0 number
5336          (memq number gnus-newsgroup-undownloaded)
5337          mark (memq number gnus-newsgroup-replied)
5338          (memq number gnus-newsgroup-expirable)
5339          (mail-header-subject header) nil
5340          (cdr (assq number gnus-newsgroup-scored))
5341          (memq number gnus-newsgroup-processable))))))
5342
5343 (defun gnus-summary-remove-list-identifiers ()
5344   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5345   (let ((regexp (if (consp gnus-list-identifiers)
5346                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5347                   gnus-list-identifiers))
5348         changed subject)
5349     (when regexp
5350       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5351       (dolist (header gnus-newsgroup-headers)
5352         (setq subject (mail-header-subject header)
5353               changed nil)
5354         (while (string-match regexp subject)
5355           (setq subject
5356                 (concat (substring subject 0 (match-beginning 1))
5357                         (substring subject (match-end 0)))
5358                 changed t))
5359         (when changed
5360           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5361             (setq subject
5362                   (concat (substring subject 0 (match-beginning 1))
5363                           (substring subject (match-end 1)))))
5364           (mail-header-set-subject header subject))))))
5365
5366 (defun gnus-fetch-headers (articles)
5367   "Fetch headers of ARTICLES."
5368   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5369     (gnus-message 5 "Fetching headers for %s..." name)
5370     (prog1
5371         (if (eq 'nov
5372                 (setq gnus-headers-retrieved-by
5373                       (gnus-retrieve-headers
5374                        articles gnus-newsgroup-name
5375                        ;; We might want to fetch old headers, but
5376                        ;; not if there is only 1 article.
5377                        (and (or (and
5378                                  (not (eq gnus-fetch-old-headers 'some))
5379                                  (not (numberp gnus-fetch-old-headers)))
5380                                 (> (length articles) 1))
5381                             gnus-fetch-old-headers))))
5382             (gnus-get-newsgroup-headers-xover
5383              articles nil nil gnus-newsgroup-name t)
5384           (gnus-get-newsgroup-headers))
5385       (gnus-message 5 "Fetching headers for %s...done" name))))
5386
5387 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5388   "Select newsgroup GROUP.
5389 If READ-ALL is non-nil, all articles in the group are selected.
5390 If SELECT-ARTICLES, only select those articles from GROUP."
5391   (let* ((entry (gnus-group-entry group))
5392          ;;!!! Dirty hack; should be removed.
5393          (gnus-summary-ignore-duplicates
5394           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5395               t
5396             gnus-summary-ignore-duplicates))
5397          (info (nth 2 entry))
5398          articles fetched-articles cached)
5399
5400     (unless (gnus-check-server
5401              (set (make-local-variable 'gnus-current-select-method)
5402                   (gnus-find-method-for-group group)))
5403       (error "Couldn't open server"))
5404
5405     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5406         (gnus-activate-group group)     ; Or we can activate it...
5407         (progn                          ; Or we bug out.
5408           (when (equal major-mode 'gnus-summary-mode)
5409             (gnus-kill-buffer (current-buffer)))
5410           (error "Couldn't activate group %s: %s"
5411                  (gnus-group-decoded-name group) (gnus-status-message group))))
5412
5413     (unless (gnus-request-group group t)
5414       (when (equal major-mode 'gnus-summary-mode)
5415         (gnus-kill-buffer (current-buffer)))
5416       (error "Couldn't request group %s: %s"
5417              (gnus-group-decoded-name group) (gnus-status-message group)))
5418
5419     (when gnus-agent
5420       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5421
5422       (setq gnus-summary-use-undownloaded-faces
5423             (gnus-agent-find-parameter
5424              group
5425              'agent-enable-undownloaded-faces)))
5426
5427     (setq gnus-newsgroup-name group
5428           gnus-newsgroup-unselected nil
5429           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5430
5431     (let ((display (gnus-group-find-parameter group 'display)))
5432       (setq gnus-newsgroup-display
5433             (cond
5434              ((not (zerop (or (car-safe read-all) 0)))
5435               ;; The user entered the group with C-u SPC/RET, let's show
5436               ;; all articles.
5437               'gnus-not-ignore)
5438              ((eq display 'all)
5439               'gnus-not-ignore)
5440              ((arrayp display)
5441               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5442              ((numberp display)
5443               ;; The following is probably the "correct" solution, but
5444               ;; it makes Gnus fetch all headers and then limit the
5445               ;; articles (which is slow), so instead we hack the
5446               ;; select-articles parameter instead. -- Simon Josefsson
5447               ;; <jas@kth.se>
5448               ;;
5449               ;; (gnus-byte-compile
5450               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5451               ;;                         display)))))
5452               (setq select-articles
5453                     (gnus-uncompress-range
5454                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5455                              (if (> tmp 0)
5456                                  tmp
5457                                1))
5458                            (cdr (gnus-active group)))))
5459               nil)
5460              (t
5461               nil))))
5462
5463     (gnus-summary-setup-default-charset)
5464
5465     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5466     (when (gnus-virtual-group-p group)
5467       (setq cached gnus-newsgroup-cached))
5468
5469     (setq gnus-newsgroup-unreads
5470           (gnus-sorted-ndifference
5471            (gnus-sorted-ndifference gnus-newsgroup-unreads
5472                                     gnus-newsgroup-marked)
5473            gnus-newsgroup-dormant))
5474
5475     (setq gnus-newsgroup-processable nil)
5476
5477     (gnus-update-read-articles group gnus-newsgroup-unreads)
5478
5479     ;; Adjust and set lists of article marks.
5480     (when info
5481       (gnus-adjust-marked-articles info))
5482     (if (setq articles select-articles)
5483         (setq gnus-newsgroup-unselected
5484               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5485       (setq articles (gnus-articles-to-read group read-all)))
5486
5487     (cond
5488      ((null articles)
5489       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5490       'quit)
5491      ((eq articles 0) nil)
5492      (t
5493       ;; Init the dependencies hash table.
5494       (setq gnus-newsgroup-dependencies
5495             (gnus-make-hashtable (length articles)))
5496       (gnus-set-global-variables)
5497       ;; Retrieve the headers and read them in.
5498
5499       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5500
5501       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5502       (when cached
5503         (setq gnus-newsgroup-cached cached))
5504
5505       ;; Suppress duplicates?
5506       (when gnus-suppress-duplicates
5507         (gnus-dup-suppress-articles))
5508
5509       ;; Set the initial limit.
5510       (setq gnus-newsgroup-limit (copy-sequence articles))
5511       ;; Remove canceled articles from the list of unread articles.
5512       (setq fetched-articles
5513             (mapcar (lambda (headers) (mail-header-number headers))
5514                     gnus-newsgroup-headers))
5515       (setq gnus-newsgroup-articles fetched-articles)
5516       (setq gnus-newsgroup-unreads
5517             (gnus-sorted-nintersection
5518              gnus-newsgroup-unreads fetched-articles))
5519       (gnus-compute-unseen-list)
5520
5521       ;; Removed marked articles that do not exist.
5522       (gnus-update-missing-marks
5523        (gnus-sorted-difference articles fetched-articles))
5524       ;; We might want to build some more threads first.
5525       (when (and gnus-fetch-old-headers
5526                  (eq gnus-headers-retrieved-by 'nov))
5527         (if (eq gnus-fetch-old-headers 'invisible)
5528             (gnus-build-all-threads)
5529           (gnus-build-old-threads)))
5530       ;; Let the Gnus agent mark articles as read.
5531       (when gnus-agent
5532         (gnus-agent-get-undownloaded-list))
5533       ;; Remove list identifiers from subject
5534       (when gnus-list-identifiers
5535         (gnus-summary-remove-list-identifiers))
5536       ;; Check whether auto-expire is to be done in this group.
5537       (setq gnus-newsgroup-auto-expire
5538             (gnus-group-auto-expirable-p group))
5539       ;; Set up the article buffer now, if necessary.
5540       (unless (and gnus-single-article-buffer
5541                    (equal gnus-article-buffer "*Article*"))
5542         (gnus-article-setup-buffer))
5543       ;; First and last article in this newsgroup.
5544       (when gnus-newsgroup-headers
5545         (setq gnus-newsgroup-begin
5546               (mail-header-number (car gnus-newsgroup-headers))
5547               gnus-newsgroup-end
5548               (mail-header-number
5549                (gnus-last-element gnus-newsgroup-headers))))
5550       ;; GROUP is successfully selected.
5551       (or gnus-newsgroup-headers t)))))
5552
5553 (defun gnus-compute-unseen-list ()
5554   ;; The `seen' marks are treated specially.
5555   (if (not gnus-newsgroup-seen)
5556       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5557     (setq gnus-newsgroup-unseen
5558           (gnus-inverse-list-range-intersection
5559            gnus-newsgroup-articles gnus-newsgroup-seen))))
5560
5561 (defun gnus-summary-display-make-predicate (display)
5562   (require 'gnus-agent)
5563   (when (= (length display) 1)
5564     (setq display (car display)))
5565   (unless gnus-summary-display-cache
5566     (dolist (elem (append '((unread . unread)
5567                             (read . read)
5568                             (unseen . unseen))
5569                           gnus-article-mark-lists))
5570       (push (cons (cdr elem)
5571                   (gnus-byte-compile
5572                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5573             gnus-summary-display-cache)))
5574   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5575         (gnus-category-predicate-cache gnus-summary-display-cache))
5576     (gnus-get-predicate display)))
5577
5578 ;; Uses the dynamically bound `number' variable.
5579 (eval-when-compile
5580   (defvar number))
5581 (defun gnus-article-marked-p (type &optional article)
5582   (let ((article (or article number)))
5583     (cond
5584      ((eq type 'tick)
5585       (memq article gnus-newsgroup-marked))
5586      ((eq type 'spam)
5587       (memq article gnus-newsgroup-spam-marked))
5588      ((eq type 'unsend)
5589       (memq article gnus-newsgroup-unsendable))
5590      ((eq type 'undownload)
5591       (memq article gnus-newsgroup-undownloaded))
5592      ((eq type 'download)
5593       (memq article gnus-newsgroup-downloadable))
5594      ((eq type 'unread)
5595       (memq article gnus-newsgroup-unreads))
5596      ((eq type 'read)
5597       (memq article gnus-newsgroup-reads))
5598      ((eq type 'dormant)
5599       (memq article gnus-newsgroup-dormant) )
5600      ((eq type 'expire)
5601       (memq article gnus-newsgroup-expirable))
5602      ((eq type 'reply)
5603       (memq article gnus-newsgroup-replied))
5604      ((eq type 'killed)
5605       (memq article gnus-newsgroup-killed))
5606      ((eq type 'bookmark)
5607       (assq article gnus-newsgroup-bookmarks))
5608      ((eq type 'score)
5609       (assq article gnus-newsgroup-scored))
5610      ((eq type 'save)
5611       (memq article gnus-newsgroup-saved))
5612      ((eq type 'cache)
5613       (memq article gnus-newsgroup-cached))
5614      ((eq type 'forward)
5615       (memq article gnus-newsgroup-forwarded))
5616      ((eq type 'seen)
5617       (not (memq article gnus-newsgroup-unseen)))
5618      ((eq type 'recent)
5619       (memq article gnus-newsgroup-recent))
5620      (t t))))
5621
5622 (defun gnus-articles-to-read (group &optional read-all)
5623   "Find out what articles the user wants to read."
5624   (let* ((articles
5625           ;; Select all articles if `read-all' is non-nil, or if there
5626           ;; are no unread articles.
5627           (if (or read-all
5628                   (and (zerop (length gnus-newsgroup-marked))
5629                        (zerop (length gnus-newsgroup-unreads)))
5630                   ;; Fetch all if the predicate is non-nil.
5631                   gnus-newsgroup-display)
5632               ;; We want to select the headers for all the articles in
5633               ;; the group, so we select either all the active
5634               ;; articles in the group, or (if that's nil), the
5635               ;; articles in the cache.
5636               (or
5637                (gnus-uncompress-range (gnus-active group))
5638                (gnus-cache-articles-in-group group))
5639             ;; Select only the "normal" subset of articles.
5640             (gnus-sorted-nunion
5641              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5642              gnus-newsgroup-unreads)))
5643          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5644          (scored (length scored-list))
5645          (number (length articles))
5646          (marked (+ (length gnus-newsgroup-marked)
5647                     (length gnus-newsgroup-dormant)))
5648          (select
5649           (cond
5650            ((numberp read-all)
5651             read-all)
5652            ((numberp gnus-newsgroup-display)
5653             gnus-newsgroup-display)
5654            (t
5655             (condition-case ()
5656                 (cond
5657                  ((and (or (<= scored marked) (= scored number))
5658                        (numberp gnus-large-newsgroup)
5659                        (> number gnus-large-newsgroup))
5660                   (let* ((cursor-in-echo-area nil)
5661                          (initial (gnus-parameter-large-newsgroup-initial
5662                                    gnus-newsgroup-name))
5663                          (input
5664                           (read-string
5665                            (format
5666                             "How many articles from %s (%s %d): "
5667                             (gnus-group-decoded-name gnus-newsgroup-name)
5668                             (if initial "max" "default")
5669                             number)
5670                            (if initial
5671                                (cons (number-to-string initial)
5672                                      0)))))
5673                     (if (string-match "^[ \t]*$" input) number input)))
5674                  ((and (> scored marked) (< scored number)
5675                        (> (- scored number) 20))
5676                   (let ((input
5677                          (read-string
5678                           (format "%s %s (%d scored, %d total): "
5679                                   "How many articles from"
5680                                   (gnus-group-decoded-name group)
5681                                   scored number))))
5682                     (if (string-match "^[ \t]*$" input)
5683                         number input)))
5684                  (t number))
5685               (quit
5686                (message "Quit getting the articles to read")
5687                nil))))))
5688     (setq select (if (stringp select) (string-to-number select) select))
5689     (if (or (null select) (zerop select))
5690         select
5691       (if (and (not (zerop scored)) (<= (abs select) scored))
5692           (progn
5693             (setq articles (sort scored-list '<))
5694             (setq number (length articles)))
5695         (setq articles (copy-sequence articles)))
5696
5697       (when (< (abs select) number)
5698         (if (< select 0)
5699             ;; Select the N oldest articles.
5700             (setcdr (nthcdr (1- (abs select)) articles) nil)
5701           ;; Select the N most recent articles.
5702           (setq articles (nthcdr (- number select) articles))))
5703       (setq gnus-newsgroup-unselected
5704             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5705       (when gnus-alter-articles-to-read-function
5706         (setq articles
5707               (sort
5708                (funcall gnus-alter-articles-to-read-function
5709                         gnus-newsgroup-name articles)
5710                '<)))
5711       articles)))
5712
5713 (defun gnus-killed-articles (killed articles)
5714   (let (out)
5715     (while articles
5716       (when (inline (gnus-member-of-range (car articles) killed))
5717         (push (car articles) out))
5718       (setq articles (cdr articles)))
5719     out))
5720
5721 (defun gnus-uncompress-marks (marks)
5722   "Uncompress the mark ranges in MARKS."
5723   (let ((uncompressed '(score bookmark))
5724         out)
5725     (while marks
5726       (if (memq (caar marks) uncompressed)
5727           (push (car marks) out)
5728         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5729       (setq marks (cdr marks)))
5730     out))
5731
5732 (defun gnus-article-mark-to-type (mark)
5733   "Return the type of MARK."
5734   (or (cadr (assq mark gnus-article-special-mark-lists))
5735       'list))
5736
5737 (defun gnus-article-unpropagatable-p (mark)
5738   "Return whether MARK should be propagated to back end."
5739   (memq mark gnus-article-unpropagated-mark-lists))
5740
5741 (defun gnus-adjust-marked-articles (info)
5742   "Set all article lists and remove all marks that are no longer valid."
5743   (let* ((marked-lists (gnus-info-marks info))
5744          (active (gnus-active (gnus-info-group info)))
5745          (min (car active))
5746          (max (cdr active))
5747          (types gnus-article-mark-lists)
5748          marks var articles article mark mark-type
5749          bgn end)
5750
5751     (dolist (marks marked-lists)
5752       (setq mark (car marks)
5753             mark-type (gnus-article-mark-to-type mark)
5754             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5755
5756       ;; We set the variable according to the type of the marks list,
5757       ;; and then adjust the marks to a subset of the active articles.
5758       (cond
5759        ;; Adjust "simple" lists - compressed yet unsorted
5760        ((eq mark-type 'list)
5761         ;; Simultaneously uncompress and clip to active range
5762         ;; See gnus-uncompress-range for a description of possible marks
5763         (let (l lh)
5764           (if (not (cadr marks))
5765               (set var nil)
5766             (setq articles (if (numberp (cddr marks))
5767                                (list (cdr marks))
5768                              (cdr marks))
5769                   lh (cons nil nil)
5770                   l lh)
5771
5772             (while (setq article (pop articles))
5773               (cond ((consp article)
5774                      (setq bgn (max (car article) min)
5775                            end (min (cdr article) max))
5776                      (while (<= bgn end)
5777                        (setq l (setcdr l (cons bgn nil))
5778                              bgn (1+ bgn))))
5779                     ((and (<= min article)
5780                           (>= max article))
5781                      (setq l (setcdr l (cons article nil))))))
5782             (set var (cdr lh)))))
5783        ;; Adjust assocs.
5784        ((eq mark-type 'tuple)
5785         (set var (setq articles (cdr marks)))
5786         (when (not (listp (cdr (symbol-value var))))
5787           (set var (list (symbol-value var))))
5788         (when (not (listp (cdr articles)))
5789           (setq articles (list articles)))
5790         (while articles
5791           (when (or (not (consp (setq article (pop articles))))
5792                     (< (car article) min)
5793                     (> (car article) max))
5794             (set var (delq article (symbol-value var))))))
5795        ;; Adjust ranges (sloppily).
5796        ((eq mark-type 'range)
5797         (cond
5798          ((eq mark 'seen)
5799           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5800           ;; It should be (seen (NUM1 . NUM2)).
5801           (when (numberp (cddr marks))
5802             (setcdr marks (list (cdr marks))))
5803           (setq articles (cdr marks))
5804           (while (and articles
5805                       (or (and (consp (car articles))
5806                                (> min (cdar articles)))
5807                           (and (numberp (car articles))
5808                                (> min (car articles)))))
5809             (pop articles))
5810           (set var articles))))))))
5811
5812 (defun gnus-update-missing-marks (missing)
5813   "Go through the list of MISSING articles and remove them from the mark lists."
5814   (when missing
5815     (let (var m)
5816       ;; Go through all types.
5817       (dolist (elem gnus-article-mark-lists)
5818         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5819           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5820           (when (symbol-value var)
5821             ;; This list has articles.  So we delete all missing
5822             ;; articles from it.
5823             (setq m missing)
5824             (while m
5825               (set var (delq (pop m) (symbol-value var))))))))))
5826
5827 (defun gnus-update-marks ()
5828   "Enter the various lists of marked articles into the newsgroup info list."
5829   (let ((types gnus-article-mark-lists)
5830         (info (gnus-get-info gnus-newsgroup-name))
5831         type list newmarked symbol delta-marks)
5832     (when info
5833       ;; Add all marks lists to the list of marks lists.
5834       (while (setq type (pop types))
5835         (setq list (symbol-value
5836                     (setq symbol
5837                           (intern (format "gnus-newsgroup-%s" (car type))))))
5838
5839         (when list
5840           ;; Get rid of the entries of the articles that have the
5841           ;; default score.
5842           (when (and (eq (cdr type) 'score)
5843                      gnus-save-score
5844                      list)
5845             (let* ((arts list)
5846                    (prev (cons nil list))
5847                    (all prev))
5848               (while arts
5849                 (if (or (not (consp (car arts)))
5850                         (= (cdar arts) gnus-summary-default-score))
5851                     (setcdr prev (cdr arts))
5852                   (setq prev arts))
5853                 (setq arts (cdr arts)))
5854               (setq list (cdr all)))))
5855
5856         (when (eq (cdr type) 'seen)
5857           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5858
5859         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5860           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5861
5862         (when (and (gnus-check-backend-function
5863                     'request-set-mark gnus-newsgroup-name)
5864                    (not (gnus-article-unpropagatable-p (cdr type))))
5865           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5866                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5867                  (add (gnus-remove-from-range
5868                        (gnus-copy-sequence list) old)))
5869             (when add
5870               (push (list add 'add (list (cdr type))) delta-marks))
5871             (when del
5872               (push (list del 'del (list (cdr type))) delta-marks))))
5873
5874         (when list
5875           (push (cons (cdr type) list) newmarked)))
5876
5877       (when delta-marks
5878         (unless (gnus-check-group gnus-newsgroup-name)
5879           (error "Can't open server for %s" gnus-newsgroup-name))
5880         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5881
5882       ;; Enter these new marks into the info of the group.
5883       (if (nthcdr 3 info)
5884           (setcar (nthcdr 3 info) newmarked)
5885         ;; Add the marks lists to the end of the info.
5886         (when newmarked
5887           (setcdr (nthcdr 2 info) (list newmarked))))
5888
5889       ;; Cut off the end of the info if there's nothing else there.
5890       (let ((i 5))
5891         (while (and (> i 2)
5892                     (not (nth i info)))
5893           (when (nthcdr (decf i) info)
5894             (setcdr (nthcdr i info) nil)))))))
5895
5896 (defun gnus-set-mode-line (where)
5897   "Set the mode line of the article or summary buffers.
5898 If WHERE is `summary', the summary mode line format will be used."
5899   ;; Is this mode line one we keep updated?
5900   (when (and (memq where gnus-updated-mode-lines)
5901              (symbol-value
5902               (intern (format "gnus-%s-mode-line-format-spec" where))))
5903     (let (mode-string)
5904       (save-excursion
5905         ;; We evaluate this in the summary buffer since these
5906         ;; variables are buffer-local to that buffer.
5907         (set-buffer gnus-summary-buffer)
5908        ;; We bind all these variables that are used in the `eval' form
5909         ;; below.
5910         (let* ((mformat (symbol-value
5911                          (intern
5912                           (format "gnus-%s-mode-line-format-spec" where))))
5913                (gnus-tmp-group-name (gnus-mode-string-quote
5914                                      (gnus-group-decoded-name
5915                                       gnus-newsgroup-name)))
5916                (gnus-tmp-article-number (or gnus-current-article 0))
5917                (gnus-tmp-unread gnus-newsgroup-unreads)
5918                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5919                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5920                (gnus-tmp-unread-and-unselected
5921                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5922                             (zerop gnus-tmp-unselected))
5923                        "")
5924                       ((zerop gnus-tmp-unselected)
5925                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5926                       (t (format "{%d(+%d) more}"
5927                                  gnus-tmp-unread-and-unticked
5928                                  gnus-tmp-unselected))))
5929                (gnus-tmp-subject
5930                 (if (and gnus-current-headers
5931                          (vectorp gnus-current-headers))
5932                     (gnus-mode-string-quote
5933                      (mail-header-subject gnus-current-headers))
5934                   ""))
5935                bufname-length max-len
5936                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5937           (setq mode-string (eval mformat))
5938           (setq bufname-length (if (string-match "%b" mode-string)
5939                                    (- (length
5940                                        (buffer-name
5941                                         (if (eq where 'summary)
5942                                             nil
5943                                           (get-buffer gnus-article-buffer))))
5944                                       2)
5945                                  0))
5946           (setq max-len (max 4 (if gnus-mode-non-string-length
5947                                    (- (window-width)
5948                                       gnus-mode-non-string-length
5949                                       bufname-length)
5950                                  (length mode-string))))
5951           ;; We might have to chop a bit of the string off...
5952           (when (> (length mode-string) max-len)
5953             (setq mode-string
5954                   (concat (truncate-string-to-width mode-string (- max-len 3))
5955                           "...")))
5956           ;; Pad the mode string a bit.
5957           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5958       ;; Update the mode line.
5959       (setq mode-line-buffer-identification
5960             (gnus-mode-line-buffer-identification (list mode-string)))
5961       (set-buffer-modified-p t))))
5962
5963 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5964   "Go through the HEADERS list and add all Xrefs to a hash table.
5965 The resulting hash table is returned, or nil if no Xrefs were found."
5966   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5967          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5968          (xref-hashtb (gnus-make-hashtable))
5969          start group entry number xrefs header)
5970     (while headers
5971       (setq header (pop headers))
5972       (when (and (setq xrefs (mail-header-xref header))
5973                  (not (memq (setq number (mail-header-number header))
5974                             unreads)))
5975         (setq start 0)
5976         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5977           (setq start (match-end 0))
5978           (setq group (if prefix
5979                           (concat prefix (substring xrefs (match-beginning 1)
5980                                                     (match-end 1)))
5981                         (substring xrefs (match-beginning 1) (match-end 1))))
5982           (setq number
5983                 (string-to-number (substring xrefs (match-beginning 2)
5984                                           (match-end 2))))
5985           (if (setq entry (gnus-gethash group xref-hashtb))
5986               (setcdr entry (cons number (cdr entry)))
5987             (gnus-sethash group (cons number nil) xref-hashtb)))))
5988     (and start xref-hashtb)))
5989
5990 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5991   "Look through all the headers and mark the Xrefs as read."
5992   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5993         name info xref-hashtb idlist method nth4)
5994     (save-excursion
5995       (set-buffer gnus-group-buffer)
5996       (when (setq xref-hashtb
5997                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5998         (mapatoms
5999          (lambda (group)
6000            (unless (string= from-newsgroup (setq name (symbol-name group)))
6001              (setq idlist (symbol-value group))
6002              ;; Dead groups are not updated.
6003              (and (prog1
6004                       (setq info (gnus-get-info name))
6005                     (when (stringp (setq nth4 (gnus-info-method info)))
6006                       (setq nth4 (gnus-server-to-method nth4))))
6007                   ;; Only do the xrefs if the group has the same
6008                   ;; select method as the group we have just read.
6009                   (or (gnus-methods-equal-p
6010                        nth4 (gnus-find-method-for-group from-newsgroup))
6011                       virtual
6012                       (equal nth4 (setq method (gnus-find-method-for-group
6013                                                 from-newsgroup)))
6014                       (and (equal (car nth4) (car method))
6015                            (equal (nth 1 nth4) (nth 1 method))))
6016                   gnus-use-cross-reference
6017                   (or (not (eq gnus-use-cross-reference t))
6018                       virtual
6019                       ;; Only do cross-references on subscribed
6020                       ;; groups, if that is what is wanted.
6021                       (<= (gnus-info-level info) gnus-level-subscribed))
6022                   (gnus-group-make-articles-read name idlist))))
6023          xref-hashtb)))))
6024
6025 (defun gnus-compute-read-articles (group articles)
6026   (let* ((entry (gnus-group-entry group))
6027          (info (nth 2 entry))
6028          (active (gnus-active group))
6029          ninfo)
6030     (when entry
6031       ;; First peel off all invalid article numbers.
6032       (when active
6033         (let ((ids articles)
6034               id first)
6035           (while (setq id (pop ids))
6036             (when (and first (> id (cdr active)))
6037               ;; We'll end up in this situation in one particular
6038               ;; obscure situation.  If you re-scan a group and get
6039               ;; a new article that is cross-posted to a different
6040               ;; group that has not been re-scanned, you might get
6041               ;; crossposted article that has a higher number than
6042               ;; Gnus believes possible.  So we re-activate this
6043               ;; group as well.  This might mean doing the
6044               ;; crossposting thingy will *increase* the number
6045               ;; of articles in some groups.  Tsk, tsk.
6046               (setq active (or (gnus-activate-group group) active)))
6047             (when (or (> id (cdr active))
6048                       (< id (car active)))
6049               (setq articles (delq id articles))))))
6050       ;; If the read list is nil, we init it.
6051       (if (and active
6052                (null (gnus-info-read info))
6053                (> (car active) 1))
6054           (setq ninfo (cons 1 (1- (car active))))
6055         (setq ninfo (gnus-info-read info)))
6056       ;; Then we add the read articles to the range.
6057       (gnus-add-to-range
6058        ninfo (setq articles (sort articles '<))))))
6059
6060 (defun gnus-group-make-articles-read (group articles)
6061   "Update the info of GROUP to say that ARTICLES are read."
6062   (let* ((num 0)
6063          (entry (gnus-group-entry group))
6064          (info (nth 2 entry))
6065          (active (gnus-active group))
6066          range)
6067     (when entry
6068       (setq range (gnus-compute-read-articles group articles))
6069       (with-current-buffer gnus-group-buffer
6070         (gnus-undo-register
6071           `(progn
6072              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6073              (gnus-info-set-read ',info ',(gnus-info-read info))
6074              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6075              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6076              (gnus-group-update-group ,group t))))
6077       ;; Add the read articles to the range.
6078       (gnus-info-set-read info range)
6079       (gnus-request-set-mark group (list (list range 'add '(read))))
6080       ;; Then we have to re-compute how many unread
6081       ;; articles there are in this group.
6082       (when active
6083         (cond
6084          ((not range)
6085           (setq num (- (1+ (cdr active)) (car active))))
6086          ((not (listp (cdr range)))
6087           (setq num (- (cdr active) (- (1+ (cdr range))
6088                                        (car range)))))
6089          (t
6090           (while range
6091             (if (numberp (car range))
6092                 (setq num (1+ num))
6093               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6094             (setq range (cdr range)))
6095           (setq num (- (cdr active) num))))
6096         ;; Update the number of unread articles.
6097         (setcar entry num)
6098         ;; Update the group buffer.
6099         (unless (gnus-ephemeral-group-p group)
6100           (gnus-group-update-group group t))))))
6101
6102 (defvar gnus-newsgroup-none-id 0)
6103
6104 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6105   (let ((cur nntp-server-buffer)
6106         (dependencies
6107          (or dependencies
6108              (with-current-buffer gnus-summary-buffer
6109                gnus-newsgroup-dependencies)))
6110         headers id end ref number
6111         (mail-parse-charset gnus-newsgroup-charset)
6112         (mail-parse-ignored-charsets
6113          (save-excursion (condition-case nil
6114                              (set-buffer gnus-summary-buffer)
6115                            (error))
6116                          gnus-newsgroup-ignored-charsets)))
6117     (save-excursion
6118       (set-buffer nntp-server-buffer)
6119       ;; Translate all TAB characters into SPACE characters.
6120       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6121       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6122       (ietf-drums-unfold-fws)
6123       (gnus-run-hooks 'gnus-parse-headers-hook)
6124       (let ((case-fold-search t)
6125             in-reply-to header p lines chars)
6126         (goto-char (point-min))
6127         ;; Search to the beginning of the next header.  Error messages
6128         ;; do not begin with 2 or 3.
6129         (while (re-search-forward "^[23][0-9]+ " nil t)
6130           (setq id nil
6131                 ref nil)
6132           ;; This implementation of this function, with nine
6133           ;; search-forwards instead of the one re-search-forward and
6134           ;; a case (which basically was the old function) is actually
6135           ;; about twice as fast, even though it looks messier.  You
6136           ;; can't have everything, I guess.  Speed and elegance
6137           ;; doesn't always go hand in hand.
6138           (setq
6139            header
6140            (vector
6141             ;; Number.
6142             (prog1
6143                 (setq number (read cur))
6144               (end-of-line)
6145               (setq p (point))
6146               (narrow-to-region (point)
6147                                 (or (and (search-forward "\n.\n" nil t)
6148                                          (- (point) 2))
6149                                     (point))))
6150             ;; Subject.
6151             (progn
6152               (goto-char p)
6153               (if (search-forward "\nsubject:" nil t)
6154                   (funcall gnus-decode-encoded-word-function
6155                            (nnheader-header-value))
6156                 "(none)"))
6157             ;; From.
6158             (progn
6159               (goto-char p)
6160               (if (search-forward "\nfrom:" nil t)
6161                   (funcall gnus-decode-encoded-address-function
6162                            (nnheader-header-value))
6163                 "(nobody)"))
6164             ;; Date.
6165             (progn
6166               (goto-char p)
6167               (if (search-forward "\ndate:" nil t)
6168                   (nnheader-header-value) ""))
6169             ;; Message-ID.
6170             (progn
6171               (goto-char p)
6172               (setq id (if (re-search-forward
6173                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6174                            ;; We do it this way to make sure the Message-ID
6175                            ;; is (somewhat) syntactically valid.
6176                            (buffer-substring (match-beginning 1)
6177                                              (match-end 1))
6178                          ;; If there was no message-id, we just fake one
6179                          ;; to make subsequent routines simpler.
6180                          (nnheader-generate-fake-message-id number))))
6181             ;; References.
6182             (progn
6183               (goto-char p)
6184               (if (search-forward "\nreferences:" nil t)
6185                   (progn
6186                     (setq end (point))
6187                     (prog1
6188                         (nnheader-header-value)
6189                       (setq ref
6190                             (buffer-substring
6191                              (progn
6192                                (end-of-line)
6193                                (search-backward ">" end t)
6194                                (1+ (point)))
6195                              (progn
6196                                (search-backward "<" end t)
6197                                (point))))))
6198                 ;; Get the references from the in-reply-to header if there
6199                 ;; were no references and the in-reply-to header looks
6200                 ;; promising.
6201                 (if (and (search-forward "\nin-reply-to:" nil t)
6202                          (setq in-reply-to (nnheader-header-value))
6203                          (string-match "<[^>]+>" in-reply-to))
6204                     (let (ref2)
6205                       (setq ref (substring in-reply-to (match-beginning 0)
6206                                            (match-end 0)))
6207                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6208                         (setq ref2 (substring in-reply-to (match-beginning 0)
6209                                               (match-end 0)))
6210                         (when (> (length ref2) (length ref))
6211                           (setq ref ref2)))
6212                       ref)
6213                   (setq ref nil))))
6214             ;; Chars.
6215             (progn
6216               (goto-char p)
6217               (if (search-forward "\nchars: " nil t)
6218                   (if (numberp (setq chars (ignore-errors (read cur))))
6219                       chars -1)
6220                 -1))
6221             ;; Lines.
6222             (progn
6223               (goto-char p)
6224               (if (search-forward "\nlines: " nil t)
6225                   (if (numberp (setq lines (ignore-errors (read cur))))
6226                       lines -1)
6227                 -1))
6228             ;; Xref.
6229             (progn
6230               (goto-char p)
6231               (and (search-forward "\nxref:" nil t)
6232                    (nnheader-header-value)))
6233             ;; Extra.
6234             (when gnus-extra-headers
6235               (let ((extra gnus-extra-headers)
6236                     out)
6237                 (while extra
6238                   (goto-char p)
6239                   (when (search-forward
6240                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6241                     (push (cons (car extra) (nnheader-header-value))
6242                           out))
6243                   (pop extra))
6244                 out))))
6245           (when (equal id ref)
6246             (setq ref nil))
6247
6248           (when gnus-alter-header-function
6249             (funcall gnus-alter-header-function header)
6250             (setq id (mail-header-id header)
6251                   ref (gnus-parent-id (mail-header-references header))))
6252
6253           (when (setq header
6254                       (gnus-dependencies-add-header
6255                        header dependencies force-new))
6256             (push header headers))
6257           (goto-char (point-max))
6258           (widen))
6259         (nreverse headers)))))
6260
6261 ;; Goes through the xover lines and returns a list of vectors
6262 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6263                                                   force-new dependencies
6264                                                   group also-fetch-heads)
6265   "Parse the news overview data in the server buffer.
6266 Return a list of headers that match SEQUENCE (see
6267 `nntp-retrieve-headers')."
6268   ;; Get the Xref when the users reads the articles since most/some
6269   ;; NNTP servers do not include Xrefs when using XOVER.
6270   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6271   (let ((mail-parse-charset gnus-newsgroup-charset)
6272         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6273         (cur nntp-server-buffer)
6274         (dependencies (or dependencies gnus-newsgroup-dependencies))
6275         (allp (cond
6276                ((eq gnus-read-all-available-headers t)
6277                 t)
6278                ((and (stringp gnus-read-all-available-headers)
6279                      group)
6280                 (string-match gnus-read-all-available-headers group))
6281                (t
6282                 nil)))
6283         number headers header)
6284     (save-excursion
6285       (set-buffer nntp-server-buffer)
6286       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6287       ;; Allow the user to mangle the headers before parsing them.
6288       (gnus-run-hooks 'gnus-parse-headers-hook)
6289       (goto-char (point-min))
6290       (gnus-parse-without-error
6291         (while (and (or sequence allp)
6292                     (not (eobp)))
6293           (setq number (read cur))
6294           (when (not allp)
6295             (while (and sequence
6296                         (< (car sequence) number))
6297               (setq sequence (cdr sequence))))
6298           (when (and (or allp
6299                          (and sequence
6300                               (eq number (car sequence))))
6301                      (progn
6302                        (setq sequence (cdr sequence))
6303                        (setq header (inline
6304                                       (gnus-nov-parse-line
6305                                        number dependencies force-new)))))
6306             (push header headers))
6307           (forward-line 1)))
6308       ;; A common bug in inn is that if you have posted an article and
6309       ;; then retrieves the active file, it will answer correctly --
6310       ;; the new article is included.  However, a NOV entry for the
6311       ;; article may not have been generated yet, so this may fail.
6312       ;; We work around this problem by retrieving the last few
6313       ;; headers using HEAD.
6314       (if (or (not also-fetch-heads)
6315               (not sequence))
6316           ;; We (probably) got all the headers.
6317           (nreverse headers)
6318         (let ((gnus-nov-is-evil t))
6319           (nconc
6320            (nreverse headers)
6321            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6322              (gnus-get-newsgroup-headers))))))))
6323
6324 (defun gnus-article-get-xrefs ()
6325   "Fill in the Xref value in `gnus-current-headers', if necessary.
6326 This is meant to be called in `gnus-article-internal-prepare-hook'."
6327   (let ((headers (with-current-buffer gnus-summary-buffer
6328                    gnus-current-headers)))
6329     (or (not gnus-use-cross-reference)
6330         (not headers)
6331         (and (mail-header-xref headers)
6332              (not (string= (mail-header-xref headers) "")))
6333         (let ((case-fold-search t)
6334               xref)
6335           (save-restriction
6336             (nnheader-narrow-to-headers)
6337             (goto-char (point-min))
6338             (when (or (and (not (eobp))
6339                            (eq (downcase (char-after)) ?x)
6340                            (looking-at "Xref:"))
6341                       (search-forward "\nXref:" nil t))
6342               (goto-char (1+ (match-end 0)))
6343               (setq xref (buffer-substring (point) (point-at-eol)))
6344               (mail-header-set-xref headers xref)))))))
6345
6346 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6347   "Find article ID and insert the summary line for that article.
6348 OLD-HEADER can either be a header or a line number to insert
6349 the subject line on."
6350   (let* ((line (and (numberp old-header) old-header))
6351          (old-header (and (vectorp old-header) old-header))
6352          (header (cond ((and old-header use-old-header)
6353                         old-header)
6354                        ((and (numberp id)
6355                              (gnus-number-to-header id))
6356                         (gnus-number-to-header id))
6357                        (t
6358                         (gnus-read-header id))))
6359          (number (and (numberp id) id))
6360          d)
6361     (when header
6362       ;; Rebuild the thread that this article is part of and go to the
6363       ;; article we have fetched.
6364       (when (and (not gnus-show-threads)
6365                  old-header)
6366         (when (and number
6367                    (setq d (gnus-data-find (mail-header-number old-header))))
6368           (goto-char (gnus-data-pos d))
6369           (gnus-data-remove
6370            number
6371            (- (point-at-bol)
6372               (prog1
6373                   (1+ (point-at-eol))
6374                 (gnus-delete-line))))))
6375       ;; Remove list identifiers from subject.
6376       (when gnus-list-identifiers
6377         (let ((gnus-newsgroup-headers (list header)))
6378           (gnus-summary-remove-list-identifiers)))
6379       (when old-header
6380         (mail-header-set-number header (mail-header-number old-header)))
6381       (setq gnus-newsgroup-sparse
6382             (delq (setq number (mail-header-number header))
6383                   gnus-newsgroup-sparse))
6384       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6385       (push number gnus-newsgroup-limit)
6386       (gnus-rebuild-thread (mail-header-id header) line)
6387       (gnus-summary-goto-subject number nil t))
6388     (when (and (numberp number)
6389                (> number 0))
6390       ;; We have to update the boundaries even if we can't fetch the
6391       ;; article if ID is a number -- so that the next `P' or `N'
6392       ;; command will fetch the previous (or next) article even
6393       ;; if the one we tried to fetch this time has been canceled.
6394       (when (> number gnus-newsgroup-end)
6395         (setq gnus-newsgroup-end number))
6396       (when (< number gnus-newsgroup-begin)
6397         (setq gnus-newsgroup-begin number))
6398       (setq gnus-newsgroup-unselected
6399             (delq number gnus-newsgroup-unselected)))
6400     ;; Report back a success?
6401     (and header (mail-header-number header))))
6402
6403 ;;; Process/prefix in the summary buffer
6404
6405 (defun gnus-summary-work-articles (n)
6406   "Return a list of articles to be worked upon.
6407 The prefix argument, the list of process marked articles, and the
6408 current article will be taken into consideration."
6409   (save-excursion
6410     (set-buffer gnus-summary-buffer)
6411     (cond
6412      (n
6413       ;; A numerical prefix has been given.
6414       (setq n (prefix-numeric-value n))
6415       (let ((backward (< n 0))
6416             (n (abs (prefix-numeric-value n)))
6417             articles article)
6418         (save-excursion
6419           (while
6420               (and (> n 0)
6421                    (push (setq article (gnus-summary-article-number))
6422                          articles)
6423                    (if backward
6424                        (gnus-summary-find-prev nil article)
6425                      (gnus-summary-find-next nil article)))
6426             (decf n)))
6427         (nreverse articles)))
6428      ((and (gnus-region-active-p) (mark))
6429       (message "region active")
6430       ;; Work on the region between point and mark.
6431       (let ((max (max (point) (mark)))
6432             articles article)
6433         (save-excursion
6434           (goto-char (min (point) (mark)))
6435           (while
6436               (and
6437                (push (setq article (gnus-summary-article-number)) articles)
6438                (gnus-summary-find-next nil article)
6439                (< (point) max)))
6440           (nreverse articles))))
6441      (gnus-newsgroup-processable
6442       ;; There are process-marked articles present.
6443       ;; Save current state.
6444       (gnus-summary-save-process-mark)
6445       ;; Return the list.
6446       (reverse gnus-newsgroup-processable))
6447      (t
6448       ;; Just return the current article.
6449       (list (gnus-summary-article-number))))))
6450
6451 (defmacro gnus-summary-iterate (arg &rest forms)
6452   "Iterate over the process/prefixed articles and do FORMS.
6453 ARG is the interactive prefix given to the command.  FORMS will be
6454 executed with point over the summary line of the articles."
6455   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6456     `(let ((,articles (gnus-summary-work-articles ,arg)))
6457        (while ,articles
6458          (gnus-summary-goto-subject (car ,articles))
6459          ,@forms
6460          (pop ,articles)))))
6461
6462 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6463 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6464
6465 (defun gnus-summary-save-process-mark ()
6466   "Push the current set of process marked articles on the stack."
6467   (interactive)
6468   (push (copy-sequence gnus-newsgroup-processable)
6469         gnus-newsgroup-process-stack))
6470
6471 (defun gnus-summary-kill-process-mark ()
6472   "Push the current set of process marked articles on the stack and unmark."
6473   (interactive)
6474   (gnus-summary-save-process-mark)
6475   (gnus-summary-unmark-all-processable))
6476
6477 (defun gnus-summary-yank-process-mark ()
6478   "Pop the last process mark state off the stack and restore it."
6479   (interactive)
6480   (unless gnus-newsgroup-process-stack
6481     (error "Empty mark stack"))
6482   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6483
6484 (defun gnus-summary-process-mark-set (set)
6485   "Make SET into the current process marked articles."
6486   (gnus-summary-unmark-all-processable)
6487   (mapc 'gnus-summary-set-process-mark set))
6488
6489 ;;; Searching and stuff
6490
6491 (defun gnus-summary-search-group (&optional backward use-level)
6492   "Search for next unread newsgroup.
6493 If optional argument BACKWARD is non-nil, search backward instead."
6494   (save-excursion
6495     (set-buffer gnus-group-buffer)
6496     (when (gnus-group-search-forward
6497            backward nil (if use-level (gnus-group-group-level) nil))
6498       (gnus-group-group-name))))
6499
6500 (defun gnus-summary-best-group (&optional exclude-group)
6501   "Find the name of the best unread group.
6502 If EXCLUDE-GROUP, do not go to this group."
6503   (with-current-buffer gnus-group-buffer
6504     (save-excursion
6505       (gnus-group-best-unread-group exclude-group))))
6506
6507 (defun gnus-summary-find-next (&optional unread article backward)
6508   (if backward
6509       (gnus-summary-find-prev unread article)
6510     (let* ((dummy (gnus-summary-article-intangible-p))
6511            (article (or article (gnus-summary-article-number)))
6512            (data (gnus-data-find-list article))
6513            result)
6514       (when (and (not dummy)
6515                  (or (not gnus-summary-check-current)
6516                      (not unread)
6517                      (not (gnus-data-unread-p (car data)))))
6518         (setq data (cdr data)))
6519       (when (setq result
6520                   (if unread
6521                       (progn
6522                         (while data
6523                           (unless (memq (gnus-data-number (car data))
6524                                         (cond
6525                                          ((eq gnus-auto-goto-ignores
6526                                               'always-undownloaded)
6527                                           gnus-newsgroup-undownloaded)
6528                                          (gnus-plugged
6529                                           nil)
6530                                          ((eq gnus-auto-goto-ignores
6531                                               'unfetched)
6532                                           gnus-newsgroup-unfetched)
6533                                          ((eq gnus-auto-goto-ignores
6534                                               'undownloaded)
6535                                           gnus-newsgroup-undownloaded)))
6536                             (when (gnus-data-unread-p (car data))
6537                               (setq result (car data)
6538                                     data nil)))
6539                           (setq data (cdr data)))
6540                         result)
6541                     (car data)))
6542         (goto-char (gnus-data-pos result))
6543         (gnus-data-number result)))))
6544
6545 (defun gnus-summary-find-prev (&optional unread article)
6546   (let* ((eobp (eobp))
6547          (article (or article (gnus-summary-article-number)))
6548          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6549          result)
6550     (when (and (not eobp)
6551                (or (not gnus-summary-check-current)
6552                    (not unread)
6553                    (not (gnus-data-unread-p (car data)))))
6554       (setq data (cdr data)))
6555     (when (setq result
6556                 (if unread
6557                     (progn
6558                       (while data
6559                         (unless (memq (gnus-data-number (car data))
6560                                       (cond
6561                                        ((eq gnus-auto-goto-ignores
6562                                             'always-undownloaded)
6563                                         gnus-newsgroup-undownloaded)
6564                                        (gnus-plugged
6565                                         nil)
6566                                        ((eq gnus-auto-goto-ignores
6567                                             'unfetched)
6568                                         gnus-newsgroup-unfetched)
6569                                        ((eq gnus-auto-goto-ignores
6570                                             'undownloaded)
6571                                         gnus-newsgroup-undownloaded)))
6572                           (when (gnus-data-unread-p (car data))
6573                             (setq result (car data)
6574                                   data nil)))
6575                         (setq data (cdr data)))
6576                       result)
6577                   (car data)))
6578       (goto-char (gnus-data-pos result))
6579       (gnus-data-number result))))
6580
6581 (defun gnus-summary-find-subject (subject &optional unread backward article)
6582   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6583          (article (or article (gnus-summary-article-number)))
6584          (articles (gnus-data-list backward))
6585          (arts (gnus-data-find-list article articles))
6586          result)
6587     (when (or (not gnus-summary-check-current)
6588               (not unread)
6589               (not (gnus-data-unread-p (car arts))))
6590       (setq arts (cdr arts)))
6591     (while arts
6592       (and (or (not unread)
6593                (gnus-data-unread-p (car arts)))
6594            (vectorp (gnus-data-header (car arts)))
6595            (gnus-subject-equal
6596             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6597            (setq result (car arts)
6598                  arts nil))
6599       (setq arts (cdr arts)))
6600     (and result
6601          (goto-char (gnus-data-pos result))
6602          (gnus-data-number result))))
6603
6604 (defun gnus-summary-search-forward (&optional unread subject backward)
6605   "Search forward for an article.
6606 If UNREAD, look for unread articles.  If SUBJECT, look for
6607 articles with that subject.  If BACKWARD, search backward instead."
6608   (cond (subject (gnus-summary-find-subject subject unread backward))
6609         (backward (gnus-summary-find-prev unread))
6610         (t (gnus-summary-find-next unread))))
6611
6612 (defun gnus-recenter (&optional n)
6613   "Center point in window and redisplay frame.
6614 Also do horizontal recentering."
6615   (interactive "P")
6616   (when (and gnus-auto-center-summary
6617              (not (eq gnus-auto-center-summary 'vertical)))
6618     (gnus-horizontal-recenter))
6619   (recenter n))
6620
6621 (defun gnus-summary-recenter ()
6622   "Center point in the summary window.
6623 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6624 displayed, no centering will be performed."
6625   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6626   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6627   (interactive)
6628   ;; The user has to want it.
6629   (when gnus-auto-center-summary
6630     (let* ((top (cond ((< (window-height) 4) 0)
6631                       ((< (window-height) 7) 1)
6632                       (t (if (numberp gnus-auto-center-summary)
6633                              gnus-auto-center-summary
6634                            (/ (1- (window-height)) 2)))))
6635            (height (1- (window-height)))
6636            (bottom (save-excursion (goto-char (point-max))
6637                                    (forward-line (- height))
6638                                    (point)))
6639            (window (get-buffer-window (current-buffer))))
6640       (when (get-buffer-window gnus-article-buffer)
6641         ;; Only do recentering when the article buffer is displayed,
6642         ;; Set the window start to either `bottom', which is the biggest
6643         ;; possible valid number, or the second line from the top,
6644         ;; whichever is the least.
6645         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6646           (if (> bottom top-pos)
6647               ;; Keep the second line from the top visible
6648               (set-window-start window top-pos)
6649             ;; Try to keep the bottom line visible; if it's partially
6650             ;; obscured, either scroll one more line to make it fully
6651             ;; visible, or revert to using TOP-POS.
6652             (save-excursion
6653               (goto-char (point-max))
6654               (forward-line -1)
6655               (let ((last-line-start (point)))
6656                 (goto-char bottom)
6657                 (set-window-start window (point) t)
6658                 (when (not (pos-visible-in-window-p last-line-start window))
6659                   (forward-line 1)
6660                   (set-window-start window (min (point) top-pos) t)))))))
6661       ;; Do horizontal recentering while we're at it.
6662       (when (and (get-buffer-window (current-buffer) t)
6663                  (not (eq gnus-auto-center-summary 'vertical)))
6664         (let ((selected (selected-window)))
6665           (select-window (get-buffer-window (current-buffer) t))
6666           (gnus-summary-position-point)
6667           (gnus-horizontal-recenter)
6668           (select-window selected))))))
6669
6670 (defun gnus-summary-jump-to-group (newsgroup)
6671   "Move point to NEWSGROUP in group mode buffer."
6672   ;; Keep update point of group mode buffer if visible.
6673   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6674       (save-window-excursion
6675         ;; Take care of tree window mode.
6676         (when (get-buffer-window gnus-group-buffer)
6677           (pop-to-buffer gnus-group-buffer))
6678         (gnus-group-jump-to-group newsgroup))
6679     (save-excursion
6680       ;; Take care of tree window mode.
6681       (if (get-buffer-window gnus-group-buffer)
6682           (pop-to-buffer gnus-group-buffer)
6683         (set-buffer gnus-group-buffer))
6684       (gnus-group-jump-to-group newsgroup))))
6685
6686 ;; This function returns a list of article numbers based on the
6687 ;; difference between the ranges of read articles in this group and
6688 ;; the range of active articles.
6689 (defun gnus-list-of-unread-articles (group)
6690   (let* ((read (gnus-info-read (gnus-get-info group)))
6691          (active (or (gnus-active group) (gnus-activate-group group)))
6692          (last (or (cdr active)
6693                    (error "Group %s couldn't be activated " group)))
6694          first nlast unread)
6695     ;; If none are read, then all are unread.
6696     (if (not read)
6697         (setq first (car active))
6698       ;; If the range of read articles is a single range, then the
6699       ;; first unread article is the article after the last read
6700       ;; article.  Sounds logical, doesn't it?
6701       (if (and (not (listp (cdr read)))
6702                (or (< (car read) (car active))
6703                    (progn (setq read (list read))
6704                           nil)))
6705           (setq first (max (car active) (1+ (cdr read))))
6706         ;; `read' is a list of ranges.
6707         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6708                                   (caar read)))
6709                   1)
6710           (setq first (car active)))
6711         (while read
6712           (when first
6713             (while (< first nlast)
6714               (setq unread (cons first unread)
6715                     first (1+ first))))
6716           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6717           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6718           (setq read (cdr read)))))
6719     ;; And add the last unread articles.
6720     (while (<= first last)
6721       (setq unread (cons first unread)
6722             first (1+ first)))
6723     ;; Return the list of unread articles.
6724     (delq 0 (nreverse unread))))
6725
6726 (defun gnus-list-of-read-articles (group)
6727   "Return a list of unread, unticked and non-dormant articles."
6728   (let* ((info (gnus-get-info group))
6729          (marked (gnus-info-marks info))
6730          (active (gnus-active group)))
6731     (and info active
6732          (gnus-list-range-difference
6733           (gnus-list-range-difference
6734            (gnus-sorted-complement
6735             (gnus-uncompress-range active)
6736             (gnus-list-of-unread-articles group))
6737            (cdr (assq 'dormant marked)))
6738           (cdr (assq 'tick marked))))))
6739
6740 ;; This function returns a sequence of article numbers based on the
6741 ;; difference between the ranges of read articles in this group and
6742 ;; the range of active articles.
6743 (defun gnus-sequence-of-unread-articles (group)
6744   (let* ((read (gnus-info-read (gnus-get-info group)))
6745          (active (or (gnus-active group) (gnus-activate-group group)))
6746          (last (cdr active))
6747          first nlast unread)
6748     ;; If none are read, then all are unread.
6749     (if (not read)
6750         (setq first (car active))
6751       ;; If the range of read articles is a single range, then the
6752       ;; first unread article is the article after the last read
6753       ;; article.  Sounds logical, doesn't it?
6754       (if (and (not (listp (cdr read)))
6755                (or (< (car read) (car active))
6756                    (progn (setq read (list read))
6757                           nil)))
6758           (setq first (max (car active) (1+ (cdr read))))
6759         ;; `read' is a list of ranges.
6760         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6761                                   (caar read)))
6762                   1)
6763           (setq first (car active)))
6764         (while read
6765           (when first
6766             (push (cons first nlast) unread))
6767           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6768           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6769           (setq read (cdr read)))))
6770     ;; And add the last unread articles.
6771     (cond ((not (and first last))
6772            nil)
6773           ((< first last)
6774            (push (cons first last) unread))
6775           ((= first last)
6776            (push first unread)))
6777     ;; Return the sequence of unread articles.
6778     (delq 0 (nreverse unread))))
6779
6780 ;; Various summary commands
6781
6782 (defun gnus-summary-select-article-buffer ()
6783   "Reconfigure windows to show article buffer."
6784   (interactive)
6785   (if (not (gnus-buffer-live-p gnus-article-buffer))
6786       (error "There is no article buffer for this summary buffer")
6787     (gnus-configure-windows 'article)
6788     (select-window (get-buffer-window gnus-article-buffer))))
6789
6790 (defun gnus-summary-universal-argument (arg)
6791   "Perform any operation on all articles that are process/prefixed."
6792   (interactive "P")
6793   (let ((articles (gnus-summary-work-articles arg))
6794         func article)
6795     (if (eq
6796          (setq
6797           func
6798           (key-binding
6799            (read-key-sequence
6800             (substitute-command-keys
6801              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6802          'undefined)
6803         (gnus-error 1 "Undefined key")
6804       (save-excursion
6805         (while articles
6806           (gnus-summary-goto-subject (setq article (pop articles)))
6807           (let (gnus-newsgroup-processable)
6808             (command-execute func))
6809           (gnus-summary-remove-process-mark article)))))
6810   (gnus-summary-position-point))
6811
6812 (defun gnus-summary-toggle-truncation (&optional arg)
6813   "Toggle truncation of summary lines.
6814 With ARG, turn line truncation on if ARG is positive."
6815   (interactive "P")
6816   (setq truncate-lines
6817         (if (null arg) (not truncate-lines)
6818           (> (prefix-numeric-value arg) 0)))
6819   (redraw-display))
6820
6821 (defun gnus-summary-find-for-reselect ()
6822   "Return the number of an article to stay on across a reselect.
6823 The current article is considered, then following articles, then previous
6824 articles.  An article is sought which is not cancelled and isn't a temporary
6825 insertion from another group.  If there's no such then return a dummy 0."
6826   (let (found)
6827     (dolist (rev '(nil t))
6828       (unless found      ; don't demand the reverse list if we don't need it
6829         (let ((data (gnus-data-find-list
6830                      (gnus-summary-article-number) (gnus-data-list rev))))
6831           (while (and data (not found))
6832             (if (and (< 0 (gnus-data-number (car data)))
6833                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6834                 (setq found (gnus-data-number (car data))))
6835             (setq data (cdr data))))))
6836     (or found 0)))
6837
6838 (defun gnus-summary-reselect-current-group (&optional all rescan)
6839   "Exit and then reselect the current newsgroup.
6840 The prefix argument ALL means to select all articles."
6841   (interactive "P")
6842   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6843     (error "Ephemeral groups can't be reselected"))
6844   (let ((current-subject (gnus-summary-find-for-reselect))
6845         (group gnus-newsgroup-name))
6846     (setq gnus-newsgroup-begin nil)
6847     (gnus-summary-exit nil 'leave-hidden)
6848     ;; We have to adjust the point of group mode buffer because
6849     ;; point was moved to the next unread newsgroup by exiting.
6850     (gnus-summary-jump-to-group group)
6851     (when rescan
6852       (save-excursion
6853         (gnus-group-get-new-news-this-group 1)))
6854     (gnus-group-read-group all t)
6855     (gnus-summary-goto-subject current-subject nil t)))
6856
6857 (defun gnus-summary-rescan-group (&optional all)
6858   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6859   (interactive "P")
6860   (gnus-summary-reselect-current-group all t))
6861
6862 (defun gnus-summary-update-info (&optional non-destructive)
6863   (save-excursion
6864     (let ((group gnus-newsgroup-name))
6865       (when group
6866         (when gnus-newsgroup-kill-headers
6867           (setq gnus-newsgroup-killed
6868                 (gnus-compress-sequence
6869                  (gnus-sorted-union
6870                   (gnus-list-range-intersection
6871                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6872                   gnus-newsgroup-unreads)
6873                  t)))
6874         (unless (listp (cdr gnus-newsgroup-killed))
6875           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6876         (let ((headers gnus-newsgroup-headers))
6877           ;; Set the new ranges of read articles.
6878           (with-current-buffer gnus-group-buffer
6879             (gnus-undo-force-boundary))
6880           (gnus-update-read-articles
6881            group (gnus-sorted-union
6882                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6883           ;; Set the current article marks.
6884           (let ((gnus-newsgroup-scored
6885                  (if (and (not gnus-save-score)
6886                           (not non-destructive))
6887                      nil
6888                    gnus-newsgroup-scored)))
6889             (save-excursion
6890               (gnus-update-marks)))
6891           ;; Do the cross-ref thing.
6892           (when gnus-use-cross-reference
6893             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6894           ;; Do not switch windows but change the buffer to work.
6895           (set-buffer gnus-group-buffer)
6896           (unless (gnus-ephemeral-group-p group)
6897             (gnus-group-update-group group)))))))
6898
6899 (defun gnus-summary-save-newsrc (&optional force)
6900   "Save the current number of read/marked articles in the dribble buffer.
6901 The dribble buffer will then be saved.
6902 If FORCE (the prefix), also save the .newsrc file(s)."
6903   (interactive "P")
6904   (gnus-summary-update-info t)
6905   (if force
6906       (gnus-save-newsrc-file)
6907     (gnus-dribble-save)))
6908
6909 (defun gnus-summary-exit (&optional temporary leave-hidden)
6910   "Exit reading current newsgroup, and then return to group selection mode.
6911 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6912   (interactive)
6913   (gnus-set-global-variables)
6914   (when (gnus-buffer-live-p gnus-article-buffer)
6915     (save-excursion
6916       (set-buffer gnus-article-buffer)
6917       (mm-destroy-parts gnus-article-mime-handles)
6918       ;; Set it to nil for safety reason.
6919       (setq gnus-article-mime-handle-alist nil)
6920       (setq gnus-article-mime-handles nil)))
6921   (gnus-kill-save-kill-buffer)
6922   (gnus-async-halt-prefetch)
6923   (let* ((group gnus-newsgroup-name)
6924          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6925          (gnus-group-is-exiting-p t)
6926          (mode major-mode)
6927          (group-point nil)
6928          (buf (current-buffer)))
6929     (unless quit-config
6930       ;; Do adaptive scoring, and possibly save score files.
6931       (when gnus-newsgroup-adaptive
6932         (gnus-score-adaptive))
6933       (when gnus-use-scoring
6934         (gnus-score-save)))
6935     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6936     ;; If we have several article buffers, we kill them at exit.
6937     (unless gnus-single-article-buffer
6938       (gnus-kill-buffer gnus-article-buffer)
6939       (gnus-kill-buffer gnus-original-article-buffer)
6940       (setq gnus-article-current nil))
6941     (when gnus-use-cache
6942       (gnus-cache-possibly-remove-articles)
6943       (gnus-cache-save-buffers))
6944     (gnus-async-prefetch-remove-group group)
6945     (when gnus-suppress-duplicates
6946       (gnus-dup-enter-articles))
6947     (when gnus-use-trees
6948       (gnus-tree-close group))
6949     (when gnus-use-cache
6950       (gnus-cache-write-active))
6951     ;; Remove entries for this group.
6952     (nnmail-purge-split-history (gnus-group-real-name group))
6953     ;; Make all changes in this group permanent.
6954     (unless quit-config
6955       (gnus-run-hooks 'gnus-exit-group-hook)
6956       (gnus-summary-update-info))
6957     (gnus-close-group group)
6958     ;; Make sure where we were, and go to next newsgroup.
6959     (set-buffer gnus-group-buffer)
6960     (unless quit-config
6961       (gnus-group-jump-to-group group))
6962     (gnus-run-hooks 'gnus-summary-exit-hook)
6963     (unless (or quit-config
6964                 (not gnus-summary-next-group-on-exit)
6965                 ;; If this group has disappeared from the summary
6966                 ;; buffer, don't skip forwards.
6967                 (not (string= group (gnus-group-group-name))))
6968       (gnus-group-next-unread-group 1))
6969     (setq group-point (point))
6970     (if temporary
6971         nil                             ;Nothing to do.
6972       ;; If we have several article buffers, we kill them at exit.
6973       (unless gnus-single-article-buffer
6974         (gnus-kill-buffer gnus-article-buffer)
6975         (gnus-kill-buffer gnus-original-article-buffer)
6976         (setq gnus-article-current nil))
6977       (set-buffer buf)
6978       (if (not gnus-kill-summary-on-exit)
6979           (progn
6980             (gnus-deaden-summary)
6981             (setq mode nil))
6982         ;; We set all buffer-local variables to nil.  It is unclear why
6983         ;; this is needed, but if we don't, buffer-local variables are
6984         ;; not garbage-collected, it seems.  This would the lead to en
6985         ;; ever-growing Emacs.
6986         (gnus-summary-clear-local-variables)
6987         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6988           (gnus-summary-clear-local-variables))
6989         (when (get-buffer gnus-article-buffer)
6990           (bury-buffer gnus-article-buffer))
6991         ;; Return to group mode buffer.
6992         (when (eq mode 'gnus-summary-mode)
6993           (gnus-kill-buffer buf)))
6994       (setq gnus-current-select-method gnus-select-method)
6995       (set-buffer gnus-group-buffer)
6996       (if quit-config
6997           (gnus-handle-ephemeral-exit quit-config)
6998         (goto-char group-point)
6999         ;; If gnus-group-buffer is already displayed, make sure we also move
7000         ;; the cursor in the window that displays it.
7001         (let ((win (get-buffer-window (current-buffer) 0)))
7002           (if win (set-window-point win (point))))
7003         (unless leave-hidden
7004           (gnus-configure-windows 'group 'force)))
7005       ;; Clear the current group name.
7006       (unless quit-config
7007         (setq gnus-newsgroup-name nil)))))
7008
7009 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7010 (defun gnus-summary-exit-no-update (&optional no-questions)
7011   "Quit reading current newsgroup without updating read article info."
7012   (interactive)
7013   (let* ((group gnus-newsgroup-name)
7014          (gnus-group-is-exiting-p t)
7015          (gnus-group-is-exiting-without-update-p t)
7016          (quit-config (gnus-group-quit-config group)))
7017     (when (or no-questions
7018               gnus-expert-user
7019               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7020       (gnus-async-halt-prefetch)
7021       (run-hooks 'gnus-summary-prepare-exit-hook)
7022       (when (gnus-buffer-live-p gnus-article-buffer)
7023         (save-excursion
7024           (set-buffer gnus-article-buffer)
7025           (mm-destroy-parts gnus-article-mime-handles)
7026           ;; Set it to nil for safety reason.
7027           (setq gnus-article-mime-handle-alist nil)
7028           (setq gnus-article-mime-handles nil)))
7029       ;; If we have several article buffers, we kill them at exit.
7030       (unless gnus-single-article-buffer
7031         (gnus-kill-buffer gnus-article-buffer)
7032         (gnus-kill-buffer gnus-original-article-buffer)
7033         (setq gnus-article-current nil))
7034       (if (not gnus-kill-summary-on-exit)
7035           (gnus-deaden-summary)
7036         (gnus-close-group group)
7037         (gnus-summary-clear-local-variables)
7038         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7039           (gnus-summary-clear-local-variables))
7040         (gnus-kill-buffer gnus-summary-buffer))
7041       (unless gnus-single-article-buffer
7042         (setq gnus-article-current nil))
7043       (when gnus-use-trees
7044         (gnus-tree-close group))
7045       (gnus-async-prefetch-remove-group group)
7046       (when (get-buffer gnus-article-buffer)
7047         (bury-buffer gnus-article-buffer))
7048       ;; Return to the group buffer.
7049       (gnus-configure-windows 'group 'force)
7050       ;; Clear the current group name.
7051       (setq gnus-newsgroup-name nil)
7052       (unless (gnus-ephemeral-group-p group)
7053         (gnus-group-update-group group))
7054       (when (equal (gnus-group-group-name) group)
7055         (gnus-group-next-unread-group 1))
7056       (when quit-config
7057         (gnus-handle-ephemeral-exit quit-config)))))
7058
7059 (defun gnus-handle-ephemeral-exit (quit-config)
7060   "Handle movement when leaving an ephemeral group.
7061 The state which existed when entering the ephemeral is reset."
7062   (if (not (buffer-name (car quit-config)))
7063       (gnus-configure-windows 'group 'force)
7064     (set-buffer (car quit-config))
7065     (cond ((eq major-mode 'gnus-summary-mode)
7066            (gnus-set-global-variables))
7067           ((eq major-mode 'gnus-article-mode)
7068            (save-excursion
7069              ;; The `gnus-summary-buffer' variable may point
7070              ;; to the old summary buffer when using a single
7071              ;; article buffer.
7072              (unless (gnus-buffer-live-p gnus-summary-buffer)
7073                (set-buffer gnus-group-buffer))
7074              (set-buffer gnus-summary-buffer)
7075              (gnus-set-global-variables))))
7076     (if (or (eq (cdr quit-config) 'article)
7077             (eq (cdr quit-config) 'pick))
7078         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7079             (gnus-configure-windows 'pick 'force)
7080           (gnus-configure-windows (cdr quit-config) 'force))
7081       (gnus-configure-windows (cdr quit-config) 'force))
7082     (when (eq major-mode 'gnus-summary-mode)
7083       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7084                                                      next-unread-noselect))
7085           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7086                                   'next-noselect)
7087                               (gnus-summary-next-subject 1 nil t))
7088                              ((eq gnus-auto-select-on-ephemeral-exit
7089                                   'next-unread-noselect)
7090                               (gnus-summary-next-subject 1 t t))))
7091             ;; Hide the article buffer which displays the article different
7092             ;; from the one that the cursor points to in the summary buffer.
7093             (gnus-configure-windows 'summary 'force))
7094         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7095                (gnus-summary-next-subject 1))
7096               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7097                (gnus-summary-next-subject 1 t))))
7098       (gnus-summary-recenter)
7099       (gnus-summary-position-point))))
7100
7101 ;;; Dead summaries.
7102
7103 (defvar gnus-dead-summary-mode-map nil)
7104
7105 (unless gnus-dead-summary-mode-map
7106   (setq gnus-dead-summary-mode-map (make-keymap))
7107   (suppress-keymap gnus-dead-summary-mode-map)
7108   (substitute-key-definition
7109    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7110   (dolist (key '("\C-d" "\r" "\177" [delete]))
7111     (define-key gnus-dead-summary-mode-map
7112       key 'gnus-summary-wake-up-the-dead))
7113   (dolist (key '("q" "Q"))
7114     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7115
7116 (defvar gnus-dead-summary-mode nil
7117   "Minor mode for Gnus summary buffers.")
7118
7119 (defun gnus-dead-summary-mode (&optional arg)
7120   "Minor mode for Gnus summary buffers."
7121   (interactive "P")
7122   (when (eq major-mode 'gnus-summary-mode)
7123     (make-local-variable 'gnus-dead-summary-mode)
7124     (setq gnus-dead-summary-mode
7125           (if (null arg) (not gnus-dead-summary-mode)
7126             (> (prefix-numeric-value arg) 0)))
7127     (when gnus-dead-summary-mode
7128       (add-minor-mode
7129        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7130
7131 (defun gnus-deaden-summary ()
7132   "Make the current summary buffer into a dead summary buffer."
7133   ;; Kill any previous dead summary buffer.
7134   (when (and gnus-dead-summary
7135              (buffer-name gnus-dead-summary))
7136     (with-current-buffer gnus-dead-summary
7137       (when gnus-dead-summary-mode
7138         (kill-buffer (current-buffer)))))
7139   ;; Make this the current dead summary.
7140   (setq gnus-dead-summary (current-buffer))
7141   (gnus-dead-summary-mode 1)
7142   (let ((name (buffer-name)))
7143     (when (string-match "Summary" name)
7144       (rename-buffer
7145        (concat (substring name 0 (match-beginning 0)) "Dead "
7146                (substring name (match-beginning 0)))
7147        t)
7148       (bury-buffer))))
7149
7150 (defun gnus-kill-or-deaden-summary (buffer)
7151   "Kill or deaden the summary BUFFER."
7152   (save-excursion
7153     (when (and (buffer-name buffer)
7154                (not gnus-single-article-buffer))
7155       (with-current-buffer buffer
7156         (gnus-kill-buffer gnus-article-buffer)
7157         (gnus-kill-buffer gnus-original-article-buffer)))
7158     (cond
7159      ;; Kill the buffer.
7160      (gnus-kill-summary-on-exit
7161       (when (and gnus-use-trees
7162                  (gnus-buffer-exists-p buffer))
7163         (save-excursion
7164           (set-buffer buffer)
7165           (gnus-tree-close gnus-newsgroup-name)))
7166       (gnus-kill-buffer buffer))
7167      ;; Deaden the buffer.
7168      ((gnus-buffer-exists-p buffer)
7169       (save-excursion
7170         (set-buffer buffer)
7171         (gnus-deaden-summary))))))
7172
7173 (defun gnus-summary-wake-up-the-dead (&rest args)
7174   "Wake up the dead summary buffer."
7175   (interactive)
7176   (gnus-dead-summary-mode -1)
7177   (let ((name (buffer-name)))
7178     (when (string-match "Dead " name)
7179       (rename-buffer
7180        (concat (substring name 0 (match-beginning 0))
7181                (substring name (match-end 0)))
7182        t)))
7183   (gnus-message 3 "This dead summary is now alive again"))
7184
7185 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7186 (defun gnus-summary-fetch-faq (&optional faq-dir)
7187   "Fetch the FAQ for the current group.
7188 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7189 in."
7190   (interactive
7191    (list
7192     (when current-prefix-arg
7193       (completing-read
7194        "FAQ dir: " (and (listp gnus-group-faq-directory)
7195                         (mapcar 'list
7196                                 gnus-group-faq-directory))))))
7197   (let (gnus-faq-buffer)
7198     (when (setq gnus-faq-buffer
7199                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7200       (gnus-configure-windows 'summary-faq))))
7201
7202 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7203 (defun gnus-summary-describe-group (&optional force)
7204   "Describe the current newsgroup."
7205   (interactive "P")
7206   (gnus-group-describe-group force gnus-newsgroup-name))
7207
7208 (defun gnus-summary-describe-briefly ()
7209   "Describe summary mode commands briefly."
7210   (interactive)
7211   (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")))
7212
7213 ;; Walking around group mode buffer from summary mode.
7214
7215 (defun gnus-summary-next-group (&optional no-article target-group backward)
7216   "Exit current newsgroup and then select next unread newsgroup.
7217 If prefix argument NO-ARTICLE is non-nil, no article is selected
7218 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7219 previous group instead."
7220   (interactive "P")
7221   ;; Stop pre-fetching.
7222   (gnus-async-halt-prefetch)
7223   (let ((current-group gnus-newsgroup-name)
7224         (current-buffer (current-buffer))
7225         entered)
7226     ;; First we semi-exit this group to update Xrefs and all variables.
7227     ;; We can't do a real exit, because the window conf must remain
7228     ;; the same in case the user is prompted for info, and we don't
7229     ;; want the window conf to change before that...
7230     (gnus-summary-exit t)
7231     (while (not entered)
7232       ;; Then we find what group we are supposed to enter.
7233       (set-buffer gnus-group-buffer)
7234       (gnus-group-jump-to-group current-group)
7235       (setq target-group
7236             (or target-group
7237                 (if (eq gnus-keep-same-level 'best)
7238                     (gnus-summary-best-group gnus-newsgroup-name)
7239                   (gnus-summary-search-group backward gnus-keep-same-level))))
7240       (if (not target-group)
7241           ;; There are no further groups, so we return to the group
7242           ;; buffer.
7243           (progn
7244             (gnus-message 5 "Returning to the group buffer")
7245             (setq entered t)
7246             (when (gnus-buffer-live-p current-buffer)
7247               (set-buffer current-buffer)
7248               (gnus-summary-exit))
7249             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7250         ;; We try to enter the target group.
7251         (gnus-group-jump-to-group target-group)
7252         (let ((unreads (gnus-group-group-unread)))
7253           (if (and (or (eq t unreads)
7254                        (and unreads (not (zerop unreads))))
7255                    (gnus-summary-read-group
7256                     target-group nil no-article
7257                     (and (buffer-name current-buffer) current-buffer)
7258                     nil backward))
7259               (setq entered t)
7260             (setq current-group target-group
7261                   target-group nil)))))))
7262
7263 (defun gnus-summary-prev-group (&optional no-article)
7264   "Exit current newsgroup and then select previous unread newsgroup.
7265 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7266   (interactive "P")
7267   (gnus-summary-next-group no-article nil t))
7268
7269 ;; Walking around summary lines.
7270
7271 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7272   "Go to the first subject satisfying any non-nil constraint.
7273 If UNREAD is non-nil, the article should be unread.
7274 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7275 If UNSEEN is non-nil, the article should be unseen.
7276 Returns the article selected or nil if there are no matching articles."
7277   (interactive "P")
7278   (cond
7279    ;; Empty summary.
7280    ((null gnus-newsgroup-data)
7281     (gnus-message 3 "No articles in the group")
7282     nil)
7283    ;; Pick the first article.
7284    ((not (or unread undownloaded unseen))
7285     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7286     (gnus-data-number (car gnus-newsgroup-data)))
7287    ;; Find the first unread article.
7288    (t
7289     (let ((data gnus-newsgroup-data))
7290       (while (and data
7291                   (let ((num (gnus-data-number (car data))))
7292                     (or (memq num gnus-newsgroup-unfetched)
7293                         (not (or (and unread
7294                                       (memq num gnus-newsgroup-unreads))
7295                                  (and undownloaded
7296                                       (memq num gnus-newsgroup-undownloaded))
7297                                  (and unseen
7298                                       (memq num gnus-newsgroup-unseen)))))))
7299         (setq data (cdr data)))
7300       (prog1
7301           (if data
7302               (progn
7303                 (goto-char (gnus-data-pos (car data)))
7304                 (gnus-data-number (car data)))
7305             (gnus-message 3 "No more%s articles"
7306                           (let* ((r (when unread " unread"))
7307                                  (d (when undownloaded " undownloaded"))
7308                                  (s (when unseen " unseen"))
7309                                  (l (delq nil (list r d s))))
7310                             (cond ((= 3 (length l))
7311                                    (concat r "," d ", or" s))
7312                                   ((= 2 (length l))
7313                                    (concat (car l) ", or" (cadr l)))
7314                                   ((= 1 (length l))
7315                                    (car l))
7316                                   (t
7317                                    ""))))
7318             nil
7319             )
7320         (gnus-summary-position-point))))))
7321
7322 (defun gnus-summary-next-subject (n &optional unread dont-display)
7323   "Go to next N'th summary line.
7324 If N is negative, go to the previous N'th subject line.
7325 If UNREAD is non-nil, only unread articles are selected.
7326 The difference between N and the actual number of steps taken is
7327 returned."
7328   (interactive "p")
7329   (let ((backward (< n 0))
7330         (n (abs n)))
7331     (while (and (> n 0)
7332                 (if backward
7333                     (gnus-summary-find-prev unread)
7334                   (gnus-summary-find-next unread)))
7335       (unless (zerop (setq n (1- n)))
7336         (gnus-summary-show-thread)))
7337     (when (/= 0 n)
7338       (gnus-message 7 "No more%s articles"
7339                     (if unread " unread" "")))
7340     (unless dont-display
7341       (gnus-summary-recenter)
7342       (gnus-summary-position-point))
7343     n))
7344
7345 (defun gnus-summary-next-unread-subject (n)
7346   "Go to next N'th unread summary line."
7347   (interactive "p")
7348   (gnus-summary-next-subject n t))
7349
7350 (defun gnus-summary-prev-subject (n &optional unread)
7351   "Go to previous N'th summary line.
7352 If optional argument UNREAD is non-nil, only unread article is selected."
7353   (interactive "p")
7354   (gnus-summary-next-subject (- n) unread))
7355
7356 (defun gnus-summary-prev-unread-subject (n)
7357   "Go to previous N'th unread summary line."
7358   (interactive "p")
7359   (gnus-summary-next-subject (- n) t))
7360
7361 (defun gnus-summary-goto-subjects (articles)
7362   "Insert the subject header for ARTICLES in the current buffer."
7363   (save-excursion
7364     (dolist (article articles)
7365       (gnus-summary-goto-subject article t)))
7366   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7367   (gnus-summary-position-point))
7368
7369 (defun gnus-summary-goto-subject (article &optional force silent)
7370   "Go the subject line of ARTICLE.
7371 If FORCE, also allow jumping to articles not currently shown."
7372   (interactive "nArticle number: ")
7373   (unless (numberp article)
7374     (error "Article %s is not a number" article))
7375   (let ((b (point))
7376         (data (gnus-data-find article)))
7377     ;; We read in the article if we have to.
7378     (and (not data)
7379          force
7380          (gnus-summary-insert-subject
7381           article
7382           (if (or (numberp force) (vectorp force)) force)
7383           t)
7384          (setq data (gnus-data-find article)))
7385     (goto-char b)
7386     (if (not data)
7387         (progn
7388           (unless silent
7389             (gnus-message 3 "Can't find article %d" article))
7390           nil)
7391       (let ((pt (gnus-data-pos data)))
7392         (goto-char pt)
7393         (gnus-summary-set-article-display-arrow pt))
7394       (gnus-summary-position-point)
7395       article)))
7396
7397 ;; Walking around summary lines with displaying articles.
7398
7399 (defun gnus-summary-expand-window (&optional arg)
7400   "Make the summary buffer take up the entire Emacs frame.
7401 Given a prefix, will force an `article' buffer configuration."
7402   (interactive "P")
7403   (if arg
7404       (gnus-configure-windows 'article 'force)
7405     (gnus-configure-windows 'summary 'force)))
7406
7407 (defun gnus-summary-display-article (article &optional all-header)
7408   "Display ARTICLE in article buffer."
7409   (when (gnus-buffer-live-p gnus-article-buffer)
7410     (with-current-buffer gnus-article-buffer
7411       (mm-enable-multibyte)))
7412   (gnus-set-global-variables)
7413   (when (gnus-buffer-live-p gnus-article-buffer)
7414     (with-current-buffer gnus-article-buffer
7415       (setq gnus-article-charset gnus-newsgroup-charset)
7416       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7417       (mm-enable-multibyte)))
7418   (if (null article)
7419       nil
7420     (prog1
7421         (if gnus-summary-display-article-function
7422             (funcall gnus-summary-display-article-function article all-header)
7423           (gnus-article-prepare article all-header))
7424       (gnus-run-hooks 'gnus-select-article-hook)
7425       (when (and gnus-current-article
7426                  (not (zerop gnus-current-article)))
7427         (gnus-summary-goto-subject gnus-current-article))
7428       (gnus-summary-recenter)
7429       (when (and gnus-use-trees gnus-show-threads)
7430         (gnus-possibly-generate-tree article)
7431         (gnus-highlight-selected-tree article))
7432       ;; Successfully display article.
7433       (gnus-article-set-window-start
7434        (cdr (assq article gnus-newsgroup-bookmarks))))))
7435
7436 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7437   "Select the current article.
7438 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7439 non-nil, the article will be re-fetched even if it already present in
7440 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7441 be displayed."
7442   ;; Make sure we are in the summary buffer to work around bbdb bug.
7443   (unless (eq major-mode 'gnus-summary-mode)
7444     (set-buffer gnus-summary-buffer))
7445   (let ((article (or article (gnus-summary-article-number)))
7446         (all-headers (not (not all-headers))) ;Must be t or nil.
7447         gnus-summary-display-article-function)
7448     (and (not pseudo)
7449          (gnus-summary-article-pseudo-p article)
7450          (error "This is a pseudo-article"))
7451     (save-excursion
7452       (set-buffer gnus-summary-buffer)
7453       (if (or (and gnus-single-article-buffer
7454                    (or (null gnus-current-article)
7455                        (null gnus-article-current)
7456                        (null (get-buffer gnus-article-buffer))
7457                        (not (eq article (cdr gnus-article-current)))
7458                        (not (equal (car gnus-article-current)
7459                                    gnus-newsgroup-name))))
7460               (and (not gnus-single-article-buffer)
7461                    (or (null gnus-current-article)
7462                        (not (eq gnus-current-article article))))
7463               force)
7464           ;; The requested article is different from the current article.
7465           (progn
7466             (gnus-summary-display-article article all-headers)
7467             (when (gnus-buffer-live-p gnus-article-buffer)
7468               (with-current-buffer gnus-article-buffer
7469                 (if (not gnus-article-decoded-p) ;; a local variable
7470                     (mm-disable-multibyte))))
7471             (gnus-article-set-window-start
7472              (cdr (assq article gnus-newsgroup-bookmarks)))
7473             article)
7474         'old))))
7475
7476 (defun gnus-summary-force-verify-and-decrypt ()
7477   "Display buttons for signed/encrypted parts and verify/decrypt them."
7478   (interactive)
7479   (let ((mm-verify-option 'known)
7480         (mm-decrypt-option 'known)
7481         (gnus-article-emulate-mime t)
7482         (gnus-buttonized-mime-types (append (list "multipart/signed"
7483                                                   "multipart/encrypted")
7484                                             gnus-buttonized-mime-types)))
7485     (gnus-summary-select-article nil 'force)))
7486
7487 (defun gnus-summary-set-current-mark (&optional current-mark)
7488   "Obsolete function."
7489   nil)
7490
7491 (defun gnus-summary-next-article (&optional unread subject backward push)
7492   "Select the next article.
7493 If UNREAD, only unread articles are selected.
7494 If SUBJECT, only articles with SUBJECT are selected.
7495 If BACKWARD, the previous article is selected instead of the next."
7496   (interactive "P")
7497   ;; Make sure we are in the summary buffer.
7498   (unless (eq major-mode 'gnus-summary-mode)
7499     (set-buffer gnus-summary-buffer))
7500   (cond
7501    ;; Is there such an article?
7502    ((and (gnus-summary-search-forward unread subject backward)
7503          (or (gnus-summary-display-article (gnus-summary-article-number))
7504              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7505     (gnus-summary-position-point))
7506    ;; If not, we try the first unread, if that is wanted.
7507    ((and subject
7508          gnus-auto-select-same
7509          (gnus-summary-first-unread-article))
7510     (gnus-summary-position-point)
7511     (gnus-message 6 "Wrapped"))
7512    ;; Try to get next/previous article not displayed in this group.
7513    ((and gnus-auto-extend-newsgroup
7514          (not unread) (not subject))
7515     (gnus-summary-goto-article
7516      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7517      nil (count-lines (point-min) (point))))
7518    ;; Go to next/previous group.
7519    (t
7520     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7521       (gnus-summary-jump-to-group gnus-newsgroup-name))
7522     (let ((cmd last-command-char)
7523           (point
7524            (with-current-buffer gnus-group-buffer
7525              (point)))
7526           (group
7527            (if (eq gnus-keep-same-level 'best)
7528                (gnus-summary-best-group gnus-newsgroup-name)
7529              (gnus-summary-search-group backward gnus-keep-same-level))))
7530       ;; For some reason, the group window gets selected.  We change
7531       ;; it back.
7532       (select-window (get-buffer-window (current-buffer)))
7533       ;; Select next unread newsgroup automagically.
7534       (cond
7535        ((or (not gnus-auto-select-next)
7536             (not cmd))
7537         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7538        ((or (eq gnus-auto-select-next 'quietly)
7539             (and (eq gnus-auto-select-next 'slightly-quietly)
7540                  push)
7541             (and (eq gnus-auto-select-next 'almost-quietly)
7542                  (gnus-summary-last-article-p)))
7543         ;; Select quietly.
7544         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7545             (gnus-summary-exit)
7546           (gnus-message 7 "No more%s articles (%s)..."
7547                         (if unread " unread" "")
7548                         (if group (concat "selecting " group)
7549                           "exiting"))
7550           (gnus-summary-next-group nil group backward)))
7551        (t
7552         (when (gnus-key-press-event-p last-input-event)
7553           (gnus-summary-walk-group-buffer
7554            gnus-newsgroup-name cmd unread backward point))))))))
7555
7556 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7557   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7558                       (?\C-p (gnus-group-prev-unread-group 1))))
7559         (cursor-in-echo-area t)
7560         keve key group ended prompt)
7561     (save-excursion
7562       (set-buffer gnus-group-buffer)
7563       (goto-char start)
7564       (setq 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     (while (not ended)
7569       (setq prompt
7570             (format
7571              "No more%s articles%s " (if unread " unread" "")
7572              (if (and group
7573                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7574                  (format " (Type %s for %s [%s])"
7575                          (single-key-description cmd)
7576                          (gnus-group-decoded-name group)
7577                          (gnus-group-unread group))
7578                (format " (Type %s to exit %s)"
7579                        (single-key-description cmd)
7580                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7581       ;; Confirm auto selection.
7582       (setq key (car (setq keve (gnus-read-event-char prompt)))
7583             ended t)
7584       (cond
7585        ((assq key keystrokes)
7586         (let ((obuf (current-buffer)))
7587           (switch-to-buffer gnus-group-buffer)
7588           (when group
7589             (gnus-group-jump-to-group group))
7590           (eval (cadr (assq key keystrokes)))
7591           (setq group (gnus-group-group-name))
7592           (switch-to-buffer obuf))
7593         (setq ended nil))
7594        ((equal key cmd)
7595         (if (or (not group)
7596                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7597             (gnus-summary-exit)
7598           (gnus-summary-next-group nil group backward)))
7599        (t
7600         (push (cdr keve) unread-command-events))))))
7601
7602 (defun gnus-summary-next-unread-article ()
7603   "Select unread article after current one."
7604   (interactive)
7605   (gnus-summary-next-article
7606    (or (not (eq gnus-summary-goto-unread 'never))
7607        (gnus-summary-last-article-p (gnus-summary-article-number)))
7608    (and gnus-auto-select-same
7609         (gnus-summary-article-subject))))
7610
7611 (defun gnus-summary-prev-article (&optional unread subject)
7612   "Select the article after the current one.
7613 If UNREAD is non-nil, only unread articles are selected."
7614   (interactive "P")
7615   (gnus-summary-next-article unread subject t))
7616
7617 (defun gnus-summary-prev-unread-article ()
7618   "Select unread article before current one."
7619   (interactive)
7620   (gnus-summary-prev-article
7621    (or (not (eq gnus-summary-goto-unread 'never))
7622        (gnus-summary-first-article-p (gnus-summary-article-number)))
7623    (and gnus-auto-select-same
7624         (gnus-summary-article-subject))))
7625
7626 (defun gnus-summary-next-page (&optional lines circular stop)
7627   "Show next page of the selected article.
7628 If at the end of the current article, select the next article.
7629 LINES says how many lines should be scrolled up.
7630
7631 If CIRCULAR is non-nil, go to the start of the article instead of
7632 selecting the next article when reaching the end of the current
7633 article.
7634
7635 If STOP is non-nil, just stop when reaching the end of the message.
7636
7637 Also see the variable `gnus-article-skip-boring'."
7638   (interactive "P")
7639   (setq gnus-summary-buffer (current-buffer))
7640   (gnus-set-global-variables)
7641   (let ((article (gnus-summary-article-number))
7642         (article-window (get-buffer-window gnus-article-buffer t))
7643         endp)
7644     ;; If the buffer is empty, we have no article.
7645     (unless article
7646       (error "No article to select"))
7647     (gnus-configure-windows 'article)
7648     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7649         (if (and (eq gnus-summary-goto-unread 'never)
7650                  (not (gnus-summary-last-article-p article)))
7651             (gnus-summary-next-article)
7652           (gnus-summary-next-unread-article))
7653       (if (or (null gnus-current-article)
7654               (null gnus-article-current)
7655               (/= article (cdr gnus-article-current))
7656               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7657           ;; Selected subject is different from current article's.
7658           (gnus-summary-display-article article)
7659         (when article-window
7660           (gnus-eval-in-buffer-window gnus-article-buffer
7661             (setq endp (or (gnus-article-next-page lines)
7662                            (gnus-article-only-boring-p))))
7663           (when endp
7664             (cond (stop
7665                    (gnus-message 3 "End of message"))
7666                   (circular
7667                    (gnus-summary-beginning-of-article))
7668                   (lines
7669                    (gnus-message 3 "End of message"))
7670                   ((null lines)
7671                    (if (and (eq gnus-summary-goto-unread 'never)
7672                             (not (gnus-summary-last-article-p article)))
7673                        (gnus-summary-next-article)
7674                      (gnus-summary-next-unread-article))))))))
7675     (gnus-summary-recenter)
7676     (gnus-summary-position-point)))
7677
7678 (defun gnus-summary-prev-page (&optional lines move)
7679   "Show previous page of selected article.
7680 Argument LINES specifies lines to be scrolled down.
7681 If MOVE, move to the previous unread article if point is at
7682 the beginning of the buffer."
7683   (interactive "P")
7684   (let ((article (gnus-summary-article-number))
7685         (article-window (get-buffer-window gnus-article-buffer t))
7686         endp)
7687     (gnus-configure-windows 'article)
7688     (if (or (null gnus-current-article)
7689             (null gnus-article-current)
7690             (/= article (cdr gnus-article-current))
7691             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7692         ;; Selected subject is different from current article's.
7693         (gnus-summary-display-article article)
7694       (gnus-summary-recenter)
7695       (when article-window
7696         (gnus-eval-in-buffer-window gnus-article-buffer
7697           (setq endp (gnus-article-prev-page lines)))
7698         (when (and move endp)
7699           (cond (lines
7700                  (gnus-message 3 "Beginning of message"))
7701                 ((null lines)
7702                  (if (and (eq gnus-summary-goto-unread 'never)
7703                           (not (gnus-summary-first-article-p article)))
7704                      (gnus-summary-prev-article)
7705                    (gnus-summary-prev-unread-article))))))))
7706   (gnus-summary-position-point))
7707
7708 (defun gnus-summary-prev-page-or-article (&optional lines)
7709   "Show previous page of selected article.
7710 Argument LINES specifies lines to be scrolled down.
7711 If at the beginning of the article, go to the next article."
7712   (interactive "P")
7713   (gnus-summary-prev-page lines t))
7714
7715 (defun gnus-summary-scroll-up (lines)
7716   "Scroll up (or down) one line current article.
7717 Argument LINES specifies lines to be scrolled up (or down if negative)."
7718   (interactive "p")
7719   (gnus-configure-windows 'article)
7720   (gnus-summary-show-thread)
7721   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7722     (gnus-eval-in-buffer-window gnus-article-buffer
7723       (cond ((> lines 0)
7724              (when (gnus-article-next-page lines)
7725                (gnus-message 3 "End of message")))
7726             ((< lines 0)
7727              (gnus-article-prev-page (- lines))))))
7728   (gnus-summary-recenter)
7729   (gnus-summary-position-point))
7730
7731 (defun gnus-summary-scroll-down (lines)
7732   "Scroll down (or up) one line current article.
7733 Argument LINES specifies lines to be scrolled down (or up if negative)."
7734   (interactive "p")
7735   (gnus-summary-scroll-up (- lines)))
7736
7737 (defun gnus-summary-next-same-subject ()
7738   "Select next article which has the same subject as current one."
7739   (interactive)
7740   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7741
7742 (defun gnus-summary-prev-same-subject ()
7743   "Select previous article which has the same subject as current one."
7744   (interactive)
7745   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7746
7747 (defun gnus-summary-next-unread-same-subject ()
7748   "Select next unread article which has the same subject as current one."
7749   (interactive)
7750   (gnus-summary-next-article t (gnus-summary-article-subject)))
7751
7752 (defun gnus-summary-prev-unread-same-subject ()
7753   "Select previous unread article which has the same subject as current one."
7754   (interactive)
7755   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7756
7757 (defun gnus-summary-first-unread-article ()
7758   "Select the first unread article.
7759 Return nil if there are no unread articles."
7760   (interactive)
7761   (prog1
7762       (when (gnus-summary-first-subject t)
7763         (gnus-summary-show-thread)
7764         (gnus-summary-first-subject t)
7765         (gnus-summary-display-article (gnus-summary-article-number)))
7766     (gnus-summary-position-point)))
7767
7768 (defun gnus-summary-first-unread-subject ()
7769   "Place the point on the subject line of the first unread article.
7770 Return nil if there are no unread articles."
7771   (interactive)
7772   (prog1
7773       (when (gnus-summary-first-subject t)
7774         (gnus-summary-show-thread)
7775         (gnus-summary-first-subject t))
7776     (gnus-summary-position-point)))
7777
7778 (defun gnus-summary-first-unseen-subject ()
7779   "Place the point on the subject line of the first unseen article.
7780 Return nil if there are no unseen articles."
7781   (interactive)
7782   (prog1
7783       (when (gnus-summary-first-subject nil nil t)
7784         (gnus-summary-show-thread)
7785         (gnus-summary-first-subject nil nil t))
7786     (gnus-summary-position-point)))
7787
7788 (defun gnus-summary-first-unseen-or-unread-subject ()
7789   "Place the point on the subject line of the first unseen article or,
7790 if all article have been seen, on the subject line of the first unread
7791 article."
7792   (interactive)
7793   (prog1
7794       (unless (when (gnus-summary-first-subject nil nil t)
7795                 (gnus-summary-show-thread)
7796                 (gnus-summary-first-subject nil nil t))
7797         (when (gnus-summary-first-subject t)
7798           (gnus-summary-show-thread)
7799           (gnus-summary-first-subject t)))
7800     (gnus-summary-position-point)))
7801
7802 (defun gnus-summary-first-article ()
7803   "Select the first article.
7804 Return nil if there are no articles."
7805   (interactive)
7806   (prog1
7807       (when (gnus-summary-first-subject)
7808         (gnus-summary-show-thread)
7809         (gnus-summary-first-subject)
7810         (gnus-summary-display-article (gnus-summary-article-number)))
7811     (gnus-summary-position-point)))
7812
7813 (defun gnus-summary-best-unread-article (&optional arg)
7814   "Select the unread article with the highest score.
7815 If given a prefix argument, select the next unread article that has a
7816 score higher than the default score."
7817   (interactive "P")
7818   (let ((article (if arg
7819                      (gnus-summary-better-unread-subject)
7820                    (gnus-summary-best-unread-subject))))
7821     (if article
7822         (gnus-summary-goto-article article)
7823       (error "No unread articles"))))
7824
7825 (defun gnus-summary-best-unread-subject ()
7826   "Select the unread subject with the highest score."
7827   (interactive)
7828   (let ((best -1000000)
7829         (data gnus-newsgroup-data)
7830         article score)
7831     (while data
7832       (and (gnus-data-unread-p (car data))
7833            (> (setq score
7834                     (gnus-summary-article-score (gnus-data-number (car data))))
7835               best)
7836            (setq best score
7837                  article (gnus-data-number (car data))))
7838       (setq data (cdr data)))
7839     (when article
7840       (gnus-summary-goto-subject article))
7841     (gnus-summary-position-point)
7842     article))
7843
7844 (defun gnus-summary-better-unread-subject ()
7845   "Select the first unread subject that has a score over the default score."
7846   (interactive)
7847   (let ((data gnus-newsgroup-data)
7848         article score)
7849     (while (and (setq article (gnus-data-number (car data)))
7850                 (or (gnus-data-read-p (car data))
7851                     (not (> (gnus-summary-article-score article)
7852                             gnus-summary-default-score))))
7853       (setq data (cdr data)))
7854     (when article
7855       (gnus-summary-goto-subject article))
7856     (gnus-summary-position-point)
7857     article))
7858
7859 (defun gnus-summary-last-subject ()
7860   "Go to the last displayed subject line in the group."
7861   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7862     (when article
7863       (gnus-summary-goto-subject article))))
7864
7865 (defun gnus-summary-goto-article (article &optional all-headers force)
7866   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7867 If ALL-HEADERS is non-nil, no header lines are hidden.
7868 If FORCE, go to the article even if it isn't displayed.  If FORCE
7869 is a number, it is the line the article is to be displayed on."
7870   (interactive
7871    (list
7872     (completing-read
7873      "Article number or Message-ID: "
7874      (mapcar (lambda (number) (list (int-to-string number)))
7875              gnus-newsgroup-limit))
7876     current-prefix-arg
7877     t))
7878   (prog1
7879       (if (and (stringp article)
7880                (string-match "@\\|%40" article))
7881           (gnus-summary-refer-article article)
7882         (when (stringp article)
7883           (setq article (string-to-number article)))
7884         (if (gnus-summary-goto-subject article force)
7885             (gnus-summary-display-article article all-headers)
7886           (gnus-message 4 "Couldn't go to article %s" article) nil))
7887     (gnus-summary-position-point)))
7888
7889 (defun gnus-summary-goto-last-article ()
7890   "Go to the previously read article."
7891   (interactive)
7892   (prog1
7893       (when gnus-last-article
7894         (gnus-summary-goto-article gnus-last-article nil t))
7895     (gnus-summary-position-point)))
7896
7897 (defun gnus-summary-pop-article (number)
7898   "Pop one article off the history and go to the previous.
7899 NUMBER articles will be popped off."
7900   (interactive "p")
7901   (let (to)
7902     (setq gnus-newsgroup-history
7903           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7904     (if to
7905         (gnus-summary-goto-article (car to) nil t)
7906       (error "Article history empty")))
7907   (gnus-summary-position-point))
7908
7909 ;; Summary commands and functions for limiting the summary buffer.
7910
7911 (defun gnus-summary-limit-to-articles (n)
7912   "Limit the summary buffer to the next N articles.
7913 If not given a prefix, use the process marked articles instead."
7914   (interactive "P")
7915   (prog1
7916       (let ((articles (gnus-summary-work-articles n)))
7917         (setq gnus-newsgroup-processable nil)
7918         (gnus-summary-limit articles))
7919     (gnus-summary-position-point)))
7920
7921 (defun gnus-summary-pop-limit (&optional total)
7922   "Restore the previous limit.
7923 If given a prefix, remove all limits."
7924   (interactive "P")
7925   (when total
7926     (setq gnus-newsgroup-limits
7927           (list (mapcar (lambda (h) (mail-header-number h))
7928                         gnus-newsgroup-headers))))
7929   (unless gnus-newsgroup-limits
7930     (error "No limit to pop"))
7931   (prog1
7932       (gnus-summary-limit nil 'pop)
7933     (gnus-summary-position-point)))
7934
7935 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7936   "Limit the summary buffer to articles that have subjects that match a regexp.
7937 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7938   (interactive
7939    (list (read-string (if current-prefix-arg
7940                           "Exclude subject (regexp): "
7941                         "Limit to subject (regexp): "))
7942          nil current-prefix-arg))
7943   (unless header
7944     (setq header "subject"))
7945   (when (not (equal "" subject))
7946     (prog1
7947         (let ((articles (gnus-summary-find-matching
7948                          (or header "subject") subject 'all nil nil
7949                          not-matching)))
7950           (unless articles
7951             (error "Found no matches for \"%s\"" subject))
7952           (gnus-summary-limit articles))
7953       (gnus-summary-position-point))))
7954
7955 (defun gnus-summary-limit-to-author (from &optional not-matching)
7956   "Limit the summary buffer to articles that have authors that match a regexp.
7957 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7958   (interactive
7959    (list (read-string (if current-prefix-arg
7960                           "Exclude author (regexp): "
7961                         "Limit to author (regexp): "))
7962          current-prefix-arg))
7963   (gnus-summary-limit-to-subject from "from" not-matching))
7964
7965 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7966   "Limit the summary buffer to articles with the given RECIPIENT.
7967
7968 If NOT-MATCHING, exclude RECIPIENT.
7969
7970 To and Cc headers are checked.  You need to include them in
7971 `nnmail-extra-headers'."
7972   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7973   (interactive
7974    (list (read-string (format "%s recipient (regexp): "
7975                               (if current-prefix-arg "Exclude" "Limit to")))
7976          current-prefix-arg))
7977   (when (not (equal "" recipient))
7978     (prog1 (let* ((to
7979                    (if (memq 'To nnmail-extra-headers)
7980                        (gnus-summary-find-matching
7981                         (cons 'extra 'To) recipient 'all nil nil
7982                         not-matching)
7983                      (gnus-message
7984                       1 "`To' isn't present in `nnmail-extra-headers'")
7985                      (sit-for 1)
7986                      nil))
7987                   (cc
7988                    (if (memq 'Cc nnmail-extra-headers)
7989                        (gnus-summary-find-matching
7990                         (cons 'extra 'Cc) recipient 'all nil nil
7991                         not-matching)
7992                      (gnus-message
7993                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7994                      (sit-for 1)
7995                      nil))
7996                   (articles
7997                    (if not-matching
7998                        ;; We need the numbers that are in both lists:
7999                        (mapcar (lambda (a)
8000                                  (and (memq a to) a))
8001                                cc)
8002                      (nconc to cc))))
8003              (unless articles
8004                (error "Found no matches for \"%s\"" recipient))
8005              (gnus-summary-limit articles))
8006       (gnus-summary-position-point))))
8007
8008 (defun gnus-summary-limit-strange-charsets-predicate (header)
8009   (let ((string (concat (mail-header-subject header)
8010                         (mail-header-from header)))
8011         charset found)
8012     (dotimes (i (1- (length string)))
8013       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8014       (when (string-match "unicode\\|big\\|japanese" charset)
8015         (setq found t)))
8016     found))
8017
8018 (defun gnus-summary-limit-to-predicate (predicate)
8019   "Limit to articles where PREDICATE returns non-nil.
8020 PREDICATE will be called with the header structures of the
8021 articles."
8022   (let ((articles nil)
8023         (case-fold-search t))
8024     (dolist (header gnus-newsgroup-headers)
8025       (when (funcall predicate header)
8026         (push (mail-header-number header) articles)))
8027     (gnus-summary-limit (nreverse articles))))
8028
8029 (defun gnus-summary-limit-to-age (age &optional younger-p)
8030   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8031 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8032 articles that are younger than AGE days."
8033   (interactive
8034    (let ((younger current-prefix-arg)
8035          (days-got nil)
8036          days)
8037      (while (not days-got)
8038        (setq days (if younger
8039                       (read-string "Limit to articles younger than (in days, older when negative): ")
8040                     (read-string
8041                      "Limit to articles older than (in days, younger when negative): ")))
8042        (when (> (length days) 0)
8043          (setq days (read days)))
8044        (if (numberp days)
8045            (progn
8046              (setq days-got t)
8047              (when (< days 0)
8048                (setq younger (not younger))
8049                (setq days (* days -1))))
8050          (message "Please enter a number.")
8051          (sleep-for 1)))
8052      (list days younger)))
8053   (prog1
8054       (let ((data gnus-newsgroup-data)
8055             (cutoff (days-to-time age))
8056             articles d date is-younger)
8057         (while (setq d (pop data))
8058           (when (and (vectorp (gnus-data-header d))
8059                      (setq date (mail-header-date (gnus-data-header d))))
8060             (setq is-younger (time-less-p
8061                               (time-since (condition-case ()
8062                                               (date-to-time date)
8063                                             (error '(0 0))))
8064                               cutoff))
8065             (when (if younger-p
8066                       is-younger
8067                     (not is-younger))
8068               (push (gnus-data-number d) articles))))
8069         (gnus-summary-limit (nreverse articles)))
8070     (gnus-summary-position-point)))
8071
8072 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8073   "Limit the summary buffer to articles that match an 'extra' header."
8074   (interactive
8075    (let ((header
8076           (intern
8077            (gnus-completing-read-with-default
8078             (symbol-name (car gnus-extra-headers))
8079             (if current-prefix-arg
8080                 "Exclude extra header"
8081               "Limit extra header")
8082             (mapcar (lambda (x)
8083                       (cons (symbol-name x) x))
8084                     gnus-extra-headers)
8085             nil
8086             t))))
8087      (list header
8088            (read-string (format "%s header %s (regexp): "
8089                                 (if current-prefix-arg "Exclude" "Limit to")
8090                                 header))
8091            current-prefix-arg)))
8092   (when (not (equal "" regexp))
8093     (prog1
8094         (let ((articles (gnus-summary-find-matching
8095                          (cons 'extra header) regexp 'all nil nil
8096                          not-matching)))
8097           (unless articles
8098             (error "Found no matches for \"%s\"" regexp))
8099           (gnus-summary-limit articles))
8100       (gnus-summary-position-point))))
8101
8102 (defun gnus-summary-limit-to-display-predicate ()
8103   "Limit the summary buffer to the predicated in the `display' group parameter."
8104   (interactive)
8105   (unless gnus-newsgroup-display
8106     (error "There is no `display' group parameter"))
8107   (let (articles)
8108     (dolist (number gnus-newsgroup-articles)
8109       (when (funcall gnus-newsgroup-display)
8110         (push number articles)))
8111     (gnus-summary-limit articles))
8112   (gnus-summary-position-point))
8113
8114 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8115 (make-obsolete
8116  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8117
8118 (defun gnus-summary-limit-to-unread (&optional all)
8119   "Limit the summary buffer to articles that are not marked as read.
8120 If ALL is non-nil, limit strictly to unread articles."
8121   (interactive "P")
8122   (if all
8123       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8124     (gnus-summary-limit-to-marks
8125      ;; Concat all the marks that say that an article is read and have
8126      ;; those removed.
8127      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8128            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8129            gnus-low-score-mark gnus-expirable-mark
8130            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8131            gnus-duplicate-mark gnus-souped-mark)
8132      'reverse)))
8133
8134 (defun gnus-summary-limit-to-headers (match &optional reverse)
8135   "Limit the summary buffer to articles that have headers that match MATCH.
8136 If REVERSE (the prefix), limit to articles that don't match."
8137   (interactive "sMatch headers (regexp): \nP")
8138   (gnus-summary-limit-to-bodies match reverse t))
8139
8140 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8141   "Limit the summary buffer to articles that have bodies that match MATCH.
8142 If REVERSE (the prefix), limit to articles that don't match."
8143   (interactive "sMatch body (regexp): \nP")
8144   (let ((articles nil)
8145         (gnus-select-article-hook nil)  ;Disable hook.
8146         (gnus-article-prepare-hook nil)
8147         (gnus-use-article-prefetch nil)
8148         (gnus-keep-backlog nil)
8149         (gnus-break-pages nil)
8150         (gnus-summary-display-arrow nil)
8151         (gnus-updated-mode-lines nil)
8152         (gnus-auto-center-summary nil)
8153         (gnus-display-mime-function nil))
8154     (dolist (data gnus-newsgroup-data)
8155       (let (gnus-mark-article-hook)
8156         (gnus-summary-select-article t t nil (gnus-data-number data)))
8157       (save-excursion
8158         (set-buffer gnus-article-buffer)
8159         (article-goto-body)
8160         (let* ((case-fold-search t)
8161                (found (if headersp
8162                           (re-search-backward match nil t)
8163                         (re-search-forward match nil t))))
8164           (when (or (and found
8165                          (not reverse))
8166                     (and (not found)
8167                          reverse))
8168             (push (gnus-data-number data) articles)))))
8169     (if (not articles)
8170         (message "No messages matched")
8171       (gnus-summary-limit articles)))
8172   (gnus-summary-position-point))
8173
8174 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8175   "Limit the summary buffer to articles that aren't part on any thread.
8176 If THREADSP (the prefix), limit to articles that are in threads."
8177   (interactive "P")
8178   (let ((articles nil)
8179         thread-articles
8180         threads)
8181     (dolist (thread gnus-newsgroup-threads)
8182       (if (stringp (car thread))
8183           (dolist (thread (cdr thread))
8184             (push thread threads))
8185         (push thread threads)))
8186     (dolist (thread threads)
8187       (setq thread-articles (gnus-articles-in-thread thread))
8188       (when (or (and threadsp
8189                      (> (length thread-articles) 1))
8190                 (and (not threadsp)
8191                      (= (length thread-articles) 1)))
8192         (setq articles (nconc thread-articles articles))))
8193     (if (not articles)
8194         (message "No messages matched")
8195       (gnus-summary-limit articles))
8196     (gnus-summary-position-point)))
8197
8198 (defun gnus-summary-limit-to-replied (&optional unreplied)
8199   "Limit the summary buffer to replied articles.
8200 If UNREPLIED (the prefix), limit to unreplied articles."
8201   (interactive "P")
8202   (if unreplied
8203       (gnus-summary-limit
8204        (gnus-set-difference gnus-newsgroup-articles
8205         gnus-newsgroup-replied))
8206     (gnus-summary-limit gnus-newsgroup-replied))
8207   (gnus-summary-position-point))
8208
8209 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8210 (make-obsolete 'gnus-summary-delete-marked-with
8211                'gnus-summary-limit-exclude-marks)
8212
8213 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8214   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8215 If REVERSE, limit the summary buffer to articles that are marked
8216 with MARKS.  MARKS can either be a string of marks or a list of marks.
8217 Returns how many articles were removed."
8218   (interactive "sMarks: ")
8219   (gnus-summary-limit-to-marks marks t))
8220
8221 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8222   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8223 If REVERSE (the prefix), limit the summary buffer to articles that are
8224 not marked with MARKS.  MARKS can either be a string of marks or a
8225 list of marks.
8226 Returns how many articles were removed."
8227   (interactive "sMarks: \nP")
8228   (prog1
8229       (let ((data gnus-newsgroup-data)
8230             (marks (if (listp marks) marks
8231                      (append marks nil))) ; Transform to list.
8232             articles)
8233         (while data
8234           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8235                   (memq (gnus-data-mark (car data)) marks))
8236             (push (gnus-data-number (car data)) articles))
8237           (setq data (cdr data)))
8238         (gnus-summary-limit articles))
8239     (gnus-summary-position-point)))
8240
8241 (defun gnus-summary-limit-to-score (score)
8242   "Limit to articles with score at or above SCORE."
8243   (interactive "NLimit to articles with score of at least: ")
8244   (let ((data gnus-newsgroup-data)
8245         articles)
8246     (while data
8247       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8248                 score)
8249         (push (gnus-data-number (car data)) articles))
8250       (setq data (cdr data)))
8251     (prog1
8252         (gnus-summary-limit articles)
8253       (gnus-summary-position-point))))
8254
8255 (defun gnus-summary-limit-to-unseen ()
8256   "Limit to unseen articles."
8257   (interactive)
8258   (prog1
8259       (gnus-summary-limit gnus-newsgroup-unseen)
8260     (gnus-summary-position-point)))
8261
8262 (defun gnus-summary-limit-include-thread (id)
8263   "Display all the hidden articles that is in the thread with ID in it.
8264 When called interactively, ID is the Message-ID of the current
8265 article."
8266   (interactive (list (mail-header-id (gnus-summary-article-header))))
8267   (let ((articles (gnus-articles-in-thread
8268                    (gnus-id-to-thread (gnus-root-id id)))))
8269     (prog1
8270         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8271       (gnus-summary-limit-include-matching-articles
8272        "subject"
8273        (regexp-quote (gnus-simplify-subject-re
8274                       (mail-header-subject (gnus-id-to-header id)))))
8275       (gnus-summary-position-point))))
8276
8277 (defun gnus-summary-limit-include-matching-articles (header regexp)
8278   "Display all the hidden articles that have HEADERs that match REGEXP."
8279   (interactive (list (read-string "Match on header: ")
8280                      (read-string "Regexp: ")))
8281   (let ((articles (gnus-find-matching-articles header regexp)))
8282     (prog1
8283         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8284       (gnus-summary-position-point))))
8285
8286 (defun gnus-summary-insert-dormant-articles ()
8287   "Insert all the dormant articles for this group into the current buffer."
8288   (interactive)
8289   (let ((gnus-verbose (max 6 gnus-verbose)))
8290     (if (not gnus-newsgroup-dormant)
8291         (gnus-message 3 "No dormant articles for this group")
8292       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8293
8294 (defun gnus-summary-insert-ticked-articles ()
8295   "Insert ticked articles for this group into the current buffer."
8296   (interactive)
8297   (let ((gnus-verbose (max 6 gnus-verbose)))
8298     (if (not gnus-newsgroup-marked)
8299         (gnus-message 3 "No ticked articles for this group")
8300       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8301
8302 (defun gnus-summary-limit-include-dormant ()
8303   "Display all the hidden articles that are marked as dormant.
8304 Note that this command only works on a subset of the articles currently
8305 fetched for this group."
8306   (interactive)
8307   (unless gnus-newsgroup-dormant
8308     (error "There are no dormant articles in this group"))
8309   (prog1
8310       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8311     (gnus-summary-position-point)))
8312
8313 (defun gnus-summary-limit-exclude-dormant ()
8314   "Hide all dormant articles."
8315   (interactive)
8316   (prog1
8317       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8318     (gnus-summary-position-point)))
8319
8320 (defun gnus-summary-limit-exclude-childless-dormant ()
8321   "Hide all dormant articles that have no children."
8322   (interactive)
8323   (let ((data (gnus-data-list t))
8324         articles d children)
8325     ;; Find all articles that are either not dormant or have
8326     ;; children.
8327     (while (setq d (pop data))
8328       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8329                 (and (setq children
8330                            (gnus-article-children (gnus-data-number d)))
8331                      (let (found)
8332                        (while children
8333                          (when (memq (car children) articles)
8334                            (setq children nil
8335                                  found t))
8336                          (pop children))
8337                        found)))
8338         (push (gnus-data-number d) articles)))
8339     ;; Do the limiting.
8340     (prog1
8341         (gnus-summary-limit articles)
8342       (gnus-summary-position-point))))
8343
8344 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8345   "Mark all unread excluded articles as read.
8346 If ALL, mark even excluded ticked and dormants as read."
8347   (interactive "P")
8348   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8349   (let ((articles (gnus-sorted-ndifference
8350                    (sort
8351                     (mapcar (lambda (h) (mail-header-number h))
8352                             gnus-newsgroup-headers)
8353                     '<)
8354                    gnus-newsgroup-limit))
8355         article)
8356     (setq gnus-newsgroup-unreads
8357           (gnus-sorted-intersection gnus-newsgroup-unreads
8358                                     gnus-newsgroup-limit))
8359     (if all
8360         (setq gnus-newsgroup-dormant nil
8361               gnus-newsgroup-marked nil
8362               gnus-newsgroup-reads
8363               (nconc
8364                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8365                gnus-newsgroup-reads))
8366       (while (setq article (pop articles))
8367         (unless (or (memq article gnus-newsgroup-dormant)
8368                     (memq article gnus-newsgroup-marked))
8369           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8370
8371 (defun gnus-summary-limit (articles &optional pop)
8372   (if pop
8373       ;; We pop the previous limit off the stack and use that.
8374       (setq articles (car gnus-newsgroup-limits)
8375             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8376     ;; We use the new limit, so we push the old limit on the stack.
8377     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8378   ;; Set the limit.
8379   (setq gnus-newsgroup-limit articles)
8380   (let ((total (length gnus-newsgroup-data))
8381         (data (gnus-data-find-list (gnus-summary-article-number)))
8382         (gnus-summary-mark-below nil)   ; Inhibit this.
8383         found)
8384     ;; This will do all the work of generating the new summary buffer
8385     ;; according to the new limit.
8386     (gnus-summary-prepare)
8387     ;; Hide any threads, possibly.
8388     (gnus-summary-maybe-hide-threads)
8389     ;; Try to return to the article you were at, or one in the
8390     ;; neighborhood.
8391     (when data
8392       ;; We try to find some article after the current one.
8393       (while data
8394         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8395           (setq data nil
8396                 found t))
8397         (setq data (cdr data))))
8398     (unless found
8399       ;; If there is no data, that means that we were after the last
8400       ;; article.  The same goes when we can't find any articles
8401       ;; after the current one.
8402       (goto-char (point-max))
8403       (gnus-summary-find-prev))
8404     (gnus-set-mode-line 'summary)
8405     ;; We return how many articles were removed from the summary
8406     ;; buffer as a result of the new limit.
8407     (- total (length gnus-newsgroup-data))))
8408
8409 (defsubst gnus-invisible-cut-children (threads)
8410   (let ((num 0))
8411     (while threads
8412       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8413         (incf num))
8414       (pop threads))
8415     (< num 2)))
8416
8417 (defsubst gnus-cut-thread (thread)
8418   "Go forwards in the thread until we find an article that we want to display."
8419   (when (or (eq gnus-fetch-old-headers 'some)
8420             (eq gnus-fetch-old-headers 'invisible)
8421             (numberp gnus-fetch-old-headers)
8422             (eq gnus-build-sparse-threads 'some)
8423             (eq gnus-build-sparse-threads 'more))
8424     ;; Deal with old-fetched headers and sparse threads.
8425     (while (and
8426             thread
8427             (or
8428              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8429              (gnus-summary-article-ancient-p
8430               (mail-header-number (car thread))))
8431             (if (or (<= (length (cdr thread)) 1)
8432                     (eq gnus-fetch-old-headers 'invisible))
8433                 (setq gnus-newsgroup-limit
8434                       (delq (mail-header-number (car thread))
8435                             gnus-newsgroup-limit)
8436                       thread (cadr thread))
8437               (when (gnus-invisible-cut-children (cdr thread))
8438                 (let ((th (cdr thread)))
8439                   (while th
8440                     (if (memq (mail-header-number (caar th))
8441                               gnus-newsgroup-limit)
8442                         (setq thread (car th)
8443                               th nil)
8444                       (setq th (cdr th))))))))))
8445   thread)
8446
8447 (defun gnus-cut-threads (threads)
8448   "Cut off all uninteresting articles from the beginning of THREADS."
8449   (when (or (eq gnus-fetch-old-headers 'some)
8450             (eq gnus-fetch-old-headers 'invisible)
8451             (numberp gnus-fetch-old-headers)
8452             (eq gnus-build-sparse-threads 'some)
8453             (eq gnus-build-sparse-threads 'more))
8454     (let ((th threads))
8455       (while th
8456         (setcar th (gnus-cut-thread (car th)))
8457         (setq th (cdr th)))))
8458   ;; Remove nixed out threads.
8459   (delq nil threads))
8460
8461 (defun gnus-summary-initial-limit (&optional show-if-empty)
8462   "Figure out what the initial limit is supposed to be on group entry.
8463 This entails weeding out unwanted dormants, low-scored articles,
8464 fetch-old-headers verbiage, and so on."
8465   ;; Most groups have nothing to remove.
8466   (if (or gnus-inhibit-limiting
8467           (and (null gnus-newsgroup-dormant)
8468                (eq gnus-newsgroup-display 'gnus-not-ignore)
8469                (not (eq gnus-fetch-old-headers 'some))
8470                (not (numberp gnus-fetch-old-headers))
8471                (not (eq gnus-fetch-old-headers 'invisible))
8472                (null gnus-summary-expunge-below)
8473                (not (eq gnus-build-sparse-threads 'some))
8474                (not (eq gnus-build-sparse-threads 'more))
8475                (null gnus-thread-expunge-below)
8476                (not gnus-use-nocem)))
8477       ()                                ; Do nothing.
8478     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8479     (setq gnus-newsgroup-limit nil)
8480     (mapatoms
8481      (lambda (node)
8482        (unless (car (symbol-value node))
8483          ;; These threads have no parents -- they are roots.
8484          (let ((nodes (cdr (symbol-value node)))
8485                thread)
8486            (while nodes
8487              (if (and gnus-thread-expunge-below
8488                       (< (gnus-thread-total-score (car nodes))
8489                          gnus-thread-expunge-below))
8490                  (gnus-expunge-thread (pop nodes))
8491                (setq thread (pop nodes))
8492                (gnus-summary-limit-children thread))))))
8493      gnus-newsgroup-dependencies)
8494     ;; If this limitation resulted in an empty group, we might
8495     ;; pop the previous limit and use it instead.
8496     (when (and (not gnus-newsgroup-limit)
8497                show-if-empty)
8498       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8499     gnus-newsgroup-limit))
8500
8501 (defun gnus-summary-limit-children (thread)
8502   "Return 1 if this subthread is visible and 0 if it is not."
8503   ;; First we get the number of visible children to this thread.  This
8504   ;; is done by recursing down the thread using this function, so this
8505   ;; will really go down to a leaf article first, before slowly
8506   ;; working its way up towards the root.
8507   (when thread
8508     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8509            (children
8510            (if (cdr thread)
8511                (apply '+ (mapcar 'gnus-summary-limit-children
8512                                  (cdr thread)))
8513              0))
8514           (number (mail-header-number (car thread)))
8515           score)
8516       (if (and
8517            (not (memq number gnus-newsgroup-marked))
8518            (or
8519             ;; If this article is dormant and has absolutely no visible
8520             ;; children, then this article isn't visible.
8521             (and (memq number gnus-newsgroup-dormant)
8522                  (zerop children))
8523             ;; If this is "fetch-old-headered" and there is no
8524             ;; visible children, then we don't want this article.
8525             (and (or (eq gnus-fetch-old-headers 'some)
8526                      (numberp gnus-fetch-old-headers))
8527                  (gnus-summary-article-ancient-p number)
8528                  (zerop children))
8529             ;; If this is "fetch-old-headered" and `invisible', then
8530             ;; we don't want this article.
8531             (and (eq gnus-fetch-old-headers 'invisible)
8532                  (gnus-summary-article-ancient-p number))
8533             ;; If this is a sparsely inserted article with no children,
8534             ;; we don't want it.
8535             (and (eq gnus-build-sparse-threads 'some)
8536                  (gnus-summary-article-sparse-p number)
8537                  (zerop children))
8538             ;; If we use expunging, and this article is really
8539             ;; low-scored, then we don't want this article.
8540             (when (and gnus-summary-expunge-below
8541                        (< (setq score
8542                                 (or (cdr (assq number gnus-newsgroup-scored))
8543                                     gnus-summary-default-score))
8544                           gnus-summary-expunge-below))
8545               ;; We increase the expunge-tally here, but that has
8546               ;; nothing to do with the limits, really.
8547               (incf gnus-newsgroup-expunged-tally)
8548               ;; We also mark as read here, if that's wanted.
8549               (when (and gnus-summary-mark-below
8550                          (< score gnus-summary-mark-below))
8551                 (setq gnus-newsgroup-unreads
8552                       (delq number gnus-newsgroup-unreads))
8553                 (if gnus-newsgroup-auto-expire
8554                     (push number gnus-newsgroup-expirable)
8555                   (push (cons number gnus-low-score-mark)
8556                         gnus-newsgroup-reads)))
8557               t)
8558             ;; Do the `display' group parameter.
8559             (and gnus-newsgroup-display
8560                  (not (funcall gnus-newsgroup-display)))
8561             ;; Check NoCeM things.
8562             (when (and gnus-use-nocem
8563                        (gnus-nocem-unwanted-article-p
8564                         (mail-header-id (car thread))))
8565               (setq gnus-newsgroup-unreads
8566                     (delq number gnus-newsgroup-unreads))
8567               t)))
8568           ;; Nope, invisible article.
8569           0
8570         ;; Ok, this article is to be visible, so we add it to the limit
8571         ;; and return 1.
8572         (push number gnus-newsgroup-limit)
8573         1))))
8574
8575 (defun gnus-expunge-thread (thread)
8576   "Mark all articles in THREAD as read."
8577   (let* ((number (mail-header-number (car thread))))
8578     (incf gnus-newsgroup-expunged-tally)
8579     ;; We also mark as read here, if that's wanted.
8580     (setq gnus-newsgroup-unreads
8581           (delq number gnus-newsgroup-unreads))
8582     (if gnus-newsgroup-auto-expire
8583         (push number gnus-newsgroup-expirable)
8584       (push (cons number gnus-low-score-mark)
8585             gnus-newsgroup-reads)))
8586   ;; Go recursively through all subthreads.
8587   (mapcar 'gnus-expunge-thread (cdr thread)))
8588
8589 ;; Summary article oriented commands
8590
8591 (defun gnus-summary-refer-parent-article (n)
8592   "Refer parent article N times.
8593 If N is negative, go to ancestor -N instead.
8594 The difference between N and the number of articles fetched is returned."
8595   (interactive "p")
8596   (let ((skip 1)
8597         error header ref)
8598     (when (not (natnump n))
8599       (setq skip (abs n)
8600             n 1))
8601     (while (and (> n 0)
8602                 (not error))
8603       (setq header (gnus-summary-article-header))
8604       (if (and (eq (mail-header-number header)
8605                    (cdr gnus-article-current))
8606                (equal gnus-newsgroup-name
8607                       (car gnus-article-current)))
8608           ;; If we try to find the parent of the currently
8609           ;; displayed article, then we take a look at the actual
8610           ;; References header, since this is slightly more
8611           ;; reliable than the References field we got from the
8612           ;; server.
8613           (save-excursion
8614             (set-buffer gnus-original-article-buffer)
8615             (nnheader-narrow-to-headers)
8616             (unless (setq ref (message-fetch-field "references"))
8617               (when (setq ref (message-fetch-field "in-reply-to"))
8618                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8619             (widen))
8620         (setq ref
8621               ;; It's not the current article, so we take a bet on
8622               ;; the value we got from the server.
8623               (mail-header-references header)))
8624       (if (and ref
8625                (not (equal ref "")))
8626           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8627             (gnus-message 1 "Couldn't find parent"))
8628         (gnus-message 1 "No references in article %d"
8629                       (gnus-summary-article-number))
8630         (setq error t))
8631       (decf n))
8632     (gnus-summary-position-point)
8633     n))
8634
8635 (defun gnus-summary-refer-references ()
8636   "Fetch all articles mentioned in the References header.
8637 Return the number of articles fetched."
8638   (interactive)
8639   (let ((ref (mail-header-references (gnus-summary-article-header)))
8640         (current (gnus-summary-article-number))
8641         (n 0))
8642     (if (or (not ref)
8643             (equal ref ""))
8644         (error "No References in the current article")
8645       ;; For each Message-ID in the References header...
8646       (while (string-match "<[^>]*>" ref)
8647         (incf n)
8648         ;; ... fetch that article.
8649         (gnus-summary-refer-article
8650          (prog1 (match-string 0 ref)
8651            (setq ref (substring ref (match-end 0))))))
8652       (gnus-summary-goto-subject current)
8653       (gnus-summary-position-point)
8654       n)))
8655
8656 (defun gnus-summary-refer-thread (&optional limit)
8657   "Fetch all articles in the current thread.
8658 If LIMIT (the numerical prefix), fetch that many old headers instead
8659 of what's specified by the `gnus-refer-thread-limit' variable."
8660   (interactive "P")
8661   (let ((id (mail-header-id (gnus-summary-article-header)))
8662         (limit (if limit (prefix-numeric-value limit)
8663                  gnus-refer-thread-limit)))
8664     (unless (eq gnus-fetch-old-headers 'invisible)
8665       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8666       ;; Retrieve the headers and read them in.
8667       (if (eq (if (numberp limit)
8668                   (gnus-retrieve-headers
8669                    (list (min
8670                           (+ (mail-header-number
8671                               (gnus-summary-article-header))
8672                              limit)
8673                           gnus-newsgroup-end))
8674                    gnus-newsgroup-name (* limit 2))
8675                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8676                 ;; headers.
8677                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8678                                        gnus-newsgroup-name limit))
8679               'nov)
8680           (gnus-build-all-threads)
8681         (error "Can't fetch thread from back ends that don't support NOV"))
8682       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8683     (gnus-summary-limit-include-thread id)))
8684
8685 (defun gnus-summary-refer-article (message-id)
8686   "Fetch an article specified by MESSAGE-ID."
8687   (interactive "sMessage-ID: ")
8688   (when (and (stringp message-id)
8689              (not (zerop (length message-id))))
8690     (setq message-id (gnus-replace-in-string message-id " " ""))
8691     ;; Construct the correct Message-ID if necessary.
8692     ;; Suggested by tale@pawl.rpi.edu.
8693     (unless (string-match "^<" message-id)
8694       (setq message-id (concat "<" message-id)))
8695     (unless (string-match ">$" message-id)
8696       (setq message-id (concat message-id ">")))
8697     ;; People often post MIDs from URLs, so unhex it:
8698     (unless (string-match "@" message-id)
8699       (setq message-id (gnus-url-unhex-string message-id)))
8700     (let* ((header (gnus-id-to-header message-id))
8701            (sparse (and header
8702                         (gnus-summary-article-sparse-p
8703                          (mail-header-number header))
8704                         (memq (mail-header-number header)
8705                               gnus-newsgroup-limit)))
8706            number)
8707       (cond
8708        ;; If the article is present in the buffer we just go to it.
8709        ((and header
8710              (or (not (gnus-summary-article-sparse-p
8711                        (mail-header-number header)))
8712                  sparse))
8713         (prog1
8714             (gnus-summary-goto-article
8715              (mail-header-number header) nil t)
8716           (when sparse
8717             (gnus-summary-update-article (mail-header-number header)))))
8718        (t
8719         ;; We fetch the article.
8720         (catch 'found
8721           (dolist (gnus-override-method (gnus-refer-article-methods))
8722             (when (and (gnus-check-server gnus-override-method)
8723                        ;; Fetch the header,
8724                        (setq number (gnus-summary-insert-subject message-id)))
8725               ;; and display the article.
8726               (gnus-summary-select-article nil nil nil number)
8727               (throw 'found t)))
8728           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8729
8730 (defun gnus-refer-article-methods ()
8731   "Return a list of referable methods."
8732   (cond
8733    ;; No method, so we default to current and native.
8734    ((null gnus-refer-article-method)
8735     (list gnus-current-select-method gnus-select-method))
8736    ;; Current.
8737    ((eq 'current gnus-refer-article-method)
8738     (list gnus-current-select-method))
8739    ;; List of select methods.
8740    ((not (and (symbolp (car gnus-refer-article-method))
8741               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8742     (let (out)
8743       (dolist (method gnus-refer-article-method)
8744         (push (if (eq 'current method)
8745                   gnus-current-select-method
8746                 method)
8747               out))
8748       (nreverse out)))
8749    ;; One single select method.
8750    (t
8751     (list gnus-refer-article-method))))
8752
8753 (defun gnus-summary-edit-parameters ()
8754   "Edit the group parameters of the current group."
8755   (interactive)
8756   (gnus-group-edit-group gnus-newsgroup-name 'params))
8757
8758 (defun gnus-summary-customize-parameters ()
8759   "Customize the group parameters of the current group."
8760   (interactive)
8761   (gnus-group-customize gnus-newsgroup-name))
8762
8763 (defun gnus-summary-enter-digest-group (&optional force)
8764   "Enter an nndoc group based on the current article.
8765 If FORCE, force a digest interpretation.  If not, try
8766 to guess what the document format is."
8767   (interactive "P")
8768   (let ((conf gnus-current-window-configuration))
8769     (save-window-excursion
8770       (save-excursion
8771         (let (gnus-article-prepare-hook
8772               gnus-display-mime-function
8773               gnus-break-pages)
8774           (gnus-summary-select-article))))
8775     (setq gnus-current-window-configuration conf)
8776     (let* ((name (format "%s-%d"
8777                          (gnus-group-prefixed-name
8778                           gnus-newsgroup-name (list 'nndoc ""))
8779                          (with-current-buffer gnus-summary-buffer
8780                            gnus-current-article)))
8781            (ogroup gnus-newsgroup-name)
8782            (params (append (gnus-info-params (gnus-get-info ogroup))
8783                            (list (cons 'to-group ogroup))
8784                            (list (cons 'parent-group ogroup))
8785                            (list (cons 'save-article-group ogroup))))
8786            (case-fold-search t)
8787            (buf (current-buffer))
8788            dig to-address)
8789       (save-excursion
8790         (set-buffer gnus-original-article-buffer)
8791         ;; Have the digest group inherit the main mail address of
8792         ;; the parent article.
8793         (when (setq to-address (or (gnus-fetch-field "reply-to")
8794                                    (gnus-fetch-field "from")))
8795           (setq params
8796                 (append
8797                  (list (cons 'to-address
8798                              (funcall gnus-decode-encoded-address-function
8799                                       to-address))))))
8800         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8801         (insert-buffer-substring gnus-original-article-buffer)
8802         ;; Remove lines that may lead nndoc to misinterpret the
8803         ;; document type.
8804         (narrow-to-region
8805          (goto-char (point-min))
8806          (or (search-forward "\n\n" nil t) (point)))
8807         (goto-char (point-min))
8808         (delete-matching-lines "^Path:\\|^From ")
8809         (widen))
8810       (unwind-protect
8811           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8812                     (gnus-newsgroup-ephemeral-ignored-charsets
8813                      gnus-newsgroup-ignored-charsets))
8814                 (gnus-group-read-ephemeral-group
8815                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8816                               (nndoc-article-type
8817                                ,(if force 'mbox 'guess)))
8818                  t nil nil nil
8819                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8820                                                         "ADAPT")))))
8821               ;; Make all postings to this group go to the parent group.
8822               (nconc (gnus-info-params (gnus-get-info name))
8823                      params)
8824             ;; Couldn't select this doc group.
8825             (switch-to-buffer buf)
8826             (gnus-set-global-variables)
8827             (gnus-configure-windows 'summary)
8828             (gnus-message 3 "Article couldn't be entered?"))
8829         (kill-buffer dig)))))
8830
8831 (defun gnus-summary-read-document (n)
8832   "Open a new group based on the current article(s).
8833 This will allow you to read digests and other similar
8834 documents as newsgroups.
8835 Obeys the standard process/prefix convention."
8836   (interactive "P")
8837   (let* ((ogroup gnus-newsgroup-name)
8838          (params (append (gnus-info-params (gnus-get-info ogroup))
8839                          (list (cons 'to-group ogroup))))
8840          group egroup groups vgroup)
8841     (dolist (article (gnus-summary-work-articles n))
8842       (setq group (format "%s-%d" gnus-newsgroup-name article))
8843       (gnus-summary-remove-process-mark article)
8844       (when (gnus-summary-display-article article)
8845         (save-excursion
8846           (with-temp-buffer
8847             (insert-buffer-substring gnus-original-article-buffer)
8848             ;; Remove some headers that may lead nndoc to make
8849             ;; the wrong guess.
8850             (message-narrow-to-head)
8851             (goto-char (point-min))
8852             (delete-matching-lines "^Path:\\|^From ")
8853             (widen)
8854             (if (setq egroup
8855                       (gnus-group-read-ephemeral-group
8856                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8857                                      (nndoc-article-type guess))
8858                        t nil t))
8859                 (progn
8860             ;; Make all postings to this group go to the parent group.
8861                   (nconc (gnus-info-params (gnus-get-info egroup))
8862                          params)
8863                   (push egroup groups))
8864               ;; Couldn't select this doc group.
8865               (gnus-error 3 "Article couldn't be entered"))))))
8866     ;; Now we have selected all the documents.
8867     (cond
8868      ((not groups)
8869       (error "None of the articles could be interpreted as documents"))
8870      ((gnus-group-read-ephemeral-group
8871        (setq vgroup (format
8872                      "nnvirtual:%s-%s" gnus-newsgroup-name
8873                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8874        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8875        t
8876        (cons (current-buffer) 'summary)))
8877      (t
8878       (error "Couldn't select virtual nndoc group")))))
8879
8880 (defun gnus-summary-isearch-article (&optional regexp-p)
8881   "Do incremental search forward on the current article.
8882 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8883   (interactive "P")
8884   (gnus-summary-select-article)
8885   (gnus-configure-windows 'article)
8886   (gnus-eval-in-buffer-window gnus-article-buffer
8887     (save-restriction
8888       (widen)
8889       (isearch-forward regexp-p))))
8890
8891 (defun gnus-summary-repeat-search-article-forward ()
8892   "Repeat the previous search forwards."
8893   (interactive)
8894   (unless gnus-last-search-regexp
8895     (error "No previous search"))
8896   (gnus-summary-search-article-forward gnus-last-search-regexp))
8897
8898 (defun gnus-summary-repeat-search-article-backward ()
8899   "Repeat the previous search backwards."
8900   (interactive)
8901   (unless gnus-last-search-regexp
8902     (error "No previous search"))
8903   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8904
8905 (defun gnus-summary-search-article-forward (regexp &optional backward)
8906   "Search for an article containing REGEXP forward.
8907 If BACKWARD, search backward instead."
8908   (interactive
8909    (list (read-string
8910           (format "Search article %s (regexp%s): "
8911                   (if current-prefix-arg "backward" "forward")
8912                   (if gnus-last-search-regexp
8913                       (concat ", default " gnus-last-search-regexp)
8914                     "")))
8915          current-prefix-arg))
8916   (if (string-equal regexp "")
8917       (setq regexp (or gnus-last-search-regexp ""))
8918     (setq gnus-last-search-regexp regexp)
8919     (setq gnus-article-before-search gnus-current-article))
8920   ;; Intentionally set gnus-last-article.
8921   (setq gnus-last-article gnus-article-before-search)
8922   (let ((gnus-last-article gnus-last-article))
8923     (if (gnus-summary-search-article regexp backward)
8924         (gnus-summary-show-thread)
8925       (signal 'search-failed (list regexp)))))
8926
8927 (defun gnus-summary-search-article-backward (regexp)
8928   "Search for an article containing REGEXP backward."
8929   (interactive
8930    (list (read-string
8931           (format "Search article backward (regexp%s): "
8932                   (if gnus-last-search-regexp
8933                       (concat ", default " gnus-last-search-regexp)
8934                     "")))))
8935   (gnus-summary-search-article-forward regexp 'backward))
8936
8937 (defun gnus-summary-search-article (regexp &optional backward)
8938   "Search for an article containing REGEXP.
8939 Optional argument BACKWARD means do search for backward.
8940 `gnus-select-article-hook' is not called during the search."
8941   ;; We have to require this here to make sure that the following
8942   ;; dynamic binding isn't shadowed by autoloading.
8943   (require 'gnus-async)
8944   (require 'gnus-art)
8945   (let ((gnus-select-article-hook nil)  ;Disable hook.
8946         (gnus-article-prepare-hook nil)
8947         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8948         (gnus-use-article-prefetch nil)
8949         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8950         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8951         (gnus-visual nil)
8952         (gnus-keep-backlog nil)
8953         (gnus-break-pages nil)
8954         (gnus-summary-display-arrow nil)
8955         (gnus-updated-mode-lines nil)
8956         (gnus-auto-center-summary nil)
8957         (sum (current-buffer))
8958         (gnus-display-mime-function nil)
8959         (found nil)
8960         point)
8961     (gnus-save-hidden-threads
8962       (gnus-summary-select-article)
8963       (set-buffer gnus-article-buffer)
8964       (goto-char (window-point (get-buffer-window (current-buffer))))
8965       (when backward
8966         (forward-line -1))
8967       (while (not found)
8968         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8969         (if (if backward
8970                 (re-search-backward regexp nil t)
8971               (re-search-forward regexp nil t))
8972             ;; We found the regexp.
8973             (progn
8974               (setq found 'found)
8975               (beginning-of-line)
8976               (set-window-start
8977                (get-buffer-window (current-buffer))
8978                (point))
8979               (forward-line 1)
8980               (set-window-point
8981                (get-buffer-window (current-buffer))
8982                (point))
8983               (set-buffer sum)
8984               (setq point (point)))
8985           ;; We didn't find it, so we go to the next article.
8986           (set-buffer sum)
8987           (setq found 'not)
8988           (while (eq found 'not)
8989             (if (not (if backward (gnus-summary-find-prev)
8990                        (gnus-summary-find-next)))
8991                 ;; No more articles.
8992                 (setq found t)
8993               ;; Select the next article and adjust point.
8994               (unless (gnus-summary-article-sparse-p
8995                        (gnus-summary-article-number))
8996                 (setq found nil)
8997                 (gnus-summary-select-article)
8998                 (set-buffer gnus-article-buffer)
8999                 (widen)
9000                 (goto-char (if backward (point-max) (point-min))))))))
9001       (gnus-message 7 ""))
9002     ;; Return whether we found the regexp.
9003     (when (eq found 'found)
9004       (goto-char point)
9005       (gnus-summary-show-thread)
9006       (gnus-summary-goto-subject gnus-current-article)
9007       (gnus-summary-position-point)
9008       t)))
9009
9010 (defun gnus-find-matching-articles (header regexp)
9011   "Return a list of all articles that match REGEXP on HEADER.
9012 This search includes all articles in the current group that Gnus has
9013 fetched headers for, whether they are displayed or not."
9014   (let ((articles nil)
9015         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9016         (case-fold-search t))
9017     (dolist (header gnus-newsgroup-headers)
9018       (when (string-match regexp (funcall func header))
9019         (push (mail-header-number header) articles)))
9020     (nreverse articles)))
9021
9022 (defun gnus-summary-find-matching (header regexp &optional backward unread
9023                                           not-case-fold not-matching)
9024   "Return a list of all articles that match REGEXP on HEADER.
9025 The search stars on the current article and goes forwards unless
9026 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9027 If UNREAD is non-nil, only unread articles will
9028 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9029 in the comparisons. If NOT-MATCHING, return a list of all articles that
9030 not match REGEXP on HEADER."
9031   (let ((case-fold-search (not not-case-fold))
9032         articles d func)
9033     (if (consp header)
9034         (if (eq (car header) 'extra)
9035             (setq func
9036                   `(lambda (h)
9037                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9038                          "")))
9039           (error "%s is an invalid header" header))
9040       (unless (fboundp (intern (concat "mail-header-" header)))
9041         (error "%s is not a valid header" header))
9042       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9043     (dolist (d (if (eq backward 'all)
9044                    gnus-newsgroup-data
9045                  (gnus-data-find-list
9046                   (gnus-summary-article-number)
9047                   (gnus-data-list backward))))
9048       (when (and (or (not unread)       ; We want all articles...
9049                      (gnus-data-unread-p d)) ; Or just unreads.
9050                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9051                  (if not-matching
9052                      (not (string-match
9053                            regexp
9054                            (funcall func (gnus-data-header d))))
9055                    (string-match regexp
9056                                  (funcall func (gnus-data-header d)))))
9057         (push (gnus-data-number d) articles))) ; Success!
9058     (nreverse articles)))
9059
9060 (defun gnus-summary-execute-command (header regexp command &optional backward)
9061   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9062 If HEADER is an empty string (or nil), the match is done on the entire
9063 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9064   (interactive
9065    (list (let ((completion-ignore-case t))
9066            (completing-read
9067             "Header name: "
9068             (mapcar (lambda (header) (list (format "%s" header)))
9069                     (append
9070                      '("Number" "Subject" "From" "Lines" "Date"
9071                        "Message-ID" "Xref" "References" "Body")
9072                      gnus-extra-headers))
9073             nil 'require-match))
9074          (read-string "Regexp: ")
9075          (read-key-sequence "Command: ")
9076          current-prefix-arg))
9077   (when (equal header "Body")
9078     (setq header ""))
9079   ;; Hidden thread subtrees must be searched as well.
9080   (gnus-summary-show-all-threads)
9081   ;; We don't want to change current point nor window configuration.
9082   (save-excursion
9083     (save-window-excursion
9084       (let (gnus-visual
9085             gnus-treat-strip-trailing-blank-lines
9086             gnus-treat-strip-leading-blank-lines
9087             gnus-treat-strip-multiple-blank-lines
9088             gnus-treat-hide-boring-headers
9089             gnus-treat-fold-newsgroups
9090             gnus-article-prepare-hook)
9091         (gnus-message 6 "Executing %s..." (key-description command))
9092         ;; We'd like to execute COMMAND interactively so as to give arguments.
9093         (gnus-execute header regexp
9094                       `(call-interactively ',(key-binding command))
9095                       backward)
9096         (gnus-message 6 "Executing %s...done" (key-description command))))))
9097
9098 (defun gnus-summary-beginning-of-article ()
9099   "Scroll the article back to the beginning."
9100   (interactive)
9101   (gnus-summary-select-article)
9102   (gnus-configure-windows 'article)
9103   (gnus-eval-in-buffer-window gnus-article-buffer
9104     (widen)
9105     (goto-char (point-min))
9106     (when gnus-break-pages
9107       (gnus-narrow-to-page))))
9108
9109 (defun gnus-summary-end-of-article ()
9110   "Scroll to the end of the article."
9111   (interactive)
9112   (gnus-summary-select-article)
9113   (gnus-configure-windows 'article)
9114   (gnus-eval-in-buffer-window gnus-article-buffer
9115     (widen)
9116     (goto-char (point-max))
9117     (recenter -3)
9118     (when gnus-break-pages
9119       (when (re-search-backward page-delimiter nil t)
9120         (narrow-to-region (match-end 0) (point-max)))
9121       (gnus-narrow-to-page))))
9122
9123 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9124   "Truncate to LEN and quote all \"(\"'s in STRING."
9125   (gnus-replace-in-string (if (and len (> (length string) len))
9126                               (substring string 0 len)
9127                             string)
9128                           "[()]" "\\\\\\&"))
9129
9130 (defun gnus-summary-print-article (&optional filename n)
9131   "Generate and print a PostScript image of the process-marked (mail) articles.
9132
9133 If used interactively, print the current article if none are
9134 process-marked.  With prefix arg, prompt the user for the name of the
9135 file to save in.
9136
9137 When used from Lisp, accept two optional args FILENAME and N.  N means
9138 to print the next N articles.  If N is negative, print the N previous
9139 articles.  If N is nil and articles have been marked with the process
9140 mark, print these instead.
9141
9142 If the optional first argument FILENAME is nil, send the image to the
9143 printer.  If FILENAME is a string, save the PostScript image in a file with
9144 that name.  If FILENAME is a number, prompt the user for the name of the file
9145 to save in."
9146   (interactive (list (ps-print-preprint current-prefix-arg)))
9147   (dolist (article (gnus-summary-work-articles n))
9148     (gnus-summary-select-article nil nil 'pseudo article)
9149     (gnus-eval-in-buffer-window gnus-article-buffer
9150       (gnus-print-buffer))
9151     (gnus-summary-remove-process-mark article))
9152   (ps-despool filename))
9153
9154 (defun gnus-print-buffer ()
9155   (let ((buffer (generate-new-buffer " *print*")))
9156     (unwind-protect
9157         (progn
9158           (copy-to-buffer buffer (point-min) (point-max))
9159           (set-buffer buffer)
9160           (gnus-remove-text-with-property 'gnus-decoration)
9161           (when (gnus-visual-p 'article-highlight 'highlight)
9162             ;; Copy-to-buffer doesn't copy overlay.  So redo
9163             ;; highlight.
9164             (let ((gnus-article-buffer buffer))
9165               (gnus-article-highlight-citation t)
9166               (gnus-article-highlight-signature)
9167               (gnus-article-emphasize)
9168               (gnus-article-delete-invisible-text)))
9169           (let ((ps-left-header
9170                  (list
9171                   (concat "("
9172                           (gnus-summary-print-truncate-and-quote
9173                            (mail-header-subject gnus-current-headers)
9174                            66) ")")
9175                   (concat "("
9176                           (gnus-summary-print-truncate-and-quote
9177                            (mail-header-from gnus-current-headers)
9178                            45) ")")))
9179                 (ps-right-header
9180                  (list
9181                   "/pagenumberstring load"
9182                   (concat "("
9183                           (mail-header-date gnus-current-headers) ")"))))
9184             (gnus-run-hooks 'gnus-ps-print-hook)
9185             (save-excursion
9186               (if window-system
9187                   (ps-spool-buffer-with-faces)
9188                 (ps-spool-buffer)))))
9189       (kill-buffer buffer))))
9190
9191 (defun gnus-summary-show-article (&optional arg)
9192   "Force redisplaying of the current article.
9193 If ARG (the prefix) is a number, show the article with the charset
9194 defined in `gnus-summary-show-article-charset-alist', or the charset
9195 input.
9196 If ARG (the prefix) is non-nil and not a number, show the raw article
9197 without any article massaging functions being run.  Normally, the key
9198 strokes are `C-u g'."
9199   (interactive "P")
9200   (cond
9201    ((numberp arg)
9202     (gnus-summary-show-article t)
9203     (let ((gnus-newsgroup-charset
9204            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9205                (mm-read-coding-system
9206                 "View as charset: " ;; actually it is coding system.
9207                 (with-current-buffer gnus-article-buffer
9208                   (mm-detect-coding-region (point) (point-max))))))
9209           (gnus-newsgroup-ignored-charsets 'gnus-all))
9210       (gnus-summary-select-article nil 'force)
9211       (let ((deps gnus-newsgroup-dependencies)
9212             head header lines)
9213         (save-excursion
9214           (set-buffer gnus-original-article-buffer)
9215           (save-restriction
9216             (message-narrow-to-head)
9217             (setq head (buffer-string))
9218             (goto-char (point-min))
9219             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9220               (goto-char (point-max))
9221               (widen)
9222               (setq lines (1- (count-lines (point) (point-max))))))
9223           (with-temp-buffer
9224             (insert (format "211 %d Article retrieved.\n"
9225                             (cdr gnus-article-current)))
9226             (insert head)
9227             (if lines (insert (format "Lines: %d\n" lines)))
9228             (insert ".\n")
9229             (let ((nntp-server-buffer (current-buffer)))
9230               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9231         (gnus-data-set-header
9232          (gnus-data-find (cdr gnus-article-current))
9233          header)
9234         (gnus-summary-update-article-line
9235          (cdr gnus-article-current) header)
9236         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9237           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9238    ((not arg)
9239     ;; Select the article the normal way.
9240     (gnus-summary-select-article nil 'force))
9241    (t
9242     ;; We have to require this here to make sure that the following
9243     ;; dynamic binding isn't shadowed by autoloading.
9244     (require 'gnus-async)
9245     (require 'gnus-art)
9246     ;; Bind the article treatment functions to nil.
9247     (let ((gnus-have-all-headers t)
9248           gnus-article-prepare-hook
9249           gnus-article-decode-hook
9250           gnus-display-mime-function
9251           gnus-break-pages)
9252       ;; Destroy any MIME parts.
9253       (when (gnus-buffer-live-p gnus-article-buffer)
9254         (save-excursion
9255           (set-buffer gnus-article-buffer)
9256           (mm-destroy-parts gnus-article-mime-handles)
9257           ;; Set it to nil for safety reason.
9258           (setq gnus-article-mime-handle-alist nil)
9259           (setq gnus-article-mime-handles nil)))
9260       (gnus-summary-select-article nil 'force))))
9261   (gnus-summary-goto-subject gnus-current-article)
9262   (gnus-summary-position-point))
9263
9264 (defun gnus-summary-show-raw-article ()
9265   "Show the raw article without any article massaging functions being run."
9266   (interactive)
9267   (gnus-summary-show-article t))
9268
9269 (defun gnus-summary-verbose-headers (&optional arg)
9270   "Toggle permanent full header display.
9271 If ARG is a positive number, turn header display on.
9272 If ARG is a negative number, turn header display off."
9273   (interactive "P")
9274   (setq gnus-show-all-headers
9275         (cond ((or (not (numberp arg))
9276                    (zerop arg))
9277                (not gnus-show-all-headers))
9278               ((natnump arg)
9279                t)))
9280   (gnus-summary-show-article))
9281
9282 (defun gnus-summary-toggle-header (&optional arg)
9283   "Show the headers if they are hidden, or hide them if they are shown.
9284 If ARG is a positive number, show the entire header.
9285 If ARG is a negative number, hide the unwanted header lines."
9286   (interactive "P")
9287   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9288                      (get-buffer-window gnus-article-buffer t))))
9289     (with-current-buffer gnus-article-buffer
9290       (widen)
9291       (article-narrow-to-head)
9292       (let* ((buffer-read-only nil)
9293              (inhibit-point-motion-hooks t)
9294              (hidden (if (numberp arg)
9295                          (>= arg 0)
9296                        (or (not (looking-at "[^ \t\n]+:"))
9297                            (gnus-article-hidden-text-p 'headers))))
9298              s e)
9299         (delete-region (point-min) (point-max))
9300         (with-current-buffer gnus-original-article-buffer
9301           (goto-char (setq s (point-min)))
9302           (setq e (if (search-forward "\n\n" nil t)
9303                       (1- (point))
9304                     (point-max))))
9305         (insert-buffer-substring gnus-original-article-buffer s e)
9306         (run-hooks 'gnus-article-decode-hook)
9307         (if hidden
9308             (let ((gnus-treat-hide-headers nil)
9309                   (gnus-treat-hide-boring-headers nil))
9310               (gnus-delete-wash-type 'headers)
9311               (gnus-treat-article 'head))
9312           (gnus-treat-article 'head))
9313         (widen)
9314         (if window
9315             (set-window-start window (goto-char (point-min))))
9316         (if gnus-break-pages
9317             (gnus-narrow-to-page)
9318           (when (gnus-visual-p 'page-marker)
9319             (let ((buffer-read-only nil))
9320               (gnus-remove-text-with-property 'gnus-prev)
9321               (gnus-remove-text-with-property 'gnus-next))))
9322         (gnus-set-mode-line 'article)))))
9323
9324 (defun gnus-summary-show-all-headers ()
9325   "Make all header lines visible."
9326   (interactive)
9327   (gnus-summary-toggle-header 1))
9328
9329 (defun gnus-summary-caesar-message (&optional arg)
9330   "Caesar rotate the current article by 13.
9331 With a non-numerical prefix, also rotate headers.  A numerical
9332 prefix specifies how many places to rotate each letter forward."
9333   (interactive "P")
9334   (gnus-summary-select-article)
9335   (let ((mail-header-separator ""))
9336     (gnus-eval-in-buffer-window gnus-article-buffer
9337       (save-restriction
9338         (widen)
9339         (let ((start (window-start))
9340               buffer-read-only)
9341           (if (equal arg '(4))
9342               (message-caesar-buffer-body nil t)
9343             (message-caesar-buffer-body arg))
9344           (set-window-start (get-buffer-window (current-buffer)) start)))))
9345   ;; Create buttons and stuff...
9346   (gnus-treat-article nil))
9347
9348 (defun gnus-summary-idna-message (&optional arg)
9349   "Decode IDNA encoded domain names in the current articles.
9350 IDNA encoded domain names looks like `xn--bar'.  If a string
9351 remain unencoded after running this function, it is likely an
9352 invalid IDNA string (`xn--bar' is invalid).
9353
9354 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9355 installed for this command to work."
9356   (interactive "P")
9357   (if (not (and (condition-case nil (require 'idna)
9358                   (file-error))
9359                 (mm-coding-system-p 'utf-8)
9360                 (executable-find (symbol-value 'idna-program))))
9361       (gnus-message
9362        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9363     (gnus-summary-select-article)
9364     (let ((mail-header-separator ""))
9365       (gnus-eval-in-buffer-window gnus-article-buffer
9366         (save-restriction
9367           (widen)
9368           (let ((start (window-start))
9369                 buffer-read-only)
9370             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9371               (replace-match (idna-to-unicode (match-string 1))))
9372             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9373
9374 (defun gnus-summary-morse-message (&optional arg)
9375   "Morse decode the current article."
9376   (interactive "P")
9377   (gnus-summary-select-article)
9378   (let ((mail-header-separator ""))
9379     (gnus-eval-in-buffer-window gnus-article-buffer
9380       (save-excursion
9381         (save-restriction
9382           (widen)
9383           (let ((pos (window-start))
9384                 buffer-read-only)
9385             (goto-char (point-min))
9386             (when (message-goto-body)
9387               (gnus-narrow-to-body))
9388             (goto-char (point-min))
9389             (while (search-forward "·" (point-max) t)
9390               (replace-match "."))
9391             (unmorse-region (point-min) (point-max))
9392             (widen)
9393             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9394
9395 (defun gnus-summary-stop-page-breaking ()
9396   "Stop page breaking in the current article."
9397   (interactive)
9398   (gnus-summary-select-article)
9399   (gnus-eval-in-buffer-window gnus-article-buffer
9400     (widen)
9401     (when (gnus-visual-p 'page-marker)
9402       (let ((buffer-read-only nil))
9403         (gnus-remove-text-with-property 'gnus-prev)
9404         (gnus-remove-text-with-property 'gnus-next))
9405       (setq gnus-page-broken nil))))
9406
9407 (defun gnus-summary-move-article (&optional n to-newsgroup
9408                                             select-method action)
9409   "Move the current article to a different newsgroup.
9410 If N is a positive number, move the N next articles.
9411 If N is a negative number, move the N previous articles.
9412 If N is nil and any articles have been marked with the process mark,
9413 move those articles instead.
9414 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9415 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9416 re-spool using this method.
9417
9418 When called interactively with TO-NEWSGROUP being nil, the value of
9419 the variable `gnus-move-split-methods' is used for finding a default
9420 for the target newsgroup.
9421
9422 For this function to work, both the current newsgroup and the
9423 newsgroup that you want to move to have to support the `request-move'
9424 and `request-accept' functions.
9425
9426 ACTION can be either `move' (the default), `crosspost' or `copy'."
9427   (interactive "P")
9428   (unless action
9429     (setq action 'move))
9430   ;; Check whether the source group supports the required functions.
9431   (cond ((and (eq action 'move)
9432               (not (gnus-check-backend-function
9433                     'request-move-article gnus-newsgroup-name)))
9434          (error "The current group does not support article moving"))
9435         ((and (eq action 'crosspost)
9436               (not (gnus-check-backend-function
9437                     'request-replace-article gnus-newsgroup-name)))
9438          (error "The current group does not support article editing")))
9439   (let ((articles (gnus-summary-work-articles n))
9440         (prefix (if (gnus-check-backend-function
9441                      'request-move-article gnus-newsgroup-name)
9442                     (funcall gnus-move-group-prefix-function
9443                              gnus-newsgroup-name)
9444                   ""))
9445         (names '((move "Move" "Moving")
9446                  (copy "Copy" "Copying")
9447                  (crosspost "Crosspost" "Crossposting")))
9448         (copy-buf (save-excursion
9449                     (nnheader-set-temp-buffer " *copy article*")))
9450         art-group to-method new-xref article to-groups articles-to-update-marks)
9451     (unless (assq action names)
9452       (error "Unknown action %s" action))
9453     ;; Read the newsgroup name.
9454     (when (and (not to-newsgroup)
9455                (not select-method))
9456       (if (and gnus-move-split-methods
9457                (not
9458                 (and (memq gnus-current-article articles)
9459                      (gnus-buffer-live-p gnus-original-article-buffer))))
9460           ;; When `gnus-move-split-methods' is non-nil, we have to
9461           ;; select an article to give `gnus-read-move-group-name' an
9462           ;; opportunity to suggest an appropriate default.  However,
9463           ;; we needn't render or mark the article.
9464           (let ((gnus-display-mime-function nil)
9465                 (gnus-article-prepare-hook nil)
9466                 (gnus-mark-article-hook nil))
9467             (gnus-summary-select-article nil nil nil (car articles))))
9468       (setq to-newsgroup
9469             (gnus-read-move-group-name
9470              (cadr (assq action names))
9471              (symbol-value (intern (format "gnus-current-%s-group" action)))
9472              articles prefix))
9473       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9474     (setq to-method (or select-method
9475                         (gnus-server-to-method
9476                          (gnus-group-method to-newsgroup))))
9477     ;; Check the method we are to move this article to...
9478     (unless (gnus-check-backend-function
9479              'request-accept-article (car to-method))
9480       (error "%s does not support article copying" (car to-method)))
9481     (unless (gnus-check-server to-method)
9482       (error "Can't open server %s" (car to-method)))
9483     (gnus-message 6 "%s to %s: %s..."
9484                   (caddr (assq action names))
9485                   (or (car select-method) to-newsgroup) articles)
9486     (while articles
9487       (setq article (pop articles))
9488       (setq
9489        art-group
9490        (cond
9491         ;; Move the article.
9492         ((eq action 'move)
9493          ;; Remove this article from future suppression.
9494          (gnus-dup-unsuppress-article article)
9495          (let* ((from-method (gnus-find-method-for-group
9496                               gnus-newsgroup-name))
9497                 (to-method (gnus-find-method-for-group
9498                             to-newsgroup))
9499                 (move-is-internal (gnus-method-equal from-method to-method)))
9500            (gnus-request-move-article
9501             article                     ; Article to move
9502             gnus-newsgroup-name         ; From newsgroup
9503             (nth 1 (gnus-find-method-for-group
9504                     gnus-newsgroup-name)) ; Server
9505             (list 'gnus-request-accept-article
9506                   to-newsgroup (list 'quote select-method)
9507                   (not articles) t)     ; Accept form
9508             (not articles)              ; Only save nov last time
9509             move-is-internal)))         ; is this move internal?
9510         ;; Copy the article.
9511         ((eq action 'copy)
9512          (save-excursion
9513            (set-buffer copy-buf)
9514            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9515              (save-restriction
9516                (nnheader-narrow-to-headers)
9517                (dolist (hdr gnus-copy-article-ignored-headers)
9518                  (message-remove-header hdr t)))
9519              (gnus-request-accept-article
9520               to-newsgroup select-method (not articles) t))))
9521         ;; Crosspost the article.
9522         ((eq action 'crosspost)
9523          (let ((xref (message-tokenize-header
9524                       (mail-header-xref (gnus-summary-article-header article))
9525                       " ")))
9526            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9527                                   ":" (number-to-string article)))
9528            (unless xref
9529              (setq xref (list (system-name))))
9530            (setq new-xref
9531                  (concat
9532                   (mapconcat 'identity
9533                              (delete "Xref:" (delete new-xref xref))
9534                              " ")
9535                   " " new-xref))
9536            (save-excursion
9537              (set-buffer copy-buf)
9538              ;; First put the article in the destination group.
9539              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9540              (when (consp (setq art-group
9541                                 (gnus-request-accept-article
9542                                  to-newsgroup select-method (not articles) t)))
9543                (setq new-xref (concat new-xref " " (car art-group)
9544                                       ":"
9545                                       (number-to-string (cdr art-group))))
9546                ;; Now we have the new Xrefs header, so we insert
9547                ;; it and replace the new article.
9548                (nnheader-replace-header "Xref" new-xref)
9549                (gnus-request-replace-article
9550                 (cdr art-group) to-newsgroup (current-buffer) t)
9551                art-group))))))
9552       (cond
9553        ((not art-group)
9554         (gnus-message 1 "Couldn't %s article %s: %s"
9555                       (cadr (assq action names)) article
9556                       (nnheader-get-report (car to-method))))
9557        ((eq art-group 'junk)
9558         (when (eq action 'move)
9559           (gnus-summary-mark-article article gnus-canceled-mark)
9560           (gnus-message 4 "Deleted article %s" article)
9561           ;; run the delete hook
9562           (run-hook-with-args 'gnus-summary-article-delete-hook
9563                               action
9564                               (gnus-data-header
9565                                (assoc article (gnus-data-list nil)))
9566                               gnus-newsgroup-name nil
9567                               select-method)))
9568        (t
9569         (let* ((pto-group (gnus-group-prefixed-name
9570                            (car art-group) to-method))
9571                (info (gnus-get-info pto-group))
9572                (to-group (gnus-info-group info))
9573                to-marks)
9574           ;; Update the group that has been moved to.
9575           (when (and info
9576                      (memq action '(move copy)))
9577             (unless (member to-group to-groups)
9578               (push to-group to-groups))
9579
9580             (unless (memq article gnus-newsgroup-unreads)
9581               (push 'read to-marks)
9582               (gnus-info-set-read
9583                info (gnus-add-to-range (gnus-info-read info)
9584                                        (list (cdr art-group)))))
9585
9586             ;; See whether the article is to be put in the cache.
9587             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9588                              gnus-article-mark-lists
9589                            (delete '(expirable . expire)
9590                                    (copy-sequence gnus-article-mark-lists))))
9591                   (to-article (cdr art-group)))
9592
9593               ;; Enter the article into the cache in the new group,
9594               ;; if that is required.
9595               (when gnus-use-cache
9596                 (gnus-cache-possibly-enter-article
9597                  to-group to-article
9598                  (memq article gnus-newsgroup-marked)
9599                  (memq article gnus-newsgroup-dormant)
9600                  (memq article gnus-newsgroup-unreads)))
9601
9602               (when gnus-preserve-marks
9603                 ;; Copy any marks over to the new group.
9604                 (when (and (equal to-group gnus-newsgroup-name)
9605                            (not (memq article gnus-newsgroup-unreads)))
9606                   ;; Mark this article as read in this group.
9607                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9608                   (setcdr (gnus-active to-group) to-article)
9609                   (setcdr gnus-newsgroup-active to-article))
9610
9611                 (while marks
9612                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9613                     (when (memq article (symbol-value
9614                                          (intern (format "gnus-newsgroup-%s"
9615                                                          (caar marks)))))
9616                       (push (cdar marks) to-marks)
9617                       ;; If the other group is the same as this group,
9618                       ;; then we have to add the mark to the list.
9619                       (when (equal to-group gnus-newsgroup-name)
9620                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9621                              (cons to-article
9622                                    (symbol-value
9623                                     (intern (format "gnus-newsgroup-%s"
9624                                                     (caar marks)))))))
9625                       ;; Copy the marks to other group.
9626                       (gnus-add-marked-articles
9627                        to-group (cdar marks) (list to-article) info)))
9628                   (setq marks (cdr marks)))
9629
9630                 (gnus-request-set-mark
9631                  to-group (list (list (list to-article) 'add to-marks))))
9632
9633               (gnus-dribble-enter
9634                (concat "(gnus-group-set-info '"
9635                        (gnus-prin1-to-string (gnus-get-info to-group))
9636                        ")"))))
9637
9638           ;; Update the Xref header in this article to point to
9639           ;; the new crossposted article we have just created.
9640           (when (eq action 'crosspost)
9641             (save-excursion
9642               (set-buffer copy-buf)
9643               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9644               (nnheader-replace-header "Xref" new-xref)
9645               (gnus-request-replace-article
9646                article gnus-newsgroup-name (current-buffer) t)))
9647
9648           ;; run the move/copy/crosspost/respool hook
9649           (run-hook-with-args 'gnus-summary-article-move-hook
9650                               action
9651                               (gnus-data-header
9652                                (assoc article (gnus-data-list nil)))
9653                               gnus-newsgroup-name
9654                               to-newsgroup
9655                               select-method))
9656
9657         ;;;!!!Why is this necessary?
9658         (set-buffer gnus-summary-buffer)
9659
9660         (gnus-summary-goto-subject article)
9661         (when (eq action 'move)
9662           (gnus-summary-mark-article article gnus-canceled-mark))))
9663       (push article articles-to-update-marks))
9664
9665     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9666     ;; Re-activate all groups that have been moved to.
9667     (save-excursion
9668       (set-buffer gnus-group-buffer)
9669       (let ((gnus-group-marked to-groups))
9670         (gnus-group-get-new-news-this-group nil t)))
9671
9672     (gnus-kill-buffer copy-buf)
9673     (gnus-summary-position-point)
9674     (gnus-set-mode-line 'summary)))
9675
9676 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9677   "Copy the current article to some other group.
9678 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9679 When called interactively, if TO-NEWSGROUP is nil, use the value of
9680 the variable `gnus-move-split-methods' for finding a default target
9681 newsgroup.
9682 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9683 re-spool using this method."
9684   (interactive "P")
9685   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9686
9687 (defun gnus-summary-crosspost-article (&optional n)
9688   "Crosspost the current article to some other group."
9689   (interactive "P")
9690   (gnus-summary-move-article n nil nil 'crosspost))
9691
9692 (defcustom gnus-summary-respool-default-method nil
9693   "Default method type for respooling an article.
9694 If nil, use to the current newsgroup method."
9695   :type 'symbol
9696   :group 'gnus-summary-mail)
9697
9698 (defcustom gnus-summary-display-while-building nil
9699   "If non-nil, show and update the summary buffer as it's being built.
9700 If the value is t, update the buffer after every line is inserted.  If
9701 the value is an integer (N), update the display every N lines."
9702   :version "22.1"
9703   :group 'gnus-thread
9704   :type '(choice (const :tag "off" nil)
9705                  number
9706                  (const :tag "frequently" t)))
9707
9708 (defun gnus-summary-respool-article (&optional n method)
9709   "Respool the current article.
9710 The article will be squeezed through the mail spooling process again,
9711 which means that it will be put in some mail newsgroup or other
9712 depending on `nnmail-split-methods'.
9713 If N is a positive number, respool the N next articles.
9714 If N is a negative number, respool the N previous articles.
9715 If N is nil and any articles have been marked with the process mark,
9716 respool those articles instead.
9717
9718 Respooling can be done both from mail groups and \"real\" newsgroups.
9719 In the former case, the articles in question will be moved from the
9720 current group into whatever groups they are destined to.  In the
9721 latter case, they will be copied into the relevant groups."
9722   (interactive
9723    (list current-prefix-arg
9724          (let* ((methods (gnus-methods-using 'respool))
9725                 (methname
9726                  (symbol-name (or gnus-summary-respool-default-method
9727                                   (car (gnus-find-method-for-group
9728                                         gnus-newsgroup-name)))))
9729                 (method
9730                  (gnus-completing-read-with-default
9731                   methname "Backend to use when respooling"
9732                   methods nil t nil 'gnus-mail-method-history))
9733                 ms)
9734            (cond
9735             ((zerop (length (setq ms (gnus-servers-using-backend
9736                                       (intern method)))))
9737              (list (intern method) ""))
9738             ((= 1 (length ms))
9739              (car ms))
9740             (t
9741              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9742                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9743                            ms-alist))))))))
9744   (unless method
9745     (error "No method given for respooling"))
9746   (if (assoc (symbol-name
9747               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9748              (gnus-methods-using 'respool))
9749       (gnus-summary-move-article n nil method)
9750     (gnus-summary-copy-article n nil method)))
9751
9752 (defun gnus-summary-import-article (file &optional edit)
9753   "Import an arbitrary file into a mail newsgroup."
9754   (interactive "fImport file: \nP")
9755   (let ((group gnus-newsgroup-name)
9756         (now (current-time))
9757         atts lines group-art)
9758     (unless (gnus-check-backend-function 'request-accept-article group)
9759       (error "%s does not support article importing" group))
9760     (or (file-readable-p file)
9761         (not (file-regular-p file))
9762         (error "Can't read %s" file))
9763     (save-excursion
9764       (set-buffer (gnus-get-buffer-create " *import file*"))
9765       (erase-buffer)
9766       (nnheader-insert-file-contents file)
9767       (goto-char (point-min))
9768       (if (nnheader-article-p)
9769           (save-restriction
9770             (goto-char (point-min))
9771             (search-forward "\n\n" nil t)
9772             (narrow-to-region (point-min) (1- (point)))
9773             (goto-char (point-min))
9774             (unless (re-search-forward "^date:" nil t)
9775               (goto-char (point-max))
9776               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9777        ;; This doesn't look like an article, so we fudge some headers.
9778         (setq atts (file-attributes file)
9779               lines (count-lines (point-min) (point-max)))
9780         (insert "From: " (read-string "From: ") "\n"
9781                 "Subject: " (read-string "Subject: ") "\n"
9782                 "Date: " (message-make-date (nth 5 atts)) "\n"
9783                 "Message-ID: " (message-make-message-id) "\n"
9784                 "Lines: " (int-to-string lines) "\n"
9785                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9786       (setq group-art (gnus-request-accept-article group nil t))
9787       (kill-buffer (current-buffer)))
9788     (setq gnus-newsgroup-active (gnus-activate-group group))
9789     (forward-line 1)
9790     (gnus-summary-goto-article (cdr group-art) nil t)
9791     (when edit
9792       (gnus-summary-edit-article))))
9793
9794 (defun gnus-summary-create-article ()
9795   "Create an article in a mail newsgroup."
9796   (interactive)
9797   (let ((group gnus-newsgroup-name)
9798         (now (current-time))
9799         group-art)
9800     (unless (gnus-check-backend-function 'request-accept-article group)
9801       (error "%s does not support article importing" group))
9802     (save-excursion
9803       (set-buffer (gnus-get-buffer-create " *import file*"))
9804       (erase-buffer)
9805       (goto-char (point-min))
9806       ;; This doesn't look like an article, so we fudge some headers.
9807       (insert "From: " (read-string "From: ") "\n"
9808               "Subject: " (read-string "Subject: ") "\n"
9809               "Date: " (message-make-date now) "\n"
9810               "Message-ID: " (message-make-message-id) "\n")
9811       (setq group-art (gnus-request-accept-article group nil t))
9812       (kill-buffer (current-buffer)))
9813     (setq gnus-newsgroup-active (gnus-activate-group group))
9814     (forward-line 1)
9815     (gnus-summary-goto-article (cdr group-art) nil t)
9816     (gnus-summary-edit-article)))
9817
9818 (defun gnus-summary-article-posted-p ()
9819   "Say whether the current (mail) article is available from news as well.
9820 This will be the case if the article has both been mailed and posted."
9821   (interactive)
9822   (let ((id (mail-header-references (gnus-summary-article-header)))
9823         (gnus-override-method (car (gnus-refer-article-methods))))
9824     (if (gnus-request-head id "")
9825         (gnus-message 2 "The current message was found on %s"
9826                       gnus-override-method)
9827       (gnus-message 2 "The current message couldn't be found on %s"
9828                     gnus-override-method)
9829       nil)))
9830
9831 (defun gnus-summary-expire-articles (&optional now)
9832   "Expire all articles that are marked as expirable in the current group."
9833   (interactive)
9834   (when (and (not gnus-group-is-exiting-without-update-p)
9835              (gnus-check-backend-function
9836               'request-expire-articles gnus-newsgroup-name))
9837     ;; This backend supports expiry.
9838     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9839            (expirable (if total
9840                           (progn
9841                             ;; We need to update the info for
9842                             ;; this group for `gnus-list-of-read-articles'
9843                             ;; to give us the right answer.
9844                             (gnus-run-hooks 'gnus-exit-group-hook)
9845                             (gnus-summary-update-info)
9846                             (gnus-list-of-read-articles gnus-newsgroup-name))
9847                         (setq gnus-newsgroup-expirable
9848                               (sort gnus-newsgroup-expirable '<))))
9849            (expiry-wait (if now 'immediate
9850                           (gnus-group-find-parameter
9851                            gnus-newsgroup-name 'expiry-wait)))
9852            (nnmail-expiry-target
9853             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9854                 nnmail-expiry-target))
9855            es)
9856       (when expirable
9857         ;; There are expirable articles in this group, so we run them
9858         ;; through the expiry process.
9859         (gnus-message 6 "Expiring articles...")
9860         (unless (gnus-check-group gnus-newsgroup-name)
9861           (error "Can't open server for %s" gnus-newsgroup-name))
9862         ;; The list of articles that weren't expired is returned.
9863         (save-excursion
9864           (if expiry-wait
9865               (let ((nnmail-expiry-wait-function nil)
9866                     (nnmail-expiry-wait expiry-wait))
9867                 (setq es (gnus-request-expire-articles
9868                           expirable gnus-newsgroup-name)))
9869             (setq es (gnus-request-expire-articles
9870                       expirable gnus-newsgroup-name)))
9871           (unless total
9872             (setq gnus-newsgroup-expirable es))
9873           ;; We go through the old list of expirable, and mark all
9874           ;; really expired articles as nonexistent.
9875           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9876             (let ((gnus-use-cache nil))
9877               (dolist (article expirable)
9878                 (when (and (not (memq article es))
9879                            (gnus-data-find article))
9880                   (gnus-summary-mark-article article gnus-canceled-mark)
9881                   (run-hook-with-args 'gnus-summary-article-expire-hook
9882                                       'delete
9883                                       (gnus-data-header
9884                                        (assoc article (gnus-data-list nil)))
9885                                       gnus-newsgroup-name
9886                                       nil
9887                                       nil))))))
9888         (gnus-message 6 "Expiring articles...done")))))
9889
9890 (defun gnus-summary-expire-articles-now ()
9891   "Expunge all expirable articles in the current group.
9892 This means that *all* articles that are marked as expirable will be
9893 deleted forever, right now."
9894   (interactive)
9895   (or gnus-expert-user
9896       (gnus-yes-or-no-p
9897        "Are you really, really sure you want to delete all expirable messages? ")
9898       (error "Phew!"))
9899   (gnus-summary-expire-articles t))
9900
9901 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9902 (defun gnus-summary-delete-article (&optional n)
9903   "Delete the N next (mail) articles.
9904 This command actually deletes articles.  This is not a marking
9905 command.  The article will disappear forever from your life, never to
9906 return.
9907
9908 If N is negative, delete backwards.
9909 If N is nil and articles have been marked with the process mark,
9910 delete these instead.
9911
9912 If `gnus-novice-user' is non-nil you will be asked for
9913 confirmation before the articles are deleted."
9914   (interactive "P")
9915   (unless (gnus-check-backend-function 'request-expire-articles
9916                                        gnus-newsgroup-name)
9917     (error "The current newsgroup does not support article deletion"))
9918   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9919     (error "Couldn't open server"))
9920   ;; Compute the list of articles to delete.
9921   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9922         (nnmail-expiry-target 'delete)
9923         not-deleted)
9924     (if (and gnus-novice-user
9925              (not (gnus-yes-or-no-p
9926                    (format "Do you really want to delete %s forever? "
9927                            (if (> (length articles) 1)
9928                                (format "these %s articles" (length articles))
9929                              "this article")))))
9930         ()
9931       ;; Delete the articles.
9932       (setq not-deleted (gnus-request-expire-articles
9933                          articles gnus-newsgroup-name 'force))
9934       (while articles
9935         (gnus-summary-remove-process-mark (car articles))
9936         ;; The backend might not have been able to delete the article
9937         ;; after all.
9938         (unless (memq (car articles) not-deleted)
9939           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9940         (let* ((article (car articles))
9941                (ghead  (gnus-data-header
9942                                     (assoc article (gnus-data-list nil)))))
9943           (run-hook-with-args 'gnus-summary-article-delete-hook
9944                               'delete ghead gnus-newsgroup-name nil
9945                               nil))
9946         (setq articles (cdr articles)))
9947       (when not-deleted
9948         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9949     (gnus-summary-position-point)
9950     (gnus-set-mode-line 'summary)
9951     not-deleted))
9952
9953 (defun gnus-summary-edit-article (&optional arg)
9954   "Edit the current article.
9955 This will have permanent effect only in mail groups.
9956 If ARG is nil, edit the decoded articles.
9957 If ARG is 1, edit the raw articles.
9958 If ARG is 2, edit the raw articles even in read-only groups.
9959 If ARG is 3, edit the articles with the current handles.
9960 Otherwise, allow editing of articles even in read-only
9961 groups."
9962   (interactive "P")
9963   (let (force raw current-handles)
9964     (cond
9965      ((null arg))
9966      ((eq arg 1)
9967       (setq raw t))
9968      ((eq arg 2)
9969       (setq raw t
9970             force t))
9971      ((eq arg 3)
9972       (setq current-handles
9973             (and (gnus-buffer-live-p gnus-article-buffer)
9974                  (with-current-buffer gnus-article-buffer
9975                    (prog1
9976                        gnus-article-mime-handles
9977                      (setq gnus-article-mime-handles nil))))))
9978      (t
9979       (setq force t)))
9980     (when (and raw (not force)
9981                (member gnus-newsgroup-name '("nndraft:delayed"
9982                                              "nndraft:drafts"
9983                                              "nndraft:queue")))
9984       (error "Can't edit the raw article in group %s"
9985              gnus-newsgroup-name))
9986     (save-excursion
9987       (set-buffer gnus-summary-buffer)
9988       (let ((mail-parse-charset gnus-newsgroup-charset)
9989             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9990         (gnus-set-global-variables)
9991         (when (and (not force)
9992                    (gnus-group-read-only-p))
9993           (error "The current newsgroup does not support article editing"))
9994         (gnus-summary-show-article t)
9995         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9996           (with-current-buffer gnus-article-buffer
9997             (mm-enable-multibyte)))
9998         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9999             (setq raw t))
10000         (gnus-article-edit-article
10001          (if raw 'ignore
10002            `(lambda ()
10003               (let ((mbl mml-buffer-list))
10004                 (setq mml-buffer-list nil)
10005                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10006                   (mime-to-mml ,'current-handles))
10007                 (let ((mbl1 mml-buffer-list))
10008                   (setq mml-buffer-list mbl)
10009                   (set (make-local-variable 'mml-buffer-list) mbl1))
10010                 (gnus-make-local-hook 'kill-buffer-hook)
10011                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10012          `(lambda (no-highlight)
10013             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10014                   (message-options message-options)
10015                   (message-options-set-recipient)
10016                   (mail-parse-ignored-charsets
10017                    ',gnus-newsgroup-ignored-charsets))
10018               ,(if (not raw) '(progn
10019                                 (mml-to-mime)
10020                                 (mml-destroy-buffers)
10021                                 (remove-hook 'kill-buffer-hook
10022                                              'mml-destroy-buffers t)
10023                                 (kill-local-variable 'mml-buffer-list)))
10024               (gnus-summary-edit-article-done
10025                ,(or (mail-header-references gnus-current-headers) "")
10026                ,(gnus-group-read-only-p)
10027                ,gnus-summary-buffer no-highlight))))))))
10028
10029 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10030
10031 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10032                                                  no-highlight)
10033   "Make edits to the current article permanent."
10034   (interactive)
10035   (save-excursion
10036    ;; The buffer restriction contains the entire article if it exists.
10037     (when (article-goto-body)
10038       (let ((lines (count-lines (point) (point-max)))
10039             (length (- (point-max) (point)))
10040             (case-fold-search t)
10041             (body (copy-marker (point))))
10042         (goto-char (point-min))
10043         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10044           (delete-region (match-beginning 1) (match-end 1))
10045           (insert (number-to-string length)))
10046         (goto-char (point-min))
10047         (when (re-search-forward
10048                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10049           (delete-region (match-beginning 1) (match-end 1))
10050           (insert (number-to-string length)))
10051         (goto-char (point-min))
10052         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10053           (delete-region (match-beginning 1) (match-end 1))
10054           (insert (number-to-string lines))))))
10055   ;; Replace the article.
10056   (let ((buf (current-buffer)))
10057     (with-temp-buffer
10058       (insert-buffer-substring buf)
10059
10060       (if (and (not read-only)
10061                (not (gnus-request-replace-article
10062                      (cdr gnus-article-current) (car gnus-article-current)
10063                      (current-buffer) t)))
10064           (error "Couldn't replace article")
10065         ;; Update the summary buffer.
10066         (if (and references
10067                  (equal (message-tokenize-header references " ")
10068                         (message-tokenize-header
10069                          (or (message-fetch-field "references") "") " ")))
10070             ;; We only have to update this line.
10071             (save-excursion
10072               (save-restriction
10073                 (message-narrow-to-head)
10074                 (let ((head (buffer-substring-no-properties
10075                              (point-min) (point-max)))
10076                       header)
10077                   (with-temp-buffer
10078                     (insert (format "211 %d Article retrieved.\n"
10079                                     (cdr gnus-article-current)))
10080                     (insert head)
10081                     (insert ".\n")
10082                     (let ((nntp-server-buffer (current-buffer)))
10083                       (setq header (car (gnus-get-newsgroup-headers
10084                                          nil t))))
10085                     (save-excursion
10086                       (set-buffer gnus-summary-buffer)
10087                       (gnus-data-set-header
10088                        (gnus-data-find (cdr gnus-article-current))
10089                        header)
10090                       (gnus-summary-update-article-line
10091                        (cdr gnus-article-current) header)
10092                       (if (gnus-summary-goto-subject
10093                            (cdr gnus-article-current) nil t)
10094                           (gnus-summary-update-secondary-mark
10095                            (cdr gnus-article-current))))))))
10096           ;; Update threads.
10097           (set-buffer (or buffer gnus-summary-buffer))
10098           (gnus-summary-update-article (cdr gnus-article-current))
10099           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10100               (gnus-summary-update-secondary-mark
10101                (cdr gnus-article-current))))
10102         ;; Prettify the article buffer again.
10103         (unless no-highlight
10104           (save-excursion
10105             (set-buffer gnus-article-buffer)
10106             ;;;!!! Fix this -- article should be rehighlighted.
10107             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10108             (set-buffer gnus-original-article-buffer)
10109             (gnus-request-article
10110              (cdr gnus-article-current)
10111              (car gnus-article-current) (current-buffer))))
10112         ;; Prettify the summary buffer line.
10113         (when (gnus-visual-p 'summary-highlight 'highlight)
10114           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10115
10116 (defun gnus-summary-edit-wash (key)
10117   "Perform editing command KEY in the article buffer."
10118   (interactive
10119    (list
10120     (progn
10121       (message "%s" (concat (this-command-keys) "- "))
10122       (read-char))))
10123   (message "")
10124   (gnus-summary-edit-article)
10125   (execute-kbd-macro (concat (this-command-keys) key))
10126   (gnus-article-edit-done))
10127
10128 ;;; Respooling
10129
10130 (defun gnus-summary-respool-query (&optional silent trace)
10131   "Query where the respool algorithm would put this article."
10132   (interactive)
10133   (let (gnus-mark-article-hook)
10134     (gnus-summary-select-article)
10135     (save-excursion
10136       (set-buffer gnus-original-article-buffer)
10137       (let ((groups (nnmail-article-group 'identity trace)))
10138         (unless silent
10139           (if groups
10140               (message "This message would go to %s"
10141                        (mapconcat 'car groups ", "))
10142             (message "This message would go to no groups"))
10143           groups)))))
10144
10145 (defun gnus-summary-respool-trace ()
10146   "Trace where the respool algorithm would put this article.
10147 Display a buffer showing all fancy splitting patterns which matched."
10148   (interactive)
10149   (gnus-summary-respool-query nil t))
10150
10151 ;; Summary marking commands.
10152
10153 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10154   "Mark articles which has the same subject as read, and then select the next.
10155 If UNMARK is positive, remove any kind of mark.
10156 If UNMARK is negative, tick articles."
10157   (interactive "P")
10158   (when unmark
10159     (setq unmark (prefix-numeric-value unmark)))
10160   (let ((count
10161          (gnus-summary-mark-same-subject
10162           (gnus-summary-article-subject) unmark)))
10163     ;; Select next unread article.  If auto-select-same mode, should
10164     ;; select the first unread article.
10165     (gnus-summary-next-article t (and gnus-auto-select-same
10166                                       (gnus-summary-article-subject)))
10167     (gnus-message 7 "%d article%s marked as %s"
10168                   count (if (= count 1) " is" "s are")
10169                   (if unmark "unread" "read"))))
10170
10171 (defun gnus-summary-kill-same-subject (&optional unmark)
10172   "Mark articles which has the same subject as read.
10173 If UNMARK is positive, remove any kind of mark.
10174 If UNMARK is negative, tick articles."
10175   (interactive "P")
10176   (when unmark
10177     (setq unmark (prefix-numeric-value unmark)))
10178   (let ((count
10179          (gnus-summary-mark-same-subject
10180           (gnus-summary-article-subject) unmark)))
10181     ;; If marked as read, go to next unread subject.
10182     (when (null unmark)
10183       ;; Go to next unread subject.
10184       (gnus-summary-next-subject 1 t))
10185     (gnus-message 7 "%d articles are marked as %s"
10186                   count (if unmark "unread" "read"))))
10187
10188 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10189   "Mark articles with same SUBJECT as read, and return marked number.
10190 If optional argument UNMARK is positive, remove any kinds of marks.
10191 If optional argument UNMARK is negative, mark articles as unread instead."
10192   (let ((count 1))
10193     (save-excursion
10194       (cond
10195        ((null unmark)                   ; Mark as read.
10196         (while (and
10197                 (progn
10198                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10199                   (gnus-summary-show-thread) t)
10200                 (gnus-summary-find-subject subject))
10201           (setq count (1+ count))))
10202        ((> unmark 0)                    ; Tick.
10203         (while (and
10204                 (progn
10205                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10206                   (gnus-summary-show-thread) t)
10207                 (gnus-summary-find-subject subject))
10208           (setq count (1+ count))))
10209        (t                               ; Mark as unread.
10210         (while (and
10211                 (progn
10212                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10213                   (gnus-summary-show-thread) t)
10214                 (gnus-summary-find-subject subject))
10215           (setq count (1+ count)))))
10216       (gnus-set-mode-line 'summary)
10217       ;; Return the number of marked articles.
10218       count)))
10219
10220 (defun gnus-summary-mark-as-processable (n &optional unmark)
10221   "Set the process mark on the next N articles.
10222 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10223 the process mark instead.  The difference between N and the actual
10224 number of articles marked is returned."
10225   (interactive "P")
10226   (if (and (null n) (gnus-region-active-p))
10227       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10228     (setq n (prefix-numeric-value n))
10229     (let ((backward (< n 0))
10230           (n (abs n)))
10231       (while (and
10232               (> n 0)
10233               (if unmark
10234                   (gnus-summary-remove-process-mark
10235                    (gnus-summary-article-number))
10236                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10237               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10238         (setq n (1- n)))
10239       (when (/= 0 n)
10240         (gnus-message 7 "No more articles"))
10241       (gnus-summary-recenter)
10242       (gnus-summary-position-point)
10243       n)))
10244
10245 (defun gnus-summary-unmark-as-processable (n)
10246   "Remove the process mark from the next N articles.
10247 If N is negative, unmark backward instead.  The difference between N and
10248 the actual number of articles unmarked is returned."
10249   (interactive "P")
10250   (gnus-summary-mark-as-processable n t))
10251
10252 (defun gnus-summary-unmark-all-processable ()
10253   "Remove the process mark from all articles."
10254   (interactive)
10255   (save-excursion
10256     (while gnus-newsgroup-processable
10257       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10258   (gnus-summary-position-point))
10259
10260 (defun gnus-summary-add-mark (article type)
10261   "Mark ARTICLE with a mark of TYPE."
10262   (let ((vtype (car (assq type gnus-article-mark-lists)))
10263         var)
10264     (if (not vtype)
10265         (error "No such mark type: %s" type)
10266       (setq var (intern (format "gnus-newsgroup-%s" type)))
10267       (set var (cons article (symbol-value var)))
10268       (if (memq type '(processable cached replied forwarded recent saved))
10269           (gnus-summary-update-secondary-mark article)
10270         ;;; !!! This is bogus.  We should find out what primary
10271         ;;; !!! mark we want to set.
10272         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10273
10274 (defun gnus-summary-mark-as-expirable (n)
10275   "Mark N articles forward as expirable.
10276 If N is negative, mark backward instead.  The difference between N and
10277 the actual number of articles marked is returned."
10278   (interactive "p")
10279   (gnus-summary-mark-forward n gnus-expirable-mark))
10280
10281 (defun gnus-summary-mark-as-spam (n)
10282   "Mark N articles forward as spam.
10283 If N is negative, mark backward instead.  The difference between N and
10284 the actual number of articles marked is returned."
10285   (interactive "p")
10286   (gnus-summary-mark-forward n gnus-spam-mark))
10287
10288 (defun gnus-summary-mark-article-as-replied (article)
10289   "Mark ARTICLE as replied to and update the summary line.
10290 ARTICLE can also be a list of articles."
10291   (interactive (list (gnus-summary-article-number)))
10292   (let ((articles (if (listp article) article (list article))))
10293     (dolist (article articles)
10294       (unless (numberp article)
10295         (error "%s is not a number" article))
10296       (push article gnus-newsgroup-replied)
10297       (let ((buffer-read-only nil))
10298         (when (gnus-summary-goto-subject article nil t)
10299           (gnus-summary-update-secondary-mark article))))))
10300
10301 (defun gnus-summary-mark-article-as-forwarded (article)
10302   "Mark ARTICLE as forwarded and update the summary line.
10303 ARTICLE can also be a list of articles."
10304   (let ((articles (if (listp article) article (list article))))
10305     (dolist (article articles)
10306       (push article gnus-newsgroup-forwarded)
10307       (let ((buffer-read-only nil))
10308         (when (gnus-summary-goto-subject article nil t)
10309           (gnus-summary-update-secondary-mark article))))))
10310
10311 (defun gnus-summary-set-bookmark (article)
10312   "Set a bookmark in current article."
10313   (interactive (list (gnus-summary-article-number)))
10314   (when (or (not (get-buffer gnus-article-buffer))
10315             (not gnus-current-article)
10316             (not gnus-article-current)
10317             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10318     (error "No current article selected"))
10319   ;; Remove old bookmark, if one exists.
10320   (gnus-pull article gnus-newsgroup-bookmarks)
10321   ;; Set the new bookmark, which is on the form
10322   ;; (article-number . line-number-in-body).
10323   (push
10324    (cons article
10325          (with-current-buffer gnus-article-buffer
10326            (count-lines
10327             (min (point)
10328                  (save-excursion
10329                    (article-goto-body)
10330                    (point)))
10331             (point))))
10332    gnus-newsgroup-bookmarks)
10333   (gnus-message 6 "A bookmark has been added to the current article."))
10334
10335 (defun gnus-summary-remove-bookmark (article)
10336   "Remove the bookmark from the current article."
10337   (interactive (list (gnus-summary-article-number)))
10338   ;; Remove old bookmark, if one exists.
10339   (if (not (assq article gnus-newsgroup-bookmarks))
10340       (gnus-message 6 "No bookmark in current article.")
10341     (gnus-pull article gnus-newsgroup-bookmarks)
10342     (gnus-message 6 "Removed bookmark.")))
10343
10344 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10345 (defun gnus-summary-mark-as-dormant (n)
10346   "Mark N articles forward as dormant.
10347 If N is negative, mark backward instead.  The difference between N and
10348 the actual number of articles marked is returned."
10349   (interactive "p")
10350   (gnus-summary-mark-forward n gnus-dormant-mark))
10351
10352 (defun gnus-summary-set-process-mark (article)
10353   "Set the process mark on ARTICLE and update the summary line."
10354   (setq gnus-newsgroup-processable
10355         (cons article
10356               (delq article gnus-newsgroup-processable)))
10357   (when (gnus-summary-goto-subject article)
10358     (gnus-summary-show-thread)
10359     (gnus-summary-goto-subject article)
10360     (gnus-summary-update-secondary-mark article)))
10361
10362 (defun gnus-summary-remove-process-mark (&rest articles)
10363   "Remove the process mark from ARTICLES and update the summary line."
10364   (dolist (article articles)
10365     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10366     (when (gnus-summary-goto-subject article)
10367       (gnus-summary-show-thread)
10368       (gnus-summary-goto-subject article)
10369       (gnus-summary-update-secondary-mark article)))
10370   t)
10371
10372 (defun gnus-summary-set-saved-mark (article)
10373   "Set the process mark on ARTICLE and update the summary line."
10374   (push article gnus-newsgroup-saved)
10375   (when (gnus-summary-goto-subject article)
10376     (gnus-summary-update-secondary-mark article)))
10377
10378 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10379   "Mark N articles as read forwards.
10380 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10381 The difference between N and the actual number of articles marked is
10382 returned.
10383 If NO-EXPIRE, auto-expiry will be inhibited."
10384   (interactive "p")
10385   (gnus-summary-show-thread)
10386   (let ((backward (< n 0))
10387         (gnus-summary-goto-unread
10388          (and gnus-summary-goto-unread
10389               (not (eq gnus-summary-goto-unread 'never))
10390               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10391                                     gnus-ticked-mark gnus-dormant-mark)))))
10392         (n (abs n))
10393         (mark (or mark gnus-del-mark)))
10394     (while (and (> n 0)
10395                 (gnus-summary-mark-article nil mark no-expire)
10396                 (zerop (gnus-summary-next-subject
10397                         (if backward -1 1)
10398                         (and gnus-summary-goto-unread
10399                              (not (eq gnus-summary-goto-unread 'never)))
10400                         t)))
10401       (setq n (1- n)))
10402     (when (/= 0 n)
10403       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10404     (gnus-summary-recenter)
10405     (gnus-summary-position-point)
10406     (gnus-set-mode-line 'summary)
10407     n))
10408
10409 (defun gnus-summary-mark-article-as-read (mark)
10410   "Mark the current article quickly as read with MARK."
10411   (let ((article (gnus-summary-article-number)))
10412     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10413     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10414     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10415     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10416     (push (cons article mark) gnus-newsgroup-reads)
10417     ;; Possibly remove from cache, if that is used.
10418     (when gnus-use-cache
10419       (gnus-cache-enter-remove-article article))
10420     ;; Allow the backend to change the mark.
10421     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10422     ;; Check for auto-expiry.
10423     (when (and gnus-newsgroup-auto-expire
10424                (memq mark gnus-auto-expirable-marks))
10425       (setq mark gnus-expirable-mark)
10426       ;; Let the backend know about the mark change.
10427       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10428       (push article gnus-newsgroup-expirable))
10429     ;; Set the mark in the buffer.
10430     (gnus-summary-update-mark mark 'unread)
10431     t))
10432
10433 (defun gnus-summary-mark-article-as-unread (mark)
10434   "Mark the current article quickly as unread with MARK."
10435   (let* ((article (gnus-summary-article-number))
10436          (old-mark (gnus-summary-article-mark article)))
10437     ;; Allow the backend to change the mark.
10438     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10439     (if (eq mark old-mark)
10440         t
10441       (if (<= article 0)
10442           (progn
10443             (gnus-error 1 "Can't mark negative article numbers")
10444             nil)
10445         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10446         (setq gnus-newsgroup-spam-marked
10447               (delq article gnus-newsgroup-spam-marked))
10448         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10449         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10450         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10451         (cond ((= mark gnus-ticked-mark)
10452                (setq gnus-newsgroup-marked
10453                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10454                                               article)))
10455               ((= mark gnus-spam-mark)
10456                (setq gnus-newsgroup-spam-marked
10457                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10458                                               article)))
10459               ((= mark gnus-dormant-mark)
10460                (setq gnus-newsgroup-dormant
10461                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10462                                               article)))
10463               (t
10464                (setq gnus-newsgroup-unreads
10465                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10466                                               article))))
10467         (gnus-pull article gnus-newsgroup-reads)
10468
10469         ;; See whether the article is to be put in the cache.
10470         (and gnus-use-cache
10471              (vectorp (gnus-summary-article-header article))
10472              (save-excursion
10473                (gnus-cache-possibly-enter-article
10474                 gnus-newsgroup-name article
10475                 (= mark gnus-ticked-mark)
10476                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10477
10478         ;; Fix the mark.
10479         (gnus-summary-update-mark mark 'unread)
10480         t))))
10481
10482 (defun gnus-summary-mark-article (&optional article mark no-expire)
10483   "Mark ARTICLE with MARK.  MARK can be any character.
10484 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10485 `??' (dormant) and `?E' (expirable).
10486 If MARK is nil, then the default character `?r' is used.
10487 If ARTICLE is nil, then the article on the current line will be
10488 marked.
10489 If NO-EXPIRE, auto-expiry will be inhibited."
10490   ;; The mark might be a string.
10491   (when (stringp mark)
10492     (setq mark (aref mark 0)))
10493   ;; If no mark is given, then we check auto-expiring.
10494   (when (null mark)
10495     (setq mark gnus-del-mark))
10496   (when (and (not no-expire)
10497              gnus-newsgroup-auto-expire
10498              (memq mark gnus-auto-expirable-marks))
10499     (setq mark gnus-expirable-mark))
10500   (let ((article (or article (gnus-summary-article-number)))
10501         (old-mark (gnus-summary-article-mark article)))
10502     ;; Allow the backend to change the mark.
10503     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10504     (if (eq mark old-mark)
10505         t
10506       (unless article
10507         (error "No article on current line"))
10508       (if (not (if (or (= mark gnus-unread-mark)
10509                        (= mark gnus-ticked-mark)
10510                        (= mark gnus-spam-mark)
10511                        (= mark gnus-dormant-mark))
10512                    (gnus-mark-article-as-unread article mark)
10513                  (gnus-mark-article-as-read article mark)))
10514           t
10515         ;; See whether the article is to be put in the cache.
10516         (and gnus-use-cache
10517              (not (= mark gnus-canceled-mark))
10518              (vectorp (gnus-summary-article-header article))
10519              (save-excursion
10520                (gnus-cache-possibly-enter-article
10521                 gnus-newsgroup-name article
10522                 (= mark gnus-ticked-mark)
10523                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10524
10525         (when (gnus-summary-goto-subject article nil t)
10526           (let ((buffer-read-only nil))
10527             (gnus-summary-show-thread)
10528             ;; Fix the mark.
10529             (gnus-summary-update-mark mark 'unread)
10530             t))))))
10531
10532 (defun gnus-summary-update-secondary-mark (article)
10533   "Update the secondary (read, process, cache) mark."
10534   (gnus-summary-update-mark
10535    (cond ((memq article gnus-newsgroup-processable)
10536           gnus-process-mark)
10537          ((memq article gnus-newsgroup-cached)
10538           gnus-cached-mark)
10539          ((memq article gnus-newsgroup-replied)
10540           gnus-replied-mark)
10541          ((memq article gnus-newsgroup-forwarded)
10542           gnus-forwarded-mark)
10543          ((memq article gnus-newsgroup-saved)
10544           gnus-saved-mark)
10545          ((memq article gnus-newsgroup-recent)
10546           gnus-recent-mark)
10547          ((memq article gnus-newsgroup-unseen)
10548           gnus-unseen-mark)
10549          (t gnus-no-mark))
10550    'replied)
10551   (when (gnus-visual-p 'summary-highlight 'highlight)
10552     (gnus-run-hooks 'gnus-summary-update-hook))
10553   t)
10554
10555 (defun gnus-summary-update-download-mark (article)
10556   "Update the download mark."
10557   (gnus-summary-update-mark
10558    (cond ((memq article gnus-newsgroup-undownloaded)
10559           gnus-undownloaded-mark)
10560          (gnus-newsgroup-agentized
10561           gnus-downloaded-mark)
10562          (t
10563           gnus-no-mark))
10564    'download)
10565   (gnus-summary-update-line t)
10566   t)
10567
10568 (defun gnus-summary-update-mark (mark type)
10569   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10570         (buffer-read-only nil))
10571     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10572     (when forward
10573       (when (looking-at "\r")
10574         (incf forward))
10575       (when (<= (+ forward (point)) (point-max))
10576         ;; Go to the right position on the line.
10577         (goto-char (+ forward (point)))
10578         ;; Replace the old mark with the new mark.
10579         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10580         ;; Optionally update the marks by some user rule.
10581         (when (eq type 'unread)
10582           (gnus-data-set-mark
10583            (gnus-data-find (gnus-summary-article-number)) mark)
10584           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10585
10586 (defun gnus-mark-article-as-read (article &optional mark)
10587   "Enter ARTICLE in the pertinent lists and remove it from others."
10588   ;; Make the article expirable.
10589   (let ((mark (or mark gnus-del-mark)))
10590     (setq gnus-newsgroup-expirable
10591           (if (= mark gnus-expirable-mark)
10592               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10593             (delq article gnus-newsgroup-expirable)))
10594     ;; Remove from unread and marked lists.
10595     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10596     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10597     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10598     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10599     (push (cons article mark) gnus-newsgroup-reads)
10600     ;; Possibly remove from cache, if that is used.
10601     (when gnus-use-cache
10602       (gnus-cache-enter-remove-article article))
10603     t))
10604
10605 (defun gnus-mark-article-as-unread (article &optional mark)
10606   "Enter ARTICLE in the pertinent lists and remove it from others."
10607   (let ((mark (or mark gnus-ticked-mark)))
10608     (if (<= article 0)
10609         (progn
10610           (gnus-error 1 "Can't mark negative article numbers")
10611           nil)
10612       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10613             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10614             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10615             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10616             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10617
10618       ;; Unsuppress duplicates?
10619       (when gnus-suppress-duplicates
10620         (gnus-dup-unsuppress-article article))
10621
10622       (cond ((= mark gnus-ticked-mark)
10623              (setq gnus-newsgroup-marked
10624                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10625             ((= mark gnus-spam-mark)
10626              (setq gnus-newsgroup-spam-marked
10627                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10628                                             article)))
10629             ((= mark gnus-dormant-mark)
10630              (setq gnus-newsgroup-dormant
10631                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10632             (t
10633              (setq gnus-newsgroup-unreads
10634                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10635       (gnus-pull article gnus-newsgroup-reads)
10636       t)))
10637
10638 (defalias 'gnus-summary-mark-as-unread-forward
10639   'gnus-summary-tick-article-forward)
10640 (make-obsolete 'gnus-summary-mark-as-unread-forward
10641                'gnus-summary-tick-article-forward)
10642 (defun gnus-summary-tick-article-forward (n)
10643   "Tick N articles forwards.
10644 If N is negative, tick backwards instead.
10645 The difference between N and the number of articles ticked is returned."
10646   (interactive "p")
10647   (gnus-summary-mark-forward n gnus-ticked-mark))
10648
10649 (defalias 'gnus-summary-mark-as-unread-backward
10650   'gnus-summary-tick-article-backward)
10651 (make-obsolete 'gnus-summary-mark-as-unread-backward
10652                'gnus-summary-tick-article-backward)
10653 (defun gnus-summary-tick-article-backward (n)
10654   "Tick N articles backwards.
10655 The difference between N and the number of articles ticked is returned."
10656   (interactive "p")
10657   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10658
10659 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10660 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10661 (defun gnus-summary-tick-article (&optional article clear-mark)
10662   "Mark current article as unread.
10663 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10664 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10665   (interactive)
10666   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10667                                        gnus-ticked-mark)))
10668
10669 (defun gnus-summary-mark-as-read-forward (n)
10670   "Mark N articles as read forwards.
10671 If N is negative, mark backwards instead.
10672 The difference between N and the actual number of articles marked is
10673 returned."
10674   (interactive "p")
10675   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10676
10677 (defun gnus-summary-mark-as-read-backward (n)
10678   "Mark the N articles as read backwards.
10679 The difference between N and the actual number of articles marked is
10680 returned."
10681   (interactive "p")
10682   (gnus-summary-mark-forward
10683    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10684
10685 (defun gnus-summary-mark-as-read (&optional article mark)
10686   "Mark current article as read.
10687 ARTICLE specifies the article to be marked as read.
10688 MARK specifies a string to be inserted at the beginning of the line."
10689   (gnus-summary-mark-article article mark))
10690
10691 (defun gnus-summary-clear-mark-forward (n)
10692   "Clear marks from N articles forward.
10693 If N is negative, clear backward instead.
10694 The difference between N and the number of marks cleared is returned."
10695   (interactive "p")
10696   (gnus-summary-mark-forward n gnus-unread-mark))
10697
10698 (defun gnus-summary-clear-mark-backward (n)
10699   "Clear marks from N articles backward.
10700 The difference between N and the number of marks cleared is returned."
10701   (interactive "p")
10702   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10703
10704 (defun gnus-summary-mark-unread-as-read ()
10705   "Intended to be used by `gnus-summary-mark-article-hook'."
10706   (when (memq gnus-current-article gnus-newsgroup-unreads)
10707     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10708
10709 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10710   "Intended to be used by `gnus-summary-mark-article-hook'."
10711   (let ((mark (gnus-summary-article-mark)))
10712     (when (or (gnus-unread-mark-p mark)
10713               (gnus-read-mark-p mark))
10714       (gnus-summary-mark-article gnus-current-article
10715                                  (or new-mark gnus-read-mark)))))
10716
10717 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10718   "Intended to be used by `gnus-summary-mark-article-hook'."
10719   (let ((mark (gnus-summary-article-mark)))
10720     (when (or (gnus-unread-mark-p mark)
10721               (gnus-read-mark-p mark))
10722       (gnus-summary-mark-article (gnus-summary-article-number)
10723                                  (or new-mark gnus-read-mark)))))
10724
10725 (defun gnus-summary-mark-unread-as-ticked ()
10726   "Intended to be used by `gnus-summary-mark-article-hook'."
10727   (when (memq gnus-current-article gnus-newsgroup-unreads)
10728     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10729
10730 (defun gnus-summary-mark-region-as-read (point mark all)
10731   "Mark all unread articles between point and mark as read.
10732 If given a prefix, mark all articles between point and mark as read,
10733 even ticked and dormant ones."
10734   (interactive "r\nP")
10735   (save-excursion
10736     (let (article)
10737       (goto-char point)
10738       (beginning-of-line)
10739       (while (and
10740               (< (point) mark)
10741               (progn
10742                 (when (or all
10743                           (memq (setq article (gnus-summary-article-number))
10744                                 gnus-newsgroup-unreads))
10745                   (gnus-summary-mark-article article gnus-del-mark))
10746                 t)
10747               (gnus-summary-find-next))))))
10748
10749 (defun gnus-summary-mark-below (score mark)
10750   "Mark articles with score less than SCORE with MARK."
10751   (interactive "P\ncMark: ")
10752   (setq score (if score
10753                   (prefix-numeric-value score)
10754                 (or gnus-summary-default-score 0)))
10755   (save-excursion
10756     (set-buffer gnus-summary-buffer)
10757     (goto-char (point-min))
10758     (while
10759         (progn
10760           (and (< (gnus-summary-article-score) score)
10761                (gnus-summary-mark-article nil mark))
10762           (gnus-summary-find-next)))))
10763
10764 (defun gnus-summary-kill-below (&optional score)
10765   "Mark articles with score below SCORE as read."
10766   (interactive "P")
10767   (gnus-summary-mark-below score gnus-killed-mark))
10768
10769 (defun gnus-summary-clear-above (&optional score)
10770   "Clear all marks from articles with score above SCORE."
10771   (interactive "P")
10772   (gnus-summary-mark-above score gnus-unread-mark))
10773
10774 (defun gnus-summary-tick-above (&optional score)
10775   "Tick all articles with score above SCORE."
10776   (interactive "P")
10777   (gnus-summary-mark-above score gnus-ticked-mark))
10778
10779 (defun gnus-summary-mark-above (score mark)
10780   "Mark articles with score over SCORE with MARK."
10781   (interactive "P\ncMark: ")
10782   (setq score (if score
10783                   (prefix-numeric-value score)
10784                 (or gnus-summary-default-score 0)))
10785   (save-excursion
10786     (set-buffer gnus-summary-buffer)
10787     (goto-char (point-min))
10788     (while (and (progn
10789                   (when (> (gnus-summary-article-score) score)
10790                     (gnus-summary-mark-article nil mark))
10791                   t)
10792                 (gnus-summary-find-next)))))
10793
10794 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10795 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10796 (defun gnus-summary-limit-include-expunged (&optional no-error)
10797   "Display all the hidden articles that were expunged for low scores."
10798   (interactive)
10799   (let ((buffer-read-only nil))
10800     (let ((scored gnus-newsgroup-scored)
10801           headers h)
10802       (while scored
10803         (unless (gnus-summary-article-header (caar scored))
10804           (and (setq h (gnus-number-to-header (caar scored)))
10805                (< (cdar scored) gnus-summary-expunge-below)
10806                (push h headers)))
10807         (setq scored (cdr scored)))
10808       (if (not headers)
10809           (when (not no-error)
10810             (error "No expunged articles hidden"))
10811         (goto-char (point-min))
10812         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10813         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10814         (mapcar (lambda (x) (push (mail-header-number x)
10815                                   gnus-newsgroup-limit))
10816                 headers)
10817         (gnus-summary-prepare-unthreaded (nreverse headers))
10818         (goto-char (point-min))
10819         (gnus-summary-position-point)
10820         t))))
10821
10822 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10823   "Mark all unread articles in this newsgroup as read.
10824 If prefix argument ALL is non-nil, ticked and dormant articles will
10825 also be marked as read.
10826 If QUIETLY is non-nil, no questions will be asked.
10827
10828 If TO-HERE is non-nil, it should be a point in the buffer.  All
10829 articles before (after, if REVERSE is set) this point will be marked
10830 as read.
10831
10832 Note that this function will only catch up the unread article
10833 in the current summary buffer limitation.
10834
10835 The number of articles marked as read is returned."
10836   (interactive "P")
10837   (prog1
10838       (save-excursion
10839         (when (or quietly
10840                   (not gnus-interactive-catchup) ;Without confirmation?
10841                   gnus-expert-user
10842                   (gnus-y-or-n-p
10843                    (if all
10844                        "Mark absolutely all articles as read? "
10845                      "Mark all unread articles as read? ")))
10846           (if (and not-mark
10847                    (not gnus-newsgroup-adaptive)
10848                    (not gnus-newsgroup-auto-expire)
10849                    (not gnus-suppress-duplicates)
10850                    (or (not gnus-use-cache)
10851                        (eq gnus-use-cache 'passive)))
10852               (progn
10853                 (when all
10854                   (setq gnus-newsgroup-marked nil
10855                         gnus-newsgroup-spam-marked nil
10856                         gnus-newsgroup-dormant nil))
10857                 (setq gnus-newsgroup-unreads
10858                       (gnus-sorted-nunion
10859                        (gnus-sorted-intersection gnus-newsgroup-unreads
10860                                                  gnus-newsgroup-downloadable)
10861                        gnus-newsgroup-unfetched)))
10862             ;; We actually mark all articles as canceled, which we
10863             ;; have to do when using auto-expiry or adaptive scoring.
10864             (gnus-summary-show-all-threads)
10865             (if (and to-here reverse)
10866                 (progn
10867                   (goto-char to-here)
10868                   (gnus-summary-mark-current-read-and-unread-as-read
10869                    gnus-catchup-mark)
10870                   (while (gnus-summary-find-next (not all))
10871                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10872               (when (gnus-summary-first-subject (not all))
10873                 (while (and
10874                         (if to-here (< (point) to-here) t)
10875                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10876                         (gnus-summary-find-next (not all))))))
10877             (gnus-set-mode-line 'summary))
10878           t))
10879     (gnus-summary-position-point)))
10880
10881 (defun gnus-summary-catchup-to-here (&optional all)
10882   "Mark all unticked articles before the current one as read.
10883 If ALL is non-nil, also mark ticked and dormant articles as read."
10884   (interactive "P")
10885   (save-excursion
10886     (gnus-save-hidden-threads
10887       (let ((beg (point)))
10888         ;; We check that there are unread articles.
10889         (when (or all (gnus-summary-find-prev))
10890           (gnus-summary-catchup all t beg)))))
10891   (gnus-summary-position-point))
10892
10893 (defun gnus-summary-catchup-from-here (&optional all)
10894   "Mark all unticked articles after (and including) the current one as read.
10895 If ALL is non-nil, also mark ticked and dormant articles as read."
10896   (interactive "P")
10897   (save-excursion
10898     (gnus-save-hidden-threads
10899       (let ((beg (point)))
10900         ;; We check that there are unread articles.
10901         (when (or all (gnus-summary-find-next))
10902           (gnus-summary-catchup all t beg nil t)))))
10903   (gnus-summary-position-point))
10904
10905 (defun gnus-summary-catchup-all (&optional quietly)
10906   "Mark all articles in this newsgroup as read.
10907 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10908 instead, which marks only unread articles as read."
10909   (interactive "P")
10910   (gnus-summary-catchup t quietly))
10911
10912 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10913   "Mark all unread articles in this group as read, then exit.
10914 If prefix argument ALL is non-nil, all articles are marked as read.
10915 If QUIETLY is non-nil, no questions will be asked."
10916   (interactive "P")
10917   (when (gnus-summary-catchup all quietly nil 'fast)
10918     ;; Select next newsgroup or exit.
10919     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10920              (eq gnus-auto-select-next 'quietly))
10921         (gnus-summary-next-group nil)
10922       (gnus-summary-exit))))
10923
10924 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10925   "Mark all articles in this newsgroup as read, and then exit.
10926 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10927 instead, which marks only unread articles as read."
10928   (interactive "P")
10929   (gnus-summary-catchup-and-exit t quietly))
10930
10931 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10932   "Mark all articles in this group as read and select the next group.
10933 If given a prefix, mark all articles, unread as well as ticked, as
10934 read."
10935   (interactive "P")
10936   (save-excursion
10937     (gnus-summary-catchup all))
10938   (gnus-summary-next-group))
10939
10940 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10941   "Mark all articles in this group as read and select the previous group.
10942 If given a prefix, mark all articles, unread as well as ticked, as
10943 read."
10944   (interactive "P")
10945   (save-excursion
10946     (gnus-summary-catchup all))
10947   (gnus-summary-next-group nil nil t))
10948
10949 ;;;
10950 ;;; with article
10951 ;;;
10952
10953 (defmacro gnus-with-article (article &rest forms)
10954   "Select ARTICLE and perform FORMS in the original article buffer.
10955 Then replace the article with the result."
10956   `(progn
10957      ;; We don't want the article to be marked as read.
10958      (let (gnus-mark-article-hook)
10959        (gnus-summary-select-article t t nil ,article))
10960      (set-buffer gnus-original-article-buffer)
10961      ,@forms
10962      (if (not (gnus-check-backend-function
10963                'request-replace-article (car gnus-article-current)))
10964          (gnus-message 5 "Read-only group; not replacing")
10965        (unless (gnus-request-replace-article
10966                 ,article (car gnus-article-current)
10967                 (current-buffer) t)
10968          (error "Couldn't replace article")))
10969      ;; The cache and backlog have to be flushed somewhat.
10970      (when gnus-keep-backlog
10971        (gnus-backlog-remove-article
10972         (car gnus-article-current) (cdr gnus-article-current)))
10973      (when gnus-use-cache
10974        (gnus-cache-update-article
10975         (car gnus-article-current) (cdr gnus-article-current)))))
10976
10977 (put 'gnus-with-article 'lisp-indent-function 1)
10978 (put 'gnus-with-article 'edebug-form-spec '(form body))
10979
10980 ;; Thread-based commands.
10981
10982 (defun gnus-summary-articles-in-thread (&optional article)
10983   "Return a list of all articles in the current thread.
10984 If ARTICLE is non-nil, return all articles in the thread that starts
10985 with that article."
10986   (let* ((article (or article (gnus-summary-article-number)))
10987          (data (gnus-data-find-list article))
10988          (top-level (gnus-data-level (car data)))
10989          (top-subject
10990           (cond ((null gnus-thread-operation-ignore-subject)
10991                  (gnus-simplify-subject-re
10992                   (mail-header-subject (gnus-data-header (car data)))))
10993                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10994                  (gnus-simplify-subject-fuzzy
10995                   (mail-header-subject (gnus-data-header (car data)))))
10996                 (t nil)))
10997          (end-point (save-excursion
10998                       (if (gnus-summary-go-to-next-thread)
10999                           (point) (point-max))))
11000          articles)
11001     (while (and data
11002                 (< (gnus-data-pos (car data)) end-point))
11003       (when (or (not top-subject)
11004                 (string= top-subject
11005                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11006                              (gnus-simplify-subject-fuzzy
11007                               (mail-header-subject
11008                                (gnus-data-header (car data))))
11009                            (gnus-simplify-subject-re
11010                             (mail-header-subject
11011                              (gnus-data-header (car data)))))))
11012         (push (gnus-data-number (car data)) articles))
11013       (unless (and (setq data (cdr data))
11014                    (> (gnus-data-level (car data)) top-level))
11015         (setq data nil)))
11016     ;; Return the list of articles.
11017     (nreverse articles)))
11018
11019 (defun gnus-summary-rethread-current ()
11020   "Rethread the thread the current article is part of."
11021   (interactive)
11022   (let* ((gnus-show-threads t)
11023          (article (gnus-summary-article-number))
11024          (id (mail-header-id (gnus-summary-article-header)))
11025          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11026     (unless id
11027       (error "No article on the current line"))
11028     (gnus-rebuild-thread id)
11029     (gnus-summary-goto-subject article)))
11030
11031 (defun gnus-summary-reparent-thread ()
11032   "Make the current article child of the marked (or previous) article.
11033
11034 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11035 is non-nil or the Subject: of both articles are the same."
11036   (interactive)
11037   (unless (not (gnus-group-read-only-p))
11038     (error "The current newsgroup does not support article editing"))
11039   (unless (<= (length gnus-newsgroup-processable) 1)
11040     (error "No more than one article may be marked"))
11041   (let ((child (gnus-summary-article-number))
11042         ;; First grab the marked article, otherwise one line up.
11043         (parent (if (not (null gnus-newsgroup-processable))
11044                     (car gnus-newsgroup-processable)
11045                   (save-excursion
11046                     (if (eq (forward-line -1) 0)
11047                         (gnus-summary-article-number)
11048                       (error "Beginning of summary buffer"))))))
11049     (gnus-summary-reparent-children parent (list child))))
11050
11051 (defun gnus-summary-reparent-children (parent children)
11052   "Make PARENT the parent of CHILDREN.
11053 When called interactively, PARENT is the current article and CHILDREN
11054 are the process-marked articles."
11055   (interactive
11056    (list (gnus-summary-article-number)
11057          (gnus-summary-work-articles nil)))
11058   (dolist (child children)
11059     (save-window-excursion
11060       (let ((gnus-article-buffer " *reparent*"))
11061         (unless (not (eq parent child))
11062           (error "An article may not be self-referential"))
11063         (let ((message-id (mail-header-id
11064                            (gnus-summary-article-header parent))))
11065           (unless (and message-id (not (equal message-id "")))
11066             (error "No message-id in desired parent"))
11067           (gnus-with-article child
11068             (save-restriction
11069               (goto-char (point-min))
11070               (message-narrow-to-head)
11071               (if (re-search-forward "^References: " nil t)
11072                   (progn
11073                     (re-search-forward "^[^ \t]" nil t)
11074                     (forward-line -1)
11075                     (end-of-line)
11076                     (insert " " message-id))
11077                 (insert "References: " message-id "\n"))))
11078           (set-buffer gnus-summary-buffer)
11079           (gnus-summary-unmark-all-processable)
11080           (gnus-summary-update-article child)
11081           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11082             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11083           (gnus-summary-rethread-current)
11084           (gnus-message 3 "Article %d is now the child of article %d"
11085                         child parent))))))
11086
11087 (defun gnus-summary-toggle-threads (&optional arg)
11088   "Toggle showing conversation threads.
11089 If ARG is positive number, turn showing conversation threads on."
11090   (interactive "P")
11091   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11092     (setq gnus-show-threads
11093           (if (null arg) (not gnus-show-threads)
11094             (> (prefix-numeric-value arg) 0)))
11095     (gnus-summary-prepare)
11096     (gnus-summary-goto-subject current)
11097     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11098     (gnus-summary-position-point)))
11099
11100 (defun gnus-summary-show-all-threads ()
11101   "Show all threads."
11102   (interactive)
11103   (save-excursion
11104     (let ((buffer-read-only nil))
11105       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11106   (gnus-summary-position-point))
11107
11108 (defun gnus-summary-show-thread ()
11109   "Show thread subtrees.
11110 Returns nil if no thread was there to be shown."
11111   (interactive)
11112   (let ((buffer-read-only nil)
11113         (orig (point))
11114         (end (point-at-eol))
11115         ;; Leave point at bol
11116         (beg (progn (beginning-of-line) (point))))
11117     (prog1
11118         ;; Any hidden lines here?
11119         (search-forward "\r" end t)
11120       (subst-char-in-region beg end ?\^M ?\n t)
11121       (goto-char orig)
11122       (gnus-summary-position-point))))
11123
11124 (defun gnus-summary-maybe-hide-threads ()
11125   "If requested, hide the threads that should be hidden."
11126   (when (and gnus-show-threads
11127              gnus-thread-hide-subtree)
11128     (gnus-summary-hide-all-threads
11129      (if (or (consp gnus-thread-hide-subtree)
11130              (functionp gnus-thread-hide-subtree))
11131          (gnus-make-predicate gnus-thread-hide-subtree)
11132        nil))))
11133
11134 ;;; Hiding predicates.
11135
11136 (defun gnus-article-unread-p (header)
11137   (memq (mail-header-number header) gnus-newsgroup-unreads))
11138
11139 (defun gnus-article-unseen-p (header)
11140   (memq (mail-header-number header) gnus-newsgroup-unseen))
11141
11142 (defun gnus-map-articles (predicate articles)
11143   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11144   (apply 'gnus-or (mapcar predicate
11145                           (mapcar (lambda (number)
11146                                     (gnus-summary-article-header number))
11147                                   articles))))
11148
11149 (defun gnus-summary-hide-all-threads (&optional predicate)
11150   "Hide all thread subtrees.
11151 If PREDICATE is supplied, threads that satisfy this predicate
11152 will not be hidden."
11153   (interactive)
11154   (save-excursion
11155     (goto-char (point-min))
11156     (let ((end nil))
11157       (while (not end)
11158         (when (or (not predicate)
11159                   (gnus-map-articles
11160                    predicate (gnus-summary-article-children)))
11161             (gnus-summary-hide-thread))
11162         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11163   (gnus-summary-position-point))
11164
11165 (defun gnus-summary-hide-thread ()
11166   "Hide thread subtrees.
11167 If PREDICATE is supplied, threads that satisfy this predicate
11168 will not be hidden.
11169 Returns nil if no threads were there to be hidden."
11170   (interactive)
11171   (let ((buffer-read-only nil)
11172         (start (point))
11173         (article (gnus-summary-article-number)))
11174     (goto-char start)
11175     ;; Go forward until either the buffer ends or the subthread
11176     ;; ends.
11177     (when (and (not (eobp))
11178                (or (zerop (gnus-summary-next-thread 1 t))
11179                    (goto-char (point-max))))
11180       (prog1
11181           (if (and (> (point) start)
11182                    (search-backward "\n" start t))
11183               (progn
11184                 (subst-char-in-region start (point) ?\n ?\^M)
11185                 (gnus-summary-goto-subject article))
11186             (goto-char start)
11187             nil)))))
11188
11189 (defun gnus-summary-go-to-next-thread (&optional previous)
11190   "Go to the same level (or less) next thread.
11191 If PREVIOUS is non-nil, go to previous thread instead.
11192 Return the article number moved to, or nil if moving was impossible."
11193   (let ((level (gnus-summary-thread-level))
11194         (way (if previous -1 1))
11195         (beg (point)))
11196     (forward-line way)
11197     (while (and (not (eobp))
11198                 (< level (gnus-summary-thread-level)))
11199       (forward-line way))
11200     (if (eobp)
11201         (progn
11202           (goto-char beg)
11203           nil)
11204       (setq beg (point))
11205       (prog1
11206           (gnus-summary-article-number)
11207         (goto-char beg)))))
11208
11209 (defun gnus-summary-next-thread (n &optional silent)
11210   "Go to the same level next N'th thread.
11211 If N is negative, search backward instead.
11212 Returns the difference between N and the number of skips actually
11213 done.
11214
11215 If SILENT, don't output messages."
11216   (interactive "p")
11217   (let ((backward (< n 0))
11218         (n (abs n)))
11219     (while (and (> n 0)
11220                 (gnus-summary-go-to-next-thread backward))
11221       (decf n))
11222     (unless silent
11223       (gnus-summary-position-point))
11224     (when (and (not silent) (/= 0 n))
11225       (gnus-message 7 "No more threads"))
11226     n))
11227
11228 (defun gnus-summary-prev-thread (n)
11229   "Go to the same level previous N'th thread.
11230 Returns the difference between N and the number of skips actually
11231 done."
11232   (interactive "p")
11233   (gnus-summary-next-thread (- n)))
11234
11235 (defun gnus-summary-go-down-thread ()
11236   "Go down one level in the current thread."
11237   (let ((children (gnus-summary-article-children)))
11238     (when children
11239       (gnus-summary-goto-subject (car children)))))
11240
11241 (defun gnus-summary-go-up-thread ()
11242   "Go up one level in the current thread."
11243   (let ((parent (gnus-summary-article-parent)))
11244     (when parent
11245       (gnus-summary-goto-subject parent))))
11246
11247 (defun gnus-summary-down-thread (n)
11248   "Go down thread N steps.
11249 If N is negative, go up instead.
11250 Returns the difference between N and how many steps down that were
11251 taken."
11252   (interactive "p")
11253   (let ((up (< n 0))
11254         (n (abs n)))
11255     (while (and (> n 0)
11256                 (if up (gnus-summary-go-up-thread)
11257                   (gnus-summary-go-down-thread)))
11258       (setq n (1- n)))
11259     (gnus-summary-position-point)
11260     (when (/= 0 n)
11261       (gnus-message 7 "Can't go further"))
11262     n))
11263
11264 (defun gnus-summary-up-thread (n)
11265   "Go up thread N steps.
11266 If N is negative, go down instead.
11267 Returns the difference between N and how many steps down that were
11268 taken."
11269   (interactive "p")
11270   (gnus-summary-down-thread (- n)))
11271
11272 (defun gnus-summary-top-thread ()
11273   "Go to the top of the thread."
11274   (interactive)
11275   (while (gnus-summary-go-up-thread))
11276   (gnus-summary-article-number))
11277
11278 (defun gnus-summary-kill-thread (&optional unmark)
11279   "Mark articles under current thread as read.
11280 If the prefix argument is positive, remove any kinds of marks.
11281 If the prefix argument is negative, tick articles instead."
11282   (interactive "P")
11283   (when unmark
11284     (setq unmark (prefix-numeric-value unmark)))
11285   (let ((articles (gnus-summary-articles-in-thread)))
11286     (save-excursion
11287       ;; Expand the thread.
11288       (gnus-summary-show-thread)
11289       ;; Mark all the articles.
11290       (while articles
11291         (gnus-summary-goto-subject (car articles))
11292         (cond ((null unmark)
11293                (gnus-summary-mark-article-as-read gnus-killed-mark))
11294               ((> unmark 0)
11295                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11296               (t
11297                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11298         (setq articles (cdr articles))))
11299     ;; Hide killed subtrees.
11300     (and (null unmark)
11301          gnus-thread-hide-killed
11302          (gnus-summary-hide-thread))
11303     ;; If marked as read, go to next unread subject.
11304     (when (null unmark)
11305       ;; Go to next unread subject.
11306       (gnus-summary-next-subject 1 t)))
11307   (gnus-set-mode-line 'summary))
11308
11309 ;; Summary sorting commands
11310
11311 (defun gnus-summary-sort-by-number (&optional reverse)
11312   "Sort the summary buffer by article number.
11313 Argument REVERSE means reverse order."
11314   (interactive "P")
11315   (gnus-summary-sort 'number reverse))
11316
11317 (defun gnus-summary-sort-by-random (&optional reverse)
11318   "Randomize the order in the summary buffer.
11319 Argument REVERSE means to randomize in reverse order."
11320   (interactive "P")
11321   (gnus-summary-sort 'random reverse))
11322
11323 (defun gnus-summary-sort-by-author (&optional reverse)
11324   "Sort the summary buffer by author name alphabetically.
11325 If `case-fold-search' is non-nil, case of letters is ignored.
11326 Argument REVERSE means reverse order."
11327   (interactive "P")
11328   (gnus-summary-sort 'author reverse))
11329
11330 (defun gnus-summary-sort-by-recipient (&optional reverse)
11331   "Sort the summary buffer by recipient name alphabetically.
11332 If `case-fold-search' is non-nil, case of letters is ignored.
11333 Argument REVERSE means reverse order."
11334   (interactive "P")
11335   (gnus-summary-sort 'recipient reverse))
11336
11337 (defun gnus-summary-sort-by-subject (&optional reverse)
11338   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11339 If `case-fold-search' is non-nil, case of letters is ignored.
11340 Argument REVERSE means reverse order."
11341   (interactive "P")
11342   (gnus-summary-sort 'subject reverse))
11343
11344 (defun gnus-summary-sort-by-date (&optional reverse)
11345   "Sort the summary buffer by date.
11346 Argument REVERSE means reverse order."
11347   (interactive "P")
11348   (gnus-summary-sort 'date reverse))
11349
11350 (defun gnus-summary-sort-by-score (&optional reverse)
11351   "Sort the summary buffer by score.
11352 Argument REVERSE means reverse order."
11353   (interactive "P")
11354   (gnus-summary-sort 'score reverse))
11355
11356 (defun gnus-summary-sort-by-lines (&optional reverse)
11357   "Sort the summary buffer by the number of lines.
11358 Argument REVERSE means reverse order."
11359   (interactive "P")
11360   (gnus-summary-sort 'lines reverse))
11361
11362 (defun gnus-summary-sort-by-chars (&optional reverse)
11363   "Sort the summary buffer by article length.
11364 Argument REVERSE means reverse order."
11365   (interactive "P")
11366   (gnus-summary-sort 'chars reverse))
11367
11368 (defun gnus-summary-sort-by-original (&optional reverse)
11369   "Sort the summary buffer using the default sorting method.
11370 Argument REVERSE means reverse order."
11371   (interactive "P")
11372   (let* ((buffer-read-only)
11373          (gnus-summary-prepare-hook nil))
11374     ;; We do the sorting by regenerating the threads.
11375     (gnus-summary-prepare)
11376     ;; Hide subthreads if needed.
11377     (gnus-summary-maybe-hide-threads)))
11378
11379 (defun gnus-summary-sort (predicate reverse)
11380   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11381   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11382          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11383          (gnus-thread-sort-functions
11384           (if (not reverse)
11385               thread
11386             `(lambda (t1 t2)
11387                (,thread t2 t1))))
11388          (gnus-sort-gathered-threads-function
11389           gnus-thread-sort-functions)
11390          (gnus-article-sort-functions
11391           (if (not reverse)
11392               article
11393             `(lambda (t1 t2)
11394                (,article t2 t1))))
11395          (buffer-read-only)
11396          (gnus-summary-prepare-hook nil))
11397     ;; We do the sorting by regenerating the threads.
11398     (gnus-summary-prepare)
11399     ;; Hide subthreads if needed.
11400     (gnus-summary-maybe-hide-threads)))
11401
11402 ;; Summary saving commands.
11403
11404 (defun gnus-summary-save-article (&optional n not-saved)
11405   "Save the current article using the default saver function.
11406 If N is a positive number, save the N next articles.
11407 If N is a negative number, save the N previous articles.
11408 If N is nil and any articles have been marked with the process mark,
11409 save those articles instead.
11410 The variable `gnus-default-article-saver' specifies the saver function.
11411
11412 If the optional second argument NOT-SAVED is non-nil, articles saved
11413 will not be marked as saved."
11414   (interactive "P")
11415   (require 'gnus-art)
11416   (let* ((articles (gnus-summary-work-articles n))
11417          (save-buffer (save-excursion
11418                         (nnheader-set-temp-buffer " *Gnus Save*")))
11419          (num (length articles))
11420          ;; Whether to save decoded articles or raw articles.
11421          (decode (when gnus-article-save-coding-system
11422                    (get gnus-default-article-saver :decode)))
11423          ;; When saving many articles in a single file, use the other
11424          ;; function to save articles other than the first one.
11425          (saver2 (get gnus-default-article-saver :function))
11426          (gnus-prompt-before-saving (if saver2
11427                                         t
11428                                       gnus-prompt-before-saving))
11429          (gnus-default-article-saver gnus-default-article-saver)
11430          header file)
11431     (dolist (article articles)
11432       (setq header (gnus-summary-article-header article))
11433       (if (not (vectorp header))
11434           ;; This is a pseudo-article.
11435           (if (assq 'name header)
11436               (gnus-copy-file (cdr (assq 'name header)))
11437             (gnus-message 1 "Article %d is unsaveable" article))
11438         ;; This is a real article.
11439         (save-window-excursion
11440           (let ((gnus-display-mime-function (when decode
11441                                               gnus-display-mime-function))
11442                 (gnus-article-prepare-hook (when decode
11443                                              gnus-article-prepare-hook)))
11444             (gnus-summary-select-article t nil nil article)
11445             (gnus-summary-goto-subject article)))
11446         (save-excursion
11447           (set-buffer save-buffer)
11448           (erase-buffer)
11449           (insert-buffer-substring (if decode
11450                                        gnus-article-buffer
11451                                      gnus-original-article-buffer)))
11452         (setq file (gnus-article-save save-buffer file num))
11453         (gnus-summary-remove-process-mark article)
11454         (unless not-saved
11455           (gnus-summary-set-saved-mark article)))
11456       (when saver2
11457         (setq gnus-default-article-saver saver2
11458               saver2 nil)))
11459     (gnus-kill-buffer save-buffer)
11460     (gnus-summary-position-point)
11461     (gnus-set-mode-line 'summary)
11462     n))
11463
11464 (defun gnus-summary-pipe-output (&optional arg headers)
11465   "Pipe the current article to a subprocess.
11466 If N is a positive number, pipe the N next articles.
11467 If N is a negative number, pipe the N previous articles.
11468 If N is nil and any articles have been marked with the process mark,
11469 pipe those articles instead.
11470 If HEADERS (the symbolic prefix), include the headers, too."
11471   (interactive (gnus-interactive "P\ny"))
11472   (require 'gnus-art)
11473   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11474         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11475     (gnus-summary-save-article arg t))
11476   (let ((buffer (get-buffer "*Shell Command Output*")))
11477     (when (and buffer
11478                (not (zerop (buffer-size buffer))))
11479       (gnus-configure-windows 'pipe))))
11480
11481 (defun gnus-summary-save-article-mail (&optional arg)
11482   "Append the current article to a Unix mail box file.
11483 If N is a positive number, save the N next articles.
11484 If N is a negative number, save the N previous articles.
11485 If N is nil and any articles have been marked with the process mark,
11486 save those articles instead."
11487   (interactive "P")
11488   (require 'gnus-art)
11489   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11490     (gnus-summary-save-article arg)))
11491
11492 (defun gnus-summary-save-article-rmail (&optional arg)
11493   "Append the current article to an rmail file.
11494 If N is a positive number, save the N next articles.
11495 If N is a negative number, save the N previous articles.
11496 If N is nil and any articles have been marked with the process mark,
11497 save those articles instead."
11498   (interactive "P")
11499   (require 'gnus-art)
11500   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11501     (gnus-summary-save-article arg)))
11502
11503 (defun gnus-summary-save-article-file (&optional arg)
11504   "Append the current article to a file.
11505 If N is a positive number, save the N next articles.
11506 If N is a negative number, save the N previous articles.
11507 If N is nil and any articles have been marked with the process mark,
11508 save those articles instead."
11509   (interactive "P")
11510   (require 'gnus-art)
11511   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11512     (gnus-summary-save-article arg)))
11513
11514 (defun gnus-summary-write-article-file (&optional arg)
11515   "Write the current article to a file, deleting the previous file.
11516 If N is a positive number, save the N next articles.
11517 If N is a negative number, save the N previous articles.
11518 If N is nil and any articles have been marked with the process mark,
11519 save those articles instead."
11520   (interactive "P")
11521   (require 'gnus-art)
11522   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11523     (gnus-summary-save-article arg)))
11524
11525 (defun gnus-summary-save-article-body-file (&optional arg)
11526   "Append the current article body to a file.
11527 If N is a positive number, save the N next articles.
11528 If N is a negative number, save the N previous articles.
11529 If N is nil and any articles have been marked with the process mark,
11530 save those articles instead."
11531   (interactive "P")
11532   (require 'gnus-art)
11533   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11534     (gnus-summary-save-article arg)))
11535
11536 (defun gnus-summary-write-article-body-file (&optional arg)
11537   "Write the current article body to a file, deleting the previous file.
11538 If N is a positive number, save the N next articles.
11539 If N is a negative number, save the N previous articles.
11540 If N is nil and any articles have been marked with the process mark,
11541 save those articles instead."
11542   (interactive "P")
11543   (require 'gnus-art)
11544   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11545     (gnus-summary-save-article arg)))
11546
11547 (defun gnus-summary-muttprint (&optional arg)
11548   "Print the current article using Muttprint.
11549 If N is a positive number, save the N next articles.
11550 If N is a negative number, save the N previous articles.
11551 If N is nil and any articles have been marked with the process mark,
11552 save those articles instead."
11553   (interactive "P")
11554   (require 'gnus-art)
11555   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11556     (gnus-summary-save-article arg t)))
11557
11558 (defun gnus-summary-pipe-message (program)
11559   "Pipe the current article through PROGRAM."
11560   (interactive "sProgram: ")
11561   (gnus-summary-select-article)
11562   (let ((mail-header-separator ""))
11563     (gnus-eval-in-buffer-window gnus-article-buffer
11564       (save-restriction
11565         (widen)
11566         (let ((start (window-start))
11567               buffer-read-only)
11568           (message-pipe-buffer-body program)
11569           (set-window-start (get-buffer-window (current-buffer)) start))))))
11570
11571 (defun gnus-get-split-value (methods)
11572   "Return a value based on the split METHODS."
11573   (let (split-name method result match)
11574     (when methods
11575       (save-excursion
11576         (set-buffer gnus-original-article-buffer)
11577         (save-restriction
11578           (nnheader-narrow-to-headers)
11579           (while (and methods (not split-name))
11580             (goto-char (point-min))
11581             (setq method (pop methods))
11582             (setq match (car method))
11583             (when (cond
11584                    ((stringp match)
11585                     ;; Regular expression.
11586                     (ignore-errors
11587                       (re-search-forward match nil t)))
11588                    ((functionp match)
11589                     ;; Function.
11590                     (save-restriction
11591                       (widen)
11592                       (setq result (funcall match gnus-newsgroup-name))))
11593                    ((consp match)
11594                     ;; Form.
11595                     (save-restriction
11596                       (widen)
11597                       (setq result (eval match)))))
11598               (setq split-name (cdr method))
11599               (cond ((stringp result)
11600                      (push (expand-file-name
11601                             result gnus-article-save-directory)
11602                            split-name))
11603                     ((consp result)
11604                      (setq split-name (append result split-name)))))))))
11605     (nreverse split-name)))
11606
11607 (defun gnus-valid-move-group-p (group)
11608   (and (boundp group)
11609        (symbol-name group)
11610        (symbol-value group)
11611        (gnus-get-function (gnus-find-method-for-group
11612                            (symbol-name group)) 'request-accept-article t)))
11613
11614 (defun gnus-read-move-group-name (prompt default articles prefix)
11615   "Read a group name."
11616   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11617          (minibuffer-confirm-incomplete nil) ; XEmacs
11618          (prom
11619           (format "%s %s to"
11620                   prompt
11621                   (if (> (length articles) 1)
11622                       (format "these %d articles" (length articles))
11623                     "this article")))
11624          (to-newsgroup
11625           (cond
11626            ((null split-name)
11627             (gnus-completing-read-with-default
11628              default prom
11629              gnus-active-hashtb
11630              'gnus-valid-move-group-p
11631              nil prefix
11632              'gnus-group-history))
11633            ((= 1 (length split-name))
11634             (gnus-completing-read-with-default
11635              (car split-name) prom
11636              gnus-active-hashtb
11637              'gnus-valid-move-group-p
11638              nil nil
11639              'gnus-group-history))
11640            (t
11641             (gnus-completing-read-with-default
11642              nil prom
11643              (mapcar 'list (nreverse split-name))
11644              nil nil nil
11645              'gnus-group-history))))
11646          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11647     (when to-newsgroup
11648       (if (or (string= to-newsgroup "")
11649               (string= to-newsgroup prefix))
11650           (setq to-newsgroup default))
11651       (unless to-newsgroup
11652         (error "No group name entered"))
11653       (or (gnus-active to-newsgroup)
11654           (gnus-activate-group to-newsgroup nil nil to-method)
11655           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11656                                      to-newsgroup))
11657               (or (and (gnus-request-create-group to-newsgroup to-method)
11658                        (gnus-activate-group
11659                         to-newsgroup nil nil to-method)
11660                        (gnus-subscribe-group to-newsgroup))
11661                   (error "Couldn't create group %s" to-newsgroup)))
11662           (error "No such group: %s" to-newsgroup)))
11663     to-newsgroup))
11664
11665 (defvar gnus-summary-save-parts-counter)
11666
11667 (defun gnus-summary-save-parts (type dir n &optional reverse)
11668   "Save parts matching TYPE to DIR.
11669 If REVERSE, save parts that do not match TYPE."
11670   (interactive
11671    (list (read-string "Save parts of type: "
11672                       (or (car gnus-summary-save-parts-type-history)
11673                           gnus-summary-save-parts-default-mime)
11674                       'gnus-summary-save-parts-type-history)
11675          (setq gnus-summary-save-parts-last-directory
11676                (read-file-name "Save to directory: "
11677                                gnus-summary-save-parts-last-directory
11678                                nil t))
11679          current-prefix-arg))
11680   (gnus-summary-iterate n
11681     (let ((gnus-display-mime-function nil)
11682           (gnus-inhibit-treatment t))
11683       (gnus-summary-select-article))
11684     (save-excursion
11685       (set-buffer gnus-article-buffer)
11686       (let ((handles (or gnus-article-mime-handles
11687                          (mm-dissect-buffer nil gnus-article-loose-mime)
11688                          (and gnus-article-emulate-mime
11689                               (mm-uu-dissect))))
11690             (gnus-summary-save-parts-counter 1))
11691         (when handles
11692           (gnus-summary-save-parts-1 type dir handles reverse)
11693           (unless gnus-article-mime-handles ;; Don't destroy this case.
11694             (mm-destroy-parts handles)))))))
11695
11696 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11697   (if (stringp (car handle))
11698       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11699               (cdr handle))
11700     (when (if reverse
11701               (not (string-match type (mm-handle-media-type handle)))
11702             (string-match type (mm-handle-media-type handle)))
11703       (let ((file (expand-file-name
11704                    (gnus-map-function
11705                     mm-file-name-rewrite-functions
11706                     (file-name-nondirectory
11707                      (or
11708                       (mail-content-type-get
11709                        (mm-handle-disposition handle) 'filename)
11710                       (mail-content-type-get
11711                        (mm-handle-type handle) 'name)
11712                       (format "%s.%d.%d" gnus-newsgroup-name
11713                               (cdr gnus-article-current)
11714                               gnus-summary-save-parts-counter))))
11715                    dir)))
11716         (incf gnus-summary-save-parts-counter)
11717         (unless (file-exists-p file)
11718           (mm-save-part-to-file handle file))))))
11719
11720 ;; Summary extract commands
11721
11722 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11723   (let ((buffer-read-only nil)
11724         (article (gnus-summary-article-number))
11725         after-article b e)
11726     (unless (gnus-summary-goto-subject article)
11727       (error "No such article: %d" article))
11728     (gnus-summary-position-point)
11729     ;; If all commands are to be bunched up on one line, we collect
11730     ;; them here.
11731     (unless gnus-view-pseudos-separately
11732       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11733             files action)
11734         (while ps
11735           (setq action (cdr (assq 'action (car ps))))
11736           (setq files (list (cdr (assq 'name (car ps)))))
11737           (while (and ps (cdr ps)
11738                       (string= (or action "1")
11739                                (or (cdr (assq 'action (cadr ps))) "2")))
11740             (push (cdr (assq 'name (cadr ps))) files)
11741             (setcdr ps (cddr ps)))
11742           (when files
11743             (when (not (string-match "%s" action))
11744               (push " " files))
11745             (push " " files)
11746             (when (assq 'execute (car ps))
11747               (setcdr (assq 'execute (car ps))
11748                       (funcall (if (string-match "%s" action)
11749                                    'format 'concat)
11750                                action
11751                                (mapconcat
11752                                 (lambda (f)
11753                                   (if (equal f " ")
11754                                       f
11755                                     (shell-quote-argument f)))
11756                                 files " ")))))
11757           (setq ps (cdr ps)))))
11758     (if (and gnus-view-pseudos (not not-view))
11759         (while pslist
11760           (when (assq 'execute (car pslist))
11761             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11762                                   (eq gnus-view-pseudos 'not-confirm)))
11763           (setq pslist (cdr pslist)))
11764       (save-excursion
11765         (while pslist
11766           (setq after-article (or (cdr (assq 'article (car pslist)))
11767                                   (gnus-summary-article-number)))
11768           (gnus-summary-goto-subject after-article)
11769           (forward-line 1)
11770           (setq b (point))
11771           (insert "    " (file-name-nondirectory
11772                           (cdr (assq 'name (car pslist))))
11773                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11774           (setq e (point))
11775           (forward-line -1)             ; back to `b'
11776           (gnus-add-text-properties
11777            b (1- e) (list 'gnus-number gnus-reffed-article-number
11778                           gnus-mouse-face-prop gnus-mouse-face))
11779           (gnus-data-enter
11780            after-article gnus-reffed-article-number
11781            gnus-unread-mark b (car pslist) 0 (- e b))
11782           (setq gnus-newsgroup-unreads
11783                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11784                                          gnus-reffed-article-number))
11785           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11786           (setq pslist (cdr pslist)))))))
11787
11788 (defun gnus-pseudos< (p1 p2)
11789   (let ((c1 (cdr (assq 'action p1)))
11790         (c2 (cdr (assq 'action p2))))
11791     (and c1 c2 (string< c1 c2))))
11792
11793 (defun gnus-request-pseudo-article (props)
11794   (cond ((assq 'execute props)
11795          (gnus-execute-command (cdr (assq 'execute props)))))
11796   (let ((gnus-current-article (gnus-summary-article-number)))
11797     (gnus-run-hooks 'gnus-mark-article-hook)))
11798
11799 (defun gnus-execute-command (command &optional automatic)
11800   (save-excursion
11801     (gnus-article-setup-buffer)
11802     (set-buffer gnus-article-buffer)
11803     (setq buffer-read-only nil)
11804     (let ((command (if automatic command
11805                      (read-string "Command: " (cons command 0)))))
11806       (erase-buffer)
11807       (insert "$ " command "\n\n")
11808       (if gnus-view-pseudo-asynchronously
11809           (start-process "gnus-execute" (current-buffer) shell-file-name
11810                          shell-command-switch command)
11811         (call-process shell-file-name nil t nil
11812                       shell-command-switch command)))))
11813
11814 ;; Summary kill commands.
11815
11816 (defun gnus-summary-edit-global-kill (article)
11817   "Edit the \"global\" kill file."
11818   (interactive (list (gnus-summary-article-number)))
11819   (gnus-group-edit-global-kill article))
11820
11821 (defun gnus-summary-edit-local-kill ()
11822   "Edit a local kill file applied to the current newsgroup."
11823   (interactive)
11824   (setq gnus-current-headers (gnus-summary-article-header))
11825   (gnus-group-edit-local-kill
11826    (gnus-summary-article-number) gnus-newsgroup-name))
11827
11828 ;;; Header reading.
11829
11830 (defun gnus-read-header (id &optional header)
11831   "Read the headers of article ID and enter them into the Gnus system."
11832   (let ((group gnus-newsgroup-name)
11833         (gnus-override-method
11834          (or
11835           gnus-override-method
11836           (and (gnus-news-group-p gnus-newsgroup-name)
11837                (car (gnus-refer-article-methods)))))
11838         where)
11839     ;; First we check to see whether the header in question is already
11840     ;; fetched.
11841     (if (stringp id)
11842         ;; This is a Message-ID.
11843         (setq header (or header (gnus-id-to-header id)))
11844       ;; This is an article number.
11845       (setq header (or header (gnus-summary-article-header id))))
11846     (if (and header
11847              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11848         ;; We have found the header.
11849         header
11850       ;; We have to really fetch the header to this article.
11851       (save-excursion
11852         (set-buffer nntp-server-buffer)
11853         (when (setq where (gnus-request-head id group))
11854           (nnheader-fold-continuation-lines)
11855           (goto-char (point-max))
11856           (insert ".\n")
11857           (goto-char (point-min))
11858           (insert "211 ")
11859           (princ (cond
11860                   ((numberp id) id)
11861                   ((cdr where) (cdr where))
11862                   (header (mail-header-number header))
11863                   (t gnus-reffed-article-number))
11864                  (current-buffer))
11865           (insert " Article retrieved.\n"))
11866         (if (or (not where)
11867                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11868             ()                          ; Malformed head.
11869           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11870             (when (and (stringp id)
11871                        (or
11872                         (not (string= (gnus-group-real-name group)
11873                                       (car where)))
11874                         (not (gnus-server-equal gnus-override-method
11875                                                 (gnus-group-method group)))))
11876               ;; If we fetched by Message-ID and the article came from
11877               ;; a different group (or server), we fudge some bogus
11878               ;; article numbers for this article.
11879               (mail-header-set-number header gnus-reffed-article-number))
11880             (save-excursion
11881               (set-buffer gnus-summary-buffer)
11882               (decf gnus-reffed-article-number)
11883               (gnus-remove-header (mail-header-number header))
11884               (push header gnus-newsgroup-headers)
11885               (setq gnus-current-headers header)
11886               (push (mail-header-number header) gnus-newsgroup-limit)))
11887           header)))))
11888
11889 (defun gnus-remove-header (number)
11890   "Remove header NUMBER from `gnus-newsgroup-headers'."
11891   (if (and gnus-newsgroup-headers
11892            (= number (mail-header-number (car gnus-newsgroup-headers))))
11893       (pop gnus-newsgroup-headers)
11894     (let ((headers gnus-newsgroup-headers))
11895       (while (and (cdr headers)
11896                   (not (= number (mail-header-number (cadr headers)))))
11897         (pop headers))
11898       (when (cdr headers)
11899         (setcdr headers (cddr headers))))))
11900
11901 ;;;
11902 ;;; summary highlights
11903 ;;;
11904
11905 (defun gnus-highlight-selected-summary ()
11906   "Highlight selected article in summary buffer."
11907   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11908   (when gnus-summary-selected-face
11909     (save-excursion
11910       (let* ((beg (point-at-bol))
11911              (end (point-at-eol))
11912              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11913              (from (if (get-text-property beg gnus-mouse-face-prop)
11914                        beg
11915                      (or (next-single-property-change
11916                           beg gnus-mouse-face-prop nil end)
11917                          beg)))
11918              (to
11919               (if (= from end)
11920                   (- from 2)
11921                 (or (next-single-property-change
11922                      from gnus-mouse-face-prop nil end)
11923                     end))))
11924         ;; If no mouse-face prop on line we will have to = from = end,
11925         ;; so we highlight the entire line instead.
11926         (when (= (+ to 2) from)
11927           (setq from beg)
11928           (setq to end))
11929         (if gnus-newsgroup-selected-overlay
11930             ;; Move old overlay.
11931             (gnus-move-overlay
11932              gnus-newsgroup-selected-overlay from to (current-buffer))
11933           ;; Create new overlay.
11934           (gnus-overlay-put
11935            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11936            'face gnus-summary-selected-face))))))
11937
11938 (defvar gnus-summary-highlight-line-cached nil)
11939 (defvar gnus-summary-highlight-line-trigger nil)
11940
11941 (defun gnus-summary-highlight-line-0 ()
11942   (if (and (eq gnus-summary-highlight-line-trigger
11943                gnus-summary-highlight)
11944            gnus-summary-highlight-line-cached)
11945       gnus-summary-highlight-line-cached
11946     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11947           gnus-summary-highlight-line-cached
11948           (let* ((cond (list 'cond))
11949                  (c cond)
11950                  (list gnus-summary-highlight))
11951             (while list
11952               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11953                               nil))
11954               (setq c (cdr c)
11955                     list (cdr list)))
11956             (gnus-byte-compile (list 'lambda nil cond))))))
11957
11958 (defun gnus-summary-highlight-line ()
11959   "Highlight current line according to `gnus-summary-highlight'."
11960   (let* ((beg (point-at-bol))
11961          (article (or (gnus-summary-article-number) gnus-current-article))
11962          (score (or (cdr (assq article
11963                                gnus-newsgroup-scored))
11964                     gnus-summary-default-score 0))
11965          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11966          (inhibit-read-only t)
11967          (default gnus-summary-default-score)
11968          (default-high gnus-summary-default-high-score)
11969          (default-low gnus-summary-default-low-score)
11970          (uncached (and gnus-summary-use-undownloaded-faces
11971                         (memq article gnus-newsgroup-undownloaded)
11972                         (not (memq article gnus-newsgroup-cached)))))
11973     (let ((face (funcall (gnus-summary-highlight-line-0))))
11974       (unless (eq face (get-text-property beg 'face))
11975         (gnus-put-text-property-excluding-characters-with-faces
11976          beg (point-at-eol) 'face
11977          (setq face (if (boundp face) (symbol-value face) face)))
11978         (when gnus-summary-highlight-line-function
11979           (funcall gnus-summary-highlight-line-function article face))))))
11980
11981 (defun gnus-update-read-articles (group unread &optional compute)
11982   "Update the list of read articles in GROUP.
11983 UNREAD is a sorted list."
11984   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11985         (info (gnus-get-info group))
11986         (prev 1)
11987         read)
11988     (if (or (not info) (not active))
11989         ;; There is no info on this group if it was, in fact,
11990         ;; killed.  Gnus stores no information on killed groups, so
11991         ;; there's nothing to be done.
11992         ;; One could store the information somewhere temporarily,
11993         ;; perhaps...  Hmmm...
11994         ()
11995       ;; Remove any negative articles numbers.
11996       (while (and unread (< (car unread) 0))
11997         (setq unread (cdr unread)))
11998       ;; Remove any expired article numbers
11999       (while (and unread (< (car unread) (car active)))
12000         (setq unread (cdr unread)))
12001       ;; Compute the ranges of read articles by looking at the list of
12002       ;; unread articles.
12003       (while unread
12004         (when (/= (car unread) prev)
12005           (push (if (= prev (1- (car unread))) prev
12006                   (cons prev (1- (car unread))))
12007                 read))
12008         (setq prev (1+ (car unread)))
12009         (setq unread (cdr unread)))
12010       (when (<= prev (cdr active))
12011         (push (cons prev (cdr active)) read))
12012       (setq read (if (> (length read) 1) (nreverse read) read))
12013       (if compute
12014           read
12015         (save-excursion
12016           (let (setmarkundo)
12017             ;; Propagate the read marks to the backend.
12018             (when (gnus-check-backend-function 'request-set-mark group)
12019               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12020                     (add (gnus-remove-from-range read (gnus-info-read info))))
12021                 (when (or add del)
12022                   (unless (gnus-check-group group)
12023                     (error "Can't open server for %s" group))
12024                   (gnus-request-set-mark
12025                    group (delq nil (list (if add (list add 'add '(read)))
12026                                          (if del (list del 'del '(read))))))
12027                   (setq setmarkundo
12028                         `(gnus-request-set-mark
12029                           ,group
12030                           ',(delq nil (list
12031                                        (if del (list del 'add '(read)))
12032                                        (if add (list add 'del '(read))))))))))
12033             (set-buffer gnus-group-buffer)
12034             (gnus-undo-register
12035               `(progn
12036                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12037                  (gnus-info-set-read ',info ',(gnus-info-read info))
12038                  (gnus-get-unread-articles-in-group ',info
12039                                                     (gnus-active ,group))
12040                  (gnus-group-update-group ,group t)
12041                  ,setmarkundo))))
12042         ;; Enter this list into the group info.
12043         (gnus-info-set-read info read)
12044         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12045         (gnus-get-unread-articles-in-group info (gnus-active group))
12046         t))))
12047
12048 (defun gnus-offer-save-summaries ()
12049   "Offer to save all active summary buffers."
12050   (let (buffers)
12051     ;; Go through all buffers and find all summaries.
12052     (dolist (buffer (buffer-list))
12053       (when (and (setq buffer (buffer-name buffer))
12054                  (string-match "Summary" buffer)
12055                  (with-current-buffer buffer
12056                    ;; We check that this is, indeed, a summary buffer.
12057                    (and (eq major-mode 'gnus-summary-mode)
12058                         ;; Also make sure this isn't bogus.
12059                         gnus-newsgroup-prepared
12060                         ;; Also make sure that this isn't a
12061                         ;; dead summary buffer.
12062                         (not gnus-dead-summary-mode))))
12063         (push buffer buffers)))
12064     ;; Go through all these summary buffers and offer to save them.
12065     (when buffers
12066       (save-excursion
12067         (map-y-or-n-p
12068          "Update summary buffer %s? "
12069          (lambda (buf)
12070            (switch-to-buffer buf)
12071            (gnus-summary-exit))
12072          buffers)))))
12073
12074 (defun gnus-summary-setup-default-charset ()
12075   "Setup newsgroup default charset."
12076   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12077       (setq gnus-newsgroup-charset nil)
12078     (let* ((ignored-charsets
12079             (or gnus-newsgroup-ephemeral-ignored-charsets
12080                 (append
12081                  (and gnus-newsgroup-name
12082                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12083                  gnus-newsgroup-ignored-charsets))))
12084       (setq gnus-newsgroup-charset
12085             (or gnus-newsgroup-ephemeral-charset
12086                 (and gnus-newsgroup-name
12087                      (gnus-parameter-charset gnus-newsgroup-name))
12088                 gnus-default-charset))
12089       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12090            ignored-charsets))))
12091
12092 ;;;
12093 ;;; Mime Commands
12094 ;;;
12095
12096 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12097   "Display the current article buffer fully MIME-buttonized.
12098 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12099 treated as multipart/mixed."
12100   (interactive "P")
12101   (require 'gnus-art)
12102   (let ((gnus-unbuttonized-mime-types nil)
12103         (gnus-mime-display-multipart-as-mixed show-all-parts))
12104     (gnus-summary-show-article)))
12105
12106 (defun gnus-summary-repair-multipart (article)
12107   "Add a Content-Type header to a multipart article without one."
12108   (interactive (list (gnus-summary-article-number)))
12109   (gnus-with-article article
12110     (message-narrow-to-head)
12111     (message-remove-header "Mime-Version")
12112     (goto-char (point-max))
12113     (insert "Mime-Version: 1.0\n")
12114     (widen)
12115     (when (search-forward "\n--" nil t)
12116       (let ((separator (buffer-substring (point) (point-at-eol))))
12117         (message-narrow-to-head)
12118         (message-remove-header "Content-Type")
12119         (goto-char (point-max))
12120         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12121                         separator))
12122         (widen))))
12123   (let (gnus-mark-article-hook)
12124     (gnus-summary-select-article t t nil article)))
12125
12126 (defun gnus-summary-toggle-display-buttonized ()
12127   "Toggle the buttonizing of the article buffer."
12128   (interactive)
12129   (require 'gnus-art)
12130   (if (setq gnus-inhibit-mime-unbuttonizing
12131             (not gnus-inhibit-mime-unbuttonizing))
12132       (let ((gnus-unbuttonized-mime-types nil))
12133         (gnus-summary-show-article))
12134     (gnus-summary-show-article)))
12135
12136 ;;;
12137 ;;; Generic summary marking commands
12138 ;;;
12139
12140 (defvar gnus-summary-marking-alist
12141   '((read gnus-del-mark "d")
12142     (unread gnus-unread-mark "u")
12143     (ticked gnus-ticked-mark "!")
12144     (dormant gnus-dormant-mark "?")
12145     (expirable gnus-expirable-mark "e"))
12146   "An alist of names/marks/keystrokes.")
12147
12148 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12149 (defvar gnus-summary-mark-map)
12150
12151 (defun gnus-summary-make-all-marking-commands ()
12152   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12153   (dolist (elem gnus-summary-marking-alist)
12154     (apply 'gnus-summary-make-marking-command elem)))
12155
12156 (defun gnus-summary-make-marking-command (name mark keystroke)
12157   (let ((map (make-sparse-keymap)))
12158     (define-key gnus-summary-generic-mark-map keystroke map)
12159     (dolist (lway `((next "next" next nil "n")
12160                     (next-unread "next unread" next t "N")
12161                     (prev "previous" prev nil "p")
12162                     (prev-unread "previous unread" prev t "P")
12163                     (nomove "" nil nil ,keystroke)))
12164       (let ((func (gnus-summary-make-marking-command-1
12165                    mark (car lway) lway name)))
12166         (setq func (eval func))
12167         (define-key map (nth 4 lway) func)))))
12168
12169 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12170   `(defun ,(intern
12171             (format "gnus-summary-put-mark-as-%s%s"
12172                     name (if (eq way 'nomove)
12173                              ""
12174                            (concat "-" (symbol-name way)))))
12175      (n)
12176      ,(format
12177        "Mark the current article as %s%s.
12178 If N, the prefix, then repeat N times.
12179 If N is negative, move in reverse order.
12180 The difference between N and the actual number of articles marked is
12181 returned."
12182        name (cadr lway))
12183      (interactive "p")
12184      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12185
12186 (defun gnus-summary-generic-mark (n mark move unread)
12187   "Mark N articles with MARK."
12188   (unless (eq major-mode 'gnus-summary-mode)
12189     (error "This command can only be used in the summary buffer"))
12190   (gnus-summary-show-thread)
12191   (let ((nummove
12192          (cond
12193           ((eq move 'next) 1)
12194           ((eq move 'prev) -1)
12195           (t 0))))
12196     (if (zerop nummove)
12197         (setq n 1)
12198       (when (< n 0)
12199         (setq n (abs n)
12200               nummove (* -1 nummove))))
12201     (while (and (> n 0)
12202                 (gnus-summary-mark-article nil mark)
12203                 (zerop (gnus-summary-next-subject nummove unread t)))
12204       (setq n (1- n)))
12205     (when (/= 0 n)
12206       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12207     (gnus-summary-recenter)
12208     (gnus-summary-position-point)
12209     (gnus-set-mode-line 'summary)
12210     n))
12211
12212 (defun gnus-summary-insert-articles (articles)
12213   (when (setq articles
12214               (gnus-sorted-difference articles
12215                                       (mapcar (lambda (h)
12216                                                 (mail-header-number h))
12217                                               gnus-newsgroup-headers)))
12218     (setq gnus-newsgroup-headers
12219           (gnus-merge 'list
12220                       gnus-newsgroup-headers
12221                       (gnus-fetch-headers articles)
12222                       'gnus-article-sort-by-number))
12223     ;; Suppress duplicates?
12224     (when gnus-suppress-duplicates
12225       (gnus-dup-suppress-articles))
12226
12227     ;; We might want to build some more threads first.
12228     (when (and gnus-fetch-old-headers
12229                (eq gnus-headers-retrieved-by 'nov))
12230       (if (eq gnus-fetch-old-headers 'invisible)
12231           (gnus-build-all-threads)
12232         (gnus-build-old-threads)))
12233     ;; Let the Gnus agent mark articles as read.
12234     (when gnus-agent
12235       (gnus-agent-get-undownloaded-list))
12236     ;; Remove list identifiers from subject
12237     (when gnus-list-identifiers
12238       (gnus-summary-remove-list-identifiers))
12239     ;; First and last article in this newsgroup.
12240     (when gnus-newsgroup-headers
12241       (setq gnus-newsgroup-begin
12242             (mail-header-number (car gnus-newsgroup-headers))
12243             gnus-newsgroup-end
12244             (mail-header-number
12245              (gnus-last-element gnus-newsgroup-headers))))
12246     (when gnus-use-scoring
12247       (gnus-possibly-score-headers))))
12248
12249 (defun gnus-summary-insert-old-articles (&optional all)
12250   "Insert all old articles in this group.
12251 If ALL is non-nil, already read articles become readable.
12252 If ALL is a number, fetch this number of articles."
12253   (interactive "P")
12254   (prog1
12255       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12256             older len)
12257         (setq older
12258               ;; Some nntp servers lie about their active range.  When
12259               ;; this happens, the active range can be in the millions.
12260               ;; Use a compressed range to avoid creating a huge list.
12261               (gnus-range-difference (list gnus-newsgroup-active) old))
12262         (setq len (gnus-range-length older))
12263         (cond
12264          ((null older) nil)
12265          ((numberp all)
12266           (if (< all len)
12267               (let ((older-range (nreverse older)))
12268                 (setq older nil)
12269
12270                 (while (> all 0)
12271                   (let* ((r (pop older-range))
12272                          (min (if (numberp r) r (car r)))
12273                          (max (if (numberp r) r (cdr r))))
12274                     (while (and (<= min max)
12275                                 (> all 0))
12276                       (push max older)
12277                       (setq all (1- all)
12278                             max (1- max))))))
12279             (setq older (gnus-uncompress-range older))))
12280          (all
12281           (setq older (gnus-uncompress-range older)))
12282          (t
12283           (when (and (numberp gnus-large-newsgroup)
12284                    (> len gnus-large-newsgroup))
12285               (let* ((cursor-in-echo-area nil)
12286                      (initial (gnus-parameter-large-newsgroup-initial
12287                                gnus-newsgroup-name))
12288                      (input
12289                       (read-string
12290                        (format
12291                         "How many articles from %s (%s %d): "
12292                         (gnus-group-decoded-name gnus-newsgroup-name)
12293                         (if initial "max" "default")
12294                         len)
12295                        (if initial
12296                            (cons (number-to-string initial)
12297                                  0)))))
12298                 (unless (string-match "^[ \t]*$" input)
12299                   (setq all (string-to-number input))
12300                   (if (< all len)
12301                       (let ((older-range (nreverse older)))
12302                         (setq older nil)
12303
12304                         (while (> all 0)
12305                           (let* ((r (pop older-range))
12306                                  (min (if (numberp r) r (car r)))
12307                                  (max (if (numberp r) r (cdr r))))
12308                             (while (and (<= min max)
12309                                         (> all 0))
12310                               (push max older)
12311                               (setq all (1- all)
12312                                     max (1- max))))))))))
12313           (setq older (gnus-uncompress-range older))))
12314         (if (not older)
12315             (message "No old news.")
12316           (gnus-summary-insert-articles older)
12317           (gnus-summary-limit (gnus-sorted-nunion old older))))
12318     (gnus-summary-position-point)))
12319
12320 (defun gnus-summary-insert-new-articles ()
12321   "Insert all new articles in this group."
12322   (interactive)
12323   (prog1
12324       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12325             (old-active gnus-newsgroup-active)
12326             (nnmail-fetched-sources (list t))
12327             i new)
12328         (setq gnus-newsgroup-active
12329               (gnus-activate-group gnus-newsgroup-name 'scan))
12330         (setq i (cdr gnus-newsgroup-active))
12331         (while (> i (cdr old-active))
12332           (push i new)
12333           (decf i))
12334         (if (not new)
12335             (message "No gnus is bad news")
12336           (gnus-summary-insert-articles new)
12337           (setq gnus-newsgroup-unreads
12338                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12339           (gnus-summary-limit (gnus-sorted-nunion old new))))
12340     (gnus-summary-position-point)))
12341
12342 (gnus-summary-make-all-marking-commands)
12343
12344 (gnus-ems-redefine)
12345
12346 (provide 'gnus-sum)
12347
12348 (run-hooks 'gnus-sum-load-hook)
12349
12350 ;; Local Variables:
12351 ;; coding: iso-8859-1
12352 ;; End:
12353
12354 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12355 ;;; gnus-sum.el ends here