(gnus-summary-expire-thread): Add new function to expire a thread,
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-summary-next-group-on-exit t
66   "If non-nil, go to the next unread newsgroup on summary exit.
67 See `gnus-group-goto-unread'."
68   :link '(custom-manual "(gnus)Group Maneuvering")
69   :group 'gnus-summary-exit
70   :version "23.0" ;; No Gnus
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already
76 read (or just marked as read) article, the old article will not
77 normally be displayed in the Summary buffer.  If this variable is
78 t, Gnus will attempt to grab the headers to the old articles, and
79 thereby build complete threads.  If it has the value `some', all
80 old headers will be fetched but only enough headers to connect
81 otherwise loose threads will be displayed.  This variable can
82 also be a number.  In that case, no more than that number of old
83 headers will be fetched.  If it has the value `invisible', all
84 old headers will be fetched, but none will be displayed.
85
86 The server has to support NOV for any of this to work.
87
88 This feature can seriously impact performance it ignores all
89 locally cached header entries."
90   :group 'gnus-thread
91   :type '(choice (const :tag "off" nil)
92                  (const :tag "on" t)
93                  (const some)
94                  (const invisible)
95                  number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-refer-thread-limit 500
99   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
100 If t, fetch all the available old headers."
101   :group 'gnus-thread
102   :type '(choice number
103                  (sexp :menu-tag "other" t)))
104
105 (defcustom gnus-summary-make-false-root 'adopt
106   "*nil means that Gnus won't gather loose threads.
107 If the root of a thread has expired or been read in a previous
108 session, the information necessary to build a complete thread has been
109 lost.  Instead of having many small sub-threads from this original thread
110 scattered all over the summary buffer, Gnus can gather them.
111
112 If non-nil, Gnus will try to gather all loose sub-threads from an
113 original thread into one large thread.
114
115 If this variable is non-nil, it should be one of `none', `adopt',
116 `dummy' or `empty'.
117
118 If this variable is `none', Gnus will not make a false root, but just
119 present the sub-threads after another.
120 If this variable is `dummy', Gnus will create a dummy root that will
121 have all the sub-threads as children.
122 If this variable is `adopt', Gnus will make one of the \"children\"
123 the parent and mark all the step-children as such.
124 If this variable is `empty', the \"children\" are printed with empty
125 subject fields.  (Or rather, they will be printed with a string
126 given by the `gnus-summary-same-subject' variable.)"
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const none)
130                  (const dummy)
131                  (const adopt)
132                  (const empty)))
133
134 (defcustom gnus-summary-make-false-root-always nil
135   "Always make a false dummy root."
136   :version "22.1"
137   :group 'gnus-thread
138   :type 'boolean)
139
140 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
141   "*A regexp to match subjects to be excluded from loose thread gathering.
142 As loose thread gathering is done on subjects only, that means that
143 there can be many false gatherings performed.  By rooting out certain
144 common subjects, gathering might become saner."
145   :group 'gnus-thread
146   :type 'regexp)
147
148 (defcustom gnus-summary-gather-subject-limit nil
149   "*Maximum length of subject comparisons when gathering loose threads.
150 Use nil to compare full subjects.  Setting this variable to a low
151 number will help gather threads that have been corrupted by
152 newsreaders chopping off subject lines, but it might also mean that
153 unrelated articles that have subject that happen to begin with the
154 same few characters will be incorrectly gathered.
155
156 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
157 comparing subjects."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  (const fuzzy)
161                  (sexp :menu-tag "on" t)))
162
163 (defcustom gnus-simplify-subject-functions nil
164   "List of functions taking a string argument that simplify subjects.
165 The functions are applied recursively.
166
167 Useful functions to put in this list include:
168 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
169 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
170   :group 'gnus-thread
171   :type '(repeat function))
172
173 (defcustom gnus-simplify-ignored-prefixes nil
174   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  regexp))
178
179 (defcustom gnus-build-sparse-threads nil
180   "*If non-nil, fill in the gaps in threads.
181 If `some', only fill in the gaps that are needed to tie loose threads
182 together.  If `more', fill in all leaf nodes that Gnus can find.  If
183 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
184   :group 'gnus-thread
185   :type '(choice (const :tag "off" nil)
186                  (const some)
187                  (const more)
188                  (sexp :menu-tag "all" t)))
189
190 (defcustom gnus-summary-thread-gathering-function
191   'gnus-gather-threads-by-subject
192   "*Function used for gathering loose threads.
193 There are two pre-defined functions: `gnus-gather-threads-by-subject',
194 which only takes Subjects into consideration; and
195 `gnus-gather-threads-by-references', which compared the References
196 headers of the articles to find matches."
197   :group 'gnus-thread
198   :type '(radio (function-item gnus-gather-threads-by-subject)
199                 (function-item gnus-gather-threads-by-references)
200                 (function :tag "other")))
201
202 (defcustom gnus-summary-same-subject ""
203   "*String indicating that the current article has the same subject as the previous.
204 This variable will only be used if the value of
205 `gnus-summary-make-false-root' is `empty'."
206   :group 'gnus-summary-format
207   :type 'string)
208
209 (defcustom gnus-summary-goto-unread t
210   "*If t, many commands will go to the next unread article.
211 This applies to marking commands as well as other commands that
212 \"naturally\" select the next article, like, for instance, `SPC' at
213 the end of an article.
214
215 If nil, the marking commands do NOT go to the next unread article
216 \(they go to the next article instead).  If `never', commands that
217 usually go to the next unread article, will go to the next article,
218 whether it is read or not."
219   :group 'gnus-summary-marks
220   :link '(custom-manual "(gnus)Setting Marks")
221   :type '(choice (const :tag "off" nil)
222                  (const never)
223                  (sexp :menu-tag "on" t)))
224
225 (defcustom gnus-summary-default-score 0
226   "*Default article score level.
227 All scores generated by the score files will be added to this score.
228 If this variable is nil, scoring will be disabled."
229   :group 'gnus-score-default
230   :type '(choice (const :tag "disable")
231                  integer))
232
233 (defcustom gnus-summary-default-high-score 0
234   "*Default threshold for a high scored article.
235 An article will be highlighted as high scored if its score is greater
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-default-low-score 0
242   "*Default threshold for a low scored article.
243 An article will be highlighted as low scored if its score is smaller
244 than this score."
245   :version "22.1"
246   :group 'gnus-score-default
247   :type 'integer)
248
249 (defcustom gnus-summary-zcore-fuzz 0
250   "*Fuzziness factor for the zcore in the summary buffer.
251 Articles with scores closer than this to `gnus-summary-default-score'
252 will not be marked."
253   :group 'gnus-summary-format
254   :type 'integer)
255
256 (defcustom gnus-simplify-subject-fuzzy-regexp nil
257   "*Strings to be removed when doing fuzzy matches.
258 This can either be a regular expression or list of regular expressions
259 that will be removed from subject strings if fuzzy subject
260 simplification is selected."
261   :group 'gnus-thread
262   :type '(repeat regexp))
263
264 (defcustom gnus-show-threads t
265   "*If non-nil, display threads in summary mode."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-subtree nil
270   "*If non-nil, hide all threads initially.
271 This can be a predicate specifier which says which threads to hide.
272 If threads are hidden, you have to run the command
273 `gnus-summary-show-thread' by hand or select an article."
274   :group 'gnus-thread
275   :type '(radio (sexp :format "Non-nil\n"
276                       :match (lambda (widget value)
277                                (not (or (consp value) (functionp value))))
278                       :value t)
279                 (const nil)
280                 (sexp :tag "Predicate specifier")))
281
282 (defcustom gnus-thread-hide-killed t
283   "*If non-nil, hide killed threads automatically."
284   :group 'gnus-thread
285   :type 'boolean)
286
287 (defcustom gnus-thread-ignore-subject t
288   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
289 If nil, articles that have different subjects from their parents will
290 start separate threads."
291   :group 'gnus-thread
292   :type 'boolean)
293
294 (defcustom gnus-thread-operation-ignore-subject t
295   "*If non-nil, subjects will be ignored when doing thread commands.
296 This affects commands like `gnus-summary-kill-thread' and
297 `gnus-summary-lower-thread'.
298
299 If this variable is nil, articles in the same thread with different
300 subjects will not be included in the operation in question.  If this
301 variable is `fuzzy', only articles that have subjects that are fuzzily
302 equal will be included."
303   :group 'gnus-thread
304   :type '(choice (const :tag "off" nil)
305                  (const fuzzy)
306                  (sexp :tag "on" t)))
307
308 (defcustom gnus-thread-indent-level 4
309   "*Number that says how much each sub-thread should be indented."
310   :group 'gnus-thread
311   :type 'integer)
312
313 (defcustom gnus-auto-extend-newsgroup t
314   "*If non-nil, extend newsgroup forward and backward when requested."
315   :group 'gnus-summary-choose
316   :type 'boolean)
317
318 (defcustom gnus-auto-select-first t
319   "If non-nil, select an article on group entry.
320 An article is selected automatically when entering a group
321 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
322 `gnus-summary-catchup-and-goto-next-group'.
323
324 Which article is selected is controlled by the variable
325 `gnus-auto-select-subject'.
326
327 If you want to prevent automatic selection of articles in some
328 newsgroups, set the variable to nil in `gnus-select-group-hook'."
329   ;; Commands include...
330   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
331   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
332   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
333   :group 'gnus-group-select
334   :type '(choice (const :tag "none" nil)
335                  (sexp :menu-tag "first" t)))
336
337 (defcustom gnus-auto-select-subject 'unread
338   "*Says what subject to place under point when entering a group.
339
340 This variable can either be the symbols `first' (place point on the
341 first subject), `unread' (place point on the subject line of the first
342 unread article), `best' (place point on the subject line of the
343 higest-scored article), `unseen' (place point on the subject line of
344 the first unseen article), `unseen-or-unread' (place point on the subject
345 line of the first unseen article or, if all article have been seen, on the
346 subject line of the first unread article), or a function to be called to
347 place point on some subject line."
348   :version "22.1"
349   :group 'gnus-group-select
350   :type '(choice (const best)
351                  (const unread)
352                  (const first)
353                  (const unseen)
354                  (const unseen-or-unread)))
355
356 (defcustom gnus-auto-select-next t
357   "*If non-nil, offer to go to the next group from the end of the previous.
358 If the value is t and the next newsgroup is empty, Gnus will exit
359 summary mode and go back to group mode.  If the value is neither nil
360 nor t, Gnus will select the following unread newsgroup.  In
361 particular, if the value is the symbol `quietly', the next unread
362 newsgroup will be selected without any confirmation, and if it is
363 `almost-quietly', the next group will be selected without any
364 confirmation if you are located on the last article in the group.
365 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
366 will go to the next group without confirmation."
367   :group 'gnus-summary-maneuvering
368   :type '(choice (const :tag "off" nil)
369                  (const quietly)
370                  (const almost-quietly)
371                  (const slightly-quietly)
372                  (sexp :menu-tag "on" t)))
373
374 (defcustom gnus-auto-select-same nil
375   "*If non-nil, select the next article with the same subject.
376 If there are no more articles with the same subject, go to
377 the first unread article."
378   :group 'gnus-summary-maneuvering
379   :type 'boolean)
380
381 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
382   "What article should be selected after exiting an ephemeral group.
383 Valid values include:
384
385 `next'
386   Select the next article.
387 `next-unread'
388   Select the next unread article.
389 `next-noselect'
390   Move the cursor to the next article.  This is the default.
391 `next-unread-noselect'
392   Move the cursor to the next unread article.
393
394 If it has any other value or there is no next (unread) article, the
395 article selected before entering to the ephemeral group will appear."
396   :version "23.0" ;; No Gnus
397   :group 'gnus-summary-maneuvering
398   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
399                  (const next) (const next-unread)
400                  (const next-noselect) (const next-unread-noselect)
401                  (sexp :tag "other" :value nil)))
402
403 (defcustom gnus-auto-goto-ignores 'unfetched
404   "*Says how to handle unfetched articles when maneuvering.
405
406 This variable can either be the symbols nil (maneuver to any
407 article), `undownloaded' (maneuvering while unplugged ignores articles
408 that have not been fetched), `always-undownloaded' (maneuvering always
409 ignores articles that have not been fetched), `unfetched' (maneuvering
410 ignores articles whose headers have not been fetched).
411
412 NOTE: The list of unfetched articles will always be nil when plugged
413 and, when unplugged, a subset of the undownloaded article list."
414   :version "22.1"
415   :group 'gnus-summary-maneuvering
416   :type '(choice (const :tag "None" nil)
417                  (const :tag "Undownloaded when unplugged" undownloaded)
418                  (const :tag "Undownloaded" always-undownloaded)
419                  (const :tag "Unfetched" unfetched)))
420
421 (defcustom gnus-summary-check-current nil
422   "*If non-nil, consider the current article when moving.
423 The \"unread\" movement commands will stay on the same line if the
424 current article is unread."
425   :group 'gnus-summary-maneuvering
426   :type 'boolean)
427
428 (defcustom gnus-auto-center-summary 2
429   "*If non-nil, always center the current summary buffer.
430 In particular, if `vertical' do only vertical recentering.  If non-nil
431 and non-`vertical', do both horizontal and vertical recentering."
432   :group 'gnus-summary-maneuvering
433   :type '(choice (const :tag "none" nil)
434                  (const vertical)
435                  (integer :tag "height")
436                  (sexp :menu-tag "both" t)))
437
438 (defvar gnus-auto-center-group t
439   "*If non-nil, always center the group buffer.")
440
441 (defcustom gnus-show-all-headers nil
442   "*If non-nil, don't hide any headers."
443   :group 'gnus-article-hiding
444   :group 'gnus-article-headers
445   :type 'boolean)
446
447 (defcustom gnus-summary-ignore-duplicates nil
448   "*If non-nil, ignore articles with identical Message-ID headers."
449   :group 'gnus-summary
450   :type 'boolean)
451
452 (defcustom gnus-single-article-buffer t
453   "*If non-nil, display all articles in the same buffer.
454 If nil, each group will get its own article buffer."
455   :group 'gnus-article-various
456   :type 'boolean)
457
458 (defcustom gnus-break-pages t
459   "*If non-nil, do page breaking on articles.
460 The page delimiter is specified by the `gnus-page-delimiter'
461 variable."
462   :group 'gnus-article-various
463   :type 'boolean)
464
465 (defcustom gnus-move-split-methods nil
466   "*Variable used to suggest where articles are to be moved to.
467 It uses the same syntax as the `gnus-split-methods' variable.
468 However, whereas `gnus-split-methods' specifies file names as targets,
469 this variable specifies group names."
470   :group 'gnus-summary-mail
471   :type '(repeat (choice (list :value (fun) function)
472                          (cons :value ("" "") regexp (repeat string))
473                          (sexp :value nil))))
474
475 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
476   "Function used to compute default prefix for article move/copy/etc prompts.
477 The function should take one argument, a group name, and return a
478 string with the suggested prefix."
479   :group 'gnus-summary-mail
480   :type 'function)
481
482 ;; FIXME: Although the custom type is `character' for the following variables,
483 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
484
485 (defcustom gnus-unread-mark ?           ;Whitespace
486   "*Mark used for unread articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-ticked-mark ?!
491   "*Mark used for ticked articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-dormant-mark ??
496   "*Mark used for dormant articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-del-mark ?r
501   "*Mark used for del'd articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-read-mark ?R
506   "*Mark used for read articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-expirable-mark ?E
511   "*Mark used for expirable articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-killed-mark ?K
516   "*Mark used for killed articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-spam-mark ?$
521   "*Mark used for spam articles."
522   :version "22.1"
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-souped-mark ?F
527   "*Mark used for souped articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-kill-file-mark ?X
532   "*Mark used for articles killed by kill files."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-low-score-mark ?Y
537   "*Mark used for articles with a low score."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-catchup-mark ?C
542   "*Mark used for articles that are caught up."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-replied-mark ?A
547   "*Mark used for articles that have been replied to."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-forwarded-mark ?F
552   "*Mark used for articles that have been forwarded."
553   :version "22.1"
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-recent-mark ?N
558   "*Mark used for articles that are recent."
559   :version "22.1"
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-cached-mark ?*
564   "*Mark used for articles that are in the cache."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-saved-mark ?S
569   "*Mark used for articles that have been saved."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-unseen-mark ?.
574   "*Mark used for articles that haven't been seen."
575   :version "22.1"
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-no-mark ?               ;Whitespace
580   "*Mark used for articles that have no other secondary mark."
581   :version "22.1"
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-ancient-mark ?O
586   "*Mark used for ancient articles."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-sparse-mark ?Q
591   "*Mark used for sparsely reffed articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-canceled-mark ?G
596   "*Mark used for canceled articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-duplicate-mark ?M
601   "*Mark used for duplicate articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-undownloaded-mark ?-
606   "*Mark used for articles that weren't downloaded."
607   :version "22.1"
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-downloaded-mark ?+
612   "*Mark used for articles that were downloaded."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloadable-mark ?%
617   "*Mark used for articles that are to be downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-unsendable-mark ?=
622   "*Mark used for articles that won't be sent."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-score-over-mark ?+
627   "*Score mark used for articles with high scores."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-below-mark ?-
632   "*Score mark used for articles with low scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-empty-thread-mark ?     ;Whitespace
637   "*There is no thread under the article."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-not-empty-thread-mark ?=
642   "*There is a thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-view-pseudo-asynchronously nil
647   "*If non-nil, Gnus will view pseudo-articles asynchronously."
648   :group 'gnus-extract-view
649   :type 'boolean)
650
651 (defcustom gnus-auto-expirable-marks
652   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
653         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
654         gnus-souped-mark gnus-duplicate-mark)
655   "*The list of marks converted into expiration if a group is auto-expirable."
656   :version "21.1"
657   :group 'gnus-summary
658   :type '(repeat character))
659
660 (defcustom gnus-inhibit-user-auto-expire t
661   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
662   :version "21.1"
663   :group 'gnus-summary
664   :type 'boolean)
665
666 (defcustom gnus-view-pseudos nil
667   "*If `automatic', pseudo-articles will be viewed automatically.
668 If `not-confirm', pseudos will be viewed automatically, and the user
669 will not be asked to confirm the command."
670   :group 'gnus-extract-view
671   :type '(choice (const :tag "off" nil)
672                  (const automatic)
673                  (const not-confirm)))
674
675 (defcustom gnus-view-pseudos-separately t
676   "*If non-nil, one pseudo-article will be created for each file to be viewed.
677 If nil, all files that use the same viewing command will be given as a
678 list of parameters to that command."
679   :group 'gnus-extract-view
680   :type 'boolean)
681
682 (defcustom gnus-insert-pseudo-articles t
683   "*If non-nil, insert pseudo-articles when decoding articles."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-summary-dummy-line-format
688   "   %(:                             :%) %S\n"
689   "*The format specification for the dummy roots in the summary buffer.
690 It works along the same lines as a normal formatting string,
691 with some simple extensions.
692
693 %S  The subject
694
695 General format specifiers can also be used.
696 See `(gnus)Formatting Variables'."
697   :link '(custom-manual "(gnus)Formatting Variables")
698   :group 'gnus-threading
699   :type 'string)
700
701 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
702   "*The format specification for the summary mode line.
703 It works along the same lines as a normal formatting string,
704 with some simple extensions:
705
706 %G  Group name
707 %p  Unprefixed group name
708 %A  Current article number
709 %z  Current article score
710 %V  Gnus version
711 %U  Number of unread articles in the group
712 %e  Number of unselected articles in the group
713 %Z  A string with unread/unselected article counts
714 %g  Shortish group name
715 %S  Subject of the current article
716 %u  User-defined spec
717 %s  Current score file name
718 %d  Number of dormant articles
719 %r  Number of articles that have been marked as read in this session
720 %E  Number of articles expunged by the score files"
721   :group 'gnus-summary-format
722   :type 'string)
723
724 (defcustom gnus-list-identifiers nil
725   "Regexp that matches list identifiers to be removed from subject.
726 This can also be a list of regexps."
727   :version "21.1"
728   :group 'gnus-summary-format
729   :group 'gnus-article-hiding
730   :type '(choice (const :tag "none" nil)
731                  (regexp :value ".*")
732                  (repeat :value (".*") regexp)))
733
734 (defcustom gnus-summary-mark-below 0
735   "*Mark all articles with a score below this variable as read.
736 This variable is local to each summary buffer and usually set by the
737 score file."
738   :group 'gnus-score-default
739   :type 'integer)
740
741 (defun gnus-widget-reversible-match (widget value)
742   "Ignoring WIDGET, convert VALUE to internal form.
743 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
744   ;; (debug value)
745   (or (symbolp value)
746       (and (listp value)
747            (eq (length value) 2)
748            (eq (nth 0 value) 'not)
749            (symbolp (nth 1 value)))))
750
751 (defun gnus-widget-reversible-to-internal (widget value)
752   "Ignoring WIDGET, convert VALUE to internal form.
753 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
754 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
755   ;; (debug value)
756   (if (atom value)
757       (list value nil)
758     (list (nth 1 value) t)))
759
760 (defun gnus-widget-reversible-to-external (widget value)
761   "Ignoring WIDGET, convert VALUE to external form.
762 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
763 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
764   ;; (debug value)
765   (if (nth 1 value)
766       (list 'not (nth 0 value))
767     (nth 0 value)))
768
769 (define-widget 'gnus-widget-reversible 'group
770   "A `group' that convert values."
771   :match 'gnus-widget-reversible-match
772   :value-to-internal 'gnus-widget-reversible-to-internal
773   :value-to-external 'gnus-widget-reversible-to-external)
774
775 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
776   "*List of functions used for sorting articles in the summary buffer.
777
778 Each function takes two articles and returns non-nil if the first
779 article should be sorted before the other.  If you use more than one
780 function, the primary sort function should be the last.  You should
781 probably always include `gnus-article-sort-by-number' in the list of
782 sorting functions -- preferably first.  Also note that sorting by date
783 is often much slower than sorting by number, and the sorting order is
784 very similar.  (Sorting by date means sorting by the time the message
785 was sent, sorting by number means sorting by arrival time.)
786
787 Each item can also be a list `(not F)' where F is a function;
788 this reverses the sort order.
789
790 Ready-made functions include `gnus-article-sort-by-number',
791 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
792 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
793 and `gnus-article-sort-by-score'.
794
795 When threading is turned on, the variable `gnus-thread-sort-functions'
796 controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat (gnus-widget-reversible
799                   (choice (function-item gnus-article-sort-by-number)
800                           (function-item gnus-article-sort-by-author)
801                           (function-item gnus-article-sort-by-subject)
802                           (function-item gnus-article-sort-by-date)
803                           (function-item gnus-article-sort-by-score)
804                           (function-item gnus-article-sort-by-random)
805                           (function :tag "other"))
806                   (boolean :tag "Reverse order"))))
807
808
809 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
810   "*List of functions used for sorting threads in the summary buffer.
811 By default, threads are sorted by article number.
812
813 Each function takes two threads and returns non-nil if the first
814 thread should be sorted before the other.  If you use more than one
815 function, the primary sort function should be the last.  You should
816 probably always include `gnus-thread-sort-by-number' in the list of
817 sorting functions -- preferably first.  Also note that sorting by date
818 is often much slower than sorting by number, and the sorting order is
819 very similar.  (Sorting by date means sorting by the time the message
820 was sent, sorting by number means sorting by arrival time.)
821
822 Each list item can also be a list `(not F)' where F is a
823 function; this specifies reversed sort order.
824
825 Ready-made functions include `gnus-thread-sort-by-number',
826 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
827 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
828 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
829 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
830 and `gnus-thread-sort-by-total-score' (see
831 `gnus-thread-score-function').
832
833 When threading is turned off, the variable
834 `gnus-article-sort-functions' controls how articles are sorted."
835   :group 'gnus-summary-sort
836   :type '(repeat
837           (gnus-widget-reversible
838            (choice (function-item gnus-thread-sort-by-number)
839                    (function-item gnus-thread-sort-by-author)
840                    (function-item gnus-thread-sort-by-recipient)
841                    (function-item gnus-thread-sort-by-subject)
842                    (function-item gnus-thread-sort-by-date)
843                    (function-item gnus-thread-sort-by-score)
844                    (function-item gnus-thread-sort-by-most-recent-number)
845                    (function-item gnus-thread-sort-by-most-recent-date)
846                    (function-item gnus-thread-sort-by-random)
847                    (function-item gnus-thread-sort-by-total-score)
848                    (function :tag "other"))
849            (boolean :tag "Reverse order"))))
850
851 (defcustom gnus-thread-score-function '+
852   "*Function used for calculating the total score of a thread.
853
854 The function is called with the scores of the article and each
855 subthread and should then return the score of the thread.
856
857 Some functions you can use are `+', `max', or `min'."
858   :group 'gnus-summary-sort
859   :type 'function)
860
861 (defcustom gnus-summary-expunge-below nil
862   "All articles that have a score less than this variable will be expunged.
863 This variable is local to the summary buffers."
864   :group 'gnus-score-default
865   :type '(choice (const :tag "off" nil)
866                  integer))
867
868 (defcustom gnus-thread-expunge-below nil
869   "All threads that have a total score less than this variable will be expunged.
870 See `gnus-thread-score-function' for en explanation of what a
871 \"thread score\" is.
872
873 This variable is local to the summary buffers."
874   :group 'gnus-threading
875   :group 'gnus-score-default
876   :type '(choice (const :tag "off" nil)
877                  integer))
878
879 (defcustom gnus-summary-mode-hook nil
880   "*A hook for Gnus summary mode.
881 This hook is run before any variables are set in the summary buffer."
882   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
883   :group 'gnus-summary-various
884   :type 'hook)
885
886 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
887 (when (featurep 'xemacs)
888   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
889   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
890   (add-hook 'gnus-summary-mode-hook
891             'gnus-xmas-switch-horizontal-scrollbar-off))
892
893 (defcustom gnus-summary-menu-hook nil
894   "*Hook run after the creation of the summary mode menu."
895   :group 'gnus-summary-visual
896   :type 'hook)
897
898 (defcustom gnus-summary-exit-hook nil
899   "*A hook called on exit from the summary buffer.
900 It will be called with point in the group buffer."
901   :group 'gnus-summary-exit
902   :type 'hook)
903
904 (defcustom gnus-summary-prepare-hook nil
905   "*A hook called after the summary buffer has been generated.
906 If you want to modify the summary buffer, you can use this hook."
907   :group 'gnus-summary-various
908   :type 'hook)
909
910 (defcustom gnus-summary-prepared-hook nil
911   "*A hook called as the last thing after the summary buffer has been generated."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-generate-hook nil
916   "*A hook run just before generating the summary buffer.
917 This hook is commonly used to customize threading variables and the
918 like."
919   :group 'gnus-summary-various
920   :type 'hook)
921
922 (defcustom gnus-select-group-hook nil
923   "*A hook called when a newsgroup is selected.
924
925 If you'd like to simplify subjects like the
926 `gnus-summary-next-same-subject' command does, you can use the
927 following hook:
928
929  (add-hook gnus-select-group-hook
930            (lambda ()
931              (mapcar (lambda (header)
932                        (mail-header-set-subject
933                         header
934                         (gnus-simplify-subject
935                          (mail-header-subject header) 're-only)))
936                      gnus-newsgroup-headers)))"
937   :group 'gnus-group-select
938   :type 'hook)
939
940 (defcustom gnus-select-article-hook nil
941   "*A hook called when an article is selected."
942   :group 'gnus-summary-choose
943   :options '(gnus-agent-fetch-selected-article)
944   :type 'hook)
945
946 (defcustom gnus-visual-mark-article-hook
947   (list 'gnus-highlight-selected-summary)
948   "*Hook run after selecting an article in the summary buffer.
949 It is meant to be used for highlighting the article in some way.  It
950 is not run if `gnus-visual' is nil."
951   :group 'gnus-summary-visual
952   :type 'hook)
953
954 (defcustom gnus-parse-headers-hook nil
955   "*A hook called before parsing the headers."
956   :group 'gnus-various
957   :type 'hook)
958
959 (defcustom gnus-exit-group-hook nil
960   "*A hook called when exiting summary mode.
961 This hook is not called from the non-updating exit commands like `Q'."
962   :group 'gnus-various
963   :type 'hook)
964
965 (defcustom gnus-summary-update-hook
966   (list 'gnus-summary-highlight-line)
967   "*A hook called when a summary line is changed.
968 The hook will not be called if `gnus-visual' is nil.
969
970 The default function `gnus-summary-highlight-line' will
971 highlight the line according to the `gnus-summary-highlight'
972 variable."
973   :group 'gnus-summary-visual
974   :type 'hook)
975
976 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
977   "*A hook called when an article is selected for the first time.
978 The hook is intended to mark an article as read (or unread)
979 automatically when it is selected."
980   :group 'gnus-summary-choose
981   :type 'hook)
982
983 (defcustom gnus-group-no-more-groups-hook nil
984   "*A hook run when returning to group mode having no more (unread) groups."
985   :group 'gnus-group-select
986   :type 'hook)
987
988 (defcustom gnus-ps-print-hook nil
989   "*A hook run before ps-printing something from Gnus."
990   :group 'gnus-summary
991   :type 'hook)
992
993 (defcustom gnus-summary-article-move-hook nil
994   "*A hook called after an article is moved, copied, respooled, or crossposted."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'hook)
998
999 (defcustom gnus-summary-article-delete-hook nil
1000   "*A hook called after an article is deleted."
1001   :version "22.1"
1002   :group 'gnus-summary
1003   :type 'hook)
1004
1005 (defcustom gnus-summary-article-expire-hook nil
1006   "*A hook called after an article is expired."
1007   :version "22.1"
1008   :group 'gnus-summary
1009   :type 'hook)
1010
1011 (defcustom gnus-summary-display-arrow
1012   (and (fboundp 'display-graphic-p)
1013        (display-graphic-p))
1014   "*If non-nil, display an arrow highlighting the current article."
1015   :version "22.1"
1016   :group 'gnus-summary
1017   :type 'boolean)
1018
1019 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1020   "Face used for highlighting the current article in the summary buffer."
1021   :group 'gnus-summary-visual
1022   :type 'face)
1023
1024 (defvar gnus-tmp-downloaded nil)
1025
1026 (defcustom gnus-summary-highlight
1027   '(((eq mark gnus-canceled-mark)
1028      . gnus-summary-cancelled)
1029     ((and uncached (> score default-high))
1030      . gnus-summary-high-undownloaded)
1031     ((and uncached (< score default-low))
1032      . gnus-summary-low-undownloaded)
1033     (uncached
1034      . gnus-summary-normal-undownloaded)
1035     ((and (> score default-high)
1036           (or (eq mark gnus-dormant-mark)
1037               (eq mark gnus-ticked-mark)))
1038      . gnus-summary-high-ticked)
1039     ((and (< score default-low)
1040           (or (eq mark gnus-dormant-mark)
1041               (eq mark gnus-ticked-mark)))
1042      . gnus-summary-low-ticked)
1043     ((or (eq mark gnus-dormant-mark)
1044          (eq mark gnus-ticked-mark))
1045      . gnus-summary-normal-ticked)
1046     ((and (> score default-high) (eq mark gnus-ancient-mark))
1047      . gnus-summary-high-ancient)
1048     ((and (< score default-low) (eq mark gnus-ancient-mark))
1049      . gnus-summary-low-ancient)
1050     ((eq mark gnus-ancient-mark)
1051      . gnus-summary-normal-ancient)
1052     ((and (> score default-high) (eq mark gnus-unread-mark))
1053      . gnus-summary-high-unread)
1054     ((and (< score default-low) (eq mark gnus-unread-mark))
1055      . gnus-summary-low-unread)
1056     ((eq mark gnus-unread-mark)
1057      . gnus-summary-normal-unread)
1058     ((> score default-high)
1059      . gnus-summary-high-read)
1060     ((< score default-low)
1061      . gnus-summary-low-read)
1062     (t
1063      . gnus-summary-normal-read))
1064   "*Controls the highlighting of summary buffer lines.
1065
1066 A list of (FORM . FACE) pairs.  When deciding how a particular
1067 summary line should be displayed, each form is evaluated.  The content
1068 of the face field after the first true form is used.  You can change
1069 how those summary lines are displayed, by editing the face field.
1070
1071 You can use the following variables in the FORM field.
1072
1073 score:        The article's score.
1074 default:      The default article score.
1075 default-high: The default score for high scored articles.
1076 default-low:  The default score for low scored articles.
1077 below:        The score below which articles are automatically marked as read.
1078 mark:         The article's mark.
1079 uncached:     Non-nil if the article is uncached."
1080   :group 'gnus-summary-visual
1081   :type '(repeat (cons (sexp :tag "Form" nil)
1082                        face)))
1083
1084 (defcustom gnus-alter-header-function nil
1085   "Function called to allow alteration of article header structures.
1086 The function is called with one parameter, the article header vector,
1087 which it may alter in any way."
1088   :type '(choice (const :tag "None" nil)
1089                  function)
1090   :group 'gnus-summary)
1091
1092 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1093   "Function used to decode a string with encoded words.")
1094
1095 (defvar gnus-decode-encoded-address-function
1096   'mail-decode-encoded-address-string
1097   "Function used to decode addresses with encoded words.")
1098
1099 (defcustom gnus-extra-headers '(To Newsgroups)
1100   "*Extra headers to parse."
1101   :version "21.1"
1102   :group 'gnus-summary
1103   :type '(repeat symbol))
1104
1105 (defcustom gnus-ignored-from-addresses
1106   (and user-mail-address
1107        (not (string= user-mail-address ""))
1108        (regexp-quote user-mail-address))
1109   "*From headers that may be suppressed in favor of To headers.
1110 This can be a regexp or a list of regexps."
1111   :version "21.1"
1112   :group 'gnus-summary
1113   :type '(choice regexp
1114                  (repeat :tag "Regexp List" regexp)))
1115
1116 (defsubst gnus-ignored-from-addresses ()
1117   (gmm-regexp-concat gnus-ignored-from-addresses))
1118
1119 (defcustom gnus-summary-to-prefix "-> "
1120   "*String prefixed to the To field in the summary line when
1121 using `gnus-ignored-from-addresses'."
1122   :version "22.1"
1123   :group 'gnus-summary
1124   :type 'string)
1125
1126 (defcustom gnus-summary-newsgroup-prefix "=> "
1127   "*String prefixed to the Newsgroup field in the summary
1128 line when using `gnus-ignored-from-addresses'."
1129   :version "22.1"
1130   :group 'gnus-summary
1131   :type 'string)
1132
1133 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1134   "List of charsets that should be ignored.
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead."
1137   :version "21.1"
1138   :type '(repeat symbol)
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-newsgroup-maximum-articles nil
1142   "The maximum number of articles a newsgroup.
1143 If this is a number, old articles in a newsgroup exceeding this number
1144 are silently ignored.  If it is nil, no article is ignored.  Note that
1145 setting this variable to a number might prevent you from reading very
1146 old articles."
1147   :group 'gnus-group-select
1148   :version "22.2"
1149   :type '(choice (const :tag "No limit" nil)
1150                  integer))
1151
1152 (gnus-define-group-parameter
1153  ignored-charsets
1154  :type list
1155  :function-document
1156  "Return the ignored charsets of GROUP."
1157  :variable gnus-group-ignored-charsets-alist
1158  :variable-default
1159  '(("alt\\.chinese\\.text" iso-8859-1))
1160  :variable-document
1161  "Alist of regexps (to match group names) and charsets that should be ignored.
1162 When these charsets are used in the \"charset\" parameter, the
1163 default charset will be used instead."
1164  :variable-group gnus-charset
1165  :variable-type '(repeat (cons (regexp :tag "Group")
1166                                (repeat symbol)))
1167  :parameter-type '(choice :tag "Ignored charsets"
1168                           :value nil
1169                           (repeat (symbol)))
1170  :parameter-document       "\
1171 List of charsets that should be ignored.
1172
1173 When these charsets are used in the \"charset\" parameter, the
1174 default charset will be used instead.")
1175
1176 (defcustom gnus-group-highlight-words-alist nil
1177   "Alist of group regexps and highlight regexps.
1178 This variable uses the same syntax as `gnus-emphasis-alist'."
1179   :version "21.1"
1180   :type '(repeat (cons (regexp :tag "Group")
1181                        (repeat (list (regexp :tag "Highlight regexp")
1182                                      (number :tag "Group for entire word" 0)
1183                                      (number :tag "Group for displayed part" 0)
1184                                      (symbol :tag "Face"
1185                                              gnus-emphasis-highlight-words)))))
1186   :group 'gnus-summary-visual)
1187
1188 (defcustom gnus-summary-show-article-charset-alist
1189   nil
1190   "Alist of number and charset.
1191 The article will be shown with the charset corresponding to the
1192 numbered argument.
1193 For example: ((1 . cn-gb-2312) (2 . big5))."
1194   :version "21.1"
1195   :type '(repeat (cons (number :tag "Argument" 1)
1196                        (symbol :tag "Charset")))
1197   :group 'gnus-charset)
1198
1199 (defcustom gnus-preserve-marks t
1200   "Whether marks are preserved when moving, copying and respooling messages."
1201   :version "21.1"
1202   :type 'boolean
1203   :group 'gnus-summary-marks)
1204
1205 (defcustom gnus-alter-articles-to-read-function nil
1206   "Function to be called to alter the list of articles to be selected."
1207   :type '(choice (const nil) function)
1208   :group 'gnus-summary)
1209
1210 (defcustom gnus-orphan-score nil
1211   "*All orphans get this score added.  Set in the score file."
1212   :group 'gnus-score-default
1213   :type '(choice (const nil)
1214                  integer))
1215
1216 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1217   "*A regexp to match MIME parts when saving multiple parts of a
1218 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1219 This regexp will be used by default when prompting the user for which
1220 type of files to save."
1221   :group 'gnus-summary
1222   :type 'regexp)
1223
1224 (defcustom gnus-read-all-available-headers nil
1225   "Whether Gnus should parse all headers made available to it.
1226 This is mostly relevant for slow back ends where the user may
1227 wish to widen the summary buffer to include all headers
1228 that were fetched.  Say, for nnultimate groups."
1229   :version "22.1"
1230   :group 'gnus-summary
1231   :type '(choice boolean regexp))
1232
1233 (defcustom gnus-summary-muttprint-program "muttprint"
1234   "Command (and optional arguments) used to run Muttprint."
1235   :version "22.1"
1236   :group 'gnus-summary
1237   :type 'string)
1238
1239 (defcustom gnus-article-loose-mime t
1240   "If non-nil, don't require MIME-Version header.
1241 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1242 supply the MIME-Version header or deliberately strip it from the mail.
1243 If non-nil (the default), Gnus will treat some articles as MIME
1244 even if the MIME-Version header is missing."
1245   :version "22.1"
1246   :type 'boolean
1247   :group 'gnus-article-mime)
1248
1249 (defcustom gnus-article-emulate-mime t
1250   "If non-nil, use MIME emulation for uuencode and the like.
1251 This means that Gnus will search message bodies for text that look
1252 like uuencoded bits, yEncoded bits, and so on, and present that using
1253 the normal Gnus MIME machinery."
1254   :version "22.1"
1255   :type 'boolean
1256   :group 'gnus-article-mime)
1257
1258 ;;; Internal variables
1259
1260 (defvar gnus-summary-display-cache nil)
1261 (defvar gnus-article-mime-handles nil)
1262 (defvar gnus-article-decoded-p nil)
1263 (defvar gnus-article-charset nil)
1264 (defvar gnus-article-ignored-charsets nil)
1265 (defvar gnus-scores-exclude-files nil)
1266 (defvar gnus-page-broken nil)
1267
1268 (defvar gnus-original-article nil)
1269 (defvar gnus-article-internal-prepare-hook nil)
1270 (defvar gnus-newsgroup-process-stack nil)
1271
1272 (defvar gnus-thread-indent-array nil)
1273 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1274 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1275   "Function called to sort the articles within a thread after it has been gathered together.")
1276
1277 (defvar gnus-summary-save-parts-type-history nil)
1278 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1279
1280 ;; Avoid highlighting in kill files.
1281 (defvar gnus-summary-inhibit-highlight nil)
1282 (defvar gnus-newsgroup-selected-overlay nil)
1283 (defvar gnus-inhibit-limiting nil)
1284 (defvar gnus-newsgroup-adaptive-score-file nil)
1285 (defvar gnus-current-score-file nil)
1286 (defvar gnus-current-move-group nil)
1287 (defvar gnus-current-copy-group nil)
1288 (defvar gnus-current-crosspost-group nil)
1289 (defvar gnus-newsgroup-display nil)
1290
1291 (defvar gnus-newsgroup-dependencies nil)
1292 (defvar gnus-newsgroup-adaptive nil)
1293 (defvar gnus-summary-display-article-function nil)
1294 (defvar gnus-summary-highlight-line-function nil
1295   "Function called after highlighting a summary line.")
1296
1297 (defvar gnus-summary-line-format-alist
1298   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1299     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1300     (?s gnus-tmp-subject-or-nil ?s)
1301     (?n gnus-tmp-name ?s)
1302     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1303         ?s)
1304     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1305             gnus-tmp-from) ?s)
1306     (?F gnus-tmp-from ?s)
1307     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1308     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1309     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1310     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1311     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1312     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1313     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1314     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1315     (?L gnus-tmp-lines ?s)
1316     (?O gnus-tmp-downloaded ?c)
1317     (?I gnus-tmp-indentation ?s)
1318     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1319     (?R gnus-tmp-replied ?c)
1320     (?\[ gnus-tmp-opening-bracket ?c)
1321     (?\] gnus-tmp-closing-bracket ?c)
1322     (?\> (make-string gnus-tmp-level ? ) ?s)
1323     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1324     (?i gnus-tmp-score ?d)
1325     (?z gnus-tmp-score-char ?c)
1326     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1327     (?U gnus-tmp-unread ?c)
1328     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1329         ?s)
1330     (?t (gnus-summary-number-of-articles-in-thread
1331          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1332         ?d)
1333     (?e (gnus-summary-number-of-articles-in-thread
1334          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1335         ?c)
1336     (?u gnus-tmp-user-defined ?s)
1337     (?P (gnus-pick-line-number) ?d)
1338     (?B gnus-tmp-thread-tree-header-string ?s)
1339     (user-date (gnus-user-date
1340                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1341   "An alist of format specifications that can appear in summary lines.
1342 These are paired with what variables they correspond with, along with
1343 the type of the variable (string, integer, character, etc).")
1344
1345 (defvar gnus-summary-dummy-line-format-alist
1346   `((?S gnus-tmp-subject ?s)
1347     (?N gnus-tmp-number ?d)
1348     (?u gnus-tmp-user-defined ?s)))
1349
1350 (defvar gnus-summary-mode-line-format-alist
1351   `((?G gnus-tmp-group-name ?s)
1352     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1353     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1354     (?A gnus-tmp-article-number ?d)
1355     (?Z gnus-tmp-unread-and-unselected ?s)
1356     (?V gnus-version ?s)
1357     (?U gnus-tmp-unread-and-unticked ?d)
1358     (?S gnus-tmp-subject ?s)
1359     (?e gnus-tmp-unselected ?d)
1360     (?u gnus-tmp-user-defined ?s)
1361     (?d (length gnus-newsgroup-dormant) ?d)
1362     (?t (length gnus-newsgroup-marked) ?d)
1363     (?h (length gnus-newsgroup-spam-marked) ?d)
1364     (?r (length gnus-newsgroup-reads) ?d)
1365     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1366     (?E gnus-newsgroup-expunged-tally ?d)
1367     (?s (gnus-current-score-file-nondirectory) ?s)))
1368
1369 (defvar gnus-last-search-regexp nil
1370   "Default regexp for article search command.")
1371
1372 (defvar gnus-last-shell-command nil
1373   "Default shell command on article.")
1374
1375 (defvar gnus-newsgroup-agentized nil
1376   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1377 (defvar gnus-newsgroup-begin nil)
1378 (defvar gnus-newsgroup-end nil)
1379 (defvar gnus-newsgroup-last-rmail nil)
1380 (defvar gnus-newsgroup-last-mail nil)
1381 (defvar gnus-newsgroup-last-folder nil)
1382 (defvar gnus-newsgroup-last-file nil)
1383 (defvar gnus-newsgroup-last-directory nil)
1384 (defvar gnus-newsgroup-auto-expire nil)
1385 (defvar gnus-newsgroup-active nil)
1386
1387 (defvar gnus-newsgroup-data nil)
1388 (defvar gnus-newsgroup-data-reverse nil)
1389 (defvar gnus-newsgroup-limit nil)
1390 (defvar gnus-newsgroup-limits nil)
1391 (defvar gnus-summary-use-undownloaded-faces nil)
1392
1393 (defvar gnus-newsgroup-unreads nil
1394   "Sorted list of unread articles in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-unselected nil
1397   "Sorted list of unselected unread articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-reads nil
1400   "Alist of read articles and article marks in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-expunged-tally nil)
1403
1404 (defvar gnus-newsgroup-marked nil
1405   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1406
1407 (defvar gnus-newsgroup-spam-marked nil
1408   "List of ranges of articles that have been marked as spam.")
1409
1410 (defvar gnus-newsgroup-killed nil
1411   "List of ranges of articles that have been through the scoring process.")
1412
1413 (defvar gnus-newsgroup-cached nil
1414   "Sorted list of articles that come from the article cache.")
1415
1416 (defvar gnus-newsgroup-saved nil
1417   "List of articles that have been saved.")
1418
1419 (defvar gnus-newsgroup-kill-headers nil)
1420
1421 (defvar gnus-newsgroup-replied nil
1422   "List of articles that have been replied to in the current newsgroup.")
1423
1424 (defvar gnus-newsgroup-forwarded nil
1425   "List of articles that have been forwarded in the current newsgroup.")
1426
1427 (defvar gnus-newsgroup-recent nil
1428   "List of articles that have are recent in the current newsgroup.")
1429
1430 (defvar gnus-newsgroup-expirable nil
1431   "Sorted list of articles in the current newsgroup that can be expired.")
1432
1433 (defvar gnus-newsgroup-processable nil
1434   "List of articles in the current newsgroup that can be processed.")
1435
1436 (defvar gnus-newsgroup-downloadable nil
1437   "Sorted list of articles in the current newsgroup that can be processed.")
1438
1439 (defvar gnus-newsgroup-unfetched nil
1440   "Sorted list of articles in the current newsgroup whose headers have
1441 not been fetched into the agent.
1442
1443 This list will always be a subset of gnus-newsgroup-undownloaded.")
1444
1445 (defvar gnus-newsgroup-undownloaded nil
1446   "List of articles in the current newsgroup that haven't been downloaded.")
1447
1448 (defvar gnus-newsgroup-unsendable nil
1449   "List of articles in the current newsgroup that won't be sent.")
1450
1451 (defvar gnus-newsgroup-bookmarks nil
1452   "List of articles in the current newsgroup that have bookmarks.")
1453
1454 (defvar gnus-newsgroup-dormant nil
1455   "Sorted list of dormant articles in the current newsgroup.")
1456
1457 (defvar gnus-newsgroup-unseen nil
1458   "List of unseen articles in the current newsgroup.")
1459
1460 (defvar gnus-newsgroup-seen nil
1461   "Range of seen articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-articles nil
1464   "List of articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-scored nil
1467   "List of scored articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-headers nil
1470   "List of article headers in the current newsgroup.")
1471
1472 (defvar gnus-newsgroup-threads nil)
1473
1474 (defvar gnus-newsgroup-prepared nil
1475   "Whether the current group has been prepared properly.")
1476
1477 (defvar gnus-newsgroup-ancient nil
1478   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1479
1480 (defvar gnus-newsgroup-sparse nil)
1481
1482 (defvar gnus-current-article nil)
1483 (defvar gnus-article-current nil)
1484 (defvar gnus-current-headers nil)
1485 (defvar gnus-have-all-headers nil)
1486 (defvar gnus-last-article nil)
1487 (defvar gnus-newsgroup-history nil)
1488 (defvar gnus-newsgroup-charset nil)
1489 (defvar gnus-newsgroup-ephemeral-charset nil)
1490 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1491
1492 (defvar gnus-article-before-search nil)
1493
1494 (defvar gnus-summary-local-variables
1495   '(gnus-newsgroup-name
1496     gnus-newsgroup-begin gnus-newsgroup-end
1497     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1498     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1499     gnus-newsgroup-last-directory
1500     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1501     gnus-newsgroup-unselected gnus-newsgroup-marked
1502     gnus-newsgroup-spam-marked
1503     gnus-newsgroup-reads gnus-newsgroup-saved
1504     gnus-newsgroup-replied gnus-newsgroup-forwarded
1505     gnus-newsgroup-recent
1506     gnus-newsgroup-expirable
1507     gnus-newsgroup-processable gnus-newsgroup-killed
1508     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1509     gnus-newsgroup-unfetched
1510     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1511     gnus-newsgroup-seen gnus-newsgroup-articles
1512     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1513     gnus-newsgroup-headers gnus-newsgroup-threads
1514     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1515     gnus-current-article gnus-current-headers gnus-have-all-headers
1516     gnus-last-article gnus-article-internal-prepare-hook
1517     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1518     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1519     gnus-thread-expunge-below
1520     gnus-score-alist gnus-current-score-file
1521     (gnus-summary-expunge-below . global)
1522     (gnus-summary-mark-below . global)
1523     (gnus-orphan-score . global)
1524     gnus-newsgroup-active gnus-scores-exclude-files
1525     gnus-newsgroup-history gnus-newsgroup-ancient
1526     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1527     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1528     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1529     (gnus-newsgroup-expunged-tally . 0)
1530     gnus-cache-removable-articles gnus-newsgroup-cached
1531     gnus-newsgroup-data gnus-newsgroup-data-reverse
1532     gnus-newsgroup-limit gnus-newsgroup-limits
1533     gnus-newsgroup-charset gnus-newsgroup-display
1534     gnus-summary-use-undownloaded-faces)
1535   "Variables that are buffer-local to the summary buffers.")
1536
1537 (defvar gnus-newsgroup-variables nil
1538   "A list of variables that have separate values in different newsgroups.
1539 A list of newsgroup (summary buffer) local variables, or cons of
1540 variables and their default expressions to be evalled (when the default
1541 values are not nil), that should be made global while the summary buffer
1542 is active.
1543
1544 Note: The default expressions will be evaluated (using function `eval')
1545 before assignment to the local variable rather than just assigned to it.
1546 If the default expression is the symbol `global', that symbol will not
1547 be evaluated but the global value of the local variable will be used
1548 instead.
1549
1550 These variables can be used to set variables in the group parameters
1551 while still allowing them to affect operations done in other buffers.
1552 For example:
1553
1554 \(setq gnus-newsgroup-variables
1555      '(message-use-followup-to
1556        (gnus-visible-headers .
1557          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1558 ")
1559
1560 ;; Byte-compiler warning.
1561 (eval-when-compile
1562   ;; Bind features so that require will believe that gnus-sum has
1563   ;; already been loaded (avoids infinite recursion)
1564   (let ((features (cons 'gnus-sum features)))
1565     ;; Several of the declarations in gnus-sum are needed to load the
1566     ;; following files. Right now, these definitions have been
1567     ;; compiled but not defined (evaluated).  We could either do a
1568     ;; eval-and-compile about all of the declarations or evaluate the
1569     ;; source file.
1570     (if (boundp 'gnus-newsgroup-variables)
1571         nil
1572       (load "gnus-sum.el" t t t))
1573     (require 'gnus)
1574     (require 'gnus-art)))
1575
1576 ;; MIME stuff.
1577
1578 (defvar gnus-decode-encoded-word-methods
1579   '(mail-decode-encoded-word-string)
1580   "List of methods used to decode encoded words.
1581
1582 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1583 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1584 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1585 whose names match REGEXP.
1586
1587 For example:
1588 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1589  mail-decode-encoded-word-string
1590  (\"chinese\" . rfc1843-decode-string))")
1591
1592 (defvar gnus-decode-encoded-word-methods-cache nil)
1593
1594 (defun gnus-multi-decode-encoded-word-string (string)
1595   "Apply the functions from `gnus-encoded-word-methods' that match."
1596   (unless (and gnus-decode-encoded-word-methods-cache
1597                (eq gnus-newsgroup-name
1598                    (car gnus-decode-encoded-word-methods-cache)))
1599     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1600     (mapcar (lambda (x)
1601               (if (symbolp x)
1602                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1603                 (if (and gnus-newsgroup-name
1604                          (string-match (car x) gnus-newsgroup-name))
1605                     (nconc gnus-decode-encoded-word-methods-cache
1606                            (list (cdr x))))))
1607             gnus-decode-encoded-word-methods))
1608   (let ((xlist gnus-decode-encoded-word-methods-cache))
1609     (pop xlist)
1610     (while xlist
1611       (setq string (funcall (pop xlist) string))))
1612   string)
1613
1614 ;; Subject simplification.
1615
1616 (defun gnus-simplify-whitespace (str)
1617   "Remove excessive whitespace from STR."
1618   ;; Multiple spaces.
1619   (while (string-match "[ \t][ \t]+" str)
1620     (setq str (concat (substring str 0 (match-beginning 0))
1621                         " "
1622                         (substring str (match-end 0)))))
1623   ;; Leading spaces.
1624   (when (string-match "^[ \t]+" str)
1625     (setq str (substring str (match-end 0))))
1626   ;; Trailing spaces.
1627   (when (string-match "[ \t]+$" str)
1628     (setq str (substring str 0 (match-beginning 0))))
1629   str)
1630
1631 (defun gnus-simplify-all-whitespace (str)
1632   "Remove all whitespace from STR."
1633   (while (string-match "[ \t\n]+" str)
1634     (setq str (replace-match "" nil nil str)))
1635   str)
1636
1637 (defsubst gnus-simplify-subject-re (subject)
1638   "Remove \"Re:\" from subject lines."
1639   (if (string-match message-subject-re-regexp subject)
1640       (substring subject (match-end 0))
1641     subject))
1642
1643 (defun gnus-simplify-subject (subject &optional re-only)
1644   "Remove `Re:' and words in parentheses.
1645 If RE-ONLY is non-nil, strip leading `Re:'s only."
1646   (let ((case-fold-search t))           ;Ignore case.
1647     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1648     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1649       (setq subject (substring subject (match-end 0))))
1650     ;; Remove uninteresting prefixes.
1651     (when (and (not re-only)
1652                gnus-simplify-ignored-prefixes
1653                (string-match gnus-simplify-ignored-prefixes subject))
1654       (setq subject (substring subject (match-end 0))))
1655     ;; Remove words in parentheses from end.
1656     (unless re-only
1657       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1658         (setq subject (substring subject 0 (match-beginning 0)))))
1659     ;; Return subject string.
1660     subject))
1661
1662 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1663 ;; all whitespace.
1664 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1665   (goto-char (point-min))
1666   (while (re-search-forward regexp nil t)
1667     (replace-match (or newtext ""))))
1668
1669 (defun gnus-simplify-buffer-fuzzy ()
1670   "Simplify string in the buffer fuzzily.
1671 The string in the accessible portion of the current buffer is simplified.
1672 It is assumed to be a single-line subject.
1673 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1674 matter is removed.  Additional things can be deleted by setting
1675 `gnus-simplify-subject-fuzzy-regexp'."
1676   (let ((case-fold-search t)
1677         (modified-tick))
1678     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1679
1680     (while (not (eq modified-tick (buffer-modified-tick)))
1681       (setq modified-tick (buffer-modified-tick))
1682       (cond
1683        ((listp gnus-simplify-subject-fuzzy-regexp)
1684         (mapcar 'gnus-simplify-buffer-fuzzy-step
1685                 gnus-simplify-subject-fuzzy-regexp))
1686        (gnus-simplify-subject-fuzzy-regexp
1687         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1688       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1689       (gnus-simplify-buffer-fuzzy-step
1690        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1691       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1692
1693     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1694     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1695     (gnus-simplify-buffer-fuzzy-step " $")
1696     (gnus-simplify-buffer-fuzzy-step "^ +")))
1697
1698 (defun gnus-simplify-subject-fuzzy (subject)
1699   "Simplify a subject string fuzzily.
1700 See `gnus-simplify-buffer-fuzzy' for details."
1701   (save-excursion
1702     (gnus-set-work-buffer)
1703     (let ((case-fold-search t))
1704       ;; Remove uninteresting prefixes.
1705       (when (and gnus-simplify-ignored-prefixes
1706                  (string-match gnus-simplify-ignored-prefixes subject))
1707         (setq subject (substring subject (match-end 0))))
1708       (insert subject)
1709       (inline (gnus-simplify-buffer-fuzzy))
1710       (buffer-string))))
1711
1712 (defsubst gnus-simplify-subject-fully (subject)
1713   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1714   (cond
1715    (gnus-simplify-subject-functions
1716     (gnus-map-function gnus-simplify-subject-functions subject))
1717    ((null gnus-summary-gather-subject-limit)
1718     (gnus-simplify-subject-re subject))
1719    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1720     (gnus-simplify-subject-fuzzy subject))
1721    ((numberp gnus-summary-gather-subject-limit)
1722     (truncate-string-to-width (gnus-simplify-subject-re subject)
1723                               gnus-summary-gather-subject-limit))
1724    (t
1725     subject)))
1726
1727 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1728   "Check whether two subjects are equal.
1729 If optional argument SIMPLE-FIRST is t, first argument is already
1730 simplified."
1731   (cond
1732    ((null simple-first)
1733     (equal (gnus-simplify-subject-fully s1)
1734            (gnus-simplify-subject-fully s2)))
1735    (t
1736     (equal s1
1737            (gnus-simplify-subject-fully s2)))))
1738
1739 (defun gnus-summary-bubble-group ()
1740   "Increase the score of the current group.
1741 This is a handy function to add to `gnus-summary-exit-hook' to
1742 increase the score of each group you read."
1743   (gnus-group-add-score gnus-newsgroup-name))
1744
1745 \f
1746 ;;;
1747 ;;; Gnus summary mode
1748 ;;;
1749
1750 (put 'gnus-summary-mode 'mode-class 'special)
1751
1752 (defvar gnus-article-commands-menu)
1753
1754 ;; Non-orthogonal keys
1755
1756 (gnus-define-keys gnus-summary-mode-map
1757   " " gnus-summary-next-page
1758   "\177" gnus-summary-prev-page
1759   [delete] gnus-summary-prev-page
1760   [backspace] gnus-summary-prev-page
1761   "\r" gnus-summary-scroll-up
1762   "\M-\r" gnus-summary-scroll-down
1763   "n" gnus-summary-next-unread-article
1764   "p" gnus-summary-prev-unread-article
1765   "N" gnus-summary-next-article
1766   "P" gnus-summary-prev-article
1767   "\M-\C-n" gnus-summary-next-same-subject
1768   "\M-\C-p" gnus-summary-prev-same-subject
1769   "\M-n" gnus-summary-next-unread-subject
1770   "\M-p" gnus-summary-prev-unread-subject
1771   "." gnus-summary-first-unread-article
1772   "," gnus-summary-best-unread-article
1773   "\M-s" gnus-summary-search-article-forward
1774   "\M-r" gnus-summary-search-article-backward
1775   "\M-S" gnus-summary-repeat-search-article-forward
1776   "\M-R" gnus-summary-repeat-search-article-backward
1777   "<" gnus-summary-beginning-of-article
1778   ">" gnus-summary-end-of-article
1779   "j" gnus-summary-goto-article
1780   "^" gnus-summary-refer-parent-article
1781   "\M-^" gnus-summary-refer-article
1782   "u" gnus-summary-tick-article-forward
1783   "!" gnus-summary-tick-article-forward
1784   "U" gnus-summary-tick-article-backward
1785   "d" gnus-summary-mark-as-read-forward
1786   "D" gnus-summary-mark-as-read-backward
1787   "E" gnus-summary-mark-as-expirable
1788   "\M-u" gnus-summary-clear-mark-forward
1789   "\M-U" gnus-summary-clear-mark-backward
1790   "k" gnus-summary-kill-same-subject-and-select
1791   "\C-k" gnus-summary-kill-same-subject
1792   "\M-\C-k" gnus-summary-kill-thread
1793   "\M-\C-e" gnus-summary-expire-thread
1794   "\M-\C-l" gnus-summary-lower-thread
1795   "e" gnus-summary-edit-article
1796   "#" gnus-summary-mark-as-processable
1797   "\M-#" gnus-summary-unmark-as-processable
1798   "\M-\C-t" gnus-summary-toggle-threads
1799   "\M-\C-s" gnus-summary-show-thread
1800   "\M-\C-h" gnus-summary-hide-thread
1801   "\M-\C-f" gnus-summary-next-thread
1802   "\M-\C-b" gnus-summary-prev-thread
1803   [(meta down)] gnus-summary-next-thread
1804   [(meta up)] gnus-summary-prev-thread
1805   "\M-\C-u" gnus-summary-up-thread
1806   "\M-\C-d" gnus-summary-down-thread
1807   "&" gnus-summary-execute-command
1808   "c" gnus-summary-catchup-and-exit
1809   "\C-w" gnus-summary-mark-region-as-read
1810   "\C-t" gnus-summary-toggle-truncation
1811   "?" gnus-summary-mark-as-dormant
1812   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1813   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1814   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1815   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1816   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1817   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1818   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1819   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1820   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1821   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1822   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1823   "=" gnus-summary-expand-window
1824   "\C-x\C-s" gnus-summary-reselect-current-group
1825   "\M-g" gnus-summary-rescan-group
1826   "w" gnus-summary-stop-page-breaking
1827   "\C-c\C-r" gnus-summary-caesar-message
1828   "f" gnus-summary-followup
1829   "F" gnus-summary-followup-with-original
1830   "C" gnus-summary-cancel-article
1831   "r" gnus-summary-reply
1832   "R" gnus-summary-reply-with-original
1833   "\C-c\C-f" gnus-summary-mail-forward
1834   "o" gnus-summary-save-article
1835   "\C-o" gnus-summary-save-article-mail
1836   "|" gnus-summary-pipe-output
1837   "\M-k" gnus-summary-edit-local-kill
1838   "\M-K" gnus-summary-edit-global-kill
1839   ;; "V" gnus-version
1840   "\C-c\C-d" gnus-summary-describe-group
1841   "q" gnus-summary-exit
1842   "Q" gnus-summary-exit-no-update
1843   "\C-c\C-i" gnus-info-find-node
1844   gnus-mouse-2 gnus-mouse-pick-article
1845   [follow-link] mouse-face
1846   "m" gnus-summary-mail-other-window
1847   "a" gnus-summary-post-news
1848   "i" gnus-summary-news-other-window
1849   "x" gnus-summary-limit-to-unread
1850   "s" gnus-summary-isearch-article
1851   "t" gnus-summary-toggle-header
1852   "g" gnus-summary-show-article
1853   "l" gnus-summary-goto-last-article
1854   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1855   "\C-d" gnus-summary-enter-digest-group
1856   "\M-\C-d" gnus-summary-read-document
1857   "\M-\C-e" gnus-summary-edit-parameters
1858   "\M-\C-a" gnus-summary-customize-parameters
1859   "\C-c\C-b" gnus-bug
1860   "*" gnus-cache-enter-article
1861   "\M-*" gnus-cache-remove-article
1862   "\M-&" gnus-summary-universal-argument
1863   "\C-l" gnus-recenter
1864   "I" gnus-summary-increase-score
1865   "L" gnus-summary-lower-score
1866   "\M-i" gnus-symbolic-argument
1867   "h" gnus-summary-select-article-buffer
1868
1869   "b" gnus-article-view-part
1870   "\M-t" gnus-summary-toggle-display-buttonized
1871
1872   "V" gnus-summary-score-map
1873   "X" gnus-uu-extract-map
1874   "S" gnus-summary-send-map)
1875
1876 ;; Sort of orthogonal keymap
1877 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1878   "t" gnus-summary-tick-article-forward
1879   "!" gnus-summary-tick-article-forward
1880   "d" gnus-summary-mark-as-read-forward
1881   "r" gnus-summary-mark-as-read-forward
1882   "c" gnus-summary-clear-mark-forward
1883   " " gnus-summary-clear-mark-forward
1884   "e" gnus-summary-mark-as-expirable
1885   "x" gnus-summary-mark-as-expirable
1886   "?" gnus-summary-mark-as-dormant
1887   "b" gnus-summary-set-bookmark
1888   "B" gnus-summary-remove-bookmark
1889   "#" gnus-summary-mark-as-processable
1890   "\M-#" gnus-summary-unmark-as-processable
1891   "S" gnus-summary-limit-include-expunged
1892   "C" gnus-summary-catchup
1893   "H" gnus-summary-catchup-to-here
1894   "h" gnus-summary-catchup-from-here
1895   "\C-c" gnus-summary-catchup-all
1896   "k" gnus-summary-kill-same-subject-and-select
1897   "K" gnus-summary-kill-same-subject
1898   "P" gnus-uu-mark-map)
1899
1900 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1901   "c" gnus-summary-clear-above
1902   "u" gnus-summary-tick-above
1903   "m" gnus-summary-mark-above
1904   "k" gnus-summary-kill-below)
1905
1906 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1907   "/" gnus-summary-limit-to-subject
1908   "n" gnus-summary-limit-to-articles
1909   "b" gnus-summary-limit-to-bodies
1910   "h" gnus-summary-limit-to-headers
1911   "w" gnus-summary-pop-limit
1912   "s" gnus-summary-limit-to-subject
1913   "a" gnus-summary-limit-to-author
1914   "u" gnus-summary-limit-to-unread
1915   "m" gnus-summary-limit-to-marks
1916   "M" gnus-summary-limit-exclude-marks
1917   "v" gnus-summary-limit-to-score
1918   "*" gnus-summary-limit-include-cached
1919   "D" gnus-summary-limit-include-dormant
1920   "T" gnus-summary-limit-include-thread
1921   "d" gnus-summary-limit-exclude-dormant
1922   "t" gnus-summary-limit-to-age
1923   "." gnus-summary-limit-to-unseen
1924   "x" gnus-summary-limit-to-extra
1925   "p" gnus-summary-limit-to-display-predicate
1926   "E" gnus-summary-limit-include-expunged
1927   "c" gnus-summary-limit-exclude-childless-dormant
1928   "C" gnus-summary-limit-mark-excluded-as-read
1929   "o" gnus-summary-insert-old-articles
1930   "N" gnus-summary-insert-new-articles
1931   "S" gnus-summary-limit-to-singletons
1932   "r" gnus-summary-limit-to-replied
1933   "R" gnus-summary-limit-to-recipient
1934   "A" gnus-summary-limit-to-address)
1935
1936 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1937   "n" gnus-summary-next-unread-article
1938   "p" gnus-summary-prev-unread-article
1939   "N" gnus-summary-next-article
1940   "P" gnus-summary-prev-article
1941   "\C-n" gnus-summary-next-same-subject
1942   "\C-p" gnus-summary-prev-same-subject
1943   "\M-n" gnus-summary-next-unread-subject
1944   "\M-p" gnus-summary-prev-unread-subject
1945   "f" gnus-summary-first-unread-article
1946   "b" gnus-summary-best-unread-article
1947   "j" gnus-summary-goto-article
1948   "g" gnus-summary-goto-subject
1949   "l" gnus-summary-goto-last-article
1950   "o" gnus-summary-pop-article)
1951
1952 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1953   "k" gnus-summary-kill-thread
1954   "e" gnus-summary-expire-thread
1955   "l" gnus-summary-lower-thread
1956   "i" gnus-summary-raise-thread
1957   "T" gnus-summary-toggle-threads
1958   "t" gnus-summary-rethread-current
1959   "^" gnus-summary-reparent-thread
1960   "\M-^" gnus-summary-reparent-children
1961   "s" gnus-summary-show-thread
1962   "S" gnus-summary-show-all-threads
1963   "h" gnus-summary-hide-thread
1964   "H" gnus-summary-hide-all-threads
1965   "n" gnus-summary-next-thread
1966   "p" gnus-summary-prev-thread
1967   "u" gnus-summary-up-thread
1968   "o" gnus-summary-top-thread
1969   "d" gnus-summary-down-thread
1970   "#" gnus-uu-mark-thread
1971   "\M-#" gnus-uu-unmark-thread)
1972
1973 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1974   "g" gnus-summary-prepare
1975   "c" gnus-summary-insert-cached-articles
1976   "d" gnus-summary-insert-dormant-articles
1977   "t" gnus-summary-insert-ticked-articles)
1978
1979 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1980   "c" gnus-summary-catchup-and-exit
1981   "C" gnus-summary-catchup-all-and-exit
1982   "E" gnus-summary-exit-no-update
1983   "Q" gnus-summary-exit
1984   "Z" gnus-summary-exit
1985   "n" gnus-summary-catchup-and-goto-next-group
1986   "p" gnus-summary-catchup-and-goto-prev-group
1987   "R" gnus-summary-reselect-current-group
1988   "G" gnus-summary-rescan-group
1989   "N" gnus-summary-next-group
1990   "s" gnus-summary-save-newsrc
1991   "P" gnus-summary-prev-group)
1992
1993 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1994   " " gnus-summary-next-page
1995   "n" gnus-summary-next-page
1996   "\177" gnus-summary-prev-page
1997   [delete] gnus-summary-prev-page
1998   "p" gnus-summary-prev-page
1999   "\r" gnus-summary-scroll-up
2000   "\M-\r" gnus-summary-scroll-down
2001   "<" gnus-summary-beginning-of-article
2002   ">" gnus-summary-end-of-article
2003   "b" gnus-summary-beginning-of-article
2004   "e" gnus-summary-end-of-article
2005   "^" gnus-summary-refer-parent-article
2006   "r" gnus-summary-refer-parent-article
2007   "D" gnus-summary-enter-digest-group
2008   "R" gnus-summary-refer-references
2009   "T" gnus-summary-refer-thread
2010   "g" gnus-summary-show-article
2011   "s" gnus-summary-isearch-article
2012   "P" gnus-summary-print-article
2013   "S" gnus-sticky-article
2014   "M" gnus-mailing-list-insinuate
2015   "t" gnus-article-babel)
2016
2017 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2018   "b" gnus-article-add-buttons
2019   "B" gnus-article-add-buttons-to-head
2020   "o" gnus-article-treat-overstrike
2021   "e" gnus-article-emphasize
2022   "w" gnus-article-fill-cited-article
2023   "Q" gnus-article-fill-long-lines
2024   "L" gnus-article-toggle-truncate-lines
2025   "C" gnus-article-capitalize-sentences
2026   "c" gnus-article-remove-cr
2027   "q" gnus-article-de-quoted-unreadable
2028   "6" gnus-article-de-base64-unreadable
2029   "Z" gnus-article-decode-HZ
2030   "A" gnus-article-treat-ansi-sequences
2031   "h" gnus-article-wash-html
2032   "u" gnus-article-unsplit-urls
2033   "s" gnus-summary-force-verify-and-decrypt
2034   "f" gnus-article-display-x-face
2035   "l" gnus-summary-stop-page-breaking
2036   "r" gnus-summary-caesar-message
2037   "m" gnus-summary-morse-message
2038   "t" gnus-summary-toggle-header
2039   "g" gnus-treat-smiley
2040   "v" gnus-summary-verbose-headers
2041   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2042   "p" gnus-article-verify-x-pgp-sig
2043   "d" gnus-article-treat-dumbquotes
2044   "i" gnus-summary-idna-message)
2045
2046 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2047   ;; mnemonic: deuglif*Y*
2048   "u" gnus-article-outlook-unwrap-lines
2049   "a" gnus-article-outlook-repair-attribution
2050   "c" gnus-article-outlook-rearrange-citation
2051   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2052
2053 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2054   "a" gnus-article-hide
2055   "h" gnus-article-hide-headers
2056   "b" gnus-article-hide-boring-headers
2057   "s" gnus-article-hide-signature
2058   "c" gnus-article-hide-citation
2059   "C" gnus-article-hide-citation-in-followups
2060   "l" gnus-article-hide-list-identifiers
2061   "B" gnus-article-strip-banner
2062   "P" gnus-article-hide-pem
2063   "\C-c" gnus-article-hide-citation-maybe)
2064
2065 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2066   "a" gnus-article-highlight
2067   "h" gnus-article-highlight-headers
2068   "c" gnus-article-highlight-citation
2069   "s" gnus-article-highlight-signature)
2070
2071 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2072   "f" gnus-article-treat-fold-headers
2073   "u" gnus-article-treat-unfold-headers
2074   "n" gnus-article-treat-fold-newsgroups)
2075
2076 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2077   "x" gnus-article-display-x-face
2078   "d" gnus-article-display-face
2079   "s" gnus-treat-smiley
2080   "D" gnus-article-remove-images
2081   "f" gnus-treat-from-picon
2082   "m" gnus-treat-mail-picon
2083   "n" gnus-treat-newsgroups-picon)
2084
2085 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2086   "w" gnus-article-decode-mime-words
2087   "c" gnus-article-decode-charset
2088   "v" gnus-mime-view-all-parts
2089   "b" gnus-article-view-part)
2090
2091 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2092   "z" gnus-article-date-ut
2093   "u" gnus-article-date-ut
2094   "l" gnus-article-date-local
2095   "p" gnus-article-date-english
2096   "e" gnus-article-date-lapsed
2097   "o" gnus-article-date-original
2098   "i" gnus-article-date-iso8601
2099   "s" gnus-article-date-user)
2100
2101 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2102   "t" gnus-article-remove-trailing-blank-lines
2103   "l" gnus-article-strip-leading-blank-lines
2104   "m" gnus-article-strip-multiple-blank-lines
2105   "a" gnus-article-strip-blank-lines
2106   "A" gnus-article-strip-all-blank-lines
2107   "s" gnus-article-strip-leading-space
2108   "e" gnus-article-strip-trailing-space
2109   "w" gnus-article-remove-leading-whitespace)
2110
2111 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2112   "v" gnus-version
2113   "f" gnus-summary-fetch-faq
2114   "d" gnus-summary-describe-group
2115   "h" gnus-summary-describe-briefly
2116   "i" gnus-info-find-node
2117   "c" gnus-group-fetch-charter
2118   "C" gnus-group-fetch-control)
2119
2120 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2121   "e" gnus-summary-expire-articles
2122   "\M-\C-e" gnus-summary-expire-articles-now
2123   "\177" gnus-summary-delete-article
2124   [delete] gnus-summary-delete-article
2125   [backspace] gnus-summary-delete-article
2126   "m" gnus-summary-move-article
2127   "r" gnus-summary-respool-article
2128   "w" gnus-summary-edit-article
2129   "c" gnus-summary-copy-article
2130   "B" gnus-summary-crosspost-article
2131   "q" gnus-summary-respool-query
2132   "t" gnus-summary-respool-trace
2133   "i" gnus-summary-import-article
2134   "I" gnus-summary-create-article
2135   "p" gnus-summary-article-posted-p)
2136
2137 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2138   "o" gnus-summary-save-article
2139   "m" gnus-summary-save-article-mail
2140   "F" gnus-summary-write-article-file
2141   "r" gnus-summary-save-article-rmail
2142   "f" gnus-summary-save-article-file
2143   "b" gnus-summary-save-article-body-file
2144   "B" gnus-summary-write-article-body-file
2145   "h" gnus-summary-save-article-folder
2146   "v" gnus-summary-save-article-vm
2147   "p" gnus-summary-pipe-output
2148   "P" gnus-summary-muttprint
2149   "s" gnus-soup-add-article)
2150
2151 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2152   "b" gnus-summary-display-buttonized
2153   "m" gnus-summary-repair-multipart
2154   "v" gnus-article-view-part
2155   "o" gnus-article-save-part
2156   "O" gnus-article-save-part-and-strip
2157   "r" gnus-article-replace-part
2158   "d" gnus-article-delete-part
2159   "t" gnus-article-view-part-as-type
2160   "j" gnus-article-jump-to-part
2161   "c" gnus-article-copy-part
2162   "C" gnus-article-view-part-as-charset
2163   "e" gnus-article-view-part-externally
2164   "H" gnus-article-browse-html-article
2165   "E" gnus-article-encrypt-body
2166   "i" gnus-article-inline-part
2167   "|" gnus-article-pipe-part)
2168
2169 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2170   "p" gnus-summary-mark-as-processable
2171   "u" gnus-summary-unmark-as-processable
2172   "U" gnus-summary-unmark-all-processable
2173   "v" gnus-uu-mark-over
2174   "s" gnus-uu-mark-series
2175   "r" gnus-uu-mark-region
2176   "g" gnus-uu-unmark-region
2177   "R" gnus-uu-mark-by-regexp
2178   "G" gnus-uu-unmark-by-regexp
2179   "t" gnus-uu-mark-thread
2180   "T" gnus-uu-unmark-thread
2181   "a" gnus-uu-mark-all
2182   "b" gnus-uu-mark-buffer
2183   "S" gnus-uu-mark-sparse
2184   "k" gnus-summary-kill-process-mark
2185   "y" gnus-summary-yank-process-mark
2186   "w" gnus-summary-save-process-mark
2187   "i" gnus-uu-invert-processable)
2188
2189 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2190   ;;"x" gnus-uu-extract-any
2191   "m" gnus-summary-save-parts
2192   "u" gnus-uu-decode-uu
2193   "U" gnus-uu-decode-uu-and-save
2194   "s" gnus-uu-decode-unshar
2195   "S" gnus-uu-decode-unshar-and-save
2196   "o" gnus-uu-decode-save
2197   "O" gnus-uu-decode-save
2198   "b" gnus-uu-decode-binhex
2199   "B" gnus-uu-decode-binhex
2200   "p" gnus-uu-decode-postscript
2201   "P" gnus-uu-decode-postscript-and-save)
2202
2203 (gnus-define-keys
2204     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2205   "u" gnus-uu-decode-uu-view
2206   "U" gnus-uu-decode-uu-and-save-view
2207   "s" gnus-uu-decode-unshar-view
2208   "S" gnus-uu-decode-unshar-and-save-view
2209   "o" gnus-uu-decode-save-view
2210   "O" gnus-uu-decode-save-view
2211   "b" gnus-uu-decode-binhex-view
2212   "B" gnus-uu-decode-binhex-view
2213   "p" gnus-uu-decode-postscript-view
2214   "P" gnus-uu-decode-postscript-and-save-view)
2215
2216 (defvar gnus-article-post-menu nil)
2217
2218 (defconst gnus-summary-menu-maxlen 20)
2219
2220 (defun gnus-summary-menu-split (menu)
2221   ;; If we have lots of elements, divide them into groups of 20
2222   ;; and make a pane (or submenu) for each one.
2223   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2224       (let ((menu menu) sublists next
2225             (i 1))
2226         (while menu
2227           ;; Pull off the next gnus-summary-menu-maxlen elements
2228           ;; and make them the next element of sublist.
2229           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2230           (if next
2231               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2232                       nil))
2233           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2234                                              (aref (car (last menu)) 0)) menu)
2235                                sublists))
2236           (setq i (1+ i))
2237           (setq menu next))
2238         (nreverse sublists))
2239     ;; Few elements--put them all in one pane.
2240     menu))
2241
2242 (defun gnus-summary-make-menu-bar ()
2243   (gnus-turn-off-edit-menu 'summary)
2244
2245   (unless (boundp 'gnus-summary-misc-menu)
2246
2247     (easy-menu-define
2248       gnus-summary-kill-menu gnus-summary-mode-map ""
2249       (cons
2250        "Score"
2251        (nconc
2252         (list
2253          ["Customize" gnus-score-customize t])
2254         (gnus-make-score-map 'increase)
2255         (gnus-make-score-map 'lower)
2256         '(("Mark"
2257            ["Kill below" gnus-summary-kill-below t]
2258            ["Mark above" gnus-summary-mark-above t]
2259            ["Tick above" gnus-summary-tick-above t]
2260            ["Clear above" gnus-summary-clear-above t])
2261           ["Current score" gnus-summary-current-score t]
2262           ["Set score" gnus-summary-set-score t]
2263           ["Switch current score file..." gnus-score-change-score-file t]
2264           ["Set mark below..." gnus-score-set-mark-below t]
2265           ["Set expunge below..." gnus-score-set-expunge-below t]
2266           ["Edit current score file" gnus-score-edit-current-scores t]
2267           ["Edit score file" gnus-score-edit-file t]
2268           ["Trace score" gnus-score-find-trace t]
2269           ["Find words" gnus-score-find-favourite-words t]
2270           ["Rescore buffer" gnus-summary-rescore t]
2271           ["Increase score..." gnus-summary-increase-score t]
2272           ["Lower score..." gnus-summary-lower-score t]))))
2273
2274     ;; Define both the Article menu in the summary buffer and the
2275     ;; equivalent Commands menu in the article buffer here for
2276     ;; consistency.
2277     (let ((innards
2278            `(("Hide"
2279               ["All" gnus-article-hide t]
2280               ["Headers" gnus-article-hide-headers t]
2281               ["Signature" gnus-article-hide-signature t]
2282               ["Citation" gnus-article-hide-citation t]
2283               ["List identifiers" gnus-article-hide-list-identifiers t]
2284               ["Banner" gnus-article-strip-banner t]
2285               ["Boring headers" gnus-article-hide-boring-headers t])
2286              ("Highlight"
2287               ["All" gnus-article-highlight t]
2288               ["Headers" gnus-article-highlight-headers t]
2289               ["Signature" gnus-article-highlight-signature t]
2290               ["Citation" gnus-article-highlight-citation t])
2291              ("MIME"
2292               ["Words" gnus-article-decode-mime-words t]
2293               ["Charset" gnus-article-decode-charset t]
2294               ["QP" gnus-article-de-quoted-unreadable t]
2295               ["Base64" gnus-article-de-base64-unreadable t]
2296               ["View MIME buttons" gnus-summary-display-buttonized t]
2297               ["View all" gnus-mime-view-all-parts t]
2298               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2299               ["Encrypt body" gnus-article-encrypt-body
2300                :active (not (gnus-group-read-only-p))
2301                ,@(if (featurep 'xemacs) nil
2302                    '(:help "Encrypt the message body on disk"))]
2303               ["Extract all parts..." gnus-summary-save-parts t]
2304               ("Multipart"
2305                ["Repair multipart" gnus-summary-repair-multipart t]
2306                ["Pipe part..." gnus-article-pipe-part t]
2307                ["Inline part" gnus-article-inline-part t]
2308                ["View part as type..." gnus-article-view-part-as-type t]
2309                ["Encrypt body" gnus-article-encrypt-body
2310                 :active (not (gnus-group-read-only-p))
2311                ,@(if (featurep 'xemacs) nil
2312                    '(:help "Encrypt the message body on disk"))]
2313                ["View part externally" gnus-article-view-part-externally t]
2314                ["View HTML parts in browser" gnus-article-browse-html-article t]
2315                ["View part with charset..." gnus-article-view-part-as-charset t]
2316                ["Copy part" gnus-article-copy-part t]
2317                ["Save part..." gnus-article-save-part t]
2318                ["View part" gnus-article-view-part t]))
2319              ("Date"
2320               ["Local" gnus-article-date-local t]
2321               ["ISO8601" gnus-article-date-iso8601 t]
2322               ["UT" gnus-article-date-ut t]
2323               ["Original" gnus-article-date-original t]
2324               ["Lapsed" gnus-article-date-lapsed t]
2325               ["User-defined" gnus-article-date-user t])
2326              ("Display"
2327               ["Remove images" gnus-article-remove-images t]
2328               ["Toggle smiley" gnus-treat-smiley t]
2329               ["Show X-Face" gnus-article-display-x-face t]
2330               ["Show picons in From" gnus-treat-from-picon t]
2331               ["Show picons in mail headers" gnus-treat-mail-picon t]
2332               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2333               ("View as different encoding"
2334                ,@(gnus-summary-menu-split
2335                   (mapcar
2336                    (lambda (cs)
2337                      ;; Since easymenu under Emacs doesn't allow
2338                      ;; lambda forms for menu commands, we should
2339                      ;; provide intern'ed function symbols.
2340                      (let ((command (intern (format "\
2341 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2342                        (fset command
2343                              `(lambda ()
2344                                 (interactive)
2345                                 (let ((gnus-summary-show-article-charset-alist
2346                                        '((1 . ,cs))))
2347                                   (gnus-summary-show-article 1))))
2348                        `[,(symbol-name cs) ,command t]))
2349                    (sort (if (fboundp 'coding-system-list)
2350                              (coding-system-list)
2351                            (mapcar 'car mm-mime-mule-charset-alist))
2352                          'string<)))))
2353              ("Washing"
2354               ("Remove Blanks"
2355                ["Leading" gnus-article-strip-leading-blank-lines t]
2356                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2357                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2358                ["All of the above" gnus-article-strip-blank-lines t]
2359                ["All" gnus-article-strip-all-blank-lines t]
2360                ["Leading space" gnus-article-strip-leading-space t]
2361                ["Trailing space" gnus-article-strip-trailing-space t]
2362                ["Leading space in headers"
2363                 gnus-article-remove-leading-whitespace t])
2364               ["Overstrike" gnus-article-treat-overstrike t]
2365               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2366               ["Emphasis" gnus-article-emphasize t]
2367               ["Word wrap" gnus-article-fill-cited-article t]
2368               ["Fill long lines" gnus-article-fill-long-lines t]
2369               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2370               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2371               ["Remove CR" gnus-article-remove-cr t]
2372               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2373               ["Base64" gnus-article-de-base64-unreadable t]
2374               ["Rot 13" gnus-summary-caesar-message
2375                ,@(if (featurep 'xemacs) '(t)
2376                    '(:help "\"Caesar rotate\" article by 13"))]
2377               ["De-IDNA" gnus-summary-idna-message t]
2378               ["Morse decode" gnus-summary-morse-message t]
2379               ["Unix pipe..." gnus-summary-pipe-message t]
2380               ["Add buttons" gnus-article-add-buttons t]
2381               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2382               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2383               ["Verbose header" gnus-summary-verbose-headers t]
2384               ["Toggle header" gnus-summary-toggle-header t]
2385               ["Unfold headers" gnus-article-treat-unfold-headers t]
2386               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2387               ["Html" gnus-article-wash-html t]
2388               ["Unsplit URLs" gnus-article-unsplit-urls t]
2389               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2390               ["Decode HZ" gnus-article-decode-HZ t]
2391               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2392               ("(Outlook) Deuglify"
2393                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2394                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2395                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2396                ["Full (Outlook) deuglify"
2397                 gnus-article-outlook-deuglify-article t])
2398               )
2399              ("Output"
2400               ["Save in default format..." gnus-summary-save-article
2401                ,@(if (featurep 'xemacs) '(t)
2402                    '(:help "Save article using default method"))]
2403               ["Save in file..." gnus-summary-save-article-file
2404                ,@(if (featurep 'xemacs) '(t)
2405                    '(:help "Save article in file"))]
2406               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2407               ["Save in MH folder..." gnus-summary-save-article-folder t]
2408               ["Save in VM folder..." gnus-summary-save-article-vm t]
2409               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2410               ["Save body in file..." gnus-summary-save-article-body-file t]
2411               ["Pipe through a filter..." gnus-summary-pipe-output t]
2412               ["Add to SOUP packet" gnus-soup-add-article t]
2413               ["Print with Muttprint..." gnus-summary-muttprint t]
2414               ["Print" gnus-summary-print-article
2415                ,@(if (featurep 'xemacs) '(t)
2416                    '(:help "Generate and print a PostScript image"))])
2417              ("Copy, move,... (Backend)"
2418               ,@(if (featurep 'xemacs) nil
2419                   '(:help "Copying, moving, expiring articles..."))
2420               ["Respool article..." gnus-summary-respool-article t]
2421               ["Move article..." gnus-summary-move-article
2422                (gnus-check-backend-function
2423                 'request-move-article gnus-newsgroup-name)]
2424               ["Copy article..." gnus-summary-copy-article t]
2425               ["Crosspost article..." gnus-summary-crosspost-article
2426                (gnus-check-backend-function
2427                 'request-replace-article gnus-newsgroup-name)]
2428               ["Import file..." gnus-summary-import-article
2429                (gnus-check-backend-function
2430                 'request-accept-article gnus-newsgroup-name)]
2431               ["Create article..." gnus-summary-create-article
2432                (gnus-check-backend-function
2433                 'request-accept-article gnus-newsgroup-name)]
2434               ["Check if posted" gnus-summary-article-posted-p t]
2435               ["Edit article" gnus-summary-edit-article
2436                (not (gnus-group-read-only-p))]
2437               ["Delete article" gnus-summary-delete-article
2438                (gnus-check-backend-function
2439                 'request-expire-articles gnus-newsgroup-name)]
2440               ["Query respool" gnus-summary-respool-query t]
2441               ["Trace respool" gnus-summary-respool-trace t]
2442               ["Delete expirable articles" gnus-summary-expire-articles-now
2443                (gnus-check-backend-function
2444                 'request-expire-articles gnus-newsgroup-name)])
2445              ("Extract"
2446               ["Uudecode" gnus-uu-decode-uu
2447                ,@(if (featurep 'xemacs) '(t)
2448                    '(:help "Decode uuencoded article(s)"))]
2449               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2450               ["Unshar" gnus-uu-decode-unshar t]
2451               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2452               ["Save" gnus-uu-decode-save t]
2453               ["Binhex" gnus-uu-decode-binhex t]
2454               ["Postscript" gnus-uu-decode-postscript t]
2455               ["All MIME parts" gnus-summary-save-parts t])
2456              ("Cache"
2457               ["Enter article" gnus-cache-enter-article t]
2458               ["Remove article" gnus-cache-remove-article t])
2459              ["Translate" gnus-article-babel t]
2460              ["Select article buffer" gnus-summary-select-article-buffer t]
2461              ["Make article buffer sticky" gnus-sticky-article t]
2462              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2463              ["Isearch article..." gnus-summary-isearch-article t]
2464              ["Beginning of the article" gnus-summary-beginning-of-article t]
2465              ["End of the article" gnus-summary-end-of-article t]
2466              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2467              ["Fetch referenced articles" gnus-summary-refer-references t]
2468              ["Fetch current thread" gnus-summary-refer-thread t]
2469              ["Fetch article with id..." gnus-summary-refer-article t]
2470              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2471              ["Redisplay" gnus-summary-show-article t]
2472              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2473       (easy-menu-define
2474         gnus-summary-article-menu gnus-summary-mode-map ""
2475         (cons "Article" innards))
2476
2477       (if (not (keymapp gnus-summary-article-menu))
2478           (easy-menu-define
2479             gnus-article-commands-menu gnus-article-mode-map ""
2480             (cons "Commands" innards))
2481         ;; in Emacs, don't share menu.
2482         (setq gnus-article-commands-menu
2483               (copy-keymap gnus-summary-article-menu))
2484         (define-key gnus-article-mode-map [menu-bar commands]
2485           (cons "Commands" gnus-article-commands-menu))))
2486
2487     (easy-menu-define
2488       gnus-summary-thread-menu gnus-summary-mode-map ""
2489       '("Threads"
2490         ["Find all messages in thread" gnus-summary-refer-thread t]
2491         ["Toggle threading" gnus-summary-toggle-threads t]
2492         ["Hide threads" gnus-summary-hide-all-threads t]
2493         ["Show threads" gnus-summary-show-all-threads t]
2494         ["Hide thread" gnus-summary-hide-thread t]
2495         ["Show thread" gnus-summary-show-thread t]
2496         ["Go to next thread" gnus-summary-next-thread t]
2497         ["Go to previous thread" gnus-summary-prev-thread t]
2498         ["Go down thread" gnus-summary-down-thread t]
2499         ["Go up thread" gnus-summary-up-thread t]
2500         ["Top of thread" gnus-summary-top-thread t]
2501         ["Mark thread as read" gnus-summary-kill-thread t]
2502         ["Mark thread as expired" gnus-summary-expire-thread t]
2503         ["Lower thread score" gnus-summary-lower-thread t]
2504         ["Raise thread score" gnus-summary-raise-thread t]
2505         ["Rethread current" gnus-summary-rethread-current t]))
2506
2507     (easy-menu-define
2508       gnus-summary-post-menu gnus-summary-mode-map ""
2509       `("Post"
2510         ["Send a message (mail or news)" gnus-summary-post-news
2511          ,@(if (featurep 'xemacs) '(t)
2512              '(:help "Compose a new message (mail or news)"))]
2513         ["Followup" gnus-summary-followup
2514          ,@(if (featurep 'xemacs) '(t)
2515              '(:help "Post followup to this article"))]
2516         ["Followup and yank" gnus-summary-followup-with-original
2517          ,@(if (featurep 'xemacs) '(t)
2518              '(:help "Post followup to this article, quoting its contents"))]
2519         ["Supersede article" gnus-summary-supersede-article t]
2520         ["Cancel article" gnus-summary-cancel-article
2521          ,@(if (featurep 'xemacs) '(t)
2522              '(:help "Cancel an article you posted"))]
2523         ["Reply" gnus-summary-reply t]
2524         ["Reply and yank" gnus-summary-reply-with-original t]
2525         ["Wide reply" gnus-summary-wide-reply t]
2526         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2527          ,@(if (featurep 'xemacs) '(t)
2528              '(:help "Mail a reply, quoting this article"))]
2529         ["Very wide reply" gnus-summary-very-wide-reply t]
2530         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2531          ,@(if (featurep 'xemacs) '(t)
2532              '(:help "Mail a very wide reply, quoting this article"))]
2533         ["Mail forward" gnus-summary-mail-forward t]
2534         ["Post forward" gnus-summary-post-forward t]
2535         ["Digest and mail" gnus-uu-digest-mail-forward t]
2536         ["Digest and post" gnus-uu-digest-post-forward t]
2537         ["Resend message" gnus-summary-resend-message t]
2538         ["Resend message edit" gnus-summary-resend-message-edit t]
2539         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2540         ["Send a mail" gnus-summary-mail-other-window t]
2541         ["Create a local message" gnus-summary-news-other-window t]
2542         ["Uuencode and post" gnus-uu-post-news
2543          ,@(if (featurep 'xemacs) '(t)
2544              '(:help "Post a uuencoded article"))]
2545         ["Followup via news" gnus-summary-followup-to-mail t]
2546         ["Followup via news and yank"
2547          gnus-summary-followup-to-mail-with-original t]
2548         ;;("Draft"
2549         ;;["Send" gnus-summary-send-draft t]
2550         ;;["Send bounced" gnus-resend-bounced-mail t])
2551         ))
2552
2553     (cond
2554      ((not (keymapp gnus-summary-post-menu))
2555       (setq gnus-article-post-menu gnus-summary-post-menu))
2556      ((not gnus-article-post-menu)
2557       ;; Don't share post menu.
2558       (setq gnus-article-post-menu
2559             (copy-keymap gnus-summary-post-menu))))
2560     (define-key gnus-article-mode-map [menu-bar post]
2561       (cons "Post" gnus-article-post-menu))
2562
2563     (easy-menu-define
2564       gnus-summary-misc-menu gnus-summary-mode-map ""
2565       `("Gnus"
2566         ("Mark Read"
2567          ["Mark as read" gnus-summary-mark-as-read-forward t]
2568          ["Mark same subject and select"
2569           gnus-summary-kill-same-subject-and-select t]
2570          ["Mark same subject" gnus-summary-kill-same-subject t]
2571          ["Catchup" gnus-summary-catchup
2572           ,@(if (featurep 'xemacs) '(t)
2573               '(:help "Mark unread articles in this group as read"))]
2574          ["Catchup all" gnus-summary-catchup-all t]
2575          ["Catchup to here" gnus-summary-catchup-to-here t]
2576          ["Catchup from here" gnus-summary-catchup-from-here t]
2577          ["Catchup region" gnus-summary-mark-region-as-read
2578           (gnus-mark-active-p)]
2579          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2580         ("Mark Various"
2581          ["Tick" gnus-summary-tick-article-forward t]
2582          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2583          ["Remove marks" gnus-summary-clear-mark-forward t]
2584          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2585          ["Set bookmark" gnus-summary-set-bookmark t]
2586          ["Remove bookmark" gnus-summary-remove-bookmark t])
2587         ("Limit to"
2588          ["Marks..." gnus-summary-limit-to-marks t]
2589          ["Subject..." gnus-summary-limit-to-subject t]
2590          ["Author..." gnus-summary-limit-to-author t]
2591          ["Recipient..." gnus-summary-limit-to-recipient t]
2592          ["Address..." gnus-summary-limit-to-address t]
2593          ["Age..." gnus-summary-limit-to-age t]
2594          ["Extra..." gnus-summary-limit-to-extra t]
2595          ["Score..." gnus-summary-limit-to-score t]
2596          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2597          ["Unread" gnus-summary-limit-to-unread t]
2598          ["Unseen" gnus-summary-limit-to-unseen t]
2599          ["Singletons" gnus-summary-limit-to-singletons t]
2600          ["Replied" gnus-summary-limit-to-replied t]
2601          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2602          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2603          ["Pop limit" gnus-summary-pop-limit t]
2604          ["Show dormant" gnus-summary-limit-include-dormant t]
2605          ["Hide childless dormant"
2606           gnus-summary-limit-exclude-childless-dormant t]
2607          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2608          ["Hide marked" gnus-summary-limit-exclude-marks t]
2609          ["Show expunged" gnus-summary-limit-include-expunged t])
2610         ("Process Mark"
2611          ["Set mark" gnus-summary-mark-as-processable t]
2612          ["Remove mark" gnus-summary-unmark-as-processable t]
2613          ["Remove all marks" gnus-summary-unmark-all-processable t]
2614          ["Invert marks" gnus-uu-invert-processable t]
2615          ["Mark above" gnus-uu-mark-over t]
2616          ["Mark series" gnus-uu-mark-series t]
2617          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2618          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2619          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2620          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2621          ["Mark all" gnus-uu-mark-all t]
2622          ["Mark buffer" gnus-uu-mark-buffer t]
2623          ["Mark sparse" gnus-uu-mark-sparse t]
2624          ["Mark thread" gnus-uu-mark-thread t]
2625          ["Unmark thread" gnus-uu-unmark-thread t]
2626          ("Process Mark Sets"
2627           ["Kill" gnus-summary-kill-process-mark t]
2628           ["Yank" gnus-summary-yank-process-mark
2629            gnus-newsgroup-process-stack]
2630           ["Save" gnus-summary-save-process-mark t]
2631           ["Run command on marked..." gnus-summary-universal-argument t]))
2632         ("Scroll article"
2633          ["Page forward" gnus-summary-next-page
2634           ,@(if (featurep 'xemacs) '(t)
2635               '(:help "Show next page of article"))]
2636          ["Page backward" gnus-summary-prev-page
2637           ,@(if (featurep 'xemacs) '(t)
2638               '(:help "Show previous page of article"))]
2639          ["Line forward" gnus-summary-scroll-up t])
2640         ("Move"
2641          ["Next unread article" gnus-summary-next-unread-article t]
2642          ["Previous unread article" gnus-summary-prev-unread-article t]
2643          ["Next article" gnus-summary-next-article t]
2644          ["Previous article" gnus-summary-prev-article t]
2645          ["Next unread subject" gnus-summary-next-unread-subject t]
2646          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2647          ["Next article same subject" gnus-summary-next-same-subject t]
2648          ["Previous article same subject" gnus-summary-prev-same-subject t]
2649          ["First unread article" gnus-summary-first-unread-article t]
2650          ["Best unread article" gnus-summary-best-unread-article t]
2651          ["Go to subject number..." gnus-summary-goto-subject t]
2652          ["Go to article number..." gnus-summary-goto-article t]
2653          ["Go to the last article" gnus-summary-goto-last-article t]
2654          ["Pop article off history" gnus-summary-pop-article t])
2655         ("Sort"
2656          ["Sort by number" gnus-summary-sort-by-number t]
2657          ["Sort by author" gnus-summary-sort-by-author t]
2658          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2659          ["Sort by subject" gnus-summary-sort-by-subject t]
2660          ["Sort by date" gnus-summary-sort-by-date t]
2661          ["Sort by score" gnus-summary-sort-by-score t]
2662          ["Sort by lines" gnus-summary-sort-by-lines t]
2663          ["Sort by characters" gnus-summary-sort-by-chars t]
2664          ["Randomize" gnus-summary-sort-by-random t]
2665          ["Original sort" gnus-summary-sort-by-original t])
2666         ("Help"
2667          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2668          ["Describe group" gnus-summary-describe-group t]
2669          ["Fetch charter" gnus-group-fetch-charter
2670           ,@(if (featurep 'xemacs) nil
2671               '(:help "Display the charter of the current group"))]
2672          ["Fetch control message" gnus-group-fetch-control
2673           ,@(if (featurep 'xemacs) nil
2674               '(:help "Display the archived control message for the current group"))]
2675          ["Read manual" gnus-info-find-node t])
2676         ("Modes"
2677          ["Pick and read" gnus-pick-mode t]
2678          ["Binary" gnus-binary-mode t])
2679         ("Regeneration"
2680          ["Regenerate" gnus-summary-prepare t]
2681          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2682          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2683          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2684          ["Toggle threading" gnus-summary-toggle-threads t])
2685         ["See old articles" gnus-summary-insert-old-articles t]
2686         ["See new articles" gnus-summary-insert-new-articles t]
2687         ["Filter articles..." gnus-summary-execute-command t]
2688         ["Run command on articles..." gnus-summary-universal-argument t]
2689         ["Search articles forward..." gnus-summary-search-article-forward t]
2690         ["Search articles backward..." gnus-summary-search-article-backward t]
2691         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2692         ["Expand window" gnus-summary-expand-window t]
2693         ["Expire expirable articles" gnus-summary-expire-articles
2694          (gnus-check-backend-function
2695           'request-expire-articles gnus-newsgroup-name)]
2696         ["Edit local kill file" gnus-summary-edit-local-kill t]
2697         ["Edit main kill file" gnus-summary-edit-global-kill t]
2698         ["Edit group parameters" gnus-summary-edit-parameters t]
2699         ["Customize group parameters" gnus-summary-customize-parameters t]
2700         ["Send a bug report" gnus-bug t]
2701         ("Exit"
2702          ["Catchup and exit" gnus-summary-catchup-and-exit
2703           ,@(if (featurep 'xemacs) '(t)
2704               '(:help "Mark unread articles in this group as read, then exit"))]
2705          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2706          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2707          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2708          ["Exit group" gnus-summary-exit
2709           ,@(if (featurep 'xemacs) '(t)
2710               '(:help "Exit current group, return to group selection mode"))]
2711          ["Exit group without updating" gnus-summary-exit-no-update t]
2712          ["Exit and goto next group" gnus-summary-next-group t]
2713          ["Exit and goto prev group" gnus-summary-prev-group t]
2714          ["Reselect group" gnus-summary-reselect-current-group t]
2715          ["Rescan group" gnus-summary-rescan-group t]
2716          ["Update dribble" gnus-summary-save-newsrc t])))
2717
2718     (gnus-run-hooks 'gnus-summary-menu-hook)))
2719
2720 (defvar gnus-summary-tool-bar-map nil)
2721
2722 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2723 ;; affect _new_ message buffers.  We might add a function that walks thru all
2724 ;; summary-mode buffers and force the update.
2725 (defun gnus-summary-tool-bar-update (&optional symbol value)
2726   "Update summary mode toolbar.
2727 Setter function for custom variables."
2728   (setq-default gnus-summary-tool-bar-map nil)
2729   (when symbol
2730     ;; When used as ":set" function:
2731     (set-default symbol value))
2732   (when (gnus-buffer-live-p gnus-summary-buffer)
2733     (with-current-buffer gnus-summary-buffer
2734       (gnus-summary-make-tool-bar))))
2735
2736 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2737                                      'gnus-summary-tool-bar-gnome
2738                                    'gnus-summary-tool-bar-retro)
2739   "Specifies the Gnus summary tool bar.
2740
2741 It can be either a list or a symbol refering to a list.  See
2742 `gmm-tool-bar-from-list' for the format of the list.  The
2743 default key map is `gnus-summary-mode-map'.
2744
2745 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2746 `gnus-summary-tool-bar-retro'."
2747   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2748                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2749                  (repeat :tag "User defined list" gmm-tool-bar-item)
2750                  (symbol))
2751   :version "23.0" ;; No Gnus
2752   :initialize 'custom-initialize-default
2753   :set 'gnus-summary-tool-bar-update
2754   :group 'gnus-summary)
2755
2756 (defcustom gnus-summary-tool-bar-gnome
2757   '((gnus-summary-post-news "mail/compose" nil)
2758     (gnus-summary-insert-new-articles "mail/inbox" nil
2759                                       :visible (or (not gnus-agent)
2760                                                    gnus-plugged))
2761     (gnus-summary-reply-with-original "mail/reply")
2762     (gnus-summary-reply "mail/reply" nil :visible nil)
2763     (gnus-summary-followup-with-original "mail/reply-all")
2764     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2765     (gnus-summary-mail-forward "mail/forward")
2766     (gnus-summary-save-article "mail/save")
2767     (gnus-summary-search-article-forward "search" nil :visible nil)
2768     (gnus-summary-print-article "print")
2769     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2770     ;; Some new commands that may need more suitable icons:
2771     (gnus-summary-save-newsrc "save" nil :visible nil)
2772     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2773     (gnus-summary-prev-article "left-arrow")
2774     (gnus-summary-next-article "right-arrow")
2775     (gnus-summary-next-page "next-page")
2776     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2777     ;;
2778     ;; Maybe some sort-by-... could be added:
2779     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2780     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2781     (gnus-summary-mark-as-expirable
2782      "delete" nil
2783      :visible (gnus-check-backend-function 'request-expire-articles
2784                                            gnus-newsgroup-name))
2785     (gnus-summary-mark-as-spam
2786      "mail/spam" t
2787      :visible (and (fboundp 'spam-group-ham-contents-p)
2788                    (spam-group-ham-contents-p gnus-newsgroup-name))
2789      :help "Mark as spam")
2790     (gnus-summary-mark-as-read-forward
2791      "mail/not-spam" nil
2792      :visible (and (fboundp 'spam-group-spam-contents-p)
2793                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2794     ;;
2795     (gnus-summary-exit "exit")
2796     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2797     (gnus-info-find-node "help"))
2798   "List of functions for the summary tool bar (GNOME style).
2799
2800 See `gmm-tool-bar-from-list' for the format of the list."
2801   :type '(repeat gmm-tool-bar-item)
2802   :version "23.0" ;; No Gnus
2803   :initialize 'custom-initialize-default
2804   :set 'gnus-summary-tool-bar-update
2805   :group 'gnus-summary)
2806
2807 (defcustom gnus-summary-tool-bar-retro
2808   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2809     (gnus-summary-next-unread-article "gnus/next-ur")
2810     (gnus-summary-post-news "gnus/post")
2811     (gnus-summary-followup-with-original "gnus/fuwo")
2812     (gnus-summary-followup "gnus/followup")
2813     (gnus-summary-reply-with-original "gnus/reply-wo")
2814     (gnus-summary-reply "gnus/reply")
2815     (gnus-summary-caesar-message "gnus/rot13")
2816     (gnus-uu-decode-uu "gnus/uu-decode")
2817     (gnus-summary-save-article-file "gnus/save-aif")
2818     (gnus-summary-save-article "gnus/save-art")
2819     (gnus-uu-post-news "gnus/uu-post")
2820     (gnus-summary-catchup "gnus/catchup")
2821     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2822     (gnus-summary-exit "gnus/exit-summ")
2823     ;; Some new command that may need more suitable icons:
2824     (gnus-summary-print-article "gnus/print" nil :visible nil)
2825     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2826     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2827     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2828     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2829     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2830     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2831     ;;
2832     (gnus-info-find-node "gnus/help" nil :visible nil))
2833   "List of functions for the summary tool bar (retro look).
2834
2835 See `gmm-tool-bar-from-list' for the format of the list."
2836   :type '(repeat gmm-tool-bar-item)
2837   :version "23.0" ;; No Gnus
2838   :initialize 'custom-initialize-default
2839   :set 'gnus-summary-tool-bar-update
2840   :group 'gnus-summary)
2841
2842 (defcustom gnus-summary-tool-bar-zap-list t
2843   "List of icon items from the global tool bar.
2844 These items are not displayed in the Gnus summary mode tool bar.
2845
2846 See `gmm-tool-bar-from-list' for the format of the list."
2847   :type 'gmm-tool-bar-zap-list
2848   :version "23.0" ;; No Gnus
2849   :initialize 'custom-initialize-default
2850   :set 'gnus-summary-tool-bar-update
2851   :group 'gnus-summary)
2852
2853 (defvar image-load-path)
2854
2855 (defun gnus-summary-make-tool-bar (&optional force)
2856   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2857 When FORCE, rebuild the tool bar."
2858   (when (and (not (featurep 'xemacs))
2859              (boundp 'tool-bar-mode)
2860              tool-bar-mode
2861              (or (not gnus-summary-tool-bar-map) force))
2862     (let* ((load-path
2863             (gmm-image-load-path-for-library "gnus"
2864                                              "mail/save.xpm"
2865                                              nil t))
2866            (image-load-path (cons (car load-path)
2867                                   (when (boundp 'image-load-path)
2868                                     image-load-path)))
2869            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2870                                         gnus-summary-tool-bar-zap-list
2871                                         'gnus-summary-mode-map)))
2872       (when map
2873         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2874         ;; uses it's value.
2875         (setq gnus-summary-tool-bar-map map))))
2876   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2877
2878 (defun gnus-score-set-default (var value)
2879   "A version of set that updates the GNU Emacs menu-bar."
2880   (set var value)
2881   ;; It is the message that forces the active status to be updated.
2882   (message ""))
2883
2884 (defun gnus-make-score-map (type)
2885   "Make a summary score map of type TYPE."
2886   (if t
2887       nil
2888     (let ((headers '(("author" "from" string)
2889                      ("subject" "subject" string)
2890                      ("article body" "body" string)
2891                      ("article head" "head" string)
2892                      ("xref" "xref" string)
2893                      ("extra header" "extra" string)
2894                      ("lines" "lines" number)
2895                      ("followups to author" "followup" string)))
2896           (types '((number ("less than" <)
2897                            ("greater than" >)
2898                            ("equal" =))
2899                    (string ("substring" s)
2900                            ("exact string" e)
2901                            ("fuzzy string" f)
2902                            ("regexp" r))))
2903           (perms '(("temporary" (current-time-string))
2904                    ("permanent" nil)
2905                    ("immediate" now)))
2906           header)
2907       (list
2908        (apply
2909         'nconc
2910         (list
2911          (if (eq type 'lower)
2912              "Lower score"
2913            "Increase score"))
2914         (let (outh)
2915           (while headers
2916             (setq header (car headers))
2917             (setq outh
2918                   (cons
2919                    (apply
2920                     'nconc
2921                     (list (car header))
2922                     (let ((ts (cdr (assoc (nth 2 header) types)))
2923                           outt)
2924                       (while ts
2925                         (setq outt
2926                               (cons
2927                                (apply
2928                                 'nconc
2929                                 (list (caar ts))
2930                                 (let ((ps perms)
2931                                       outp)
2932                                   (while ps
2933                                     (setq outp
2934                                           (cons
2935                                            (vector
2936                                             (caar ps)
2937                                             (list
2938                                              'gnus-summary-score-entry
2939                                              (nth 1 header)
2940                                              (if (or (string= (nth 1 header)
2941                                                               "head")
2942                                                      (string= (nth 1 header)
2943                                                               "body"))
2944                                                  ""
2945                                                (list 'gnus-summary-header
2946                                                      (nth 1 header)))
2947                                              (list 'quote (nth 1 (car ts)))
2948                                              (list 'gnus-score-delta-default
2949                                                    nil)
2950                                              (nth 1 (car ps))
2951                                              t)
2952                                             t)
2953                                            outp))
2954                                     (setq ps (cdr ps)))
2955                                   (list (nreverse outp))))
2956                                outt))
2957                         (setq ts (cdr ts)))
2958                       (list (nreverse outt))))
2959                    outh))
2960             (setq headers (cdr headers)))
2961           (list (nreverse outh))))))))
2962
2963 \f
2964
2965 (defun gnus-summary-mode (&optional group)
2966   "Major mode for reading articles.
2967
2968 All normal editing commands are switched off.
2969 \\<gnus-summary-mode-map>
2970 Each line in this buffer represents one article.  To read an
2971 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2972 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2973 respectively.
2974
2975 You can also post articles and send mail from this buffer.  To
2976 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2977 of an article, type `\\[gnus-summary-reply]'.
2978
2979 There are approx. one gazillion commands you can execute in this
2980 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2981
2982 The following commands are available:
2983
2984 \\{gnus-summary-mode-map}"
2985   (interactive)
2986   (kill-all-local-variables)
2987   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2988     (gnus-summary-make-local-variables))
2989   (gnus-summary-make-local-variables)
2990   (setq gnus-newsgroup-name group)
2991   (when (gnus-visual-p 'summary-menu 'menu)
2992     (gnus-summary-make-menu-bar)
2993     (gnus-summary-make-tool-bar))
2994   (gnus-make-thread-indent-array)
2995   (gnus-simplify-mode-line)
2996   (setq major-mode 'gnus-summary-mode)
2997   (setq mode-name "Summary")
2998   (make-local-variable 'minor-mode-alist)
2999   (use-local-map gnus-summary-mode-map)
3000   (buffer-disable-undo)
3001   (setq buffer-read-only t              ;Disable modification
3002         show-trailing-whitespace nil)
3003   (setq truncate-lines t)
3004   (setq selective-display t)
3005   (setq selective-display-ellipses t)   ;Display `...'
3006   (gnus-summary-set-display-table)
3007   (gnus-set-default-directory)
3008   (make-local-variable 'gnus-summary-line-format)
3009   (make-local-variable 'gnus-summary-line-format-spec)
3010   (make-local-variable 'gnus-summary-dummy-line-format)
3011   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3012   (make-local-variable 'gnus-summary-mark-positions)
3013   (gnus-make-local-hook 'pre-command-hook)
3014   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3015   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3016   (turn-on-gnus-mailing-list-mode)
3017   (mm-enable-multibyte)
3018   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3019   (gnus-update-summary-mark-positions))
3020
3021 (defun gnus-summary-make-local-variables ()
3022   "Make all the local summary buffer variables."
3023   (let (global)
3024     (dolist (local gnus-summary-local-variables)
3025       (if (consp local)
3026           (progn
3027             (if (eq (cdr local) 'global)
3028                 ;; Copy the global value of the variable.
3029                 (setq global (symbol-value (car local)))
3030               ;; Use the value from the list.
3031               (setq global (eval (cdr local))))
3032             (set (make-local-variable (car local)) global))
3033         ;; Simple nil-valued local variable.
3034         (set (make-local-variable local) nil)))))
3035
3036 (defun gnus-summary-clear-local-variables ()
3037   (let ((locals gnus-summary-local-variables))
3038     (while locals
3039       (if (consp (car locals))
3040           (and (symbolp (caar locals))
3041                (set (caar locals) nil))
3042         (and (symbolp (car locals))
3043              (set (car locals) nil)))
3044       (setq locals (cdr locals)))))
3045
3046 ;; Summary data functions.
3047
3048 (defmacro gnus-data-number (data)
3049   `(car ,data))
3050
3051 (defmacro gnus-data-set-number (data number)
3052   `(setcar ,data ,number))
3053
3054 (defmacro gnus-data-mark (data)
3055   `(nth 1 ,data))
3056
3057 (defmacro gnus-data-set-mark (data mark)
3058   `(setcar (nthcdr 1 ,data) ,mark))
3059
3060 (defmacro gnus-data-pos (data)
3061   `(nth 2 ,data))
3062
3063 (defmacro gnus-data-set-pos (data pos)
3064   `(setcar (nthcdr 2 ,data) ,pos))
3065
3066 (defmacro gnus-data-header (data)
3067   `(nth 3 ,data))
3068
3069 (defmacro gnus-data-set-header (data header)
3070   `(setf (nth 3 ,data) ,header))
3071
3072 (defmacro gnus-data-level (data)
3073   `(nth 4 ,data))
3074
3075 (defmacro gnus-data-unread-p (data)
3076   `(= (nth 1 ,data) gnus-unread-mark))
3077
3078 (defmacro gnus-data-read-p (data)
3079   `(/= (nth 1 ,data) gnus-unread-mark))
3080
3081 (defmacro gnus-data-pseudo-p (data)
3082   `(consp (nth 3 ,data)))
3083
3084 (defmacro gnus-data-find (number)
3085   `(assq ,number gnus-newsgroup-data))
3086
3087 (defmacro gnus-data-find-list (number &optional data)
3088   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3089      (memq (assq ,number bdata)
3090            bdata)))
3091
3092 (defmacro gnus-data-make (number mark pos header level)
3093   `(list ,number ,mark ,pos ,header ,level))
3094
3095 (defun gnus-data-enter (after-article number mark pos header level offset)
3096   (let ((data (gnus-data-find-list after-article)))
3097     (unless data
3098       (error "No such article: %d" after-article))
3099     (setcdr data (cons (gnus-data-make number mark pos header level)
3100                        (cdr data)))
3101     (setq gnus-newsgroup-data-reverse nil)
3102     (gnus-data-update-list (cddr data) offset)))
3103
3104 (defun gnus-data-enter-list (after-article list &optional offset)
3105   (when list
3106     (let ((data (and after-article (gnus-data-find-list after-article)))
3107           (ilist list))
3108       (if (not (or data
3109                    after-article))
3110           (let ((odata gnus-newsgroup-data))
3111             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3112             (when offset
3113               (gnus-data-update-list odata offset)))
3114         ;; Find the last element in the list to be spliced into the main
3115         ;; list.
3116         (setq list (last list))
3117         (if (not data)
3118             (progn
3119               (setcdr list gnus-newsgroup-data)
3120               (setq gnus-newsgroup-data ilist)
3121               (when offset
3122                 (gnus-data-update-list (cdr list) offset)))
3123           (setcdr list (cdr data))
3124           (setcdr data ilist)
3125           (when offset
3126             (gnus-data-update-list (cdr list) offset))))
3127       (setq gnus-newsgroup-data-reverse nil))))
3128
3129 (defun gnus-data-remove (article &optional offset)
3130   (let ((data gnus-newsgroup-data))
3131     (if (= (gnus-data-number (car data)) article)
3132         (progn
3133           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3134                 gnus-newsgroup-data-reverse nil)
3135           (when offset
3136             (gnus-data-update-list gnus-newsgroup-data offset)))
3137       (while (cdr data)
3138         (when (= (gnus-data-number (cadr data)) article)
3139           (setcdr data (cddr data))
3140           (when offset
3141             (gnus-data-update-list (cdr data) offset))
3142           (setq data nil
3143                 gnus-newsgroup-data-reverse nil))
3144         (setq data (cdr data))))))
3145
3146 (defmacro gnus-data-list (backward)
3147   `(if ,backward
3148        (or gnus-newsgroup-data-reverse
3149            (setq gnus-newsgroup-data-reverse
3150                  (reverse gnus-newsgroup-data)))
3151      gnus-newsgroup-data))
3152
3153 (defun gnus-data-update-list (data offset)
3154   "Add OFFSET to the POS of all data entries in DATA."
3155   (setq gnus-newsgroup-data-reverse nil)
3156   (while data
3157     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3158     (setq data (cdr data))))
3159
3160 (defun gnus-summary-article-pseudo-p (article)
3161   "Say whether this article is a pseudo article or not."
3162   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3163
3164 (defmacro gnus-summary-article-sparse-p (article)
3165   "Say whether this article is a sparse article or not."
3166   `(memq ,article gnus-newsgroup-sparse))
3167
3168 (defmacro gnus-summary-article-ancient-p (article)
3169   "Say whether this article is a sparse article or not."
3170   `(memq ,article gnus-newsgroup-ancient))
3171
3172 (defun gnus-article-parent-p (number)
3173   "Say whether this article is a parent or not."
3174   (let ((data (gnus-data-find-list number)))
3175     (and (cdr data)              ; There has to be an article after...
3176          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3177             (gnus-data-level (nth 1 data))))))
3178
3179 (defun gnus-article-children (number)
3180   "Return a list of all children to NUMBER."
3181   (let* ((data (gnus-data-find-list number))
3182          (level (gnus-data-level (car data)))
3183          children)
3184     (setq data (cdr data))
3185     (while (and data
3186                 (= (gnus-data-level (car data)) (1+ level)))
3187       (push (gnus-data-number (car data)) children)
3188       (setq data (cdr data)))
3189     children))
3190
3191 (defmacro gnus-summary-skip-intangible ()
3192   "If the current article is intangible, then jump to a different article."
3193   '(let ((to (get-text-property (point) 'gnus-intangible)))
3194      (and to (gnus-summary-goto-subject to))))
3195
3196 (defmacro gnus-summary-article-intangible-p ()
3197   "Say whether this article is intangible or not."
3198   '(get-text-property (point) 'gnus-intangible))
3199
3200 (defun gnus-article-read-p (article)
3201   "Say whether ARTICLE is read or not."
3202   (not (or (memq article gnus-newsgroup-marked)
3203            (memq article gnus-newsgroup-spam-marked)
3204            (memq article gnus-newsgroup-unreads)
3205            (memq article gnus-newsgroup-unselected)
3206            (memq article gnus-newsgroup-dormant))))
3207
3208 ;; Some summary mode macros.
3209
3210 (defmacro gnus-summary-article-number ()
3211   "The article number of the article on the current line.
3212 If there isn't an article number here, then we return the current
3213 article number."
3214   '(progn
3215      (gnus-summary-skip-intangible)
3216      (or (get-text-property (point) 'gnus-number)
3217          (gnus-summary-last-subject))))
3218
3219 (defmacro gnus-summary-article-header (&optional number)
3220   "Return the header of article NUMBER."
3221   `(gnus-data-header (gnus-data-find
3222                       ,(or number '(gnus-summary-article-number)))))
3223
3224 (defmacro gnus-summary-thread-level (&optional number)
3225   "Return the level of thread that starts with article NUMBER."
3226   `(if (and (eq gnus-summary-make-false-root 'dummy)
3227             (get-text-property (point) 'gnus-intangible))
3228        0
3229      (gnus-data-level (gnus-data-find
3230                        ,(or number '(gnus-summary-article-number))))))
3231
3232 (defmacro gnus-summary-article-mark (&optional number)
3233   "Return the mark of article NUMBER."
3234   `(gnus-data-mark (gnus-data-find
3235                     ,(or number '(gnus-summary-article-number)))))
3236
3237 (defmacro gnus-summary-article-pos (&optional number)
3238   "Return the position of the line of article NUMBER."
3239   `(gnus-data-pos (gnus-data-find
3240                    ,(or number '(gnus-summary-article-number)))))
3241
3242 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3243 (defmacro gnus-summary-article-subject (&optional number)
3244   "Return current subject string or nil if nothing."
3245   `(let ((headers
3246           ,(if number
3247                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3248              '(gnus-data-header (assq (gnus-summary-article-number)
3249                                       gnus-newsgroup-data)))))
3250      (and headers
3251           (vectorp headers)
3252           (mail-header-subject headers))))
3253
3254 (defmacro gnus-summary-article-score (&optional number)
3255   "Return current article score."
3256   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3257                   gnus-newsgroup-scored))
3258        gnus-summary-default-score 0))
3259
3260 (defun gnus-summary-article-children (&optional number)
3261   "Return a list of article numbers that are children of article NUMBER."
3262   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3263          (level (gnus-data-level (car data)))
3264          l children)
3265     (while (and (setq data (cdr data))
3266                 (> (setq l (gnus-data-level (car data))) level))
3267       (and (= (1+ level) l)
3268            (push (gnus-data-number (car data))
3269                  children)))
3270     (nreverse children)))
3271
3272 (defun gnus-summary-article-parent (&optional number)
3273   "Return the article number of the parent of article NUMBER."
3274   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3275                                     (gnus-data-list t)))
3276          (level (gnus-data-level (car data))))
3277     (if (zerop level)
3278         ()                              ; This is a root.
3279       ;; We search until we find an article with a level less than
3280       ;; this one.  That function has to be the parent.
3281       (while (and (setq data (cdr data))
3282                   (not (< (gnus-data-level (car data)) level))))
3283       (and data (gnus-data-number (car data))))))
3284
3285 (defun gnus-unread-mark-p (mark)
3286   "Say whether MARK is the unread mark."
3287   (= mark gnus-unread-mark))
3288
3289 (defun gnus-read-mark-p (mark)
3290   "Say whether MARK is one of the marks that mark as read.
3291 This is all marks except unread, ticked, dormant, and expirable."
3292   (not (or (= mark gnus-unread-mark)
3293            (= mark gnus-ticked-mark)
3294            (= mark gnus-spam-mark)
3295            (= mark gnus-dormant-mark)
3296            (= mark gnus-expirable-mark))))
3297
3298 (defmacro gnus-article-mark (number)
3299   "Return the MARK of article NUMBER.
3300 This macro should only be used when computing the mark the \"first\"
3301 time; i.e., when generating the summary lines.  After that,
3302 `gnus-summary-article-mark' should be used to examine the
3303 marks of articles."
3304   `(cond
3305     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3306     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3307     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3308     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3309     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3310     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3311     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3312     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3313            gnus-ancient-mark))))
3314
3315 ;; Saving hidden threads.
3316
3317 (defmacro gnus-save-hidden-threads (&rest forms)
3318   "Save hidden threads, eval FORMS, and restore the hidden threads."
3319   (let ((config (make-symbol "config")))
3320     `(let ((,config (gnus-hidden-threads-configuration)))
3321        (unwind-protect
3322            (save-excursion
3323              ,@forms)
3324          (gnus-restore-hidden-threads-configuration ,config)))))
3325 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3326 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3327
3328 (defun gnus-data-compute-positions ()
3329   "Compute the positions of all articles."
3330   (setq gnus-newsgroup-data-reverse nil)
3331   (let ((data gnus-newsgroup-data))
3332     (save-excursion
3333       (gnus-save-hidden-threads
3334         (gnus-summary-show-all-threads)
3335         (goto-char (point-min))
3336         (while data
3337           (while (get-text-property (point) 'gnus-intangible)
3338             (forward-line 1))
3339           (gnus-data-set-pos (car data) (+ (point) 3))
3340           (setq data (cdr data))
3341           (forward-line 1))))))
3342
3343 (defun gnus-hidden-threads-configuration ()
3344   "Return the current hidden threads configuration."
3345   (save-excursion
3346     (let (config)
3347       (goto-char (point-min))
3348       (while (search-forward "\r" nil t)
3349         (push (1- (point)) config))
3350       config)))
3351
3352 (defun gnus-restore-hidden-threads-configuration (config)
3353   "Restore hidden threads configuration from CONFIG."
3354   (save-excursion
3355     (let (point buffer-read-only)
3356       (while (setq point (pop config))
3357         (when (and (< point (point-max))
3358                    (goto-char point)
3359                    (eq (char-after) ?\n))
3360           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3361
3362 ;; Various summary mode internalish functions.
3363
3364 (defun gnus-mouse-pick-article (e)
3365   (interactive "e")
3366   (mouse-set-point e)
3367   (gnus-summary-next-page nil t))
3368
3369 (defun gnus-summary-set-display-table ()
3370   "Change the display table.
3371 Odd characters have a tendency to mess
3372 up nicely formatted displays - we make all possible glyphs
3373 display only a single character."
3374
3375   ;; We start from the standard display table, if any.
3376   (let ((table (or (copy-sequence standard-display-table)
3377                    (make-display-table)))
3378         (i 32))
3379     ;; Nix out all the control chars...
3380     (while (>= (setq i (1- i)) 0)
3381       (aset table i [??]))
3382    ;; ... but not newline and cr, of course.  (cr is necessary for the
3383     ;; selective display).
3384     (aset table ?\n nil)
3385     (aset table ?\r nil)
3386     ;; We keep TAB as well.
3387     (aset table ?\t nil)
3388     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3389     ;; Emacs 23 (unicode), that are not set already.
3390     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3391                  160
3392                256)))
3393       (while (>= (setq i (1- i)) 127)
3394         ;; Only modify if the entry is nil.
3395         (unless (aref table i)
3396           (aset table i [??]))))
3397     (setq buffer-display-table table)))
3398
3399 (defun gnus-summary-set-article-display-arrow (pos)
3400   "Update the overlay arrow to point to line at position POS."
3401   (when (and gnus-summary-display-arrow
3402              (boundp 'overlay-arrow-position)
3403              (boundp 'overlay-arrow-string))
3404     (save-excursion
3405       (goto-char pos)
3406       (beginning-of-line)
3407       (unless overlay-arrow-position
3408         (setq overlay-arrow-position (make-marker)))
3409       (setq overlay-arrow-string "=>"
3410             overlay-arrow-position (set-marker overlay-arrow-position
3411                                                (point)
3412                                                (current-buffer))))))
3413
3414 (defun gnus-summary-setup-buffer (group)
3415   "Initialize summary buffer."
3416   (let ((buffer (gnus-summary-buffer-name group))
3417         (dead-name (concat "*Dead Summary "
3418                            (gnus-group-decoded-name group) "*")))
3419     ;; If a dead summary buffer exists, we kill it.
3420     (when (gnus-buffer-live-p dead-name)
3421       (gnus-kill-buffer dead-name))
3422     (if (get-buffer buffer)
3423         (progn
3424           (set-buffer buffer)
3425           (setq gnus-summary-buffer (current-buffer))
3426           (not gnus-newsgroup-prepared))
3427       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3428       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3429       (gnus-summary-mode group)
3430       (when gnus-carpal
3431         (gnus-carpal-setup-buffer 'summary))
3432       (when (gnus-group-quit-config group)
3433         (set (make-local-variable 'gnus-single-article-buffer) nil))
3434       (make-local-variable 'gnus-article-buffer)
3435       (make-local-variable 'gnus-article-current)
3436       (make-local-variable 'gnus-original-article-buffer)
3437       (setq gnus-newsgroup-name group)
3438       ;; Set any local variables in the group parameters.
3439       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3440       t)))
3441
3442 (defun gnus-set-global-variables ()
3443   "Set the global equivalents of the buffer-local variables.
3444 They are set to the latest values they had.  These reflect the summary
3445 buffer that was in action when the last article was fetched."
3446   (when (eq major-mode 'gnus-summary-mode)
3447     (setq gnus-summary-buffer (current-buffer))
3448     (let ((name gnus-newsgroup-name)
3449           (marked gnus-newsgroup-marked)
3450           (spam gnus-newsgroup-spam-marked)
3451           (unread gnus-newsgroup-unreads)
3452           (headers gnus-current-headers)
3453           (data gnus-newsgroup-data)
3454           (summary gnus-summary-buffer)
3455           (article-buffer gnus-article-buffer)
3456           (original gnus-original-article-buffer)
3457           (gac gnus-article-current)
3458           (reffed gnus-reffed-article-number)
3459           (score-file gnus-current-score-file)
3460           (default-charset gnus-newsgroup-charset)
3461           vlist)
3462       (let ((locals gnus-newsgroup-variables))
3463         (while locals
3464           (if (consp (car locals))
3465               (push (eval (caar locals)) vlist)
3466             (push (eval (car locals)) vlist))
3467           (setq locals (cdr locals)))
3468         (setq vlist (nreverse vlist)))
3469       (with-current-buffer gnus-group-buffer
3470         (setq gnus-newsgroup-name name
3471               gnus-newsgroup-marked marked
3472               gnus-newsgroup-spam-marked spam
3473               gnus-newsgroup-unreads unread
3474               gnus-current-headers headers
3475               gnus-newsgroup-data data
3476               gnus-article-current gac
3477               gnus-summary-buffer summary
3478               gnus-article-buffer article-buffer
3479               gnus-original-article-buffer original
3480               gnus-reffed-article-number reffed
3481               gnus-current-score-file score-file
3482               gnus-newsgroup-charset default-charset)
3483         (let ((locals gnus-newsgroup-variables))
3484           (while locals
3485             (if (consp (car locals))
3486                 (set (caar locals) (pop vlist))
3487               (set (car locals) (pop vlist)))
3488             (setq locals (cdr locals))))
3489         ;; The article buffer also has local variables.
3490         (when (gnus-buffer-live-p gnus-article-buffer)
3491           (set-buffer gnus-article-buffer)
3492           (setq gnus-summary-buffer summary))))))
3493
3494 (defun gnus-summary-article-unread-p (article)
3495   "Say whether ARTICLE is unread or not."
3496   (memq article gnus-newsgroup-unreads))
3497
3498 (defun gnus-summary-first-article-p (&optional article)
3499   "Return whether ARTICLE is the first article in the buffer."
3500   (if (not (setq article (or article (gnus-summary-article-number))))
3501       nil
3502     (eq article (caar gnus-newsgroup-data))))
3503
3504 (defun gnus-summary-last-article-p (&optional article)
3505   "Return whether ARTICLE is the last article in the buffer."
3506   (if (not (setq article (or article (gnus-summary-article-number))))
3507       ;; All non-existent numbers are the last article.  :-)
3508       t
3509     (not (cdr (gnus-data-find-list article)))))
3510
3511 (defun gnus-make-thread-indent-array (&optional n)
3512   (when (or n
3513             (progn (setq n 200) nil)
3514             (null gnus-thread-indent-array)
3515             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3516     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3517           gnus-thread-indent-array-level gnus-thread-indent-level)
3518     (while (>= n 0)
3519       (aset gnus-thread-indent-array n
3520             (make-string (* n gnus-thread-indent-level) ? ))
3521       (setq n (1- n)))))
3522
3523 (defun gnus-update-summary-mark-positions ()
3524   "Compute where the summary marks are to go."
3525   (save-excursion
3526     (when (gnus-buffer-exists-p gnus-summary-buffer)
3527       (set-buffer gnus-summary-buffer))
3528     (let ((spec gnus-summary-line-format-spec)
3529           pos)
3530       (save-excursion
3531         (gnus-set-work-buffer)
3532         (let ((gnus-tmp-unread ?Z)
3533               (gnus-replied-mark ?Z)
3534               (gnus-score-below-mark ?Z)
3535               (gnus-score-over-mark ?Z)
3536               (gnus-undownloaded-mark ?Z)
3537               (gnus-summary-line-format-spec spec)
3538               (gnus-newsgroup-downloadable '(0))
3539               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3540               case-fold-search ignores)
3541           ;; Here, all marks are bound to Z.
3542           (gnus-summary-insert-line header
3543                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3544           (goto-char (point-min))
3545           ;; Memorize the positions of the same characters as dummy marks.
3546           (while (re-search-forward "[A-D]" nil t)
3547             (push (point) ignores))
3548           (erase-buffer)
3549           ;; We use A-D as dummy marks in order to know column positions
3550           ;; where marks should be inserted.
3551           (setq gnus-tmp-unread ?A
3552                 gnus-replied-mark ?B
3553                 gnus-score-below-mark ?C
3554                 gnus-score-over-mark ?C
3555                 gnus-undownloaded-mark ?D)
3556           (gnus-summary-insert-line header
3557                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3558           ;; Ignore characters which aren't dummy marks.
3559           (dolist (p ignores)
3560             (delete-region (goto-char (1- p)) p)
3561             (insert ?Z))
3562           (goto-char (point-min))
3563           (setq pos (list (cons 'unread
3564                                 (and (search-forward "A" nil t)
3565                                      (- (point) (point-min) 1)))))
3566           (goto-char (point-min))
3567           (push (cons 'replied (and (search-forward "B" nil t)
3568                                     (- (point) (point-min) 1)))
3569                 pos)
3570           (goto-char (point-min))
3571           (push (cons 'score (and (search-forward "C" nil t)
3572                                   (- (point) (point-min) 1)))
3573                 pos)
3574           (goto-char (point-min))
3575           (push (cons 'download (and (search-forward "D" nil t)
3576                                      (- (point) (point-min) 1)))
3577                 pos)))
3578       (setq gnus-summary-mark-positions pos))))
3579
3580 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3581   "Insert a dummy root in the summary buffer."
3582   (beginning-of-line)
3583   (gnus-add-text-properties
3584    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3585    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3586
3587 (defun gnus-summary-extract-address-component (from)
3588   (or (car (funcall gnus-extract-address-components from))
3589       from))
3590
3591 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3592   (let ((mail-parse-charset gnus-newsgroup-charset)
3593         (ignored-from-addresses (gnus-ignored-from-addresses))
3594         ; Is it really necessary to do this next part for each summary line?
3595         ; Luckily, doesn't seem to slow things down much.
3596         (mail-parse-ignored-charsets
3597          (with-current-buffer gnus-summary-buffer
3598            gnus-newsgroup-ignored-charsets)))
3599     (or
3600      (and ignored-from-addresses
3601           (string-match ignored-from-addresses gnus-tmp-from)
3602           (let ((extra-headers (mail-header-extra header))
3603                 to
3604                 newsgroups)
3605             (cond
3606              ((setq to (cdr (assq 'To extra-headers)))
3607               (concat gnus-summary-to-prefix
3608                       (inline
3609                         (gnus-summary-extract-address-component
3610                          (funcall gnus-decode-encoded-address-function to)))))
3611              ((setq newsgroups
3612                     (or
3613                      (cdr (assq 'Newsgroups extra-headers))
3614                      (and
3615                       (memq 'Newsgroups gnus-extra-headers)
3616                       (eq (car (gnus-find-method-for-group
3617                                 gnus-newsgroup-name)) 'nntp)
3618                       (gnus-group-real-name gnus-newsgroup-name))))
3619               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3620      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3621
3622 (defun gnus-summary-insert-line (gnus-tmp-header
3623                                  gnus-tmp-level gnus-tmp-current
3624                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3625                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3626                                  &optional gnus-tmp-dummy gnus-tmp-score
3627                                  gnus-tmp-process)
3628   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3629       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3630                                           gnus-tmp-level)))
3631   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3632          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3633          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3634          (gnus-tmp-score-char
3635           (if (or (null gnus-summary-default-score)
3636                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3637                       gnus-summary-zcore-fuzz))
3638               ?                         ;Whitespace
3639             (if (< gnus-tmp-score gnus-summary-default-score)
3640                 gnus-score-below-mark gnus-score-over-mark)))
3641          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3642          (gnus-tmp-replied
3643           (cond (gnus-tmp-process gnus-process-mark)
3644                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3645                  gnus-cached-mark)
3646                 (gnus-tmp-replied gnus-replied-mark)
3647                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3648                  gnus-forwarded-mark)
3649                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3650                  gnus-saved-mark)
3651                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3652                  gnus-recent-mark)
3653                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3654                  gnus-unseen-mark)
3655                 (t gnus-no-mark)))
3656          (gnus-tmp-downloaded
3657           (cond (undownloaded
3658                  gnus-undownloaded-mark)
3659                 (gnus-newsgroup-agentized
3660                  gnus-downloaded-mark)
3661                 (t
3662                  gnus-no-mark)))
3663          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3664          (gnus-tmp-name
3665           (cond
3666            ((string-match "<[^>]+> *$" gnus-tmp-from)
3667             (let ((beg (match-beginning 0)))
3668               (or (and (string-match "^\".+\"" gnus-tmp-from)
3669                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3670                   (substring gnus-tmp-from 0 beg))))
3671            ((string-match "(.+)" gnus-tmp-from)
3672             (substring gnus-tmp-from
3673                        (1+ (match-beginning 0)) (1- (match-end 0))))
3674            (t gnus-tmp-from)))
3675          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3676          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3677          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3678          (buffer-read-only nil))
3679     (when (string= gnus-tmp-name "")
3680       (setq gnus-tmp-name gnus-tmp-from))
3681     (unless (numberp gnus-tmp-lines)
3682       (setq gnus-tmp-lines -1))
3683     (if (= gnus-tmp-lines -1)
3684         (setq gnus-tmp-lines "?")
3685       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3686       (gnus-put-text-property
3687      (point)
3688      (progn (eval gnus-summary-line-format-spec) (point))
3689        'gnus-number gnus-tmp-number)
3690     (when (gnus-visual-p 'summary-highlight 'highlight)
3691       (forward-line -1)
3692       (gnus-run-hooks 'gnus-summary-update-hook)
3693       (forward-line 1))))
3694
3695 (defun gnus-summary-update-line (&optional dont-update)
3696   "Update summary line after change."
3697   (when (and gnus-summary-default-score
3698              (not gnus-summary-inhibit-highlight))
3699     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3700            (article (gnus-summary-article-number))
3701            (score (gnus-summary-article-score article)))
3702       (unless dont-update
3703         (if (and gnus-summary-mark-below
3704                  (< (gnus-summary-article-score)
3705                     gnus-summary-mark-below))
3706             ;; This article has a low score, so we mark it as read.
3707             (when (memq article gnus-newsgroup-unreads)
3708               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3709           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3710             ;; This article was previously marked as read on account
3711             ;; of a low score, but now it has risen, so we mark it as
3712             ;; unread.
3713             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3714         (gnus-summary-update-mark
3715          (if (or (null gnus-summary-default-score)
3716                  (<= (abs (- score gnus-summary-default-score))
3717                      gnus-summary-zcore-fuzz))
3718              ?                          ;Whitespace
3719            (if (< score gnus-summary-default-score)
3720                gnus-score-below-mark gnus-score-over-mark))
3721          'score))
3722       ;; Do visual highlighting.
3723       (when (gnus-visual-p 'summary-highlight 'highlight)
3724         (gnus-run-hooks 'gnus-summary-update-hook)))))
3725
3726 (defvar gnus-tmp-new-adopts nil)
3727
3728 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3729   "Return the number of articles in THREAD.
3730 This may be 0 in some cases -- if none of the articles in
3731 the thread are to be displayed."
3732   (let* ((number
3733          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3734           (cond
3735            ((not (listp thread))
3736             1)
3737            ((and (consp thread) (cdr thread))
3738             (apply
3739              '+ 1 (mapcar
3740                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3741            ((null thread)
3742             1)
3743            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3744             1)
3745            (t 0))))
3746     (when (and level (zerop level) gnus-tmp-new-adopts)
3747       (incf number
3748             (apply '+ (mapcar
3749                        'gnus-summary-number-of-articles-in-thread
3750                        gnus-tmp-new-adopts))))
3751     (if char
3752         (if (> number 1) gnus-not-empty-thread-mark
3753           gnus-empty-thread-mark)
3754       number)))
3755
3756 (defsubst gnus-summary-line-message-size (head)
3757   "Return pretty-printed version of message size.
3758 This function is intended to be used in
3759 `gnus-summary-line-format-alist'."
3760   (let ((c (or (mail-header-chars head) -1)))
3761     (cond ((< c 0) "n/a")               ; chars not available
3762           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3763           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3764           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3765           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3766
3767
3768 (defun gnus-summary-set-local-parameters (group)
3769   "Go through the local params of GROUP and set all variable specs in that list."
3770   (let ((vars '(quit-config)))          ; Ignore quit-config.
3771     (dolist (elem (gnus-group-find-parameter group))
3772       (and (consp elem)                 ; Has to be a cons.
3773            (consp (cdr elem))           ; The cdr has to be a list.
3774            (symbolp (car elem))         ; Has to be a symbol in there.
3775            (not (memq (car elem) vars))
3776            (ignore-errors               ; So we set it.
3777              (push (car elem) vars)
3778              (make-local-variable (car elem))
3779              (set (car elem) (eval (nth 1 elem))))))))
3780
3781 (defun gnus-summary-read-group (group &optional show-all no-article
3782                                       kill-buffer no-display backward
3783                                       select-articles)
3784   "Start reading news in newsgroup GROUP.
3785 If SHOW-ALL is non-nil, already read articles are also listed.
3786 If NO-ARTICLE is non-nil, no article is selected initially.
3787 If NO-DISPLAY, don't generate a summary buffer."
3788   (let (result)
3789     (while (and group
3790                 (null (setq result
3791                             (let ((gnus-auto-select-next nil))
3792                               (or (gnus-summary-read-group-1
3793                                    group show-all no-article
3794                                    kill-buffer no-display
3795                                    select-articles)
3796                                   (setq show-all nil
3797                                         select-articles nil)))))
3798                 (eq gnus-auto-select-next 'quietly))
3799       (set-buffer gnus-group-buffer)
3800       ;; The entry function called above goes to the next
3801       ;; group automatically, so we go two groups back
3802       ;; if we are searching for the previous group.
3803       (when backward
3804         (gnus-group-prev-unread-group 2))
3805       (if (not (equal group (gnus-group-group-name)))
3806           (setq group (gnus-group-group-name))
3807         (setq group nil)))
3808     result))
3809
3810 (defun gnus-summary-read-group-1 (group show-all no-article
3811                                         kill-buffer no-display
3812                                         &optional select-articles)
3813   ;; Killed foreign groups can't be entered.
3814   ;;  (when (and (not (gnus-group-native-p group))
3815   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3816   ;;    (error "Dead non-native groups can't be entered"))
3817   (gnus-message 5 "Retrieving newsgroup: %s..."
3818                 (gnus-group-decoded-name group))
3819   (let* ((new-group (gnus-summary-setup-buffer group))
3820          (quit-config (gnus-group-quit-config group))
3821          (did-select (and new-group (gnus-select-newsgroup
3822                                      group show-all select-articles))))
3823     (cond
3824      ;; This summary buffer exists already, so we just select it.
3825      ((not new-group)
3826       (gnus-set-global-variables)
3827       (when kill-buffer
3828         (gnus-kill-or-deaden-summary kill-buffer))
3829       (gnus-configure-windows 'summary 'force)
3830       (gnus-set-mode-line 'summary)
3831       (gnus-summary-position-point)
3832       (message "")
3833       t)
3834      ;; We couldn't select this group.
3835      ((null did-select)
3836       (when (and (eq major-mode 'gnus-summary-mode)
3837                  (not (equal (current-buffer) kill-buffer)))
3838         (kill-buffer (current-buffer))
3839         (if (not quit-config)
3840             (progn
3841               ;; Update the info -- marks might need to be removed,
3842               ;; for instance.
3843               (gnus-summary-update-info)
3844               (set-buffer gnus-group-buffer)
3845               (gnus-group-jump-to-group group)
3846               (gnus-group-next-unread-group 1))
3847           (gnus-handle-ephemeral-exit quit-config)))
3848       (let ((grpinfo (gnus-get-info group)))
3849         (if (null (gnus-info-read grpinfo))
3850             (gnus-message 3 "Group %s contains no messages"
3851                           (gnus-group-decoded-name group))
3852           (gnus-message 3 "Can't select group")))
3853       nil)
3854      ;; The user did a `C-g' while prompting for number of articles,
3855      ;; so we exit this group.
3856      ((eq did-select 'quit)
3857       (and (eq major-mode 'gnus-summary-mode)
3858            (not (equal (current-buffer) kill-buffer))
3859            (kill-buffer (current-buffer)))
3860       (when kill-buffer
3861         (gnus-kill-or-deaden-summary kill-buffer))
3862       (if (not quit-config)
3863           (progn
3864             (set-buffer gnus-group-buffer)
3865             (gnus-group-jump-to-group group)
3866             (gnus-group-next-unread-group 1)
3867             (gnus-configure-windows 'group 'force))
3868         (gnus-handle-ephemeral-exit quit-config))
3869       ;; Finally signal the quit.
3870       (signal 'quit nil))
3871      ;; The group was successfully selected.
3872      (t
3873       (gnus-set-global-variables)
3874       ;; Save the active value in effect when the group was entered.
3875       (setq gnus-newsgroup-active
3876             (gnus-copy-sequence
3877              (gnus-active gnus-newsgroup-name)))
3878       ;; You can change the summary buffer in some way with this hook.
3879       (gnus-run-hooks 'gnus-select-group-hook)
3880       (when (memq 'summary (gnus-update-format-specifications
3881                             nil 'summary 'summary-mode 'summary-dummy))
3882         ;; The format specification for the summary line was updated,
3883         ;; so we need to update the mark positions as well.
3884         (gnus-update-summary-mark-positions))
3885       ;; Do score processing.
3886       (when gnus-use-scoring
3887         (gnus-possibly-score-headers))
3888       ;; Check whether to fill in the gaps in the threads.
3889       (when gnus-build-sparse-threads
3890         (gnus-build-sparse-threads))
3891       ;; Find the initial limit.
3892       (if show-all
3893           (let ((gnus-newsgroup-dormant nil))
3894             (gnus-summary-initial-limit show-all))
3895         (gnus-summary-initial-limit show-all))
3896       ;; Generate the summary buffer.
3897       (unless no-display
3898         (gnus-summary-prepare))
3899       (when gnus-use-trees
3900         (gnus-tree-open group)
3901         (setq gnus-summary-highlight-line-function
3902               'gnus-tree-highlight-article))
3903       ;; If the summary buffer is empty, but there are some low-scored
3904       ;; articles or some excluded dormants, we include these in the
3905       ;; buffer.
3906       (when (and (zerop (buffer-size))
3907                  (not no-display))
3908         (cond (gnus-newsgroup-dormant
3909                (gnus-summary-limit-include-dormant))
3910               ((and gnus-newsgroup-scored show-all)
3911                (gnus-summary-limit-include-expunged t))))
3912       ;; Function `gnus-apply-kill-file' must be called in this hook.
3913       (gnus-run-hooks 'gnus-apply-kill-hook)
3914       (if (and (zerop (buffer-size))
3915                (not no-display))
3916           (progn
3917             ;; This newsgroup is empty.
3918             (gnus-summary-catchup-and-exit nil t)
3919             (gnus-message 6 "No unread news")
3920             (when kill-buffer
3921               (gnus-kill-or-deaden-summary kill-buffer))
3922             ;; Return nil from this function.
3923             nil)
3924         ;; Hide conversation thread subtrees.  We cannot do this in
3925         ;; gnus-summary-prepare-hook since kill processing may not
3926         ;; work with hidden articles.
3927         (gnus-summary-maybe-hide-threads)
3928         (when kill-buffer
3929           (gnus-kill-or-deaden-summary kill-buffer))
3930         (gnus-summary-auto-select-subject)
3931         ;; Show first unread article if requested.
3932         (if (and (not no-article)
3933                  (not no-display)
3934                  gnus-newsgroup-unreads
3935                  gnus-auto-select-first)
3936             (progn
3937               (gnus-configure-windows 'summary)
3938               (let ((art (gnus-summary-article-number)))
3939                 (unless (and (not gnus-plugged)
3940                              (or (memq art gnus-newsgroup-undownloaded)
3941                                  (memq art gnus-newsgroup-downloadable)))
3942                   (gnus-summary-goto-article art))))
3943           ;; Don't select any articles.
3944           (gnus-summary-position-point)
3945           (gnus-configure-windows 'summary 'force)
3946           (gnus-set-mode-line 'summary))
3947         (when (and gnus-auto-center-group
3948                    (get-buffer-window gnus-group-buffer t))
3949           ;; Gotta use windows, because recenter does weird stuff if
3950           ;; the current buffer ain't the displayed window.
3951           (let ((owin (selected-window)))
3952             (select-window (get-buffer-window gnus-group-buffer t))
3953             (when (gnus-group-goto-group group)
3954               (recenter))
3955             (select-window owin)))
3956         ;; Mark this buffer as "prepared".
3957         (setq gnus-newsgroup-prepared t)
3958         (gnus-run-hooks 'gnus-summary-prepared-hook)
3959         (unless (gnus-ephemeral-group-p group)
3960           (gnus-group-update-group group))
3961         t)))))
3962
3963 (defun gnus-summary-auto-select-subject ()
3964   "Select the subject line on initial group entry."
3965   (goto-char (point-min))
3966   (cond
3967    ((eq gnus-auto-select-subject 'best)
3968     (gnus-summary-best-unread-subject))
3969    ((eq gnus-auto-select-subject 'unread)
3970     (gnus-summary-first-unread-subject))
3971    ((eq gnus-auto-select-subject 'unseen)
3972     (gnus-summary-first-unseen-subject))
3973    ((eq gnus-auto-select-subject 'unseen-or-unread)
3974     (gnus-summary-first-unseen-or-unread-subject))
3975    ((eq gnus-auto-select-subject 'first)
3976     ;; Do nothing.
3977     )
3978    ((functionp gnus-auto-select-subject)
3979     (funcall gnus-auto-select-subject))))
3980
3981 (defun gnus-summary-prepare ()
3982   "Generate the summary buffer."
3983   (interactive)
3984   (let ((buffer-read-only nil))
3985     (erase-buffer)
3986     (setq gnus-newsgroup-data nil
3987           gnus-newsgroup-data-reverse nil)
3988     (gnus-run-hooks 'gnus-summary-generate-hook)
3989     ;; Generate the buffer, either with threads or without.
3990     (when gnus-newsgroup-headers
3991       (gnus-summary-prepare-threads
3992        (if gnus-show-threads
3993            (gnus-sort-gathered-threads
3994             (funcall gnus-summary-thread-gathering-function
3995                      (gnus-sort-threads
3996                       (gnus-cut-threads (gnus-make-threads)))))
3997          ;; Unthreaded display.
3998          (gnus-sort-articles gnus-newsgroup-headers))))
3999     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4000     ;; Call hooks for modifying summary buffer.
4001     (goto-char (point-min))
4002     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4003
4004 (defsubst gnus-general-simplify-subject (subject)
4005   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4006   (setq subject
4007         (cond
4008          ;; Truncate the subject.
4009          (gnus-simplify-subject-functions
4010           (gnus-map-function gnus-simplify-subject-functions subject))
4011          ((numberp gnus-summary-gather-subject-limit)
4012           (setq subject (gnus-simplify-subject-re subject))
4013           (if (> (length subject) gnus-summary-gather-subject-limit)
4014               (substring subject 0 gnus-summary-gather-subject-limit)
4015             subject))
4016          ;; Fuzzily simplify it.
4017          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4018           (gnus-simplify-subject-fuzzy subject))
4019          ;; Just remove the leading "Re:".
4020          (t
4021           (gnus-simplify-subject-re subject))))
4022
4023   (if (and gnus-summary-gather-exclude-subject
4024            (string-match gnus-summary-gather-exclude-subject subject))
4025       nil                         ; This article shouldn't be gathered
4026     subject))
4027
4028 (defun gnus-summary-simplify-subject-query ()
4029   "Query where the respool algorithm would put this article."
4030   (interactive)
4031   (gnus-summary-select-article)
4032   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4033
4034 (defun gnus-gather-threads-by-subject (threads)
4035   "Gather threads by looking at Subject headers."
4036   (if (not gnus-summary-make-false-root)
4037       threads
4038     (let ((hashtb (gnus-make-hashtable 1024))
4039           (prev threads)
4040           (result threads)
4041           subject hthread whole-subject)
4042       (while threads
4043         (setq subject (gnus-general-simplify-subject
4044                        (setq whole-subject (mail-header-subject
4045                                             (caar threads)))))
4046         (when subject
4047           (if (setq hthread (gnus-gethash subject hashtb))
4048               (progn
4049                 ;; We enter a dummy root into the thread, if we
4050                 ;; haven't done that already.
4051                 (unless (stringp (caar hthread))
4052                   (setcar hthread (list whole-subject (car hthread))))
4053                 ;; We add this new gathered thread to this gathered
4054                 ;; thread.
4055                 (setcdr (car hthread)
4056                         (nconc (cdar hthread) (list (car threads))))
4057                 ;; Remove it from the list of threads.
4058                 (setcdr prev (cdr threads))
4059                 (setq threads prev))
4060             ;; Enter this thread into the hash table.
4061             (gnus-sethash subject
4062                           (if gnus-summary-make-false-root-always
4063                               (progn
4064                                 ;; If you want a dummy root above all
4065                                 ;; threads...
4066                                 (setcar threads (list whole-subject
4067                                                       (car threads)))
4068                                 threads)
4069                             threads)
4070                           hashtb)))
4071         (setq prev threads)
4072         (setq threads (cdr threads)))
4073       result)))
4074
4075 (defun gnus-gather-threads-by-references (threads)
4076   "Gather threads by looking at References headers."
4077   (let ((idhashtb (gnus-make-hashtable 1024))
4078         (thhashtb (gnus-make-hashtable 1024))
4079         (prev threads)
4080         (result threads)
4081         ids references id gthread gid entered ref)
4082     (while threads
4083       (when (setq references (mail-header-references (caar threads)))
4084         (setq id (mail-header-id (caar threads))
4085               ids (inline (gnus-split-references references))
4086               entered nil)
4087         (while (setq ref (pop ids))
4088           (setq ids (delete ref ids))
4089           (if (not (setq gid (gnus-gethash ref idhashtb)))
4090               (progn
4091                 (gnus-sethash ref id idhashtb)
4092                 (gnus-sethash id threads thhashtb))
4093             (setq gthread (gnus-gethash gid thhashtb))
4094             (unless entered
4095               ;; We enter a dummy root into the thread, if we
4096               ;; haven't done that already.
4097               (unless (stringp (caar gthread))
4098                 (setcar gthread (list (mail-header-subject (caar gthread))
4099                                       (car gthread))))
4100               ;; We add this new gathered thread to this gathered
4101               ;; thread.
4102               (setcdr (car gthread)
4103                       (nconc (cdar gthread) (list (car threads)))))
4104             ;; Add it into the thread hash table.
4105             (gnus-sethash id gthread thhashtb)
4106             (setq entered t)
4107             ;; Remove it from the list of threads.
4108             (setcdr prev (cdr threads))
4109             (setq threads prev))))
4110       (setq prev threads)
4111       (setq threads (cdr threads)))
4112     result))
4113
4114 (defun gnus-sort-gathered-threads (threads)
4115   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4116   (let ((result threads))
4117     (while threads
4118       (when (stringp (caar threads))
4119         (setcdr (car threads)
4120                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4121       (setq threads (cdr threads)))
4122     result))
4123
4124 (defun gnus-thread-loop-p (root thread)
4125   "Say whether ROOT is in THREAD."
4126   (let ((stack (list thread))
4127         (infloop 0)
4128         th)
4129     (while (setq thread (pop stack))
4130       (setq th (cdr thread))
4131       (while (and th
4132                   (not (eq (caar th) root)))
4133         (pop th))
4134       (if th
4135           ;; We have found a loop.
4136           (let (ref-dep)
4137             (setcdr thread (delq (car th) (cdr thread)))
4138             (if (boundp (setq ref-dep (intern "none"
4139                                               gnus-newsgroup-dependencies)))
4140                 (setcdr (symbol-value ref-dep)
4141                         (nconc (cdr (symbol-value ref-dep))
4142                                (list (car th))))
4143               (set ref-dep (list nil (car th))))
4144             (setq infloop 1
4145                   stack nil))
4146         ;; Push all the subthreads onto the stack.
4147         (push (cdr thread) stack)))
4148     infloop))
4149
4150 (defun gnus-make-threads ()
4151   "Go through the dependency hashtb and find the roots.  Return all threads."
4152   (let (threads)
4153     (while (catch 'infloop
4154              (mapatoms
4155               (lambda (refs)
4156                 ;; Deal with self-referencing References loops.
4157                 (when (and (car (symbol-value refs))
4158                            (not (zerop
4159                                  (apply
4160                                   '+
4161                                   (mapcar
4162                                    (lambda (thread)
4163                                      (gnus-thread-loop-p
4164                                       (car (symbol-value refs)) thread))
4165                                    (cdr (symbol-value refs)))))))
4166                   (setq threads nil)
4167                   (throw 'infloop t))
4168                 (unless (car (symbol-value refs))
4169                   ;; These threads do not refer back to any other
4170                   ;; articles, so they're roots.
4171                   (setq threads (append (cdr (symbol-value refs)) threads))))
4172               gnus-newsgroup-dependencies)))
4173     threads))
4174
4175 ;; Build the thread tree.
4176 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4177   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4178
4179 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4180 if it was already present.
4181
4182 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4183 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4184 Message-IDs will be renamed to a unique Message-ID before being
4185 entered.
4186
4187 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4188   (let* ((id (mail-header-id header))
4189          (id-dep (and id (intern id dependencies)))
4190          parent-id ref ref-dep ref-header replaced)
4191     ;; Enter this `header' in the `dependencies' table.
4192     (cond
4193      ((not id-dep)
4194       (setq header nil))
4195      ;; The first two cases do the normal part: enter a new `header'
4196      ;; in the `dependencies' table.
4197      ((not (boundp id-dep))
4198       (set id-dep (list header)))
4199      ((null (car (symbol-value id-dep)))
4200       (setcar (symbol-value id-dep) header))
4201
4202      ;; From here the `header' was already present in the
4203      ;; `dependencies' table.
4204      (force-new
4205       ;; Overrides an existing entry;
4206       ;; just set the header part of the entry.
4207       (setcar (symbol-value id-dep) header)
4208       (setq replaced t))
4209
4210      ;; Renames the existing `header' to a unique Message-ID.
4211      ((not gnus-summary-ignore-duplicates)
4212       ;; An article with this Message-ID has already been seen.
4213       ;; We rename the Message-ID.
4214       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4215            (list header))
4216       (mail-header-set-id header id))
4217
4218      ;; The last case ignores an existing entry, except it adds any
4219      ;; additional Xrefs (in case the two articles came from different
4220      ;; servers.
4221      ;; Also sets `header' to `nil' meaning that the `dependencies'
4222      ;; table was *not* modified.
4223      (t
4224       (mail-header-set-xref
4225        (car (symbol-value id-dep))
4226        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4227                    "")
4228                (or (mail-header-xref header) "")))
4229       (setq header nil)))
4230
4231     (when (and header (not replaced))
4232       ;; First check that we are not creating a References loop.
4233       (setq parent-id (gnus-parent-id (mail-header-references header)))
4234       (setq ref parent-id)
4235       (while (and ref
4236                   (setq ref-dep (intern-soft ref dependencies))
4237                   (boundp ref-dep)
4238                   (setq ref-header (car (symbol-value ref-dep))))
4239         (if (string= id ref)
4240             ;; Yuk!  This is a reference loop.  Make the article be a
4241             ;; root article.
4242             (progn
4243               (mail-header-set-references (car (symbol-value id-dep)) "none")
4244               (setq ref nil)
4245               (setq parent-id nil))
4246           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4247       (setq ref-dep (intern (or parent-id "none") dependencies))
4248       (if (boundp ref-dep)
4249           (setcdr (symbol-value ref-dep)
4250                   (nconc (cdr (symbol-value ref-dep))
4251                          (list (symbol-value id-dep))))
4252         (set ref-dep (list nil (symbol-value id-dep)))))
4253     header))
4254
4255 (defun gnus-extract-message-id-from-in-reply-to (string)
4256   (if (string-match "<[^>]+>" string)
4257       (substring string (match-beginning 0) (match-end 0))
4258     nil))
4259
4260 (defun gnus-build-sparse-threads ()
4261   (let ((headers gnus-newsgroup-headers)
4262         (mail-parse-charset gnus-newsgroup-charset)
4263         (gnus-summary-ignore-duplicates t)
4264         header references generation relations
4265         subject child end new-child date)
4266     ;; First we create an alist of generations/relations, where
4267     ;; generations is how much we trust the relation, and the relation
4268     ;; is parent/child.
4269     (gnus-message 7 "Making sparse threads...")
4270     (save-excursion
4271       (nnheader-set-temp-buffer " *gnus sparse threads*")
4272       (while (setq header (pop headers))
4273         (when (and (setq references (mail-header-references header))
4274                    (not (string= references "")))
4275           (insert references)
4276           (setq child (mail-header-id header)
4277                 subject (mail-header-subject header)
4278                 date (mail-header-date header)
4279                 generation 0)
4280           (while (search-backward ">" nil t)
4281             (setq end (1+ (point)))
4282             (when (search-backward "<" nil t)
4283               (setq new-child (buffer-substring (point) end))
4284               (push (list (incf generation)
4285                           child (setq child new-child)
4286                           subject date)
4287                     relations)))
4288           (when child
4289             (push (list (1+ generation) child nil subject) relations))
4290           (erase-buffer)))
4291       (kill-buffer (current-buffer)))
4292     ;; Sort over trustworthiness.
4293     (mapcar
4294      (lambda (relation)
4295        (when (gnus-dependencies-add-header
4296               (make-full-mail-header
4297                gnus-reffed-article-number
4298                (nth 3 relation) "" (or (nth 4 relation) "")
4299                (nth 1 relation)
4300                (or (nth 2 relation) "") 0 0 "")
4301               gnus-newsgroup-dependencies nil)
4302          (push gnus-reffed-article-number gnus-newsgroup-limit)
4303          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4304          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4305                gnus-newsgroup-reads)
4306          (decf gnus-reffed-article-number)))
4307      (sort relations 'car-less-than-car))
4308     (gnus-message 7 "Making sparse threads...done")))
4309
4310 (defun gnus-build-old-threads ()
4311   ;; Look at all the articles that refer back to old articles, and
4312   ;; fetch the headers for the articles that aren't there.  This will
4313   ;; build complete threads - if the roots haven't been expired by the
4314   ;; server, that is.
4315   (let ((mail-parse-charset gnus-newsgroup-charset)
4316         id heads)
4317     (mapatoms
4318      (lambda (refs)
4319        (when (not (car (symbol-value refs)))
4320          (setq heads (cdr (symbol-value refs)))
4321          (while heads
4322            (if (memq (mail-header-number (caar heads))
4323                      gnus-newsgroup-dormant)
4324                (setq heads (cdr heads))
4325              (setq id (symbol-name refs))
4326              (while (and (setq id (gnus-build-get-header id))
4327                          (not (car (gnus-id-to-thread id)))))
4328              (setq heads nil)))))
4329      gnus-newsgroup-dependencies)))
4330
4331 (defsubst gnus-remove-odd-characters (string)
4332   "Translate STRING into something that doesn't contain weird characters."
4333   (mm-subst-char-in-string
4334    ?\r ?\-
4335    (mm-subst-char-in-string ?\n ?\- string t) t))
4336
4337 ;; This function has to be called with point after the article number
4338 ;; on the beginning of the line.
4339 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4340   (let ((eol (point-at-eol))
4341         (buffer (current-buffer))
4342         header references in-reply-to)
4343
4344     ;; overview: [num subject from date id refs chars lines misc]
4345     (unwind-protect
4346         (let (x)
4347           (narrow-to-region (point) eol)
4348           (unless (eobp)
4349             (forward-char))
4350
4351           (setq header
4352                 (make-full-mail-header
4353                  number                 ; number
4354                  (condition-case ()     ; subject
4355                      (gnus-remove-odd-characters
4356                       (funcall gnus-decode-encoded-word-function
4357                                (setq x (nnheader-nov-field))))
4358                    (error x))
4359                  (condition-case ()     ; from
4360                      (gnus-remove-odd-characters
4361                       (funcall gnus-decode-encoded-address-function
4362                                (setq x (nnheader-nov-field))))
4363                    (error x))
4364                  (nnheader-nov-field)   ; date
4365                  (nnheader-nov-read-message-id number)  ; id
4366                  (setq references (nnheader-nov-field)) ; refs
4367                  (nnheader-nov-read-integer) ; chars
4368                  (nnheader-nov-read-integer) ; lines
4369                  (unless (eobp)
4370                    (if (looking-at "Xref: ")
4371                        (goto-char (match-end 0)))
4372                    (nnheader-nov-field)) ; Xref
4373                  (nnheader-nov-parse-extra)))) ; extra
4374
4375       (widen))
4376
4377     (when (and (string= references "")
4378                (setq in-reply-to (mail-header-extra header))
4379                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4380       (mail-header-set-references
4381        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4382
4383     (when gnus-alter-header-function
4384       (funcall gnus-alter-header-function header))
4385     (gnus-dependencies-add-header header dependencies force-new)))
4386
4387 (defun gnus-build-get-header (id)
4388   "Look through the buffer of NOV lines and find the header to ID.
4389 Enter this line into the dependencies hash table, and return
4390 the id of the parent article (if any)."
4391   (let ((deps gnus-newsgroup-dependencies)
4392         found header)
4393     (prog1
4394         (save-excursion
4395           (set-buffer nntp-server-buffer)
4396           (let ((case-fold-search nil))
4397             (goto-char (point-min))
4398             (while (and (not found)
4399                         (search-forward id nil t))
4400               (beginning-of-line)
4401               (setq found (looking-at
4402                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4403                                    (regexp-quote id))))
4404               (or found (beginning-of-line 2)))
4405             (when found
4406               (beginning-of-line)
4407               (and
4408                (setq header (gnus-nov-parse-line
4409                              (read (current-buffer)) deps))
4410                (gnus-parent-id (mail-header-references header))))))
4411       (when header
4412         (let ((number (mail-header-number header)))
4413           (push number gnus-newsgroup-limit)
4414           (push header gnus-newsgroup-headers)
4415           (if (memq number gnus-newsgroup-unselected)
4416               (progn
4417                 (setq gnus-newsgroup-unreads
4418                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4419                                                number))
4420                 (setq gnus-newsgroup-unselected
4421                       (delq number gnus-newsgroup-unselected)))
4422             (push number gnus-newsgroup-ancient)))))))
4423
4424 (defun gnus-build-all-threads ()
4425   "Read all the headers."
4426   (let ((gnus-summary-ignore-duplicates t)
4427         (mail-parse-charset gnus-newsgroup-charset)
4428         (dependencies gnus-newsgroup-dependencies)
4429         header article)
4430     (save-excursion
4431       (set-buffer nntp-server-buffer)
4432       (let ((case-fold-search nil))
4433         (goto-char (point-min))
4434         (while (not (eobp))
4435           (ignore-errors
4436             (setq article (read (current-buffer))
4437                   header (gnus-nov-parse-line article dependencies)))
4438           (when header
4439             (with-current-buffer gnus-summary-buffer
4440               (push header gnus-newsgroup-headers)
4441               (if (memq (setq article (mail-header-number header))
4442                         gnus-newsgroup-unselected)
4443                   (progn
4444                     (setq gnus-newsgroup-unreads
4445                           (gnus-add-to-sorted-list
4446                            gnus-newsgroup-unreads article))
4447                     (setq gnus-newsgroup-unselected
4448                           (delq article gnus-newsgroup-unselected)))
4449                 (push article gnus-newsgroup-ancient)))
4450             (forward-line 1)))))))
4451
4452 (defun gnus-summary-update-article-line (article header)
4453   "Update the line for ARTICLE using HEADER."
4454   (let* ((id (mail-header-id header))
4455          (thread (gnus-id-to-thread id)))
4456     (unless thread
4457       (error "Article in no thread"))
4458     ;; Update the thread.
4459     (setcar thread header)
4460     (gnus-summary-goto-subject article)
4461     (let* ((datal (gnus-data-find-list article))
4462            (data (car datal))
4463            (buffer-read-only nil)
4464            (level (gnus-summary-thread-level)))
4465       (gnus-delete-line)
4466       (let ((inserted (- (point)
4467                          (progn
4468                            (gnus-summary-insert-line
4469                             header level nil
4470                             (memq article gnus-newsgroup-undownloaded)
4471                             (gnus-article-mark article)
4472                             (memq article gnus-newsgroup-replied)
4473                             (memq article gnus-newsgroup-expirable)
4474                             ;; Only insert the Subject string when it's different
4475                             ;; from the previous Subject string.
4476                             (if (and
4477                                  gnus-show-threads
4478                                  (gnus-subject-equal
4479                                   (condition-case ()
4480                                       (mail-header-subject
4481                                        (gnus-data-header
4482                                         (cadr
4483                                          (gnus-data-find-list
4484                                           article
4485                                           (gnus-data-list t)))))
4486                                     ;; Error on the side of excessive subjects.
4487                                     (error ""))
4488                                   (mail-header-subject header)))
4489                                 ""
4490                               (mail-header-subject header))
4491                             nil (cdr (assq article gnus-newsgroup-scored))
4492                             (memq article gnus-newsgroup-processable))
4493                            (point)))))
4494         (when (cdr datal)
4495           (gnus-data-update-list
4496            (cdr datal)
4497            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4498
4499 (defun gnus-summary-update-article (article &optional iheader)
4500   "Update ARTICLE in the summary buffer."
4501   (set-buffer gnus-summary-buffer)
4502   (let* ((header (gnus-summary-article-header article))
4503          (id (mail-header-id header))
4504          (data (gnus-data-find article))
4505          (thread (gnus-id-to-thread id))
4506          (references (mail-header-references header))
4507          (parent
4508           (gnus-id-to-thread
4509            (or (gnus-parent-id
4510                 (when (and references
4511                            (not (equal "" references)))
4512                   references))
4513                "none")))
4514          (buffer-read-only nil)
4515          (old (car thread)))
4516     (when thread
4517       (unless iheader
4518         (setcar thread nil)
4519         (when parent
4520           (delq thread parent)))
4521       (if (gnus-summary-insert-subject id header)
4522           ;; Set the (possibly) new article number in the data structure.
4523           (gnus-data-set-number data (gnus-id-to-article id))
4524         (setcar thread old)
4525         nil))))
4526
4527 (defun gnus-rebuild-thread (id &optional line)
4528   "Rebuild the thread containing ID.
4529 If LINE, insert the rebuilt thread starting on line LINE."
4530   (let ((buffer-read-only nil)
4531         old-pos current thread data)
4532     (if (not gnus-show-threads)
4533         (setq thread (list (car (gnus-id-to-thread id))))
4534       ;; Get the thread this article is part of.
4535       (setq thread (gnus-remove-thread id)))
4536     (setq old-pos (point-at-bol))
4537     (setq current (save-excursion
4538                     (and (re-search-backward "[\r\n]" nil t)
4539                          (gnus-summary-article-number))))
4540     ;; If this is a gathered thread, we have to go some re-gathering.
4541     (when (stringp (car thread))
4542       (let ((subject (car thread))
4543             roots thr)
4544         (setq thread (cdr thread))
4545         (while thread
4546           (unless (memq (setq thr (gnus-id-to-thread
4547                                    (gnus-root-id
4548                                     (mail-header-id (caar thread)))))
4549                         roots)
4550             (push thr roots))
4551           (setq thread (cdr thread)))
4552         ;; We now have all (unique) roots.
4553         (if (= (length roots) 1)
4554             ;; All the loose roots are now one solid root.
4555             (setq thread (car roots))
4556           (setq thread (cons subject (gnus-sort-threads roots))))))
4557     (let (threads)
4558       ;; We then insert this thread into the summary buffer.
4559       (when line
4560         (goto-char (point-min))
4561         (forward-line (1- line)))
4562       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4563         (if gnus-show-threads
4564             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4565           (gnus-summary-prepare-unthreaded thread))
4566         (setq data (nreverse gnus-newsgroup-data))
4567         (setq threads gnus-newsgroup-threads))
4568       ;; We splice the new data into the data structure.
4569       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4570       ;;!!! then we want to insert at the beginning of the buffer.
4571       ;;!!! That happens to be true with Gnus now, but that may
4572       ;;!!! change in the future.  Perhaps.
4573       (gnus-data-enter-list
4574        (if line nil current) data (- (point) old-pos))
4575       (setq gnus-newsgroup-threads
4576             (nconc threads gnus-newsgroup-threads))
4577       (gnus-data-compute-positions))))
4578
4579 (defun gnus-number-to-header (number)
4580   "Return the header for article NUMBER."
4581   (let ((headers gnus-newsgroup-headers))
4582     (while (and headers
4583                 (not (= number (mail-header-number (car headers)))))
4584       (pop headers))
4585     (when headers
4586       (car headers))))
4587
4588 (defun gnus-parent-headers (in-headers &optional generation)
4589   "Return the headers of the GENERATIONeth parent of HEADERS."
4590   (unless generation
4591     (setq generation 1))
4592   (let ((parent t)
4593         (headers in-headers)
4594         references)
4595     (while (and parent
4596                 (not (zerop generation))
4597                 (setq references (mail-header-references headers)))
4598       (setq headers (if (and references
4599                              (setq parent (gnus-parent-id references)))
4600                         (car (gnus-id-to-thread parent))
4601                       nil))
4602       (decf generation))
4603     (and (not (eq headers in-headers))
4604          headers)))
4605
4606 (defun gnus-id-to-thread (id)
4607   "Return the (sub-)thread where ID appears."
4608   (gnus-gethash id gnus-newsgroup-dependencies))
4609
4610 (defun gnus-id-to-article (id)
4611   "Return the article number of ID."
4612   (let ((thread (gnus-id-to-thread id)))
4613     (when (and thread
4614                (car thread))
4615       (mail-header-number (car thread)))))
4616
4617 (defun gnus-id-to-header (id)
4618   "Return the article headers of ID."
4619   (car (gnus-id-to-thread id)))
4620
4621 (defun gnus-article-displayed-root-p (article)
4622   "Say whether ARTICLE is a root(ish) article."
4623   (let ((level (gnus-summary-thread-level article))
4624         (refs (mail-header-references  (gnus-summary-article-header article)))
4625         particle)
4626     (cond
4627      ((null level) nil)
4628      ((zerop level) t)
4629      ((null refs) t)
4630      ((null (gnus-parent-id refs)) t)
4631      ((and (= 1 level)
4632            (null (setq particle (gnus-id-to-article
4633                                  (gnus-parent-id refs))))
4634            (null (gnus-summary-thread-level particle)))))))
4635
4636 (defun gnus-root-id (id)
4637   "Return the id of the root of the thread where ID appears."
4638   (let (last-id prev)
4639     (while (and id (setq prev (car (gnus-id-to-thread id))))
4640       (setq last-id id
4641             id (gnus-parent-id (mail-header-references prev))))
4642     last-id))
4643
4644 (defun gnus-articles-in-thread (thread)
4645   "Return the list of articles in THREAD."
4646   (cons (mail-header-number (car thread))
4647         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4648
4649 (defun gnus-remove-thread (id &optional dont-remove)
4650   "Remove the thread that has ID in it."
4651   (let (headers thread last-id)
4652     ;; First go up in this thread until we find the root.
4653     (setq last-id (gnus-root-id id)
4654           headers (message-flatten-list (gnus-id-to-thread last-id)))
4655     ;; We have now found the real root of this thread.  It might have
4656     ;; been gathered into some loose thread, so we have to search
4657     ;; through the threads to find the thread we wanted.
4658     (let ((threads gnus-newsgroup-threads)
4659           sub)
4660       (while threads
4661         (setq sub (car threads))
4662         (if (stringp (car sub))
4663             ;; This is a gathered thread, so we look at the roots
4664             ;; below it to find whether this article is in this
4665             ;; gathered root.
4666             (progn
4667               (setq sub (cdr sub))
4668               (while sub
4669                 (when (member (caar sub) headers)
4670                   (setq thread (car threads)
4671                         threads nil
4672                         sub nil))
4673                 (setq sub (cdr sub))))
4674           ;; It's an ordinary thread, so we check it.
4675           (when (eq (car sub) (car headers))
4676             (setq thread sub
4677                   threads nil)))
4678         (setq threads (cdr threads)))
4679       ;; If this article is in no thread, then it's a root.
4680       (if thread
4681           (unless dont-remove
4682             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4683         (setq thread (gnus-id-to-thread last-id)))
4684       (when thread
4685         (prog1
4686             thread                      ; We return this thread.
4687           (unless dont-remove
4688             (if (stringp (car thread))
4689                 (progn
4690                   ;; If we use dummy roots, then we have to remove the
4691                   ;; dummy root as well.
4692                   (when (eq gnus-summary-make-false-root 'dummy)
4693                     ;; We go to the dummy root by going to
4694                     ;; the first sub-"thread", and then one line up.
4695                     (gnus-summary-goto-article
4696                      (mail-header-number (caadr thread)))
4697                     (forward-line -1)
4698                     (gnus-delete-line)
4699                     (gnus-data-compute-positions))
4700                   (setq thread (cdr thread))
4701                   (while thread
4702                     (gnus-remove-thread-1 (car thread))
4703                     (setq thread (cdr thread))))
4704               (gnus-remove-thread-1 thread))))))))
4705
4706 (defun gnus-remove-thread-1 (thread)
4707   "Remove the thread THREAD recursively."
4708   (let ((number (mail-header-number (pop thread)))
4709         d)
4710     (setq thread (reverse thread))
4711     (while thread
4712       (gnus-remove-thread-1 (pop thread)))
4713     (when (setq d (gnus-data-find number))
4714       (goto-char (gnus-data-pos d))
4715       (gnus-summary-show-thread)
4716       (gnus-data-remove
4717        number
4718        (- (point-at-bol)
4719           (prog1
4720               (1+ (point-at-eol))
4721             (gnus-delete-line)))))))
4722
4723 (defun gnus-sort-threads-recursive (threads func)
4724   (sort (mapcar (lambda (thread)
4725                   (cons (car thread)
4726                         (and (cdr thread)
4727                              (gnus-sort-threads-recursive (cdr thread) func))))
4728                 threads) func))
4729
4730 (defun gnus-sort-threads-loop (threads func)
4731   (let* ((superthread (cons nil threads))
4732          (stack (list (cons superthread threads)))
4733          remaining-threads thread)
4734     (while stack
4735       (setq remaining-threads (cdr (car stack)))
4736       (if remaining-threads
4737           (progn (setq thread (car remaining-threads))
4738                  (setcdr (car stack) (cdr remaining-threads))
4739                  (if (cdr thread)
4740                      (push (cons thread (cdr thread)) stack)))
4741         (setq thread (caar stack))
4742         (setcdr thread (sort (cdr thread) func))
4743         (pop stack)))
4744     (cdr superthread)))
4745
4746 (defun gnus-sort-threads (threads)
4747   "Sort THREADS."
4748   (if (not gnus-thread-sort-functions)
4749       threads
4750     (gnus-message 8 "Sorting threads...")
4751     (prog1
4752         (condition-case nil
4753             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4754               (gnus-sort-threads-recursive
4755                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4756           ;; Even after binding max-lisp-eval-depth, the recursive
4757           ;; sorter might fail for very long threads.  In that case,
4758           ;; try using a (less well-tested) non-recursive sorter.
4759           (error (gnus-sort-threads-loop
4760                   threads (gnus-make-sort-function
4761                            gnus-thread-sort-functions))))
4762       (gnus-message 8 "Sorting threads...done"))))
4763
4764 (defun gnus-sort-articles (articles)
4765   "Sort ARTICLES."
4766   (when gnus-article-sort-functions
4767     (gnus-message 7 "Sorting articles...")
4768     (prog1
4769         (setq gnus-newsgroup-headers
4770               (sort articles (gnus-make-sort-function
4771                               gnus-article-sort-functions)))
4772       (gnus-message 7 "Sorting articles...done"))))
4773
4774 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4775 (defmacro gnus-thread-header (thread)
4776   "Return header of first article in THREAD.
4777 Note that THREAD must never, ever be anything else than a variable -
4778 using some other form will lead to serious barfage."
4779   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4780   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4781   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4782         (vector thread) 2))
4783
4784 (defsubst gnus-article-sort-by-number (h1 h2)
4785   "Sort articles by article number."
4786   (< (mail-header-number h1)
4787      (mail-header-number h2)))
4788
4789 (defun gnus-thread-sort-by-number (h1 h2)
4790   "Sort threads by root article number."
4791   (gnus-article-sort-by-number
4792    (gnus-thread-header h1) (gnus-thread-header h2)))
4793
4794 (defsubst gnus-article-sort-by-random (h1 h2)
4795   "Sort articles by article number."
4796   (zerop (random 2)))
4797
4798 (defun gnus-thread-sort-by-random (h1 h2)
4799   "Sort threads by root article number."
4800   (gnus-article-sort-by-random
4801    (gnus-thread-header h1) (gnus-thread-header h2)))
4802
4803 (defsubst gnus-article-sort-by-lines (h1 h2)
4804   "Sort articles by article Lines header."
4805   (< (mail-header-lines h1)
4806      (mail-header-lines h2)))
4807
4808 (defun gnus-thread-sort-by-lines (h1 h2)
4809   "Sort threads by root article Lines header."
4810   (gnus-article-sort-by-lines
4811    (gnus-thread-header h1) (gnus-thread-header h2)))
4812
4813 (defsubst gnus-article-sort-by-chars (h1 h2)
4814   "Sort articles by octet length."
4815   (< (mail-header-chars h1)
4816      (mail-header-chars h2)))
4817
4818 (defun gnus-thread-sort-by-chars (h1 h2)
4819   "Sort threads by root article octet length."
4820   (gnus-article-sort-by-chars
4821    (gnus-thread-header h1) (gnus-thread-header h2)))
4822
4823 (defsubst gnus-article-sort-by-author (h1 h2)
4824   "Sort articles by root author."
4825   (string-lessp
4826    (let ((extract (funcall
4827                    gnus-extract-address-components
4828                    (mail-header-from h1))))
4829      (or (car extract) (cadr extract) ""))
4830    (let ((extract (funcall
4831                    gnus-extract-address-components
4832                    (mail-header-from h2))))
4833      (or (car extract) (cadr extract) ""))))
4834
4835 (defun gnus-thread-sort-by-author (h1 h2)
4836   "Sort threads by root author."
4837   (gnus-article-sort-by-author
4838    (gnus-thread-header h1)  (gnus-thread-header h2)))
4839
4840 (defsubst gnus-article-sort-by-recipient (h1 h2)
4841   "Sort articles by recipient."
4842   (string-lessp
4843    (let ((extract (funcall
4844                    gnus-extract-address-components
4845                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4846      (or (car extract) (cadr extract)))
4847    (let ((extract (funcall
4848                    gnus-extract-address-components
4849                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4850      (or (car extract) (cadr extract)))))
4851
4852 (defun gnus-thread-sort-by-recipient (h1 h2)
4853   "Sort threads by root recipient."
4854   (gnus-article-sort-by-recipient
4855    (gnus-thread-header h1) (gnus-thread-header h2)))
4856
4857 (defsubst gnus-article-sort-by-subject (h1 h2)
4858   "Sort articles by root subject."
4859   (string-lessp
4860    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4861    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4862
4863 (defun gnus-thread-sort-by-subject (h1 h2)
4864   "Sort threads by root subject."
4865   (gnus-article-sort-by-subject
4866    (gnus-thread-header h1) (gnus-thread-header h2)))
4867
4868 (defsubst gnus-article-sort-by-date (h1 h2)
4869   "Sort articles by root article date."
4870   (time-less-p
4871    (gnus-date-get-time (mail-header-date h1))
4872    (gnus-date-get-time (mail-header-date h2))))
4873
4874 (defun gnus-thread-sort-by-date (h1 h2)
4875   "Sort threads by root article date."
4876   (gnus-article-sort-by-date
4877    (gnus-thread-header h1) (gnus-thread-header h2)))
4878
4879 (defsubst gnus-article-sort-by-score (h1 h2)
4880   "Sort articles by root article score.
4881 Unscored articles will be counted as having a score of zero."
4882   (> (or (cdr (assq (mail-header-number h1)
4883                     gnus-newsgroup-scored))
4884          gnus-summary-default-score 0)
4885      (or (cdr (assq (mail-header-number h2)
4886                     gnus-newsgroup-scored))
4887          gnus-summary-default-score 0)))
4888
4889 (defun gnus-thread-sort-by-score (h1 h2)
4890   "Sort threads by root article score."
4891   (gnus-article-sort-by-score
4892    (gnus-thread-header h1) (gnus-thread-header h2)))
4893
4894 (defun gnus-thread-sort-by-total-score (h1 h2)
4895   "Sort threads by the sum of all scores in the thread.
4896 Unscored articles will be counted as having a score of zero."
4897   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4898
4899 (defun gnus-thread-total-score (thread)
4900   ;; This function find the total score of THREAD.
4901   (cond
4902    ((null thread)
4903     0)
4904    ((consp thread)
4905     (if (stringp (car thread))
4906         (apply gnus-thread-score-function 0
4907                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4908       (gnus-thread-total-score-1 thread)))
4909    (t
4910     (gnus-thread-total-score-1 (list thread)))))
4911
4912 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4913   "Sort threads such that the thread with the most recently arrived article comes first."
4914   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4915
4916 (defun gnus-thread-highest-number (thread)
4917   "Return the highest article number in THREAD."
4918   (apply 'max (mapcar (lambda (header)
4919                         (mail-header-number header))
4920                       (message-flatten-list thread))))
4921
4922 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4923   "Sort threads such that the thread with the most recently dated article comes first."
4924   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4925
4926 (defun gnus-thread-latest-date (thread)
4927   "Return the highest article date in THREAD."
4928   (let ((previous-time 0))
4929     (apply 'max
4930            (mapcar
4931             (lambda (header)
4932               (setq previous-time
4933                     (condition-case ()
4934                         (time-to-seconds (mail-header-parse-date
4935                                           (mail-header-date header)))
4936                       (error previous-time))))
4937             (sort
4938              (message-flatten-list thread)
4939              (lambda (h1 h2)
4940                (< (mail-header-number h1)
4941                   (mail-header-number h2))))))))
4942
4943 (defun gnus-thread-total-score-1 (root)
4944   ;; This function find the total score of the thread below ROOT.
4945   (setq root (car root))
4946   (apply gnus-thread-score-function
4947          (or (append
4948               (mapcar 'gnus-thread-total-score
4949                       (cdr (gnus-id-to-thread (mail-header-id root))))
4950               (when (> (mail-header-number root) 0)
4951                 (list (or (cdr (assq (mail-header-number root)
4952                                      gnus-newsgroup-scored))
4953                           gnus-summary-default-score 0))))
4954              (list gnus-summary-default-score)
4955              '(0))))
4956
4957 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4958 (defvar gnus-tmp-prev-subject nil)
4959 (defvar gnus-tmp-false-parent nil)
4960 (defvar gnus-tmp-root-expunged nil)
4961 (defvar gnus-tmp-dummy-line nil)
4962
4963 (eval-when-compile (defvar gnus-tmp-header))
4964 (defun gnus-extra-header (type &optional header)
4965   "Return the extra header of TYPE."
4966   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4967       ""))
4968
4969 (defvar gnus-tmp-thread-tree-header-string "")
4970
4971 (defcustom gnus-sum-thread-tree-root "> "
4972   "With %B spec, used for the root of a thread.
4973 If nil, use subject instead."
4974   :version "22.1"
4975   :type '(radio (const :format "%v  " nil) string)
4976   :group 'gnus-thread)
4977
4978 (defcustom gnus-sum-thread-tree-false-root "> "
4979   "With %B spec, used for a false root of a thread.
4980 If nil, use subject instead."
4981   :version "22.1"
4982   :type '(radio (const :format "%v  " nil) string)
4983   :group 'gnus-thread)
4984
4985 (defcustom gnus-sum-thread-tree-single-indent ""
4986   "With %B spec, used for a thread with just one message.
4987 If nil, use subject instead."
4988   :version "22.1"
4989   :type '(radio (const :format "%v  " nil) string)
4990   :group 'gnus-thread)
4991
4992 (defcustom gnus-sum-thread-tree-vertical "| "
4993   "With %B spec, used for drawing a vertical line."
4994   :version "22.1"
4995   :type 'string
4996   :group 'gnus-thread)
4997
4998 (defcustom gnus-sum-thread-tree-indent "  "
4999   "With %B spec, used for indenting."
5000   :version "22.1"
5001   :type 'string
5002   :group 'gnus-thread)
5003
5004 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5005   "With %B spec, used for a leaf with brothers."
5006   :version "22.1"
5007   :type 'string
5008   :group 'gnus-thread)
5009
5010 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5011   "With %B spec, used for a leaf without brothers."
5012   :version "22.1"
5013   :type 'string
5014   :group 'gnus-thread)
5015
5016 (defun gnus-summary-prepare-threads (threads)
5017   "Prepare summary buffer from THREADS and indentation LEVEL.
5018 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5019 or a straight list of headers."
5020   (gnus-message 7 "Generating summary...")
5021
5022   (setq gnus-newsgroup-threads threads)
5023   (beginning-of-line)
5024
5025   (let ((gnus-tmp-level 0)
5026         (default-score (or gnus-summary-default-score 0))
5027         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5028         (building-line-count gnus-summary-display-while-building)
5029         (building-count (integerp gnus-summary-display-while-building))
5030         thread number subject stack state gnus-tmp-gathered beg-match
5031         new-roots gnus-tmp-new-adopts thread-end simp-subject
5032         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5033         gnus-tmp-replied gnus-tmp-subject-or-nil
5034         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5035         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5036         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5037         tree-stack)
5038
5039     (setq gnus-tmp-prev-subject nil
5040           gnus-tmp-thread-tree-header-string "")
5041
5042     (if (vectorp (car threads))
5043         ;; If this is a straight (sic) list of headers, then a
5044         ;; threaded summary display isn't required, so we just create
5045         ;; an unthreaded one.
5046         (gnus-summary-prepare-unthreaded threads)
5047
5048       ;; Do the threaded display.
5049
5050       (if gnus-summary-display-while-building
5051           (switch-to-buffer (buffer-name)))
5052       (while (or threads stack gnus-tmp-new-adopts new-roots)
5053
5054         (if (and (= gnus-tmp-level 0)
5055                  (or (not stack)
5056                      (= (caar stack) 0))
5057                  (not gnus-tmp-false-parent)
5058                  (or gnus-tmp-new-adopts new-roots))
5059             (if gnus-tmp-new-adopts
5060                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5061                       thread (list (car gnus-tmp-new-adopts))
5062                       gnus-tmp-header (caar thread)
5063                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5064               (when new-roots
5065                 (setq thread (list (car new-roots))
5066                       gnus-tmp-header (caar thread)
5067                       new-roots (cdr new-roots))))
5068
5069           (if threads
5070               ;; If there are some threads, we do them before the
5071               ;; threads on the stack.
5072               (setq thread threads
5073                     gnus-tmp-header (caar thread))
5074             ;; There were no current threads, so we pop something off
5075             ;; the stack.
5076             (setq state (car stack)
5077                   gnus-tmp-level (car state)
5078                   tree-stack (cadr state)
5079                   thread (caddr state)
5080                   stack (cdr stack)
5081                   gnus-tmp-header (caar thread))))
5082
5083         (setq gnus-tmp-false-parent nil)
5084         (setq gnus-tmp-root-expunged nil)
5085         (setq thread-end nil)
5086
5087         (if (stringp gnus-tmp-header)
5088             ;; The header is a dummy root.
5089             (cond
5090              ((eq gnus-summary-make-false-root 'adopt)
5091               ;; We let the first article adopt the rest.
5092               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5093                                                (cddar thread)))
5094               (setq gnus-tmp-gathered
5095                     (nconc (mapcar
5096                             (lambda (h) (mail-header-number (car h)))
5097                             (cddar thread))
5098                            gnus-tmp-gathered))
5099               (setq thread (cons (list (caar thread)
5100                                        (cadar thread))
5101                                  (cdr thread)))
5102               (setq gnus-tmp-level -1
5103                     gnus-tmp-false-parent t))
5104              ((eq gnus-summary-make-false-root 'empty)
5105               ;; We print adopted articles with empty subject fields.
5106               (setq gnus-tmp-gathered
5107                     (nconc (mapcar
5108                             (lambda (h) (mail-header-number (car h)))
5109                             (cddar thread))
5110                            gnus-tmp-gathered))
5111               (setq gnus-tmp-level -1))
5112              ((eq gnus-summary-make-false-root 'dummy)
5113               ;; We remember that we probably want to output a dummy
5114               ;; root.
5115               (setq gnus-tmp-dummy-line gnus-tmp-header)
5116               (setq gnus-tmp-prev-subject gnus-tmp-header))
5117              (t
5118               ;; We do not make a root for the gathered
5119               ;; sub-threads at all.
5120               (setq gnus-tmp-level -1)))
5121
5122           (setq number (mail-header-number gnus-tmp-header)
5123                 subject (mail-header-subject gnus-tmp-header)
5124                 simp-subject (gnus-simplify-subject-fully subject))
5125
5126           (cond
5127            ;; If the thread has changed subject, we might want to make
5128            ;; this subthread into a root.
5129            ((and (null gnus-thread-ignore-subject)
5130                  (not (zerop gnus-tmp-level))
5131                  gnus-tmp-prev-subject
5132                  (not (string= gnus-tmp-prev-subject simp-subject)))
5133             (setq new-roots (nconc new-roots (list (car thread)))
5134                   thread-end t
5135                   gnus-tmp-header nil))
5136            ;; If the article lies outside the current limit,
5137            ;; then we do not display it.
5138            ((not (memq number gnus-newsgroup-limit))
5139             (setq gnus-tmp-gathered
5140                   (nconc (mapcar
5141                           (lambda (h) (mail-header-number (car h)))
5142                           (cdar thread))
5143                          gnus-tmp-gathered))
5144             (setq gnus-tmp-new-adopts (if (cdar thread)
5145                                           (append gnus-tmp-new-adopts
5146                                                   (cdar thread))
5147                                         gnus-tmp-new-adopts)
5148                   thread-end t
5149                   gnus-tmp-header nil)
5150             (when (zerop gnus-tmp-level)
5151               (setq gnus-tmp-root-expunged t)))
5152            ;; Perhaps this article is to be marked as read?
5153            ((and gnus-summary-mark-below
5154                  (< (or (cdr (assq number gnus-newsgroup-scored))
5155                         default-score)
5156                     gnus-summary-mark-below)
5157                  ;; Don't touch sparse articles.
5158                  (not (gnus-summary-article-sparse-p number))
5159                  (not (gnus-summary-article-ancient-p number)))
5160             (setq gnus-newsgroup-unreads
5161                   (delq number gnus-newsgroup-unreads))
5162             (if gnus-newsgroup-auto-expire
5163                 (setq gnus-newsgroup-expirable
5164                       (gnus-add-to-sorted-list
5165                        gnus-newsgroup-expirable number))
5166               (push (cons number gnus-low-score-mark)
5167                     gnus-newsgroup-reads))))
5168
5169           (when gnus-tmp-header
5170             ;; We may have an old dummy line to output before this
5171             ;; article.
5172             (when (and gnus-tmp-dummy-line
5173                        (gnus-subject-equal
5174                         gnus-tmp-dummy-line
5175                         (mail-header-subject gnus-tmp-header)))
5176               (gnus-summary-insert-dummy-line
5177                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5178               (setq gnus-tmp-dummy-line nil))
5179
5180             ;; Compute the mark.
5181             (setq gnus-tmp-unread (gnus-article-mark number))
5182
5183             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5184                                   gnus-tmp-header gnus-tmp-level)
5185                   gnus-newsgroup-data)
5186
5187             ;; Actually insert the line.
5188             (setq
5189              gnus-tmp-subject-or-nil
5190              (cond
5191               ((and gnus-thread-ignore-subject
5192                     gnus-tmp-prev-subject
5193                     (not (string= gnus-tmp-prev-subject simp-subject)))
5194                subject)
5195               ((zerop gnus-tmp-level)
5196                (if (and (eq gnus-summary-make-false-root 'empty)
5197                         (memq number gnus-tmp-gathered)
5198                         gnus-tmp-prev-subject
5199                         (string= gnus-tmp-prev-subject simp-subject))
5200                    gnus-summary-same-subject
5201                  subject))
5202               (t gnus-summary-same-subject)))
5203             (if (and (eq gnus-summary-make-false-root 'adopt)
5204                      (= gnus-tmp-level 1)
5205                      (memq number gnus-tmp-gathered))
5206                 (setq gnus-tmp-opening-bracket ?\<
5207                       gnus-tmp-closing-bracket ?\>)
5208               (setq gnus-tmp-opening-bracket ?\[
5209                     gnus-tmp-closing-bracket ?\]))
5210             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5211                 (gnus-make-thread-indent-array
5212                  (max (* 2 (length gnus-thread-indent-array))
5213                       gnus-tmp-level)))
5214             (setq
5215              gnus-tmp-indentation
5216              (aref gnus-thread-indent-array gnus-tmp-level)
5217              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5218              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5219                                 gnus-summary-default-score 0)
5220              gnus-tmp-score-char
5221              (if (or (null gnus-summary-default-score)
5222                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5223                          gnus-summary-zcore-fuzz))
5224                  ?                      ;Whitespace
5225                (if (< gnus-tmp-score gnus-summary-default-score)
5226                    gnus-score-below-mark gnus-score-over-mark))
5227              gnus-tmp-replied
5228              (cond ((memq number gnus-newsgroup-processable)
5229                     gnus-process-mark)
5230                    ((memq number gnus-newsgroup-cached)
5231                     gnus-cached-mark)
5232                    ((memq number gnus-newsgroup-replied)
5233                     gnus-replied-mark)
5234                    ((memq number gnus-newsgroup-forwarded)
5235                     gnus-forwarded-mark)
5236                    ((memq number gnus-newsgroup-saved)
5237                     gnus-saved-mark)
5238                    ((memq number gnus-newsgroup-recent)
5239                     gnus-recent-mark)
5240                    ((memq number gnus-newsgroup-unseen)
5241                     gnus-unseen-mark)
5242                    (t gnus-no-mark))
5243              gnus-tmp-downloaded
5244              (cond ((memq number gnus-newsgroup-undownloaded)
5245                     gnus-undownloaded-mark)
5246                    (gnus-newsgroup-agentized
5247                     gnus-downloaded-mark)
5248                    (t
5249                     gnus-no-mark))
5250              gnus-tmp-from (mail-header-from gnus-tmp-header)
5251              gnus-tmp-name
5252              (cond
5253               ((string-match "<[^>]+> *$" gnus-tmp-from)
5254                (setq beg-match (match-beginning 0))
5255                (or (and (string-match "^\".+\"" gnus-tmp-from)
5256                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5257                    (substring gnus-tmp-from 0 beg-match)))
5258               ((string-match "(.+)" gnus-tmp-from)
5259                (substring gnus-tmp-from
5260                           (1+ (match-beginning 0)) (1- (match-end 0))))
5261               (t gnus-tmp-from))
5262
5263              ;; Do the %B string
5264              gnus-tmp-thread-tree-header-string
5265              (cond
5266               ((not gnus-show-threads) "")
5267               ((zerop gnus-tmp-level)
5268                (cond ((cdar thread)
5269                       (or gnus-sum-thread-tree-root subject))
5270                      (gnus-tmp-new-adopts
5271                       (or gnus-sum-thread-tree-false-root subject))
5272                      (t
5273                       (or gnus-sum-thread-tree-single-indent subject))))
5274               (t
5275                (concat (apply 'concat
5276                               (mapcar (lambda (item)
5277                                         (if (= item 1)
5278                                             gnus-sum-thread-tree-vertical
5279                                           gnus-sum-thread-tree-indent))
5280                                       (cdr (reverse tree-stack))))
5281                        (if (nth 1 thread)
5282                            gnus-sum-thread-tree-leaf-with-other
5283                          gnus-sum-thread-tree-single-leaf)))))
5284             (when (string= gnus-tmp-name "")
5285               (setq gnus-tmp-name gnus-tmp-from))
5286             (unless (numberp gnus-tmp-lines)
5287               (setq gnus-tmp-lines -1))
5288             (if (= gnus-tmp-lines -1)
5289                 (setq gnus-tmp-lines "?")
5290               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5291               (gnus-put-text-property
5292              (point)
5293              (progn (eval gnus-summary-line-format-spec) (point))
5294                'gnus-number number)
5295             (when gnus-visual-p
5296               (forward-line -1)
5297               (gnus-run-hooks 'gnus-summary-update-hook)
5298               (forward-line 1))
5299
5300             (setq gnus-tmp-prev-subject simp-subject)))
5301
5302         (when (nth 1 thread)
5303           (push (list (max 0 gnus-tmp-level)
5304                       (copy-sequence tree-stack)
5305                       (nthcdr 1 thread))
5306                 stack))
5307         (push (if (nth 1 thread) 1 0) tree-stack)
5308         (incf gnus-tmp-level)
5309         (setq threads (if thread-end nil (cdar thread)))
5310         (if gnus-summary-display-while-building
5311             (if building-count
5312                 (progn
5313                   ;; use a set frequency
5314                   (setq building-line-count (1- building-line-count))
5315                   (when (= building-line-count 0)
5316                     (sit-for 0)
5317                     (setq building-line-count
5318                           gnus-summary-display-while-building)))
5319               ;; always
5320               (sit-for 0)))
5321         (unless threads
5322           (setq gnus-tmp-level 0)))))
5323   (gnus-message 7 "Generating summary...done"))
5324
5325 (defun gnus-summary-prepare-unthreaded (headers)
5326   "Generate an unthreaded summary buffer based on HEADERS."
5327   (let (header number mark)
5328
5329     (beginning-of-line)
5330
5331     (while headers
5332       ;; We may have to root out some bad articles...
5333       (when (memq (setq number (mail-header-number
5334                                 (setq header (pop headers))))
5335                   gnus-newsgroup-limit)
5336         ;; Mark article as read when it has a low score.
5337         (when (and gnus-summary-mark-below
5338                    (< (or (cdr (assq number gnus-newsgroup-scored))
5339                           gnus-summary-default-score 0)
5340                       gnus-summary-mark-below)
5341                    (not (gnus-summary-article-ancient-p number)))
5342           (setq gnus-newsgroup-unreads
5343                 (delq number gnus-newsgroup-unreads))
5344           (if gnus-newsgroup-auto-expire
5345               (push number gnus-newsgroup-expirable)
5346             (push (cons number gnus-low-score-mark)
5347                   gnus-newsgroup-reads)))
5348
5349         (setq mark (gnus-article-mark number))
5350         (push (gnus-data-make number mark (1+ (point)) header 0)
5351               gnus-newsgroup-data)
5352         (gnus-summary-insert-line
5353          header 0 number
5354          (memq number gnus-newsgroup-undownloaded)
5355          mark (memq number gnus-newsgroup-replied)
5356          (memq number gnus-newsgroup-expirable)
5357          (mail-header-subject header) nil
5358          (cdr (assq number gnus-newsgroup-scored))
5359          (memq number gnus-newsgroup-processable))))))
5360
5361 (defun gnus-summary-remove-list-identifiers ()
5362   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5363   (let ((regexp (if (consp gnus-list-identifiers)
5364                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5365                   gnus-list-identifiers))
5366         changed subject)
5367     (when regexp
5368       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5369       (dolist (header gnus-newsgroup-headers)
5370         (setq subject (mail-header-subject header)
5371               changed nil)
5372         (while (string-match regexp subject)
5373           (setq subject
5374                 (concat (substring subject 0 (match-beginning 1))
5375                         (substring subject (match-end 0)))
5376                 changed t))
5377         (when changed
5378           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5379             (setq subject
5380                   (concat (substring subject 0 (match-beginning 1))
5381                           (substring subject (match-end 1)))))
5382           (mail-header-set-subject header subject))))))
5383
5384 (defun gnus-fetch-headers (articles)
5385   "Fetch headers of ARTICLES."
5386   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5387     (gnus-message 5 "Fetching headers for %s..." name)
5388     (prog1
5389         (if (eq 'nov
5390                 (setq gnus-headers-retrieved-by
5391                       (gnus-retrieve-headers
5392                        articles gnus-newsgroup-name
5393                        ;; We might want to fetch old headers, but
5394                        ;; not if there is only 1 article.
5395                        (and (or (and
5396                                  (not (eq gnus-fetch-old-headers 'some))
5397                                  (not (numberp gnus-fetch-old-headers)))
5398                                 (> (length articles) 1))
5399                             gnus-fetch-old-headers))))
5400             (gnus-get-newsgroup-headers-xover
5401              articles nil nil gnus-newsgroup-name t)
5402           (gnus-get-newsgroup-headers))
5403       (gnus-message 5 "Fetching headers for %s...done" name))))
5404
5405 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5406   "Select newsgroup GROUP.
5407 If READ-ALL is non-nil, all articles in the group are selected.
5408 If SELECT-ARTICLES, only select those articles from GROUP."
5409   (let* ((entry (gnus-group-entry group))
5410          ;;!!! Dirty hack; should be removed.
5411          (gnus-summary-ignore-duplicates
5412           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5413               t
5414             gnus-summary-ignore-duplicates))
5415          (info (nth 2 entry))
5416          charset articles fetched-articles cached)
5417
5418     (unless (gnus-check-server
5419              (set (make-local-variable 'gnus-current-select-method)
5420                   (gnus-find-method-for-group group)))
5421       (error "Couldn't open server"))
5422     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5423
5424     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5425         (gnus-activate-group group)     ; Or we can activate it...
5426         (progn                          ; Or we bug out.
5427           (when (equal major-mode 'gnus-summary-mode)
5428             (gnus-kill-buffer (current-buffer)))
5429           (error
5430            "Couldn't activate group %s: %s"
5431            (mm-decode-coding-string group charset)
5432            (mm-decode-coding-string (gnus-status-message group) charset))))
5433
5434     (unless (gnus-request-group group t)
5435         (when (equal major-mode 'gnus-summary-mode)
5436           (gnus-kill-buffer (current-buffer)))
5437         (error "Couldn't request group %s: %s"
5438                (mm-decode-coding-string group charset)
5439                (mm-decode-coding-string (gnus-status-message group) charset)))
5440
5441     (when gnus-agent
5442       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5443
5444       (setq gnus-summary-use-undownloaded-faces
5445             (gnus-agent-find-parameter
5446              group
5447              'agent-enable-undownloaded-faces)))
5448
5449     (setq gnus-newsgroup-name group
5450           gnus-newsgroup-unselected nil
5451           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5452
5453     (let ((display (gnus-group-find-parameter group 'display)))
5454       (setq gnus-newsgroup-display
5455             (cond
5456              ((not (zerop (or (car-safe read-all) 0)))
5457               ;; The user entered the group with C-u SPC/RET, let's show
5458               ;; all articles.
5459               'gnus-not-ignore)
5460              ((eq display 'all)
5461               'gnus-not-ignore)
5462              ((arrayp display)
5463               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5464              ((numberp display)
5465               ;; The following is probably the "correct" solution, but
5466               ;; it makes Gnus fetch all headers and then limit the
5467               ;; articles (which is slow), so instead we hack the
5468               ;; select-articles parameter instead. -- Simon Josefsson
5469               ;; <jas@kth.se>
5470               ;;
5471               ;; (gnus-byte-compile
5472               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5473               ;;                         display)))))
5474               (setq select-articles
5475                     (gnus-uncompress-range
5476                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5477                              (if (> tmp 0)
5478                                  tmp
5479                                1))
5480                            (cdr (gnus-active group)))))
5481               nil)
5482              (t
5483               nil))))
5484
5485     (gnus-summary-setup-default-charset)
5486
5487     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5488     (when (gnus-virtual-group-p group)
5489       (setq cached gnus-newsgroup-cached))
5490
5491     (setq gnus-newsgroup-unreads
5492           (gnus-sorted-ndifference
5493            (gnus-sorted-ndifference gnus-newsgroup-unreads
5494                                     gnus-newsgroup-marked)
5495            gnus-newsgroup-dormant))
5496
5497     (setq gnus-newsgroup-processable nil)
5498
5499     (gnus-update-read-articles group gnus-newsgroup-unreads)
5500
5501     ;; Adjust and set lists of article marks.
5502     (when info
5503       (gnus-adjust-marked-articles info))
5504     (if (setq articles select-articles)
5505         (setq gnus-newsgroup-unselected
5506               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5507       (setq articles (gnus-articles-to-read group read-all)))
5508
5509     (cond
5510      ((null articles)
5511       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5512       'quit)
5513      ((eq articles 0) nil)
5514      (t
5515       ;; Init the dependencies hash table.
5516       (setq gnus-newsgroup-dependencies
5517             (gnus-make-hashtable (length articles)))
5518       (gnus-set-global-variables)
5519       ;; Retrieve the headers and read them in.
5520
5521       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5522
5523       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5524       (when cached
5525         (setq gnus-newsgroup-cached cached))
5526
5527       ;; Suppress duplicates?
5528       (when gnus-suppress-duplicates
5529         (gnus-dup-suppress-articles))
5530
5531       ;; Set the initial limit.
5532       (setq gnus-newsgroup-limit (copy-sequence articles))
5533       ;; Remove canceled articles from the list of unread articles.
5534       (setq fetched-articles
5535             (mapcar (lambda (headers) (mail-header-number headers))
5536                     gnus-newsgroup-headers))
5537       (setq gnus-newsgroup-articles fetched-articles)
5538       (setq gnus-newsgroup-unreads
5539             (gnus-sorted-nintersection
5540              gnus-newsgroup-unreads fetched-articles))
5541       (gnus-compute-unseen-list)
5542
5543       ;; Removed marked articles that do not exist.
5544       (gnus-update-missing-marks
5545        (gnus-sorted-difference articles fetched-articles))
5546       ;; We might want to build some more threads first.
5547       (when (and gnus-fetch-old-headers
5548                  (eq gnus-headers-retrieved-by 'nov))
5549         (if (eq gnus-fetch-old-headers 'invisible)
5550             (gnus-build-all-threads)
5551           (gnus-build-old-threads)))
5552       ;; Let the Gnus agent mark articles as read.
5553       (when gnus-agent
5554         (gnus-agent-get-undownloaded-list))
5555       ;; Remove list identifiers from subject
5556       (when gnus-list-identifiers
5557         (gnus-summary-remove-list-identifiers))
5558       ;; Check whether auto-expire is to be done in this group.
5559       (setq gnus-newsgroup-auto-expire
5560             (gnus-group-auto-expirable-p group))
5561       ;; Set up the article buffer now, if necessary.
5562       (unless (and gnus-single-article-buffer
5563                    (equal gnus-article-buffer "*Article*"))
5564         (gnus-article-setup-buffer))
5565       ;; First and last article in this newsgroup.
5566       (when gnus-newsgroup-headers
5567         (setq gnus-newsgroup-begin
5568               (mail-header-number (car gnus-newsgroup-headers))
5569               gnus-newsgroup-end
5570               (mail-header-number
5571                (gnus-last-element gnus-newsgroup-headers))))
5572       ;; GROUP is successfully selected.
5573       (or gnus-newsgroup-headers t)))))
5574
5575 (defun gnus-compute-unseen-list ()
5576   ;; The `seen' marks are treated specially.
5577   (if (not gnus-newsgroup-seen)
5578       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5579     (setq gnus-newsgroup-unseen
5580           (gnus-inverse-list-range-intersection
5581            gnus-newsgroup-articles gnus-newsgroup-seen))))
5582
5583 (defun gnus-summary-display-make-predicate (display)
5584   (require 'gnus-agent)
5585   (when (= (length display) 1)
5586     (setq display (car display)))
5587   (unless gnus-summary-display-cache
5588     (dolist (elem (append '((unread . unread)
5589                             (read . read)
5590                             (unseen . unseen))
5591                           gnus-article-mark-lists))
5592       (push (cons (cdr elem)
5593                   (gnus-byte-compile
5594                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5595             gnus-summary-display-cache)))
5596   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5597         (gnus-category-predicate-cache gnus-summary-display-cache))
5598     (gnus-get-predicate display)))
5599
5600 ;; Uses the dynamically bound `number' variable.
5601 (eval-when-compile
5602   (defvar number))
5603 (defun gnus-article-marked-p (type &optional article)
5604   (let ((article (or article number)))
5605     (cond
5606      ((eq type 'tick)
5607       (memq article gnus-newsgroup-marked))
5608      ((eq type 'spam)
5609       (memq article gnus-newsgroup-spam-marked))
5610      ((eq type 'unsend)
5611       (memq article gnus-newsgroup-unsendable))
5612      ((eq type 'undownload)
5613       (memq article gnus-newsgroup-undownloaded))
5614      ((eq type 'download)
5615       (memq article gnus-newsgroup-downloadable))
5616      ((eq type 'unread)
5617       (memq article gnus-newsgroup-unreads))
5618      ((eq type 'read)
5619       (memq article gnus-newsgroup-reads))
5620      ((eq type 'dormant)
5621       (memq article gnus-newsgroup-dormant) )
5622      ((eq type 'expire)
5623       (memq article gnus-newsgroup-expirable))
5624      ((eq type 'reply)
5625       (memq article gnus-newsgroup-replied))
5626      ((eq type 'killed)
5627       (memq article gnus-newsgroup-killed))
5628      ((eq type 'bookmark)
5629       (assq article gnus-newsgroup-bookmarks))
5630      ((eq type 'score)
5631       (assq article gnus-newsgroup-scored))
5632      ((eq type 'save)
5633       (memq article gnus-newsgroup-saved))
5634      ((eq type 'cache)
5635       (memq article gnus-newsgroup-cached))
5636      ((eq type 'forward)
5637       (memq article gnus-newsgroup-forwarded))
5638      ((eq type 'seen)
5639       (not (memq article gnus-newsgroup-unseen)))
5640      ((eq type 'recent)
5641       (memq article gnus-newsgroup-recent))
5642      (t t))))
5643
5644 (defun gnus-articles-to-read (group &optional read-all)
5645   "Find out what articles the user wants to read."
5646   (let* ((articles
5647           ;; Select all articles if `read-all' is non-nil, or if there
5648           ;; are no unread articles.
5649           (if (or read-all
5650                   (and (zerop (length gnus-newsgroup-marked))
5651                        (zerop (length gnus-newsgroup-unreads)))
5652                   ;; Fetch all if the predicate is non-nil.
5653                   gnus-newsgroup-display)
5654               ;; We want to select the headers for all the articles in
5655               ;; the group, so we select either all the active
5656               ;; articles in the group, or (if that's nil), the
5657               ;; articles in the cache.
5658               (or
5659                (if gnus-newsgroup-maximum-articles
5660                    (let ((active (gnus-active group)))
5661                      (gnus-uncompress-range
5662                       (cons (max (car active)
5663                                  (- (cdr active)
5664                                     gnus-newsgroup-maximum-articles
5665                                     -1))
5666                             (cdr active))))
5667                  (gnus-uncompress-range (gnus-active group)))
5668                (gnus-cache-articles-in-group group))
5669             ;; Select only the "normal" subset of articles.
5670             (gnus-sorted-nunion
5671              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5672              gnus-newsgroup-unreads)))
5673          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5674          (scored (length scored-list))
5675          (number (length articles))
5676          (marked (+ (length gnus-newsgroup-marked)
5677                     (length gnus-newsgroup-dormant)))
5678          (select
5679           (cond
5680            ((numberp read-all)
5681             read-all)
5682            ((numberp gnus-newsgroup-display)
5683             gnus-newsgroup-display)
5684            (t
5685             (condition-case ()
5686                 (cond
5687                  ((and (or (<= scored marked) (= scored number))
5688                        (numberp gnus-large-newsgroup)
5689                        (> number gnus-large-newsgroup))
5690                   (let* ((cursor-in-echo-area nil)
5691                          (initial (gnus-parameter-large-newsgroup-initial
5692                                    gnus-newsgroup-name))
5693                          (input
5694                           (read-string
5695                            (format
5696                             "How many articles from %s (%s %d): "
5697                             (gnus-group-decoded-name gnus-newsgroup-name)
5698                             (if initial "max" "default")
5699                             number)
5700                            (if initial
5701                                (cons (number-to-string initial)
5702                                      0)))))
5703                     (if (string-match "^[ \t]*$" input) number input)))
5704                  ((and (> scored marked) (< scored number)
5705                        (> (- scored number) 20))
5706                   (let ((input
5707                          (read-string
5708                           (format "%s %s (%d scored, %d total): "
5709                                   "How many articles from"
5710                                   (gnus-group-decoded-name group)
5711                                   scored number))))
5712                     (if (string-match "^[ \t]*$" input)
5713                         number input)))
5714                  (t number))
5715               (quit
5716                (message "Quit getting the articles to read")
5717                nil))))))
5718     (setq select (if (stringp select) (string-to-number select) select))
5719     (if (or (null select) (zerop select))
5720         select
5721       (if (and (not (zerop scored)) (<= (abs select) scored))
5722           (progn
5723             (setq articles (sort scored-list '<))
5724             (setq number (length articles)))
5725         (setq articles (copy-sequence articles)))
5726
5727       (when (< (abs select) number)
5728         (if (< select 0)
5729             ;; Select the N oldest articles.
5730             (setcdr (nthcdr (1- (abs select)) articles) nil)
5731           ;; Select the N most recent articles.
5732           (setq articles (nthcdr (- number select) articles))))
5733       (setq gnus-newsgroup-unselected
5734             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5735       (when gnus-alter-articles-to-read-function
5736         (setq articles
5737               (sort
5738                (funcall gnus-alter-articles-to-read-function
5739                         gnus-newsgroup-name articles)
5740                '<)))
5741       articles)))
5742
5743 (defun gnus-killed-articles (killed articles)
5744   (let (out)
5745     (while articles
5746       (when (inline (gnus-member-of-range (car articles) killed))
5747         (push (car articles) out))
5748       (setq articles (cdr articles)))
5749     out))
5750
5751 (defun gnus-uncompress-marks (marks)
5752   "Uncompress the mark ranges in MARKS."
5753   (let ((uncompressed '(score bookmark))
5754         out)
5755     (while marks
5756       (if (memq (caar marks) uncompressed)
5757           (push (car marks) out)
5758         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5759       (setq marks (cdr marks)))
5760     out))
5761
5762 (defun gnus-article-mark-to-type (mark)
5763   "Return the type of MARK."
5764   (or (cadr (assq mark gnus-article-special-mark-lists))
5765       'list))
5766
5767 (defun gnus-article-unpropagatable-p (mark)
5768   "Return whether MARK should be propagated to back end."
5769   (memq mark gnus-article-unpropagated-mark-lists))
5770
5771 (defun gnus-adjust-marked-articles (info)
5772   "Set all article lists and remove all marks that are no longer valid."
5773   (let* ((marked-lists (gnus-info-marks info))
5774          (active (gnus-active (gnus-info-group info)))
5775          (min (car active))
5776          (max (cdr active))
5777          (types gnus-article-mark-lists)
5778          marks var articles article mark mark-type
5779          bgn end)
5780
5781     (dolist (marks marked-lists)
5782       (setq mark (car marks)
5783             mark-type (gnus-article-mark-to-type mark)
5784             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5785
5786       ;; We set the variable according to the type of the marks list,
5787       ;; and then adjust the marks to a subset of the active articles.
5788       (cond
5789        ;; Adjust "simple" lists - compressed yet unsorted
5790        ((eq mark-type 'list)
5791         ;; Simultaneously uncompress and clip to active range
5792         ;; See gnus-uncompress-range for a description of possible marks
5793         (let (l lh)
5794           (if (not (cadr marks))
5795               (set var nil)
5796             (setq articles (if (numberp (cddr marks))
5797                                (list (cdr marks))
5798                              (cdr marks))
5799                   lh (cons nil nil)
5800                   l lh)
5801
5802             (while (setq article (pop articles))
5803               (cond ((consp article)
5804                      (setq bgn (max (car article) min)
5805                            end (min (cdr article) max))
5806                      (while (<= bgn end)
5807                        (setq l (setcdr l (cons bgn nil))
5808                              bgn (1+ bgn))))
5809                     ((and (<= min article)
5810                           (>= max article))
5811                      (setq l (setcdr l (cons article nil))))))
5812             (set var (cdr lh)))))
5813        ;; Adjust assocs.
5814        ((eq mark-type 'tuple)
5815         (set var (setq articles (cdr marks)))
5816         (when (not (listp (cdr (symbol-value var))))
5817           (set var (list (symbol-value var))))
5818         (when (not (listp (cdr articles)))
5819           (setq articles (list articles)))
5820         (while articles
5821           (when (or (not (consp (setq article (pop articles))))
5822                     (< (car article) min)
5823                     (> (car article) max))
5824             (set var (delq article (symbol-value var))))))
5825        ;; Adjust ranges (sloppily).
5826        ((eq mark-type 'range)
5827         (cond
5828          ((eq mark 'seen)
5829           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5830           ;; It should be (seen (NUM1 . NUM2)).
5831           (when (numberp (cddr marks))
5832             (setcdr marks (list (cdr marks))))
5833           (setq articles (cdr marks))
5834           (while (and articles
5835                       (or (and (consp (car articles))
5836                                (> min (cdar articles)))
5837                           (and (numberp (car articles))
5838                                (> min (car articles)))))
5839             (pop articles))
5840           (set var articles))))))))
5841
5842 (defun gnus-update-missing-marks (missing)
5843   "Go through the list of MISSING articles and remove them from the mark lists."
5844   (when missing
5845     (let (var m)
5846       ;; Go through all types.
5847       (dolist (elem gnus-article-mark-lists)
5848         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5849           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5850           (when (symbol-value var)
5851             ;; This list has articles.  So we delete all missing
5852             ;; articles from it.
5853             (setq m missing)
5854             (while m
5855               (set var (delq (pop m) (symbol-value var))))))))))
5856
5857 (defun gnus-update-marks ()
5858   "Enter the various lists of marked articles into the newsgroup info list."
5859   (let ((types gnus-article-mark-lists)
5860         (info (gnus-get-info gnus-newsgroup-name))
5861         type list newmarked symbol delta-marks)
5862     (when info
5863       ;; Add all marks lists to the list of marks lists.
5864       (while (setq type (pop types))
5865         (setq list (symbol-value
5866                     (setq symbol
5867                           (intern (format "gnus-newsgroup-%s" (car type))))))
5868
5869         (when list
5870           ;; Get rid of the entries of the articles that have the
5871           ;; default score.
5872           (when (and (eq (cdr type) 'score)
5873                      gnus-save-score
5874                      list)
5875             (let* ((arts list)
5876                    (prev (cons nil list))
5877                    (all prev))
5878               (while arts
5879                 (if (or (not (consp (car arts)))
5880                         (= (cdar arts) gnus-summary-default-score))
5881                     (setcdr prev (cdr arts))
5882                   (setq prev arts))
5883                 (setq arts (cdr arts)))
5884               (setq list (cdr all)))))
5885
5886         (when (eq (cdr type) 'seen)
5887           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5888
5889         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5890           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5891
5892         (when (and (gnus-check-backend-function
5893                     'request-set-mark gnus-newsgroup-name)
5894                    (not (gnus-article-unpropagatable-p (cdr type))))
5895           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5896                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5897                  (add (gnus-remove-from-range
5898                        (gnus-copy-sequence list) old)))
5899             (when add
5900               (push (list add 'add (list (cdr type))) delta-marks))
5901             (when del
5902               (push (list del 'del (list (cdr type))) delta-marks))))
5903
5904         (when list
5905           (push (cons (cdr type) list) newmarked)))
5906
5907       (when delta-marks
5908         (unless (gnus-check-group gnus-newsgroup-name)
5909           (error "Can't open server for %s" gnus-newsgroup-name))
5910         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5911
5912       ;; Enter these new marks into the info of the group.
5913       (if (nthcdr 3 info)
5914           (setcar (nthcdr 3 info) newmarked)
5915         ;; Add the marks lists to the end of the info.
5916         (when newmarked
5917           (setcdr (nthcdr 2 info) (list newmarked))))
5918
5919       ;; Cut off the end of the info if there's nothing else there.
5920       (let ((i 5))
5921         (while (and (> i 2)
5922                     (not (nth i info)))
5923           (when (nthcdr (decf i) info)
5924             (setcdr (nthcdr i info) nil)))))))
5925
5926 (defun gnus-set-mode-line (where)
5927   "Set the mode line of the article or summary buffers.
5928 If WHERE is `summary', the summary mode line format will be used."
5929   ;; Is this mode line one we keep updated?
5930   (when (and (memq where gnus-updated-mode-lines)
5931              (symbol-value
5932               (intern (format "gnus-%s-mode-line-format-spec" where))))
5933     (let (mode-string)
5934       (save-excursion
5935         ;; We evaluate this in the summary buffer since these
5936         ;; variables are buffer-local to that buffer.
5937         (set-buffer gnus-summary-buffer)
5938        ;; We bind all these variables that are used in the `eval' form
5939         ;; below.
5940         (let* ((mformat (symbol-value
5941                          (intern
5942                           (format "gnus-%s-mode-line-format-spec" where))))
5943                (gnus-tmp-group-name (gnus-mode-string-quote
5944                                      (gnus-group-decoded-name
5945                                       gnus-newsgroup-name)))
5946                (gnus-tmp-article-number (or gnus-current-article 0))
5947                (gnus-tmp-unread gnus-newsgroup-unreads)
5948                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5949                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5950                (gnus-tmp-unread-and-unselected
5951                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5952                             (zerop gnus-tmp-unselected))
5953                        "")
5954                       ((zerop gnus-tmp-unselected)
5955                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5956                       (t (format "{%d(+%d) more}"
5957                                  gnus-tmp-unread-and-unticked
5958                                  gnus-tmp-unselected))))
5959                (gnus-tmp-subject
5960                 (if (and gnus-current-headers
5961                          (vectorp gnus-current-headers))
5962                     (gnus-mode-string-quote
5963                      (mail-header-subject gnus-current-headers))
5964                   ""))
5965                bufname-length max-len
5966                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5967           (setq mode-string (eval mformat))
5968           (setq bufname-length (if (string-match "%b" mode-string)
5969                                    (- (length
5970                                        (buffer-name
5971                                         (if (eq where 'summary)
5972                                             nil
5973                                           (get-buffer gnus-article-buffer))))
5974                                       2)
5975                                  0))
5976           (setq max-len (max 4 (if gnus-mode-non-string-length
5977                                    (- (window-width)
5978                                       gnus-mode-non-string-length
5979                                       bufname-length)
5980                                  (length mode-string))))
5981           ;; We might have to chop a bit of the string off...
5982           (when (> (length mode-string) max-len)
5983             (setq mode-string
5984                   (concat (truncate-string-to-width mode-string (- max-len 3))
5985                           "...")))
5986           ;; Pad the mode string a bit.
5987           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5988       ;; Update the mode line.
5989       (setq mode-line-buffer-identification
5990             (gnus-mode-line-buffer-identification (list mode-string)))
5991       (set-buffer-modified-p t))))
5992
5993 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5994   "Go through the HEADERS list and add all Xrefs to a hash table.
5995 The resulting hash table is returned, or nil if no Xrefs were found."
5996   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5997          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5998          (xref-hashtb (gnus-make-hashtable))
5999          start group entry number xrefs header)
6000     (while headers
6001       (setq header (pop headers))
6002       (when (and (setq xrefs (mail-header-xref header))
6003                  (not (memq (setq number (mail-header-number header))
6004                             unreads)))
6005         (setq start 0)
6006         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6007           (setq start (match-end 0))
6008           (setq group (if prefix
6009                           (concat prefix (substring xrefs (match-beginning 1)
6010                                                     (match-end 1)))
6011                         (substring xrefs (match-beginning 1) (match-end 1))))
6012           (setq number
6013                 (string-to-number (substring xrefs (match-beginning 2)
6014                                           (match-end 2))))
6015           (if (setq entry (gnus-gethash group xref-hashtb))
6016               (setcdr entry (cons number (cdr entry)))
6017             (gnus-sethash group (cons number nil) xref-hashtb)))))
6018     (and start xref-hashtb)))
6019
6020 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6021   "Look through all the headers and mark the Xrefs as read."
6022   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6023         name info xref-hashtb idlist method nth4)
6024     (save-excursion
6025       (set-buffer gnus-group-buffer)
6026       (when (setq xref-hashtb
6027                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6028         (mapatoms
6029          (lambda (group)
6030            (unless (string= from-newsgroup (setq name (symbol-name group)))
6031              (setq idlist (symbol-value group))
6032              ;; Dead groups are not updated.
6033              (and (prog1
6034                       (setq info (gnus-get-info name))
6035                     (when (stringp (setq nth4 (gnus-info-method info)))
6036                       (setq nth4 (gnus-server-to-method nth4))))
6037                   ;; Only do the xrefs if the group has the same
6038                   ;; select method as the group we have just read.
6039                   (or (gnus-methods-equal-p
6040                        nth4 (gnus-find-method-for-group from-newsgroup))
6041                       virtual
6042                       (equal nth4 (setq method (gnus-find-method-for-group
6043                                                 from-newsgroup)))
6044                       (and (equal (car nth4) (car method))
6045                            (equal (nth 1 nth4) (nth 1 method))))
6046                   gnus-use-cross-reference
6047                   (or (not (eq gnus-use-cross-reference t))
6048                       virtual
6049                       ;; Only do cross-references on subscribed
6050                       ;; groups, if that is what is wanted.
6051                       (<= (gnus-info-level info) gnus-level-subscribed))
6052                   (gnus-group-make-articles-read name idlist))))
6053          xref-hashtb)))))
6054
6055 (defun gnus-compute-read-articles (group articles)
6056   (let* ((entry (gnus-group-entry group))
6057          (info (nth 2 entry))
6058          (active (gnus-active group))
6059          ninfo)
6060     (when entry
6061       ;; First peel off all invalid article numbers.
6062       (when active
6063         (let ((ids articles)
6064               id first)
6065           (while (setq id (pop ids))
6066             (when (and first (> id (cdr active)))
6067               ;; We'll end up in this situation in one particular
6068               ;; obscure situation.  If you re-scan a group and get
6069               ;; a new article that is cross-posted to a different
6070               ;; group that has not been re-scanned, you might get
6071               ;; crossposted article that has a higher number than
6072               ;; Gnus believes possible.  So we re-activate this
6073               ;; group as well.  This might mean doing the
6074               ;; crossposting thingy will *increase* the number
6075               ;; of articles in some groups.  Tsk, tsk.
6076               (setq active (or (gnus-activate-group group) active)))
6077             (when (or (> id (cdr active))
6078                       (< id (car active)))
6079               (setq articles (delq id articles))))))
6080       ;; If the read list is nil, we init it.
6081       (if (and active
6082                (null (gnus-info-read info))
6083                (> (car active) 1))
6084           (setq ninfo (cons 1 (1- (car active))))
6085         (setq ninfo (gnus-info-read info)))
6086       ;; Then we add the read articles to the range.
6087       (gnus-add-to-range
6088        ninfo (setq articles (sort articles '<))))))
6089
6090 (defun gnus-group-make-articles-read (group articles)
6091   "Update the info of GROUP to say that ARTICLES are read."
6092   (let* ((num 0)
6093          (entry (gnus-group-entry group))
6094          (info (nth 2 entry))
6095          (active (gnus-active group))
6096          range)
6097     (when entry
6098       (setq range (gnus-compute-read-articles group articles))
6099       (with-current-buffer gnus-group-buffer
6100         (gnus-undo-register
6101           `(progn
6102              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6103              (gnus-info-set-read ',info ',(gnus-info-read info))
6104              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6105              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6106              (gnus-group-update-group ,group t))))
6107       ;; Add the read articles to the range.
6108       (gnus-info-set-read info range)
6109       (gnus-request-set-mark group (list (list range 'add '(read))))
6110       ;; Then we have to re-compute how many unread
6111       ;; articles there are in this group.
6112       (when active
6113         (cond
6114          ((not range)
6115           (setq num (- (1+ (cdr active)) (car active))))
6116          ((not (listp (cdr range)))
6117           (setq num (- (cdr active) (- (1+ (cdr range))
6118                                        (car range)))))
6119          (t
6120           (while range
6121             (if (numberp (car range))
6122                 (setq num (1+ num))
6123               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6124             (setq range (cdr range)))
6125           (setq num (- (cdr active) num))))
6126         ;; Update the number of unread articles.
6127         (setcar entry num)
6128         ;; Update the group buffer.
6129         (unless (gnus-ephemeral-group-p group)
6130           (gnus-group-update-group group t))))))
6131
6132 (defvar gnus-newsgroup-none-id 0)
6133
6134 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6135   (let ((cur nntp-server-buffer)
6136         (dependencies
6137          (or dependencies
6138              (with-current-buffer gnus-summary-buffer
6139                gnus-newsgroup-dependencies)))
6140         headers id end ref number
6141         (mail-parse-charset gnus-newsgroup-charset)
6142         (mail-parse-ignored-charsets
6143          (save-excursion (condition-case nil
6144                              (set-buffer gnus-summary-buffer)
6145                            (error))
6146                          gnus-newsgroup-ignored-charsets)))
6147     (save-excursion
6148       (set-buffer nntp-server-buffer)
6149       ;; Translate all TAB characters into SPACE characters.
6150       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6151       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6152       (ietf-drums-unfold-fws)
6153       (gnus-run-hooks 'gnus-parse-headers-hook)
6154       (let ((case-fold-search t)
6155             in-reply-to header p lines chars)
6156         (goto-char (point-min))
6157         ;; Search to the beginning of the next header.  Error messages
6158         ;; do not begin with 2 or 3.
6159         (while (re-search-forward "^[23][0-9]+ " nil t)
6160           (setq id nil
6161                 ref nil)
6162           ;; This implementation of this function, with nine
6163           ;; search-forwards instead of the one re-search-forward and
6164           ;; a case (which basically was the old function) is actually
6165           ;; about twice as fast, even though it looks messier.  You
6166           ;; can't have everything, I guess.  Speed and elegance
6167           ;; doesn't always go hand in hand.
6168           (setq
6169            header
6170            (vector
6171             ;; Number.
6172             (prog1
6173                 (setq number (read cur))
6174               (end-of-line)
6175               (setq p (point))
6176               (narrow-to-region (point)
6177                                 (or (and (search-forward "\n.\n" nil t)
6178                                          (- (point) 2))
6179                                     (point))))
6180             ;; Subject.
6181             (progn
6182               (goto-char p)
6183               (if (search-forward "\nsubject:" nil t)
6184                   (funcall gnus-decode-encoded-word-function
6185                            (nnheader-header-value))
6186                 "(none)"))
6187             ;; From.
6188             (progn
6189               (goto-char p)
6190               (if (search-forward "\nfrom:" nil t)
6191                   (funcall gnus-decode-encoded-address-function
6192                            (nnheader-header-value))
6193                 "(nobody)"))
6194             ;; Date.
6195             (progn
6196               (goto-char p)
6197               (if (search-forward "\ndate:" nil t)
6198                   (nnheader-header-value) ""))
6199             ;; Message-ID.
6200             (progn
6201               (goto-char p)
6202               (setq id (if (re-search-forward
6203                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6204                            ;; We do it this way to make sure the Message-ID
6205                            ;; is (somewhat) syntactically valid.
6206                            (buffer-substring (match-beginning 1)
6207                                              (match-end 1))
6208                          ;; If there was no message-id, we just fake one
6209                          ;; to make subsequent routines simpler.
6210                          (nnheader-generate-fake-message-id number))))
6211             ;; References.
6212             (progn
6213               (goto-char p)
6214               (if (search-forward "\nreferences:" nil t)
6215                   (progn
6216                     (setq end (point))
6217                     (prog1
6218                         (nnheader-header-value)
6219                       (setq ref
6220                             (buffer-substring
6221                              (progn
6222                                (end-of-line)
6223                                (search-backward ">" end t)
6224                                (1+ (point)))
6225                              (progn
6226                                (search-backward "<" end t)
6227                                (point))))))
6228                 ;; Get the references from the in-reply-to header if there
6229                 ;; were no references and the in-reply-to header looks
6230                 ;; promising.
6231                 (if (and (search-forward "\nin-reply-to:" nil t)
6232                          (setq in-reply-to (nnheader-header-value))
6233                          (string-match "<[^>]+>" in-reply-to))
6234                     (let (ref2)
6235                       (setq ref (substring in-reply-to (match-beginning 0)
6236                                            (match-end 0)))
6237                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6238                         (setq ref2 (substring in-reply-to (match-beginning 0)
6239                                               (match-end 0)))
6240                         (when (> (length ref2) (length ref))
6241                           (setq ref ref2)))
6242                       ref)
6243                   (setq ref nil))))
6244             ;; Chars.
6245             (progn
6246               (goto-char p)
6247               (if (search-forward "\nchars: " nil t)
6248                   (if (numberp (setq chars (ignore-errors (read cur))))
6249                       chars -1)
6250                 -1))
6251             ;; Lines.
6252             (progn
6253               (goto-char p)
6254               (if (search-forward "\nlines: " nil t)
6255                   (if (numberp (setq lines (ignore-errors (read cur))))
6256                       lines -1)
6257                 -1))
6258             ;; Xref.
6259             (progn
6260               (goto-char p)
6261               (and (search-forward "\nxref:" nil t)
6262                    (nnheader-header-value)))
6263             ;; Extra.
6264             (when gnus-extra-headers
6265               (let ((extra gnus-extra-headers)
6266                     out)
6267                 (while extra
6268                   (goto-char p)
6269                   (when (search-forward
6270                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6271                     (push (cons (car extra) (nnheader-header-value))
6272                           out))
6273                   (pop extra))
6274                 out))))
6275           (when (equal id ref)
6276             (setq ref nil))
6277
6278           (when gnus-alter-header-function
6279             (funcall gnus-alter-header-function header)
6280             (setq id (mail-header-id header)
6281                   ref (gnus-parent-id (mail-header-references header))))
6282
6283           (when (setq header
6284                       (gnus-dependencies-add-header
6285                        header dependencies force-new))
6286             (push header headers))
6287           (goto-char (point-max))
6288           (widen))
6289         (nreverse headers)))))
6290
6291 ;; Goes through the xover lines and returns a list of vectors
6292 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6293                                                   force-new dependencies
6294                                                   group also-fetch-heads)
6295   "Parse the news overview data in the server buffer.
6296 Return a list of headers that match SEQUENCE (see
6297 `nntp-retrieve-headers')."
6298   ;; Get the Xref when the users reads the articles since most/some
6299   ;; NNTP servers do not include Xrefs when using XOVER.
6300   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6301   (let ((mail-parse-charset gnus-newsgroup-charset)
6302         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6303         (cur nntp-server-buffer)
6304         (dependencies (or dependencies gnus-newsgroup-dependencies))
6305         (allp (cond
6306                ((eq gnus-read-all-available-headers t)
6307                 t)
6308                ((and (stringp gnus-read-all-available-headers)
6309                      group)
6310                 (string-match gnus-read-all-available-headers group))
6311                (t
6312                 nil)))
6313         number headers header)
6314     (save-excursion
6315       (set-buffer nntp-server-buffer)
6316       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6317       ;; Allow the user to mangle the headers before parsing them.
6318       (gnus-run-hooks 'gnus-parse-headers-hook)
6319       (goto-char (point-min))
6320       (gnus-parse-without-error
6321         (while (and (or sequence allp)
6322                     (not (eobp)))
6323           (setq number (read cur))
6324           (when (not allp)
6325             (while (and sequence
6326                         (< (car sequence) number))
6327               (setq sequence (cdr sequence))))
6328           (when (and (or allp
6329                          (and sequence
6330                               (eq number (car sequence))))
6331                      (progn
6332                        (setq sequence (cdr sequence))
6333                        (setq header (inline
6334                                       (gnus-nov-parse-line
6335                                        number dependencies force-new)))))
6336             (push header headers))
6337           (forward-line 1)))
6338       ;; A common bug in inn is that if you have posted an article and
6339       ;; then retrieves the active file, it will answer correctly --
6340       ;; the new article is included.  However, a NOV entry for the
6341       ;; article may not have been generated yet, so this may fail.
6342       ;; We work around this problem by retrieving the last few
6343       ;; headers using HEAD.
6344       (if (or (not also-fetch-heads)
6345               (not sequence))
6346           ;; We (probably) got all the headers.
6347           (nreverse headers)
6348         (let ((gnus-nov-is-evil t))
6349           (nconc
6350            (nreverse headers)
6351            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6352              (gnus-get-newsgroup-headers))))))))
6353
6354 (defun gnus-article-get-xrefs ()
6355   "Fill in the Xref value in `gnus-current-headers', if necessary.
6356 This is meant to be called in `gnus-article-internal-prepare-hook'."
6357   (let ((headers (with-current-buffer gnus-summary-buffer
6358                    gnus-current-headers)))
6359     (or (not gnus-use-cross-reference)
6360         (not headers)
6361         (and (mail-header-xref headers)
6362              (not (string= (mail-header-xref headers) "")))
6363         (let ((case-fold-search t)
6364               xref)
6365           (save-restriction
6366             (nnheader-narrow-to-headers)
6367             (goto-char (point-min))
6368             (when (or (and (not (eobp))
6369                            (eq (downcase (char-after)) ?x)
6370                            (looking-at "Xref:"))
6371                       (search-forward "\nXref:" nil t))
6372               (goto-char (1+ (match-end 0)))
6373               (setq xref (buffer-substring (point) (point-at-eol)))
6374               (mail-header-set-xref headers xref)))))))
6375
6376 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6377   "Find article ID and insert the summary line for that article.
6378 OLD-HEADER can either be a header or a line number to insert
6379 the subject line on."
6380   (let* ((line (and (numberp old-header) old-header))
6381          (old-header (and (vectorp old-header) old-header))
6382          (header (cond ((and old-header use-old-header)
6383                         old-header)
6384                        ((and (numberp id)
6385                              (gnus-number-to-header id))
6386                         (gnus-number-to-header id))
6387                        (t
6388                         (gnus-read-header id))))
6389          (number (and (numberp id) id))
6390          d)
6391     (when header
6392       ;; Rebuild the thread that this article is part of and go to the
6393       ;; article we have fetched.
6394       (when (and (not gnus-show-threads)
6395                  old-header)
6396         (when (and number
6397                    (setq d (gnus-data-find (mail-header-number old-header))))
6398           (goto-char (gnus-data-pos d))
6399           (gnus-data-remove
6400            number
6401            (- (point-at-bol)
6402               (prog1
6403                   (1+ (point-at-eol))
6404                 (gnus-delete-line))))))
6405       ;; Remove list identifiers from subject.
6406       (when gnus-list-identifiers
6407         (let ((gnus-newsgroup-headers (list header)))
6408           (gnus-summary-remove-list-identifiers)))
6409       (when old-header
6410         (mail-header-set-number header (mail-header-number old-header)))
6411       (setq gnus-newsgroup-sparse
6412             (delq (setq number (mail-header-number header))
6413                   gnus-newsgroup-sparse))
6414       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6415       (push number gnus-newsgroup-limit)
6416       (gnus-rebuild-thread (mail-header-id header) line)
6417       (gnus-summary-goto-subject number nil t))
6418     (when (and (numberp number)
6419                (> number 0))
6420       ;; We have to update the boundaries even if we can't fetch the
6421       ;; article if ID is a number -- so that the next `P' or `N'
6422       ;; command will fetch the previous (or next) article even
6423       ;; if the one we tried to fetch this time has been canceled.
6424       (when (> number gnus-newsgroup-end)
6425         (setq gnus-newsgroup-end number))
6426       (when (< number gnus-newsgroup-begin)
6427         (setq gnus-newsgroup-begin number))
6428       (setq gnus-newsgroup-unselected
6429             (delq number gnus-newsgroup-unselected)))
6430     ;; Report back a success?
6431     (and header (mail-header-number header))))
6432
6433 ;;; Process/prefix in the summary buffer
6434
6435 (defun gnus-summary-work-articles (n)
6436   "Return a list of articles to be worked upon.
6437 The prefix argument, the list of process marked articles, and the
6438 current article will be taken into consideration."
6439   (save-excursion
6440     (set-buffer gnus-summary-buffer)
6441     (cond
6442      (n
6443       ;; A numerical prefix has been given.
6444       (setq n (prefix-numeric-value n))
6445       (let ((backward (< n 0))
6446             (n (abs (prefix-numeric-value n)))
6447             articles article)
6448         (save-excursion
6449           (while
6450               (and (> n 0)
6451                    (push (setq article (gnus-summary-article-number))
6452                          articles)
6453                    (if backward
6454                        (gnus-summary-find-prev nil article)
6455                      (gnus-summary-find-next nil article)))
6456             (decf n)))
6457         (nreverse articles)))
6458      ((and (gnus-region-active-p) (mark))
6459       (message "region active")
6460       ;; Work on the region between point and mark.
6461       (let ((max (max (point) (mark)))
6462             articles article)
6463         (save-excursion
6464           (goto-char (min (point) (mark)))
6465           (while
6466               (and
6467                (push (setq article (gnus-summary-article-number)) articles)
6468                (gnus-summary-find-next nil article)
6469                (< (point) max)))
6470           (nreverse articles))))
6471      (gnus-newsgroup-processable
6472       ;; There are process-marked articles present.
6473       ;; Save current state.
6474       (gnus-summary-save-process-mark)
6475       ;; Return the list.
6476       (reverse gnus-newsgroup-processable))
6477      (t
6478       ;; Just return the current article.
6479       (list (gnus-summary-article-number))))))
6480
6481 (defmacro gnus-summary-iterate (arg &rest forms)
6482   "Iterate over the process/prefixed articles and do FORMS.
6483 ARG is the interactive prefix given to the command.  FORMS will be
6484 executed with point over the summary line of the articles."
6485   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6486     `(let ((,articles (gnus-summary-work-articles ,arg)))
6487        (while ,articles
6488          (gnus-summary-goto-subject (car ,articles))
6489          ,@forms
6490          (pop ,articles)))))
6491
6492 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6493 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6494
6495 (defun gnus-summary-save-process-mark ()
6496   "Push the current set of process marked articles on the stack."
6497   (interactive)
6498   (push (copy-sequence gnus-newsgroup-processable)
6499         gnus-newsgroup-process-stack))
6500
6501 (defun gnus-summary-kill-process-mark ()
6502   "Push the current set of process marked articles on the stack and unmark."
6503   (interactive)
6504   (gnus-summary-save-process-mark)
6505   (gnus-summary-unmark-all-processable))
6506
6507 (defun gnus-summary-yank-process-mark ()
6508   "Pop the last process mark state off the stack and restore it."
6509   (interactive)
6510   (unless gnus-newsgroup-process-stack
6511     (error "Empty mark stack"))
6512   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6513
6514 (defun gnus-summary-process-mark-set (set)
6515   "Make SET into the current process marked articles."
6516   (gnus-summary-unmark-all-processable)
6517   (mapc 'gnus-summary-set-process-mark set))
6518
6519 ;;; Searching and stuff
6520
6521 (defun gnus-summary-search-group (&optional backward use-level)
6522   "Search for next unread newsgroup.
6523 If optional argument BACKWARD is non-nil, search backward instead."
6524   (save-excursion
6525     (set-buffer gnus-group-buffer)
6526     (when (gnus-group-search-forward
6527            backward nil (if use-level (gnus-group-group-level) nil))
6528       (gnus-group-group-name))))
6529
6530 (defun gnus-summary-best-group (&optional exclude-group)
6531   "Find the name of the best unread group.
6532 If EXCLUDE-GROUP, do not go to this group."
6533   (with-current-buffer gnus-group-buffer
6534     (save-excursion
6535       (gnus-group-best-unread-group exclude-group))))
6536
6537 (defun gnus-summary-find-next (&optional unread article backward)
6538   (if backward
6539       (gnus-summary-find-prev unread article)
6540     (let* ((dummy (gnus-summary-article-intangible-p))
6541            (article (or article (gnus-summary-article-number)))
6542            (data (gnus-data-find-list article))
6543            result)
6544       (when (and (not dummy)
6545                  (or (not gnus-summary-check-current)
6546                      (not unread)
6547                      (not (gnus-data-unread-p (car data)))))
6548         (setq data (cdr data)))
6549       (when (setq result
6550                   (if unread
6551                       (progn
6552                         (while data
6553                           (unless (memq (gnus-data-number (car data))
6554                                         (cond
6555                                          ((eq gnus-auto-goto-ignores
6556                                               'always-undownloaded)
6557                                           gnus-newsgroup-undownloaded)
6558                                          (gnus-plugged
6559                                           nil)
6560                                          ((eq gnus-auto-goto-ignores
6561                                               'unfetched)
6562                                           gnus-newsgroup-unfetched)
6563                                          ((eq gnus-auto-goto-ignores
6564                                               'undownloaded)
6565                                           gnus-newsgroup-undownloaded)))
6566                             (when (gnus-data-unread-p (car data))
6567                               (setq result (car data)
6568                                     data nil)))
6569                           (setq data (cdr data)))
6570                         result)
6571                     (car data)))
6572         (goto-char (gnus-data-pos result))
6573         (gnus-data-number result)))))
6574
6575 (defun gnus-summary-find-prev (&optional unread article)
6576   (let* ((eobp (eobp))
6577          (article (or article (gnus-summary-article-number)))
6578          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6579          result)
6580     (when (and (not eobp)
6581                (or (not gnus-summary-check-current)
6582                    (not unread)
6583                    (not (gnus-data-unread-p (car data)))))
6584       (setq data (cdr data)))
6585     (when (setq result
6586                 (if unread
6587                     (progn
6588                       (while data
6589                         (unless (memq (gnus-data-number (car data))
6590                                       (cond
6591                                        ((eq gnus-auto-goto-ignores
6592                                             'always-undownloaded)
6593                                         gnus-newsgroup-undownloaded)
6594                                        (gnus-plugged
6595                                         nil)
6596                                        ((eq gnus-auto-goto-ignores
6597                                             'unfetched)
6598                                         gnus-newsgroup-unfetched)
6599                                        ((eq gnus-auto-goto-ignores
6600                                             'undownloaded)
6601                                         gnus-newsgroup-undownloaded)))
6602                           (when (gnus-data-unread-p (car data))
6603                             (setq result (car data)
6604                                   data nil)))
6605                         (setq data (cdr data)))
6606                       result)
6607                   (car data)))
6608       (goto-char (gnus-data-pos result))
6609       (gnus-data-number result))))
6610
6611 (defun gnus-summary-find-subject (subject &optional unread backward article)
6612   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6613          (article (or article (gnus-summary-article-number)))
6614          (articles (gnus-data-list backward))
6615          (arts (gnus-data-find-list article articles))
6616          result)
6617     (when (or (not gnus-summary-check-current)
6618               (not unread)
6619               (not (gnus-data-unread-p (car arts))))
6620       (setq arts (cdr arts)))
6621     (while arts
6622       (and (or (not unread)
6623                (gnus-data-unread-p (car arts)))
6624            (vectorp (gnus-data-header (car arts)))
6625            (gnus-subject-equal
6626             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6627            (setq result (car arts)
6628                  arts nil))
6629       (setq arts (cdr arts)))
6630     (and result
6631          (goto-char (gnus-data-pos result))
6632          (gnus-data-number result))))
6633
6634 (defun gnus-summary-search-forward (&optional unread subject backward)
6635   "Search forward for an article.
6636 If UNREAD, look for unread articles.  If SUBJECT, look for
6637 articles with that subject.  If BACKWARD, search backward instead."
6638   (cond (subject (gnus-summary-find-subject subject unread backward))
6639         (backward (gnus-summary-find-prev unread))
6640         (t (gnus-summary-find-next unread))))
6641
6642 (defun gnus-recenter (&optional n)
6643   "Center point in window and redisplay frame.
6644 Also do horizontal recentering."
6645   (interactive "P")
6646   (when (and gnus-auto-center-summary
6647              (not (eq gnus-auto-center-summary 'vertical)))
6648     (gnus-horizontal-recenter))
6649   (recenter n))
6650
6651 (defun gnus-summary-recenter ()
6652   "Center point in the summary window.
6653 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6654 displayed, no centering will be performed."
6655   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6656   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6657   (interactive)
6658   ;; The user has to want it.
6659   (when gnus-auto-center-summary
6660     (let* ((top (cond ((< (window-height) 4) 0)
6661                       ((< (window-height) 7) 1)
6662                       (t (if (numberp gnus-auto-center-summary)
6663                              gnus-auto-center-summary
6664                            (/ (1- (window-height)) 2)))))
6665            (height (1- (window-height)))
6666            (bottom (save-excursion (goto-char (point-max))
6667                                    (forward-line (- height))
6668                                    (point)))
6669            (window (get-buffer-window (current-buffer))))
6670       (when (get-buffer-window gnus-article-buffer)
6671         ;; Only do recentering when the article buffer is displayed,
6672         ;; Set the window start to either `bottom', which is the biggest
6673         ;; possible valid number, or the second line from the top,
6674         ;; whichever is the least.
6675         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6676           (if (> bottom top-pos)
6677               ;; Keep the second line from the top visible
6678               (set-window-start window top-pos)
6679             ;; Try to keep the bottom line visible; if it's partially
6680             ;; obscured, either scroll one more line to make it fully
6681             ;; visible, or revert to using TOP-POS.
6682             (save-excursion
6683               (goto-char (point-max))
6684               (forward-line -1)
6685               (let ((last-line-start (point)))
6686                 (goto-char bottom)
6687                 (set-window-start window (point) t)
6688                 (when (not (pos-visible-in-window-p last-line-start window))
6689                   (forward-line 1)
6690                   (set-window-start window (min (point) top-pos) t)))))))
6691       ;; Do horizontal recentering while we're at it.
6692       (when (and (get-buffer-window (current-buffer) t)
6693                  (not (eq gnus-auto-center-summary 'vertical)))
6694         (let ((selected (selected-window)))
6695           (select-window (get-buffer-window (current-buffer) t))
6696           (gnus-summary-position-point)
6697           (gnus-horizontal-recenter)
6698           (select-window selected))))))
6699
6700 (defun gnus-summary-jump-to-group (newsgroup)
6701   "Move point to NEWSGROUP in group mode buffer."
6702   ;; Keep update point of group mode buffer if visible.
6703   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6704       (save-window-excursion
6705         ;; Take care of tree window mode.
6706         (when (get-buffer-window gnus-group-buffer)
6707           (pop-to-buffer gnus-group-buffer))
6708         (gnus-group-jump-to-group newsgroup))
6709     (save-excursion
6710       ;; Take care of tree window mode.
6711       (if (get-buffer-window gnus-group-buffer)
6712           (pop-to-buffer gnus-group-buffer)
6713         (set-buffer gnus-group-buffer))
6714       (gnus-group-jump-to-group newsgroup))))
6715
6716 ;; This function returns a list of article numbers based on the
6717 ;; difference between the ranges of read articles in this group and
6718 ;; the range of active articles.
6719 (defun gnus-list-of-unread-articles (group)
6720   (let* ((read (gnus-info-read (gnus-get-info group)))
6721          (active (or (gnus-active group) (gnus-activate-group group)))
6722          (last (or (cdr active)
6723                    (error "Group %s couldn't be activated " group)))
6724          (bottom (if gnus-newsgroup-maximum-articles
6725                      (max (car active)
6726                           (- last gnus-newsgroup-maximum-articles -1))
6727                    (car active)))
6728          first nlast unread)
6729     ;; If none are read, then all are unread.
6730     (if (not read)
6731         (setq first bottom)
6732       ;; If the range of read articles is a single range, then the
6733       ;; first unread article is the article after the last read
6734       ;; article.  Sounds logical, doesn't it?
6735       (if (and (not (listp (cdr read)))
6736                (or (< (car read) bottom)
6737                    (progn (setq read (list read))
6738                           nil)))
6739           (setq first (max bottom (1+ (cdr read))))
6740         ;; `read' is a list of ranges.
6741         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6742                                   (caar read)))
6743                   1)
6744           (setq first bottom))
6745         (while read
6746           (when first
6747             (while (< first nlast)
6748               (setq unread (cons first unread)
6749                     first (1+ first))))
6750           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6751           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6752           (setq read (cdr read)))))
6753     ;; And add the last unread articles.
6754     (while (<= first last)
6755       (setq unread (cons first unread)
6756             first (1+ first)))
6757     ;; Return the list of unread articles.
6758     (delq 0 (nreverse unread))))
6759
6760 (defun gnus-list-of-read-articles (group)
6761   "Return a list of unread, unticked and non-dormant articles."
6762   (let* ((info (gnus-get-info group))
6763          (marked (gnus-info-marks info))
6764          (active (gnus-active group)))
6765     (and info active
6766          (gnus-list-range-difference
6767           (gnus-list-range-difference
6768            (gnus-sorted-complement
6769             (gnus-uncompress-range
6770              (if gnus-newsgroup-maximum-articles
6771                  (cons (max (car active)
6772                             (- (cdr active)
6773                                gnus-newsgroup-maximum-articles
6774                                -1))
6775                        (cdr active))
6776                active))
6777             (gnus-list-of-unread-articles group))
6778            (cdr (assq 'dormant marked)))
6779           (cdr (assq 'tick marked))))))
6780
6781 ;; This function returns a sequence of article numbers based on the
6782 ;; difference between the ranges of read articles in this group and
6783 ;; the range of active articles.
6784 (defun gnus-sequence-of-unread-articles (group)
6785   (let* ((read (gnus-info-read (gnus-get-info group)))
6786          (active (or (gnus-active group) (gnus-activate-group group)))
6787          (last (cdr active))
6788          (bottom (if gnus-newsgroup-maximum-articles
6789                      (max (car active)
6790                           (- last gnus-newsgroup-maximum-articles -1))
6791                    (car active)))
6792          first nlast unread)
6793     ;; If none are read, then all are unread.
6794     (if (not read)
6795         (setq first bottom)
6796       ;; If the range of read articles is a single range, then the
6797       ;; first unread article is the article after the last read
6798       ;; article.  Sounds logical, doesn't it?
6799       (if (and (not (listp (cdr read)))
6800                (or (< (car read) bottom)
6801                    (progn (setq read (list read))
6802                           nil)))
6803           (setq first (max bottom (1+ (cdr read))))
6804         ;; `read' is a list of ranges.
6805         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6806                                   (caar read)))
6807                   1)
6808           (setq first bottom))
6809         (while read
6810           (when first
6811             (push (cons first nlast) unread))
6812           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6813           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6814           (setq read (cdr read)))))
6815     ;; And add the last unread articles.
6816     (cond ((not (and first last))
6817            nil)
6818           ((< first last)
6819            (push (cons first last) unread))
6820           ((= first last)
6821            (push first unread)))
6822     ;; Return the sequence of unread articles.
6823     (delq 0 (nreverse unread))))
6824
6825 ;; Various summary commands
6826
6827 (defun gnus-summary-select-article-buffer ()
6828   "Reconfigure windows to show article buffer."
6829   (interactive)
6830   (if (not (gnus-buffer-live-p gnus-article-buffer))
6831       (error "There is no article buffer for this summary buffer")
6832     (gnus-configure-windows 'article)
6833     (select-window (get-buffer-window gnus-article-buffer))))
6834
6835 (defun gnus-summary-universal-argument (arg)
6836   "Perform any operation on all articles that are process/prefixed."
6837   (interactive "P")
6838   (let ((articles (gnus-summary-work-articles arg))
6839         func article)
6840     (if (eq
6841          (setq
6842           func
6843           (key-binding
6844            (read-key-sequence
6845             (substitute-command-keys
6846              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6847          'undefined)
6848         (gnus-error 1 "Undefined key")
6849       (save-excursion
6850         (while articles
6851           (gnus-summary-goto-subject (setq article (pop articles)))
6852           (let (gnus-newsgroup-processable)
6853             (command-execute func))
6854           (gnus-summary-remove-process-mark article)))))
6855   (gnus-summary-position-point))
6856
6857 (defun gnus-summary-toggle-truncation (&optional arg)
6858   "Toggle truncation of summary lines.
6859 With ARG, turn line truncation on if ARG is positive."
6860   (interactive "P")
6861   (setq truncate-lines
6862         (if (null arg) (not truncate-lines)
6863           (> (prefix-numeric-value arg) 0)))
6864   (redraw-display))
6865
6866 (defun gnus-summary-find-for-reselect ()
6867   "Return the number of an article to stay on across a reselect.
6868 The current article is considered, then following articles, then previous
6869 articles.  An article is sought which is not cancelled and isn't a temporary
6870 insertion from another group.  If there's no such then return a dummy 0."
6871   (let (found)
6872     (dolist (rev '(nil t))
6873       (unless found      ; don't demand the reverse list if we don't need it
6874         (let ((data (gnus-data-find-list
6875                      (gnus-summary-article-number) (gnus-data-list rev))))
6876           (while (and data (not found))
6877             (if (and (< 0 (gnus-data-number (car data)))
6878                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6879                 (setq found (gnus-data-number (car data))))
6880             (setq data (cdr data))))))
6881     (or found 0)))
6882
6883 (defun gnus-summary-reselect-current-group (&optional all rescan)
6884   "Exit and then reselect the current newsgroup.
6885 The prefix argument ALL means to select all articles."
6886   (interactive "P")
6887   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6888     (error "Ephemeral groups can't be reselected"))
6889   (let ((current-subject (gnus-summary-find-for-reselect))
6890         (group gnus-newsgroup-name))
6891     (setq gnus-newsgroup-begin nil)
6892     (gnus-summary-exit nil 'leave-hidden)
6893     ;; We have to adjust the point of group mode buffer because
6894     ;; point was moved to the next unread newsgroup by exiting.
6895     (gnus-summary-jump-to-group group)
6896     (when rescan
6897       (save-excursion
6898         (gnus-group-get-new-news-this-group 1)))
6899     (gnus-group-read-group all t)
6900     (gnus-summary-goto-subject current-subject nil t)))
6901
6902 (defun gnus-summary-rescan-group (&optional all)
6903   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6904   (interactive "P")
6905   (gnus-summary-reselect-current-group all t))
6906
6907 (defun gnus-summary-update-info (&optional non-destructive)
6908   (save-excursion
6909     (let ((group gnus-newsgroup-name))
6910       (when group
6911         (when gnus-newsgroup-kill-headers
6912           (setq gnus-newsgroup-killed
6913                 (gnus-compress-sequence
6914                  (gnus-sorted-union
6915                   (gnus-list-range-intersection
6916                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6917                   gnus-newsgroup-unreads)
6918                  t)))
6919         (unless (listp (cdr gnus-newsgroup-killed))
6920           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6921         (let ((headers gnus-newsgroup-headers))
6922           ;; Set the new ranges of read articles.
6923           (with-current-buffer gnus-group-buffer
6924             (gnus-undo-force-boundary))
6925           (gnus-update-read-articles
6926            group (gnus-sorted-union
6927                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6928           ;; Set the current article marks.
6929           (let ((gnus-newsgroup-scored
6930                  (if (and (not gnus-save-score)
6931                           (not non-destructive))
6932                      nil
6933                    gnus-newsgroup-scored)))
6934             (save-excursion
6935               (gnus-update-marks)))
6936           ;; Do the cross-ref thing.
6937           (when gnus-use-cross-reference
6938             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6939           ;; Do not switch windows but change the buffer to work.
6940           (set-buffer gnus-group-buffer)
6941           (unless (gnus-ephemeral-group-p group)
6942             (gnus-group-update-group group)))))))
6943
6944 (defun gnus-summary-save-newsrc (&optional force)
6945   "Save the current number of read/marked articles in the dribble buffer.
6946 The dribble buffer will then be saved.
6947 If FORCE (the prefix), also save the .newsrc file(s)."
6948   (interactive "P")
6949   (gnus-summary-update-info t)
6950   (if force
6951       (gnus-save-newsrc-file)
6952     (gnus-dribble-save)))
6953
6954 (defun gnus-summary-exit (&optional temporary leave-hidden)
6955   "Exit reading current newsgroup, and then return to group selection mode.
6956 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6957   (interactive)
6958   (gnus-set-global-variables)
6959   (when (gnus-buffer-live-p gnus-article-buffer)
6960     (save-excursion
6961       (set-buffer gnus-article-buffer)
6962       (mm-destroy-parts gnus-article-mime-handles)
6963       ;; Set it to nil for safety reason.
6964       (setq gnus-article-mime-handle-alist nil)
6965       (setq gnus-article-mime-handles nil)))
6966   (gnus-kill-save-kill-buffer)
6967   (gnus-async-halt-prefetch)
6968   (let* ((group gnus-newsgroup-name)
6969          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6970          (gnus-group-is-exiting-p t)
6971          (mode major-mode)
6972          (group-point nil)
6973          (buf (current-buffer)))
6974     (unless quit-config
6975       ;; Do adaptive scoring, and possibly save score files.
6976       (when gnus-newsgroup-adaptive
6977         (gnus-score-adaptive))
6978       (when gnus-use-scoring
6979         (gnus-score-save)))
6980     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6981     ;; If we have several article buffers, we kill them at exit.
6982     (unless gnus-single-article-buffer
6983       (when (gnus-buffer-live-p gnus-article-buffer)
6984         (with-current-buffer gnus-article-buffer
6985           ;; Don't kill sticky article buffers
6986           (unless (eq major-mode 'gnus-sticky-article-mode)
6987             (gnus-kill-buffer gnus-article-buffer)
6988             (setq gnus-article-current nil))))
6989       (gnus-kill-buffer gnus-original-article-buffer))
6990     (when gnus-use-cache
6991       (gnus-cache-possibly-remove-articles)
6992       (gnus-cache-save-buffers))
6993     (gnus-async-prefetch-remove-group group)
6994     (when gnus-suppress-duplicates
6995       (gnus-dup-enter-articles))
6996     (when gnus-use-trees
6997       (gnus-tree-close group))
6998     (when gnus-use-cache
6999       (gnus-cache-write-active))
7000     ;; Remove entries for this group.
7001     (nnmail-purge-split-history (gnus-group-real-name group))
7002     ;; Make all changes in this group permanent.
7003     (unless quit-config
7004       (gnus-run-hooks 'gnus-exit-group-hook)
7005       (gnus-summary-update-info))
7006     (gnus-close-group group)
7007     ;; Make sure where we were, and go to next newsgroup.
7008     (set-buffer gnus-group-buffer)
7009     (unless quit-config
7010       (gnus-group-jump-to-group group))
7011     (gnus-run-hooks 'gnus-summary-exit-hook)
7012     (unless (or quit-config
7013                 (not gnus-summary-next-group-on-exit)
7014                 ;; If this group has disappeared from the summary
7015                 ;; buffer, don't skip forwards.
7016                 (not (string= group (gnus-group-group-name))))
7017       (gnus-group-next-unread-group 1))
7018     (setq group-point (point))
7019     (if temporary
7020         nil                             ;Nothing to do.
7021       (set-buffer buf)
7022       (if (not gnus-kill-summary-on-exit)
7023           (progn
7024             (gnus-deaden-summary)
7025             (setq mode nil))
7026         ;; We set all buffer-local variables to nil.  It is unclear why
7027         ;; this is needed, but if we don't, buffer-local variables are
7028         ;; not garbage-collected, it seems.  This would the lead to en
7029         ;; ever-growing Emacs.
7030         (gnus-summary-clear-local-variables)
7031         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7032           (gnus-summary-clear-local-variables))
7033         (when (get-buffer gnus-article-buffer)
7034           (bury-buffer gnus-article-buffer))
7035         ;; Return to group mode buffer.
7036         (when (eq mode 'gnus-summary-mode)
7037           (gnus-kill-buffer buf)))
7038       (setq gnus-current-select-method gnus-select-method)
7039       (set-buffer gnus-group-buffer)
7040       (if quit-config
7041           (gnus-handle-ephemeral-exit quit-config)
7042         (goto-char group-point)
7043         ;; If gnus-group-buffer is already displayed, make sure we also move
7044         ;; the cursor in the window that displays it.
7045         (let ((win (get-buffer-window (current-buffer) 0)))
7046           (if win (set-window-point win (point))))
7047         (unless leave-hidden
7048           (gnus-configure-windows 'group 'force)))
7049       ;; Clear the current group name.
7050       (unless quit-config
7051         (setq gnus-newsgroup-name nil)))))
7052
7053 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7054 (defun gnus-summary-exit-no-update (&optional no-questions)
7055   "Quit reading current newsgroup without updating read article info."
7056   (interactive)
7057   (let* ((group gnus-newsgroup-name)
7058          (gnus-group-is-exiting-p t)
7059          (gnus-group-is-exiting-without-update-p t)
7060          (quit-config (gnus-group-quit-config group)))
7061     (when (or no-questions
7062               gnus-expert-user
7063               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7064       (gnus-async-halt-prefetch)
7065       (run-hooks 'gnus-summary-prepare-exit-hook)
7066       (when (gnus-buffer-live-p gnus-article-buffer)
7067         (save-excursion
7068           (set-buffer gnus-article-buffer)
7069           (mm-destroy-parts gnus-article-mime-handles)
7070           ;; Set it to nil for safety reason.
7071           (setq gnus-article-mime-handle-alist nil)
7072           (setq gnus-article-mime-handles nil)))
7073       ;; If we have several article buffers, we kill them at exit.
7074       (unless gnus-single-article-buffer
7075         (gnus-kill-buffer gnus-article-buffer)
7076         (gnus-kill-buffer gnus-original-article-buffer)
7077         (setq gnus-article-current nil))
7078       (if (not gnus-kill-summary-on-exit)
7079           (gnus-deaden-summary)
7080         (gnus-close-group group)
7081         (gnus-summary-clear-local-variables)
7082         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7083           (gnus-summary-clear-local-variables))
7084         (gnus-kill-buffer gnus-summary-buffer))
7085       (unless gnus-single-article-buffer
7086         (setq gnus-article-current nil))
7087       (when gnus-use-trees
7088         (gnus-tree-close group))
7089       (gnus-async-prefetch-remove-group group)
7090       (when (get-buffer gnus-article-buffer)
7091         (bury-buffer gnus-article-buffer))
7092       ;; Return to the group buffer.
7093       (gnus-configure-windows 'group 'force)
7094       ;; Clear the current group name.
7095       (setq gnus-newsgroup-name nil)
7096       (unless (gnus-ephemeral-group-p group)
7097         (gnus-group-update-group group))
7098       (when (equal (gnus-group-group-name) group)
7099         (gnus-group-next-unread-group 1))
7100       (when quit-config
7101         (gnus-handle-ephemeral-exit quit-config)))))
7102
7103 (defun gnus-handle-ephemeral-exit (quit-config)
7104   "Handle movement when leaving an ephemeral group.
7105 The state which existed when entering the ephemeral is reset."
7106   (if (not (buffer-name (car quit-config)))
7107       (gnus-configure-windows 'group 'force)
7108     (set-buffer (car quit-config))
7109     (cond ((eq major-mode 'gnus-summary-mode)
7110            (gnus-set-global-variables))
7111           ((eq major-mode 'gnus-article-mode)
7112            (save-excursion
7113              ;; The `gnus-summary-buffer' variable may point
7114              ;; to the old summary buffer when using a single
7115              ;; article buffer.
7116              (unless (gnus-buffer-live-p gnus-summary-buffer)
7117                (set-buffer gnus-group-buffer))
7118              (set-buffer gnus-summary-buffer)
7119              (gnus-set-global-variables))))
7120     (if (or (eq (cdr quit-config) 'article)
7121             (eq (cdr quit-config) 'pick))
7122         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7123             (gnus-configure-windows 'pick 'force)
7124           (gnus-configure-windows (cdr quit-config) 'force))
7125       (gnus-configure-windows (cdr quit-config) 'force))
7126     (when (eq major-mode 'gnus-summary-mode)
7127       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7128                                                      next-unread-noselect))
7129           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7130                                   'next-noselect)
7131                               (gnus-summary-next-subject 1 nil t))
7132                              ((eq gnus-auto-select-on-ephemeral-exit
7133                                   'next-unread-noselect)
7134                               (gnus-summary-next-subject 1 t t))))
7135             ;; Hide the article buffer which displays the article different
7136             ;; from the one that the cursor points to in the summary buffer.
7137             (gnus-configure-windows 'summary 'force))
7138         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7139                (gnus-summary-next-subject 1))
7140               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7141                (gnus-summary-next-subject 1 t))))
7142       (gnus-summary-recenter)
7143       (gnus-summary-position-point))))
7144
7145 ;;; Dead summaries.
7146
7147 (defvar gnus-dead-summary-mode-map nil)
7148
7149 (unless gnus-dead-summary-mode-map
7150   (setq gnus-dead-summary-mode-map (make-keymap))
7151   (suppress-keymap gnus-dead-summary-mode-map)
7152   (substitute-key-definition
7153    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7154   (dolist (key '("\C-d" "\r" "\177" [delete]))
7155     (define-key gnus-dead-summary-mode-map
7156       key 'gnus-summary-wake-up-the-dead))
7157   (dolist (key '("q" "Q"))
7158     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7159
7160 (defvar gnus-dead-summary-mode nil
7161   "Minor mode for Gnus summary buffers.")
7162
7163 (defun gnus-dead-summary-mode (&optional arg)
7164   "Minor mode for Gnus summary buffers."
7165   (interactive "P")
7166   (when (eq major-mode 'gnus-summary-mode)
7167     (make-local-variable 'gnus-dead-summary-mode)
7168     (setq gnus-dead-summary-mode
7169           (if (null arg) (not gnus-dead-summary-mode)
7170             (> (prefix-numeric-value arg) 0)))
7171     (when gnus-dead-summary-mode
7172       (add-minor-mode
7173        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7174
7175 (defun gnus-deaden-summary ()
7176   "Make the current summary buffer into a dead summary buffer."
7177   ;; Kill any previous dead summary buffer.
7178   (when (and gnus-dead-summary
7179              (buffer-name gnus-dead-summary))
7180     (with-current-buffer gnus-dead-summary
7181       (when gnus-dead-summary-mode
7182         (kill-buffer (current-buffer)))))
7183   ;; Make this the current dead summary.
7184   (setq gnus-dead-summary (current-buffer))
7185   (gnus-dead-summary-mode 1)
7186   (let ((name (buffer-name)))
7187     (when (string-match "Summary" name)
7188       (rename-buffer
7189        (concat (substring name 0 (match-beginning 0)) "Dead "
7190                (substring name (match-beginning 0)))
7191        t)
7192       (bury-buffer))))
7193
7194 (defun gnus-kill-or-deaden-summary (buffer)
7195   "Kill or deaden the summary BUFFER."
7196   (save-excursion
7197     (when (and (buffer-name buffer)
7198                (not gnus-single-article-buffer))
7199       (with-current-buffer buffer
7200         (gnus-kill-buffer gnus-article-buffer)
7201         (gnus-kill-buffer gnus-original-article-buffer)))
7202     (cond
7203      ;; Kill the buffer.
7204      (gnus-kill-summary-on-exit
7205       (when (and gnus-use-trees
7206                  (gnus-buffer-exists-p buffer))
7207         (save-excursion
7208           (set-buffer buffer)
7209           (gnus-tree-close gnus-newsgroup-name)))
7210       (gnus-kill-buffer buffer))
7211      ;; Deaden the buffer.
7212      ((gnus-buffer-exists-p buffer)
7213       (save-excursion
7214         (set-buffer buffer)
7215         (gnus-deaden-summary))))))
7216
7217 (defun gnus-summary-wake-up-the-dead (&rest args)
7218   "Wake up the dead summary buffer."
7219   (interactive)
7220   (gnus-dead-summary-mode -1)
7221   (let ((name (buffer-name)))
7222     (when (string-match "Dead " name)
7223       (rename-buffer
7224        (concat (substring name 0 (match-beginning 0))
7225                (substring name (match-end 0)))
7226        t)))
7227   (gnus-message 3 "This dead summary is now alive again"))
7228
7229 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7230 (defun gnus-summary-fetch-faq (&optional faq-dir)
7231   "Fetch the FAQ for the current group.
7232 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7233 in."
7234   (interactive
7235    (list
7236     (when current-prefix-arg
7237       (completing-read
7238        "FAQ dir: " (and (listp gnus-group-faq-directory)
7239                         (mapcar 'list
7240                                 gnus-group-faq-directory))))))
7241   (let (gnus-faq-buffer)
7242     (when (setq gnus-faq-buffer
7243                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7244       (gnus-configure-windows 'summary-faq))))
7245
7246 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7247 (defun gnus-summary-describe-group (&optional force)
7248   "Describe the current newsgroup."
7249   (interactive "P")
7250   (gnus-group-describe-group force gnus-newsgroup-name))
7251
7252 (defun gnus-summary-describe-briefly ()
7253   "Describe summary mode commands briefly."
7254   (interactive)
7255   (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")))
7256
7257 ;; Walking around group mode buffer from summary mode.
7258
7259 (defun gnus-summary-next-group (&optional no-article target-group backward)
7260   "Exit current newsgroup and then select next unread newsgroup.
7261 If prefix argument NO-ARTICLE is non-nil, no article is selected
7262 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7263 previous group instead."
7264   (interactive "P")
7265   ;; Stop pre-fetching.
7266   (gnus-async-halt-prefetch)
7267   (let ((current-group gnus-newsgroup-name)
7268         (current-buffer (current-buffer))
7269         entered)
7270     ;; First we semi-exit this group to update Xrefs and all variables.
7271     ;; We can't do a real exit, because the window conf must remain
7272     ;; the same in case the user is prompted for info, and we don't
7273     ;; want the window conf to change before that...
7274     (gnus-summary-exit t)
7275     (while (not entered)
7276       ;; Then we find what group we are supposed to enter.
7277       (set-buffer gnus-group-buffer)
7278       (gnus-group-jump-to-group current-group)
7279       (setq target-group
7280             (or target-group
7281                 (if (eq gnus-keep-same-level 'best)
7282                     (gnus-summary-best-group gnus-newsgroup-name)
7283                   (gnus-summary-search-group backward gnus-keep-same-level))))
7284       (if (not target-group)
7285           ;; There are no further groups, so we return to the group
7286           ;; buffer.
7287           (progn
7288             (gnus-message 5 "Returning to the group buffer")
7289             (setq entered t)
7290             (when (gnus-buffer-live-p current-buffer)
7291               (set-buffer current-buffer)
7292               (gnus-summary-exit))
7293             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7294         ;; We try to enter the target group.
7295         (gnus-group-jump-to-group target-group)
7296         (let ((unreads (gnus-group-group-unread)))
7297           (if (and (or (eq t unreads)
7298                        (and unreads (not (zerop unreads))))
7299                    (gnus-summary-read-group
7300                     target-group nil no-article
7301                     (and (buffer-name current-buffer) current-buffer)
7302                     nil backward))
7303               (setq entered t)
7304             (setq current-group target-group
7305                   target-group nil)))))))
7306
7307 (defun gnus-summary-prev-group (&optional no-article)
7308   "Exit current newsgroup and then select previous unread newsgroup.
7309 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7310   (interactive "P")
7311   (gnus-summary-next-group no-article nil t))
7312
7313 ;; Walking around summary lines.
7314
7315 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7316   "Go to the first subject satisfying any non-nil constraint.
7317 If UNREAD is non-nil, the article should be unread.
7318 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7319 If UNSEEN is non-nil, the article should be unseen.
7320 Returns the article selected or nil if there are no matching articles."
7321   (interactive "P")
7322   (cond
7323    ;; Empty summary.
7324    ((null gnus-newsgroup-data)
7325     (gnus-message 3 "No articles in the group")
7326     nil)
7327    ;; Pick the first article.
7328    ((not (or unread undownloaded unseen))
7329     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7330     (gnus-data-number (car gnus-newsgroup-data)))
7331    ;; Find the first unread article.
7332    (t
7333     (let ((data gnus-newsgroup-data))
7334       (while (and data
7335                   (let ((num (gnus-data-number (car data))))
7336                     (or (memq num gnus-newsgroup-unfetched)
7337                         (not (or (and unread
7338                                       (memq num gnus-newsgroup-unreads))
7339                                  (and undownloaded
7340                                       (memq num gnus-newsgroup-undownloaded))
7341                                  (and unseen
7342                                       (memq num gnus-newsgroup-unseen)))))))
7343         (setq data (cdr data)))
7344       (prog1
7345           (if data
7346               (progn
7347                 (goto-char (gnus-data-pos (car data)))
7348                 (gnus-data-number (car data)))
7349             (gnus-message 3 "No more%s articles"
7350                           (let* ((r (when unread " unread"))
7351                                  (d (when undownloaded " undownloaded"))
7352                                  (s (when unseen " unseen"))
7353                                  (l (delq nil (list r d s))))
7354                             (cond ((= 3 (length l))
7355                                    (concat r "," d ", or" s))
7356                                   ((= 2 (length l))
7357                                    (concat (car l) ", or" (cadr l)))
7358                                   ((= 1 (length l))
7359                                    (car l))
7360                                   (t
7361                                    ""))))
7362             nil
7363             )
7364         (gnus-summary-position-point))))))
7365
7366 (defun gnus-summary-next-subject (n &optional unread dont-display)
7367   "Go to next N'th summary line.
7368 If N is negative, go to the previous N'th subject line.
7369 If UNREAD is non-nil, only unread articles are selected.
7370 The difference between N and the actual number of steps taken is
7371 returned."
7372   (interactive "p")
7373   (let ((backward (< n 0))
7374         (n (abs n)))
7375     (while (and (> n 0)
7376                 (if backward
7377                     (gnus-summary-find-prev unread)
7378                   (gnus-summary-find-next unread)))
7379       (unless (zerop (setq n (1- n)))
7380         (gnus-summary-show-thread)))
7381     (when (/= 0 n)
7382       (gnus-message 7 "No more%s articles"
7383                     (if unread " unread" "")))
7384     (unless dont-display
7385       (gnus-summary-recenter)
7386       (gnus-summary-position-point))
7387     n))
7388
7389 (defun gnus-summary-next-unread-subject (n)
7390   "Go to next N'th unread summary line."
7391   (interactive "p")
7392   (gnus-summary-next-subject n t))
7393
7394 (defun gnus-summary-prev-subject (n &optional unread)
7395   "Go to previous N'th summary line.
7396 If optional argument UNREAD is non-nil, only unread article is selected."
7397   (interactive "p")
7398   (gnus-summary-next-subject (- n) unread))
7399
7400 (defun gnus-summary-prev-unread-subject (n)
7401   "Go to previous N'th unread summary line."
7402   (interactive "p")
7403   (gnus-summary-next-subject (- n) t))
7404
7405 (defun gnus-summary-goto-subjects (articles)
7406   "Insert the subject header for ARTICLES in the current buffer."
7407   (save-excursion
7408     (dolist (article articles)
7409       (gnus-summary-goto-subject article t)))
7410   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7411   (gnus-summary-position-point))
7412
7413 (defun gnus-summary-goto-subject (article &optional force silent)
7414   "Go the subject line of ARTICLE.
7415 If FORCE, also allow jumping to articles not currently shown."
7416   (interactive "nArticle number: ")
7417   (unless (numberp article)
7418     (error "Article %s is not a number" article))
7419   (let ((b (point))
7420         (data (gnus-data-find article)))
7421     ;; We read in the article if we have to.
7422     (and (not data)
7423          force
7424          (gnus-summary-insert-subject
7425           article
7426           (if (or (numberp force) (vectorp force)) force)
7427           t)
7428          (setq data (gnus-data-find article)))
7429     (goto-char b)
7430     (if (not data)
7431         (progn
7432           (unless silent
7433             (gnus-message 3 "Can't find article %d" article))
7434           nil)
7435       (let ((pt (gnus-data-pos data)))
7436         (goto-char pt)
7437         (gnus-summary-set-article-display-arrow pt))
7438       (gnus-summary-position-point)
7439       article)))
7440
7441 ;; Walking around summary lines with displaying articles.
7442
7443 (defun gnus-summary-expand-window (&optional arg)
7444   "Make the summary buffer take up the entire Emacs frame.
7445 Given a prefix, will force an `article' buffer configuration."
7446   (interactive "P")
7447   (if arg
7448       (gnus-configure-windows 'article 'force)
7449     (gnus-configure-windows 'summary 'force)))
7450
7451 (defun gnus-summary-display-article (article &optional all-header)
7452   "Display ARTICLE in article buffer."
7453   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7454                (with-current-buffer gnus-article-buffer
7455                  (eq major-mode 'gnus-article-mode)))
7456     (gnus-article-setup-buffer))
7457   (gnus-set-global-variables)
7458   (with-current-buffer gnus-article-buffer
7459     (setq gnus-article-charset gnus-newsgroup-charset)
7460     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7461     (mm-enable-multibyte))
7462   (if (null article)
7463       nil
7464     (prog1
7465         (if gnus-summary-display-article-function
7466             (funcall gnus-summary-display-article-function article all-header)
7467           (gnus-article-prepare article all-header))
7468       (gnus-run-hooks 'gnus-select-article-hook)
7469       (when (and gnus-current-article
7470                  (not (zerop gnus-current-article)))
7471         (gnus-summary-goto-subject gnus-current-article))
7472       (gnus-summary-recenter)
7473       (when (and gnus-use-trees gnus-show-threads)
7474         (gnus-possibly-generate-tree article)
7475         (gnus-highlight-selected-tree article))
7476       ;; Successfully display article.
7477       (gnus-article-set-window-start
7478        (cdr (assq article gnus-newsgroup-bookmarks))))))
7479
7480 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7481   "Select the current article.
7482 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7483 non-nil, the article will be re-fetched even if it already present in
7484 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7485 be displayed."
7486   ;; Make sure we are in the summary buffer to work around bbdb bug.
7487   (unless (eq major-mode 'gnus-summary-mode)
7488     (set-buffer gnus-summary-buffer))
7489   (let ((article (or article (gnus-summary-article-number)))
7490         (all-headers (not (not all-headers))) ;Must be t or nil.
7491         gnus-summary-display-article-function)
7492     (and (not pseudo)
7493          (gnus-summary-article-pseudo-p article)
7494          (error "This is a pseudo-article"))
7495     (save-excursion
7496       (set-buffer gnus-summary-buffer)
7497       (if (or (and gnus-single-article-buffer
7498                    (or (null gnus-current-article)
7499                        (null gnus-article-current)
7500                        (null (get-buffer gnus-article-buffer))
7501                        (not (eq article (cdr gnus-article-current)))
7502                        (not (equal (car gnus-article-current)
7503                                    gnus-newsgroup-name))))
7504               (and (not gnus-single-article-buffer)
7505                    (or (null gnus-current-article)
7506                        (not (eq gnus-current-article article))))
7507               force)
7508           ;; The requested article is different from the current article.
7509           (progn
7510             (gnus-summary-display-article article all-headers)
7511             (when (gnus-buffer-live-p gnus-article-buffer)
7512               (with-current-buffer gnus-article-buffer
7513                 (if (not gnus-article-decoded-p) ;; a local variable
7514                     (mm-disable-multibyte))))
7515             (gnus-article-set-window-start
7516              (cdr (assq article gnus-newsgroup-bookmarks)))
7517             article)
7518         'old))))
7519
7520 (defun gnus-summary-force-verify-and-decrypt ()
7521   "Display buttons for signed/encrypted parts and verify/decrypt them."
7522   (interactive)
7523   (let ((mm-verify-option 'known)
7524         (mm-decrypt-option 'known)
7525         (gnus-article-emulate-mime t)
7526         (gnus-buttonized-mime-types (append (list "multipart/signed"
7527                                                   "multipart/encrypted")
7528                                             gnus-buttonized-mime-types)))
7529     (gnus-summary-select-article nil 'force)))
7530
7531 (defun gnus-summary-set-current-mark (&optional current-mark)
7532   "Obsolete function."
7533   nil)
7534
7535 (defun gnus-summary-next-article (&optional unread subject backward push)
7536   "Select the next article.
7537 If UNREAD, only unread articles are selected.
7538 If SUBJECT, only articles with SUBJECT are selected.
7539 If BACKWARD, the previous article is selected instead of the next."
7540   (interactive "P")
7541   ;; Make sure we are in the summary buffer.
7542   (unless (eq major-mode 'gnus-summary-mode)
7543     (set-buffer gnus-summary-buffer))
7544   (cond
7545    ;; Is there such an article?
7546    ((and (gnus-summary-search-forward unread subject backward)
7547          (or (gnus-summary-display-article (gnus-summary-article-number))
7548              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7549     (gnus-summary-position-point))
7550    ;; If not, we try the first unread, if that is wanted.
7551    ((and subject
7552          gnus-auto-select-same
7553          (gnus-summary-first-unread-article))
7554     (gnus-summary-position-point)
7555     (gnus-message 6 "Wrapped"))
7556    ;; Try to get next/previous article not displayed in this group.
7557    ((and gnus-auto-extend-newsgroup
7558          (not unread) (not subject))
7559     (gnus-summary-goto-article
7560      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7561      nil (count-lines (point-min) (point))))
7562    ;; Go to next/previous group.
7563    (t
7564     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7565       (gnus-summary-jump-to-group gnus-newsgroup-name))
7566     (let ((cmd last-command-char)
7567           (point
7568            (with-current-buffer gnus-group-buffer
7569              (point)))
7570           (group
7571            (if (eq gnus-keep-same-level 'best)
7572                (gnus-summary-best-group gnus-newsgroup-name)
7573              (gnus-summary-search-group backward gnus-keep-same-level))))
7574       ;; For some reason, the group window gets selected.  We change
7575       ;; it back.
7576       (select-window (get-buffer-window (current-buffer)))
7577       ;; Select next unread newsgroup automagically.
7578       (cond
7579        ((or (not gnus-auto-select-next)
7580             (not cmd))
7581         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7582        ((or (eq gnus-auto-select-next 'quietly)
7583             (and (eq gnus-auto-select-next 'slightly-quietly)
7584                  push)
7585             (and (eq gnus-auto-select-next 'almost-quietly)
7586                  (gnus-summary-last-article-p)))
7587         ;; Select quietly.
7588         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7589             (gnus-summary-exit)
7590           (gnus-message 7 "No more%s articles (%s)..."
7591                         (if unread " unread" "")
7592                         (if group (concat "selecting " group)
7593                           "exiting"))
7594           (gnus-summary-next-group nil group backward)))
7595        (t
7596         (when (gnus-key-press-event-p last-input-event)
7597           (gnus-summary-walk-group-buffer
7598            gnus-newsgroup-name cmd unread backward point))))))))
7599
7600 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7601   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7602                       (?\C-p (gnus-group-prev-unread-group 1))))
7603         (cursor-in-echo-area t)
7604         keve key group ended prompt)
7605     (save-excursion
7606       (set-buffer gnus-group-buffer)
7607       (goto-char start)
7608       (setq group
7609             (if (eq gnus-keep-same-level 'best)
7610                 (gnus-summary-best-group gnus-newsgroup-name)
7611               (gnus-summary-search-group backward gnus-keep-same-level))))
7612     (while (not ended)
7613       (setq prompt
7614             (format
7615              "No more%s articles%s " (if unread " unread" "")
7616              (if (and group
7617                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7618                  (format " (Type %s for %s [%s])"
7619                          (single-key-description cmd)
7620                          (gnus-group-decoded-name group)
7621                          (gnus-group-unread group))
7622                (format " (Type %s to exit %s)"
7623                        (single-key-description cmd)
7624                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7625       ;; Confirm auto selection.
7626       (setq key (car (setq keve (gnus-read-event-char prompt)))
7627             ended t)
7628       (cond
7629        ((assq key keystrokes)
7630         (let ((obuf (current-buffer)))
7631           (switch-to-buffer gnus-group-buffer)
7632           (when group
7633             (gnus-group-jump-to-group group))
7634           (eval (cadr (assq key keystrokes)))
7635           (setq group (gnus-group-group-name))
7636           (switch-to-buffer obuf))
7637         (setq ended nil))
7638        ((equal key cmd)
7639         (if (or (not group)
7640                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7641             (gnus-summary-exit)
7642           (gnus-summary-next-group nil group backward)))
7643        (t
7644         (push (cdr keve) unread-command-events))))))
7645
7646 (defun gnus-summary-next-unread-article ()
7647   "Select unread article after current one."
7648   (interactive)
7649   (gnus-summary-next-article
7650    (or (not (eq gnus-summary-goto-unread 'never))
7651        (gnus-summary-last-article-p (gnus-summary-article-number)))
7652    (and gnus-auto-select-same
7653         (gnus-summary-article-subject))))
7654
7655 (defun gnus-summary-prev-article (&optional unread subject)
7656   "Select the article after the current one.
7657 If UNREAD is non-nil, only unread articles are selected."
7658   (interactive "P")
7659   (gnus-summary-next-article unread subject t))
7660
7661 (defun gnus-summary-prev-unread-article ()
7662   "Select unread article before current one."
7663   (interactive)
7664   (gnus-summary-prev-article
7665    (or (not (eq gnus-summary-goto-unread 'never))
7666        (gnus-summary-first-article-p (gnus-summary-article-number)))
7667    (and gnus-auto-select-same
7668         (gnus-summary-article-subject))))
7669
7670 (defun gnus-summary-next-page (&optional lines circular stop)
7671   "Show next page of the selected article.
7672 If at the end of the current article, select the next article.
7673 LINES says how many lines should be scrolled up.
7674
7675 If CIRCULAR is non-nil, go to the start of the article instead of
7676 selecting the next article when reaching the end of the current
7677 article.
7678
7679 If STOP is non-nil, just stop when reaching the end of the message.
7680
7681 Also see the variable `gnus-article-skip-boring'."
7682   (interactive "P")
7683   (setq gnus-summary-buffer (current-buffer))
7684   (gnus-set-global-variables)
7685   (let ((article (gnus-summary-article-number))
7686         (article-window (get-buffer-window gnus-article-buffer t))
7687         endp)
7688     ;; If the buffer is empty, we have no article.
7689     (unless article
7690       (error "No article to select"))
7691     (gnus-configure-windows 'article)
7692     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7693         (if (and (eq gnus-summary-goto-unread 'never)
7694                  (not (gnus-summary-last-article-p article)))
7695             (gnus-summary-next-article)
7696           (gnus-summary-next-unread-article))
7697       (if (or (null gnus-current-article)
7698               (null gnus-article-current)
7699               (/= article (cdr gnus-article-current))
7700               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7701           ;; Selected subject is different from current article's.
7702           (gnus-summary-display-article article)
7703         (when article-window
7704           (gnus-eval-in-buffer-window gnus-article-buffer
7705             (setq endp (or (gnus-article-next-page lines)
7706                            (gnus-article-only-boring-p))))
7707           (when endp
7708             (cond (stop
7709                    (gnus-message 3 "End of message"))
7710                   (circular
7711                    (gnus-summary-beginning-of-article))
7712                   (lines
7713                    (gnus-message 3 "End of message"))
7714                   ((null lines)
7715                    (if (and (eq gnus-summary-goto-unread 'never)
7716                             (not (gnus-summary-last-article-p article)))
7717                        (gnus-summary-next-article)
7718                      (gnus-summary-next-unread-article))))))))
7719     (gnus-summary-recenter)
7720     (gnus-summary-position-point)))
7721
7722 (defun gnus-summary-prev-page (&optional lines move)
7723   "Show previous page of selected article.
7724 Argument LINES specifies lines to be scrolled down.
7725 If MOVE, move to the previous unread article if point is at
7726 the beginning of the buffer."
7727   (interactive "P")
7728   (let ((article (gnus-summary-article-number))
7729         (article-window (get-buffer-window gnus-article-buffer t))
7730         endp)
7731     (gnus-configure-windows 'article)
7732     (if (or (null gnus-current-article)
7733             (null gnus-article-current)
7734             (/= article (cdr gnus-article-current))
7735             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7736         ;; Selected subject is different from current article's.
7737         (gnus-summary-display-article article)
7738       (gnus-summary-recenter)
7739       (when article-window
7740         (gnus-eval-in-buffer-window gnus-article-buffer
7741           (setq endp (gnus-article-prev-page lines)))
7742         (when (and move endp)
7743           (cond (lines
7744                  (gnus-message 3 "Beginning of message"))
7745                 ((null lines)
7746                  (if (and (eq gnus-summary-goto-unread 'never)
7747                           (not (gnus-summary-first-article-p article)))
7748                      (gnus-summary-prev-article)
7749                    (gnus-summary-prev-unread-article))))))))
7750   (gnus-summary-position-point))
7751
7752 (defun gnus-summary-prev-page-or-article (&optional lines)
7753   "Show previous page of selected article.
7754 Argument LINES specifies lines to be scrolled down.
7755 If at the beginning of the article, go to the next article."
7756   (interactive "P")
7757   (gnus-summary-prev-page lines t))
7758
7759 (defun gnus-summary-scroll-up (lines)
7760   "Scroll up (or down) one line current article.
7761 Argument LINES specifies lines to be scrolled up (or down if negative)."
7762   (interactive "p")
7763   (gnus-configure-windows 'article)
7764   (gnus-summary-show-thread)
7765   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7766     (gnus-eval-in-buffer-window gnus-article-buffer
7767       (cond ((> lines 0)
7768              (when (gnus-article-next-page lines)
7769                (gnus-message 3 "End of message")))
7770             ((< lines 0)
7771              (gnus-article-prev-page (- lines))))))
7772   (gnus-summary-recenter)
7773   (gnus-summary-position-point))
7774
7775 (defun gnus-summary-scroll-down (lines)
7776   "Scroll down (or up) one line current article.
7777 Argument LINES specifies lines to be scrolled down (or up if negative)."
7778   (interactive "p")
7779   (gnus-summary-scroll-up (- lines)))
7780
7781 (defun gnus-summary-next-same-subject ()
7782   "Select next article which has the same subject as current one."
7783   (interactive)
7784   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7785
7786 (defun gnus-summary-prev-same-subject ()
7787   "Select previous article which has the same subject as current one."
7788   (interactive)
7789   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7790
7791 (defun gnus-summary-next-unread-same-subject ()
7792   "Select next unread article which has the same subject as current one."
7793   (interactive)
7794   (gnus-summary-next-article t (gnus-summary-article-subject)))
7795
7796 (defun gnus-summary-prev-unread-same-subject ()
7797   "Select previous unread article which has the same subject as current one."
7798   (interactive)
7799   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7800
7801 (defun gnus-summary-first-unread-article ()
7802   "Select the first unread article.
7803 Return nil if there are no unread articles."
7804   (interactive)
7805   (prog1
7806       (when (gnus-summary-first-subject t)
7807         (gnus-summary-show-thread)
7808         (gnus-summary-first-subject t)
7809         (gnus-summary-display-article (gnus-summary-article-number)))
7810     (gnus-summary-position-point)))
7811
7812 (defun gnus-summary-first-unread-subject ()
7813   "Place the point on the subject line of the first unread article.
7814 Return nil if there are no unread articles."
7815   (interactive)
7816   (prog1
7817       (when (gnus-summary-first-subject t)
7818         (gnus-summary-show-thread)
7819         (gnus-summary-first-subject t))
7820     (gnus-summary-position-point)))
7821
7822 (defun gnus-summary-first-unseen-subject ()
7823   "Place the point on the subject line of the first unseen article.
7824 Return nil if there are no unseen articles."
7825   (interactive)
7826   (prog1
7827       (when (gnus-summary-first-subject nil nil t)
7828         (gnus-summary-show-thread)
7829         (gnus-summary-first-subject nil nil t))
7830     (gnus-summary-position-point)))
7831
7832 (defun gnus-summary-first-unseen-or-unread-subject ()
7833   "Place the point on the subject line of the first unseen article or,
7834 if all article have been seen, on the subject line of the first unread
7835 article."
7836   (interactive)
7837   (prog1
7838       (unless (when (gnus-summary-first-subject nil nil t)
7839                 (gnus-summary-show-thread)
7840                 (gnus-summary-first-subject nil nil t))
7841         (when (gnus-summary-first-subject t)
7842           (gnus-summary-show-thread)
7843           (gnus-summary-first-subject t)))
7844     (gnus-summary-position-point)))
7845
7846 (defun gnus-summary-first-article ()
7847   "Select the first article.
7848 Return nil if there are no articles."
7849   (interactive)
7850   (prog1
7851       (when (gnus-summary-first-subject)
7852         (gnus-summary-show-thread)
7853         (gnus-summary-first-subject)
7854         (gnus-summary-display-article (gnus-summary-article-number)))
7855     (gnus-summary-position-point)))
7856
7857 (defun gnus-summary-best-unread-article (&optional arg)
7858   "Select the unread article with the highest score.
7859 If given a prefix argument, select the next unread article that has a
7860 score higher than the default score."
7861   (interactive "P")
7862   (let ((article (if arg
7863                      (gnus-summary-better-unread-subject)
7864                    (gnus-summary-best-unread-subject))))
7865     (if article
7866         (gnus-summary-goto-article article)
7867       (error "No unread articles"))))
7868
7869 (defun gnus-summary-best-unread-subject ()
7870   "Select the unread subject with the highest score."
7871   (interactive)
7872   (let ((best -1000000)
7873         (data gnus-newsgroup-data)
7874         article score)
7875     (while data
7876       (and (gnus-data-unread-p (car data))
7877            (> (setq score
7878                     (gnus-summary-article-score (gnus-data-number (car data))))
7879               best)
7880            (setq best score
7881                  article (gnus-data-number (car data))))
7882       (setq data (cdr data)))
7883     (when article
7884       (gnus-summary-goto-subject article))
7885     (gnus-summary-position-point)
7886     article))
7887
7888 (defun gnus-summary-better-unread-subject ()
7889   "Select the first unread subject that has a score over the default score."
7890   (interactive)
7891   (let ((data gnus-newsgroup-data)
7892         article score)
7893     (while (and (setq article (gnus-data-number (car data)))
7894                 (or (gnus-data-read-p (car data))
7895                     (not (> (gnus-summary-article-score article)
7896                             gnus-summary-default-score))))
7897       (setq data (cdr data)))
7898     (when article
7899       (gnus-summary-goto-subject article))
7900     (gnus-summary-position-point)
7901     article))
7902
7903 (defun gnus-summary-last-subject ()
7904   "Go to the last displayed subject line in the group."
7905   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7906     (when article
7907       (gnus-summary-goto-subject article))))
7908
7909 (defun gnus-summary-goto-article (article &optional all-headers force)
7910   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7911 If ALL-HEADERS is non-nil, no header lines are hidden.
7912 If FORCE, go to the article even if it isn't displayed.  If FORCE
7913 is a number, it is the line the article is to be displayed on."
7914   (interactive
7915    (list
7916     (completing-read
7917      "Article number or Message-ID: "
7918      (mapcar (lambda (number) (list (int-to-string number)))
7919              gnus-newsgroup-limit))
7920     current-prefix-arg
7921     t))
7922   (prog1
7923       (if (and (stringp article)
7924                (string-match "@\\|%40" article))
7925           (gnus-summary-refer-article article)
7926         (when (stringp article)
7927           (setq article (string-to-number article)))
7928         (if (gnus-summary-goto-subject article force)
7929             (gnus-summary-display-article article all-headers)
7930           (gnus-message 4 "Couldn't go to article %s" article) nil))
7931     (gnus-summary-position-point)))
7932
7933 (defun gnus-summary-goto-last-article ()
7934   "Go to the previously read article."
7935   (interactive)
7936   (prog1
7937       (when gnus-last-article
7938         (gnus-summary-goto-article gnus-last-article nil t))
7939     (gnus-summary-position-point)))
7940
7941 (defun gnus-summary-pop-article (number)
7942   "Pop one article off the history and go to the previous.
7943 NUMBER articles will be popped off."
7944   (interactive "p")
7945   (let (to)
7946     (setq gnus-newsgroup-history
7947           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7948     (if to
7949         (gnus-summary-goto-article (car to) nil t)
7950       (error "Article history empty")))
7951   (gnus-summary-position-point))
7952
7953 ;; Summary commands and functions for limiting the summary buffer.
7954
7955 (defun gnus-summary-limit-to-articles (n)
7956   "Limit the summary buffer to the next N articles.
7957 If not given a prefix, use the process marked articles instead."
7958   (interactive "P")
7959   (prog1
7960       (let ((articles (gnus-summary-work-articles n)))
7961         (setq gnus-newsgroup-processable nil)
7962         (gnus-summary-limit articles))
7963     (gnus-summary-position-point)))
7964
7965 (defun gnus-summary-pop-limit (&optional total)
7966   "Restore the previous limit.
7967 If given a prefix, remove all limits."
7968   (interactive "P")
7969   (when total
7970     (setq gnus-newsgroup-limits
7971           (list (mapcar (lambda (h) (mail-header-number h))
7972                         gnus-newsgroup-headers))))
7973   (unless gnus-newsgroup-limits
7974     (error "No limit to pop"))
7975   (prog1
7976       (gnus-summary-limit nil 'pop)
7977     (gnus-summary-position-point)))
7978
7979 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7980   "Limit the summary buffer to articles that have subjects that match a regexp.
7981 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7982   (interactive
7983    (list (read-string (if current-prefix-arg
7984                           "Exclude subject (regexp): "
7985                         "Limit to subject (regexp): "))
7986          nil current-prefix-arg))
7987   (unless header
7988     (setq header "subject"))
7989   (when (not (equal "" subject))
7990     (prog1
7991         (let ((articles (gnus-summary-find-matching
7992                          (or header "subject") subject 'all nil nil
7993                          not-matching)))
7994           (unless articles
7995             (error "Found no matches for \"%s\"" subject))
7996           (gnus-summary-limit articles))
7997       (gnus-summary-position-point))))
7998
7999 (defun gnus-summary-limit-to-author (from &optional not-matching)
8000   "Limit the summary buffer to articles that have authors that match a regexp.
8001 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8002   (interactive
8003    (list (read-string (if current-prefix-arg
8004                           "Exclude author (regexp): "
8005                         "Limit to author (regexp): "))
8006          current-prefix-arg))
8007   (gnus-summary-limit-to-subject from "from" not-matching))
8008
8009 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8010   "Limit the summary buffer to articles with the given RECIPIENT.
8011
8012 If NOT-MATCHING, exclude RECIPIENT.
8013
8014 To and Cc headers are checked.  You need to include them in
8015 `nnmail-extra-headers'."
8016   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8017   (interactive
8018    (list (read-string (format "%s recipient (regexp): "
8019                               (if current-prefix-arg "Exclude" "Limit to")))
8020          current-prefix-arg))
8021   (when (not (equal "" recipient))
8022     (prog1 (let* ((to
8023                    (if (memq 'To nnmail-extra-headers)
8024                        (gnus-summary-find-matching
8025                         (cons 'extra 'To) recipient 'all nil nil
8026                         not-matching)
8027                      (gnus-message
8028                       1 "`To' isn't present in `nnmail-extra-headers'")
8029                      (sit-for 1)
8030                      nil))
8031                   (cc
8032                    (if (memq 'Cc nnmail-extra-headers)
8033                        (gnus-summary-find-matching
8034                         (cons 'extra 'Cc) recipient 'all nil nil
8035                         not-matching)
8036                      (gnus-message
8037                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8038                      (sit-for 1)
8039                      nil))
8040                   (articles
8041                    (if not-matching
8042                        ;; We need the numbers that are in both lists:
8043                        (mapcar (lambda (a)
8044                                  (and (memq a to) a))
8045                                cc)
8046                      (nconc to cc))))
8047              (unless articles
8048                (error "Found no matches for \"%s\"" recipient))
8049              (gnus-summary-limit articles))
8050       (gnus-summary-position-point))))
8051
8052 (defun gnus-summary-limit-to-address (address &optional not-matching)
8053   "Limit the summary buffer to articles with the given ADDRESS.
8054
8055 If NOT-MATCHING, exclude ADDRESS.
8056
8057 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8058 in `nnmail-extra-headers'."
8059   (interactive
8060    (list (read-string (format "%s address (regexp): "
8061                               (if current-prefix-arg "Exclude" "Limit to")))
8062          current-prefix-arg))
8063   (when (not (equal "" address))
8064     (prog1 (let* ((to
8065                    (if (memq 'To nnmail-extra-headers)
8066                        (gnus-summary-find-matching
8067                         (cons 'extra 'To) address 'all nil nil
8068                         not-matching)
8069                      (gnus-message
8070                       1 "`To' isn't present in `nnmail-extra-headers'")
8071                      (sit-for 1)
8072                      t))
8073                   (cc
8074                    (if (memq 'Cc nnmail-extra-headers)
8075                        (gnus-summary-find-matching
8076                         (cons 'extra 'Cc) address 'all nil nil
8077                         not-matching)
8078                      (gnus-message
8079                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8080                      (sit-for 1)
8081                      t))
8082                   (from
8083                    (gnus-summary-find-matching "from" address
8084                                                'all nil nil not-matching))
8085                   (articles
8086                    (if not-matching
8087                        ;; We need the numbers that are in all lists:
8088                        (if (eq cc t)
8089                            (if (eq to t)
8090                                from
8091                              (mapcar (lambda (a) (car (memq a from))) to))
8092                          (if (eq to t)
8093                              (mapcar (lambda (a) (car (memq a from))) cc)
8094                            (mapcar (lambda (a) (car (memq a from)))
8095                                    (mapcar (lambda (a) (car (memq a to)))
8096                                            cc))))
8097                      (nconc (if (eq to t) nil to)
8098                             (if (eq cc t) nil cc)
8099                             from))))
8100              (unless articles
8101                (error "Found no matches for \"%s\"" address))
8102              (gnus-summary-limit articles))
8103       (gnus-summary-position-point))))
8104
8105 (defun gnus-summary-limit-strange-charsets-predicate (header)
8106   (let ((string (concat (mail-header-subject header)
8107                         (mail-header-from header)))
8108         charset found)
8109     (dotimes (i (1- (length string)))
8110       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8111       (when (string-match "unicode\\|big\\|japanese" charset)
8112         (setq found t)))
8113     found))
8114
8115 (defun gnus-summary-limit-to-predicate (predicate)
8116   "Limit to articles where PREDICATE returns non-nil.
8117 PREDICATE will be called with the header structures of the
8118 articles."
8119   (let ((articles nil)
8120         (case-fold-search t))
8121     (dolist (header gnus-newsgroup-headers)
8122       (when (funcall predicate header)
8123         (push (mail-header-number header) articles)))
8124     (gnus-summary-limit (nreverse articles))))
8125
8126 (defun gnus-summary-limit-to-age (age &optional younger-p)
8127   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8128 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8129 articles that are younger than AGE days."
8130   (interactive
8131    (let ((younger current-prefix-arg)
8132          (days-got nil)
8133          days)
8134      (while (not days-got)
8135        (setq days (if younger
8136                       (read-string "Limit to articles younger than (in days, older when negative): ")
8137                     (read-string
8138                      "Limit to articles older than (in days, younger when negative): ")))
8139        (when (> (length days) 0)
8140          (setq days (read days)))
8141        (if (numberp days)
8142            (progn
8143              (setq days-got t)
8144              (when (< days 0)
8145                (setq younger (not younger))
8146                (setq days (* days -1))))
8147          (message "Please enter a number.")
8148          (sleep-for 1)))
8149      (list days younger)))
8150   (prog1
8151       (let ((data gnus-newsgroup-data)
8152             (cutoff (days-to-time age))
8153             articles d date is-younger)
8154         (while (setq d (pop data))
8155           (when (and (vectorp (gnus-data-header d))
8156                      (setq date (mail-header-date (gnus-data-header d))))
8157             (setq is-younger (time-less-p
8158                               (time-since (condition-case ()
8159                                               (date-to-time date)
8160                                             (error '(0 0))))
8161                               cutoff))
8162             (when (if younger-p
8163                       is-younger
8164                     (not is-younger))
8165               (push (gnus-data-number d) articles))))
8166         (gnus-summary-limit (nreverse articles)))
8167     (gnus-summary-position-point)))
8168
8169 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8170   "Limit the summary buffer to articles that match an 'extra' header."
8171   (interactive
8172    (let ((header
8173           (intern
8174            (gnus-completing-read-with-default
8175             (symbol-name (car gnus-extra-headers))
8176             (if current-prefix-arg
8177                 "Exclude extra header"
8178               "Limit extra header")
8179             (mapcar (lambda (x)
8180                       (cons (symbol-name x) x))
8181                     gnus-extra-headers)
8182             nil
8183             t))))
8184      (list header
8185            (read-string (format "%s header %s (regexp): "
8186                                 (if current-prefix-arg "Exclude" "Limit to")
8187                                 header))
8188            current-prefix-arg)))
8189   (when (not (equal "" regexp))
8190     (prog1
8191         (let ((articles (gnus-summary-find-matching
8192                          (cons 'extra header) regexp 'all nil nil
8193                          not-matching)))
8194           (unless articles
8195             (error "Found no matches for \"%s\"" regexp))
8196           (gnus-summary-limit articles))
8197       (gnus-summary-position-point))))
8198
8199 (defun gnus-summary-limit-to-display-predicate ()
8200   "Limit the summary buffer to the predicated in the `display' group parameter."
8201   (interactive)
8202   (unless gnus-newsgroup-display
8203     (error "There is no `display' group parameter"))
8204   (let (articles)
8205     (dolist (number gnus-newsgroup-articles)
8206       (when (funcall gnus-newsgroup-display)
8207         (push number articles)))
8208     (gnus-summary-limit articles))
8209   (gnus-summary-position-point))
8210
8211 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8212 (make-obsolete
8213  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8214
8215 (defun gnus-summary-limit-to-unread (&optional all)
8216   "Limit the summary buffer to articles that are not marked as read.
8217 If ALL is non-nil, limit strictly to unread articles."
8218   (interactive "P")
8219   (if all
8220       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8221     (gnus-summary-limit-to-marks
8222      ;; Concat all the marks that say that an article is read and have
8223      ;; those removed.
8224      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8225            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8226            gnus-low-score-mark gnus-expirable-mark
8227            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8228            gnus-duplicate-mark gnus-souped-mark)
8229      'reverse)))
8230
8231 (defun gnus-summary-limit-to-headers (match &optional reverse)
8232   "Limit the summary buffer to articles that have headers that match MATCH.
8233 If REVERSE (the prefix), limit to articles that don't match."
8234   (interactive "sMatch headers (regexp): \nP")
8235   (gnus-summary-limit-to-bodies match reverse t))
8236
8237 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8238   "Limit the summary buffer to articles that have bodies that match MATCH.
8239 If REVERSE (the prefix), limit to articles that don't match."
8240   (interactive "sMatch body (regexp): \nP")
8241   (let ((articles nil)
8242         (gnus-select-article-hook nil)  ;Disable hook.
8243         (gnus-article-prepare-hook nil)
8244         (gnus-use-article-prefetch nil)
8245         (gnus-keep-backlog nil)
8246         (gnus-break-pages nil)
8247         (gnus-summary-display-arrow nil)
8248         (gnus-updated-mode-lines nil)
8249         (gnus-auto-center-summary nil)
8250         (gnus-display-mime-function nil))
8251     (dolist (data gnus-newsgroup-data)
8252       (let (gnus-mark-article-hook)
8253         (gnus-summary-select-article t t nil (gnus-data-number data)))
8254       (save-excursion
8255         (set-buffer gnus-article-buffer)
8256         (article-goto-body)
8257         (let* ((case-fold-search t)
8258                (found (if headersp
8259                           (re-search-backward match nil t)
8260                         (re-search-forward match nil t))))
8261           (when (or (and found
8262                          (not reverse))
8263                     (and (not found)
8264                          reverse))
8265             (push (gnus-data-number data) articles)))))
8266     (if (not articles)
8267         (message "No messages matched")
8268       (gnus-summary-limit articles)))
8269   (gnus-summary-position-point))
8270
8271 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8272   "Limit the summary buffer to articles that aren't part on any thread.
8273 If THREADSP (the prefix), limit to articles that are in threads."
8274   (interactive "P")
8275   (let ((articles nil)
8276         thread-articles
8277         threads)
8278     (dolist (thread gnus-newsgroup-threads)
8279       (if (stringp (car thread))
8280           (dolist (thread (cdr thread))
8281             (push thread threads))
8282         (push thread threads)))
8283     (dolist (thread threads)
8284       (setq thread-articles (gnus-articles-in-thread thread))
8285       (when (or (and threadsp
8286                      (> (length thread-articles) 1))
8287                 (and (not threadsp)
8288                      (= (length thread-articles) 1)))
8289         (setq articles (nconc thread-articles articles))))
8290     (if (not articles)
8291         (message "No messages matched")
8292       (gnus-summary-limit articles))
8293     (gnus-summary-position-point)))
8294
8295 (defun gnus-summary-limit-to-replied (&optional unreplied)
8296   "Limit the summary buffer to replied articles.
8297 If UNREPLIED (the prefix), limit to unreplied articles."
8298   (interactive "P")
8299   (if unreplied
8300       (gnus-summary-limit
8301        (gnus-set-difference gnus-newsgroup-articles
8302         gnus-newsgroup-replied))
8303     (gnus-summary-limit gnus-newsgroup-replied))
8304   (gnus-summary-position-point))
8305
8306 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8307 (make-obsolete 'gnus-summary-delete-marked-with
8308                'gnus-summary-limit-exclude-marks)
8309
8310 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8311   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8312 If REVERSE, limit the summary buffer to articles that are marked
8313 with MARKS.  MARKS can either be a string of marks or a list of marks.
8314 Returns how many articles were removed."
8315   (interactive "sMarks: ")
8316   (gnus-summary-limit-to-marks marks t))
8317
8318 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8319   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8320 If REVERSE (the prefix), limit the summary buffer to articles that are
8321 not marked with MARKS.  MARKS can either be a string of marks or a
8322 list of marks.
8323 Returns how many articles were removed."
8324   (interactive "sMarks: \nP")
8325   (prog1
8326       (let ((data gnus-newsgroup-data)
8327             (marks (if (listp marks) marks
8328                      (append marks nil))) ; Transform to list.
8329             articles)
8330         (while data
8331           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8332                   (memq (gnus-data-mark (car data)) marks))
8333             (push (gnus-data-number (car data)) articles))
8334           (setq data (cdr data)))
8335         (gnus-summary-limit articles))
8336     (gnus-summary-position-point)))
8337
8338 (defun gnus-summary-limit-to-score (score)
8339   "Limit to articles with score at or above SCORE."
8340   (interactive "NLimit to articles with score of at least: ")
8341   (let ((data gnus-newsgroup-data)
8342         articles)
8343     (while data
8344       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8345                 score)
8346         (push (gnus-data-number (car data)) articles))
8347       (setq data (cdr data)))
8348     (prog1
8349         (gnus-summary-limit articles)
8350       (gnus-summary-position-point))))
8351
8352 (defun gnus-summary-limit-to-unseen ()
8353   "Limit to unseen articles."
8354   (interactive)
8355   (prog1
8356       (gnus-summary-limit gnus-newsgroup-unseen)
8357     (gnus-summary-position-point)))
8358
8359 (defun gnus-summary-limit-include-thread (id)
8360   "Display all the hidden articles that is in the thread with ID in it.
8361 When called interactively, ID is the Message-ID of the current
8362 article."
8363   (interactive (list (mail-header-id (gnus-summary-article-header))))
8364   (let ((articles (gnus-articles-in-thread
8365                    (gnus-id-to-thread (gnus-root-id id)))))
8366     (prog1
8367         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8368       (gnus-summary-limit-include-matching-articles
8369        "subject"
8370        (regexp-quote (gnus-simplify-subject-re
8371                       (mail-header-subject (gnus-id-to-header id)))))
8372       (gnus-summary-position-point))))
8373
8374 (defun gnus-summary-limit-include-matching-articles (header regexp)
8375   "Display all the hidden articles that have HEADERs that match REGEXP."
8376   (interactive (list (read-string "Match on header: ")
8377                      (read-string "Regexp: ")))
8378   (let ((articles (gnus-find-matching-articles header regexp)))
8379     (prog1
8380         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8381       (gnus-summary-position-point))))
8382
8383 (defun gnus-summary-insert-dormant-articles ()
8384   "Insert all the dormant articles for this group into the current buffer."
8385   (interactive)
8386   (let ((gnus-verbose (max 6 gnus-verbose)))
8387     (if (not gnus-newsgroup-dormant)
8388         (gnus-message 3 "No dormant articles for this group")
8389       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8390
8391 (defun gnus-summary-insert-ticked-articles ()
8392   "Insert ticked articles for this group into the current buffer."
8393   (interactive)
8394   (let ((gnus-verbose (max 6 gnus-verbose)))
8395     (if (not gnus-newsgroup-marked)
8396         (gnus-message 3 "No ticked articles for this group")
8397       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8398
8399 (defun gnus-summary-limit-include-dormant ()
8400   "Display all the hidden articles that are marked as dormant.
8401 Note that this command only works on a subset of the articles currently
8402 fetched for this group."
8403   (interactive)
8404   (unless gnus-newsgroup-dormant
8405     (error "There are no dormant articles in this group"))
8406   (prog1
8407       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8408     (gnus-summary-position-point)))
8409
8410 (defun gnus-summary-limit-exclude-dormant ()
8411   "Hide all dormant articles."
8412   (interactive)
8413   (prog1
8414       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8415     (gnus-summary-position-point)))
8416
8417 (defun gnus-summary-limit-exclude-childless-dormant ()
8418   "Hide all dormant articles that have no children."
8419   (interactive)
8420   (let ((data (gnus-data-list t))
8421         articles d children)
8422     ;; Find all articles that are either not dormant or have
8423     ;; children.
8424     (while (setq d (pop data))
8425       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8426                 (and (setq children
8427                            (gnus-article-children (gnus-data-number d)))
8428                      (let (found)
8429                        (while children
8430                          (when (memq (car children) articles)
8431                            (setq children nil
8432                                  found t))
8433                          (pop children))
8434                        found)))
8435         (push (gnus-data-number d) articles)))
8436     ;; Do the limiting.
8437     (prog1
8438         (gnus-summary-limit articles)
8439       (gnus-summary-position-point))))
8440
8441 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8442   "Mark all unread excluded articles as read.
8443 If ALL, mark even excluded ticked and dormants as read."
8444   (interactive "P")
8445   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8446   (let ((articles (gnus-sorted-ndifference
8447                    (sort
8448                     (mapcar (lambda (h) (mail-header-number h))
8449                             gnus-newsgroup-headers)
8450                     '<)
8451                    gnus-newsgroup-limit))
8452         article)
8453     (setq gnus-newsgroup-unreads
8454           (gnus-sorted-intersection gnus-newsgroup-unreads
8455                                     gnus-newsgroup-limit))
8456     (if all
8457         (setq gnus-newsgroup-dormant nil
8458               gnus-newsgroup-marked nil
8459               gnus-newsgroup-reads
8460               (nconc
8461                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8462                gnus-newsgroup-reads))
8463       (while (setq article (pop articles))
8464         (unless (or (memq article gnus-newsgroup-dormant)
8465                     (memq article gnus-newsgroup-marked))
8466           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8467
8468 (defun gnus-summary-limit (articles &optional pop)
8469   (if pop
8470       ;; We pop the previous limit off the stack and use that.
8471       (setq articles (car gnus-newsgroup-limits)
8472             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8473     ;; We use the new limit, so we push the old limit on the stack.
8474     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8475   ;; Set the limit.
8476   (setq gnus-newsgroup-limit articles)
8477   (let ((total (length gnus-newsgroup-data))
8478         (data (gnus-data-find-list (gnus-summary-article-number)))
8479         (gnus-summary-mark-below nil)   ; Inhibit this.
8480         found)
8481     ;; This will do all the work of generating the new summary buffer
8482     ;; according to the new limit.
8483     (gnus-summary-prepare)
8484     ;; Hide any threads, possibly.
8485     (gnus-summary-maybe-hide-threads)
8486     ;; Try to return to the article you were at, or one in the
8487     ;; neighborhood.
8488     (when data
8489       ;; We try to find some article after the current one.
8490       (while data
8491         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8492           (setq data nil
8493                 found t))
8494         (setq data (cdr data))))
8495     (unless found
8496       ;; If there is no data, that means that we were after the last
8497       ;; article.  The same goes when we can't find any articles
8498       ;; after the current one.
8499       (goto-char (point-max))
8500       (gnus-summary-find-prev))
8501     (gnus-set-mode-line 'summary)
8502     ;; We return how many articles were removed from the summary
8503     ;; buffer as a result of the new limit.
8504     (- total (length gnus-newsgroup-data))))
8505
8506 (defsubst gnus-invisible-cut-children (threads)
8507   (let ((num 0))
8508     (while threads
8509       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8510         (incf num))
8511       (pop threads))
8512     (< num 2)))
8513
8514 (defsubst gnus-cut-thread (thread)
8515   "Go forwards in the thread until we find an article that we want to display."
8516   (when (or (eq gnus-fetch-old-headers 'some)
8517             (eq gnus-fetch-old-headers 'invisible)
8518             (numberp gnus-fetch-old-headers)
8519             (eq gnus-build-sparse-threads 'some)
8520             (eq gnus-build-sparse-threads 'more))
8521     ;; Deal with old-fetched headers and sparse threads.
8522     (while (and
8523             thread
8524             (or
8525              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8526              (gnus-summary-article-ancient-p
8527               (mail-header-number (car thread))))
8528             (if (or (<= (length (cdr thread)) 1)
8529                     (eq gnus-fetch-old-headers 'invisible))
8530                 (setq gnus-newsgroup-limit
8531                       (delq (mail-header-number (car thread))
8532                             gnus-newsgroup-limit)
8533                       thread (cadr thread))
8534               (when (gnus-invisible-cut-children (cdr thread))
8535                 (let ((th (cdr thread)))
8536                   (while th
8537                     (if (memq (mail-header-number (caar th))
8538                               gnus-newsgroup-limit)
8539                         (setq thread (car th)
8540                               th nil)
8541                       (setq th (cdr th))))))))))
8542   thread)
8543
8544 (defun gnus-cut-threads (threads)
8545   "Cut off all uninteresting articles from the beginning of THREADS."
8546   (when (or (eq gnus-fetch-old-headers 'some)
8547             (eq gnus-fetch-old-headers 'invisible)
8548             (numberp gnus-fetch-old-headers)
8549             (eq gnus-build-sparse-threads 'some)
8550             (eq gnus-build-sparse-threads 'more))
8551     (let ((th threads))
8552       (while th
8553         (setcar th (gnus-cut-thread (car th)))
8554         (setq th (cdr th)))))
8555   ;; Remove nixed out threads.
8556   (delq nil threads))
8557
8558 (defun gnus-summary-initial-limit (&optional show-if-empty)
8559   "Figure out what the initial limit is supposed to be on group entry.
8560 This entails weeding out unwanted dormants, low-scored articles,
8561 fetch-old-headers verbiage, and so on."
8562   ;; Most groups have nothing to remove.
8563   (if (or gnus-inhibit-limiting
8564           (and (null gnus-newsgroup-dormant)
8565                (eq gnus-newsgroup-display 'gnus-not-ignore)
8566                (not (eq gnus-fetch-old-headers 'some))
8567                (not (numberp gnus-fetch-old-headers))
8568                (not (eq gnus-fetch-old-headers 'invisible))
8569                (null gnus-summary-expunge-below)
8570                (not (eq gnus-build-sparse-threads 'some))
8571                (not (eq gnus-build-sparse-threads 'more))
8572                (null gnus-thread-expunge-below)
8573                (not gnus-use-nocem)))
8574       ()                                ; Do nothing.
8575     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8576     (setq gnus-newsgroup-limit nil)
8577     (mapatoms
8578      (lambda (node)
8579        (unless (car (symbol-value node))
8580          ;; These threads have no parents -- they are roots.
8581          (let ((nodes (cdr (symbol-value node)))
8582                thread)
8583            (while nodes
8584              (if (and gnus-thread-expunge-below
8585                       (< (gnus-thread-total-score (car nodes))
8586                          gnus-thread-expunge-below))
8587                  (gnus-expunge-thread (pop nodes))
8588                (setq thread (pop nodes))
8589                (gnus-summary-limit-children thread))))))
8590      gnus-newsgroup-dependencies)
8591     ;; If this limitation resulted in an empty group, we might
8592     ;; pop the previous limit and use it instead.
8593     (when (and (not gnus-newsgroup-limit)
8594                show-if-empty)
8595       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8596     gnus-newsgroup-limit))
8597
8598 (defun gnus-summary-limit-children (thread)
8599   "Return 1 if this subthread is visible and 0 if it is not."
8600   ;; First we get the number of visible children to this thread.  This
8601   ;; is done by recursing down the thread using this function, so this
8602   ;; will really go down to a leaf article first, before slowly
8603   ;; working its way up towards the root.
8604   (when thread
8605     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8606            (children
8607            (if (cdr thread)
8608                (apply '+ (mapcar 'gnus-summary-limit-children
8609                                  (cdr thread)))
8610              0))
8611           (number (mail-header-number (car thread)))
8612           score)
8613       (if (and
8614            (not (memq number gnus-newsgroup-marked))
8615            (or
8616             ;; If this article is dormant and has absolutely no visible
8617             ;; children, then this article isn't visible.
8618             (and (memq number gnus-newsgroup-dormant)
8619                  (zerop children))
8620             ;; If this is "fetch-old-headered" and there is no
8621             ;; visible children, then we don't want this article.
8622             (and (or (eq gnus-fetch-old-headers 'some)
8623                      (numberp gnus-fetch-old-headers))
8624                  (gnus-summary-article-ancient-p number)
8625                  (zerop children))
8626             ;; If this is "fetch-old-headered" and `invisible', then
8627             ;; we don't want this article.
8628             (and (eq gnus-fetch-old-headers 'invisible)
8629                  (gnus-summary-article-ancient-p number))
8630             ;; If this is a sparsely inserted article with no children,
8631             ;; we don't want it.
8632             (and (eq gnus-build-sparse-threads 'some)
8633                  (gnus-summary-article-sparse-p number)
8634                  (zerop children))
8635             ;; If we use expunging, and this article is really
8636             ;; low-scored, then we don't want this article.
8637             (when (and gnus-summary-expunge-below
8638                        (< (setq score
8639                                 (or (cdr (assq number gnus-newsgroup-scored))
8640                                     gnus-summary-default-score))
8641                           gnus-summary-expunge-below))
8642               ;; We increase the expunge-tally here, but that has
8643               ;; nothing to do with the limits, really.
8644               (incf gnus-newsgroup-expunged-tally)
8645               ;; We also mark as read here, if that's wanted.
8646               (when (and gnus-summary-mark-below
8647                          (< score gnus-summary-mark-below))
8648                 (setq gnus-newsgroup-unreads
8649                       (delq number gnus-newsgroup-unreads))
8650                 (if gnus-newsgroup-auto-expire
8651                     (push number gnus-newsgroup-expirable)
8652                   (push (cons number gnus-low-score-mark)
8653                         gnus-newsgroup-reads)))
8654               t)
8655             ;; Do the `display' group parameter.
8656             (and gnus-newsgroup-display
8657                  (not (funcall gnus-newsgroup-display)))
8658             ;; Check NoCeM things.
8659             (when (and gnus-use-nocem
8660                        (gnus-nocem-unwanted-article-p
8661                         (mail-header-id (car thread))))
8662               (setq gnus-newsgroup-unreads
8663                     (delq number gnus-newsgroup-unreads))
8664               t)))
8665           ;; Nope, invisible article.
8666           0
8667         ;; Ok, this article is to be visible, so we add it to the limit
8668         ;; and return 1.
8669         (push number gnus-newsgroup-limit)
8670         1))))
8671
8672 (defun gnus-expunge-thread (thread)
8673   "Mark all articles in THREAD as read."
8674   (let* ((number (mail-header-number (car thread))))
8675     (incf gnus-newsgroup-expunged-tally)
8676     ;; We also mark as read here, if that's wanted.
8677     (setq gnus-newsgroup-unreads
8678           (delq number gnus-newsgroup-unreads))
8679     (if gnus-newsgroup-auto-expire
8680         (push number gnus-newsgroup-expirable)
8681       (push (cons number gnus-low-score-mark)
8682             gnus-newsgroup-reads)))
8683   ;; Go recursively through all subthreads.
8684   (mapcar 'gnus-expunge-thread (cdr thread)))
8685
8686 ;; Summary article oriented commands
8687
8688 (defun gnus-summary-refer-parent-article (n)
8689   "Refer parent article N times.
8690 If N is negative, go to ancestor -N instead.
8691 The difference between N and the number of articles fetched is returned."
8692   (interactive "p")
8693   (let ((skip 1)
8694         error header ref)
8695     (when (not (natnump n))
8696       (setq skip (abs n)
8697             n 1))
8698     (while (and (> n 0)
8699                 (not error))
8700       (setq header (gnus-summary-article-header))
8701       (if (and (eq (mail-header-number header)
8702                    (cdr gnus-article-current))
8703                (equal gnus-newsgroup-name
8704                       (car gnus-article-current)))
8705           ;; If we try to find the parent of the currently
8706           ;; displayed article, then we take a look at the actual
8707           ;; References header, since this is slightly more
8708           ;; reliable than the References field we got from the
8709           ;; server.
8710           (save-excursion
8711             (set-buffer gnus-original-article-buffer)
8712             (nnheader-narrow-to-headers)
8713             (unless (setq ref (message-fetch-field "references"))
8714               (when (setq ref (message-fetch-field "in-reply-to"))
8715                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8716             (widen))
8717         (setq ref
8718               ;; It's not the current article, so we take a bet on
8719               ;; the value we got from the server.
8720               (mail-header-references header)))
8721       (if (and ref
8722                (not (equal ref "")))
8723           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8724             (gnus-message 1 "Couldn't find parent"))
8725         (gnus-message 1 "No references in article %d"
8726                       (gnus-summary-article-number))
8727         (setq error t))
8728       (decf n))
8729     (gnus-summary-position-point)
8730     n))
8731
8732 (defun gnus-summary-refer-references ()
8733   "Fetch all articles mentioned in the References header.
8734 Return the number of articles fetched."
8735   (interactive)
8736   (let ((ref (mail-header-references (gnus-summary-article-header)))
8737         (current (gnus-summary-article-number))
8738         (n 0))
8739     (if (or (not ref)
8740             (equal ref ""))
8741         (error "No References in the current article")
8742       ;; For each Message-ID in the References header...
8743       (while (string-match "<[^>]*>" ref)
8744         (incf n)
8745         ;; ... fetch that article.
8746         (gnus-summary-refer-article
8747          (prog1 (match-string 0 ref)
8748            (setq ref (substring ref (match-end 0))))))
8749       (gnus-summary-goto-subject current)
8750       (gnus-summary-position-point)
8751       n)))
8752
8753 (defun gnus-summary-refer-thread (&optional limit)
8754   "Fetch all articles in the current thread.
8755 If LIMIT (the numerical prefix), fetch that many old headers instead
8756 of what's specified by the `gnus-refer-thread-limit' variable."
8757   (interactive "P")
8758   (let ((id (mail-header-id (gnus-summary-article-header)))
8759         (limit (if limit (prefix-numeric-value limit)
8760                  gnus-refer-thread-limit)))
8761     (unless (eq gnus-fetch-old-headers 'invisible)
8762       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8763       ;; Retrieve the headers and read them in.
8764       (if (eq (if (numberp limit)
8765                   (gnus-retrieve-headers
8766                    (list (min
8767                           (+ (mail-header-number
8768                               (gnus-summary-article-header))
8769                              limit)
8770                           gnus-newsgroup-end))
8771                    gnus-newsgroup-name (* limit 2))
8772                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8773                 ;; headers.
8774                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8775                                        gnus-newsgroup-name limit))
8776               'nov)
8777           (gnus-build-all-threads)
8778         (error "Can't fetch thread from back ends that don't support NOV"))
8779       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8780     (gnus-summary-limit-include-thread id)))
8781
8782 (defun gnus-summary-refer-article (message-id)
8783   "Fetch an article specified by MESSAGE-ID."
8784   (interactive "sMessage-ID: ")
8785   (when (and (stringp message-id)
8786              (not (zerop (length message-id))))
8787     (setq message-id (gnus-replace-in-string message-id " " ""))
8788     ;; Construct the correct Message-ID if necessary.
8789     ;; Suggested by tale@pawl.rpi.edu.
8790     (unless (string-match "^<" message-id)
8791       (setq message-id (concat "<" message-id)))
8792     (unless (string-match ">$" message-id)
8793       (setq message-id (concat message-id ">")))
8794     ;; People often post MIDs from URLs, so unhex it:
8795     (unless (string-match "@" message-id)
8796       (setq message-id (gnus-url-unhex-string message-id)))
8797     (let* ((header (gnus-id-to-header message-id))
8798            (sparse (and header
8799                         (gnus-summary-article-sparse-p
8800                          (mail-header-number header))
8801                         (memq (mail-header-number header)
8802                               gnus-newsgroup-limit)))
8803            number)
8804       (cond
8805        ;; If the article is present in the buffer we just go to it.
8806        ((and header
8807              (or (not (gnus-summary-article-sparse-p
8808                        (mail-header-number header)))
8809                  sparse))
8810         (prog1
8811             (gnus-summary-goto-article
8812              (mail-header-number header) nil t)
8813           (when sparse
8814             (gnus-summary-update-article (mail-header-number header)))))
8815        (t
8816         ;; We fetch the article.
8817         (catch 'found
8818           (dolist (gnus-override-method (gnus-refer-article-methods))
8819             (when (and (gnus-check-server gnus-override-method)
8820                        ;; Fetch the header,
8821                        (setq number (gnus-summary-insert-subject message-id)))
8822               ;; and display the article.
8823               (gnus-summary-select-article nil nil nil number)
8824               (throw 'found t)))
8825           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8826
8827 (defun gnus-refer-article-methods ()
8828   "Return a list of referable methods."
8829   (cond
8830    ;; No method, so we default to current and native.
8831    ((null gnus-refer-article-method)
8832     (list gnus-current-select-method gnus-select-method))
8833    ;; Current.
8834    ((eq 'current gnus-refer-article-method)
8835     (list gnus-current-select-method))
8836    ;; List of select methods.
8837    ((not (and (symbolp (car gnus-refer-article-method))
8838               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8839     (let (out)
8840       (dolist (method gnus-refer-article-method)
8841         (push (if (eq 'current method)
8842                   gnus-current-select-method
8843                 method)
8844               out))
8845       (nreverse out)))
8846    ;; One single select method.
8847    (t
8848     (list gnus-refer-article-method))))
8849
8850 (defun gnus-summary-edit-parameters ()
8851   "Edit the group parameters of the current group."
8852   (interactive)
8853   (gnus-group-edit-group gnus-newsgroup-name 'params))
8854
8855 (defun gnus-summary-customize-parameters ()
8856   "Customize the group parameters of the current group."
8857   (interactive)
8858   (gnus-group-customize gnus-newsgroup-name))
8859
8860 (defun gnus-summary-enter-digest-group (&optional force)
8861   "Enter an nndoc group based on the current article.
8862 If FORCE, force a digest interpretation.  If not, try
8863 to guess what the document format is."
8864   (interactive "P")
8865   (let ((conf gnus-current-window-configuration))
8866     (save-window-excursion
8867       (save-excursion
8868         (let (gnus-article-prepare-hook
8869               gnus-display-mime-function
8870               gnus-break-pages)
8871           (gnus-summary-select-article))))
8872     (setq gnus-current-window-configuration conf)
8873     (let* ((name (format "%s-%d"
8874                          (gnus-group-prefixed-name
8875                           gnus-newsgroup-name (list 'nndoc ""))
8876                          (with-current-buffer gnus-summary-buffer
8877                            gnus-current-article)))
8878            (ogroup gnus-newsgroup-name)
8879            (params (append (gnus-info-params (gnus-get-info ogroup))
8880                            (list (cons 'to-group ogroup))
8881                            (list (cons 'parent-group ogroup))
8882                            (list (cons 'save-article-group ogroup))))
8883            (case-fold-search t)
8884            (buf (current-buffer))
8885            dig to-address)
8886       (save-excursion
8887         (set-buffer gnus-original-article-buffer)
8888         ;; Have the digest group inherit the main mail address of
8889         ;; the parent article.
8890         (when (setq to-address (or (gnus-fetch-field "reply-to")
8891                                    (gnus-fetch-field "from")))
8892           (setq params
8893                 (append
8894                  (list (cons 'to-address
8895                              (funcall gnus-decode-encoded-address-function
8896                                       to-address))))))
8897         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8898         (insert-buffer-substring gnus-original-article-buffer)
8899         ;; Remove lines that may lead nndoc to misinterpret the
8900         ;; document type.
8901         (narrow-to-region
8902          (goto-char (point-min))
8903          (or (search-forward "\n\n" nil t) (point)))
8904         (goto-char (point-min))
8905         (delete-matching-lines "^Path:\\|^From ")
8906         (widen))
8907       (unwind-protect
8908           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8909                     (gnus-newsgroup-ephemeral-ignored-charsets
8910                      gnus-newsgroup-ignored-charsets))
8911                 (gnus-group-read-ephemeral-group
8912                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8913                               (nndoc-article-type
8914                                ,(if force 'mbox 'guess)))
8915                  t nil nil nil
8916                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8917                                                         "ADAPT")))))
8918               ;; Make all postings to this group go to the parent group.
8919               (nconc (gnus-info-params (gnus-get-info name))
8920                      params)
8921             ;; Couldn't select this doc group.
8922             (switch-to-buffer buf)
8923             (gnus-set-global-variables)
8924             (gnus-configure-windows 'summary)
8925             (gnus-message 3 "Article couldn't be entered?"))
8926         (kill-buffer dig)))))
8927
8928 (defun gnus-summary-read-document (n)
8929   "Open a new group based on the current article(s).
8930 This will allow you to read digests and other similar
8931 documents as newsgroups.
8932 Obeys the standard process/prefix convention."
8933   (interactive "P")
8934   (let* ((ogroup gnus-newsgroup-name)
8935          (params (append (gnus-info-params (gnus-get-info ogroup))
8936                          (list (cons 'to-group ogroup))))
8937          group egroup groups vgroup)
8938     (dolist (article (gnus-summary-work-articles n))
8939       (setq group (format "%s-%d" gnus-newsgroup-name article))
8940       (gnus-summary-remove-process-mark article)
8941       (when (gnus-summary-display-article article)
8942         (save-excursion
8943           (with-temp-buffer
8944             (insert-buffer-substring gnus-original-article-buffer)
8945             ;; Remove some headers that may lead nndoc to make
8946             ;; the wrong guess.
8947             (message-narrow-to-head)
8948             (goto-char (point-min))
8949             (delete-matching-lines "^Path:\\|^From ")
8950             (widen)
8951             (if (setq egroup
8952                       (gnus-group-read-ephemeral-group
8953                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8954                                      (nndoc-article-type guess))
8955                        t nil t))
8956                 (progn
8957             ;; Make all postings to this group go to the parent group.
8958                   (nconc (gnus-info-params (gnus-get-info egroup))
8959                          params)
8960                   (push egroup groups))
8961               ;; Couldn't select this doc group.
8962               (gnus-error 3 "Article couldn't be entered"))))))
8963     ;; Now we have selected all the documents.
8964     (cond
8965      ((not groups)
8966       (error "None of the articles could be interpreted as documents"))
8967      ((gnus-group-read-ephemeral-group
8968        (setq vgroup (format
8969                      "nnvirtual:%s-%s" gnus-newsgroup-name
8970                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8971        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8972        t
8973        (cons (current-buffer) 'summary)))
8974      (t
8975       (error "Couldn't select virtual nndoc group")))))
8976
8977 (defun gnus-summary-isearch-article (&optional regexp-p)
8978   "Do incremental search forward on the current article.
8979 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8980   (interactive "P")
8981   (gnus-summary-select-article)
8982   (gnus-configure-windows 'article)
8983   (gnus-eval-in-buffer-window gnus-article-buffer
8984     (save-restriction
8985       (widen)
8986       (isearch-forward regexp-p))))
8987
8988 (defun gnus-summary-repeat-search-article-forward ()
8989   "Repeat the previous search forwards."
8990   (interactive)
8991   (unless gnus-last-search-regexp
8992     (error "No previous search"))
8993   (gnus-summary-search-article-forward gnus-last-search-regexp))
8994
8995 (defun gnus-summary-repeat-search-article-backward ()
8996   "Repeat the previous search backwards."
8997   (interactive)
8998   (unless gnus-last-search-regexp
8999     (error "No previous search"))
9000   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9001
9002 (defun gnus-summary-search-article-forward (regexp &optional backward)
9003   "Search for an article containing REGEXP forward.
9004 If BACKWARD, search backward instead."
9005   (interactive
9006    (list (read-string
9007           (format "Search article %s (regexp%s): "
9008                   (if current-prefix-arg "backward" "forward")
9009                   (if gnus-last-search-regexp
9010                       (concat ", default " gnus-last-search-regexp)
9011                     "")))
9012          current-prefix-arg))
9013   (if (string-equal regexp "")
9014       (setq regexp (or gnus-last-search-regexp ""))
9015     (setq gnus-last-search-regexp regexp)
9016     (setq gnus-article-before-search gnus-current-article))
9017   ;; Intentionally set gnus-last-article.
9018   (setq gnus-last-article gnus-article-before-search)
9019   (let ((gnus-last-article gnus-last-article))
9020     (if (gnus-summary-search-article regexp backward)
9021         (gnus-summary-show-thread)
9022       (signal 'search-failed (list regexp)))))
9023
9024 (defun gnus-summary-search-article-backward (regexp)
9025   "Search for an article containing REGEXP backward."
9026   (interactive
9027    (list (read-string
9028           (format "Search article backward (regexp%s): "
9029                   (if gnus-last-search-regexp
9030                       (concat ", default " gnus-last-search-regexp)
9031                     "")))))
9032   (gnus-summary-search-article-forward regexp 'backward))
9033
9034 (defun gnus-summary-search-article (regexp &optional backward)
9035   "Search for an article containing REGEXP.
9036 Optional argument BACKWARD means do search for backward.
9037 `gnus-select-article-hook' is not called during the search."
9038   ;; We have to require this here to make sure that the following
9039   ;; dynamic binding isn't shadowed by autoloading.
9040   (require 'gnus-async)
9041   (require 'gnus-art)
9042   (let ((gnus-select-article-hook nil)  ;Disable hook.
9043         (gnus-article-prepare-hook nil)
9044         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9045         (gnus-use-article-prefetch nil)
9046         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9047         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9048         (gnus-visual nil)
9049         (gnus-keep-backlog nil)
9050         (gnus-break-pages nil)
9051         (gnus-summary-display-arrow nil)
9052         (gnus-updated-mode-lines nil)
9053         (gnus-auto-center-summary nil)
9054         (sum (current-buffer))
9055         (gnus-display-mime-function nil)
9056         (found nil)
9057         point)
9058     (gnus-save-hidden-threads
9059       (gnus-summary-select-article)
9060       (set-buffer gnus-article-buffer)
9061       (goto-char (window-point (get-buffer-window (current-buffer))))
9062       (when backward
9063         (forward-line -1))
9064       (while (not found)
9065         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9066         (if (if backward
9067                 (re-search-backward regexp nil t)
9068               (re-search-forward regexp nil t))
9069             ;; We found the regexp.
9070             (progn
9071               (setq found 'found)
9072               (beginning-of-line)
9073               (set-window-start
9074                (get-buffer-window (current-buffer))
9075                (point))
9076               (forward-line 1)
9077               (set-window-point
9078                (get-buffer-window (current-buffer))
9079                (point))
9080               (set-buffer sum)
9081               (setq point (point)))
9082           ;; We didn't find it, so we go to the next article.
9083           (set-buffer sum)
9084           (setq found 'not)
9085           (while (eq found 'not)
9086             (if (not (if backward (gnus-summary-find-prev)
9087                        (gnus-summary-find-next)))
9088                 ;; No more articles.
9089                 (setq found t)
9090               ;; Select the next article and adjust point.
9091               (unless (gnus-summary-article-sparse-p
9092                        (gnus-summary-article-number))
9093                 (setq found nil)
9094                 (gnus-summary-select-article)
9095                 (set-buffer gnus-article-buffer)
9096                 (widen)
9097                 (goto-char (if backward (point-max) (point-min))))))))
9098       (gnus-message 7 ""))
9099     ;; Return whether we found the regexp.
9100     (when (eq found 'found)
9101       (goto-char point)
9102       (gnus-summary-show-thread)
9103       (gnus-summary-goto-subject gnus-current-article)
9104       (gnus-summary-position-point)
9105       t)))
9106
9107 (defun gnus-find-matching-articles (header regexp)
9108   "Return a list of all articles that match REGEXP on HEADER.
9109 This search includes all articles in the current group that Gnus has
9110 fetched headers for, whether they are displayed or not."
9111   (let ((articles nil)
9112         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9113         (case-fold-search t))
9114     (dolist (header gnus-newsgroup-headers)
9115       (when (string-match regexp (funcall func header))
9116         (push (mail-header-number header) articles)))
9117     (nreverse articles)))
9118
9119 (defun gnus-summary-find-matching (header regexp &optional backward unread
9120                                           not-case-fold not-matching)
9121   "Return a list of all articles that match REGEXP on HEADER.
9122 The search stars on the current article and goes forwards unless
9123 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9124 If UNREAD is non-nil, only unread articles will
9125 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9126 in the comparisons. If NOT-MATCHING, return a list of all articles that
9127 not match REGEXP on HEADER."
9128   (let ((case-fold-search (not not-case-fold))
9129         articles d func)
9130     (if (consp header)
9131         (if (eq (car header) 'extra)
9132             (setq func
9133                   `(lambda (h)
9134                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9135                          "")))
9136           (error "%s is an invalid header" header))
9137       (unless (fboundp (intern (concat "mail-header-" header)))
9138         (error "%s is not a valid header" header))
9139       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9140     (dolist (d (if (eq backward 'all)
9141                    gnus-newsgroup-data
9142                  (gnus-data-find-list
9143                   (gnus-summary-article-number)
9144                   (gnus-data-list backward))))
9145       (when (and (or (not unread)       ; We want all articles...
9146                      (gnus-data-unread-p d)) ; Or just unreads.
9147                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9148                  (if not-matching
9149                      (not (string-match
9150                            regexp
9151                            (funcall func (gnus-data-header d))))
9152                    (string-match regexp
9153                                  (funcall func (gnus-data-header d)))))
9154         (push (gnus-data-number d) articles))) ; Success!
9155     (nreverse articles)))
9156
9157 (defun gnus-summary-execute-command (header regexp command &optional backward)
9158   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9159 If HEADER is an empty string (or nil), the match is done on the entire
9160 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9161   (interactive
9162    (list (let ((completion-ignore-case t))
9163            (completing-read
9164             "Header name: "
9165             (mapcar (lambda (header) (list (format "%s" header)))
9166                     (append
9167                      '("Number" "Subject" "From" "Lines" "Date"
9168                        "Message-ID" "Xref" "References" "Body")
9169                      gnus-extra-headers))
9170             nil 'require-match))
9171          (read-string "Regexp: ")
9172          (read-key-sequence "Command: ")
9173          current-prefix-arg))
9174   (when (equal header "Body")
9175     (setq header ""))
9176   ;; Hidden thread subtrees must be searched as well.
9177   (gnus-summary-show-all-threads)
9178   ;; We don't want to change current point nor window configuration.
9179   (save-excursion
9180     (save-window-excursion
9181       (let (gnus-visual
9182             gnus-treat-strip-trailing-blank-lines
9183             gnus-treat-strip-leading-blank-lines
9184             gnus-treat-strip-multiple-blank-lines
9185             gnus-treat-hide-boring-headers
9186             gnus-treat-fold-newsgroups
9187             gnus-article-prepare-hook)
9188         (gnus-message 6 "Executing %s..." (key-description command))
9189         ;; We'd like to execute COMMAND interactively so as to give arguments.
9190         (gnus-execute header regexp
9191                       `(call-interactively ',(key-binding command))
9192                       backward)
9193         (gnus-message 6 "Executing %s...done" (key-description command))))))
9194
9195 (defun gnus-summary-beginning-of-article ()
9196   "Scroll the article back to the beginning."
9197   (interactive)
9198   (gnus-summary-select-article)
9199   (gnus-configure-windows 'article)
9200   (gnus-eval-in-buffer-window gnus-article-buffer
9201     (widen)
9202     (goto-char (point-min))
9203     (when gnus-break-pages
9204       (gnus-narrow-to-page))))
9205
9206 (defun gnus-summary-end-of-article ()
9207   "Scroll to the end of the article."
9208   (interactive)
9209   (gnus-summary-select-article)
9210   (gnus-configure-windows 'article)
9211   (gnus-eval-in-buffer-window gnus-article-buffer
9212     (widen)
9213     (goto-char (point-max))
9214     (recenter -3)
9215     (when gnus-break-pages
9216       (when (re-search-backward page-delimiter nil t)
9217         (narrow-to-region (match-end 0) (point-max)))
9218       (gnus-narrow-to-page))))
9219
9220 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9221   "Truncate to LEN and quote all \"(\"'s in STRING."
9222   (gnus-replace-in-string (if (and len (> (length string) len))
9223                               (substring string 0 len)
9224                             string)
9225                           "[()]" "\\\\\\&"))
9226
9227 (defun gnus-summary-print-article (&optional filename n)
9228   "Generate and print a PostScript image of the process-marked (mail) articles.
9229
9230 If used interactively, print the current article if none are
9231 process-marked.  With prefix arg, prompt the user for the name of the
9232 file to save in.
9233
9234 When used from Lisp, accept two optional args FILENAME and N.  N means
9235 to print the next N articles.  If N is negative, print the N previous
9236 articles.  If N is nil and articles have been marked with the process
9237 mark, print these instead.
9238
9239 If the optional first argument FILENAME is nil, send the image to the
9240 printer.  If FILENAME is a string, save the PostScript image in a file with
9241 that name.  If FILENAME is a number, prompt the user for the name of the file
9242 to save in."
9243   (interactive (list (ps-print-preprint current-prefix-arg)))
9244   (dolist (article (gnus-summary-work-articles n))
9245     (gnus-summary-select-article nil nil 'pseudo article)
9246     (gnus-eval-in-buffer-window gnus-article-buffer
9247       (gnus-print-buffer))
9248     (gnus-summary-remove-process-mark article))
9249   (ps-despool filename))
9250
9251 (defun gnus-print-buffer ()
9252   (let ((buffer (generate-new-buffer " *print*")))
9253     (unwind-protect
9254         (progn
9255           (copy-to-buffer buffer (point-min) (point-max))
9256           (set-buffer buffer)
9257           (gnus-remove-text-with-property 'gnus-decoration)
9258           (when (gnus-visual-p 'article-highlight 'highlight)
9259             ;; Copy-to-buffer doesn't copy overlay.  So redo
9260             ;; highlight.
9261             (let ((gnus-article-buffer buffer))
9262               (gnus-article-highlight-citation t)
9263               (gnus-article-highlight-signature)
9264               (gnus-article-emphasize)
9265               (gnus-article-delete-invisible-text)))
9266           (let ((ps-left-header
9267                  (list
9268                   (concat "("
9269                           (gnus-summary-print-truncate-and-quote
9270                            (mail-header-subject gnus-current-headers)
9271                            66) ")")
9272                   (concat "("
9273                           (gnus-summary-print-truncate-and-quote
9274                            (mail-header-from gnus-current-headers)
9275                            45) ")")))
9276                 (ps-right-header
9277                  (list
9278                   "/pagenumberstring load"
9279                   (concat "("
9280                           (mail-header-date gnus-current-headers) ")"))))
9281             (gnus-run-hooks 'gnus-ps-print-hook)
9282             (save-excursion
9283               (if window-system
9284                   (ps-spool-buffer-with-faces)
9285                 (ps-spool-buffer)))))
9286       (kill-buffer buffer))))
9287
9288 (defun gnus-summary-show-article (&optional arg)
9289   "Force redisplaying of the current article.
9290 If ARG (the prefix) is a number, show the article with the charset
9291 defined in `gnus-summary-show-article-charset-alist', or the charset
9292 input.
9293 If ARG (the prefix) is non-nil and not a number, show the raw article
9294 without any article massaging functions being run.  Normally, the key
9295 strokes are `C-u g'."
9296   (interactive "P")
9297   (cond
9298    ((numberp arg)
9299     (gnus-summary-show-article t)
9300     (let ((gnus-newsgroup-charset
9301            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9302                (mm-read-coding-system
9303                 "View as charset: " ;; actually it is coding system.
9304                 (with-current-buffer gnus-article-buffer
9305                   (mm-detect-coding-region (point) (point-max))))))
9306           (gnus-newsgroup-ignored-charsets 'gnus-all))
9307       (gnus-summary-select-article nil 'force)
9308       (let ((deps gnus-newsgroup-dependencies)
9309             head header lines)
9310         (save-excursion
9311           (set-buffer gnus-original-article-buffer)
9312           (save-restriction
9313             (message-narrow-to-head)
9314             (setq head (buffer-string))
9315             (goto-char (point-min))
9316             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9317               (goto-char (point-max))
9318               (widen)
9319               (setq lines (1- (count-lines (point) (point-max))))))
9320           (with-temp-buffer
9321             (insert (format "211 %d Article retrieved.\n"
9322                             (cdr gnus-article-current)))
9323             (insert head)
9324             (if lines (insert (format "Lines: %d\n" lines)))
9325             (insert ".\n")
9326             (let ((nntp-server-buffer (current-buffer)))
9327               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9328         (gnus-data-set-header
9329          (gnus-data-find (cdr gnus-article-current))
9330          header)
9331         (gnus-summary-update-article-line
9332          (cdr gnus-article-current) header)
9333         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9334           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9335    ((not arg)
9336     ;; Select the article the normal way.
9337     (gnus-summary-select-article nil 'force))
9338    (t
9339     ;; We have to require this here to make sure that the following
9340     ;; dynamic binding isn't shadowed by autoloading.
9341     (require 'gnus-async)
9342     (require 'gnus-art)
9343     ;; Bind the article treatment functions to nil.
9344     (let ((gnus-have-all-headers t)
9345           gnus-article-prepare-hook
9346           gnus-article-decode-hook
9347           gnus-display-mime-function
9348           gnus-break-pages)
9349       ;; Destroy any MIME parts.
9350       (when (gnus-buffer-live-p gnus-article-buffer)
9351         (save-excursion
9352           (set-buffer gnus-article-buffer)
9353           (mm-destroy-parts gnus-article-mime-handles)
9354           ;; Set it to nil for safety reason.
9355           (setq gnus-article-mime-handle-alist nil)
9356           (setq gnus-article-mime-handles nil)))
9357       (gnus-summary-select-article nil 'force))))
9358   (gnus-summary-goto-subject gnus-current-article)
9359   (gnus-summary-position-point))
9360
9361 (defun gnus-summary-show-raw-article ()
9362   "Show the raw article without any article massaging functions being run."
9363   (interactive)
9364   (gnus-summary-show-article t))
9365
9366 (defun gnus-summary-verbose-headers (&optional arg)
9367   "Toggle permanent full header display.
9368 If ARG is a positive number, turn header display on.
9369 If ARG is a negative number, turn header display off."
9370   (interactive "P")
9371   (setq gnus-show-all-headers
9372         (cond ((or (not (numberp arg))
9373                    (zerop arg))
9374                (not gnus-show-all-headers))
9375               ((natnump arg)
9376                t)))
9377   (gnus-summary-show-article))
9378
9379 (defun gnus-summary-toggle-header (&optional arg)
9380   "Show the headers if they are hidden, or hide them if they are shown.
9381 If ARG is a positive number, show the entire header.
9382 If ARG is a negative number, hide the unwanted header lines."
9383   (interactive "P")
9384   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9385                      (get-buffer-window gnus-article-buffer t))))
9386     (with-current-buffer gnus-article-buffer
9387       (widen)
9388       (article-narrow-to-head)
9389       (let* ((buffer-read-only nil)
9390              (inhibit-point-motion-hooks t)
9391              (hidden (if (numberp arg)
9392                          (>= arg 0)
9393                        (or (not (looking-at "[^ \t\n]+:"))
9394                            (gnus-article-hidden-text-p 'headers))))
9395              s e)
9396         (delete-region (point-min) (point-max))
9397         (with-current-buffer gnus-original-article-buffer
9398           (goto-char (setq s (point-min)))
9399           (setq e (if (search-forward "\n\n" nil t)
9400                       (1- (point))
9401                     (point-max))))
9402         (insert-buffer-substring gnus-original-article-buffer s e)
9403         (run-hooks 'gnus-article-decode-hook)
9404         (if hidden
9405             (let ((gnus-treat-hide-headers nil)
9406                   (gnus-treat-hide-boring-headers nil))
9407               (gnus-delete-wash-type 'headers)
9408               (gnus-treat-article 'head))
9409           (gnus-treat-article 'head))
9410         (widen)
9411         (if window
9412             (set-window-start window (goto-char (point-min))))
9413         (if gnus-break-pages
9414             (gnus-narrow-to-page)
9415           (when (gnus-visual-p 'page-marker)
9416             (let ((buffer-read-only nil))
9417               (gnus-remove-text-with-property 'gnus-prev)
9418               (gnus-remove-text-with-property 'gnus-next))))
9419         (gnus-set-mode-line 'article)))))
9420
9421 (defun gnus-summary-show-all-headers ()
9422   "Make all header lines visible."
9423   (interactive)
9424   (gnus-summary-toggle-header 1))
9425
9426 (defun gnus-summary-caesar-message (&optional arg)
9427   "Caesar rotate the current article by 13.
9428 With a non-numerical prefix, also rotate headers.  A numerical
9429 prefix specifies how many places to rotate each letter forward."
9430   (interactive "P")
9431   (gnus-summary-select-article)
9432   (let ((mail-header-separator ""))
9433     (gnus-eval-in-buffer-window gnus-article-buffer
9434       (save-restriction
9435         (widen)
9436         (let ((start (window-start))
9437               buffer-read-only)
9438           (if (equal arg '(4))
9439               (message-caesar-buffer-body nil t)
9440             (message-caesar-buffer-body arg))
9441           (set-window-start (get-buffer-window (current-buffer)) start)))))
9442   ;; Create buttons and stuff...
9443   (gnus-treat-article nil))
9444
9445 (defun gnus-summary-idna-message (&optional arg)
9446   "Decode IDNA encoded domain names in the current articles.
9447 IDNA encoded domain names looks like `xn--bar'.  If a string
9448 remain unencoded after running this function, it is likely an
9449 invalid IDNA string (`xn--bar' is invalid).
9450
9451 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9452 installed for this command to work."
9453   (interactive "P")
9454   (if (not (and (condition-case nil (require 'idna)
9455                   (file-error))
9456                 (mm-coding-system-p 'utf-8)
9457                 (executable-find (symbol-value 'idna-program))))
9458       (gnus-message
9459        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9460     (gnus-summary-select-article)
9461     (let ((mail-header-separator ""))
9462       (gnus-eval-in-buffer-window gnus-article-buffer
9463         (save-restriction
9464           (widen)
9465           (let ((start (window-start))
9466                 buffer-read-only)
9467             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9468               (replace-match (idna-to-unicode (match-string 1))))
9469             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9470
9471 (defun gnus-summary-morse-message (&optional arg)
9472   "Morse decode the current article."
9473   (interactive "P")
9474   (gnus-summary-select-article)
9475   (let ((mail-header-separator ""))
9476     (gnus-eval-in-buffer-window gnus-article-buffer
9477       (save-excursion
9478         (save-restriction
9479           (widen)
9480           (let ((pos (window-start))
9481                 buffer-read-only)
9482             (goto-char (point-min))
9483             (when (message-goto-body)
9484               (gnus-narrow-to-body))
9485             (goto-char (point-min))
9486             (while (search-forward "·" (point-max) t)
9487               (replace-match "."))
9488             (unmorse-region (point-min) (point-max))
9489             (widen)
9490             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9491
9492 (defun gnus-summary-stop-page-breaking ()
9493   "Stop page breaking in the current article."
9494   (interactive)
9495   (gnus-summary-select-article)
9496   (gnus-eval-in-buffer-window gnus-article-buffer
9497     (widen)
9498     (when (gnus-visual-p 'page-marker)
9499       (let ((buffer-read-only nil))
9500         (gnus-remove-text-with-property 'gnus-prev)
9501         (gnus-remove-text-with-property 'gnus-next))
9502       (setq gnus-page-broken nil))))
9503
9504 (defun gnus-summary-move-article (&optional n to-newsgroup
9505                                             select-method action)
9506   "Move the current article to a different newsgroup.
9507 If N is a positive number, move the N next articles.
9508 If N is a negative number, move the N previous articles.
9509 If N is nil and any articles have been marked with the process mark,
9510 move those articles instead.
9511 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9512 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9513 re-spool using this method.
9514
9515 When called interactively with TO-NEWSGROUP being nil, the value of
9516 the variable `gnus-move-split-methods' is used for finding a default
9517 for the target newsgroup.
9518
9519 For this function to work, both the current newsgroup and the
9520 newsgroup that you want to move to have to support the `request-move'
9521 and `request-accept' functions.
9522
9523 ACTION can be either `move' (the default), `crosspost' or `copy'."
9524   (interactive "P")
9525   (unless action
9526     (setq action 'move))
9527   ;; Check whether the source group supports the required functions.
9528   (cond ((and (eq action 'move)
9529               (not (gnus-check-backend-function
9530                     'request-move-article gnus-newsgroup-name)))
9531          (error "The current group does not support article moving"))
9532         ((and (eq action 'crosspost)
9533               (not (gnus-check-backend-function
9534                     'request-replace-article gnus-newsgroup-name)))
9535          (error "The current group does not support article editing")))
9536   (let ((articles (gnus-summary-work-articles n))
9537         (prefix (if (gnus-check-backend-function
9538                      'request-move-article gnus-newsgroup-name)
9539                     (funcall gnus-move-group-prefix-function
9540                              gnus-newsgroup-name)
9541                   ""))
9542         (names '((move "Move" "Moving")
9543                  (copy "Copy" "Copying")
9544                  (crosspost "Crosspost" "Crossposting")))
9545         (copy-buf (save-excursion
9546                     (nnheader-set-temp-buffer " *copy article*")))
9547         art-group to-method new-xref article to-groups
9548         articles-to-update-marks encoded)
9549     (unless (assq action names)
9550       (error "Unknown action %s" action))
9551     ;; Read the newsgroup name.
9552     (when (and (not to-newsgroup)
9553                (not select-method))
9554       (if (and gnus-move-split-methods
9555                (not
9556                 (and (memq gnus-current-article articles)
9557                      (gnus-buffer-live-p gnus-original-article-buffer))))
9558           ;; When `gnus-move-split-methods' is non-nil, we have to
9559           ;; select an article to give `gnus-read-move-group-name' an
9560           ;; opportunity to suggest an appropriate default.  However,
9561           ;; we needn't render or mark the article.
9562           (let ((gnus-display-mime-function nil)
9563                 (gnus-article-prepare-hook nil)
9564                 (gnus-mark-article-hook nil))
9565             (gnus-summary-select-article nil nil nil (car articles))))
9566       (setq to-newsgroup (gnus-read-move-group-name
9567                           (cadr (assq action names))
9568                           (symbol-value
9569                            (intern (format "gnus-current-%s-group" action)))
9570                           articles prefix)
9571             encoded to-newsgroup
9572             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9573       (set (intern (format "gnus-current-%s-group" action))
9574            (mm-decode-coding-string
9575             to-newsgroup
9576             (gnus-group-name-charset to-method to-newsgroup))))
9577     (unless to-method
9578       (setq to-method (or select-method
9579                           (gnus-server-to-method
9580                            (gnus-group-method to-newsgroup)))))
9581     (setq to-newsgroup
9582           (or encoded
9583               (and to-newsgroup
9584                    (mm-encode-coding-string
9585                     to-newsgroup
9586                     (gnus-group-name-charset to-method to-newsgroup)))))
9587     ;; Check the method we are to move this article to...
9588     (unless (gnus-check-backend-function
9589              'request-accept-article (car to-method))
9590       (error "%s does not support article copying" (car to-method)))
9591     (unless (gnus-check-server to-method)
9592       (error "Can't open server %s" (car to-method)))
9593     (gnus-message 6 "%s to %s: %s..."
9594                   (caddr (assq action names))
9595                   (or (car select-method)
9596                       (gnus-group-decoded-name to-newsgroup))
9597                   articles)
9598     (while articles
9599       (setq article (pop articles))
9600       (setq
9601        art-group
9602        (cond
9603         ;; Move the article.
9604         ((eq action 'move)
9605          ;; Remove this article from future suppression.
9606          (gnus-dup-unsuppress-article article)
9607          (let* ((from-method (gnus-find-method-for-group
9608                               gnus-newsgroup-name))
9609                 (to-method (or select-method
9610                                (gnus-find-method-for-group to-newsgroup)))
9611                 (move-is-internal (gnus-method-equal from-method to-method)))
9612            (gnus-request-move-article
9613             article                     ; Article to move
9614             gnus-newsgroup-name         ; From newsgroup
9615             (nth 1 (gnus-find-method-for-group
9616                     gnus-newsgroup-name)) ; Server
9617             (list 'gnus-request-accept-article
9618                   to-newsgroup (list 'quote select-method)
9619                   (not articles) t)     ; Accept form
9620             (not articles)              ; Only save nov last time
9621             move-is-internal)))         ; is this move internal?
9622         ;; Copy the article.
9623         ((eq action 'copy)
9624          (save-excursion
9625            (set-buffer copy-buf)
9626            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9627              (save-restriction
9628                (nnheader-narrow-to-headers)
9629                (dolist (hdr gnus-copy-article-ignored-headers)
9630                  (message-remove-header hdr t)))
9631              (gnus-request-accept-article
9632               to-newsgroup select-method (not articles) t))))
9633         ;; Crosspost the article.
9634         ((eq action 'crosspost)
9635          (let ((xref (message-tokenize-header
9636                       (mail-header-xref (gnus-summary-article-header article))
9637                       " ")))
9638            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9639                                   ":" (number-to-string article)))
9640            (unless xref
9641              (setq xref (list (system-name))))
9642            (setq new-xref
9643                  (concat
9644                   (mapconcat 'identity
9645                              (delete "Xref:" (delete new-xref xref))
9646                              " ")
9647                   " " new-xref))
9648            (save-excursion
9649              (set-buffer copy-buf)
9650              ;; First put the article in the destination group.
9651              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9652              (when (consp (setq art-group
9653                                 (gnus-request-accept-article
9654                                  to-newsgroup select-method (not articles) t)))
9655                (setq new-xref (concat new-xref " " (car art-group)
9656                                       ":"
9657                                       (number-to-string (cdr art-group))))
9658                ;; Now we have the new Xrefs header, so we insert
9659                ;; it and replace the new article.
9660                (nnheader-replace-header "Xref" new-xref)
9661                (gnus-request-replace-article
9662                 (cdr art-group) to-newsgroup (current-buffer) t)
9663                art-group))))))
9664       (cond
9665        ((not art-group)
9666         (gnus-message 1 "Couldn't %s article %s: %s"
9667                       (cadr (assq action names)) article
9668                       (nnheader-get-report (car to-method))))
9669        ((eq art-group 'junk)
9670         (when (eq action 'move)
9671           (gnus-summary-mark-article article gnus-canceled-mark)
9672           (gnus-message 4 "Deleted article %s" article)
9673           ;; run the delete hook
9674           (run-hook-with-args 'gnus-summary-article-delete-hook
9675                               action
9676                               (gnus-data-header
9677                                (assoc article (gnus-data-list nil)))
9678                               gnus-newsgroup-name nil
9679                               select-method)))
9680        (t
9681         (let* ((pto-group (gnus-group-prefixed-name
9682                            (car art-group) to-method))
9683                (info (gnus-get-info pto-group))
9684                (to-group (gnus-info-group info))
9685                to-marks)
9686           ;; Update the group that has been moved to.
9687           (when (and info
9688                      (memq action '(move copy)))
9689             (unless (member to-group to-groups)
9690               (push to-group to-groups))
9691
9692             (unless (memq article gnus-newsgroup-unreads)
9693               (push 'read to-marks)
9694               (gnus-info-set-read
9695                info (gnus-add-to-range (gnus-info-read info)
9696                                        (list (cdr art-group)))))
9697
9698             ;; See whether the article is to be put in the cache.
9699             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9700                              gnus-article-mark-lists
9701                            (delete '(expirable . expire)
9702                                    (copy-sequence gnus-article-mark-lists))))
9703                   (to-article (cdr art-group)))
9704
9705               ;; Enter the article into the cache in the new group,
9706               ;; if that is required.
9707               (when gnus-use-cache
9708                 (gnus-cache-possibly-enter-article
9709                  to-group to-article
9710                  (memq article gnus-newsgroup-marked)
9711                  (memq article gnus-newsgroup-dormant)
9712                  (memq article gnus-newsgroup-unreads)))
9713
9714               (when gnus-preserve-marks
9715                 ;; Copy any marks over to the new group.
9716                 (when (and (equal to-group gnus-newsgroup-name)
9717                            (not (memq article gnus-newsgroup-unreads)))
9718                   ;; Mark this article as read in this group.
9719                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9720                   (setcdr (gnus-active to-group) to-article)
9721                   (setcdr gnus-newsgroup-active to-article))
9722
9723                 (while marks
9724                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9725                     (when (memq article (symbol-value
9726                                          (intern (format "gnus-newsgroup-%s"
9727                                                          (caar marks)))))
9728                       (push (cdar marks) to-marks)
9729                       ;; If the other group is the same as this group,
9730                       ;; then we have to add the mark to the list.
9731                       (when (equal to-group gnus-newsgroup-name)
9732                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9733                              (cons to-article
9734                                    (symbol-value
9735                                     (intern (format "gnus-newsgroup-%s"
9736                                                     (caar marks)))))))
9737                       ;; Copy the marks to other group.
9738                       (gnus-add-marked-articles
9739                        to-group (cdar marks) (list to-article) info)))
9740                   (setq marks (cdr marks)))
9741
9742                 (gnus-request-set-mark
9743                  to-group (list (list (list to-article) 'add to-marks))))
9744
9745               (gnus-dribble-enter
9746                (concat "(gnus-group-set-info '"
9747                        (gnus-prin1-to-string (gnus-get-info to-group))
9748                        ")"))))
9749
9750           ;; Update the Xref header in this article to point to
9751           ;; the new crossposted article we have just created.
9752           (when (eq action 'crosspost)
9753             (save-excursion
9754               (set-buffer copy-buf)
9755               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9756               (nnheader-replace-header "Xref" new-xref)
9757               (gnus-request-replace-article
9758                article gnus-newsgroup-name (current-buffer) t)))
9759
9760           ;; run the move/copy/crosspost/respool hook
9761           (run-hook-with-args 'gnus-summary-article-move-hook
9762                               action
9763                               (gnus-data-header
9764                                (assoc article (gnus-data-list nil)))
9765                               gnus-newsgroup-name
9766                               to-newsgroup
9767                               select-method))
9768
9769         ;;;!!!Why is this necessary?
9770         (set-buffer gnus-summary-buffer)
9771
9772         (gnus-summary-goto-subject article)
9773         (when (eq action 'move)
9774           (gnus-summary-mark-article article gnus-canceled-mark))))
9775       (push article articles-to-update-marks))
9776
9777     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9778     ;; Re-activate all groups that have been moved to.
9779     (save-excursion
9780       (set-buffer gnus-group-buffer)
9781       (let ((gnus-group-marked to-groups))
9782         (gnus-group-get-new-news-this-group nil t)))
9783
9784     (gnus-kill-buffer copy-buf)
9785     (gnus-summary-position-point)
9786     (gnus-set-mode-line 'summary)))
9787
9788 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9789   "Copy the current article to some other group.
9790 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9791 When called interactively, if TO-NEWSGROUP is nil, use the value of
9792 the variable `gnus-move-split-methods' for finding a default target
9793 newsgroup.
9794 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9795 re-spool using this method."
9796   (interactive "P")
9797   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9798
9799 (defun gnus-summary-crosspost-article (&optional n)
9800   "Crosspost the current article to some other group."
9801   (interactive "P")
9802   (gnus-summary-move-article n nil nil 'crosspost))
9803
9804 (defcustom gnus-summary-respool-default-method nil
9805   "Default method type for respooling an article.
9806 If nil, use to the current newsgroup method."
9807   :type 'symbol
9808   :group 'gnus-summary-mail)
9809
9810 (defcustom gnus-summary-display-while-building nil
9811   "If non-nil, show and update the summary buffer as it's being built.
9812 If the value is t, update the buffer after every line is inserted.  If
9813 the value is an integer (N), update the display every N lines."
9814   :version "22.1"
9815   :group 'gnus-thread
9816   :type '(choice (const :tag "off" nil)
9817                  number
9818                  (const :tag "frequently" t)))
9819
9820 (defun gnus-summary-respool-article (&optional n method)
9821   "Respool the current article.
9822 The article will be squeezed through the mail spooling process again,
9823 which means that it will be put in some mail newsgroup or other
9824 depending on `nnmail-split-methods'.
9825 If N is a positive number, respool the N next articles.
9826 If N is a negative number, respool the N previous articles.
9827 If N is nil and any articles have been marked with the process mark,
9828 respool those articles instead.
9829
9830 Respooling can be done both from mail groups and \"real\" newsgroups.
9831 In the former case, the articles in question will be moved from the
9832 current group into whatever groups they are destined to.  In the
9833 latter case, they will be copied into the relevant groups."
9834   (interactive
9835    (list current-prefix-arg
9836          (let* ((methods (gnus-methods-using 'respool))
9837                 (methname
9838                  (symbol-name (or gnus-summary-respool-default-method
9839                                   (car (gnus-find-method-for-group
9840                                         gnus-newsgroup-name)))))
9841                 (method
9842                  (gnus-completing-read-with-default
9843                   methname "Backend to use when respooling"
9844                   methods nil t nil 'gnus-mail-method-history))
9845                 ms)
9846            (cond
9847             ((zerop (length (setq ms (gnus-servers-using-backend
9848                                       (intern method)))))
9849              (list (intern method) ""))
9850             ((= 1 (length ms))
9851              (car ms))
9852             (t
9853              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9854                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9855                            ms-alist))))))))
9856   (unless method
9857     (error "No method given for respooling"))
9858   (if (assoc (symbol-name
9859               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9860              (gnus-methods-using 'respool))
9861       (gnus-summary-move-article n nil method)
9862     (gnus-summary-copy-article n nil method)))
9863
9864 (defun gnus-summary-import-article (file &optional edit)
9865   "Import an arbitrary file into a mail newsgroup."
9866   (interactive "fImport file: \nP")
9867   (let ((group gnus-newsgroup-name)
9868         (now (current-time))
9869         atts lines group-art)
9870     (unless (gnus-check-backend-function 'request-accept-article group)
9871       (error "%s does not support article importing" group))
9872     (or (file-readable-p file)
9873         (not (file-regular-p file))
9874         (error "Can't read %s" file))
9875     (save-excursion
9876       (set-buffer (gnus-get-buffer-create " *import file*"))
9877       (erase-buffer)
9878       (nnheader-insert-file-contents file)
9879       (goto-char (point-min))
9880       (if (nnheader-article-p)
9881           (save-restriction
9882             (goto-char (point-min))
9883             (search-forward "\n\n" nil t)
9884             (narrow-to-region (point-min) (1- (point)))
9885             (goto-char (point-min))
9886             (unless (re-search-forward "^date:" nil t)
9887               (goto-char (point-max))
9888               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9889        ;; This doesn't look like an article, so we fudge some headers.
9890         (setq atts (file-attributes file)
9891               lines (count-lines (point-min) (point-max)))
9892         (insert "From: " (read-string "From: ") "\n"
9893                 "Subject: " (read-string "Subject: ") "\n"
9894                 "Date: " (message-make-date (nth 5 atts)) "\n"
9895                 "Message-ID: " (message-make-message-id) "\n"
9896                 "Lines: " (int-to-string lines) "\n"
9897                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9898       (setq group-art (gnus-request-accept-article group nil t))
9899       (kill-buffer (current-buffer)))
9900     (setq gnus-newsgroup-active (gnus-activate-group group))
9901     (forward-line 1)
9902     (gnus-summary-goto-article (cdr group-art) nil t)
9903     (when edit
9904       (gnus-summary-edit-article))))
9905
9906 (defun gnus-summary-create-article ()
9907   "Create an article in a mail newsgroup."
9908   (interactive)
9909   (let ((group gnus-newsgroup-name)
9910         (now (current-time))
9911         group-art)
9912     (unless (gnus-check-backend-function 'request-accept-article group)
9913       (error "%s does not support article importing" group))
9914     (save-excursion
9915       (set-buffer (gnus-get-buffer-create " *import file*"))
9916       (erase-buffer)
9917       (goto-char (point-min))
9918       ;; This doesn't look like an article, so we fudge some headers.
9919       (insert "From: " (read-string "From: ") "\n"
9920               "Subject: " (read-string "Subject: ") "\n"
9921               "Date: " (message-make-date now) "\n"
9922               "Message-ID: " (message-make-message-id) "\n")
9923       (setq group-art (gnus-request-accept-article group nil t))
9924       (kill-buffer (current-buffer)))
9925     (setq gnus-newsgroup-active (gnus-activate-group group))
9926     (forward-line 1)
9927     (gnus-summary-goto-article (cdr group-art) nil t)
9928     (gnus-summary-edit-article)))
9929
9930 (defun gnus-summary-article-posted-p ()
9931   "Say whether the current (mail) article is available from news as well.
9932 This will be the case if the article has both been mailed and posted."
9933   (interactive)
9934   (let ((id (mail-header-references (gnus-summary-article-header)))
9935         (gnus-override-method (car (gnus-refer-article-methods))))
9936     (if (gnus-request-head id "")
9937         (gnus-message 2 "The current message was found on %s"
9938                       gnus-override-method)
9939       (gnus-message 2 "The current message couldn't be found on %s"
9940                     gnus-override-method)
9941       nil)))
9942
9943 (defun gnus-summary-expire-articles (&optional now)
9944   "Expire all articles that are marked as expirable in the current group."
9945   (interactive)
9946   (when (and (not gnus-group-is-exiting-without-update-p)
9947              (gnus-check-backend-function
9948               'request-expire-articles gnus-newsgroup-name))
9949     ;; This backend supports expiry.
9950     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9951            (expirable (if total
9952                           (progn
9953                             ;; We need to update the info for
9954                             ;; this group for `gnus-list-of-read-articles'
9955                             ;; to give us the right answer.
9956                             (gnus-run-hooks 'gnus-exit-group-hook)
9957                             (gnus-summary-update-info)
9958                             (gnus-list-of-read-articles gnus-newsgroup-name))
9959                         (setq gnus-newsgroup-expirable
9960                               (sort gnus-newsgroup-expirable '<))))
9961            (expiry-wait (if now 'immediate
9962                           (gnus-group-find-parameter
9963                            gnus-newsgroup-name 'expiry-wait)))
9964            (nnmail-expiry-target
9965             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9966                 nnmail-expiry-target))
9967            es)
9968       (when expirable
9969         ;; There are expirable articles in this group, so we run them
9970         ;; through the expiry process.
9971         (gnus-message 6 "Expiring articles...")
9972         (unless (gnus-check-group gnus-newsgroup-name)
9973           (error "Can't open server for %s" gnus-newsgroup-name))
9974         ;; The list of articles that weren't expired is returned.
9975         (save-excursion
9976           (if expiry-wait
9977               (let ((nnmail-expiry-wait-function nil)
9978                     (nnmail-expiry-wait expiry-wait))
9979                 (setq es (gnus-request-expire-articles
9980                           expirable gnus-newsgroup-name)))
9981             (setq es (gnus-request-expire-articles
9982                       expirable gnus-newsgroup-name)))
9983           (unless total
9984             (setq gnus-newsgroup-expirable es))
9985           ;; We go through the old list of expirable, and mark all
9986           ;; really expired articles as nonexistent.
9987           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9988             (let ((gnus-use-cache nil))
9989               (dolist (article expirable)
9990                 (when (and (not (memq article es))
9991                            (gnus-data-find article))
9992                   (gnus-summary-mark-article article gnus-canceled-mark)
9993                   (run-hook-with-args 'gnus-summary-article-expire-hook
9994                                       'delete
9995                                       (gnus-data-header
9996                                        (assoc article (gnus-data-list nil)))
9997                                       gnus-newsgroup-name
9998                                       nil
9999                                       nil))))))
10000         (gnus-message 6 "Expiring articles...done")))))
10001
10002 (defun gnus-summary-expire-articles-now ()
10003   "Expunge all expirable articles in the current group.
10004 This means that *all* articles that are marked as expirable will be
10005 deleted forever, right now."
10006   (interactive)
10007   (or gnus-expert-user
10008       (gnus-yes-or-no-p
10009        "Are you really, really sure you want to delete all expirable messages? ")
10010       (error "Phew!"))
10011   (gnus-summary-expire-articles t))
10012
10013 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10014 (defun gnus-summary-delete-article (&optional n)
10015   "Delete the N next (mail) articles.
10016 This command actually deletes articles.  This is not a marking
10017 command.  The article will disappear forever from your life, never to
10018 return.
10019
10020 If N is negative, delete backwards.
10021 If N is nil and articles have been marked with the process mark,
10022 delete these instead.
10023
10024 If `gnus-novice-user' is non-nil you will be asked for
10025 confirmation before the articles are deleted."
10026   (interactive "P")
10027   (unless (gnus-check-backend-function 'request-expire-articles
10028                                        gnus-newsgroup-name)
10029     (error "The current newsgroup does not support article deletion"))
10030   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10031     (error "Couldn't open server"))
10032   ;; Compute the list of articles to delete.
10033   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10034         (nnmail-expiry-target 'delete)
10035         not-deleted)
10036     (if (and gnus-novice-user
10037              (not (gnus-yes-or-no-p
10038                    (format "Do you really want to delete %s forever? "
10039                            (if (> (length articles) 1)
10040                                (format "these %s articles" (length articles))
10041                              "this article")))))
10042         ()
10043       ;; Delete the articles.
10044       (setq not-deleted (gnus-request-expire-articles
10045                          articles gnus-newsgroup-name 'force))
10046       (while articles
10047         (gnus-summary-remove-process-mark (car articles))
10048         ;; The backend might not have been able to delete the article
10049         ;; after all.
10050         (unless (memq (car articles) not-deleted)
10051           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10052         (let* ((article (car articles))
10053                (ghead  (gnus-data-header
10054                                     (assoc article (gnus-data-list nil)))))
10055           (run-hook-with-args 'gnus-summary-article-delete-hook
10056                               'delete ghead gnus-newsgroup-name nil
10057                               nil))
10058         (setq articles (cdr articles)))
10059       (when not-deleted
10060         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10061     (gnus-summary-position-point)
10062     (gnus-set-mode-line 'summary)
10063     not-deleted))
10064
10065 (defun gnus-summary-edit-article (&optional arg)
10066   "Edit the current article.
10067 This will have permanent effect only in mail groups.
10068 If ARG is nil, edit the decoded articles.
10069 If ARG is 1, edit the raw articles.
10070 If ARG is 2, edit the raw articles even in read-only groups.
10071 If ARG is 3, edit the articles with the current handles.
10072 Otherwise, allow editing of articles even in read-only
10073 groups."
10074   (interactive "P")
10075   (let (force raw current-handles)
10076     (cond
10077      ((null arg))
10078      ((eq arg 1)
10079       (setq raw t))
10080      ((eq arg 2)
10081       (setq raw t
10082             force t))
10083      ((eq arg 3)
10084       (setq current-handles
10085             (and (gnus-buffer-live-p gnus-article-buffer)
10086                  (with-current-buffer gnus-article-buffer
10087                    (prog1
10088                        gnus-article-mime-handles
10089                      (setq gnus-article-mime-handles nil))))))
10090      (t
10091       (setq force t)))
10092     (when (and raw (not force)
10093                (member gnus-newsgroup-name '("nndraft:delayed"
10094                                              "nndraft:drafts"
10095                                              "nndraft:queue")))
10096       (error "Can't edit the raw article in group %s"
10097              gnus-newsgroup-name))
10098     (save-excursion
10099       (set-buffer gnus-summary-buffer)
10100       (let ((mail-parse-charset gnus-newsgroup-charset)
10101             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10102         (gnus-set-global-variables)
10103         (when (and (not force)
10104                    (gnus-group-read-only-p))
10105           (error "The current newsgroup does not support article editing"))
10106         (gnus-summary-show-article t)
10107         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10108           (with-current-buffer gnus-article-buffer
10109             (mm-enable-multibyte)))
10110         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10111             (setq raw t))
10112         (gnus-article-edit-article
10113          (if raw 'ignore
10114            `(lambda ()
10115               (let ((mbl mml-buffer-list))
10116                 (setq mml-buffer-list nil)
10117                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10118                   (mime-to-mml ,'current-handles))
10119                 (let ((mbl1 mml-buffer-list))
10120                   (setq mml-buffer-list mbl)
10121                   (set (make-local-variable 'mml-buffer-list) mbl1))
10122                 (gnus-make-local-hook 'kill-buffer-hook)
10123                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10124          `(lambda (no-highlight)
10125             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10126                   (message-options message-options)
10127                   (message-options-set-recipient)
10128                   (mail-parse-ignored-charsets
10129                    ',gnus-newsgroup-ignored-charsets)
10130                   (rfc2047-header-encoding-alist
10131                    ',(let ((charset (gnus-group-name-charset
10132                                      (gnus-find-method-for-group
10133                                       gnus-newsgroup-name)
10134                                      gnus-newsgroup-name)))
10135                        (append (list (cons "Newsgroups" charset)
10136                                      (cons "Followup-To" charset)
10137                                      (cons "Xref" charset))
10138                                rfc2047-header-encoding-alist))))
10139               ,(if (not raw) '(progn
10140                                 (mml-to-mime)
10141                                 (mml-destroy-buffers)
10142                                 (remove-hook 'kill-buffer-hook
10143                                              'mml-destroy-buffers t)
10144                                 (kill-local-variable 'mml-buffer-list)))
10145               (gnus-summary-edit-article-done
10146                ,(or (mail-header-references gnus-current-headers) "")
10147                ,(gnus-group-read-only-p)
10148                ,gnus-summary-buffer no-highlight))))))))
10149
10150 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10151
10152 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10153                                                  no-highlight)
10154   "Make edits to the current article permanent."
10155   (interactive)
10156   (save-excursion
10157    ;; The buffer restriction contains the entire article if it exists.
10158     (when (article-goto-body)
10159       (let ((lines (count-lines (point) (point-max)))
10160             (length (- (point-max) (point)))
10161             (case-fold-search t)
10162             (body (copy-marker (point))))
10163         (goto-char (point-min))
10164         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10165           (delete-region (match-beginning 1) (match-end 1))
10166           (insert (number-to-string length)))
10167         (goto-char (point-min))
10168         (when (re-search-forward
10169                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10170           (delete-region (match-beginning 1) (match-end 1))
10171           (insert (number-to-string length)))
10172         (goto-char (point-min))
10173         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10174           (delete-region (match-beginning 1) (match-end 1))
10175           (insert (number-to-string lines))))))
10176   ;; Replace the article.
10177   (let ((buf (current-buffer)))
10178     (with-temp-buffer
10179       (insert-buffer-substring buf)
10180
10181       (if (and (not read-only)
10182                (not (gnus-request-replace-article
10183                      (cdr gnus-article-current) (car gnus-article-current)
10184                      (current-buffer) t)))
10185           (error "Couldn't replace article")
10186         ;; Update the summary buffer.
10187         (if (and references
10188                  (equal (message-tokenize-header references " ")
10189                         (message-tokenize-header
10190                          (or (message-fetch-field "references") "") " ")))
10191             ;; We only have to update this line.
10192             (save-excursion
10193               (save-restriction
10194                 (message-narrow-to-head)
10195                 (let ((head (buffer-substring-no-properties
10196                              (point-min) (point-max)))
10197                       header)
10198                   (with-temp-buffer
10199                     (insert (format "211 %d Article retrieved.\n"
10200                                     (cdr gnus-article-current)))
10201                     (insert head)
10202                     (insert ".\n")
10203                     (let ((nntp-server-buffer (current-buffer)))
10204                       (setq header (car (gnus-get-newsgroup-headers
10205                                          nil t))))
10206                     (save-excursion
10207                       (set-buffer gnus-summary-buffer)
10208                       (gnus-data-set-header
10209                        (gnus-data-find (cdr gnus-article-current))
10210                        header)
10211                       (gnus-summary-update-article-line
10212                        (cdr gnus-article-current) header)
10213                       (if (gnus-summary-goto-subject
10214                            (cdr gnus-article-current) nil t)
10215                           (gnus-summary-update-secondary-mark
10216                            (cdr gnus-article-current))))))))
10217           ;; Update threads.
10218           (set-buffer (or buffer gnus-summary-buffer))
10219           (gnus-summary-update-article (cdr gnus-article-current))
10220           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10221               (gnus-summary-update-secondary-mark
10222                (cdr gnus-article-current))))
10223         ;; Prettify the article buffer again.
10224         (unless no-highlight
10225           (save-excursion
10226             (set-buffer gnus-article-buffer)
10227             ;;;!!! Fix this -- article should be rehighlighted.
10228             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10229             (set-buffer gnus-original-article-buffer)
10230             (gnus-request-article
10231              (cdr gnus-article-current)
10232              (car gnus-article-current) (current-buffer))))
10233         ;; Prettify the summary buffer line.
10234         (when (gnus-visual-p 'summary-highlight 'highlight)
10235           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10236
10237 (defun gnus-summary-edit-wash (key)
10238   "Perform editing command KEY in the article buffer."
10239   (interactive
10240    (list
10241     (progn
10242       (message "%s" (concat (this-command-keys) "- "))
10243       (read-char))))
10244   (message "")
10245   (gnus-summary-edit-article)
10246   (execute-kbd-macro (concat (this-command-keys) key))
10247   (gnus-article-edit-done))
10248
10249 ;;; Respooling
10250
10251 (defun gnus-summary-respool-query (&optional silent trace)
10252   "Query where the respool algorithm would put this article."
10253   (interactive)
10254   (let (gnus-mark-article-hook)
10255     (gnus-summary-select-article)
10256     (save-excursion
10257       (set-buffer gnus-original-article-buffer)
10258       (let ((groups (nnmail-article-group 'identity trace)))
10259         (unless silent
10260           (if groups
10261               (message "This message would go to %s"
10262                        (mapconcat 'car groups ", "))
10263             (message "This message would go to no groups"))
10264           groups)))))
10265
10266 (defun gnus-summary-respool-trace ()
10267   "Trace where the respool algorithm would put this article.
10268 Display a buffer showing all fancy splitting patterns which matched."
10269   (interactive)
10270   (gnus-summary-respool-query nil t))
10271
10272 ;; Summary marking commands.
10273
10274 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10275   "Mark articles which has the same subject as read, and then select the next.
10276 If UNMARK is positive, remove any kind of mark.
10277 If UNMARK is negative, tick articles."
10278   (interactive "P")
10279   (when unmark
10280     (setq unmark (prefix-numeric-value unmark)))
10281   (let ((count
10282          (gnus-summary-mark-same-subject
10283           (gnus-summary-article-subject) unmark)))
10284     ;; Select next unread article.  If auto-select-same mode, should
10285     ;; select the first unread article.
10286     (gnus-summary-next-article t (and gnus-auto-select-same
10287                                       (gnus-summary-article-subject)))
10288     (gnus-message 7 "%d article%s marked as %s"
10289                   count (if (= count 1) " is" "s are")
10290                   (if unmark "unread" "read"))))
10291
10292 (defun gnus-summary-kill-same-subject (&optional unmark)
10293   "Mark articles which has the same subject as read.
10294 If UNMARK is positive, remove any kind of mark.
10295 If UNMARK is negative, tick articles."
10296   (interactive "P")
10297   (when unmark
10298     (setq unmark (prefix-numeric-value unmark)))
10299   (let ((count
10300          (gnus-summary-mark-same-subject
10301           (gnus-summary-article-subject) unmark)))
10302     ;; If marked as read, go to next unread subject.
10303     (when (null unmark)
10304       ;; Go to next unread subject.
10305       (gnus-summary-next-subject 1 t))
10306     (gnus-message 7 "%d articles are marked as %s"
10307                   count (if unmark "unread" "read"))))
10308
10309 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10310   "Mark articles with same SUBJECT as read, and return marked number.
10311 If optional argument UNMARK is positive, remove any kinds of marks.
10312 If optional argument UNMARK is negative, mark articles as unread instead."
10313   (let ((count 1))
10314     (save-excursion
10315       (cond
10316        ((null unmark)                   ; Mark as read.
10317         (while (and
10318                 (progn
10319                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10320                   (gnus-summary-show-thread) t)
10321                 (gnus-summary-find-subject subject))
10322           (setq count (1+ count))))
10323        ((> unmark 0)                    ; Tick.
10324         (while (and
10325                 (progn
10326                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10327                   (gnus-summary-show-thread) t)
10328                 (gnus-summary-find-subject subject))
10329           (setq count (1+ count))))
10330        (t                               ; Mark as unread.
10331         (while (and
10332                 (progn
10333                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10334                   (gnus-summary-show-thread) t)
10335                 (gnus-summary-find-subject subject))
10336           (setq count (1+ count)))))
10337       (gnus-set-mode-line 'summary)
10338       ;; Return the number of marked articles.
10339       count)))
10340
10341 (defun gnus-summary-mark-as-processable (n &optional unmark)
10342   "Set the process mark on the next N articles.
10343 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10344 the process mark instead.  The difference between N and the actual
10345 number of articles marked is returned."
10346   (interactive "P")
10347   (if (and (null n) (gnus-region-active-p))
10348       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10349     (setq n (prefix-numeric-value n))
10350     (let ((backward (< n 0))
10351           (n (abs n)))
10352       (while (and
10353               (> n 0)
10354               (if unmark
10355                   (gnus-summary-remove-process-mark
10356                    (gnus-summary-article-number))
10357                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10358               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10359         (setq n (1- n)))
10360       (when (/= 0 n)
10361         (gnus-message 7 "No more articles"))
10362       (gnus-summary-recenter)
10363       (gnus-summary-position-point)
10364       n)))
10365
10366 (defun gnus-summary-unmark-as-processable (n)
10367   "Remove the process mark from the next N articles.
10368 If N is negative, unmark backward instead.  The difference between N and
10369 the actual number of articles unmarked is returned."
10370   (interactive "P")
10371   (gnus-summary-mark-as-processable n t))
10372
10373 (defun gnus-summary-unmark-all-processable ()
10374   "Remove the process mark from all articles."
10375   (interactive)
10376   (save-excursion
10377     (while gnus-newsgroup-processable
10378       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10379   (gnus-summary-position-point))
10380
10381 (defun gnus-summary-add-mark (article type)
10382   "Mark ARTICLE with a mark of TYPE."
10383   (let ((vtype (car (assq type gnus-article-mark-lists)))
10384         var)
10385     (if (not vtype)
10386         (error "No such mark type: %s" type)
10387       (setq var (intern (format "gnus-newsgroup-%s" type)))
10388       (set var (cons article (symbol-value var)))
10389       (if (memq type '(processable cached replied forwarded recent saved))
10390           (gnus-summary-update-secondary-mark article)
10391         ;;; !!! This is bogus.  We should find out what primary
10392         ;;; !!! mark we want to set.
10393         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10394
10395 (defun gnus-summary-mark-as-expirable (n)
10396   "Mark N articles forward as expirable.
10397 If N is negative, mark backward instead.  The difference between N and
10398 the actual number of articles marked is returned."
10399   (interactive "p")
10400   (gnus-summary-mark-forward n gnus-expirable-mark))
10401
10402 (defun gnus-summary-mark-as-spam (n)
10403   "Mark N articles forward as spam.
10404 If N is negative, mark backward instead.  The difference between N and
10405 the actual number of articles marked is returned."
10406   (interactive "p")
10407   (gnus-summary-mark-forward n gnus-spam-mark))
10408
10409 (defun gnus-summary-mark-article-as-replied (article)
10410   "Mark ARTICLE as replied to and update the summary line.
10411 ARTICLE can also be a list of articles."
10412   (interactive (list (gnus-summary-article-number)))
10413   (let ((articles (if (listp article) article (list article))))
10414     (dolist (article articles)
10415       (unless (numberp article)
10416         (error "%s is not a number" article))
10417       (push article gnus-newsgroup-replied)
10418       (let ((buffer-read-only nil))
10419         (when (gnus-summary-goto-subject article nil t)
10420           (gnus-summary-update-secondary-mark article))))))
10421
10422 (defun gnus-summary-mark-article-as-forwarded (article)
10423   "Mark ARTICLE as forwarded and update the summary line.
10424 ARTICLE can also be a list of articles."
10425   (let ((articles (if (listp article) article (list article))))
10426     (dolist (article articles)
10427       (push article gnus-newsgroup-forwarded)
10428       (let ((buffer-read-only nil))
10429         (when (gnus-summary-goto-subject article nil t)
10430           (gnus-summary-update-secondary-mark article))))))
10431
10432 (defun gnus-summary-set-bookmark (article)
10433   "Set a bookmark in current article."
10434   (interactive (list (gnus-summary-article-number)))
10435   (when (or (not (get-buffer gnus-article-buffer))
10436             (not gnus-current-article)
10437             (not gnus-article-current)
10438             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10439     (error "No current article selected"))
10440   ;; Remove old bookmark, if one exists.
10441   (gnus-pull article gnus-newsgroup-bookmarks)
10442   ;; Set the new bookmark, which is on the form
10443   ;; (article-number . line-number-in-body).
10444   (push
10445    (cons article
10446          (with-current-buffer gnus-article-buffer
10447            (count-lines
10448             (min (point)
10449                  (save-excursion
10450                    (article-goto-body)
10451                    (point)))
10452             (point))))
10453    gnus-newsgroup-bookmarks)
10454   (gnus-message 6 "A bookmark has been added to the current article."))
10455
10456 (defun gnus-summary-remove-bookmark (article)
10457   "Remove the bookmark from the current article."
10458   (interactive (list (gnus-summary-article-number)))
10459   ;; Remove old bookmark, if one exists.
10460   (if (not (assq article gnus-newsgroup-bookmarks))
10461       (gnus-message 6 "No bookmark in current article.")
10462     (gnus-pull article gnus-newsgroup-bookmarks)
10463     (gnus-message 6 "Removed bookmark.")))
10464
10465 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10466 (defun gnus-summary-mark-as-dormant (n)
10467   "Mark N articles forward as dormant.
10468 If N is negative, mark backward instead.  The difference between N and
10469 the actual number of articles marked is returned."
10470   (interactive "p")
10471   (gnus-summary-mark-forward n gnus-dormant-mark))
10472
10473 (defun gnus-summary-set-process-mark (article)
10474   "Set the process mark on ARTICLE and update the summary line."
10475   (setq gnus-newsgroup-processable
10476         (cons article
10477               (delq article gnus-newsgroup-processable)))
10478   (when (gnus-summary-goto-subject article)
10479     (gnus-summary-show-thread)
10480     (gnus-summary-goto-subject article)
10481     (gnus-summary-update-secondary-mark article)))
10482
10483 (defun gnus-summary-remove-process-mark (&rest articles)
10484   "Remove the process mark from ARTICLES and update the summary line."
10485   (dolist (article articles)
10486     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10487     (when (gnus-summary-goto-subject article)
10488       (gnus-summary-show-thread)
10489       (gnus-summary-goto-subject article)
10490       (gnus-summary-update-secondary-mark article)))
10491   t)
10492
10493 (defun gnus-summary-set-saved-mark (article)
10494   "Set the process mark on ARTICLE and update the summary line."
10495   (push article gnus-newsgroup-saved)
10496   (when (gnus-summary-goto-subject article)
10497     (gnus-summary-update-secondary-mark article)))
10498
10499 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10500   "Mark N articles as read forwards.
10501 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10502 The difference between N and the actual number of articles marked is
10503 returned.
10504 If NO-EXPIRE, auto-expiry will be inhibited."
10505   (interactive "p")
10506   (gnus-summary-show-thread)
10507   (let ((backward (< n 0))
10508         (gnus-summary-goto-unread
10509          (and gnus-summary-goto-unread
10510               (not (eq gnus-summary-goto-unread 'never))
10511               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10512                                     gnus-ticked-mark gnus-dormant-mark)))))
10513         (n (abs n))
10514         (mark (or mark gnus-del-mark)))
10515     (while (and (> n 0)
10516                 (gnus-summary-mark-article nil mark no-expire)
10517                 (zerop (gnus-summary-next-subject
10518                         (if backward -1 1)
10519                         (and gnus-summary-goto-unread
10520                              (not (eq gnus-summary-goto-unread 'never)))
10521                         t)))
10522       (setq n (1- n)))
10523     (when (/= 0 n)
10524       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10525     (gnus-summary-recenter)
10526     (gnus-summary-position-point)
10527     (gnus-set-mode-line 'summary)
10528     n))
10529
10530 (defun gnus-summary-mark-article-as-read (mark)
10531   "Mark the current article quickly as read with MARK."
10532   (let ((article (gnus-summary-article-number)))
10533     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10534     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10535     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10536     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10537     (push (cons article mark) gnus-newsgroup-reads)
10538     ;; Possibly remove from cache, if that is used.
10539     (when gnus-use-cache
10540       (gnus-cache-enter-remove-article article))
10541     ;; Allow the backend to change the mark.
10542     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10543     ;; Check for auto-expiry.
10544     (when (and gnus-newsgroup-auto-expire
10545                (memq mark gnus-auto-expirable-marks))
10546       (setq mark gnus-expirable-mark)
10547       ;; Let the backend know about the mark change.
10548       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10549       (push article gnus-newsgroup-expirable))
10550     ;; Set the mark in the buffer.
10551     (gnus-summary-update-mark mark 'unread)
10552     t))
10553
10554 (defun gnus-summary-mark-article-as-unread (mark)
10555   "Mark the current article quickly as unread with MARK."
10556   (let* ((article (gnus-summary-article-number))
10557          (old-mark (gnus-summary-article-mark article)))
10558     ;; Allow the backend to change the mark.
10559     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10560     (if (eq mark old-mark)
10561         t
10562       (if (<= article 0)
10563           (progn
10564             (gnus-error 1 "Can't mark negative article numbers")
10565             nil)
10566         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10567         (setq gnus-newsgroup-spam-marked
10568               (delq article gnus-newsgroup-spam-marked))
10569         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10570         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10571         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10572         (cond ((= mark gnus-ticked-mark)
10573                (setq gnus-newsgroup-marked
10574                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10575                                               article)))
10576               ((= mark gnus-spam-mark)
10577                (setq gnus-newsgroup-spam-marked
10578                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10579                                               article)))
10580               ((= mark gnus-dormant-mark)
10581                (setq gnus-newsgroup-dormant
10582                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10583                                               article)))
10584               (t
10585                (setq gnus-newsgroup-unreads
10586                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10587                                               article))))
10588         (gnus-pull article gnus-newsgroup-reads)
10589
10590         ;; See whether the article is to be put in the cache.
10591         (and gnus-use-cache
10592              (vectorp (gnus-summary-article-header article))
10593              (save-excursion
10594                (gnus-cache-possibly-enter-article
10595                 gnus-newsgroup-name article
10596                 (= mark gnus-ticked-mark)
10597                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10598
10599         ;; Fix the mark.
10600         (gnus-summary-update-mark mark 'unread)
10601         t))))
10602
10603 (defun gnus-summary-mark-article (&optional article mark no-expire)
10604   "Mark ARTICLE with MARK.  MARK can be any character.
10605 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10606 `??' (dormant) and `?E' (expirable).
10607 If MARK is nil, then the default character `?r' is used.
10608 If ARTICLE is nil, then the article on the current line will be
10609 marked.
10610 If NO-EXPIRE, auto-expiry will be inhibited."
10611   ;; The mark might be a string.
10612   (when (stringp mark)
10613     (setq mark (aref mark 0)))
10614   ;; If no mark is given, then we check auto-expiring.
10615   (when (null mark)
10616     (setq mark gnus-del-mark))
10617   (when (and (not no-expire)
10618              gnus-newsgroup-auto-expire
10619              (memq mark gnus-auto-expirable-marks))
10620     (setq mark gnus-expirable-mark))
10621   (let ((article (or article (gnus-summary-article-number)))
10622         (old-mark (gnus-summary-article-mark article)))
10623     ;; Allow the backend to change the mark.
10624     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10625     (if (eq mark old-mark)
10626         t
10627       (unless article
10628         (error "No article on current line"))
10629       (if (not (if (or (= mark gnus-unread-mark)
10630                        (= mark gnus-ticked-mark)
10631                        (= mark gnus-spam-mark)
10632                        (= mark gnus-dormant-mark))
10633                    (gnus-mark-article-as-unread article mark)
10634                  (gnus-mark-article-as-read article mark)))
10635           t
10636         ;; See whether the article is to be put in the cache.
10637         (and gnus-use-cache
10638              (not (= mark gnus-canceled-mark))
10639              (vectorp (gnus-summary-article-header article))
10640              (save-excursion
10641                (gnus-cache-possibly-enter-article
10642                 gnus-newsgroup-name article
10643                 (= mark gnus-ticked-mark)
10644                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10645
10646         (when (gnus-summary-goto-subject article nil t)
10647           (let ((buffer-read-only nil))
10648             (gnus-summary-show-thread)
10649             ;; Fix the mark.
10650             (gnus-summary-update-mark mark 'unread)
10651             t))))))
10652
10653 (defun gnus-summary-update-secondary-mark (article)
10654   "Update the secondary (read, process, cache) mark."
10655   (gnus-summary-update-mark
10656    (cond ((memq article gnus-newsgroup-processable)
10657           gnus-process-mark)
10658          ((memq article gnus-newsgroup-cached)
10659           gnus-cached-mark)
10660          ((memq article gnus-newsgroup-replied)
10661           gnus-replied-mark)
10662          ((memq article gnus-newsgroup-forwarded)
10663           gnus-forwarded-mark)
10664          ((memq article gnus-newsgroup-saved)
10665           gnus-saved-mark)
10666          ((memq article gnus-newsgroup-recent)
10667           gnus-recent-mark)
10668          ((memq article gnus-newsgroup-unseen)
10669           gnus-unseen-mark)
10670          (t gnus-no-mark))
10671    'replied)
10672   (when (gnus-visual-p 'summary-highlight 'highlight)
10673     (gnus-run-hooks 'gnus-summary-update-hook))
10674   t)
10675
10676 (defun gnus-summary-update-download-mark (article)
10677   "Update the download mark."
10678   (gnus-summary-update-mark
10679    (cond ((memq article gnus-newsgroup-undownloaded)
10680           gnus-undownloaded-mark)
10681          (gnus-newsgroup-agentized
10682           gnus-downloaded-mark)
10683          (t
10684           gnus-no-mark))
10685    'download)
10686   (gnus-summary-update-line t)
10687   t)
10688
10689 (defun gnus-summary-update-mark (mark type)
10690   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10691         (buffer-read-only nil))
10692     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10693     (when forward
10694       (when (looking-at "\r")
10695         (incf forward))
10696       (when (<= (+ forward (point)) (point-max))
10697         ;; Go to the right position on the line.
10698         (goto-char (+ forward (point)))
10699         ;; Replace the old mark with the new mark.
10700         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10701         ;; Optionally update the marks by some user rule.
10702         (when (eq type 'unread)
10703           (gnus-data-set-mark
10704            (gnus-data-find (gnus-summary-article-number)) mark)
10705           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10706
10707 (defun gnus-mark-article-as-read (article &optional mark)
10708   "Enter ARTICLE in the pertinent lists and remove it from others."
10709   ;; Make the article expirable.
10710   (let ((mark (or mark gnus-del-mark)))
10711     (setq gnus-newsgroup-expirable
10712           (if (= mark gnus-expirable-mark)
10713               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10714             (delq article gnus-newsgroup-expirable)))
10715     ;; Remove from unread and marked lists.
10716     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10717     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10718     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10719     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10720     (push (cons article mark) gnus-newsgroup-reads)
10721     ;; Possibly remove from cache, if that is used.
10722     (when gnus-use-cache
10723       (gnus-cache-enter-remove-article article))
10724     t))
10725
10726 (defun gnus-mark-article-as-unread (article &optional mark)
10727   "Enter ARTICLE in the pertinent lists and remove it from others."
10728   (let ((mark (or mark gnus-ticked-mark)))
10729     (if (<= article 0)
10730         (progn
10731           (gnus-error 1 "Can't mark negative article numbers")
10732           nil)
10733       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10734             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10735             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10736             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10737             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10738
10739       ;; Unsuppress duplicates?
10740       (when gnus-suppress-duplicates
10741         (gnus-dup-unsuppress-article article))
10742
10743       (cond ((= mark gnus-ticked-mark)
10744              (setq gnus-newsgroup-marked
10745                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10746             ((= mark gnus-spam-mark)
10747              (setq gnus-newsgroup-spam-marked
10748                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10749                                             article)))
10750             ((= mark gnus-dormant-mark)
10751              (setq gnus-newsgroup-dormant
10752                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10753             (t
10754              (setq gnus-newsgroup-unreads
10755                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10756       (gnus-pull article gnus-newsgroup-reads)
10757       t)))
10758
10759 (defalias 'gnus-summary-mark-as-unread-forward
10760   'gnus-summary-tick-article-forward)
10761 (make-obsolete 'gnus-summary-mark-as-unread-forward
10762                'gnus-summary-tick-article-forward)
10763 (defun gnus-summary-tick-article-forward (n)
10764   "Tick N articles forwards.
10765 If N is negative, tick backwards instead.
10766 The difference between N and the number of articles ticked is returned."
10767   (interactive "p")
10768   (gnus-summary-mark-forward n gnus-ticked-mark))
10769
10770 (defalias 'gnus-summary-mark-as-unread-backward
10771   'gnus-summary-tick-article-backward)
10772 (make-obsolete 'gnus-summary-mark-as-unread-backward
10773                'gnus-summary-tick-article-backward)
10774 (defun gnus-summary-tick-article-backward (n)
10775   "Tick N articles backwards.
10776 The difference between N and the number of articles ticked is returned."
10777   (interactive "p")
10778   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10779
10780 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10781 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10782 (defun gnus-summary-tick-article (&optional article clear-mark)
10783   "Mark current article as unread.
10784 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10785 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10786   (interactive)
10787   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10788                                        gnus-ticked-mark)))
10789
10790 (defun gnus-summary-mark-as-read-forward (n)
10791   "Mark N articles as read forwards.
10792 If N is negative, mark backwards instead.
10793 The difference between N and the actual number of articles marked is
10794 returned."
10795   (interactive "p")
10796   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10797
10798 (defun gnus-summary-mark-as-read-backward (n)
10799   "Mark the N articles as read backwards.
10800 The difference between N and the actual number of articles marked is
10801 returned."
10802   (interactive "p")
10803   (gnus-summary-mark-forward
10804    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10805
10806 (defun gnus-summary-mark-as-read (&optional article mark)
10807   "Mark current article as read.
10808 ARTICLE specifies the article to be marked as read.
10809 MARK specifies a string to be inserted at the beginning of the line."
10810   (gnus-summary-mark-article article mark))
10811
10812 (defun gnus-summary-clear-mark-forward (n)
10813   "Clear marks from N articles forward.
10814 If N is negative, clear backward instead.
10815 The difference between N and the number of marks cleared is returned."
10816   (interactive "p")
10817   (gnus-summary-mark-forward n gnus-unread-mark))
10818
10819 (defun gnus-summary-clear-mark-backward (n)
10820   "Clear marks from N articles backward.
10821 The difference between N and the number of marks cleared is returned."
10822   (interactive "p")
10823   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10824
10825 (defun gnus-summary-mark-unread-as-read ()
10826   "Intended to be used by `gnus-summary-mark-article-hook'."
10827   (when (memq gnus-current-article gnus-newsgroup-unreads)
10828     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10829
10830 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10831   "Intended to be used by `gnus-summary-mark-article-hook'."
10832   (let ((mark (gnus-summary-article-mark)))
10833     (when (or (gnus-unread-mark-p mark)
10834               (gnus-read-mark-p mark))
10835       (gnus-summary-mark-article gnus-current-article
10836                                  (or new-mark gnus-read-mark)))))
10837
10838 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10839   "Intended to be used by `gnus-summary-mark-article-hook'."
10840   (let ((mark (gnus-summary-article-mark)))
10841     (when (or (gnus-unread-mark-p mark)
10842               (gnus-read-mark-p mark))
10843       (gnus-summary-mark-article (gnus-summary-article-number)
10844                                  (or new-mark gnus-read-mark)))))
10845
10846 (defun gnus-summary-mark-unread-as-ticked ()
10847   "Intended to be used by `gnus-summary-mark-article-hook'."
10848   (when (memq gnus-current-article gnus-newsgroup-unreads)
10849     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10850
10851 (defun gnus-summary-mark-region-as-read (point mark all)
10852   "Mark all unread articles between point and mark as read.
10853 If given a prefix, mark all articles between point and mark as read,
10854 even ticked and dormant ones."
10855   (interactive "r\nP")
10856   (save-excursion
10857     (let (article)
10858       (goto-char point)
10859       (beginning-of-line)
10860       (while (and
10861               (< (point) mark)
10862               (progn
10863                 (when (or all
10864                           (memq (setq article (gnus-summary-article-number))
10865                                 gnus-newsgroup-unreads))
10866                   (gnus-summary-mark-article article gnus-del-mark))
10867                 t)
10868               (gnus-summary-find-next))))))
10869
10870 (defun gnus-summary-mark-below (score mark)
10871   "Mark articles with score less than SCORE with MARK."
10872   (interactive "P\ncMark: ")
10873   (setq score (if score
10874                   (prefix-numeric-value score)
10875                 (or gnus-summary-default-score 0)))
10876   (save-excursion
10877     (set-buffer gnus-summary-buffer)
10878     (goto-char (point-min))
10879     (while
10880         (progn
10881           (and (< (gnus-summary-article-score) score)
10882                (gnus-summary-mark-article nil mark))
10883           (gnus-summary-find-next)))))
10884
10885 (defun gnus-summary-kill-below (&optional score)
10886   "Mark articles with score below SCORE as read."
10887   (interactive "P")
10888   (gnus-summary-mark-below score gnus-killed-mark))
10889
10890 (defun gnus-summary-clear-above (&optional score)
10891   "Clear all marks from articles with score above SCORE."
10892   (interactive "P")
10893   (gnus-summary-mark-above score gnus-unread-mark))
10894
10895 (defun gnus-summary-tick-above (&optional score)
10896   "Tick all articles with score above SCORE."
10897   (interactive "P")
10898   (gnus-summary-mark-above score gnus-ticked-mark))
10899
10900 (defun gnus-summary-mark-above (score mark)
10901   "Mark articles with score over SCORE with MARK."
10902   (interactive "P\ncMark: ")
10903   (setq score (if score
10904                   (prefix-numeric-value score)
10905                 (or gnus-summary-default-score 0)))
10906   (save-excursion
10907     (set-buffer gnus-summary-buffer)
10908     (goto-char (point-min))
10909     (while (and (progn
10910                   (when (> (gnus-summary-article-score) score)
10911                     (gnus-summary-mark-article nil mark))
10912                   t)
10913                 (gnus-summary-find-next)))))
10914
10915 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10916 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10917 (defun gnus-summary-limit-include-expunged (&optional no-error)
10918   "Display all the hidden articles that were expunged for low scores."
10919   (interactive)
10920   (let ((buffer-read-only nil))
10921     (let ((scored gnus-newsgroup-scored)
10922           headers h)
10923       (while scored
10924         (unless (gnus-summary-article-header (caar scored))
10925           (and (setq h (gnus-number-to-header (caar scored)))
10926                (< (cdar scored) gnus-summary-expunge-below)
10927                (push h headers)))
10928         (setq scored (cdr scored)))
10929       (if (not headers)
10930           (when (not no-error)
10931             (error "No expunged articles hidden"))
10932         (goto-char (point-min))
10933         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10934         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10935         (mapcar (lambda (x) (push (mail-header-number x)
10936                                   gnus-newsgroup-limit))
10937                 headers)
10938         (gnus-summary-prepare-unthreaded (nreverse headers))
10939         (goto-char (point-min))
10940         (gnus-summary-position-point)
10941         t))))
10942
10943 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10944   "Mark all unread articles in this newsgroup as read.
10945 If prefix argument ALL is non-nil, ticked and dormant articles will
10946 also be marked as read.
10947 If QUIETLY is non-nil, no questions will be asked.
10948
10949 If TO-HERE is non-nil, it should be a point in the buffer.  All
10950 articles before (after, if REVERSE is set) this point will be marked
10951 as read.
10952
10953 Note that this function will only catch up the unread article
10954 in the current summary buffer limitation.
10955
10956 The number of articles marked as read is returned."
10957   (interactive "P")
10958   (prog1
10959       (save-excursion
10960         (when (or quietly
10961                   (not gnus-interactive-catchup) ;Without confirmation?
10962                   gnus-expert-user
10963                   (gnus-y-or-n-p
10964                    (if all
10965                        "Mark absolutely all articles as read? "
10966                      "Mark all unread articles as read? ")))
10967           (if (and not-mark
10968                    (not gnus-newsgroup-adaptive)
10969                    (not gnus-newsgroup-auto-expire)
10970                    (not gnus-suppress-duplicates)
10971                    (or (not gnus-use-cache)
10972                        (eq gnus-use-cache 'passive)))
10973               (progn
10974                 (when all
10975                   (setq gnus-newsgroup-marked nil
10976                         gnus-newsgroup-spam-marked nil
10977                         gnus-newsgroup-dormant nil))
10978                 (setq gnus-newsgroup-unreads
10979                       (gnus-sorted-nunion
10980                        (gnus-sorted-intersection gnus-newsgroup-unreads
10981                                                  gnus-newsgroup-downloadable)
10982                        (gnus-sorted-difference gnus-newsgroup-unfetched
10983                                                gnus-newsgroup-cached))))
10984             ;; We actually mark all articles as canceled, which we
10985             ;; have to do when using auto-expiry or adaptive scoring.
10986             (gnus-summary-show-all-threads)
10987             (if (and to-here reverse)
10988                 (progn
10989                   (goto-char to-here)
10990                   (gnus-summary-mark-current-read-and-unread-as-read
10991                    gnus-catchup-mark)
10992                   (while (gnus-summary-find-next (not all))
10993                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10994               (when (gnus-summary-first-subject (not all))
10995                 (while (and
10996                         (if to-here (< (point) to-here) t)
10997                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10998                         (gnus-summary-find-next (not all))))))
10999             (gnus-set-mode-line 'summary))
11000           t))
11001     (gnus-summary-position-point)))
11002
11003 (defun gnus-summary-catchup-to-here (&optional all)
11004   "Mark all unticked articles before the current one as read.
11005 If ALL is non-nil, also mark ticked and dormant articles as read."
11006   (interactive "P")
11007   (save-excursion
11008     (gnus-save-hidden-threads
11009       (let ((beg (point)))
11010         ;; We check that there are unread articles.
11011         (when (or all (gnus-summary-find-prev))
11012           (gnus-summary-catchup all t beg)))))
11013   (gnus-summary-position-point))
11014
11015 (defun gnus-summary-catchup-from-here (&optional all)
11016   "Mark all unticked articles after (and including) the current one as read.
11017 If ALL is non-nil, also mark ticked and dormant articles as read."
11018   (interactive "P")
11019   (save-excursion
11020     (gnus-save-hidden-threads
11021       (let ((beg (point)))
11022         ;; We check that there are unread articles.
11023         (when (or all (gnus-summary-find-next))
11024           (gnus-summary-catchup all t beg nil t)))))
11025   (gnus-summary-position-point))
11026
11027 (defun gnus-summary-catchup-all (&optional quietly)
11028   "Mark all articles in this newsgroup as read.
11029 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11030 instead, which marks only unread articles as read."
11031   (interactive "P")
11032   (gnus-summary-catchup t quietly))
11033
11034 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11035   "Mark all unread articles in this group as read, then exit.
11036 If prefix argument ALL is non-nil, all articles are marked as read.
11037 If QUIETLY is non-nil, no questions will be asked."
11038   (interactive "P")
11039   (when (gnus-summary-catchup all quietly nil 'fast)
11040     ;; Select next newsgroup or exit.
11041     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11042              (eq gnus-auto-select-next 'quietly))
11043         (gnus-summary-next-group nil)
11044       (gnus-summary-exit))))
11045
11046 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11047   "Mark all articles in this newsgroup as read, and then exit.
11048 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11049 instead, which marks only unread articles as read."
11050   (interactive "P")
11051   (gnus-summary-catchup-and-exit t quietly))
11052
11053 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11054   "Mark all articles in this group as read and select the next group.
11055 If given a prefix, mark all articles, unread as well as ticked, as
11056 read."
11057   (interactive "P")
11058   (save-excursion
11059     (gnus-summary-catchup all))
11060   (gnus-summary-next-group))
11061
11062 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11063   "Mark all articles in this group as read and select the previous group.
11064 If given a prefix, mark all articles, unread as well as ticked, as
11065 read."
11066   (interactive "P")
11067   (save-excursion
11068     (gnus-summary-catchup all))
11069   (gnus-summary-next-group nil nil t))
11070
11071 ;;;
11072 ;;; with article
11073 ;;;
11074
11075 (defmacro gnus-with-article (article &rest forms)
11076   "Select ARTICLE and perform FORMS in the original article buffer.
11077 Then replace the article with the result."
11078   `(progn
11079      ;; We don't want the article to be marked as read.
11080      (let (gnus-mark-article-hook)
11081        (gnus-summary-select-article t t nil ,article))
11082      (set-buffer gnus-original-article-buffer)
11083      ,@forms
11084      (if (not (gnus-check-backend-function
11085                'request-replace-article (car gnus-article-current)))
11086          (gnus-message 5 "Read-only group; not replacing")
11087        (unless (gnus-request-replace-article
11088                 ,article (car gnus-article-current)
11089                 (current-buffer) t)
11090          (error "Couldn't replace article")))
11091      ;; The cache and backlog have to be flushed somewhat.
11092      (when gnus-keep-backlog
11093        (gnus-backlog-remove-article
11094         (car gnus-article-current) (cdr gnus-article-current)))
11095      (when gnus-use-cache
11096        (gnus-cache-update-article
11097         (car gnus-article-current) (cdr gnus-article-current)))))
11098
11099 (put 'gnus-with-article 'lisp-indent-function 1)
11100 (put 'gnus-with-article 'edebug-form-spec '(form body))
11101
11102 ;; Thread-based commands.
11103
11104 (defun gnus-summary-articles-in-thread (&optional article)
11105   "Return a list of all articles in the current thread.
11106 If ARTICLE is non-nil, return all articles in the thread that starts
11107 with that article."
11108   (let* ((article (or article (gnus-summary-article-number)))
11109          (data (gnus-data-find-list article))
11110          (top-level (gnus-data-level (car data)))
11111          (top-subject
11112           (cond ((null gnus-thread-operation-ignore-subject)
11113                  (gnus-simplify-subject-re
11114                   (mail-header-subject (gnus-data-header (car data)))))
11115                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11116                  (gnus-simplify-subject-fuzzy
11117                   (mail-header-subject (gnus-data-header (car data)))))
11118                 (t nil)))
11119          (end-point (save-excursion
11120                       (if (gnus-summary-go-to-next-thread)
11121                           (point) (point-max))))
11122          articles)
11123     (while (and data
11124                 (< (gnus-data-pos (car data)) end-point))
11125       (when (or (not top-subject)
11126                 (string= top-subject
11127                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11128                              (gnus-simplify-subject-fuzzy
11129                               (mail-header-subject
11130                                (gnus-data-header (car data))))
11131                            (gnus-simplify-subject-re
11132                             (mail-header-subject
11133                              (gnus-data-header (car data)))))))
11134         (push (gnus-data-number (car data)) articles))
11135       (unless (and (setq data (cdr data))
11136                    (> (gnus-data-level (car data)) top-level))
11137         (setq data nil)))
11138     ;; Return the list of articles.
11139     (nreverse articles)))
11140
11141 (defun gnus-summary-rethread-current ()
11142   "Rethread the thread the current article is part of."
11143   (interactive)
11144   (let* ((gnus-show-threads t)
11145          (article (gnus-summary-article-number))
11146          (id (mail-header-id (gnus-summary-article-header)))
11147          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11148     (unless id
11149       (error "No article on the current line"))
11150     (gnus-rebuild-thread id)
11151     (gnus-summary-goto-subject article)))
11152
11153 (defun gnus-summary-reparent-thread ()
11154   "Make the current article child of the marked (or previous) article.
11155
11156 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11157 is non-nil or the Subject: of both articles are the same."
11158   (interactive)
11159   (unless (not (gnus-group-read-only-p))
11160     (error "The current newsgroup does not support article editing"))
11161   (unless (<= (length gnus-newsgroup-processable) 1)
11162     (error "No more than one article may be marked"))
11163   (let ((child (gnus-summary-article-number))
11164         ;; First grab the marked article, otherwise one line up.
11165         (parent (if (not (null gnus-newsgroup-processable))
11166                     (car gnus-newsgroup-processable)
11167                   (save-excursion
11168                     (if (eq (forward-line -1) 0)
11169                         (gnus-summary-article-number)
11170                       (error "Beginning of summary buffer"))))))
11171     (gnus-summary-reparent-children parent (list child))))
11172
11173 (defun gnus-summary-reparent-children (parent children)
11174   "Make PARENT the parent of CHILDREN.
11175 When called interactively, PARENT is the current article and CHILDREN
11176 are the process-marked articles."
11177   (interactive
11178    (list (gnus-summary-article-number)
11179          (gnus-summary-work-articles nil)))
11180   (dolist (child children)
11181     (save-window-excursion
11182       (let ((gnus-article-buffer " *reparent*"))
11183         (unless (not (eq parent child))
11184           (error "An article may not be self-referential"))
11185         (let ((message-id (mail-header-id
11186                            (gnus-summary-article-header parent))))
11187           (unless (and message-id (not (equal message-id "")))
11188             (error "No message-id in desired parent"))
11189           (gnus-with-article child
11190             (save-restriction
11191               (goto-char (point-min))
11192               (message-narrow-to-head)
11193               (if (re-search-forward "^References: " nil t)
11194                   (progn
11195                     (re-search-forward "^[^ \t]" nil t)
11196                     (forward-line -1)
11197                     (end-of-line)
11198                     (insert " " message-id))
11199                 (insert "References: " message-id "\n"))))
11200           (set-buffer gnus-summary-buffer)
11201           (gnus-summary-unmark-all-processable)
11202           (gnus-summary-update-article child)
11203           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11204             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11205           (gnus-summary-rethread-current)
11206           (gnus-message 3 "Article %d is now the child of article %d"
11207                         child parent))))))
11208
11209 (defun gnus-summary-toggle-threads (&optional arg)
11210   "Toggle showing conversation threads.
11211 If ARG is positive number, turn showing conversation threads on."
11212   (interactive "P")
11213   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11214     (setq gnus-show-threads
11215           (if (null arg) (not gnus-show-threads)
11216             (> (prefix-numeric-value arg) 0)))
11217     (gnus-summary-prepare)
11218     (gnus-summary-goto-subject current)
11219     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11220     (gnus-summary-position-point)))
11221
11222 (defun gnus-summary-show-all-threads ()
11223   "Show all threads."
11224   (interactive)
11225   (save-excursion
11226     (let ((buffer-read-only nil))
11227       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11228   (gnus-summary-position-point))
11229
11230 (defun gnus-summary-show-thread ()
11231   "Show thread subtrees.
11232 Returns nil if no thread was there to be shown."
11233   (interactive)
11234   (let ((buffer-read-only nil)
11235         (orig (point))
11236         (end (point-at-eol))
11237         ;; Leave point at bol
11238         (beg (progn (beginning-of-line) (point))))
11239     (prog1
11240         ;; Any hidden lines here?
11241         (search-forward "\r" end t)
11242       (subst-char-in-region beg end ?\^M ?\n t)
11243       (goto-char orig)
11244       (gnus-summary-position-point))))
11245
11246 (defun gnus-summary-maybe-hide-threads ()
11247   "If requested, hide the threads that should be hidden."
11248   (when (and gnus-show-threads
11249              gnus-thread-hide-subtree)
11250     (gnus-summary-hide-all-threads
11251      (if (or (consp gnus-thread-hide-subtree)
11252              (functionp gnus-thread-hide-subtree))
11253          (gnus-make-predicate gnus-thread-hide-subtree)
11254        nil))))
11255
11256 ;;; Hiding predicates.
11257
11258 (defun gnus-article-unread-p (header)
11259   (memq (mail-header-number header) gnus-newsgroup-unreads))
11260
11261 (defun gnus-article-unseen-p (header)
11262   (memq (mail-header-number header) gnus-newsgroup-unseen))
11263
11264 (defun gnus-map-articles (predicate articles)
11265   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11266   (apply 'gnus-or (mapcar predicate
11267                           (mapcar (lambda (number)
11268                                     (gnus-summary-article-header number))
11269                                   articles))))
11270
11271 (defun gnus-summary-hide-all-threads (&optional predicate)
11272   "Hide all thread subtrees.
11273 If PREDICATE is supplied, threads that satisfy this predicate
11274 will not be hidden."
11275   (interactive)
11276   (save-excursion
11277     (goto-char (point-min))
11278     (let ((end nil))
11279       (while (not end)
11280         (when (or (not predicate)
11281                   (gnus-map-articles
11282                    predicate (gnus-summary-article-children)))
11283             (gnus-summary-hide-thread))
11284         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11285   (gnus-summary-position-point))
11286
11287 (defun gnus-summary-hide-thread ()
11288   "Hide thread subtrees.
11289 If PREDICATE is supplied, threads that satisfy this predicate
11290 will not be hidden.
11291 Returns nil if no threads were there to be hidden."
11292   (interactive)
11293   (let ((buffer-read-only nil)
11294         (start (point))
11295         (article (gnus-summary-article-number)))
11296     (goto-char start)
11297     ;; Go forward until either the buffer ends or the subthread
11298     ;; ends.
11299     (when (and (not (eobp))
11300                (or (zerop (gnus-summary-next-thread 1 t))
11301                    (goto-char (point-max))))
11302       (prog1
11303           (if (and (> (point) start)
11304                    (search-backward "\n" start t))
11305               (progn
11306                 (subst-char-in-region start (point) ?\n ?\^M)
11307                 (gnus-summary-goto-subject article))
11308             (goto-char start)
11309             nil)))))
11310
11311 (defun gnus-summary-go-to-next-thread (&optional previous)
11312   "Go to the same level (or less) next thread.
11313 If PREVIOUS is non-nil, go to previous thread instead.
11314 Return the article number moved to, or nil if moving was impossible."
11315   (let ((level (gnus-summary-thread-level))
11316         (way (if previous -1 1))
11317         (beg (point)))
11318     (forward-line way)
11319     (while (and (not (eobp))
11320                 (< level (gnus-summary-thread-level)))
11321       (forward-line way))
11322     (if (eobp)
11323         (progn
11324           (goto-char beg)
11325           nil)
11326       (setq beg (point))
11327       (prog1
11328           (gnus-summary-article-number)
11329         (goto-char beg)))))
11330
11331 (defun gnus-summary-next-thread (n &optional silent)
11332   "Go to the same level next N'th thread.
11333 If N is negative, search backward instead.
11334 Returns the difference between N and the number of skips actually
11335 done.
11336
11337 If SILENT, don't output messages."
11338   (interactive "p")
11339   (let ((backward (< n 0))
11340         (n (abs n)))
11341     (while (and (> n 0)
11342                 (gnus-summary-go-to-next-thread backward))
11343       (decf n))
11344     (unless silent
11345       (gnus-summary-position-point))
11346     (when (and (not silent) (/= 0 n))
11347       (gnus-message 7 "No more threads"))
11348     n))
11349
11350 (defun gnus-summary-prev-thread (n)
11351   "Go to the same level previous N'th thread.
11352 Returns the difference between N and the number of skips actually
11353 done."
11354   (interactive "p")
11355   (gnus-summary-next-thread (- n)))
11356
11357 (defun gnus-summary-go-down-thread ()
11358   "Go down one level in the current thread."
11359   (let ((children (gnus-summary-article-children)))
11360     (when children
11361       (gnus-summary-goto-subject (car children)))))
11362
11363 (defun gnus-summary-go-up-thread ()
11364   "Go up one level in the current thread."
11365   (let ((parent (gnus-summary-article-parent)))
11366     (when parent
11367       (gnus-summary-goto-subject parent))))
11368
11369 (defun gnus-summary-down-thread (n)
11370   "Go down thread N steps.
11371 If N is negative, go up instead.
11372 Returns the difference between N and how many steps down that were
11373 taken."
11374   (interactive "p")
11375   (let ((up (< n 0))
11376         (n (abs n)))
11377     (while (and (> n 0)
11378                 (if up (gnus-summary-go-up-thread)
11379                   (gnus-summary-go-down-thread)))
11380       (setq n (1- n)))
11381     (gnus-summary-position-point)
11382     (when (/= 0 n)
11383       (gnus-message 7 "Can't go further"))
11384     n))
11385
11386 (defun gnus-summary-up-thread (n)
11387   "Go up thread N steps.
11388 If N is negative, go down instead.
11389 Returns the difference between N and how many steps down that were
11390 taken."
11391   (interactive "p")
11392   (gnus-summary-down-thread (- n)))
11393
11394 (defun gnus-summary-top-thread ()
11395   "Go to the top of the thread."
11396   (interactive)
11397   (while (gnus-summary-go-up-thread))
11398   (gnus-summary-article-number))
11399
11400 (defun gnus-summary-expire-thread ()
11401   "Mark articles under current thread as expired."
11402   (interactive)
11403   (gnus-summary-kill-thread 0))
11404
11405 (defun gnus-summary-kill-thread (&optional unmark)
11406   "Mark articles under current thread as read.
11407 If the prefix argument is positive, remove any kinds of marks.
11408 If the prefix argument is zero, mark thread as expired.
11409 If the prefix argument is negative, tick articles instead."
11410   (interactive "P")
11411   (when unmark
11412     (setq unmark (prefix-numeric-value unmark)))
11413   (let ((articles (gnus-summary-articles-in-thread))
11414         (hide (or (null unmark) (= unmark 0))))
11415     (save-excursion
11416       ;; Expand the thread.
11417       (gnus-summary-show-thread)
11418       ;; Mark all the articles.
11419       (while articles
11420         (gnus-summary-goto-subject (car articles))
11421         (cond ((null unmark)
11422                (gnus-summary-mark-article-as-read gnus-killed-mark))
11423               ((> unmark 0)
11424                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11425               ((= unmark 0)
11426                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11427               (t
11428                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11429         (setq articles (cdr articles))))
11430     ;; Hide killed subtrees when hide is true.
11431     (and hide
11432          gnus-thread-hide-killed
11433          (gnus-summary-hide-thread))
11434     ;; If hide is t, go to next unread subject.
11435     (when hide
11436       ;; Go to next unread subject.
11437       (gnus-summary-next-subject 1 t)))
11438   (gnus-set-mode-line 'summary))
11439
11440 ;; Summary sorting commands
11441
11442 (defun gnus-summary-sort-by-number (&optional reverse)
11443   "Sort the summary buffer by article number.
11444 Argument REVERSE means reverse order."
11445   (interactive "P")
11446   (gnus-summary-sort 'number reverse))
11447
11448 (defun gnus-summary-sort-by-random (&optional reverse)
11449   "Randomize the order in the summary buffer.
11450 Argument REVERSE means to randomize in reverse order."
11451   (interactive "P")
11452   (gnus-summary-sort 'random reverse))
11453
11454 (defun gnus-summary-sort-by-author (&optional reverse)
11455   "Sort the summary buffer by author name alphabetically.
11456 If `case-fold-search' is non-nil, case of letters is ignored.
11457 Argument REVERSE means reverse order."
11458   (interactive "P")
11459   (gnus-summary-sort 'author reverse))
11460
11461 (defun gnus-summary-sort-by-recipient (&optional reverse)
11462   "Sort the summary buffer by recipient name alphabetically.
11463 If `case-fold-search' is non-nil, case of letters is ignored.
11464 Argument REVERSE means reverse order."
11465   (interactive "P")
11466   (gnus-summary-sort 'recipient reverse))
11467
11468 (defun gnus-summary-sort-by-subject (&optional reverse)
11469   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11470 If `case-fold-search' is non-nil, case of letters is ignored.
11471 Argument REVERSE means reverse order."
11472   (interactive "P")
11473   (gnus-summary-sort 'subject reverse))
11474
11475 (defun gnus-summary-sort-by-date (&optional reverse)
11476   "Sort the summary buffer by date.
11477 Argument REVERSE means reverse order."
11478   (interactive "P")
11479   (gnus-summary-sort 'date reverse))
11480
11481 (defun gnus-summary-sort-by-score (&optional reverse)
11482   "Sort the summary buffer by score.
11483 Argument REVERSE means reverse order."
11484   (interactive "P")
11485   (gnus-summary-sort 'score reverse))
11486
11487 (defun gnus-summary-sort-by-lines (&optional reverse)
11488   "Sort the summary buffer by the number of lines.
11489 Argument REVERSE means reverse order."
11490   (interactive "P")
11491   (gnus-summary-sort 'lines reverse))
11492
11493 (defun gnus-summary-sort-by-chars (&optional reverse)
11494   "Sort the summary buffer by article length.
11495 Argument REVERSE means reverse order."
11496   (interactive "P")
11497   (gnus-summary-sort 'chars reverse))
11498
11499 (defun gnus-summary-sort-by-original (&optional reverse)
11500   "Sort the summary buffer using the default sorting method.
11501 Argument REVERSE means reverse order."
11502   (interactive "P")
11503   (let* ((buffer-read-only)
11504          (gnus-summary-prepare-hook nil))
11505     ;; We do the sorting by regenerating the threads.
11506     (gnus-summary-prepare)
11507     ;; Hide subthreads if needed.
11508     (gnus-summary-maybe-hide-threads)))
11509
11510 (defun gnus-summary-sort (predicate reverse)
11511   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11512   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11513          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11514          (gnus-thread-sort-functions
11515           (if (not reverse)
11516               thread
11517             `(lambda (t1 t2)
11518                (,thread t2 t1))))
11519          (gnus-sort-gathered-threads-function
11520           gnus-thread-sort-functions)
11521          (gnus-article-sort-functions
11522           (if (not reverse)
11523               article
11524             `(lambda (t1 t2)
11525                (,article t2 t1))))
11526          (buffer-read-only)
11527          (gnus-summary-prepare-hook nil))
11528     ;; We do the sorting by regenerating the threads.
11529     (gnus-summary-prepare)
11530     ;; Hide subthreads if needed.
11531     (gnus-summary-maybe-hide-threads)))
11532
11533 ;; Summary saving commands.
11534
11535 (defun gnus-summary-save-article (&optional n not-saved)
11536   "Save the current article using the default saver function.
11537 If N is a positive number, save the N next articles.
11538 If N is a negative number, save the N previous articles.
11539 If N is nil and any articles have been marked with the process mark,
11540 save those articles instead.
11541 The variable `gnus-default-article-saver' specifies the saver function.
11542
11543 If the optional second argument NOT-SAVED is non-nil, articles saved
11544 will not be marked as saved."
11545   (interactive "P")
11546   (require 'gnus-art)
11547   (let* ((articles (gnus-summary-work-articles n))
11548          (save-buffer (save-excursion
11549                         (nnheader-set-temp-buffer " *Gnus Save*")))
11550          (num (length articles))
11551          ;; Whether to save decoded articles or raw articles.
11552          (decode (when gnus-article-save-coding-system
11553                    (get gnus-default-article-saver :decode)))
11554          ;; When saving many articles in a single file, use the other
11555          ;; function to save articles other than the first one.
11556          (saver2 (get gnus-default-article-saver :function))
11557          (gnus-prompt-before-saving (if saver2
11558                                         t
11559                                       gnus-prompt-before-saving))
11560          (gnus-default-article-saver gnus-default-article-saver)
11561          header file)
11562     (dolist (article articles)
11563       (setq header (gnus-summary-article-header article))
11564       (if (not (vectorp header))
11565           ;; This is a pseudo-article.
11566           (if (assq 'name header)
11567               (gnus-copy-file (cdr (assq 'name header)))
11568             (gnus-message 1 "Article %d is unsaveable" article))
11569         ;; This is a real article.
11570         (save-window-excursion
11571           (let ((gnus-display-mime-function (when decode
11572                                               gnus-display-mime-function))
11573                 (gnus-article-prepare-hook (when decode
11574                                              gnus-article-prepare-hook)))
11575             (gnus-summary-select-article t nil nil article)
11576             (gnus-summary-goto-subject article)))
11577         (save-excursion
11578           (set-buffer save-buffer)
11579           (erase-buffer)
11580           (insert-buffer-substring (if decode
11581                                        gnus-article-buffer
11582                                      gnus-original-article-buffer)))
11583         (setq file (gnus-article-save save-buffer file num))
11584         (gnus-summary-remove-process-mark article)
11585         (unless not-saved
11586           (gnus-summary-set-saved-mark article)))
11587       (when saver2
11588         (setq gnus-default-article-saver saver2
11589               saver2 nil)))
11590     (gnus-kill-buffer save-buffer)
11591     (gnus-summary-position-point)
11592     (gnus-set-mode-line 'summary)
11593     n))
11594
11595 (defun gnus-summary-pipe-output (&optional arg headers)
11596   "Pipe the current article to a subprocess.
11597 If N is a positive number, pipe the N next articles.
11598 If N is a negative number, pipe the N previous articles.
11599 If N is nil and any articles have been marked with the process mark,
11600 pipe those articles instead.
11601 If HEADERS (the symbolic prefix), include the headers, too."
11602   (interactive (gnus-interactive "P\ny"))
11603   (require 'gnus-art)
11604   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11605         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11606     (gnus-summary-save-article arg t))
11607   (let ((buffer (get-buffer "*Shell Command Output*")))
11608     (when (and buffer
11609                (not (zerop (buffer-size buffer))))
11610       (gnus-configure-windows 'pipe))))
11611
11612 (defun gnus-summary-save-article-mail (&optional arg)
11613   "Append the current article to a Unix mail box file.
11614 If N is a positive number, save the N next articles.
11615 If N is a negative number, save the N previous articles.
11616 If N is nil and any articles have been marked with the process mark,
11617 save those articles instead."
11618   (interactive "P")
11619   (require 'gnus-art)
11620   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11621     (gnus-summary-save-article arg)))
11622
11623 (defun gnus-summary-save-article-rmail (&optional arg)
11624   "Append the current article to an rmail file.
11625 If N is a positive number, save the N next articles.
11626 If N is a negative number, save the N previous articles.
11627 If N is nil and any articles have been marked with the process mark,
11628 save those articles instead."
11629   (interactive "P")
11630   (require 'gnus-art)
11631   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11632     (gnus-summary-save-article arg)))
11633
11634 (defun gnus-summary-save-article-file (&optional arg)
11635   "Append the current article to a file.
11636 If N is a positive number, save the N next articles.
11637 If N is a negative number, save the N previous articles.
11638 If N is nil and any articles have been marked with the process mark,
11639 save those articles instead."
11640   (interactive "P")
11641   (require 'gnus-art)
11642   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11643     (gnus-summary-save-article arg)))
11644
11645 (defun gnus-summary-write-article-file (&optional arg)
11646   "Write the current article to a file, deleting the previous file.
11647 If N is a positive number, save the N next articles.
11648 If N is a negative number, save the N previous articles.
11649 If N is nil and any articles have been marked with the process mark,
11650 save those articles instead."
11651   (interactive "P")
11652   (require 'gnus-art)
11653   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11654     (gnus-summary-save-article arg)))
11655
11656 (defun gnus-summary-save-article-body-file (&optional arg)
11657   "Append the current article body to a file.
11658 If N is a positive number, save the N next articles.
11659 If N is a negative number, save the N previous articles.
11660 If N is nil and any articles have been marked with the process mark,
11661 save those articles instead."
11662   (interactive "P")
11663   (require 'gnus-art)
11664   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11665     (gnus-summary-save-article arg)))
11666
11667 (defun gnus-summary-write-article-body-file (&optional arg)
11668   "Write the current article body to a file, deleting the previous file.
11669 If N is a positive number, save the N next articles.
11670 If N is a negative number, save the N previous articles.
11671 If N is nil and any articles have been marked with the process mark,
11672 save those articles instead."
11673   (interactive "P")
11674   (require 'gnus-art)
11675   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11676     (gnus-summary-save-article arg)))
11677
11678 (defun gnus-summary-muttprint (&optional arg)
11679   "Print the current article using Muttprint.
11680 If N is a positive number, save the N next articles.
11681 If N is a negative number, save the N previous articles.
11682 If N is nil and any articles have been marked with the process mark,
11683 save those articles instead."
11684   (interactive "P")
11685   (require 'gnus-art)
11686   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11687     (gnus-summary-save-article arg t)))
11688
11689 (defun gnus-summary-pipe-message (program)
11690   "Pipe the current article through PROGRAM."
11691   (interactive "sProgram: ")
11692   (gnus-summary-select-article)
11693   (let ((mail-header-separator ""))
11694     (gnus-eval-in-buffer-window gnus-article-buffer
11695       (save-restriction
11696         (widen)
11697         (let ((start (window-start))
11698               buffer-read-only)
11699           (message-pipe-buffer-body program)
11700           (set-window-start (get-buffer-window (current-buffer)) start))))))
11701
11702 (defun gnus-get-split-value (methods)
11703   "Return a value based on the split METHODS."
11704   (let (split-name method result match)
11705     (when methods
11706       (save-excursion
11707         (set-buffer gnus-original-article-buffer)
11708         (save-restriction
11709           (nnheader-narrow-to-headers)
11710           (while (and methods (not split-name))
11711             (goto-char (point-min))
11712             (setq method (pop methods))
11713             (setq match (car method))
11714             (when (cond
11715                    ((stringp match)
11716                     ;; Regular expression.
11717                     (ignore-errors
11718                       (re-search-forward match nil t)))
11719                    ((functionp match)
11720                     ;; Function.
11721                     (save-restriction
11722                       (widen)
11723                       (setq result (funcall match gnus-newsgroup-name))))
11724                    ((consp match)
11725                     ;; Form.
11726                     (save-restriction
11727                       (widen)
11728                       (setq result (eval match)))))
11729               (setq split-name (cdr method))
11730               (cond ((stringp result)
11731                      (push (expand-file-name
11732                             result gnus-article-save-directory)
11733                            split-name))
11734                     ((consp result)
11735                      (setq split-name (append result split-name)))))))))
11736     (nreverse split-name)))
11737
11738 (defun gnus-valid-move-group-p (group)
11739   (and (boundp group)
11740        (symbol-name group)
11741        (symbol-value group)
11742        (gnus-get-function (gnus-find-method-for-group
11743                            (symbol-name group)) 'request-accept-article t)))
11744
11745 (defun gnus-read-move-group-name (prompt default articles prefix)
11746   "Read a group name."
11747   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11748          (minibuffer-confirm-incomplete nil) ; XEmacs
11749          (prom
11750           (format "%s %s to"
11751                   prompt
11752                   (if (> (length articles) 1)
11753                       (format "these %d articles" (length articles))
11754                     "this article")))
11755          (to-newsgroup
11756           (let (active group)
11757             (when (or (null split-name) (= 1 (length split-name)))
11758               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11759               (mapatoms (lambda (symbol)
11760                           (setq group (symbol-name symbol))
11761                           (when (string-match "[^\000-\177]" group)
11762                             (setq group (gnus-group-decoded-name group)))
11763                           (set (intern group active) group))
11764                         gnus-active-hashtb))
11765             (cond
11766              ((null split-name)
11767               (gnus-completing-read-with-default
11768                default prom active 'gnus-valid-move-group-p nil prefix
11769                'gnus-group-history))
11770              ((= 1 (length split-name))
11771               (gnus-completing-read-with-default
11772                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11773                'gnus-group-history))
11774              (t
11775               (gnus-completing-read-with-default
11776                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11777                'gnus-group-history)))))
11778          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11779          encoded)
11780     (when to-newsgroup
11781       (if (or (string= to-newsgroup "")
11782               (string= to-newsgroup prefix))
11783           (setq to-newsgroup default))
11784       (unless to-newsgroup
11785         (error "No group name entered"))
11786       (setq encoded (mm-encode-coding-string
11787                      to-newsgroup
11788                      (gnus-group-name-charset to-method to-newsgroup)))
11789       (or (gnus-active encoded)
11790           (gnus-activate-group encoded nil nil to-method)
11791           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11792                                      to-newsgroup))
11793               (or (and (gnus-request-create-group encoded to-method)
11794                        (gnus-activate-group encoded nil nil to-method)
11795                        (gnus-subscribe-group encoded))
11796                   (error "Couldn't create group %s" to-newsgroup)))
11797           (error "No such group: %s" to-newsgroup))
11798       encoded)))
11799
11800 (defvar gnus-summary-save-parts-counter)
11801
11802 (defun gnus-summary-save-parts (type dir n &optional reverse)
11803   "Save parts matching TYPE to DIR.
11804 If REVERSE, save parts that do not match TYPE."
11805   (interactive
11806    (list (read-string "Save parts of type: "
11807                       (or (car gnus-summary-save-parts-type-history)
11808                           gnus-summary-save-parts-default-mime)
11809                       'gnus-summary-save-parts-type-history)
11810          (setq gnus-summary-save-parts-last-directory
11811                (read-file-name "Save to directory: "
11812                                gnus-summary-save-parts-last-directory
11813                                nil t))
11814          current-prefix-arg))
11815   (gnus-summary-iterate n
11816     (let ((gnus-display-mime-function nil)
11817           (gnus-inhibit-treatment t))
11818       (gnus-summary-select-article))
11819     (save-excursion
11820       (set-buffer gnus-article-buffer)
11821       (let ((handles (or gnus-article-mime-handles
11822                          (mm-dissect-buffer nil gnus-article-loose-mime)
11823                          (and gnus-article-emulate-mime
11824                               (mm-uu-dissect))))
11825             (gnus-summary-save-parts-counter 1))
11826         (when handles
11827           (gnus-summary-save-parts-1 type dir handles reverse)
11828           (unless gnus-article-mime-handles ;; Don't destroy this case.
11829             (mm-destroy-parts handles)))))))
11830
11831 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11832   (if (stringp (car handle))
11833       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11834               (cdr handle))
11835     (when (if reverse
11836               (not (string-match type (mm-handle-media-type handle)))
11837             (string-match type (mm-handle-media-type handle)))
11838       (let ((file (expand-file-name
11839                    (gnus-map-function
11840                     mm-file-name-rewrite-functions
11841                     (file-name-nondirectory
11842                      (or
11843                       (mail-content-type-get
11844                        (mm-handle-disposition handle) 'filename)
11845                       (mail-content-type-get
11846                        (mm-handle-type handle) 'name)
11847                       (format "%s.%d.%d" gnus-newsgroup-name
11848                               (cdr gnus-article-current)
11849                               gnus-summary-save-parts-counter))))
11850                    dir)))
11851         (incf gnus-summary-save-parts-counter)
11852         (unless (file-exists-p file)
11853           (mm-save-part-to-file handle file))))))
11854
11855 ;; Summary extract commands
11856
11857 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11858   (let ((buffer-read-only nil)
11859         (article (gnus-summary-article-number))
11860         after-article b e)
11861     (unless (gnus-summary-goto-subject article)
11862       (error "No such article: %d" article))
11863     (gnus-summary-position-point)
11864     ;; If all commands are to be bunched up on one line, we collect
11865     ;; them here.
11866     (unless gnus-view-pseudos-separately
11867       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11868             files action)
11869         (while ps
11870           (setq action (cdr (assq 'action (car ps))))
11871           (setq files (list (cdr (assq 'name (car ps)))))
11872           (while (and ps (cdr ps)
11873                       (string= (or action "1")
11874                                (or (cdr (assq 'action (cadr ps))) "2")))
11875             (push (cdr (assq 'name (cadr ps))) files)
11876             (setcdr ps (cddr ps)))
11877           (when files
11878             (when (not (string-match "%s" action))
11879               (push " " files))
11880             (push " " files)
11881             (when (assq 'execute (car ps))
11882               (setcdr (assq 'execute (car ps))
11883                       (funcall (if (string-match "%s" action)
11884                                    'format 'concat)
11885                                action
11886                                (mapconcat
11887                                 (lambda (f)
11888                                   (if (equal f " ")
11889                                       f
11890                                     (shell-quote-argument f)))
11891                                 files " ")))))
11892           (setq ps (cdr ps)))))
11893     (if (and gnus-view-pseudos (not not-view))
11894         (while pslist
11895           (when (assq 'execute (car pslist))
11896             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11897                                   (eq gnus-view-pseudos 'not-confirm)))
11898           (setq pslist (cdr pslist)))
11899       (save-excursion
11900         (while pslist
11901           (setq after-article (or (cdr (assq 'article (car pslist)))
11902                                   (gnus-summary-article-number)))
11903           (gnus-summary-goto-subject after-article)
11904           (forward-line 1)
11905           (setq b (point))
11906           (insert "    " (file-name-nondirectory
11907                           (cdr (assq 'name (car pslist))))
11908                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11909           (setq e (point))
11910           (forward-line -1)             ; back to `b'
11911           (gnus-add-text-properties
11912            b (1- e) (list 'gnus-number gnus-reffed-article-number
11913                           gnus-mouse-face-prop gnus-mouse-face))
11914           (gnus-data-enter
11915            after-article gnus-reffed-article-number
11916            gnus-unread-mark b (car pslist) 0 (- e b))
11917           (setq gnus-newsgroup-unreads
11918                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11919                                          gnus-reffed-article-number))
11920           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11921           (setq pslist (cdr pslist)))))))
11922
11923 (defun gnus-pseudos< (p1 p2)
11924   (let ((c1 (cdr (assq 'action p1)))
11925         (c2 (cdr (assq 'action p2))))
11926     (and c1 c2 (string< c1 c2))))
11927
11928 (defun gnus-request-pseudo-article (props)
11929   (cond ((assq 'execute props)
11930          (gnus-execute-command (cdr (assq 'execute props)))))
11931   (let ((gnus-current-article (gnus-summary-article-number)))
11932     (gnus-run-hooks 'gnus-mark-article-hook)))
11933
11934 (defun gnus-execute-command (command &optional automatic)
11935   (save-excursion
11936     (gnus-article-setup-buffer)
11937     (set-buffer gnus-article-buffer)
11938     (setq buffer-read-only nil)
11939     (let ((command (if automatic command
11940                      (read-string "Command: " (cons command 0)))))
11941       (erase-buffer)
11942       (insert "$ " command "\n\n")
11943       (if gnus-view-pseudo-asynchronously
11944           (start-process "gnus-execute" (current-buffer) shell-file-name
11945                          shell-command-switch command)
11946         (call-process shell-file-name nil t nil
11947                       shell-command-switch command)))))
11948
11949 ;; Summary kill commands.
11950
11951 (defun gnus-summary-edit-global-kill (article)
11952   "Edit the \"global\" kill file."
11953   (interactive (list (gnus-summary-article-number)))
11954   (gnus-group-edit-global-kill article))
11955
11956 (defun gnus-summary-edit-local-kill ()
11957   "Edit a local kill file applied to the current newsgroup."
11958   (interactive)
11959   (setq gnus-current-headers (gnus-summary-article-header))
11960   (gnus-group-edit-local-kill
11961    (gnus-summary-article-number) gnus-newsgroup-name))
11962
11963 ;;; Header reading.
11964
11965 (defun gnus-read-header (id &optional header)
11966   "Read the headers of article ID and enter them into the Gnus system."
11967   (let ((group gnus-newsgroup-name)
11968         (gnus-override-method
11969          (or
11970           gnus-override-method
11971           (and (gnus-news-group-p gnus-newsgroup-name)
11972                (car (gnus-refer-article-methods)))))
11973         where)
11974     ;; First we check to see whether the header in question is already
11975     ;; fetched.
11976     (if (stringp id)
11977         ;; This is a Message-ID.
11978         (setq header (or header (gnus-id-to-header id)))
11979       ;; This is an article number.
11980       (setq header (or header (gnus-summary-article-header id))))
11981     (if (and header
11982              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11983         ;; We have found the header.
11984         header
11985       ;; We have to really fetch the header to this article.
11986       (save-excursion
11987         (set-buffer nntp-server-buffer)
11988         (when (setq where (gnus-request-head id group))
11989           (nnheader-fold-continuation-lines)
11990           (goto-char (point-max))
11991           (insert ".\n")
11992           (goto-char (point-min))
11993           (insert "211 ")
11994           (princ (cond
11995                   ((numberp id) id)
11996                   ((cdr where) (cdr where))
11997                   (header (mail-header-number header))
11998                   (t gnus-reffed-article-number))
11999                  (current-buffer))
12000           (insert " Article retrieved.\n"))
12001         (if (or (not where)
12002                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12003             ()                          ; Malformed head.
12004           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12005             (when (and (stringp id)
12006                        (or
12007                         (not (string= (gnus-group-real-name group)
12008                                       (car where)))
12009                         (not (gnus-server-equal gnus-override-method
12010                                                 (gnus-group-method group)))))
12011               ;; If we fetched by Message-ID and the article came from
12012               ;; a different group (or server), we fudge some bogus
12013               ;; article numbers for this article.
12014               (mail-header-set-number header gnus-reffed-article-number))
12015             (save-excursion
12016               (set-buffer gnus-summary-buffer)
12017               (decf gnus-reffed-article-number)
12018               (gnus-remove-header (mail-header-number header))
12019               (push header gnus-newsgroup-headers)
12020               (setq gnus-current-headers header)
12021               (push (mail-header-number header) gnus-newsgroup-limit)))
12022           header)))))
12023
12024 (defun gnus-remove-header (number)
12025   "Remove header NUMBER from `gnus-newsgroup-headers'."
12026   (if (and gnus-newsgroup-headers
12027            (= number (mail-header-number (car gnus-newsgroup-headers))))
12028       (pop gnus-newsgroup-headers)
12029     (let ((headers gnus-newsgroup-headers))
12030       (while (and (cdr headers)
12031                   (not (= number (mail-header-number (cadr headers)))))
12032         (pop headers))
12033       (when (cdr headers)
12034         (setcdr headers (cddr headers))))))
12035
12036 ;;;
12037 ;;; summary highlights
12038 ;;;
12039
12040 (defun gnus-highlight-selected-summary ()
12041   "Highlight selected article in summary buffer."
12042   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12043   (when gnus-summary-selected-face
12044     (save-excursion
12045       (let* ((beg (point-at-bol))
12046              (end (point-at-eol))
12047              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12048              (from (if (get-text-property beg gnus-mouse-face-prop)
12049                        beg
12050                      (or (next-single-property-change
12051                           beg gnus-mouse-face-prop nil end)
12052                          beg)))
12053              (to
12054               (if (= from end)
12055                   (- from 2)
12056                 (or (next-single-property-change
12057                      from gnus-mouse-face-prop nil end)
12058                     end))))
12059         ;; If no mouse-face prop on line we will have to = from = end,
12060         ;; so we highlight the entire line instead.
12061         (when (= (+ to 2) from)
12062           (setq from beg)
12063           (setq to end))
12064         (if gnus-newsgroup-selected-overlay
12065             ;; Move old overlay.
12066             (gnus-move-overlay
12067              gnus-newsgroup-selected-overlay from to (current-buffer))
12068           ;; Create new overlay.
12069           (gnus-overlay-put
12070            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12071            'face gnus-summary-selected-face))))))
12072
12073 (defvar gnus-summary-highlight-line-cached nil)
12074 (defvar gnus-summary-highlight-line-trigger nil)
12075
12076 (defun gnus-summary-highlight-line-0 ()
12077   (if (and (eq gnus-summary-highlight-line-trigger
12078                gnus-summary-highlight)
12079            gnus-summary-highlight-line-cached)
12080       gnus-summary-highlight-line-cached
12081     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12082           gnus-summary-highlight-line-cached
12083           (let* ((cond (list 'cond))
12084                  (c cond)
12085                  (list gnus-summary-highlight))
12086             (while list
12087               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12088                               nil))
12089               (setq c (cdr c)
12090                     list (cdr list)))
12091             (gnus-byte-compile (list 'lambda nil cond))))))
12092
12093 (defun gnus-summary-highlight-line ()
12094   "Highlight current line according to `gnus-summary-highlight'."
12095   (let* ((beg (point-at-bol))
12096          (article (or (gnus-summary-article-number) gnus-current-article))
12097          (score (or (cdr (assq article
12098                                gnus-newsgroup-scored))
12099                     gnus-summary-default-score 0))
12100          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12101          (inhibit-read-only t)
12102          (default gnus-summary-default-score)
12103          (default-high gnus-summary-default-high-score)
12104          (default-low gnus-summary-default-low-score)
12105          (uncached (and gnus-summary-use-undownloaded-faces
12106                         (memq article gnus-newsgroup-undownloaded)
12107                         (not (memq article gnus-newsgroup-cached)))))
12108     (let ((face (funcall (gnus-summary-highlight-line-0))))
12109       (unless (eq face (get-text-property beg 'face))
12110         (gnus-put-text-property-excluding-characters-with-faces
12111          beg (point-at-eol) 'face
12112          (setq face (if (boundp face) (symbol-value face) face)))
12113         (when gnus-summary-highlight-line-function
12114           (funcall gnus-summary-highlight-line-function article face))))))
12115
12116 (defun gnus-update-read-articles (group unread &optional compute)
12117   "Update the list of read articles in GROUP.
12118 UNREAD is a sorted list."
12119   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12120         (info (gnus-get-info group))
12121         (prev 1)
12122         read)
12123     (if (or (not info) (not active))
12124         ;; There is no info on this group if it was, in fact,
12125         ;; killed.  Gnus stores no information on killed groups, so
12126         ;; there's nothing to be done.
12127         ;; One could store the information somewhere temporarily,
12128         ;; perhaps...  Hmmm...
12129         ()
12130       ;; Remove any negative articles numbers.
12131       (while (and unread (< (car unread) 0))
12132         (setq unread (cdr unread)))
12133       ;; Remove any expired article numbers
12134       (while (and unread (< (car unread) (car active)))
12135         (setq unread (cdr unread)))
12136       ;; Compute the ranges of read articles by looking at the list of
12137       ;; unread articles.
12138       (while unread
12139         (when (/= (car unread) prev)
12140           (push (if (= prev (1- (car unread))) prev
12141                   (cons prev (1- (car unread))))
12142                 read))
12143         (setq prev (1+ (car unread)))
12144         (setq unread (cdr unread)))
12145       (when (<= prev (cdr active))
12146         (push (cons prev (cdr active)) read))
12147       (setq read (if (> (length read) 1) (nreverse read) read))
12148       (if compute
12149           read
12150         (save-excursion
12151           (let (setmarkundo)
12152             ;; Propagate the read marks to the backend.
12153             (when (gnus-check-backend-function 'request-set-mark group)
12154               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12155                     (add (gnus-remove-from-range read (gnus-info-read info))))
12156                 (when (or add del)
12157                   (unless (gnus-check-group group)
12158                     (error "Can't open server for %s" group))
12159                   (gnus-request-set-mark
12160                    group (delq nil (list (if add (list add 'add '(read)))
12161                                          (if del (list del 'del '(read))))))
12162                   (setq setmarkundo
12163                         `(gnus-request-set-mark
12164                           ,group
12165                           ',(delq nil (list
12166                                        (if del (list del 'add '(read)))
12167                                        (if add (list add 'del '(read))))))))))
12168             (set-buffer gnus-group-buffer)
12169             (gnus-undo-register
12170               `(progn
12171                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12172                  (gnus-info-set-read ',info ',(gnus-info-read info))
12173                  (gnus-get-unread-articles-in-group ',info
12174                                                     (gnus-active ,group))
12175                  (gnus-group-update-group ,group t)
12176                  ,setmarkundo))))
12177         ;; Enter this list into the group info.
12178         (gnus-info-set-read info read)
12179         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12180         (gnus-get-unread-articles-in-group info (gnus-active group))
12181         t))))
12182
12183 (defun gnus-offer-save-summaries ()
12184   "Offer to save all active summary buffers."
12185   (let (buffers)
12186     ;; Go through all buffers and find all summaries.
12187     (dolist (buffer (buffer-list))
12188       (when (and (setq buffer (buffer-name buffer))
12189                  (string-match "Summary" buffer)
12190                  (with-current-buffer buffer
12191                    ;; We check that this is, indeed, a summary buffer.
12192                    (and (eq major-mode 'gnus-summary-mode)
12193                         ;; Also make sure this isn't bogus.
12194                         gnus-newsgroup-prepared
12195                         ;; Also make sure that this isn't a
12196                         ;; dead summary buffer.
12197                         (not gnus-dead-summary-mode))))
12198         (push buffer buffers)))
12199     ;; Go through all these summary buffers and offer to save them.
12200     (when buffers
12201       (save-excursion
12202         (map-y-or-n-p
12203          "Update summary buffer %s? "
12204          (lambda (buf)
12205            (switch-to-buffer buf)
12206            (gnus-summary-exit))
12207          buffers)))))
12208
12209 (defun gnus-summary-setup-default-charset ()
12210   "Setup newsgroup default charset."
12211   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12212       (setq gnus-newsgroup-charset nil)
12213     (let* ((ignored-charsets
12214             (or gnus-newsgroup-ephemeral-ignored-charsets
12215                 (append
12216                  (and gnus-newsgroup-name
12217                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12218                  gnus-newsgroup-ignored-charsets))))
12219       (setq gnus-newsgroup-charset
12220             (or gnus-newsgroup-ephemeral-charset
12221                 (and gnus-newsgroup-name
12222                      (gnus-parameter-charset gnus-newsgroup-name))
12223                 gnus-default-charset))
12224       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12225            ignored-charsets))))
12226
12227 ;;;
12228 ;;; Mime Commands
12229 ;;;
12230
12231 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12232   "Display the current article buffer fully MIME-buttonized.
12233 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12234 treated as multipart/mixed."
12235   (interactive "P")
12236   (require 'gnus-art)
12237   (let ((gnus-unbuttonized-mime-types nil)
12238         (gnus-mime-display-multipart-as-mixed show-all-parts))
12239     (gnus-summary-show-article)))
12240
12241 (defun gnus-summary-repair-multipart (article)
12242   "Add a Content-Type header to a multipart article without one."
12243   (interactive (list (gnus-summary-article-number)))
12244   (gnus-with-article article
12245     (message-narrow-to-head)
12246     (message-remove-header "Mime-Version")
12247     (goto-char (point-max))
12248     (insert "Mime-Version: 1.0\n")
12249     (widen)
12250     (when (search-forward "\n--" nil t)
12251       (let ((separator (buffer-substring (point) (point-at-eol))))
12252         (message-narrow-to-head)
12253         (message-remove-header "Content-Type")
12254         (goto-char (point-max))
12255         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12256                         separator))
12257         (widen))))
12258   (let (gnus-mark-article-hook)
12259     (gnus-summary-select-article t t nil article)))
12260
12261 (defun gnus-summary-toggle-display-buttonized ()
12262   "Toggle the buttonizing of the article buffer."
12263   (interactive)
12264   (require 'gnus-art)
12265   (if (setq gnus-inhibit-mime-unbuttonizing
12266             (not gnus-inhibit-mime-unbuttonizing))
12267       (let ((gnus-unbuttonized-mime-types nil))
12268         (gnus-summary-show-article))
12269     (gnus-summary-show-article)))
12270
12271 ;;;
12272 ;;; Generic summary marking commands
12273 ;;;
12274
12275 (defvar gnus-summary-marking-alist
12276   '((read gnus-del-mark "d")
12277     (unread gnus-unread-mark "u")
12278     (ticked gnus-ticked-mark "!")
12279     (dormant gnus-dormant-mark "?")
12280     (expirable gnus-expirable-mark "e"))
12281   "An alist of names/marks/keystrokes.")
12282
12283 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12284 (defvar gnus-summary-mark-map)
12285
12286 (defun gnus-summary-make-all-marking-commands ()
12287   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12288   (dolist (elem gnus-summary-marking-alist)
12289     (apply 'gnus-summary-make-marking-command elem)))
12290
12291 (defun gnus-summary-make-marking-command (name mark keystroke)
12292   (let ((map (make-sparse-keymap)))
12293     (define-key gnus-summary-generic-mark-map keystroke map)
12294     (dolist (lway `((next "next" next nil "n")
12295                     (next-unread "next unread" next t "N")
12296                     (prev "previous" prev nil "p")
12297                     (prev-unread "previous unread" prev t "P")
12298                     (nomove "" nil nil ,keystroke)))
12299       (let ((func (gnus-summary-make-marking-command-1
12300                    mark (car lway) lway name)))
12301         (setq func (eval func))
12302         (define-key map (nth 4 lway) func)))))
12303
12304 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12305   `(defun ,(intern
12306             (format "gnus-summary-put-mark-as-%s%s"
12307                     name (if (eq way 'nomove)
12308                              ""
12309                            (concat "-" (symbol-name way)))))
12310      (n)
12311      ,(format
12312        "Mark the current article as %s%s.
12313 If N, the prefix, then repeat N times.
12314 If N is negative, move in reverse order.
12315 The difference between N and the actual number of articles marked is
12316 returned."
12317        name (cadr lway))
12318      (interactive "p")
12319      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12320
12321 (defun gnus-summary-generic-mark (n mark move unread)
12322   "Mark N articles with MARK."
12323   (unless (eq major-mode 'gnus-summary-mode)
12324     (error "This command can only be used in the summary buffer"))
12325   (gnus-summary-show-thread)
12326   (let ((nummove
12327          (cond
12328           ((eq move 'next) 1)
12329           ((eq move 'prev) -1)
12330           (t 0))))
12331     (if (zerop nummove)
12332         (setq n 1)
12333       (when (< n 0)
12334         (setq n (abs n)
12335               nummove (* -1 nummove))))
12336     (while (and (> n 0)
12337                 (gnus-summary-mark-article nil mark)
12338                 (zerop (gnus-summary-next-subject nummove unread t)))
12339       (setq n (1- n)))
12340     (when (/= 0 n)
12341       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12342     (gnus-summary-recenter)
12343     (gnus-summary-position-point)
12344     (gnus-set-mode-line 'summary)
12345     n))
12346
12347 (defun gnus-summary-insert-articles (articles)
12348   (when (setq articles
12349               (gnus-sorted-difference articles
12350                                       (mapcar (lambda (h)
12351                                                 (mail-header-number h))
12352                                               gnus-newsgroup-headers)))
12353     (setq gnus-newsgroup-headers
12354           (gnus-merge 'list
12355                       gnus-newsgroup-headers
12356                       (gnus-fetch-headers articles)
12357                       'gnus-article-sort-by-number))
12358     ;; Suppress duplicates?
12359     (when gnus-suppress-duplicates
12360       (gnus-dup-suppress-articles))
12361
12362     (if (and gnus-fetch-old-headers
12363              (eq gnus-headers-retrieved-by 'nov))
12364         ;; We might want to build some more threads first.
12365         (if (eq gnus-fetch-old-headers 'invisible)
12366             (gnus-build-all-threads)
12367           (gnus-build-old-threads))
12368       ;; Mark the inserted articles that are unread as unread.
12369       (setq gnus-newsgroup-unreads
12370             (gnus-sorted-nunion
12371              gnus-newsgroup-unreads
12372              (gnus-sorted-nintersection
12373               (gnus-list-of-unread-articles gnus-newsgroup-name)
12374               articles)))
12375       ;; Mark the inserted articles as selected so that the information
12376       ;; of the marks having been changed by a user may be updated when
12377       ;; exiting this group.  See `gnus-summary-update-info'.
12378       (dolist (art articles)
12379         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12380     ;; Let the Gnus agent mark articles as read.
12381     (when gnus-agent
12382       (gnus-agent-get-undownloaded-list))
12383     ;; Remove list identifiers from subject
12384     (when gnus-list-identifiers
12385       (gnus-summary-remove-list-identifiers))
12386     ;; First and last article in this newsgroup.
12387     (when gnus-newsgroup-headers
12388       (setq gnus-newsgroup-begin
12389             (mail-header-number (car gnus-newsgroup-headers))
12390             gnus-newsgroup-end
12391             (mail-header-number
12392              (gnus-last-element gnus-newsgroup-headers))))
12393     (when gnus-use-scoring
12394       (gnus-possibly-score-headers))))
12395
12396 (defun gnus-summary-insert-old-articles (&optional all)
12397   "Insert all old articles in this group.
12398 If ALL is non-nil, already read articles become readable.
12399 If ALL is a number, fetch this number of articles."
12400   (interactive "P")
12401   (prog1
12402       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12403             older len)
12404         (setq older
12405               ;; Some nntp servers lie about their active range.  When
12406               ;; this happens, the active range can be in the millions.
12407               ;; Use a compressed range to avoid creating a huge list.
12408               (gnus-range-difference (list gnus-newsgroup-active) old))
12409         (setq len (gnus-range-length older))
12410         (cond
12411          ((null older) nil)
12412          ((numberp all)
12413           (if (< all len)
12414               (let ((older-range (nreverse older)))
12415                 (setq older nil)
12416
12417                 (while (> all 0)
12418                   (let* ((r (pop older-range))
12419                          (min (if (numberp r) r (car r)))
12420                          (max (if (numberp r) r (cdr r))))
12421                     (while (and (<= min max)
12422                                 (> all 0))
12423                       (push max older)
12424                       (setq all (1- all)
12425                             max (1- max))))))
12426             (setq older (gnus-uncompress-range older))))
12427          (all
12428           (setq older (gnus-uncompress-range older)))
12429          (t
12430           (when (and (numberp gnus-large-newsgroup)
12431                    (> len gnus-large-newsgroup))
12432               (let* ((cursor-in-echo-area nil)
12433                      (initial (gnus-parameter-large-newsgroup-initial
12434                                gnus-newsgroup-name))
12435                      (input
12436                       (read-string
12437                        (format
12438                         "How many articles from %s (%s %d): "
12439                         (gnus-group-decoded-name gnus-newsgroup-name)
12440                         (if initial "max" "default")
12441                         len)
12442                        (if initial
12443                            (cons (number-to-string initial)
12444                                  0)))))
12445                 (unless (string-match "^[ \t]*$" input)
12446                   (setq all (string-to-number input))
12447                   (if (< all len)
12448                       (let ((older-range (nreverse older)))
12449                         (setq older nil)
12450
12451                         (while (> all 0)
12452                           (let* ((r (pop older-range))
12453                                  (min (if (numberp r) r (car r)))
12454                                  (max (if (numberp r) r (cdr r))))
12455                             (while (and (<= min max)
12456                                         (> all 0))
12457                               (push max older)
12458                               (setq all (1- all)
12459                                     max (1- max))))))))))
12460           (setq older (gnus-uncompress-range older))))
12461         (if (not older)
12462             (message "No old news.")
12463           (gnus-summary-insert-articles older)
12464           (gnus-summary-limit (gnus-sorted-nunion old older))))
12465     (gnus-summary-position-point)))
12466
12467 (defun gnus-summary-insert-new-articles ()
12468   "Insert all new articles in this group."
12469   (interactive)
12470   (prog1
12471       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12472             (old-active gnus-newsgroup-active)
12473             (nnmail-fetched-sources (list t))
12474             i new)
12475         (setq gnus-newsgroup-active
12476               (gnus-activate-group gnus-newsgroup-name 'scan))
12477         (setq i (cdr gnus-newsgroup-active))
12478         (while (> i (cdr old-active))
12479           (push i new)
12480           (decf i))
12481         (if (not new)
12482             (message "No gnus is bad news")
12483           (gnus-summary-insert-articles new)
12484           (setq gnus-newsgroup-unreads
12485                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12486           (gnus-summary-limit (gnus-sorted-nunion old new))))
12487     (gnus-summary-position-point)))
12488
12489 (gnus-summary-make-all-marking-commands)
12490
12491 (gnus-ems-redefine)
12492
12493 (provide 'gnus-sum)
12494
12495 (run-hooks 'gnus-sum-load-hook)
12496
12497 ;; Local Variables:
12498 ;; coding: iso-8859-1
12499 ;; End:
12500
12501 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12502 ;;; gnus-sum.el ends here