Translating...
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
62 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
63 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-fetch-old-headers nil
73   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
74 If an unread article in the group refers to an older, already read (or
75 just marked as read) article, the old article will not normally be
76 displayed in the Summary buffer.  If this variable is t, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const :tag "on" t)
88                  (const some)
89                  (const invisible)
90                  number
91                  (sexp :menu-tag "other" t)))
92
93 (defcustom gnus-refer-thread-limit 200
94   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
95 If t, fetch all the available old headers."
96   :group 'gnus-thread
97   :type '(choice number
98                  (sexp :menu-tag "other" t)))
99
100 (defcustom gnus-summary-make-false-root 'adopt
101   "*nil means that Gnus won't gather loose threads.
102 If the root of a thread has expired or been read in a previous
103 session, the information necessary to build a complete thread has been
104 lost.  Instead of having many small sub-threads from this original thread
105 scattered all over the summary buffer, Gnus can gather them.
106
107 If non-nil, Gnus will try to gather all loose sub-threads from an
108 original thread into one large thread.
109
110 If this variable is non-nil, it should be one of `none', `adopt',
111 `dummy' or `empty'.
112
113 If this variable is `none', Gnus will not make a false root, but just
114 present the sub-threads after another.
115 If this variable is `dummy', Gnus will create a dummy root that will
116 have all the sub-threads as children.
117 If this variable is `adopt', Gnus will make one of the \"children\"
118 the parent and mark all the step-children as such.
119 If this variable is `empty', the \"children\" are printed with empty
120 subject fields.  (Or rather, they will be printed with a string
121 given by the `gnus-summary-same-subject' variable.)"
122   :group 'gnus-thread
123   :type '(choice (const :tag "off" nil)
124                  (const none)
125                  (const dummy)
126                  (const adopt)
127                  (const empty)))
128
129 (defcustom gnus-summary-make-false-root-always nil
130   "Always make a false dummy root."
131   :version "22.1"
132   :group 'gnus-thread
133   :type 'boolean)
134
135 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
136   "*A regexp to match subjects to be excluded from loose thread gathering.
137 As loose thread gathering is done on subjects only, that means that
138 there can be many false gatherings performed.  By rooting out certain
139 common subjects, gathering might become saner."
140   :group 'gnus-thread
141   :type 'regexp)
142
143 (defcustom gnus-summary-gather-subject-limit nil
144   "*Maximum length of subject comparisons when gathering loose threads.
145 Use nil to compare full subjects.  Setting this variable to a low
146 number will help gather threads that have been corrupted by
147 newsreaders chopping off subject lines, but it might also mean that
148 unrelated articles that have subject that happen to begin with the
149 same few characters will be incorrectly gathered.
150
151 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
152 comparing subjects."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const fuzzy)
156                  (sexp :menu-tag "on" t)))
157
158 (defcustom gnus-simplify-subject-functions nil
159   "List of functions taking a string argument that simplify subjects.
160 The functions are applied recursively.
161
162 Useful functions to put in this list include:
163 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
164 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
165   :group 'gnus-thread
166   :type '(repeat function))
167
168 (defcustom gnus-simplify-ignored-prefixes nil
169   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  regexp))
173
174 (defcustom gnus-build-sparse-threads nil
175   "*If non-nil, fill in the gaps in threads.
176 If `some', only fill in the gaps that are needed to tie loose threads
177 together.  If `more', fill in all leaf nodes that Gnus can find.  If
178 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
179   :group 'gnus-thread
180   :type '(choice (const :tag "off" nil)
181                  (const some)
182                  (const more)
183                  (sexp :menu-tag "all" t)))
184
185 (defcustom gnus-summary-thread-gathering-function
186   'gnus-gather-threads-by-subject
187   "*Function used for gathering loose threads.
188 There are two pre-defined functions: `gnus-gather-threads-by-subject',
189 which only takes Subjects into consideration; and
190 `gnus-gather-threads-by-references', which compared the References
191 headers of the articles to find matches."
192   :group 'gnus-thread
193   :type '(radio (function-item gnus-gather-threads-by-subject)
194                 (function-item gnus-gather-threads-by-references)
195                 (function :tag "other")))
196
197 (defcustom gnus-summary-same-subject ""
198   "*String indicating that the current article has the same subject as the previous.
199 This variable will only be used if the value of
200 `gnus-summary-make-false-root' is `empty'."
201   :group 'gnus-summary-format
202   :type 'string)
203
204 (defcustom gnus-summary-goto-unread t
205   "*If t, many commands will go to the next unread article.
206 This applies to marking commands as well as other commands that
207 \"naturally\" select the next article, like, for instance, `SPC' at
208 the end of an article.
209
210 If nil, the marking commands do NOT go to the next unread article
211 \(they go to the next article instead).  If `never', commands that
212 usually go to the next unread article, will go to the next article,
213 whether it is read or not."
214   :group 'gnus-summary-marks
215   :link '(custom-manual "(gnus)Setting Marks")
216   :type '(choice (const :tag "off" nil)
217                  (const never)
218                  (sexp :menu-tag "on" t)))
219
220 (defcustom gnus-summary-default-score 0
221   "*Default article score level.
222 All scores generated by the score files will be added to this score.
223 If this variable is nil, scoring will be disabled."
224   :group 'gnus-score-default
225   :type '(choice (const :tag "disable")
226                  integer))
227
228 (defcustom gnus-summary-default-high-score 0
229   "*Default threshold for a high scored article.
230 An article will be highlighted as high scored if its score is greater
231 than this score."
232   :version "22.1"
233   :group 'gnus-score-default
234   :type 'integer)
235
236 (defcustom gnus-summary-default-low-score 0
237   "*Default threshold for a low scored article.
238 An article will be highlighted as low scored if its score is smaller
239 than this score."
240   :version "22.1"
241   :group 'gnus-score-default
242   :type 'integer)
243
244 (defcustom gnus-summary-zcore-fuzz 0
245   "*Fuzziness factor for the zcore in the summary buffer.
246 Articles with scores closer than this to `gnus-summary-default-score'
247 will not be marked."
248   :group 'gnus-summary-format
249   :type 'integer)
250
251 (defcustom gnus-simplify-subject-fuzzy-regexp nil
252   "*Strings to be removed when doing fuzzy matches.
253 This can either be a regular expression or list of regular expressions
254 that will be removed from subject strings if fuzzy subject
255 simplification is selected."
256   :group 'gnus-thread
257   :type '(repeat regexp))
258
259 (defcustom gnus-show-threads t
260   "*If non-nil, display threads in summary mode."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-hide-subtree nil
265   "*If non-nil, hide all threads initially.
266 This can be a predicate specifier which says which threads to hide.
267 If threads are hidden, you have to run the command
268 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
269 to expose hidden threads."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier")))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), `unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "22.1"
337   :group 'gnus-group-select
338   :type '(choice (const best)
339                  (const unread)
340                  (const first)
341                  (const unseen)
342                  (const unseen-or-unread)))
343
344 (defcustom gnus-dont-select-after-jump-to-other-group nil
345   "If non-nil, don't select the first unread article after entering the
346 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
347 it is depend on the value of `gnus-auto-select-first' whether to select
348 or not."
349   :group 'gnus-group-select
350   :type 'boolean)
351
352 (defcustom gnus-auto-select-next t
353   "*If non-nil, offer to go to the next group from the end of the previous.
354 If the value is t and the next newsgroup is empty, Gnus will exit
355 summary mode and go back to group mode.  If the value is neither nil
356 nor t, Gnus will select the following unread newsgroup.  In
357 particular, if the value is the symbol `quietly', the next unread
358 newsgroup will be selected without any confirmation, and if it is
359 `almost-quietly', the next group will be selected without any
360 confirmation if you are located on the last article in the group.
361 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
362 will go to the next group without confirmation."
363   :group 'gnus-summary-maneuvering
364   :type '(choice (const :tag "off" nil)
365                  (const quietly)
366                  (const almost-quietly)
367                  (const slightly-quietly)
368                  (sexp :menu-tag "on" t)))
369
370 (defcustom gnus-auto-select-same nil
371   "*If non-nil, select the next article with the same subject.
372 If there are no more articles with the same subject, go to
373 the first unread article."
374   :group 'gnus-summary-maneuvering
375   :type 'boolean)
376
377 (defcustom gnus-auto-goto-ignores 'unfetched
378   "*Says how to handle unfetched articles when maneuvering.
379
380 This variable can either be the symbols nil (maneuver to any
381 article), `undownloaded' (maneuvering while unplugged ignores articles
382 that have not been fetched), `always-undownloaded' (maneuvering always
383 ignores articles that have not been fetched), `unfetched' (maneuvering
384 ignores articles whose headers have not been fetched).
385
386 NOTE: The list of unfetched articles will always be nil when plugged
387 and, when unplugged, a subset of the undownloaded article list."
388   :version "22.1"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 ;; FIXME: Although the custom type is `character' for the following variables,
464 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
465
466 (defcustom gnus-unread-mark ?\ ;;;Whitespace
467   "*Mark used for unread articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ticked-mark ?!
472   "*Mark used for ticked articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-dormant-mark ??
477   "*Mark used for dormant articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-del-mark ?r
482   "*Mark used for del'd articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-read-mark ?R
487   "*Mark used for read articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-expirable-mark ?E
492   "*Mark used for expirable articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-killed-mark ?K
497   "*Mark used for killed articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-spam-mark ?$
502   "*Mark used for spam articles."
503   :version "22.1"
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-souped-mark ?F
508   "*Mark used for souped articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-kill-file-mark ?X
513   "*Mark used for articles killed by kill files."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-low-score-mark ?Y
518   "*Mark used for articles with a low score."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-catchup-mark ?C
523   "*Mark used for articles that are caught up."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-replied-mark ?A
528   "*Mark used for articles that have been replied to."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-forwarded-mark ?F
533   "*Mark used for articles that have been forwarded."
534   :version "22.1"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-recent-mark ?N
539   "*Mark used for articles that are recent."
540   :version "22.1"
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-cached-mark ?*
545   "*Mark used for articles that are in the cache."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-saved-mark ?S
550   "*Mark used for articles that have been saved."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-unseen-mark ?.
555   "*Mark used for articles that haven't been seen."
556   :version "22.1"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-no-mark ?\ ;;;Whitespace
561   "*Mark used for articles that have no other secondary mark."
562   :version "22.1"
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-ancient-mark ?O
567   "*Mark used for ancient articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-sparse-mark ?Q
572   "*Mark used for sparsely reffed articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-canceled-mark ?G
577   "*Mark used for canceled articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-duplicate-mark ?M
582   "*Mark used for duplicate articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-undownloaded-mark ?-
587   "*Mark used for articles that weren't downloaded."
588   :version "22.1"
589   :group 'gnus-summary-marks
590   :type 'character)
591
592 (defcustom gnus-downloaded-mark ?+
593   "*Mark used for articles that were downloaded."
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloadable-mark ?%
598   "*Mark used for articles that are to be downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-unsendable-mark ?=
603   "*Mark used for articles that won't be sent."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-score-over-mark ?+
608   "*Score mark used for articles with high scores."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-below-mark ?-
613   "*Score mark used for articles with low scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
618   "*There is no thread under the article."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-not-empty-thread-mark ?=
623   "*There is a thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-view-pseudo-asynchronously nil
628   "*If non-nil, Gnus will view pseudo-articles asynchronously."
629   :group 'gnus-extract-view
630   :type 'boolean)
631
632 (defcustom gnus-auto-expirable-marks
633   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
634         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
635         gnus-souped-mark gnus-duplicate-mark)
636   "*The list of marks converted into expiration if a group is auto-expirable."
637   :version "21.1"
638   :group 'gnus-summary
639   :type '(repeat character))
640
641 (defcustom gnus-inhibit-user-auto-expire t
642   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
643   :version "21.1"
644   :group 'gnus-summary
645   :type 'boolean)
646
647 (defcustom gnus-view-pseudos nil
648   "*If `automatic', pseudo-articles will be viewed automatically.
649 If `not-confirm', pseudos will be viewed automatically, and the user
650 will not be asked to confirm the command."
651   :group 'gnus-extract-view
652   :type '(choice (const :tag "off" nil)
653                  (const automatic)
654                  (const not-confirm)))
655
656 (defcustom gnus-view-pseudos-separately t
657   "*If non-nil, one pseudo-article will be created for each file to be viewed.
658 If nil, all files that use the same viewing command will be given as a
659 list of parameters to that command."
660   :group 'gnus-extract-view
661   :type 'boolean)
662
663 (defcustom gnus-insert-pseudo-articles t
664   "*If non-nil, insert pseudo-articles when decoding articles."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-summary-dummy-line-format
669   "   %(:                             :%) %S\n"
670   "*The format specification for the dummy roots in the summary buffer.
671 It works along the same lines as a normal formatting string,
672 with some simple extensions.
673
674 %S  The subject
675
676 General format specifiers can also be used.
677 See `(gnus)Formatting Variables'."
678   :link '(custom-manual "(gnus)Formatting Variables")
679   :group 'gnus-threading
680   :type 'string)
681
682 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
683   "*The format specification for the summary mode line.
684 It works along the same lines as a normal formatting string,
685 with some simple extensions:
686
687 %G  Group name
688 %p  Unprefixed group name
689 %A  Current article number
690 %z  Current article score
691 %V  Gnus version
692 %U  Number of unread articles in the group
693 %e  Number of unselected articles in the group
694 %Z  A string with unread/unselected article counts
695 %g  Shortish group name
696 %S  Subject of the current article
697 %u  User-defined spec
698 %s  Current score file name
699 %d  Number of dormant articles
700 %r  Number of articles that have been marked as read in this session
701 %E  Number of articles expunged by the score files"
702   :group 'gnus-summary-format
703   :type 'string)
704
705 (defcustom gnus-list-identifiers nil
706   "Regexp that matches list identifiers to be removed from subject.
707 This can also be a list of regexps."
708   :version "21.1"
709   :group 'gnus-summary-format
710   :group 'gnus-article-hiding
711   :type '(choice (const :tag "none" nil)
712                  (regexp :value ".*")
713                  (repeat :value (".*") regexp)))
714
715 (defcustom gnus-summary-mark-below 0
716   "*Mark all articles with a score below this variable as read.
717 This variable is local to each summary buffer and usually set by the
718 score file."
719   :group 'gnus-score-default
720   :type 'integer)
721
722 (defun gnus-widget-reversible-match (widget value)
723   "Ignoring WIDGET, convert VALUE to internal form.
724 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
725   ;; (debug value)
726   (or (symbolp value)
727       (and (listp value)
728            (eq (length value) 2)
729            (eq (nth 0 value) 'not)
730            (symbolp (nth 1 value)))))
731
732 (defun gnus-widget-reversible-to-internal (widget value)
733   "Ignoring WIDGET, convert VALUE to internal form.
734 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
735 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
736   ;; (debug value)
737   (if (atom value)
738       (list value nil)
739     (list (nth 1 value) t)))
740
741 (defun gnus-widget-reversible-to-external (widget value)
742   "Ignoring WIDGET, convert VALUE to external form.
743 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
744 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
745   ;; (debug value)
746   (if (nth 1 value)
747       (list 'not (nth 0 value))
748     (nth 0 value)))
749
750 (define-widget 'gnus-widget-reversible 'group
751   "A `group' that convert values."
752   :match 'gnus-widget-reversible-match
753   :value-to-internal 'gnus-widget-reversible-to-internal
754   :value-to-external 'gnus-widget-reversible-to-external)
755
756 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
757   "*List of functions used for sorting articles in the summary buffer.
758
759 Each function takes two articles and returns non-nil if the first
760 article should be sorted before the other.  If you use more than one
761 function, the primary sort function should be the last.  You should
762 probably always include `gnus-article-sort-by-number' in the list of
763 sorting functions -- preferably first.  Also note that sorting by date
764 is often much slower than sorting by number, and the sorting order is
765 very similar.  (Sorting by date means sorting by the time the message
766 was sent, sorting by number means sorting by arrival time.)
767
768 Each item can also be a list `(not F)' where F is a function;
769 this reverses the sort order.
770
771 Ready-made functions include `gnus-article-sort-by-number',
772 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
773 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
774 and `gnus-article-sort-by-score'.
775
776 When threading is turned on, the variable `gnus-thread-sort-functions'
777 controls how articles are sorted."
778   :group 'gnus-summary-sort
779   :type '(repeat (gnus-widget-reversible
780                   (choice (function-item gnus-article-sort-by-number)
781                           (function-item gnus-article-sort-by-author)
782                           (function-item gnus-article-sort-by-subject)
783                           (function-item gnus-article-sort-by-date)
784                           (function-item gnus-article-sort-by-score)
785                           (function-item gnus-article-sort-by-random)
786                           (function :tag "other"))
787                   (boolean :tag "Reverse order"))))
788
789
790 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
791   "*List of functions used for sorting threads in the summary buffer.
792 By default, threads are sorted by article number.
793
794 Each function takes two threads and returns non-nil if the first
795 thread should be sorted before the other.  If you use more than one
796 function, the primary sort function should be the last.  You should
797 probably always include `gnus-thread-sort-by-number' in the list of
798 sorting functions -- preferably first.  Also note that sorting by date
799 is often much slower than sorting by number, and the sorting order is
800 very similar.  (Sorting by date means sorting by the time the message
801 was sent, sorting by number means sorting by arrival time.)
802
803 Each list item can also be a list `(not F)' where F is a
804 function; this specifies reversed sort order.
805
806 Ready-made functions include `gnus-thread-sort-by-number',
807 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
808 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
809 `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date',
811 `gnus-thread-sort-by-random', and
812 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
813
814 When threading is turned off, the variable
815 `gnus-article-sort-functions' controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat 
818           (gnus-widget-reversible
819            (choice (function-item gnus-thread-sort-by-number)
820                    (function-item gnus-thread-sort-by-author)
821                    (function-item gnus-thread-sort-by-subject)
822                    (function-item gnus-thread-sort-by-date)
823                    (function-item gnus-thread-sort-by-score)
824                    (function-item gnus-thread-sort-by-most-recent-number)
825                    (function-item gnus-thread-sort-by-most-recent-date)
826                    (function-item gnus-thread-sort-by-random)
827                    (function-item gnus-thread-sort-by-total-score)
828                    (function :tag "other"))
829            (boolean :tag "Reverse order"))))
830
831 (defcustom gnus-thread-score-function '+
832   "*Function used for calculating the total score of a thread.
833
834 The function is called with the scores of the article and each
835 subthread and should then return the score of the thread.
836
837 Some functions you can use are `+', `max', or `min'."
838   :group 'gnus-summary-sort
839   :type 'function)
840
841 (defcustom gnus-summary-expunge-below nil
842   "All articles that have a score less than this variable will be expunged.
843 This variable is local to the summary buffers."
844   :group 'gnus-score-default
845   :type '(choice (const :tag "off" nil)
846                  integer))
847
848 (defcustom gnus-thread-expunge-below nil
849   "All threads that have a total score less than this variable will be expunged.
850 See `gnus-thread-score-function' for en explanation of what a
851 \"thread score\" is.
852
853 This variable is local to the summary buffers."
854   :group 'gnus-threading
855   :group 'gnus-score-default
856   :type '(choice (const :tag "off" nil)
857                  integer))
858
859 (defcustom gnus-summary-mode-hook nil
860   "*A hook for Gnus summary mode.
861 This hook is run before any variables are set in the summary buffer."
862   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
867 (when (featurep 'xemacs)
868   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
870   (add-hook 'gnus-summary-mode-hook
871             'gnus-xmas-switch-horizontal-scrollbar-off))
872
873 (defcustom gnus-summary-menu-hook nil
874   "*Hook run after the creation of the summary mode menu."
875   :group 'gnus-summary-visual
876   :type 'hook)
877
878 (defcustom gnus-summary-exit-hook nil
879   "*A hook called on exit from the summary buffer.
880 It will be called with point in the group buffer."
881   :group 'gnus-summary-exit
882   :type 'hook)
883
884 (defcustom gnus-summary-prepare-hook nil
885   "*A hook called after the summary buffer has been generated.
886 If you want to modify the summary buffer, you can use this hook."
887   :group 'gnus-summary-various
888   :type 'hook)
889
890 (defcustom gnus-summary-prepared-hook nil
891   "*A hook called as the last thing after the summary buffer has been generated."
892   :group 'gnus-summary-various
893   :type 'hook)
894
895 (defcustom gnus-summary-generate-hook nil
896   "*A hook run just before generating the summary buffer.
897 This hook is commonly used to customize threading variables and the
898 like."
899   :group 'gnus-summary-various
900   :type 'hook)
901
902 (defcustom gnus-select-group-hook nil
903   "*A hook called when a newsgroup is selected.
904
905 If you'd like to simplify subjects like the
906 `gnus-summary-next-same-subject' command does, you can use the
907 following hook:
908
909  (add-hook gnus-select-group-hook
910            (lambda ()
911              (mapcar (lambda (header)
912                        (mail-header-set-subject
913                         header
914                         (gnus-simplify-subject
915                          (mail-header-subject header) 're-only)))
916                      gnus-newsgroup-headers)))"
917   :group 'gnus-group-select
918   :type 'hook)
919
920 (defcustom gnus-select-article-hook nil
921   "*A hook called when an article is selected."
922   :group 'gnus-summary-choose
923   :options '(gnus-agent-fetch-selected-article)
924   :type 'hook)
925
926 (defcustom gnus-visual-mark-article-hook
927   (list 'gnus-highlight-selected-summary)
928   "*Hook run after selecting an article in the summary buffer.
929 It is meant to be used for highlighting the article in some way.  It
930 is not run if `gnus-visual' is nil."
931   :group 'gnus-summary-visual
932   :type 'hook)
933
934 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
935   "*A hook called before parsing the headers."
936   :group 'gnus-various
937   :type 'hook)
938
939 (defcustom gnus-exit-group-hook nil
940   "*A hook called when exiting summary mode.
941 This hook is not called from the non-updating exit commands like `Q'."
942   :group 'gnus-various
943   :type 'hook)
944
945 (defcustom gnus-summary-update-hook
946   (list 'gnus-summary-highlight-line)
947   "*A hook called when a summary line is changed.
948 The hook will not be called if `gnus-visual' is nil.
949
950 The default function `gnus-summary-highlight-line' will
951 highlight the line according to the `gnus-summary-highlight'
952 variable."
953   :group 'gnus-summary-visual
954   :type 'hook)
955
956 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
957   "*A hook called when an article is selected for the first time.
958 The hook is intended to mark an article as read (or unread)
959 automatically when it is selected."
960   :group 'gnus-summary-choose
961   :type 'hook)
962
963 (defcustom gnus-group-no-more-groups-hook nil
964   "*A hook run when returning to group mode having no more (unread) groups."
965   :group 'gnus-group-select
966   :type 'hook)
967
968 (defcustom gnus-ps-print-hook nil
969   "*A hook run before ps-printing something from Gnus."
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-article-move-hook nil
974   "*A hook called after an article is moved, copied, respooled, or crossposted."
975   :version "22.1"
976   :group 'gnus-summary
977   :type 'hook)
978
979 (defcustom gnus-summary-article-delete-hook nil
980   "*A hook called after an article is deleted."
981   :version "22.1"
982   :group 'gnus-summary
983   :type 'hook)
984
985 (defcustom gnus-summary-article-expire-hook nil
986   "*A hook called after an article is expired."
987   :version "22.1"
988   :group 'gnus-summary
989   :type 'hook)
990
991 (defcustom gnus-summary-display-arrow
992   (and (fboundp 'display-graphic-p)
993        (display-graphic-p))
994   "*If non-nil, display an arrow highlighting the current article."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'boolean)
998
999 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1000   "Face used for highlighting the current article in the summary buffer."
1001   :group 'gnus-summary-visual
1002   :type 'face)
1003
1004 (defvar gnus-tmp-downloaded nil)
1005
1006 (defcustom gnus-summary-highlight
1007   '(((eq mark gnus-canceled-mark)
1008      . gnus-summary-cancelled)
1009     ((and uncached (> score default-high))
1010      . gnus-summary-high-undownloaded)
1011     ((and uncached (< score default-low))
1012      . gnus-summary-low-undownloaded)
1013     (uncached
1014      . gnus-summary-normal-undownloaded)
1015     ((and (> score default-high)
1016           (or (eq mark gnus-dormant-mark)
1017               (eq mark gnus-ticked-mark)))
1018      . gnus-summary-high-ticked)
1019     ((and (< score default-low)
1020           (or (eq mark gnus-dormant-mark)
1021               (eq mark gnus-ticked-mark)))
1022      . gnus-summary-low-ticked)
1023     ((or (eq mark gnus-dormant-mark)
1024          (eq mark gnus-ticked-mark))
1025      . gnus-summary-normal-ticked)
1026     ((and (> score default-high) (eq mark gnus-ancient-mark))
1027      . gnus-summary-high-ancient)
1028     ((and (< score default-low) (eq mark gnus-ancient-mark))
1029      . gnus-summary-low-ancient)
1030     ((eq mark gnus-ancient-mark)
1031      . gnus-summary-normal-ancient)
1032     ((and (> score default-high) (eq mark gnus-unread-mark))
1033      . gnus-summary-high-unread)
1034     ((and (< score default-low) (eq mark gnus-unread-mark))
1035      . gnus-summary-low-unread)
1036     ((eq mark gnus-unread-mark)
1037      . gnus-summary-normal-unread)
1038     ((> score default-high)
1039      . gnus-summary-high-read)
1040     ((< score default-low)
1041      . gnus-summary-low-read)
1042     (t
1043      . gnus-summary-normal-read))
1044   "*Controls the highlighting of summary buffer lines.
1045
1046 A list of (FORM . FACE) pairs.  When deciding how a a particular
1047 summary line should be displayed, each form is evaluated.  The content
1048 of the face field after the first true form is used.  You can change
1049 how those summary lines are displayed, by editing the face field.
1050
1051 You can use the following variables in the FORM field.
1052
1053 score:        The article's score
1054 default:      The default article score.
1055 default-high: The default score for high scored articles.
1056 default-low:  The default score for low scored articles.
1057 below:        The score below which articles are automatically marked as read.
1058 mark:         The article's mark.
1059 uncached:     Non-nil if the article is uncached."
1060   :group 'gnus-summary-visual
1061   :type '(repeat (cons (sexp :tag "Form" nil)
1062                        face)))
1063
1064 (defcustom gnus-alter-header-function nil
1065   "Function called to allow alteration of article header structures.
1066 The function is called with one parameter, the article header vector,
1067 which it may alter in any way."
1068   :type '(choice (const :tag "None" nil)
1069                  function)
1070   :group 'gnus-summary)
1071
1072 (defvar gnus-decode-encoded-word-function
1073   (mime-find-field-decoder 'From 'nov)
1074   "Variable that says which function should be used to decode a string with encoded words.")
1075
1076 (defcustom gnus-extra-headers '(To Newsgroups)
1077   "*Extra headers to parse."
1078   :version "21.1"
1079   :group 'gnus-summary
1080   :type '(repeat symbol))
1081
1082 (defcustom gnus-ignored-from-addresses
1083   (and user-mail-address (regexp-quote user-mail-address))
1084   "*Regexp of From headers that may be suppressed in favor of To headers."
1085   :version "21.1"
1086   :group 'gnus-summary
1087   :type 'regexp)
1088
1089 (defcustom gnus-summary-to-prefix "-> "
1090   "*String prefixed to the To field in the summary line when
1091 using `gnus-ignored-from-addresses'."
1092   :version "22.1"
1093   :group 'gnus-summary
1094   :type 'string)
1095
1096 (defcustom gnus-summary-newsgroup-prefix "=> "
1097   "*String prefixed to the Newsgroup field in the summary
1098 line when using `gnus-ignored-from-addresses'."
1099   :version "22.1"
1100   :group 'gnus-summary
1101   :type 'string)
1102
1103 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1104   "List of charsets that should be ignored.
1105 When these charsets are used in the \"charset\" parameter, the
1106 default charset will be used instead."
1107   :version "21.1"
1108   :type '(repeat symbol)
1109   :group 'gnus-charset)
1110
1111 (gnus-define-group-parameter
1112  ignored-charsets
1113  :type list
1114  :function-document
1115  "Return the ignored charsets of GROUP."
1116  :variable gnus-group-ignored-charsets-alist
1117  :variable-default
1118  '(("alt\\.chinese\\.text" iso-8859-1))
1119  :variable-document
1120  "Alist of regexps (to match group names) and charsets that should be ignored.
1121 When these charsets are used in the \"charset\" parameter, the
1122 default charset will be used instead."
1123  :variable-group gnus-charset
1124  :variable-type '(repeat (cons (regexp :tag "Group")
1125                                (repeat symbol)))
1126  :parameter-type '(choice :tag "Ignored charsets"
1127                           :value nil
1128                           (repeat (symbol)))
1129  :parameter-document       "\
1130 List of charsets that should be ignored.
1131
1132 When these charsets are used in the \"charset\" parameter, the
1133 default charset will be used instead.")
1134
1135 (defcustom gnus-group-highlight-words-alist nil
1136   "Alist of group regexps and highlight regexps.
1137 This variable uses the same syntax as `gnus-emphasis-alist'."
1138   :version "21.1"
1139   :type '(repeat (cons (regexp :tag "Group")
1140                        (repeat (list (regexp :tag "Highlight regexp")
1141                                      (number :tag "Group for entire word" 0)
1142                                      (number :tag "Group for displayed part" 0)
1143                                      (symbol :tag "Face"
1144                                              gnus-emphasis-highlight-words)))))
1145   :group 'gnus-summary-visual)
1146
1147 (defcustom gnus-use-wheel nil
1148   "Use Intelli-mouse on summary movement"
1149   :type 'boolean
1150   :group 'gnus-summary-maneuvering)
1151
1152 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1153   "Amount to scroll messages by spinning the mouse wheel.
1154 This is actually a cons cell, where the first item is the amount to scroll
1155 on a normal wheel event, and the second is the amount to scroll when the
1156 wheel is moved with the shift key depressed."
1157   :type '(cons (integer :tag "Shift") integer)
1158   :group 'gnus-summary-maneuvering)
1159
1160 (defcustom gnus-wheel-edge-resistance 2
1161   "How hard it should be to change the current article
1162 by moving the mouse over the edge of the article window."
1163   :type 'integer
1164   :group 'gnus-summary-maneuvering)
1165
1166 (defcustom gnus-summary-show-article-charset-alist
1167   nil
1168   "Alist of number and charset.
1169 The article will be shown with the charset corresponding to the
1170 numbered argument.
1171 For example: ((1 . cn-gb-2312) (2 . big5))."
1172   :version "21.1"
1173   :type '(repeat (cons (number :tag "Argument" 1)
1174                        (symbol :tag "Charset")))
1175   :group 'gnus-charset)
1176
1177 (defcustom gnus-preserve-marks t
1178   "Whether marks are preserved when moving, copying and respooling messages."
1179   :version "21.1"
1180   :type 'boolean
1181   :group 'gnus-summary-marks)
1182
1183 (defcustom gnus-alter-articles-to-read-function nil
1184   "Function to be called to alter the list of articles to be selected."
1185   :type '(choice (const nil) function)
1186   :group 'gnus-summary)
1187
1188 (defcustom gnus-orphan-score nil
1189   "*All orphans get this score added.  Set in the score file."
1190   :group 'gnus-score-default
1191   :type '(choice (const nil)
1192                  integer))
1193
1194 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1195   "*A regexp to match MIME parts when saving multiple parts of a
1196 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1197 This regexp will be used by default when prompting the user for which
1198 type of files to save."
1199   :group 'gnus-summary
1200   :type 'regexp)
1201
1202 (defcustom gnus-read-all-available-headers nil
1203   "Whether Gnus should parse all headers made available to it.
1204 This is mostly relevant for slow back ends where the user may
1205 wish to widen the summary buffer to include all headers
1206 that were fetched.  Say, for nnultimate groups."
1207   :version "22.1"
1208   :group 'gnus-summary
1209   :type '(choice boolean regexp))
1210
1211 (defcustom gnus-summary-muttprint-program "muttprint"
1212   "Command (and optional arguments) used to run Muttprint."
1213   :version "22.1"
1214   :group 'gnus-summary
1215   :type 'string)
1216
1217 (defcustom gnus-article-loose-mime t
1218   "If non-nil, don't require MIME-Version header.
1219 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1220 supply the MIME-Version header or deliberately strip it from the mail.
1221 If non-nil (the default), Gnus will treat some articles as MIME
1222 even if the MIME-Version header is missing."
1223   :version "22.1"
1224   :type 'boolean
1225   :group 'gnus-article-mime)
1226
1227 (defcustom gnus-article-emulate-mime t
1228   "If non-nil, use MIME emulation for uuencode and the like.
1229 This means that Gnus will search message bodies for text that look
1230 like uuencoded bits, yEncoded bits, and so on, and present that using
1231 the normal Gnus MIME machinery."
1232   :version "22.1"
1233   :type 'boolean
1234   :group 'gnus-article-mime)
1235
1236 ;;; Internal variables
1237
1238 (defvar gnus-summary-display-cache nil)
1239 (defvar gnus-article-mime-handles nil)
1240 (defvar gnus-article-decoded-p nil)
1241 (defvar gnus-article-charset nil)
1242 (defvar gnus-article-ignored-charsets nil)
1243 (defvar gnus-scores-exclude-files nil)
1244 (defvar gnus-page-broken nil)
1245
1246 (defvar gnus-original-article nil)
1247 (defvar gnus-article-internal-prepare-hook nil)
1248 (defvar gnus-newsgroup-process-stack nil)
1249
1250 (defvar gnus-thread-indent-array nil)
1251 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1252 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1253   "Function called to sort the articles within a thread after it has been gathered together.")
1254
1255 (defvar gnus-summary-save-parts-type-history nil)
1256 (defvar gnus-summary-save-parts-last-directory nil)
1257
1258 ;; Avoid highlighting in kill files.
1259 (defvar gnus-summary-inhibit-highlight nil)
1260 (defvar gnus-newsgroup-selected-overlay nil)
1261 (defvar gnus-inhibit-limiting nil)
1262 (defvar gnus-newsgroup-adaptive-score-file nil)
1263 (defvar gnus-current-score-file nil)
1264 (defvar gnus-current-move-group nil)
1265 (defvar gnus-current-copy-group nil)
1266 (defvar gnus-current-crosspost-group nil)
1267 (defvar gnus-newsgroup-display nil)
1268
1269 (defvar gnus-newsgroup-dependencies nil)
1270 (defvar gnus-newsgroup-adaptive nil)
1271 (defvar gnus-summary-display-article-function nil)
1272 (defvar gnus-summary-highlight-line-function nil
1273   "Function called after highlighting a summary line.")
1274
1275 (defvar gnus-summary-line-format-alist
1276   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1277     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1278     (?s gnus-tmp-subject-or-nil ?s)
1279     (?n gnus-tmp-name ?s)
1280     (?A (std11-address-string
1281          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1282     (?a (or (std11-full-name-string
1283              (car (mime-entity-read-field gnus-tmp-header 'From)))
1284             gnus-tmp-from) ?s)
1285     (?F gnus-tmp-from ?s)
1286     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1287     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1288     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1289     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1290     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1291     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1292     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1293     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1294     (?L gnus-tmp-lines ?s)
1295     (?O gnus-tmp-downloaded ?c)
1296     (?I gnus-tmp-indentation ?s)
1297     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1298     (?R gnus-tmp-replied ?c)
1299     (?\[ gnus-tmp-opening-bracket ?c)
1300     (?\] gnus-tmp-closing-bracket ?c)
1301     (?\> (make-string gnus-tmp-level ? ) ?s)
1302     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1303     (?i gnus-tmp-score ?d)
1304     (?z gnus-tmp-score-char ?c)
1305     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1306     (?U gnus-tmp-unread ?c)
1307     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1308         ?s)
1309     (?t (gnus-summary-number-of-articles-in-thread
1310          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1311         ?d)
1312     (?e (gnus-summary-number-of-articles-in-thread
1313          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1314         ?c)
1315     (?u gnus-tmp-user-defined ?s)
1316     (?P (gnus-pick-line-number) ?d)
1317     (?B gnus-tmp-thread-tree-header-string ?s)
1318     (user-date (gnus-user-date
1319                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1320   "An alist of format specifications that can appear in summary lines.
1321 These are paired with what variables they correspond with, along with
1322 the type of the variable (string, integer, character, etc).")
1323
1324 (defvar gnus-summary-dummy-line-format-alist
1325   `((?S gnus-tmp-subject ?s)
1326     (?N gnus-tmp-number ?d)
1327     (?u gnus-tmp-user-defined ?s)))
1328
1329 (defvar gnus-summary-mode-line-format-alist
1330   `((?G gnus-tmp-group-name ?s)
1331     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1332     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1333     (?A gnus-tmp-article-number ?d)
1334     (?Z gnus-tmp-unread-and-unselected ?s)
1335     (?V gnus-version ?s)
1336     (?U gnus-tmp-unread-and-unticked ?d)
1337     (?S gnus-tmp-subject ?s)
1338     (?e gnus-tmp-unselected ?d)
1339     (?u gnus-tmp-user-defined ?s)
1340     (?d (length gnus-newsgroup-dormant) ?d)
1341     (?t (length gnus-newsgroup-marked) ?d)
1342     (?h (length gnus-newsgroup-spam-marked) ?d)
1343     (?r (length gnus-newsgroup-reads) ?d)
1344     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1345     (?E gnus-newsgroup-expunged-tally ?d)
1346     (?s (gnus-current-score-file-nondirectory) ?s)))
1347
1348 (defvar gnus-last-search-regexp nil
1349   "Default regexp for article search command.")
1350
1351 (defvar gnus-summary-search-article-matched-data nil
1352   "Last matched data of article search command.  It is the local variable
1353 in `gnus-article-buffer' which consists of the list of start position,
1354 end position and text.")
1355
1356 (defvar gnus-last-shell-command nil
1357   "Default shell command on article.")
1358
1359 (defvar gnus-newsgroup-agentized nil
1360   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1361 (defvar gnus-newsgroup-begin nil)
1362 (defvar gnus-newsgroup-end nil)
1363 (defvar gnus-newsgroup-last-rmail nil)
1364 (defvar gnus-newsgroup-last-mail nil)
1365 (defvar gnus-newsgroup-last-folder nil)
1366 (defvar gnus-newsgroup-last-file nil)
1367 (defvar gnus-newsgroup-auto-expire nil)
1368 (defvar gnus-newsgroup-active nil)
1369
1370 (defvar gnus-newsgroup-data nil)
1371 (defvar gnus-newsgroup-data-reverse nil)
1372 (defvar gnus-newsgroup-limit nil)
1373 (defvar gnus-newsgroup-limits nil)
1374 (defvar gnus-summary-use-undownloaded-faces nil)
1375
1376 (defvar gnus-newsgroup-unreads nil
1377   "Sorted list of unread articles in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-unselected nil
1380   "Sorted list of unselected unread articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-reads nil
1383   "Alist of read articles and article marks in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-expunged-tally nil)
1386
1387 (defvar gnus-newsgroup-marked nil
1388   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1389
1390 (defvar gnus-newsgroup-spam-marked nil
1391   "List of ranges of articles that have been marked as spam.")
1392
1393 (defvar gnus-newsgroup-killed nil
1394   "List of ranges of articles that have been through the scoring process.")
1395
1396 (defvar gnus-newsgroup-cached nil
1397   "Sorted list of articles that come from the article cache.")
1398
1399 (defvar gnus-newsgroup-saved nil
1400   "List of articles that have been saved.")
1401
1402 (defvar gnus-newsgroup-kill-headers nil)
1403
1404 (defvar gnus-newsgroup-replied nil
1405   "List of articles that have been replied to in the current newsgroup.")
1406
1407 (defvar gnus-newsgroup-forwarded nil
1408   "List of articles that have been forwarded in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-recent nil
1411   "List of articles that have are recent in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-expirable nil
1414   "Sorted list of articles in the current newsgroup that can be expired.")
1415
1416 (defvar gnus-newsgroup-processable nil
1417   "List of articles in the current newsgroup that can be processed.")
1418
1419 (defvar gnus-newsgroup-downloadable nil
1420   "Sorted list of articles in the current newsgroup that can be processed.")
1421
1422 (defvar gnus-newsgroup-unfetched nil
1423   "Sorted list of articles in the current newsgroup whose headers have
1424 not been fetched into the agent.
1425
1426 This list will always be a subset of gnus-newsgroup-undownloaded.")
1427
1428 (defvar gnus-newsgroup-undownloaded nil
1429   "List of articles in the current newsgroup that haven't been downloaded.")
1430
1431 (defvar gnus-newsgroup-unsendable nil
1432   "List of articles in the current newsgroup that won't be sent.")
1433
1434 (defvar gnus-newsgroup-bookmarks nil
1435   "List of articles in the current newsgroup that have bookmarks.")
1436
1437 (defvar gnus-newsgroup-dormant nil
1438   "Sorted list of dormant articles in the current newsgroup.")
1439
1440 (defvar gnus-newsgroup-unseen nil
1441   "List of unseen articles in the current newsgroup.")
1442
1443 (defvar gnus-newsgroup-seen nil
1444   "Range of seen articles in the current newsgroup.")
1445
1446 (defvar gnus-newsgroup-articles nil
1447   "List of articles in the current newsgroup.")
1448
1449 (defvar gnus-newsgroup-scored nil
1450   "List of scored articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-incorporated nil
1453   "List of incorporated articles in the current newsgroup.")
1454
1455 (defvar gnus-newsgroup-headers nil
1456   "List of article headers in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-threads nil)
1459
1460 (defvar gnus-newsgroup-prepared nil
1461   "Whether the current group has been prepared properly.")
1462
1463 (defvar gnus-newsgroup-ancient nil
1464   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-sparse nil)
1467
1468 (defvar gnus-current-article nil)
1469 (defvar gnus-article-current nil)
1470 (defvar gnus-current-headers nil)
1471 (defvar gnus-have-all-headers nil)
1472 (defvar gnus-last-article nil)
1473 (defvar gnus-newsgroup-history nil)
1474 (defvar gnus-newsgroup-charset nil)
1475 (defvar gnus-newsgroup-ephemeral-charset nil)
1476 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1477
1478 (defvar gnus-article-before-search nil)
1479
1480 (defvar gnus-summary-local-variables
1481   '(gnus-newsgroup-name
1482     gnus-newsgroup-begin gnus-newsgroup-end
1483     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1484     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1485     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1486     gnus-newsgroup-unselected gnus-newsgroup-marked
1487     gnus-newsgroup-spam-marked
1488     gnus-newsgroup-reads gnus-newsgroup-saved
1489     gnus-newsgroup-replied gnus-newsgroup-forwarded
1490     gnus-newsgroup-recent
1491     gnus-newsgroup-expirable
1492     gnus-newsgroup-processable gnus-newsgroup-killed
1493     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1494     gnus-newsgroup-unfetched
1495     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1496     gnus-newsgroup-seen gnus-newsgroup-articles
1497     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1498     gnus-newsgroup-headers gnus-newsgroup-threads
1499     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1500     gnus-current-article gnus-current-headers gnus-have-all-headers
1501     gnus-last-article gnus-article-internal-prepare-hook
1502     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1503     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1504     gnus-thread-expunge-below
1505     gnus-score-alist gnus-current-score-file
1506     (gnus-summary-expunge-below . global)
1507     (gnus-summary-mark-below . global)
1508     (gnus-orphan-score . global)
1509     gnus-newsgroup-active gnus-scores-exclude-files
1510     gnus-newsgroup-history gnus-newsgroup-ancient
1511     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1512     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1513     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1514     (gnus-newsgroup-expunged-tally . 0)
1515     gnus-cache-removable-articles gnus-newsgroup-cached
1516     gnus-newsgroup-data gnus-newsgroup-data-reverse
1517     gnus-newsgroup-limit gnus-newsgroup-limits
1518     gnus-newsgroup-charset gnus-newsgroup-display
1519     gnus-summary-use-undownloaded-faces
1520     gnus-newsgroup-incorporated)
1521   "Variables that are buffer-local to the summary buffers.")
1522
1523 (defvar gnus-newsgroup-variables nil
1524   "A list of variables that have separate values in different newsgroups.
1525 A list of newsgroup (summary buffer) local variables, or cons of
1526 variables and their default expressions to be evalled (when the default
1527 values are not nil), that should be made global while the summary buffer
1528 is active.
1529
1530 Note: The default expressions will be evaluated (using function `eval')
1531 before assignment to the local variable rather than just assigned to it.
1532 If the default expression is the symbol `global', that symbol will not
1533 be evaluated but the global value of the local variable will be used
1534 instead.
1535
1536 These variables can be used to set variables in the group parameters
1537 while still allowing them to affect operations done in other buffers.
1538 For example:
1539
1540 \(setq gnus-newsgroup-variables
1541      '(message-use-followup-to
1542        (gnus-visible-headers .
1543          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1544 ")
1545
1546 ;; Byte-compiler warning.
1547 (eval-when-compile
1548   ;; Bind features so that require will believe that gnus-sum has
1549   ;; already been loaded (avoids infinite recursion)
1550   (let ((features (cons 'gnus-sum features)))
1551     ;; Several of the declarations in gnus-sum are needed to load the
1552     ;; following files. Right now, these definitions have been
1553     ;; compiled but not defined (evaluated).  We could either do a
1554     ;; eval-and-compile about all of the declarations or evaluate the
1555     ;; source file.
1556     (if (boundp 'gnus-newsgroup-variables)
1557         nil
1558       (load "gnus-sum.el" t t t))
1559     (require 'gnus)
1560     (require 'gnus-art)))
1561
1562 ;; Subject simplification.
1563
1564 (defun gnus-simplify-whitespace (str)
1565   "Remove excessive whitespace from STR."
1566   ;; Multiple spaces.
1567   (while (string-match "[ \t][ \t]+" str)
1568     (setq str (concat (substring str 0 (match-beginning 0))
1569                         " "
1570                         (substring str (match-end 0)))))
1571   ;; Leading spaces.
1572   (when (string-match "^[ \t]+" str)
1573     (setq str (substring str (match-end 0))))
1574   ;; Trailing spaces.
1575   (when (string-match "[ \t]+$" str)
1576     (setq str (substring str 0 (match-beginning 0))))
1577   str)
1578
1579 (defun gnus-simplify-all-whitespace (str)
1580   "Remove all whitespace from STR."
1581   (while (string-match "[ \t\n]+" str)
1582     (setq str (replace-match "" nil nil str)))
1583   str)
1584
1585 (defsubst gnus-simplify-subject-re (subject)
1586   "Remove \"Re:\" from subject lines."
1587   (if (string-match message-subject-re-regexp subject)
1588       (substring subject (match-end 0))
1589     subject))
1590
1591 (defun gnus-simplify-subject (subject &optional re-only)
1592   "Remove `Re:' and words in parentheses.
1593 If RE-ONLY is non-nil, strip leading `Re:'s only."
1594   (let ((case-fold-search t))           ;Ignore case.
1595     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1596     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1597       (setq subject (substring subject (match-end 0))))
1598     ;; Remove uninteresting prefixes.
1599     (when (and (not re-only)
1600                gnus-simplify-ignored-prefixes
1601                (string-match gnus-simplify-ignored-prefixes subject))
1602       (setq subject (substring subject (match-end 0))))
1603     ;; Remove words in parentheses from end.
1604     (unless re-only
1605       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1606         (setq subject (substring subject 0 (match-beginning 0)))))
1607     ;; Return subject string.
1608     subject))
1609
1610 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1611 ;; all whitespace.
1612 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1613   (goto-char (point-min))
1614   (while (re-search-forward regexp nil t)
1615     (replace-match (or newtext ""))))
1616
1617 (defun gnus-simplify-buffer-fuzzy ()
1618   "Simplify string in the buffer fuzzily.
1619 The string in the accessible portion of the current buffer is simplified.
1620 It is assumed to be a single-line subject.
1621 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1622 matter is removed.  Additional things can be deleted by setting
1623 `gnus-simplify-subject-fuzzy-regexp'."
1624   (let ((case-fold-search t)
1625         (modified-tick))
1626     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1627
1628     (while (not (eq modified-tick (buffer-modified-tick)))
1629       (setq modified-tick (buffer-modified-tick))
1630       (cond
1631        ((listp gnus-simplify-subject-fuzzy-regexp)
1632         (mapcar 'gnus-simplify-buffer-fuzzy-step
1633                 gnus-simplify-subject-fuzzy-regexp))
1634        (gnus-simplify-subject-fuzzy-regexp
1635         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1636       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1637       (gnus-simplify-buffer-fuzzy-step
1638        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1639       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1640
1641     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1642     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1643     (gnus-simplify-buffer-fuzzy-step " $")
1644     (gnus-simplify-buffer-fuzzy-step "^ +")))
1645
1646 (defun gnus-simplify-subject-fuzzy (subject)
1647   "Simplify a subject string fuzzily.
1648 See `gnus-simplify-buffer-fuzzy' for details."
1649   (save-excursion
1650     (gnus-set-work-buffer)
1651     (let ((case-fold-search t))
1652       ;; Remove uninteresting prefixes.
1653       (when (and gnus-simplify-ignored-prefixes
1654                  (string-match gnus-simplify-ignored-prefixes subject))
1655         (setq subject (substring subject (match-end 0))))
1656       (insert subject)
1657       (inline (gnus-simplify-buffer-fuzzy))
1658       (buffer-string))))
1659
1660 (defsubst gnus-simplify-subject-fully (subject)
1661   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1662   (cond
1663    (gnus-simplify-subject-functions
1664     (gnus-map-function gnus-simplify-subject-functions subject))
1665    ((null gnus-summary-gather-subject-limit)
1666     (gnus-simplify-subject-re subject))
1667    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1668     (gnus-simplify-subject-fuzzy subject))
1669    ((numberp gnus-summary-gather-subject-limit)
1670     (gnus-limit-string (gnus-simplify-subject-re subject)
1671                        gnus-summary-gather-subject-limit))
1672    (t
1673     subject)))
1674
1675 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1676   "Check whether two subjects are equal.
1677 If optional argument SIMPLE-FIRST is t, first argument is already
1678 simplified."
1679   (cond
1680    ((null simple-first)
1681     (equal (gnus-simplify-subject-fully s1)
1682            (gnus-simplify-subject-fully s2)))
1683    (t
1684     (equal s1
1685            (gnus-simplify-subject-fully s2)))))
1686
1687 (defun gnus-summary-bubble-group ()
1688   "Increase the score of the current group.
1689 This is a handy function to add to `gnus-summary-exit-hook' to
1690 increase the score of each group you read."
1691   (gnus-group-add-score gnus-newsgroup-name))
1692
1693 \f
1694 ;;;
1695 ;;; Gnus summary mode
1696 ;;;
1697
1698 (put 'gnus-summary-mode 'mode-class 'special)
1699
1700 (defvar gnus-article-commands-menu)
1701
1702 ;; Non-orthogonal keys
1703
1704 (gnus-define-keys gnus-summary-mode-map
1705   " " gnus-summary-next-page
1706   "\177" gnus-summary-prev-page
1707   [delete] gnus-summary-prev-page
1708   [backspace] gnus-summary-prev-page
1709   "\r" gnus-summary-scroll-up
1710   "\M-\r" gnus-summary-scroll-down
1711   "n" gnus-summary-next-unread-article
1712   "p" gnus-summary-prev-unread-article
1713   "N" gnus-summary-next-article
1714   "P" gnus-summary-prev-article
1715   "\M-\C-n" gnus-summary-next-same-subject
1716   "\M-\C-p" gnus-summary-prev-same-subject
1717   "\M-n" gnus-summary-next-unread-subject
1718   "\M-p" gnus-summary-prev-unread-subject
1719   "." gnus-summary-first-unread-article
1720   "," gnus-summary-best-unread-article
1721   "\M-s" gnus-summary-search-article-forward
1722   "\M-r" gnus-summary-search-article-backward
1723   "<" gnus-summary-beginning-of-article
1724   ">" gnus-summary-end-of-article
1725   "j" gnus-summary-goto-article
1726   "^" gnus-summary-refer-parent-article
1727   "\M-^" gnus-summary-refer-article
1728   "u" gnus-summary-tick-article-forward
1729   "!" gnus-summary-tick-article-forward
1730   "U" gnus-summary-tick-article-backward
1731   "d" gnus-summary-mark-as-read-forward
1732   "D" gnus-summary-mark-as-read-backward
1733   "E" gnus-summary-mark-as-expirable
1734   "\M-u" gnus-summary-clear-mark-forward
1735   "\M-U" gnus-summary-clear-mark-backward
1736   "k" gnus-summary-kill-same-subject-and-select
1737   "\C-k" gnus-summary-kill-same-subject
1738   "\M-\C-k" gnus-summary-kill-thread
1739   "\M-\C-l" gnus-summary-lower-thread
1740   "e" gnus-summary-edit-article
1741   "#" gnus-summary-mark-as-processable
1742   "\M-#" gnus-summary-unmark-as-processable
1743   "\M-\C-t" gnus-summary-toggle-threads
1744   "\M-\C-s" gnus-summary-show-thread
1745   "\M-\C-h" gnus-summary-hide-thread
1746   "\M-\C-f" gnus-summary-next-thread
1747   "\M-\C-b" gnus-summary-prev-thread
1748   [(meta down)] gnus-summary-next-thread
1749   [(meta up)] gnus-summary-prev-thread
1750   "\M-\C-u" gnus-summary-up-thread
1751   "\M-\C-d" gnus-summary-down-thread
1752   "&" gnus-summary-execute-command
1753   "c" gnus-summary-catchup-and-exit
1754   "\C-w" gnus-summary-mark-region-as-read
1755   "\C-t" gnus-summary-toggle-truncation
1756   "?" gnus-summary-mark-as-dormant
1757   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1758   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1759   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1760   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1761   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1762   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1763   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1764   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1765   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1766   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1767   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1768   "=" gnus-summary-expand-window
1769   "\C-x\C-s" gnus-summary-reselect-current-group
1770   "\M-g" gnus-summary-rescan-group
1771   "w" gnus-summary-stop-page-breaking
1772   "\C-c\C-r" gnus-summary-caesar-message
1773   "\M-t" gnus-summary-toggle-mime
1774   "f" gnus-summary-followup
1775   "F" gnus-summary-followup-with-original
1776   "C" gnus-summary-cancel-article
1777   "r" gnus-summary-reply
1778   "R" gnus-summary-reply-with-original
1779   "\C-c\C-f" gnus-summary-mail-forward
1780   "o" gnus-summary-save-article
1781   "\C-o" gnus-summary-save-article-mail
1782   "|" gnus-summary-pipe-output
1783   "\M-k" gnus-summary-edit-local-kill
1784   "\M-K" gnus-summary-edit-global-kill
1785   ;; "V" gnus-version
1786   "\C-c\C-d" gnus-summary-describe-group
1787   "q" gnus-summary-exit
1788   "Q" gnus-summary-exit-no-update
1789   "\C-c\C-i" gnus-info-find-node
1790   gnus-mouse-2 gnus-mouse-pick-article
1791   [follow-link] mouse-face
1792   "m" gnus-summary-mail-other-window
1793   "a" gnus-summary-post-news
1794   "i" gnus-summary-news-other-window
1795   "x" gnus-summary-limit-to-unread
1796   "s" gnus-summary-isearch-article
1797   "t" gnus-summary-toggle-header
1798   "g" gnus-summary-show-article
1799   "l" gnus-summary-goto-last-article
1800   "v" gnus-summary-preview-mime-message
1801   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1802   "\C-d" gnus-summary-enter-digest-group
1803   "\M-\C-d" gnus-summary-read-document
1804   "\M-\C-e" gnus-summary-edit-parameters
1805   "\M-\C-a" gnus-summary-customize-parameters
1806   "\C-c\C-b" gnus-bug
1807   "\C-c\C-n" gnus-namazu-search
1808   "*" gnus-cache-enter-article
1809   "\M-*" gnus-cache-remove-article
1810   "\M-&" gnus-summary-universal-argument
1811   "\C-l" gnus-recenter
1812   "I" gnus-summary-increase-score
1813   "L" gnus-summary-lower-score
1814   "\M-i" gnus-symbolic-argument
1815   "h" gnus-summary-select-article-buffer
1816
1817   "V" gnus-summary-score-map
1818   "X" gnus-uu-extract-map
1819   "S" gnus-summary-send-map)
1820
1821   ;; Sort of orthogonal keymap
1822 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1823   "t" gnus-summary-tick-article-forward
1824   "!" gnus-summary-tick-article-forward
1825   "d" gnus-summary-mark-as-read-forward
1826   "r" gnus-summary-mark-as-read-forward
1827   "c" gnus-summary-clear-mark-forward
1828   " " gnus-summary-clear-mark-forward
1829   "e" gnus-summary-mark-as-expirable
1830   "x" gnus-summary-mark-as-expirable
1831   "?" gnus-summary-mark-as-dormant
1832   "b" gnus-summary-set-bookmark
1833   "B" gnus-summary-remove-bookmark
1834   "#" gnus-summary-mark-as-processable
1835   "\M-#" gnus-summary-unmark-as-processable
1836   "S" gnus-summary-limit-include-expunged
1837   "C" gnus-summary-catchup
1838   "H" gnus-summary-catchup-to-here
1839   "h" gnus-summary-catchup-from-here
1840   "\C-c" gnus-summary-catchup-all
1841   "k" gnus-summary-kill-same-subject-and-select
1842   "K" gnus-summary-kill-same-subject
1843   "P" gnus-uu-mark-map)
1844
1845 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1846   "c" gnus-summary-clear-above
1847   "u" gnus-summary-tick-above
1848   "m" gnus-summary-mark-above
1849   "k" gnus-summary-kill-below)
1850
1851 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1852   "/" gnus-summary-limit-to-subject
1853   "n" gnus-summary-limit-to-articles
1854   "w" gnus-summary-pop-limit
1855   "s" gnus-summary-limit-to-subject
1856   "a" gnus-summary-limit-to-author
1857   "u" gnus-summary-limit-to-unread
1858   "m" gnus-summary-limit-to-marks
1859   "M" gnus-summary-limit-exclude-marks
1860   "v" gnus-summary-limit-to-score
1861   "*" gnus-summary-limit-include-cached
1862   "D" gnus-summary-limit-include-dormant
1863   "T" gnus-summary-limit-include-thread
1864   "d" gnus-summary-limit-exclude-dormant
1865   "t" gnus-summary-limit-to-age
1866   "." gnus-summary-limit-to-unseen
1867   "x" gnus-summary-limit-to-extra
1868   "p" gnus-summary-limit-to-display-predicate
1869   "E" gnus-summary-limit-include-expunged
1870   "c" gnus-summary-limit-exclude-childless-dormant
1871   "C" gnus-summary-limit-mark-excluded-as-read
1872   "o" gnus-summary-insert-old-articles
1873   "N" gnus-summary-insert-new-articles
1874   "r" gnus-summary-limit-to-replied
1875   "R" gnus-summary-limit-to-recipient)
1876
1877 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1878   "n" gnus-summary-next-unread-article
1879   "p" gnus-summary-prev-unread-article
1880   "N" gnus-summary-next-article
1881   "P" gnus-summary-prev-article
1882   "\C-n" gnus-summary-next-same-subject
1883   "\C-p" gnus-summary-prev-same-subject
1884   "\M-n" gnus-summary-next-unread-subject
1885   "\M-p" gnus-summary-prev-unread-subject
1886   "f" gnus-summary-first-unread-article
1887   "b" gnus-summary-best-unread-article
1888   "j" gnus-summary-goto-article
1889   "g" gnus-summary-goto-subject
1890   "l" gnus-summary-goto-last-article
1891   "o" gnus-summary-pop-article)
1892
1893 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1894   "k" gnus-summary-kill-thread
1895   "l" gnus-summary-lower-thread
1896   "i" gnus-summary-raise-thread
1897   "T" gnus-summary-toggle-threads
1898   "t" gnus-summary-rethread-current
1899   "^" gnus-summary-reparent-thread
1900   "s" gnus-summary-show-thread
1901   "S" gnus-summary-show-all-threads
1902   "h" gnus-summary-hide-thread
1903   "H" gnus-summary-hide-all-threads
1904   "n" gnus-summary-next-thread
1905   "p" gnus-summary-prev-thread
1906   "u" gnus-summary-up-thread
1907   "o" gnus-summary-top-thread
1908   "d" gnus-summary-down-thread
1909   "#" gnus-uu-mark-thread
1910   "\M-#" gnus-uu-unmark-thread)
1911
1912 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1913   "g" gnus-summary-prepare
1914   "c" gnus-summary-insert-cached-articles
1915   "d" gnus-summary-insert-dormant-articles)
1916
1917 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1918   "c" gnus-summary-catchup-and-exit
1919   "C" gnus-summary-catchup-all-and-exit
1920   "E" gnus-summary-exit-no-update
1921   "J" gnus-summary-jump-to-other-group
1922   "Q" gnus-summary-exit
1923   "Z" gnus-summary-exit
1924   "n" gnus-summary-catchup-and-goto-next-group
1925   "R" gnus-summary-reselect-current-group
1926   "G" gnus-summary-rescan-group
1927   "N" gnus-summary-next-group
1928   "s" gnus-summary-save-newsrc
1929   "P" gnus-summary-prev-group)
1930
1931 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1932   " " gnus-summary-next-page
1933   "n" gnus-summary-next-page
1934   "\177" gnus-summary-prev-page
1935   [delete] gnus-summary-prev-page
1936   "p" gnus-summary-prev-page
1937   "\r" gnus-summary-scroll-up
1938   "\M-\r" gnus-summary-scroll-down
1939   "<" gnus-summary-beginning-of-article
1940   ">" gnus-summary-end-of-article
1941   "b" gnus-summary-beginning-of-article
1942   "e" gnus-summary-end-of-article
1943   "^" gnus-summary-refer-parent-article
1944   "r" gnus-summary-refer-parent-article
1945   "D" gnus-summary-enter-digest-group
1946   "R" gnus-summary-refer-references
1947   "T" gnus-summary-refer-thread
1948   "g" gnus-summary-show-article
1949   "s" gnus-summary-isearch-article
1950   "P" gnus-summary-print-article
1951   "M" gnus-mailing-list-insinuate
1952   "t" gnus-article-babel)
1953
1954 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1955   "b" gnus-article-add-buttons
1956   "B" gnus-article-add-buttons-to-head
1957   "o" gnus-article-treat-overstrike
1958   "e" gnus-article-emphasize
1959   "w" gnus-article-fill-cited-article
1960   "Q" gnus-article-fill-long-lines
1961   "C" gnus-article-capitalize-sentences
1962   "c" gnus-article-remove-cr
1963   "Z" gnus-article-decode-HZ
1964   "A" gnus-article-treat-ansi-sequences
1965   "h" gnus-article-wash-html
1966   "u" gnus-article-unsplit-urls
1967   "f" gnus-article-display-x-face
1968   "l" gnus-summary-stop-page-breaking
1969   "r" gnus-summary-caesar-message
1970   "m" gnus-summary-morse-message
1971   "t" gnus-summary-toggle-header
1972   "g" gnus-treat-smiley
1973   "v" gnus-summary-verbose-headers
1974   "m" gnus-summary-toggle-mime
1975   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1976   "p" gnus-article-verify-x-pgp-sig
1977   "d" gnus-article-treat-dumbquotes
1978   "i" gnus-summary-idna-message)
1979
1980 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1981   ;; mnemonic: deuglif*Y*
1982   "u" gnus-article-outlook-unwrap-lines
1983   "a" gnus-article-outlook-repair-attribution
1984   "c" gnus-article-outlook-rearrange-citation
1985   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1986
1987 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1988   "a" gnus-article-hide
1989   "h" gnus-article-hide-headers
1990   "b" gnus-article-hide-boring-headers
1991   "s" gnus-article-hide-signature
1992   "c" gnus-article-hide-citation
1993   "C" gnus-article-hide-citation-in-followups
1994   "l" gnus-article-hide-list-identifiers
1995   "B" gnus-article-strip-banner
1996   "P" gnus-article-hide-pem
1997   "\C-c" gnus-article-hide-citation-maybe)
1998
1999 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2000   "a" gnus-article-highlight
2001   "h" gnus-article-highlight-headers
2002   "c" gnus-article-highlight-citation
2003   "s" gnus-article-highlight-signature)
2004
2005 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2006   "f" gnus-article-treat-fold-headers
2007   "u" gnus-article-treat-unfold-headers
2008   "n" gnus-article-treat-fold-newsgroups)
2009
2010 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2011   "x" gnus-article-display-x-face
2012   "d" gnus-article-display-face
2013   "s" gnus-treat-smiley
2014   "D" gnus-article-remove-images
2015   "f" gnus-treat-from-picon
2016   "m" gnus-treat-mail-picon
2017   "n" gnus-treat-newsgroups-picon)
2018
2019 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2020   "z" gnus-article-date-ut
2021   "u" gnus-article-date-ut
2022   "l" gnus-article-date-local
2023   "p" gnus-article-date-english
2024   "e" gnus-article-date-lapsed
2025   "o" gnus-article-date-original
2026   "i" gnus-article-date-iso8601
2027   "s" gnus-article-date-user)
2028
2029 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2030   "t" gnus-article-remove-trailing-blank-lines
2031   "l" gnus-article-strip-leading-blank-lines
2032   "m" gnus-article-strip-multiple-blank-lines
2033   "a" gnus-article-strip-blank-lines
2034   "A" gnus-article-strip-all-blank-lines
2035   "s" gnus-article-strip-leading-space
2036   "e" gnus-article-strip-trailing-space
2037   "w" gnus-article-remove-leading-whitespace)
2038
2039 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2040   "v" gnus-version
2041   "f" gnus-summary-fetch-faq
2042   "d" gnus-summary-describe-group
2043   "h" gnus-summary-describe-briefly
2044   "i" gnus-info-find-node
2045   "c" gnus-group-fetch-charter
2046   "C" gnus-group-fetch-control)
2047
2048 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2049   "e" gnus-summary-expire-articles
2050   "\M-\C-e" gnus-summary-expire-articles-now
2051   "\177" gnus-summary-delete-article
2052   [delete] gnus-summary-delete-article
2053   [backspace] gnus-summary-delete-article
2054   "m" gnus-summary-move-article
2055   "r" gnus-summary-respool-article
2056   "w" gnus-summary-edit-article
2057   "c" gnus-summary-copy-article
2058   "B" gnus-summary-crosspost-article
2059   "q" gnus-summary-respool-query
2060   "t" gnus-summary-respool-trace
2061   "i" gnus-summary-import-article
2062   "I" gnus-summary-create-article
2063   "p" gnus-summary-article-posted-p)
2064
2065 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2066   "o" gnus-summary-save-article
2067   "m" gnus-summary-save-article-mail
2068   "F" gnus-summary-write-article-file
2069   "r" gnus-summary-save-article-rmail
2070   "f" gnus-summary-save-article-file
2071   "b" gnus-summary-save-article-body-file
2072   "h" gnus-summary-save-article-folder
2073   "v" gnus-summary-save-article-vm
2074   "p" gnus-summary-pipe-output
2075   "P" gnus-summary-muttprint
2076   "s" gnus-soup-add-article)
2077
2078 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2079   "b" gnus-summary-display-buttonized
2080   "m" gnus-summary-repair-multipart
2081   "v" gnus-article-view-part
2082   "o" gnus-article-save-part
2083   "c" gnus-article-copy-part
2084   "C" gnus-article-view-part-as-charset
2085   "e" gnus-article-view-part-externally
2086   "E" gnus-article-encrypt-body
2087   "i" gnus-article-inline-part
2088   "|" gnus-article-pipe-part)
2089
2090 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2091   "p" gnus-summary-mark-as-processable
2092   "u" gnus-summary-unmark-as-processable
2093   "U" gnus-summary-unmark-all-processable
2094   "v" gnus-uu-mark-over
2095   "s" gnus-uu-mark-series
2096   "r" gnus-uu-mark-region
2097   "g" gnus-uu-unmark-region
2098   "R" gnus-uu-mark-by-regexp
2099   "G" gnus-uu-unmark-by-regexp
2100   "t" gnus-uu-mark-thread
2101   "T" gnus-uu-unmark-thread
2102   "a" gnus-uu-mark-all
2103   "b" gnus-uu-mark-buffer
2104   "S" gnus-uu-mark-sparse
2105   "k" gnus-summary-kill-process-mark
2106   "y" gnus-summary-yank-process-mark
2107   "w" gnus-summary-save-process-mark
2108   "i" gnus-uu-invert-processable)
2109
2110 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2111   ;;"x" gnus-uu-extract-any
2112   "m" gnus-summary-save-parts
2113   "u" gnus-uu-decode-uu
2114   "U" gnus-uu-decode-uu-and-save
2115   "s" gnus-uu-decode-unshar
2116   "S" gnus-uu-decode-unshar-and-save
2117   "o" gnus-uu-decode-save
2118   "O" gnus-uu-decode-save
2119   "b" gnus-uu-decode-binhex
2120   "B" gnus-uu-decode-binhex
2121   "p" gnus-uu-decode-postscript
2122   "P" gnus-uu-decode-postscript-and-save)
2123
2124 (gnus-define-keys
2125     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2126   "u" gnus-uu-decode-uu-view
2127   "U" gnus-uu-decode-uu-and-save-view
2128   "s" gnus-uu-decode-unshar-view
2129   "S" gnus-uu-decode-unshar-and-save-view
2130   "o" gnus-uu-decode-save-view
2131   "O" gnus-uu-decode-save-view
2132   "b" gnus-uu-decode-binhex-view
2133   "B" gnus-uu-decode-binhex-view
2134   "p" gnus-uu-decode-postscript-view
2135   "P" gnus-uu-decode-postscript-and-save-view)
2136
2137 (defvar gnus-article-post-menu nil)
2138
2139 (defconst gnus-summary-menu-maxlen 20)
2140
2141 (defun gnus-summary-menu-split (menu)
2142   ;; If we have lots of elements, divide them into groups of 20
2143   ;; and make a pane (or submenu) for each one.
2144   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2145       (let ((menu menu) sublists next
2146             (i 1))
2147         (while menu
2148           ;; Pull off the next gnus-summary-menu-maxlen elements
2149           ;; and make them the next element of sublist.
2150           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2151           (if next
2152               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2153                       nil))
2154           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2155                                              (aref (car (last menu)) 0)) menu)
2156                                sublists))
2157           (setq i (1+ i))
2158           (setq menu next))
2159         (nreverse sublists))
2160     ;; Few elements--put them all in one pane.
2161     menu))
2162
2163 (defun gnus-summary-make-menu-bar ()
2164   (gnus-turn-off-edit-menu 'summary)
2165
2166   (unless (boundp 'gnus-summary-misc-menu)
2167
2168     (easy-menu-define
2169       gnus-summary-kill-menu gnus-summary-mode-map ""
2170       (cons
2171        "Score"
2172        (nconc
2173         (list
2174          ["Customize" gnus-score-customize t])
2175         (gnus-make-score-map 'increase)
2176         (gnus-make-score-map 'lower)
2177         '(("Mark"
2178            ["Kill below" gnus-summary-kill-below t]
2179            ["Mark above" gnus-summary-mark-above t]
2180            ["Tick above" gnus-summary-tick-above t]
2181            ["Clear above" gnus-summary-clear-above t])
2182           ["Current score" gnus-summary-current-score t]
2183           ["Set score" gnus-summary-set-score t]
2184           ["Switch current score file..." gnus-score-change-score-file t]
2185           ["Set mark below..." gnus-score-set-mark-below t]
2186           ["Set expunge below..." gnus-score-set-expunge-below t]
2187           ["Edit current score file" gnus-score-edit-current-scores t]
2188           ["Edit score file" gnus-score-edit-file t]
2189           ["Trace score" gnus-score-find-trace t]
2190           ["Find words" gnus-score-find-favourite-words t]
2191           ["Rescore buffer" gnus-summary-rescore t]
2192           ["Increase score..." gnus-summary-increase-score t]
2193           ["Lower score..." gnus-summary-lower-score t]))))
2194
2195     ;; Define both the Article menu in the summary buffer and the
2196     ;; equivalent Commands menu in the article buffer here for
2197     ;; consistency.
2198     (let ((innards
2199            `(("Hide"
2200               ["All" gnus-article-hide t]
2201               ["Headers" gnus-article-hide-headers t]
2202               ["Signature" gnus-article-hide-signature t]
2203               ["Citation" gnus-article-hide-citation t]
2204               ["List identifiers" gnus-article-hide-list-identifiers t]
2205               ["Banner" gnus-article-strip-banner t]
2206               ["Boring headers" gnus-article-hide-boring-headers t])
2207              ("Highlight"
2208               ["All" gnus-article-highlight t]
2209               ["Headers" gnus-article-highlight-headers t]
2210               ["Signature" gnus-article-highlight-signature t]
2211               ["Citation" gnus-article-highlight-citation t])
2212              ("Date"
2213               ["Local" gnus-article-date-local t]
2214               ["ISO8601" gnus-article-date-iso8601 t]
2215               ["UT" gnus-article-date-ut t]
2216               ["Original" gnus-article-date-original t]
2217               ["Lapsed" gnus-article-date-lapsed t]
2218               ["User-defined" gnus-article-date-user t])
2219              ("Display"
2220               ["Remove images" gnus-article-remove-images t]
2221               ["Toggle smiley" gnus-treat-smiley t]
2222               ["Show X-Face" gnus-article-display-x-face t]
2223               ["Show picons in From" gnus-treat-from-picon t]
2224               ["Show picons in mail headers" gnus-treat-mail-picon t]
2225               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2226               ("View as different encoding"
2227                ,@(gnus-summary-menu-split
2228                   (mapcar
2229                    (lambda (cs)
2230                      ;; Since easymenu under Emacs doesn't allow
2231                      ;; lambda forms for menu commands, we should
2232                      ;; provide intern'ed function symbols.
2233                      (let ((command (intern (format "\
2234 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2235                        (fset command
2236                              `(lambda ()
2237                                 (interactive)
2238                                 (let ((gnus-summary-show-article-charset-alist
2239                                        '((1 . ,cs))))
2240                                   (gnus-summary-show-article 1))))
2241                        `[,(symbol-name cs) ,command t]))
2242                    (sort (if (fboundp 'coding-system-list)
2243                              (coding-system-list)
2244                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2245                            )
2246                          'string<)))))
2247              ("Washing"
2248               ("Remove Blanks"
2249                ["Leading" gnus-article-strip-leading-blank-lines t]
2250                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2251                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2252                ["All of the above" gnus-article-strip-blank-lines t]
2253                ["All" gnus-article-strip-all-blank-lines t]
2254                ["Leading space" gnus-article-strip-leading-space t]
2255                ["Trailing space" gnus-article-strip-trailing-space t]
2256                ["Leading space in headers"
2257                 gnus-article-remove-leading-whitespace t])
2258               ["Overstrike" gnus-article-treat-overstrike t]
2259               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2260               ["Emphasis" gnus-article-emphasize t]
2261               ["Word wrap" gnus-article-fill-cited-article t]
2262               ["Fill long lines" gnus-article-fill-long-lines t]
2263               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2264               ["Remove CR" gnus-article-remove-cr t]
2265               ["Rot 13" gnus-summary-caesar-message
2266                ,@(if (featurep 'xemacs) '(t)
2267                    '(:help "\"Caesar rotate\" article by 13"))]
2268               ["De-IDNA" gnus-summary-idna-message t]
2269               ["Morse decode" gnus-summary-morse-message t]
2270               ["Unix pipe..." gnus-summary-pipe-message t]
2271               ["Add buttons" gnus-article-add-buttons t]
2272               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2273               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2274               ["Toggle MIME" gnus-summary-toggle-mime t]
2275               ["Verbose header" gnus-summary-verbose-headers t]
2276               ["Toggle header" gnus-summary-toggle-header t]
2277               ["Unfold headers" gnus-article-treat-unfold-headers t]
2278               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2279               ["Html" gnus-article-wash-html t]
2280               ["Unsplit URLs" gnus-article-unsplit-urls t]
2281               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2282               ["Decode HZ" gnus-article-decode-HZ t]
2283               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2284               ("(Outlook) Deuglify"
2285                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2286                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2287                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2288                ["Full (Outlook) deuglify"
2289                 gnus-article-outlook-deuglify-article t])
2290               )
2291              ("Output"
2292               ["Save in default format..." gnus-summary-save-article
2293                ,@(if (featurep 'xemacs) '(t)
2294                    '(:help "Save article using default method"))]
2295               ["Save in file..." gnus-summary-save-article-file
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Save article in file"))]
2298               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2299               ["Save in MH folder..." gnus-summary-save-article-folder t]
2300               ["Save in VM folder..." gnus-summary-save-article-vm t]
2301               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2302               ["Save body in file..." gnus-summary-save-article-body-file t]
2303               ["Pipe through a filter..." gnus-summary-pipe-output t]
2304               ["Add to SOUP packet" gnus-soup-add-article t]
2305               ["Print with Muttprint..." gnus-summary-muttprint t]
2306               ["Print" gnus-summary-print-article
2307                ,@(if (featurep 'xemacs) '(t)
2308                    '(:help "Generate and print a PostScript image"))])
2309              ("Copy, move,... (Backend)"
2310               ,@(if (featurep 'xemacs) nil
2311                   '(:help "Copying, moving, expiring articles..."))
2312               ["Respool article..." gnus-summary-respool-article t]
2313               ["Move article..." gnus-summary-move-article
2314                (gnus-check-backend-function
2315                 'request-move-article gnus-newsgroup-name)]
2316               ["Copy article..." gnus-summary-copy-article t]
2317               ["Crosspost article..." gnus-summary-crosspost-article
2318                (gnus-check-backend-function
2319                 'request-replace-article gnus-newsgroup-name)]
2320               ["Import file..." gnus-summary-import-article
2321                (gnus-check-backend-function
2322                 'request-accept-article gnus-newsgroup-name)]
2323               ["Create article..." gnus-summary-create-article
2324                (gnus-check-backend-function
2325                 'request-accept-article gnus-newsgroup-name)]
2326               ["Check if posted" gnus-summary-article-posted-p t]
2327               ["Edit article" gnus-summary-edit-article
2328                (not (gnus-group-read-only-p))]
2329               ["Delete article" gnus-summary-delete-article
2330                (gnus-check-backend-function
2331                 'request-expire-articles gnus-newsgroup-name)]
2332               ["Query respool" gnus-summary-respool-query t]
2333               ["Trace respool" gnus-summary-respool-trace t]
2334               ["Delete expirable articles" gnus-summary-expire-articles-now
2335                (gnus-check-backend-function
2336                 'request-expire-articles gnus-newsgroup-name)])
2337              ("Extract"
2338               ["Uudecode" gnus-uu-decode-uu
2339                ,@(if (featurep 'xemacs) '(t)
2340                    '(:help "Decode uuencoded article(s)"))]
2341               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2342               ["Unshar" gnus-uu-decode-unshar t]
2343               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2344               ["Save" gnus-uu-decode-save t]
2345               ["Binhex" gnus-uu-decode-binhex t]
2346               ["Postscript" gnus-uu-decode-postscript t])
2347              ("Cache"
2348               ["Enter article" gnus-cache-enter-article t]
2349               ["Remove article" gnus-cache-remove-article t])
2350              ["Translate" gnus-article-babel t]
2351              ["Select article buffer" gnus-summary-select-article-buffer t]
2352              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2353              ["Isearch article..." gnus-summary-isearch-article t]
2354              ["Beginning of the article" gnus-summary-beginning-of-article t]
2355              ["End of the article" gnus-summary-end-of-article t]
2356              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2357              ["Fetch referenced articles" gnus-summary-refer-references t]
2358              ["Fetch current thread" gnus-summary-refer-thread t]
2359              ["Fetch article with id..." gnus-summary-refer-article t]
2360              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2361              ["Redisplay" gnus-summary-show-article t]
2362              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2363       (easy-menu-define
2364         gnus-summary-article-menu gnus-summary-mode-map ""
2365         (cons "Article" innards))
2366
2367       (if (not (keymapp gnus-summary-article-menu))
2368           (easy-menu-define
2369             gnus-article-commands-menu gnus-article-mode-map ""
2370             (cons "Commands" innards))
2371         ;; in Emacs, don't share menu.
2372         (setq gnus-article-commands-menu
2373               (copy-keymap gnus-summary-article-menu))
2374         (define-key gnus-article-mode-map [menu-bar commands]
2375           (cons "Commands" gnus-article-commands-menu))))
2376
2377     (easy-menu-define
2378       gnus-summary-thread-menu gnus-summary-mode-map ""
2379       '("Threads"
2380         ["Find all messages in thread" gnus-summary-refer-thread t]
2381         ["Toggle threading" gnus-summary-toggle-threads t]
2382         ["Hide threads" gnus-summary-hide-all-threads t]
2383         ["Show threads" gnus-summary-show-all-threads t]
2384         ["Hide thread" gnus-summary-hide-thread t]
2385         ["Show thread" gnus-summary-show-thread t]
2386         ["Go to next thread" gnus-summary-next-thread t]
2387         ["Go to previous thread" gnus-summary-prev-thread t]
2388         ["Go down thread" gnus-summary-down-thread t]
2389         ["Go up thread" gnus-summary-up-thread t]
2390         ["Top of thread" gnus-summary-top-thread t]
2391         ["Mark thread as read" gnus-summary-kill-thread t]
2392         ["Lower thread score" gnus-summary-lower-thread t]
2393         ["Raise thread score" gnus-summary-raise-thread t]
2394         ["Rethread current" gnus-summary-rethread-current t]))
2395
2396     (easy-menu-define
2397       gnus-summary-post-menu gnus-summary-mode-map ""
2398       `("Post"
2399         ["Send a message (mail or news)" gnus-summary-post-news
2400          ,@(if (featurep 'xemacs) '(t)
2401              '(:help "Compose a new message (mail or news)"))]
2402         ["Followup" gnus-summary-followup
2403          ,@(if (featurep 'xemacs) '(t)
2404              '(:help "Post followup to this article"))]
2405         ["Followup and yank" gnus-summary-followup-with-original
2406          ,@(if (featurep 'xemacs) '(t)
2407              '(:help "Post followup to this article, quoting its contents"))]
2408         ["Supersede article" gnus-summary-supersede-article t]
2409         ["Cancel article" gnus-summary-cancel-article
2410          ,@(if (featurep 'xemacs) '(t)
2411              '(:help "Cancel an article you posted"))]
2412         ["Reply" gnus-summary-reply t]
2413         ["Reply and yank" gnus-summary-reply-with-original t]
2414         ["Wide reply" gnus-summary-wide-reply t]
2415         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2416          ,@(if (featurep 'xemacs) '(t)
2417              '(:help "Mail a reply, quoting this article"))]
2418         ["Very wide reply" gnus-summary-very-wide-reply t]
2419         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2420          ,@(if (featurep 'xemacs) '(t)
2421              '(:help "Mail a very wide reply, quoting this article"))]
2422         ["Mail forward" gnus-summary-mail-forward t]
2423         ["Post forward" gnus-summary-post-forward t]
2424         ["Digest and mail" gnus-summary-digest-mail-forward t]
2425         ["Digest and post" gnus-summary-digest-post-forward t]
2426         ["Resend message" gnus-summary-resend-message t]
2427         ["Resend message edit" gnus-summary-resend-message-edit t]
2428         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2429         ["Send a mail" gnus-summary-mail-other-window t]
2430         ["Create a local message" gnus-summary-news-other-window t]
2431         ["Uuencode and post" gnus-uu-post-news
2432          ,@(if (featurep 'xemacs) '(t)
2433              '(:help "Post a uuencoded article"))]
2434         ["Followup via news" gnus-summary-followup-to-mail t]
2435         ["Followup via news and yank"
2436          gnus-summary-followup-to-mail-with-original t]
2437         ;;("Draft"
2438         ;;["Send" gnus-summary-send-draft t]
2439         ;;["Send bounced" gnus-resend-bounced-mail t])
2440         ))
2441
2442     (cond
2443      ((not (keymapp gnus-summary-post-menu))
2444       (setq gnus-article-post-menu gnus-summary-post-menu))
2445      ((not gnus-article-post-menu)
2446       ;; Don't share post menu.
2447       (setq gnus-article-post-menu
2448             (copy-keymap gnus-summary-post-menu))))
2449     (define-key gnus-article-mode-map [menu-bar post]
2450       (cons "Post" gnus-article-post-menu))
2451
2452     (easy-menu-define
2453       gnus-summary-misc-menu gnus-summary-mode-map ""
2454       `("Gnus"
2455         ("Mark Read"
2456          ["Mark as read" gnus-summary-mark-as-read-forward t]
2457          ["Mark same subject and select"
2458           gnus-summary-kill-same-subject-and-select t]
2459          ["Mark same subject" gnus-summary-kill-same-subject t]
2460          ["Catchup" gnus-summary-catchup
2461           ,@(if (featurep 'xemacs) '(t)
2462               '(:help "Mark unread articles in this group as read"))]
2463          ["Catchup all" gnus-summary-catchup-all t]
2464          ["Catchup to here" gnus-summary-catchup-to-here t]
2465          ["Catchup from here" gnus-summary-catchup-from-here t]
2466          ["Catchup region" gnus-summary-mark-region-as-read
2467           (gnus-mark-active-p)]
2468          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2469         ("Mark Various"
2470          ["Tick" gnus-summary-tick-article-forward t]
2471          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2472          ["Remove marks" gnus-summary-clear-mark-forward t]
2473          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2474          ["Set bookmark" gnus-summary-set-bookmark t]
2475          ["Remove bookmark" gnus-summary-remove-bookmark t])
2476         ("Limit to"
2477          ["Marks..." gnus-summary-limit-to-marks t]
2478          ["Subject..." gnus-summary-limit-to-subject t]
2479          ["Author..." gnus-summary-limit-to-author t]
2480          ["Recipient..." gnus-summary-limit-to-recipient t]
2481          ["Age..." gnus-summary-limit-to-age t]
2482          ["Extra..." gnus-summary-limit-to-extra t]
2483          ["Score..." gnus-summary-limit-to-score t]
2484          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2485          ["Unread" gnus-summary-limit-to-unread t]
2486          ["Unseen" gnus-summary-limit-to-unseen t]
2487          ["Replied" gnus-summary-limit-to-replied t]
2488          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2489          ["Next articles" gnus-summary-limit-to-articles t]
2490          ["Pop limit" gnus-summary-pop-limit t]
2491          ["Show dormant" gnus-summary-limit-include-dormant t]
2492          ["Hide childless dormant"
2493           gnus-summary-limit-exclude-childless-dormant t]
2494          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2495          ["Hide marked" gnus-summary-limit-exclude-marks t]
2496          ["Show expunged" gnus-summary-limit-include-expunged t])
2497         ("Process Mark"
2498          ["Set mark" gnus-summary-mark-as-processable t]
2499          ["Remove mark" gnus-summary-unmark-as-processable t]
2500          ["Remove all marks" gnus-summary-unmark-all-processable t]
2501          ["Invert marks" gnus-uu-invert-processable t]
2502          ["Mark above" gnus-uu-mark-over t]
2503          ["Mark series" gnus-uu-mark-series t]
2504          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2505          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2506          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2507          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2508          ["Mark all" gnus-uu-mark-all t]
2509          ["Mark buffer" gnus-uu-mark-buffer t]
2510          ["Mark sparse" gnus-uu-mark-sparse t]
2511          ["Mark thread" gnus-uu-mark-thread t]
2512          ["Unmark thread" gnus-uu-unmark-thread t]
2513          ("Process Mark Sets"
2514           ["Kill" gnus-summary-kill-process-mark t]
2515           ["Yank" gnus-summary-yank-process-mark
2516            gnus-newsgroup-process-stack]
2517           ["Save" gnus-summary-save-process-mark t]
2518           ["Run command on marked..." gnus-summary-universal-argument t]))
2519         ("Scroll article"
2520          ["Page forward" gnus-summary-next-page
2521           ,@(if (featurep 'xemacs) '(t)
2522               '(:help "Show next page of article"))]
2523          ["Page backward" gnus-summary-prev-page
2524           ,@(if (featurep 'xemacs) '(t)
2525               '(:help "Show previous page of article"))]
2526          ["Line forward" gnus-summary-scroll-up t])
2527         ("Move"
2528          ["Next unread article" gnus-summary-next-unread-article t]
2529          ["Previous unread article" gnus-summary-prev-unread-article t]
2530          ["Next article" gnus-summary-next-article t]
2531          ["Previous article" gnus-summary-prev-article t]
2532          ["Next unread subject" gnus-summary-next-unread-subject t]
2533          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2534          ["Next article same subject" gnus-summary-next-same-subject t]
2535          ["Previous article same subject" gnus-summary-prev-same-subject t]
2536          ["First unread article" gnus-summary-first-unread-article t]
2537          ["Best unread article" gnus-summary-best-unread-article t]
2538          ["Go to subject number..." gnus-summary-goto-subject t]
2539          ["Go to article number..." gnus-summary-goto-article t]
2540          ["Go to the last article" gnus-summary-goto-last-article t]
2541          ["Pop article off history" gnus-summary-pop-article t])
2542         ("Sort"
2543          ["Sort by number" gnus-summary-sort-by-number t]
2544          ["Sort by author" gnus-summary-sort-by-author t]
2545          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2546          ["Sort by subject" gnus-summary-sort-by-subject t]
2547          ["Sort by date" gnus-summary-sort-by-date t]
2548          ["Sort by score" gnus-summary-sort-by-score t]
2549          ["Sort by lines" gnus-summary-sort-by-lines t]
2550          ["Sort by characters" gnus-summary-sort-by-chars t]
2551          ["Randomize" gnus-summary-sort-by-random t]
2552          ["Original sort" gnus-summary-sort-by-original t])
2553         ("Help"
2554          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2555          ["Describe group" gnus-summary-describe-group t]
2556          ["Fetch charter" gnus-group-fetch-charter
2557           ,@(if (featurep 'xemacs) nil
2558               '(:help "Display the charter of the current group"))]
2559          ["Fetch control message" gnus-group-fetch-control
2560           ,@(if (featurep 'xemacs) nil
2561               '(:help "Display the archived control message for the current group"))]
2562          ["Read manual" gnus-info-find-node t])
2563         ("Modes"
2564          ["Pick and read" gnus-pick-mode t]
2565          ["Binary" gnus-binary-mode t])
2566         ("Regeneration"
2567          ["Regenerate" gnus-summary-prepare t]
2568          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2569          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2570          ["Toggle threading" gnus-summary-toggle-threads t])
2571         ["See old articles" gnus-summary-insert-old-articles t]
2572         ["See new articles" gnus-summary-insert-new-articles t]
2573         ["Filter articles..." gnus-summary-execute-command t]
2574         ["Run command on articles..." gnus-summary-universal-argument t]
2575         ["Search articles forward..." gnus-summary-search-article-forward t]
2576         ["Search articles backward..." gnus-summary-search-article-backward t]
2577         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2578         ["Expand window" gnus-summary-expand-window t]
2579         ["Expire expirable articles" gnus-summary-expire-articles
2580          (gnus-check-backend-function
2581           'request-expire-articles gnus-newsgroup-name)]
2582         ["Edit local kill file" gnus-summary-edit-local-kill t]
2583         ["Edit main kill file" gnus-summary-edit-global-kill t]
2584         ["Edit group parameters" gnus-summary-edit-parameters t]
2585         ["Customize group parameters" gnus-summary-customize-parameters t]
2586         ["Send a bug report" gnus-bug t]
2587         ("Exit"
2588          ["Catchup and exit" gnus-summary-catchup-and-exit
2589           ,@(if (featurep 'xemacs) '(t)
2590               '(:help "Mark unread articles in this group as read, then exit"))]
2591          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2592          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2593          ["Exit group" gnus-summary-exit
2594           ,@(if (featurep 'xemacs) '(t)
2595               '(:help "Exit current group, return to group selection mode"))]
2596          ["Exit group without updating" gnus-summary-exit-no-update t]
2597          ["Exit and goto next group" gnus-summary-next-group t]
2598          ["Exit and goto prev group" gnus-summary-prev-group t]
2599          ["Reselect group" gnus-summary-reselect-current-group t]
2600          ["Rescan group" gnus-summary-rescan-group t]
2601          ["Update dribble" gnus-summary-save-newsrc t])))
2602
2603     (gnus-run-hooks 'gnus-summary-menu-hook)))
2604
2605 (defvar gnus-summary-tool-bar-map nil)
2606
2607 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2608 (defun gnus-summary-make-tool-bar ()
2609   (if (and (fboundp 'tool-bar-add-item-from-menu)
2610            (default-value 'tool-bar-mode)
2611            (not gnus-summary-tool-bar-map))
2612       (setq gnus-summary-tool-bar-map
2613             (let ((tool-bar-map (make-sparse-keymap))
2614                   (load-path (mm-image-load-path)))
2615               (tool-bar-add-item-from-menu
2616                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2617               (tool-bar-add-item-from-menu
2618                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-post-news "post" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-followup "followup" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-reply "reply" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2647               tool-bar-map)))
2648   (if gnus-summary-tool-bar-map
2649       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2650
2651 (defun gnus-score-set-default (var value)
2652   "A version of set that updates the GNU Emacs menu-bar."
2653   (set var value)
2654   ;; It is the message that forces the active status to be updated.
2655   (message ""))
2656
2657 (defun gnus-make-score-map (type)
2658   "Make a summary score map of type TYPE."
2659   (if t
2660       nil
2661     (let ((headers '(("author" "from" string)
2662                      ("subject" "subject" string)
2663                      ("article body" "body" string)
2664                      ("article head" "head" string)
2665                      ("xref" "xref" string)
2666                      ("extra header" "extra" string)
2667                      ("lines" "lines" number)
2668                      ("followups to author" "followup" string)))
2669           (types '((number ("less than" <)
2670                            ("greater than" >)
2671                            ("equal" =))
2672                    (string ("substring" s)
2673                            ("exact string" e)
2674                            ("fuzzy string" f)
2675                            ("regexp" r))))
2676           (perms '(("temporary" (current-time-string))
2677                    ("permanent" nil)
2678                    ("immediate" now)))
2679           header)
2680       (list
2681        (apply
2682         'nconc
2683         (list
2684          (if (eq type 'lower)
2685              "Lower score"
2686            "Increase score"))
2687         (let (outh)
2688           (while headers
2689             (setq header (car headers))
2690             (setq outh
2691                   (cons
2692                    (apply
2693                     'nconc
2694                     (list (car header))
2695                     (let ((ts (cdr (assoc (nth 2 header) types)))
2696                           outt)
2697                       (while ts
2698                         (setq outt
2699                               (cons
2700                                (apply
2701                                 'nconc
2702                                 (list (caar ts))
2703                                 (let ((ps perms)
2704                                       outp)
2705                                   (while ps
2706                                     (setq outp
2707                                           (cons
2708                                            (vector
2709                                             (caar ps)
2710                                             (list
2711                                              'gnus-summary-score-entry
2712                                              (nth 1 header)
2713                                              (if (or (string= (nth 1 header)
2714                                                               "head")
2715                                                      (string= (nth 1 header)
2716                                                               "body"))
2717                                                  ""
2718                                                (list 'gnus-summary-header
2719                                                      (nth 1 header)))
2720                                              (list 'quote (nth 1 (car ts)))
2721                                              (list 'gnus-score-delta-default
2722                                                    nil)
2723                                              (nth 1 (car ps))
2724                                              t)
2725                                             t)
2726                                            outp))
2727                                     (setq ps (cdr ps)))
2728                                   (list (nreverse outp))))
2729                                outt))
2730                         (setq ts (cdr ts)))
2731                       (list (nreverse outt))))
2732                    outh))
2733             (setq headers (cdr headers)))
2734           (list (nreverse outh))))))))
2735
2736 \f
2737
2738 (defun gnus-summary-mode (&optional group)
2739   "Major mode for reading articles.
2740
2741 All normal editing commands are switched off.
2742 \\<gnus-summary-mode-map>
2743 Each line in this buffer represents one article.  To read an
2744 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2745 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2746 respectively.
2747
2748 You can also post articles and send mail from this buffer.  To
2749 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2750 of an article, type `\\[gnus-summary-reply]'.
2751
2752 There are approx. one gazillion commands you can execute in this
2753 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2754
2755 The following commands are available:
2756
2757 \\{gnus-summary-mode-map}"
2758   (interactive)
2759   (kill-all-local-variables)
2760   (when (gnus-visual-p 'summary-menu 'menu)
2761     (gnus-summary-make-menu-bar)
2762     (gnus-summary-make-tool-bar))
2763   (gnus-summary-make-local-variables)
2764   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2765     (gnus-summary-make-local-variables))
2766   (gnus-make-thread-indent-array)
2767   (gnus-simplify-mode-line)
2768   (setq major-mode 'gnus-summary-mode)
2769   (setq mode-name "Summary")
2770   (make-local-variable 'minor-mode-alist)
2771   (use-local-map gnus-summary-mode-map)
2772   (buffer-disable-undo)
2773   (setq buffer-read-only t              ;Disable modification
2774         show-trailing-whitespace nil)
2775   (setq truncate-lines t)
2776   (setq selective-display t)
2777   (setq selective-display-ellipses t)   ;Display `...'
2778   (gnus-summary-set-display-table)
2779   (gnus-set-default-directory)
2780   (setq gnus-newsgroup-name group)
2781   (unless (gnus-news-group-p group)
2782     (setq gnus-newsgroup-incorporated
2783           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2784   (make-local-variable 'gnus-summary-line-format)
2785   (make-local-variable 'gnus-summary-line-format-spec)
2786   (make-local-variable 'gnus-summary-dummy-line-format)
2787   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2788   (make-local-variable 'gnus-summary-mark-positions)
2789   (gnus-make-local-hook 'pre-command-hook)
2790   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2791   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2792   (turn-on-gnus-mailing-list-mode)
2793   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2794   (gnus-update-summary-mark-positions))
2795
2796 (defun gnus-summary-make-local-variables ()
2797   "Make all the local summary buffer variables."
2798   (let (global)
2799     (dolist (local gnus-summary-local-variables)
2800       (if (consp local)
2801           (progn
2802             (if (eq (cdr local) 'global)
2803                 ;; Copy the global value of the variable.
2804                 (setq global (symbol-value (car local)))
2805               ;; Use the value from the list.
2806               (setq global (eval (cdr local))))
2807             (set (make-local-variable (car local)) global))
2808         ;; Simple nil-valued local variable.
2809         (set (make-local-variable local) nil)))))
2810
2811 (defun gnus-summary-clear-local-variables ()
2812   (let ((locals gnus-summary-local-variables))
2813     (while locals
2814       (if (consp (car locals))
2815           (and (symbolp (caar locals))
2816                (set (caar locals) nil))
2817         (and (symbolp (car locals))
2818              (set (car locals) nil)))
2819       (setq locals (cdr locals)))))
2820
2821 ;; Summary data functions.
2822
2823 (defmacro gnus-data-number (data)
2824   `(car ,data))
2825
2826 (defmacro gnus-data-set-number (data number)
2827   `(setcar ,data ,number))
2828
2829 (defmacro gnus-data-mark (data)
2830   `(nth 1 ,data))
2831
2832 (defmacro gnus-data-set-mark (data mark)
2833   `(setcar (nthcdr 1 ,data) ,mark))
2834
2835 (defmacro gnus-data-pos (data)
2836   `(nth 2 ,data))
2837
2838 (defmacro gnus-data-set-pos (data pos)
2839   `(setcar (nthcdr 2 ,data) ,pos))
2840
2841 (defmacro gnus-data-header (data)
2842   `(nth 3 ,data))
2843
2844 (defmacro gnus-data-set-header (data header)
2845   `(setcar (nthcdr 3 ,data) ,header))
2846
2847 (defmacro gnus-data-level (data)
2848   `(nth 4 ,data))
2849
2850 (defmacro gnus-data-unread-p (data)
2851   `(= (nth 1 ,data) gnus-unread-mark))
2852
2853 (defmacro gnus-data-read-p (data)
2854   `(/= (nth 1 ,data) gnus-unread-mark))
2855
2856 (defmacro gnus-data-pseudo-p (data)
2857   `(consp (nth 3 ,data)))
2858
2859 (defmacro gnus-data-find (number)
2860   `(assq ,number gnus-newsgroup-data))
2861
2862 (defmacro gnus-data-find-list (number &optional data)
2863   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2864      (memq (assq ,number bdata)
2865            bdata)))
2866
2867 (defmacro gnus-data-make (number mark pos header level)
2868   `(list ,number ,mark ,pos ,header ,level))
2869
2870 (defun gnus-data-enter (after-article number mark pos header level offset)
2871   (let ((data (gnus-data-find-list after-article)))
2872     (unless data
2873       (error "No such article: %d" after-article))
2874     (setcdr data (cons (gnus-data-make number mark pos header level)
2875                        (cdr data)))
2876     (setq gnus-newsgroup-data-reverse nil)
2877     (gnus-data-update-list (cddr data) offset)))
2878
2879 (defun gnus-data-enter-list (after-article list &optional offset)
2880   (when list
2881     (let ((data (and after-article (gnus-data-find-list after-article)))
2882           (ilist list))
2883       (if (not (or data
2884                    after-article))
2885           (let ((odata gnus-newsgroup-data))
2886             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2887             (when offset
2888               (gnus-data-update-list odata offset)))
2889         ;; Find the last element in the list to be spliced into the main
2890         ;; list.
2891         (setq list (last list))
2892         (if (not data)
2893             (progn
2894               (setcdr list gnus-newsgroup-data)
2895               (setq gnus-newsgroup-data ilist)
2896               (when offset
2897                 (gnus-data-update-list (cdr list) offset)))
2898           (setcdr list (cdr data))
2899           (setcdr data ilist)
2900           (when offset
2901             (gnus-data-update-list (cdr list) offset))))
2902       (setq gnus-newsgroup-data-reverse nil))))
2903
2904 (defun gnus-data-remove (article &optional offset)
2905   (let ((data gnus-newsgroup-data))
2906     (if (= (gnus-data-number (car data)) article)
2907         (progn
2908           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2909                 gnus-newsgroup-data-reverse nil)
2910           (when offset
2911             (gnus-data-update-list gnus-newsgroup-data offset)))
2912       (while (cdr data)
2913         (when (= (gnus-data-number (cadr data)) article)
2914           (setcdr data (cddr data))
2915           (when offset
2916             (gnus-data-update-list (cdr data) offset))
2917           (setq data nil
2918                 gnus-newsgroup-data-reverse nil))
2919         (setq data (cdr data))))))
2920
2921 (defmacro gnus-data-list (backward)
2922   `(if ,backward
2923        (or gnus-newsgroup-data-reverse
2924            (setq gnus-newsgroup-data-reverse
2925                  (reverse gnus-newsgroup-data)))
2926      gnus-newsgroup-data))
2927
2928 (defun gnus-data-update-list (data offset)
2929   "Add OFFSET to the POS of all data entries in DATA."
2930   (setq gnus-newsgroup-data-reverse nil)
2931   (while data
2932     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2933     (setq data (cdr data))))
2934
2935 (defun gnus-summary-article-pseudo-p (article)
2936   "Say whether this article is a pseudo article or not."
2937   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2938
2939 (defmacro gnus-summary-article-sparse-p (article)
2940   "Say whether this article is a sparse article or not."
2941   `(memq ,article gnus-newsgroup-sparse))
2942
2943 (defmacro gnus-summary-article-ancient-p (article)
2944   "Say whether this article is a sparse article or not."
2945   `(memq ,article gnus-newsgroup-ancient))
2946
2947 (defun gnus-article-parent-p (number)
2948   "Say whether this article is a parent or not."
2949   (let ((data (gnus-data-find-list number)))
2950     (and (cdr data)                     ; There has to be an article after...
2951          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2952             (gnus-data-level (nth 1 data))))))
2953
2954 (defun gnus-article-children (number)
2955   "Return a list of all children to NUMBER."
2956   (let* ((data (gnus-data-find-list number))
2957          (level (gnus-data-level (car data)))
2958          children)
2959     (setq data (cdr data))
2960     (while (and data
2961                 (= (gnus-data-level (car data)) (1+ level)))
2962       (push (gnus-data-number (car data)) children)
2963       (setq data (cdr data)))
2964     children))
2965
2966 (defmacro gnus-summary-skip-intangible ()
2967   "If the current article is intangible, then jump to a different article."
2968   '(let ((to (get-text-property (point) 'gnus-intangible)))
2969      (and to (gnus-summary-goto-subject to))))
2970
2971 (defmacro gnus-summary-article-intangible-p ()
2972   "Say whether this article is intangible or not."
2973   '(get-text-property (point) 'gnus-intangible))
2974
2975 (defun gnus-article-read-p (article)
2976   "Say whether ARTICLE is read or not."
2977   (not (or (memq article gnus-newsgroup-marked)
2978            (memq article gnus-newsgroup-spam-marked)
2979            (memq article gnus-newsgroup-unreads)
2980            (memq article gnus-newsgroup-unselected)
2981            (memq article gnus-newsgroup-dormant))))
2982
2983 ;; Some summary mode macros.
2984
2985 (defmacro gnus-summary-article-number ()
2986   "The article number of the article on the current line.
2987 If there isn't an article number here, then we return the current
2988 article number."
2989   '(progn
2990      (gnus-summary-skip-intangible)
2991      (or (get-text-property (point) 'gnus-number)
2992          (gnus-summary-last-subject))))
2993
2994 (defmacro gnus-summary-article-header (&optional number)
2995   "Return the header of article NUMBER."
2996   `(gnus-data-header (gnus-data-find
2997                       ,(or number '(gnus-summary-article-number)))))
2998
2999 (defmacro gnus-summary-thread-level (&optional number)
3000   "Return the level of thread that starts with article NUMBER."
3001   `(if (and (eq gnus-summary-make-false-root 'dummy)
3002             (get-text-property (point) 'gnus-intangible))
3003        0
3004      (gnus-data-level (gnus-data-find
3005                        ,(or number '(gnus-summary-article-number))))))
3006
3007 (defmacro gnus-summary-article-mark (&optional number)
3008   "Return the mark of article NUMBER."
3009   `(gnus-data-mark (gnus-data-find
3010                     ,(or number '(gnus-summary-article-number)))))
3011
3012 (defmacro gnus-summary-article-pos (&optional number)
3013   "Return the position of the line of article NUMBER."
3014   `(gnus-data-pos (gnus-data-find
3015                    ,(or number '(gnus-summary-article-number)))))
3016
3017 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3018 (defmacro gnus-summary-article-subject (&optional number)
3019   "Return current subject string or nil if nothing."
3020   `(let ((headers
3021           ,(if number
3022                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3023              '(gnus-data-header (assq (gnus-summary-article-number)
3024                                       gnus-newsgroup-data)))))
3025      (and headers
3026           (vectorp headers)
3027           (mail-header-subject headers))))
3028
3029 (defmacro gnus-summary-article-score (&optional number)
3030   "Return current article score."
3031   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3032                   gnus-newsgroup-scored))
3033        gnus-summary-default-score 0))
3034
3035 (defun gnus-summary-article-children (&optional number)
3036   "Return a list of article numbers that are children of article NUMBER."
3037   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3038          (level (gnus-data-level (car data)))
3039          l children)
3040     (while (and (setq data (cdr data))
3041                 (> (setq l (gnus-data-level (car data))) level))
3042       (and (= (1+ level) l)
3043            (push (gnus-data-number (car data))
3044                  children)))
3045     (nreverse children)))
3046
3047 (defun gnus-summary-article-parent (&optional number)
3048   "Return the article number of the parent of article NUMBER."
3049   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3050                                     (gnus-data-list t)))
3051          (level (gnus-data-level (car data))))
3052     (if (zerop level)
3053         ()                              ; This is a root.
3054       ;; We search until we find an article with a level less than
3055       ;; this one.  That function has to be the parent.
3056       (while (and (setq data (cdr data))
3057                   (not (< (gnus-data-level (car data)) level))))
3058       (and data (gnus-data-number (car data))))))
3059
3060 (defun gnus-unread-mark-p (mark)
3061   "Say whether MARK is the unread mark."
3062   (= mark gnus-unread-mark))
3063
3064 (defun gnus-read-mark-p (mark)
3065   "Say whether MARK is one of the marks that mark as read.
3066 This is all marks except unread, ticked, dormant, and expirable."
3067   (not (or (= mark gnus-unread-mark)
3068            (= mark gnus-ticked-mark)
3069            (= mark gnus-spam-mark)
3070            (= mark gnus-dormant-mark)
3071            (= mark gnus-expirable-mark))))
3072
3073 (defmacro gnus-article-mark (number)
3074   "Return the MARK of article NUMBER.
3075 This macro should only be used when computing the mark the \"first\"
3076 time; i.e., when generating the summary lines.  After that,
3077 `gnus-summary-article-mark' should be used to examine the
3078 marks of articles."
3079   `(cond
3080     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3081     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3082     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3083     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3084     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3085     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3086     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3087     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3088            gnus-ancient-mark))))
3089
3090 ;; Saving hidden threads.
3091
3092 (defmacro gnus-save-hidden-threads (&rest forms)
3093   "Save hidden threads, eval FORMS, and restore the hidden threads."
3094   (let ((config (make-symbol "config")))
3095     `(let ((,config (gnus-hidden-threads-configuration)))
3096        (unwind-protect
3097            (save-excursion
3098              ,@forms)
3099          (gnus-restore-hidden-threads-configuration ,config)))))
3100 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3101 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3102
3103 (defun gnus-data-compute-positions ()
3104   "Compute the positions of all articles."
3105   (setq gnus-newsgroup-data-reverse nil)
3106   (let ((data gnus-newsgroup-data))
3107     (save-excursion
3108       (gnus-save-hidden-threads
3109         (gnus-summary-show-all-threads)
3110         (goto-char (point-min))
3111         (while data
3112           (while (get-text-property (point) 'gnus-intangible)
3113             (forward-line 1))
3114           (gnus-data-set-pos (car data) (+ (point) 3))
3115           (setq data (cdr data))
3116           (forward-line 1))))))
3117
3118 (defun gnus-hidden-threads-configuration ()
3119   "Return the current hidden threads configuration."
3120   (save-excursion
3121     (let (config)
3122       (goto-char (point-min))
3123       (while (search-forward "\r" nil t)
3124         (push (1- (point)) config))
3125       config)))
3126
3127 (defun gnus-restore-hidden-threads-configuration (config)
3128   "Restore hidden threads configuration from CONFIG."
3129   (save-excursion
3130     (let (point buffer-read-only)
3131       (while (setq point (pop config))
3132         (when (and (< point (point-max))
3133                    (goto-char point)
3134                    (eq (char-after) ?\n))
3135           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3136
3137 ;; Various summary mode internalish functions.
3138
3139 (defun gnus-mouse-pick-article (e)
3140   (interactive "e")
3141   (mouse-set-point e)
3142   (gnus-summary-next-page nil t))
3143
3144 (defun gnus-summary-set-display-table ()
3145   "Change the display table.
3146 Odd characters have a tendency to mess
3147 up nicely formatted displays - we make all possible glyphs
3148 display only a single character."
3149
3150   ;; We start from the standard display table, if any.
3151   (let ((table (or (copy-sequence standard-display-table)
3152                    (make-display-table)))
3153         (i 32))
3154     ;; Nix out all the control chars...
3155     (while (>= (setq i (1- i)) 0)
3156       (aset table i [??]))
3157     ;; ... but not newline and cr, of course.  (cr is necessary for the
3158     ;; selective display).
3159     (aset table ?\n nil)
3160     (aset table ?\r nil)
3161     ;; We keep TAB as well.
3162     (aset table ?\t nil)
3163     ;; We nix out any glyphs over 126 that are not set already.
3164     (let ((i 256))
3165       (while (>= (setq i (1- i)) 127)
3166         ;; Only modify if the entry is nil.
3167         (unless (aref table i)
3168           (aset table i [??]))))
3169     (setq buffer-display-table table)))
3170
3171 (defun gnus-summary-set-article-display-arrow (pos)
3172   "Update the overlay arrow to point to line at position POS."
3173   (when (and gnus-summary-display-arrow
3174              (boundp 'overlay-arrow-position)
3175              (boundp 'overlay-arrow-string))
3176     (save-excursion
3177       (goto-char pos)
3178       (beginning-of-line)
3179       (unless overlay-arrow-position
3180         (setq overlay-arrow-position (make-marker)))
3181       (setq overlay-arrow-string "=>"
3182             overlay-arrow-position (set-marker overlay-arrow-position
3183                                                (point)
3184                                                (current-buffer))))))
3185
3186 (defun gnus-summary-setup-buffer (group)
3187   "Initialize summary buffer."
3188   (let ((buffer (gnus-summary-buffer-name group))
3189         (dead-name (concat "*Dead Summary "
3190                            (gnus-group-decoded-name group) "*")))
3191     ;; If a dead summary buffer exists, we kill it.
3192     (when (gnus-buffer-live-p dead-name)
3193       (gnus-kill-buffer dead-name))
3194     (if (get-buffer buffer)
3195         (progn
3196           (set-buffer buffer)
3197           (setq gnus-summary-buffer (current-buffer))
3198           (not gnus-newsgroup-prepared))
3199       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3200       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3201       (gnus-summary-mode group)
3202       (when gnus-carpal
3203         (gnus-carpal-setup-buffer 'summary))
3204       (unless gnus-single-article-buffer
3205         (make-local-variable 'gnus-article-buffer)
3206         (make-local-variable 'gnus-article-current)
3207         (make-local-variable 'gnus-original-article-buffer))
3208       (setq gnus-newsgroup-name group)
3209       ;; Set any local variables in the group parameters.
3210       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3211       t)))
3212
3213 (defun gnus-set-global-variables ()
3214   "Set the global equivalents of the buffer-local variables.
3215 They are set to the latest values they had.  These reflect the summary
3216 buffer that was in action when the last article was fetched."
3217   (when (eq major-mode 'gnus-summary-mode)
3218     (setq gnus-summary-buffer (current-buffer))
3219     (let ((name gnus-newsgroup-name)
3220           (marked gnus-newsgroup-marked)
3221           (spam gnus-newsgroup-spam-marked)
3222           (unread gnus-newsgroup-unreads)
3223           (headers gnus-current-headers)
3224           (data gnus-newsgroup-data)
3225           (summary gnus-summary-buffer)
3226           (article-buffer gnus-article-buffer)
3227           (original gnus-original-article-buffer)
3228           (gac gnus-article-current)
3229           (reffed gnus-reffed-article-number)
3230           (score-file gnus-current-score-file)
3231           (default-charset gnus-newsgroup-charset)
3232           vlist)
3233       (let ((locals gnus-newsgroup-variables))
3234         (while locals
3235           (if (consp (car locals))
3236               (push (eval (caar locals)) vlist)
3237             (push (eval (car locals)) vlist))
3238           (setq locals (cdr locals)))
3239         (setq vlist (nreverse vlist)))
3240       (with-current-buffer gnus-group-buffer
3241         (setq gnus-newsgroup-name name
3242               gnus-newsgroup-marked marked
3243               gnus-newsgroup-spam-marked spam
3244               gnus-newsgroup-unreads unread
3245               gnus-current-headers headers
3246               gnus-newsgroup-data data
3247               gnus-article-current gac
3248               gnus-summary-buffer summary
3249               gnus-article-buffer article-buffer
3250               gnus-original-article-buffer original
3251               gnus-reffed-article-number reffed
3252               gnus-current-score-file score-file
3253               gnus-newsgroup-charset default-charset)
3254         (let ((locals gnus-newsgroup-variables))
3255           (while locals
3256             (if (consp (car locals))
3257                 (set (caar locals) (pop vlist))
3258               (set (car locals) (pop vlist)))
3259             (setq locals (cdr locals))))
3260         ;; The article buffer also has local variables.
3261         (when (gnus-buffer-live-p gnus-article-buffer)
3262           (set-buffer gnus-article-buffer)
3263           (setq gnus-summary-buffer summary))))))
3264
3265 (defun gnus-summary-article-unread-p (article)
3266   "Say whether ARTICLE is unread or not."
3267   (memq article gnus-newsgroup-unreads))
3268
3269 (defun gnus-summary-first-article-p (&optional article)
3270   "Return whether ARTICLE is the first article in the buffer."
3271   (if (not (setq article (or article (gnus-summary-article-number))))
3272       nil
3273     (eq article (caar gnus-newsgroup-data))))
3274
3275 (defun gnus-summary-last-article-p (&optional article)
3276   "Return whether ARTICLE is the last article in the buffer."
3277   (if (not (setq article (or article (gnus-summary-article-number))))
3278       ;; All non-existent numbers are the last article.  :-)
3279       t
3280     (not (cdr (gnus-data-find-list article)))))
3281
3282 (defun gnus-make-thread-indent-array ()
3283   (let ((n 200))
3284     (unless (and gnus-thread-indent-array
3285                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3286       (setq gnus-thread-indent-array (make-vector 201 "")
3287             gnus-thread-indent-array-level gnus-thread-indent-level)
3288       (while (>= n 0)
3289         (aset gnus-thread-indent-array n
3290               (make-string (* n gnus-thread-indent-level) ? ))
3291         (setq n (1- n))))))
3292
3293 (defun gnus-update-summary-mark-positions ()
3294   "Compute where the summary marks are to go."
3295   (save-excursion
3296     (when (gnus-buffer-exists-p gnus-summary-buffer)
3297       (set-buffer gnus-summary-buffer))
3298     (let ((spec gnus-summary-line-format-spec)
3299           pos)
3300       (save-excursion
3301         (gnus-set-work-buffer)
3302         (let ((gnus-tmp-unread ?Z)
3303               (gnus-replied-mark ?Z)
3304               (gnus-score-below-mark ?Z)
3305               (gnus-score-over-mark ?Z)
3306               (gnus-undownloaded-mark ?Z)
3307               (gnus-summary-line-format-spec spec)
3308               (gnus-newsgroup-downloadable '(0))
3309               (header
3310                (make-full-mail-header
3311                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3312               case-fold-search ignores)
3313           ;; Here, all marks are bound to Z.
3314           (gnus-summary-insert-line header
3315                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3316           (goto-char (point-min))
3317           ;; Memorize the positions of the same characters as dummy marks.
3318           (while (re-search-forward "[A-D]" nil t)
3319             (push (point) ignores))
3320           (erase-buffer)
3321           ;; We use A-D as dummy marks in order to know column positions
3322           ;; where marks should be inserted.
3323           (setq gnus-tmp-unread ?A
3324                 gnus-replied-mark ?B
3325                 gnus-score-below-mark ?C
3326                 gnus-score-over-mark ?C
3327                 gnus-undownloaded-mark ?D)
3328           (gnus-summary-insert-line header
3329                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3330           ;; Ignore characters which aren't dummy marks.
3331           (dolist (p ignores)
3332             (delete-region (goto-char (1- p)) p)
3333             (insert ?Z))
3334           (goto-char (point-min))
3335           (setq pos (list (cons 'unread
3336                                 (and (search-forward "A" nil t)
3337                                      (- (point) (point-min) 1)))))
3338           (goto-char (point-min))
3339           (push (cons 'replied (and (search-forward "B" nil t)
3340                                     (- (point) (point-min) 1)))
3341                 pos)
3342           (goto-char (point-min))
3343           (push (cons 'score (and (search-forward "C" nil t)
3344                                   (- (point) (point-min) 1)))
3345                 pos)
3346           (goto-char (point-min))
3347           (push (cons 'download (and (search-forward "D" nil t)
3348                                      (- (point) (point-min) 1)))
3349                 pos)))
3350       (setq gnus-summary-mark-positions pos))))
3351
3352 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3353   "Insert a dummy root in the summary buffer."
3354   (beginning-of-line)
3355   (gnus-add-text-properties
3356    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3357    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3358
3359 (defun gnus-summary-extract-address-component (from)
3360   (or (car (funcall gnus-extract-address-components from))
3361       from))
3362
3363 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3364   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3365                                 default-mime-charset)))
3366     ;; Is it really necessary to do this next part for each summary line?
3367     ;; Luckily, doesn't seem to slow things down much.
3368     (or
3369      (and gnus-ignored-from-addresses
3370           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3371           (let ((extra-headers (mail-header-extra header))
3372                 to
3373                 newsgroups)
3374             (cond
3375              ((setq to (cdr (assq 'To extra-headers)))
3376               (concat gnus-summary-to-prefix
3377                       (inline
3378                         (gnus-summary-extract-address-component
3379                          (funcall gnus-decode-encoded-word-function to)))))
3380              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3381               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3382      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3383
3384 (defun gnus-summary-insert-line (gnus-tmp-header
3385                                  gnus-tmp-level gnus-tmp-current
3386                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3387                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3388                                  &optional gnus-tmp-dummy gnus-tmp-score
3389                                  gnus-tmp-process)
3390   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3391          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3392          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3393          (gnus-tmp-score-char
3394           (if (or (null gnus-summary-default-score)
3395                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3396                       gnus-summary-zcore-fuzz))
3397               ?\ ;;;Whitespace
3398             (if (< gnus-tmp-score gnus-summary-default-score)
3399                 gnus-score-below-mark gnus-score-over-mark)))
3400          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3401          (gnus-tmp-replied
3402           (cond (gnus-tmp-process gnus-process-mark)
3403                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3404                  gnus-cached-mark)
3405                 (gnus-tmp-replied gnus-replied-mark)
3406                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3407                  gnus-forwarded-mark)
3408                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3409                  gnus-saved-mark)
3410                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3411                  gnus-recent-mark)
3412                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3413                  gnus-unseen-mark)
3414                 (t gnus-no-mark)))
3415          (gnus-tmp-downloaded
3416           (cond (undownloaded
3417                  gnus-undownloaded-mark)
3418                 (gnus-newsgroup-agentized
3419                  gnus-downloaded-mark)
3420                 (t
3421                  gnus-no-mark)))
3422          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3423          (gnus-tmp-name
3424           (cond
3425            ((string-match "<[^>]+> *$" gnus-tmp-from)
3426             (let ((beg (match-beginning 0)))
3427               (or (and (string-match "^\".+\"" gnus-tmp-from)
3428                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3429                   (substring gnus-tmp-from 0 beg))))
3430            ((string-match "(.+)" gnus-tmp-from)
3431             (substring gnus-tmp-from
3432                        (1+ (match-beginning 0)) (1- (match-end 0))))
3433            (t gnus-tmp-from)))
3434          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3435          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3436          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3437          (buffer-read-only nil))
3438     (when (string= gnus-tmp-name "")
3439       (setq gnus-tmp-name gnus-tmp-from))
3440     (unless (numberp gnus-tmp-lines)
3441       (setq gnus-tmp-lines -1))
3442     (if (= gnus-tmp-lines -1)
3443         (setq gnus-tmp-lines "?")
3444       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3445     (gnus-put-text-property-excluding-characters-with-faces
3446      (point)
3447      (progn (eval gnus-summary-line-format-spec) (point))
3448      'gnus-number gnus-tmp-number)
3449     (when (gnus-visual-p 'summary-highlight 'highlight)
3450       (forward-line -1)
3451       (gnus-run-hooks 'gnus-summary-update-hook)
3452       (forward-line 1))))
3453
3454 (defun gnus-summary-update-line (&optional dont-update)
3455   "Update summary line after change."
3456   (when (and gnus-summary-default-score
3457              (not gnus-summary-inhibit-highlight))
3458     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3459            (article (gnus-summary-article-number))
3460            (score (gnus-summary-article-score article)))
3461       (unless dont-update
3462         (if (and gnus-summary-mark-below
3463                  (< (gnus-summary-article-score)
3464                     gnus-summary-mark-below))
3465             ;; This article has a low score, so we mark it as read.
3466             (when (memq article gnus-newsgroup-unreads)
3467               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3468           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3469             ;; This article was previously marked as read on account
3470             ;; of a low score, but now it has risen, so we mark it as
3471             ;; unread.
3472             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3473         (gnus-summary-update-mark
3474          (if (or (null gnus-summary-default-score)
3475                  (<= (abs (- score gnus-summary-default-score))
3476                      gnus-summary-zcore-fuzz))
3477              ?\ ;;;Whitespace
3478            (if (< score gnus-summary-default-score)
3479                gnus-score-below-mark gnus-score-over-mark))
3480          'score))
3481       ;; Do visual highlighting.
3482       (when (gnus-visual-p 'summary-highlight 'highlight)
3483         (gnus-run-hooks 'gnus-summary-update-hook)))))
3484
3485 (defvar gnus-tmp-new-adopts nil)
3486
3487 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3488   "Return the number of articles in THREAD.
3489 This may be 0 in some cases -- if none of the articles in
3490 the thread are to be displayed."
3491   (let* ((number
3492           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3493           (cond
3494            ((not (listp thread))
3495             1)
3496            ((and (consp thread) (cdr thread))
3497             (apply
3498              '+ 1 (mapcar
3499                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3500            ((null thread)
3501             1)
3502            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3503             1)
3504            (t 0))))
3505     (when (and level (zerop level) gnus-tmp-new-adopts)
3506       (incf number
3507             (apply '+ (mapcar
3508                        'gnus-summary-number-of-articles-in-thread
3509                        gnus-tmp-new-adopts))))
3510     (if char
3511         (if (> number 1) gnus-not-empty-thread-mark
3512           gnus-empty-thread-mark)
3513       number)))
3514
3515 (defsubst gnus-summary-line-message-size (head)
3516   "Return pretty-printed version of message size.
3517 This function is intended to be used in
3518 `gnus-summary-line-format-alist'."
3519   (let ((c (or (mail-header-chars head) -1)))
3520     (cond ((< c 0) "n/a")               ; chars not available
3521           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3522           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3523           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3524           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3525
3526
3527 (defun gnus-summary-set-local-parameters (group)
3528   "Go through the local params of GROUP and set all variable specs in that list."
3529   (let ((vars '(quit-config)))          ; Ignore quit-config.
3530     (dolist (elem (gnus-group-find-parameter group))
3531       (and (consp elem)                 ; Has to be a cons.
3532            (consp (cdr elem))           ; The cdr has to be a list.
3533            (symbolp (car elem))         ; Has to be a symbol in there.
3534            (not (memq (car elem) vars))
3535            (ignore-errors               ; So we set it.
3536              (push (car elem) vars)
3537              (make-local-variable (car elem))
3538              (set (car elem) (eval (nth 1 elem))))))))
3539
3540 (defun gnus-summary-read-group (group &optional show-all no-article
3541                                       kill-buffer no-display backward
3542                                       select-articles)
3543   "Start reading news in newsgroup GROUP.
3544 If SHOW-ALL is non-nil, already read articles are also listed.
3545 If NO-ARTICLE is non-nil, no article is selected initially.
3546 If NO-DISPLAY, don't generate a summary buffer."
3547   (let (result)
3548     (while (and group
3549                 (null (setq result
3550                             (let ((gnus-auto-select-next nil))
3551                               (or (gnus-summary-read-group-1
3552                                    group show-all no-article
3553                                    kill-buffer no-display
3554                                    select-articles)
3555                                   (setq show-all nil
3556                                         select-articles nil)))))
3557                 (eq gnus-auto-select-next 'quietly))
3558       (set-buffer gnus-group-buffer)
3559       ;; The entry function called above goes to the next
3560       ;; group automatically, so we go two groups back
3561       ;; if we are searching for the previous group.
3562       (when backward
3563         (gnus-group-prev-unread-group 2))
3564       (if (not (equal group (gnus-group-group-name)))
3565           (setq group (gnus-group-group-name))
3566         (setq group nil)))
3567     result))
3568
3569 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3570   "Directly jump to the other GROUP from summary buffer.
3571 If SHOW-ALL is non-nil, already read articles are also listed."
3572   (interactive
3573    (if (eq gnus-summary-buffer (current-buffer))
3574        (list (completing-read
3575               "Group: " gnus-active-hashtb nil t
3576               (when (and gnus-newsgroup-name
3577                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3578                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3579               'gnus-group-history)
3580              current-prefix-arg)
3581      (error "%s must be invoked from a gnus summary buffer." this-command)))
3582   (unless (or (zerop (length group))
3583               (and gnus-newsgroup-name
3584                    (string-equal gnus-newsgroup-name group)))
3585     (gnus-summary-exit)
3586     (gnus-summary-read-group group show-all
3587                              gnus-dont-select-after-jump-to-other-group)))
3588
3589 (defun gnus-summary-read-group-1 (group show-all no-article
3590                                         kill-buffer no-display
3591                                         &optional select-articles)
3592   ;; Killed foreign groups can't be entered.
3593   ;;  (when (and (not (gnus-group-native-p group))
3594   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3595   ;;    (error "Dead non-native groups can't be entered"))
3596   (gnus-message 5 "Retrieving newsgroup: %s..."
3597                 (gnus-group-decoded-name group))
3598   (let* ((new-group (gnus-summary-setup-buffer group))
3599          (quit-config (gnus-group-quit-config group))
3600          (did-select (and new-group (gnus-select-newsgroup
3601                                      group show-all select-articles))))
3602     (cond
3603      ;; This summary buffer exists already, so we just select it.
3604      ((not new-group)
3605       (gnus-set-global-variables)
3606       (when kill-buffer
3607         (gnus-kill-or-deaden-summary kill-buffer))
3608       (gnus-configure-windows 'summary 'force)
3609       (gnus-set-mode-line 'summary)
3610       (gnus-summary-position-point)
3611       (message "")
3612       t)
3613      ;; We couldn't select this group.
3614      ((null did-select)
3615       (when (and (eq major-mode 'gnus-summary-mode)
3616                  (not (equal (current-buffer) kill-buffer)))
3617         (kill-buffer (current-buffer))
3618         (if (not quit-config)
3619             (progn
3620               ;; Update the info -- marks might need to be removed,
3621               ;; for instance.
3622               (gnus-summary-update-info)
3623               (set-buffer gnus-group-buffer)
3624               (gnus-group-jump-to-group group)
3625               (gnus-group-next-unread-group 1))
3626           (gnus-handle-ephemeral-exit quit-config)))
3627       (let ((grpinfo (gnus-get-info group)))
3628         (if (null (gnus-info-read grpinfo))
3629             (gnus-message 3 "Group %s contains no messages"
3630                           (gnus-group-decoded-name group))
3631           (gnus-message 3 "Can't select group")))
3632       nil)
3633      ;; The user did a `C-g' while prompting for number of articles,
3634      ;; so we exit this group.
3635      ((eq did-select 'quit)
3636       (and (eq major-mode 'gnus-summary-mode)
3637            (not (equal (current-buffer) kill-buffer))
3638            (kill-buffer (current-buffer)))
3639       (when kill-buffer
3640         (gnus-kill-or-deaden-summary kill-buffer))
3641       (if (not quit-config)
3642           (progn
3643             (set-buffer gnus-group-buffer)
3644             (gnus-group-jump-to-group group)
3645             (gnus-group-next-unread-group 1)
3646             (gnus-configure-windows 'group 'force))
3647         (gnus-handle-ephemeral-exit quit-config))
3648       ;; Finally signal the quit.
3649       (signal 'quit nil))
3650      ;; The group was successfully selected.
3651      (t
3652       (gnus-set-global-variables)
3653       ;; Save the active value in effect when the group was entered.
3654       (setq gnus-newsgroup-active
3655             (gnus-copy-sequence
3656              (gnus-active gnus-newsgroup-name)))
3657       ;; You can change the summary buffer in some way with this hook.
3658       (gnus-run-hooks 'gnus-select-group-hook)
3659       (when (memq 'summary (gnus-update-format-specifications
3660                             nil 'summary 'summary-mode 'summary-dummy))
3661         ;; The format specification for the summary line was updated,
3662         ;; so we need to update the mark positions as well.
3663         (gnus-update-summary-mark-positions))
3664       ;; Do score processing.
3665       (when gnus-use-scoring
3666         (gnus-possibly-score-headers))
3667       ;; Check whether to fill in the gaps in the threads.
3668       (when gnus-build-sparse-threads
3669         (gnus-build-sparse-threads))
3670       ;; Find the initial limit.
3671       (if show-all
3672           (let ((gnus-newsgroup-dormant nil))
3673             (gnus-summary-initial-limit show-all))
3674         (gnus-summary-initial-limit show-all))
3675       ;; Generate the summary buffer.
3676       (unless no-display
3677         (gnus-summary-prepare))
3678       (when gnus-use-trees
3679         (gnus-tree-open group)
3680         (setq gnus-summary-highlight-line-function
3681               'gnus-tree-highlight-article))
3682       ;; If the summary buffer is empty, but there are some low-scored
3683       ;; articles or some excluded dormants, we include these in the
3684       ;; buffer.
3685       (when (and (zerop (buffer-size))
3686                  (not no-display))
3687         (cond (gnus-newsgroup-dormant
3688                (gnus-summary-limit-include-dormant))
3689               ((and gnus-newsgroup-scored show-all)
3690                (gnus-summary-limit-include-expunged t))))
3691       ;; Function `gnus-apply-kill-file' must be called in this hook.
3692       (gnus-run-hooks 'gnus-apply-kill-hook)
3693       (if (and (zerop (buffer-size))
3694                (not no-display))
3695           (progn
3696             ;; This newsgroup is empty.
3697             (gnus-summary-catchup-and-exit nil t)
3698             (gnus-message 6 "No unread news")
3699             (when kill-buffer
3700               (gnus-kill-or-deaden-summary kill-buffer))
3701             ;; Return nil from this function.
3702             nil)
3703         ;; Hide conversation thread subtrees.  We cannot do this in
3704         ;; gnus-summary-prepare-hook since kill processing may not
3705         ;; work with hidden articles.
3706         (gnus-summary-maybe-hide-threads)
3707         (when kill-buffer
3708           (gnus-kill-or-deaden-summary kill-buffer))
3709         (gnus-summary-auto-select-subject)
3710         ;; Show first unread article if requested.
3711         (if (and (not no-article)
3712                  (not no-display)
3713                  gnus-newsgroup-unreads
3714                  gnus-auto-select-first)
3715             (progn
3716               (gnus-configure-windows 'summary)
3717               (let ((art (gnus-summary-article-number)))
3718                 (unless (and (not gnus-plugged)
3719                              (or (memq art gnus-newsgroup-undownloaded)
3720                                  (memq art gnus-newsgroup-downloadable)))
3721                   (gnus-summary-goto-article art))))
3722           ;; Don't select any articles.
3723           (gnus-summary-position-point)
3724           (gnus-configure-windows 'summary 'force)
3725           (gnus-set-mode-line 'summary))
3726         (when (and gnus-auto-center-group
3727                    (get-buffer-window gnus-group-buffer t))
3728           ;; Gotta use windows, because recenter does weird stuff if
3729           ;; the current buffer ain't the displayed window.
3730           (let ((owin (selected-window)))
3731             (select-window (get-buffer-window gnus-group-buffer t))
3732             (when (gnus-group-goto-group group)
3733               (recenter))
3734             (select-window owin)))
3735         ;; Mark this buffer as "prepared".
3736         (setq gnus-newsgroup-prepared t)
3737         (gnus-run-hooks 'gnus-summary-prepared-hook)
3738         (unless (gnus-ephemeral-group-p group)
3739           (gnus-group-update-group group))
3740         t)))))
3741
3742 (defun gnus-summary-auto-select-subject ()
3743   "Select the subject line on initial group entry."
3744   (goto-char (point-min))
3745   (cond
3746    ((eq gnus-auto-select-subject 'best)
3747     (gnus-summary-best-unread-subject))
3748    ((eq gnus-auto-select-subject 'unread)
3749     (gnus-summary-first-unread-subject))
3750    ((eq gnus-auto-select-subject 'unseen)
3751     (gnus-summary-first-unseen-subject))
3752    ((eq gnus-auto-select-subject 'unseen-or-unread)
3753     (gnus-summary-first-unseen-or-unread-subject))
3754    ((eq gnus-auto-select-subject 'first)
3755     ;; Do nothing.
3756     )
3757    ((functionp gnus-auto-select-subject)
3758     (funcall gnus-auto-select-subject))))
3759
3760 (defun gnus-summary-prepare ()
3761   "Generate the summary buffer."
3762   (interactive)
3763   (let ((buffer-read-only nil))
3764     (erase-buffer)
3765     (setq gnus-newsgroup-data nil
3766           gnus-newsgroup-data-reverse nil)
3767     (gnus-run-hooks 'gnus-summary-generate-hook)
3768     ;; Generate the buffer, either with threads or without.
3769     (when gnus-newsgroup-headers
3770       (gnus-summary-prepare-threads
3771        (if gnus-show-threads
3772            (gnus-sort-gathered-threads
3773             (funcall gnus-summary-thread-gathering-function
3774                      (gnus-sort-threads
3775                       (gnus-cut-threads (gnus-make-threads)))))
3776          ;; Unthreaded display.
3777          (gnus-sort-articles gnus-newsgroup-headers))))
3778     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3779     ;; Call hooks for modifying summary buffer.
3780     (goto-char (point-min))
3781     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3782
3783 (defsubst gnus-general-simplify-subject (subject)
3784   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3785   (setq subject
3786         (cond
3787          ;; Truncate the subject.
3788          (gnus-simplify-subject-functions
3789           (gnus-map-function gnus-simplify-subject-functions subject))
3790          ((numberp gnus-summary-gather-subject-limit)
3791           (setq subject (gnus-simplify-subject-re subject))
3792           (if (> (length subject) gnus-summary-gather-subject-limit)
3793               (substring subject 0 gnus-summary-gather-subject-limit)
3794             subject))
3795          ;; Fuzzily simplify it.
3796          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3797           (gnus-simplify-subject-fuzzy subject))
3798          ;; Just remove the leading "Re:".
3799          (t
3800           (gnus-simplify-subject-re subject))))
3801
3802   (if (and gnus-summary-gather-exclude-subject
3803            (string-match gnus-summary-gather-exclude-subject subject))
3804       nil                               ; This article shouldn't be gathered
3805     subject))
3806
3807 (defun gnus-summary-simplify-subject-query ()
3808   "Query where the respool algorithm would put this article."
3809   (interactive)
3810   (gnus-summary-select-article)
3811   (message "%s"
3812            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3813
3814 (defun gnus-gather-threads-by-subject (threads)
3815   "Gather threads by looking at Subject headers."
3816   (if (not gnus-summary-make-false-root)
3817       threads
3818     (let ((hashtb (gnus-make-hashtable 1024))
3819           (prev threads)
3820           (result threads)
3821           subject hthread whole-subject)
3822       (while threads
3823         (setq subject (gnus-general-simplify-subject
3824                        (setq whole-subject (mail-header-subject
3825                                             (caar threads)))))
3826         (when subject
3827           (if (setq hthread (gnus-gethash subject hashtb))
3828               (progn
3829                 ;; We enter a dummy root into the thread, if we
3830                 ;; haven't done that already.
3831                 (unless (stringp (caar hthread))
3832                   (setcar hthread (list whole-subject (car hthread))))
3833                 ;; We add this new gathered thread to this gathered
3834                 ;; thread.
3835                 (setcdr (car hthread)
3836                         (nconc (cdar hthread) (list (car threads))))
3837                 ;; Remove it from the list of threads.
3838                 (setcdr prev (cdr threads))
3839                 (setq threads prev))
3840             ;; Enter this thread into the hash table.
3841             (gnus-sethash subject
3842                           (if gnus-summary-make-false-root-always
3843                               (progn
3844                                 ;; If you want a dummy root above all
3845                                 ;; threads...
3846                                 (setcar threads (list whole-subject
3847                                                       (car threads)))
3848                                 threads)
3849                             threads)
3850                           hashtb)))
3851         (setq prev threads)
3852         (setq threads (cdr threads)))
3853       result)))
3854
3855 (defun gnus-gather-threads-by-references (threads)
3856   "Gather threads by looking at References headers."
3857   (let ((idhashtb (gnus-make-hashtable 1024))
3858         (thhashtb (gnus-make-hashtable 1024))
3859         (prev threads)
3860         (result threads)
3861         ids references id gthread gid entered ref)
3862     (while threads
3863       (when (setq references (mail-header-references (caar threads)))
3864         (setq id (mail-header-id (caar threads))
3865               ids (inline (gnus-split-references references))
3866               entered nil)
3867         (while (setq ref (pop ids))
3868           (setq ids (delete ref ids))
3869           (if (not (setq gid (gnus-gethash ref idhashtb)))
3870               (progn
3871                 (gnus-sethash ref id idhashtb)
3872                 (gnus-sethash id threads thhashtb))
3873             (setq gthread (gnus-gethash gid thhashtb))
3874             (unless entered
3875               ;; We enter a dummy root into the thread, if we
3876               ;; haven't done that already.
3877               (unless (stringp (caar gthread))
3878                 (setcar gthread (list (mail-header-subject (caar gthread))
3879                                       (car gthread))))
3880               ;; We add this new gathered thread to this gathered
3881               ;; thread.
3882               (setcdr (car gthread)
3883                       (nconc (cdar gthread) (list (car threads)))))
3884             ;; Add it into the thread hash table.
3885             (gnus-sethash id gthread thhashtb)
3886             (setq entered t)
3887             ;; Remove it from the list of threads.
3888             (setcdr prev (cdr threads))
3889             (setq threads prev))))
3890       (setq prev threads)
3891       (setq threads (cdr threads)))
3892     result))
3893
3894 (defun gnus-sort-gathered-threads (threads)
3895   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3896   (let ((result threads))
3897     (while threads
3898       (when (stringp (caar threads))
3899         (setcdr (car threads)
3900                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3901       (setq threads (cdr threads)))
3902     result))
3903
3904 (defun gnus-thread-loop-p (root thread)
3905   "Say whether ROOT is in THREAD."
3906   (let ((stack (list thread))
3907         (infloop 0)
3908         th)
3909     (while (setq thread (pop stack))
3910       (setq th (cdr thread))
3911       (while (and th
3912                   (not (eq (caar th) root)))
3913         (pop th))
3914       (if th
3915           ;; We have found a loop.
3916           (let (ref-dep)
3917             (setcdr thread (delq (car th) (cdr thread)))
3918             (if (boundp (setq ref-dep (intern "none"
3919                                               gnus-newsgroup-dependencies)))
3920                 (setcdr (symbol-value ref-dep)
3921                         (nconc (cdr (symbol-value ref-dep))
3922                                (list (car th))))
3923               (set ref-dep (list nil (car th))))
3924             (setq infloop 1
3925                   stack nil))
3926         ;; Push all the subthreads onto the stack.
3927         (push (cdr thread) stack)))
3928     infloop))
3929
3930 (defun gnus-make-threads ()
3931   "Go through the dependency hashtb and find the roots.  Return all threads."
3932   (let (threads)
3933     (while (catch 'infloop
3934              (mapatoms
3935               (lambda (refs)
3936                 ;; Deal with self-referencing References loops.
3937                 (when (and (car (symbol-value refs))
3938                            (not (zerop
3939                                  (apply
3940                                   '+
3941                                   (mapcar
3942                                    (lambda (thread)
3943                                      (gnus-thread-loop-p
3944                                       (car (symbol-value refs)) thread))
3945                                    (cdr (symbol-value refs)))))))
3946                   (setq threads nil)
3947                   (throw 'infloop t))
3948                 (unless (car (symbol-value refs))
3949                   ;; These threads do not refer back to any other articles,
3950                   ;; so they're roots.
3951                   (setq threads (append (cdr (symbol-value refs)) threads))))
3952               gnus-newsgroup-dependencies)))
3953     threads))
3954
3955 ;; Build the thread tree.
3956 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3957   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3958
3959 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3960 if it was already present.
3961
3962 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3963 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3964 Message-IDs will be renamed to a unique Message-ID before being
3965 entered.
3966
3967 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3968   (let* ((id (mail-header-id header))
3969          (id-dep (and id (intern id dependencies)))
3970          parent-id ref ref-dep ref-header replaced)
3971     ;; Enter this `header' in the `dependencies' table.
3972     (cond
3973      ((not id-dep)
3974       (setq header nil))
3975      ;; The first two cases do the normal part: enter a new `header'
3976      ;; in the `dependencies' table.
3977      ((not (boundp id-dep))
3978       (set id-dep (list header)))
3979      ((null (car (symbol-value id-dep)))
3980       (setcar (symbol-value id-dep) header))
3981
3982      ;; From here the `header' was already present in the
3983      ;; `dependencies' table.
3984      (force-new
3985       ;; Overrides an existing entry;
3986       ;; just set the header part of the entry.
3987       (setcar (symbol-value id-dep) header)
3988       (setq replaced t))
3989
3990      ;; Renames the existing `header' to a unique Message-ID.
3991      ((not gnus-summary-ignore-duplicates)
3992       ;; An article with this Message-ID has already been seen.
3993       ;; We rename the Message-ID.
3994       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3995            (list header))
3996       (mail-header-set-id header id))
3997
3998      ;; The last case ignores an existing entry, except it adds any
3999      ;; additional Xrefs (in case the two articles came from different
4000      ;; servers.
4001      ;; Also sets `header' to `nil' meaning that the `dependencies'
4002      ;; table was *not* modified.
4003      (t
4004       (mail-header-set-xref
4005        (car (symbol-value id-dep))
4006        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4007                    "")
4008                (or (mail-header-xref header) "")))
4009       (setq header nil)))
4010
4011     (when (and header (not replaced))
4012       ;; First check that we are not creating a References loop.
4013       (setq parent-id (gnus-parent-id (mail-header-references header)))
4014       (setq ref parent-id)
4015       (while (and ref
4016                   (setq ref-dep (intern-soft ref dependencies))
4017                   (boundp ref-dep)
4018                   (setq ref-header (car (symbol-value ref-dep))))
4019         (if (string= id ref)
4020             ;; Yuk!  This is a reference loop.  Make the article be a
4021             ;; root article.
4022             (progn
4023               (mail-header-set-references (car (symbol-value id-dep)) "none")
4024               (setq ref nil)
4025               (setq parent-id nil))
4026           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4027       (setq ref-dep (intern (or parent-id "none") dependencies))
4028       (if (boundp ref-dep)
4029           (setcdr (symbol-value ref-dep)
4030                   (nconc (cdr (symbol-value ref-dep))
4031                          (list (symbol-value id-dep))))
4032         (set ref-dep (list nil (symbol-value id-dep)))))
4033     header))
4034
4035 (defun gnus-extract-message-id-from-in-reply-to (string)
4036   (if (string-match "<[^>]+>" string)
4037       (substring string (match-beginning 0) (match-end 0))
4038     nil))
4039
4040 (defun gnus-build-sparse-threads ()
4041   (let ((headers gnus-newsgroup-headers)
4042         (mail-parse-charset gnus-newsgroup-charset)
4043         (gnus-summary-ignore-duplicates t)
4044         header references generation relations
4045         subject child end new-child date)
4046     ;; First we create an alist of generations/relations, where
4047     ;; generations is how much we trust the relation, and the relation
4048     ;; is parent/child.
4049     (gnus-message 7 "Making sparse threads...")
4050     (save-excursion
4051       (nnheader-set-temp-buffer " *gnus sparse threads*")
4052       (while (setq header (pop headers))
4053         (when (and (setq references (mail-header-references header))
4054                    (not (string= references "")))
4055           (insert references)
4056           (setq child (mail-header-id header)
4057                 subject (mail-header-subject header)
4058                 date (mail-header-date header)
4059                 generation 0)
4060           (while (search-backward ">" nil t)
4061             (setq end (1+ (point)))
4062             (when (search-backward "<" nil t)
4063               (setq new-child (buffer-substring (point) end))
4064               (push (list (incf generation)
4065                           child (setq child new-child)
4066                           subject date)
4067                     relations)))
4068           (when child
4069             (push (list (1+ generation) child nil subject) relations))
4070           (erase-buffer)))
4071       (kill-buffer (current-buffer)))
4072     ;; Sort over trustworthiness.
4073     (mapcar
4074      (lambda (relation)
4075        (when (gnus-dependencies-add-header
4076               (make-full-mail-header-from-decoded-header
4077                gnus-reffed-article-number
4078                (nth 3 relation) "" (or (nth 4 relation) "")
4079                (nth 1 relation)
4080                (or (nth 2 relation) "") 0 0 "")
4081               gnus-newsgroup-dependencies nil)
4082          (push gnus-reffed-article-number gnus-newsgroup-limit)
4083          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4084          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4085                gnus-newsgroup-reads)
4086          (decf gnus-reffed-article-number)))
4087      (sort relations 'car-less-than-car))
4088     (gnus-message 7 "Making sparse threads...done")))
4089
4090 (defun gnus-build-old-threads ()
4091   ;; Look at all the articles that refer back to old articles, and
4092   ;; fetch the headers for the articles that aren't there.  This will
4093   ;; build complete threads - if the roots haven't been expired by the
4094   ;; server, that is.
4095   (let ((mail-parse-charset gnus-newsgroup-charset)
4096         id heads)
4097     (mapatoms
4098      (lambda (refs)
4099        (when (not (car (symbol-value refs)))
4100          (setq heads (cdr (symbol-value refs)))
4101          (while heads
4102            (if (memq (mail-header-number (caar heads))
4103                      gnus-newsgroup-dormant)
4104                (setq heads (cdr heads))
4105              (setq id (symbol-name refs))
4106              (while (and (setq id (gnus-build-get-header id))
4107                          (not (car (gnus-id-to-thread id)))))
4108              (setq heads nil)))))
4109      gnus-newsgroup-dependencies)))
4110
4111 (defsubst gnus-remove-odd-characters (string)
4112   "Translate STRING into something that doesn't contain weird characters."
4113   (mm-subst-char-in-string
4114    ?\r ?\-
4115    (mm-subst-char-in-string ?\n ?\- string t) t))
4116
4117 ;; This function has to be called with point after the article number
4118 ;; on the beginning of the line.
4119 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4120   (let ((eol (point-at-eol))
4121         (buffer (current-buffer))
4122         header references in-reply-to)
4123
4124     ;; overview: [num subject from date id refs chars lines misc]
4125     (unwind-protect
4126         (progn
4127           (narrow-to-region (point) eol)
4128           (unless (eobp)
4129             (forward-char))
4130
4131           (setq header
4132                 (make-full-mail-header
4133                  number                         ; number
4134                  (nnheader-nov-field)           ; subject
4135                  (nnheader-nov-field)           ; from
4136                  (nnheader-nov-field)           ; date
4137                  (nnheader-nov-read-message-id number)  ; id
4138                  (setq references (nnheader-nov-field)) ; refs
4139                  (nnheader-nov-read-integer)    ; chars
4140                  (nnheader-nov-read-integer)    ; lines
4141                  (unless (eobp)
4142                    (if (looking-at "Xref: ")
4143                        (goto-char (match-end 0)))
4144                    (nnheader-nov-field))        ; Xref
4145                  (nnheader-nov-parse-extra))))  ; extra
4146
4147       (widen))
4148
4149     (when (and (string= references "")
4150                (setq in-reply-to (mail-header-extra header))
4151                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4152       (mail-header-set-references
4153        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4154
4155     (when gnus-alter-header-function
4156       (funcall gnus-alter-header-function header))
4157     (gnus-dependencies-add-header header dependencies force-new)))
4158
4159 (defun gnus-build-get-header (id)
4160   "Look through the buffer of NOV lines and find the header to ID.
4161 Enter this line into the dependencies hash table, and return
4162 the id of the parent article (if any)."
4163   (let ((deps gnus-newsgroup-dependencies)
4164         found header)
4165     (prog1
4166         (save-excursion
4167           (set-buffer nntp-server-buffer)
4168           (let ((case-fold-search nil))
4169             (goto-char (point-min))
4170             (while (and (not found)
4171                         (search-forward id nil t))
4172               (beginning-of-line)
4173               (setq found (looking-at
4174                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4175                                    (regexp-quote id))))
4176               (or found (beginning-of-line 2)))
4177             (when found
4178               (beginning-of-line)
4179               (and
4180                (setq header (gnus-nov-parse-line
4181                              (read (current-buffer)) deps))
4182                (gnus-parent-id (mail-header-references header))))))
4183       (when header
4184         (let ((number (mail-header-number header)))
4185           (push number gnus-newsgroup-limit)
4186           (push header gnus-newsgroup-headers)
4187           (if (memq number gnus-newsgroup-unselected)
4188               (progn
4189                 (setq gnus-newsgroup-unreads
4190                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4191                                                number))
4192                 (setq gnus-newsgroup-unselected
4193                       (delq number gnus-newsgroup-unselected)))
4194             (push number gnus-newsgroup-ancient)))))))
4195
4196 (defun gnus-build-all-threads ()
4197   "Read all the headers."
4198   (let ((gnus-summary-ignore-duplicates t)
4199         (mail-parse-charset gnus-newsgroup-charset)
4200         (dependencies gnus-newsgroup-dependencies)
4201         header article)
4202     (save-excursion
4203       (set-buffer nntp-server-buffer)
4204       (let ((case-fold-search nil))
4205         (goto-char (point-min))
4206         (while (not (eobp))
4207           (ignore-errors
4208             (setq article (read (current-buffer))
4209                   header (gnus-nov-parse-line article dependencies)))
4210           (when header
4211             (with-current-buffer gnus-summary-buffer
4212               (push header gnus-newsgroup-headers)
4213               (if (memq (setq article (mail-header-number header))
4214                         gnus-newsgroup-unselected)
4215                   (progn
4216                     (setq gnus-newsgroup-unreads
4217                           (gnus-add-to-sorted-list
4218                            gnus-newsgroup-unreads article))
4219                     (setq gnus-newsgroup-unselected
4220                           (delq article gnus-newsgroup-unselected)))
4221                 (push article gnus-newsgroup-ancient)))
4222             (forward-line 1)))))))
4223
4224 (defun gnus-summary-update-article-line (article header)
4225   "Update the line for ARTICLE using HEADER."
4226   (let* ((id (mail-header-id header))
4227          (thread (gnus-id-to-thread id)))
4228     (unless thread
4229       (error "Article in no thread"))
4230     ;; Update the thread.
4231     (setcar thread header)
4232     (gnus-summary-goto-subject article)
4233     (let* ((datal (gnus-data-find-list article))
4234            (data (car datal))
4235            (buffer-read-only nil)
4236            (level (gnus-summary-thread-level)))
4237       (gnus-delete-line)
4238       (let ((inserted (- (point)
4239                          (progn
4240                            (gnus-summary-insert-line
4241                             header level nil
4242                             (memq article gnus-newsgroup-undownloaded)
4243                             (gnus-article-mark article)
4244                             (memq article gnus-newsgroup-replied)
4245                             (memq article gnus-newsgroup-expirable)
4246                             ;; Only insert the Subject string when it's different
4247                             ;; from the previous Subject string.
4248                             (if (and
4249                                  gnus-show-threads
4250                                  (gnus-subject-equal
4251                                   (condition-case ()
4252                                       (mail-header-subject
4253                                        (gnus-data-header
4254                                         (cadr
4255                                          (gnus-data-find-list
4256                                           article
4257                                           (gnus-data-list t)))))
4258                                     ;; Error on the side of excessive subjects.
4259                                     (error ""))
4260                                   (mail-header-subject header)))
4261                                 ""
4262                               (mail-header-subject header))
4263                             nil (cdr (assq article gnus-newsgroup-scored))
4264                             (memq article gnus-newsgroup-processable))
4265                            (point)))))
4266         (when (cdr datal)
4267           (gnus-data-update-list
4268            (cdr datal)
4269            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4270
4271 (defun gnus-summary-update-article (article &optional iheader)
4272   "Update ARTICLE in the summary buffer."
4273   (set-buffer gnus-summary-buffer)
4274   (let* ((header (gnus-summary-article-header article))
4275          (id (mail-header-id header))
4276          (data (gnus-data-find article))
4277          (thread (gnus-id-to-thread id))
4278          (references (mail-header-references header))
4279          (parent
4280           (gnus-id-to-thread
4281            (or (gnus-parent-id
4282                 (when (and references
4283                            (not (equal "" references)))
4284                   references))
4285                "none")))
4286          (buffer-read-only nil)
4287          (old (car thread)))
4288     (when thread
4289       (unless iheader
4290         (setcar thread nil)
4291         (when parent
4292           (delq thread parent)))
4293       (if (gnus-summary-insert-subject id header)
4294           ;; Set the (possibly) new article number in the data structure.
4295           (gnus-data-set-number data (gnus-id-to-article id))
4296         (setcar thread old)
4297         nil))))
4298
4299 (defun gnus-rebuild-thread (id &optional line)
4300   "Rebuild the thread containing ID.
4301 If LINE, insert the rebuilt thread starting on line LINE."
4302   (let ((buffer-read-only nil)
4303         old-pos current thread data)
4304     (if (not gnus-show-threads)
4305         (setq thread (list (car (gnus-id-to-thread id))))
4306       ;; Get the thread this article is part of.
4307       (setq thread (gnus-remove-thread id)))
4308     (setq old-pos (point-at-bol))
4309     (setq current (save-excursion
4310                     (and (re-search-backward "[\r\n]" nil t)
4311                          (gnus-summary-article-number))))
4312     ;; If this is a gathered thread, we have to go some re-gathering.
4313     (when (stringp (car thread))
4314       (let ((subject (car thread))
4315             roots thr)
4316         (setq thread (cdr thread))
4317         (while thread
4318           (unless (memq (setq thr (gnus-id-to-thread
4319                                    (gnus-root-id
4320                                     (mail-header-id (caar thread)))))
4321                         roots)
4322             (push thr roots))
4323           (setq thread (cdr thread)))
4324         ;; We now have all (unique) roots.
4325         (if (= (length roots) 1)
4326             ;; All the loose roots are now one solid root.
4327             (setq thread (car roots))
4328           (setq thread (cons subject (gnus-sort-threads roots))))))
4329     (let (threads)
4330       ;; We then insert this thread into the summary buffer.
4331       (when line
4332         (goto-char (point-min))
4333         (forward-line (1- line)))
4334       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4335         (if gnus-show-threads
4336             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4337           (gnus-summary-prepare-unthreaded thread))
4338         (setq data (nreverse gnus-newsgroup-data))
4339         (setq threads gnus-newsgroup-threads))
4340       ;; We splice the new data into the data structure.
4341       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4342       ;;!!! then we want to insert at the beginning of the buffer.
4343       ;;!!! That happens to be true with Gnus now, but that may
4344       ;;!!! change in the future.  Perhaps.
4345       (gnus-data-enter-list
4346        (if line nil current) data (- (point) old-pos))
4347       (setq gnus-newsgroup-threads
4348             (nconc threads gnus-newsgroup-threads))
4349       (gnus-data-compute-positions))))
4350
4351 (defun gnus-number-to-header (number)
4352   "Return the header for article NUMBER."
4353   (let ((headers gnus-newsgroup-headers))
4354     (while (and headers
4355                 (not (= number (mail-header-number (car headers)))))
4356       (pop headers))
4357     (when headers
4358       (car headers))))
4359
4360 (defun gnus-parent-headers (in-headers &optional generation)
4361   "Return the headers of the GENERATIONeth parent of HEADERS."
4362   (unless generation
4363     (setq generation 1))
4364   (let ((parent t)
4365         (headers in-headers)
4366         references)
4367     (while (and parent
4368                 (not (zerop generation))
4369                 (setq references (mail-header-references headers)))
4370       (setq headers (if (and references
4371                              (setq parent (gnus-parent-id references)))
4372                         (car (gnus-id-to-thread parent))
4373                       nil))
4374       (decf generation))
4375     (and (not (eq headers in-headers))
4376          headers)))
4377
4378 (defun gnus-id-to-thread (id)
4379   "Return the (sub-)thread where ID appears."
4380   (gnus-gethash id gnus-newsgroup-dependencies))
4381
4382 (defun gnus-id-to-article (id)
4383   "Return the article number of ID."
4384   (let ((thread (gnus-id-to-thread id)))
4385     (when (and thread
4386                (car thread))
4387       (mail-header-number (car thread)))))
4388
4389 (defun gnus-id-to-header (id)
4390   "Return the article headers of ID."
4391   (car (gnus-id-to-thread id)))
4392
4393 (defun gnus-article-displayed-root-p (article)
4394   "Say whether ARTICLE is a root(ish) article."
4395   (let ((level (gnus-summary-thread-level article))
4396         (refs (mail-header-references  (gnus-summary-article-header article)))
4397         particle)
4398     (cond
4399      ((null level) nil)
4400      ((zerop level) t)
4401      ((null refs) t)
4402      ((null (gnus-parent-id refs)) t)
4403      ((and (= 1 level)
4404            (null (setq particle (gnus-id-to-article
4405                                  (gnus-parent-id refs))))
4406            (null (gnus-summary-thread-level particle)))))))
4407
4408 (defun gnus-root-id (id)
4409   "Return the id of the root of the thread where ID appears."
4410   (let (last-id prev)
4411     (while (and id (setq prev (car (gnus-id-to-thread id))))
4412       (setq last-id id
4413             id (gnus-parent-id (mail-header-references prev))))
4414     last-id))
4415
4416 (defun gnus-articles-in-thread (thread)
4417   "Return the list of articles in THREAD."
4418   (cons (mail-header-number (car thread))
4419         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4420
4421 (defun gnus-remove-thread (id &optional dont-remove)
4422   "Remove the thread that has ID in it."
4423   (let (headers thread last-id)
4424     ;; First go up in this thread until we find the root.
4425     (setq last-id (gnus-root-id id)
4426           headers (message-flatten-list (gnus-id-to-thread last-id)))
4427     ;; We have now found the real root of this thread.  It might have
4428     ;; been gathered into some loose thread, so we have to search
4429     ;; through the threads to find the thread we wanted.
4430     (let ((threads gnus-newsgroup-threads)
4431           sub)
4432       (while threads
4433         (setq sub (car threads))
4434         (if (stringp (car sub))
4435             ;; This is a gathered thread, so we look at the roots
4436             ;; below it to find whether this article is in this
4437             ;; gathered root.
4438             (progn
4439               (setq sub (cdr sub))
4440               (while sub
4441                 (when (member (caar sub) headers)
4442                   (setq thread (car threads)
4443                         threads nil
4444                         sub nil))
4445                 (setq sub (cdr sub))))
4446           ;; It's an ordinary thread, so we check it.
4447           (when (eq (car sub) (car headers))
4448             (setq thread sub
4449                   threads nil)))
4450         (setq threads (cdr threads)))
4451       ;; If this article is in no thread, then it's a root.
4452       (if thread
4453           (unless dont-remove
4454             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4455         (setq thread (gnus-id-to-thread last-id)))
4456       (when thread
4457         (prog1
4458             thread                      ; We return this thread.
4459           (unless dont-remove
4460             (if (stringp (car thread))
4461                 (progn
4462                   ;; If we use dummy roots, then we have to remove the
4463                   ;; dummy root as well.
4464                   (when (eq gnus-summary-make-false-root 'dummy)
4465                     ;; We go to the dummy root by going to
4466                     ;; the first sub-"thread", and then one line up.
4467                     (gnus-summary-goto-article
4468                      (mail-header-number (caadr thread)))
4469                     (forward-line -1)
4470                     (gnus-delete-line)
4471                     (gnus-data-compute-positions))
4472                   (setq thread (cdr thread))
4473                   (while thread
4474                     (gnus-remove-thread-1 (car thread))
4475                     (setq thread (cdr thread))))
4476               (gnus-remove-thread-1 thread))))))))
4477
4478 (defun gnus-remove-thread-1 (thread)
4479   "Remove the thread THREAD recursively."
4480   (let ((number (mail-header-number (pop thread)))
4481         d)
4482     (setq thread (reverse thread))
4483     (while thread
4484       (gnus-remove-thread-1 (pop thread)))
4485     (when (setq d (gnus-data-find number))
4486       (goto-char (gnus-data-pos d))
4487       (gnus-summary-show-thread)
4488       (gnus-data-remove
4489        number
4490        (- (point-at-bol)
4491           (prog1
4492               (1+ (point-at-eol))
4493             (gnus-delete-line)))))))
4494
4495 (defun gnus-sort-threads-1 (threads func)
4496   (sort (mapcar (lambda (thread)
4497                   (cons (car thread)
4498                         (and (cdr thread)
4499                              (gnus-sort-threads-1 (cdr thread) func))))
4500                 threads) func))
4501
4502 (defun gnus-sort-threads (threads)
4503   "Sort THREADS."
4504   (if (not gnus-thread-sort-functions)
4505       threads
4506     (gnus-message 8 "Sorting threads...")
4507     (let ((max-lisp-eval-depth 5000))
4508       (prog1 (gnus-sort-threads-1
4509          threads
4510          (gnus-make-sort-function gnus-thread-sort-functions))
4511         (gnus-message 8 "Sorting threads...done")))))
4512
4513 (defun gnus-sort-articles (articles)
4514   "Sort ARTICLES."
4515   (when gnus-article-sort-functions
4516     (gnus-message 7 "Sorting articles...")
4517     (prog1
4518         (setq gnus-newsgroup-headers
4519               (sort articles (gnus-make-sort-function
4520                               gnus-article-sort-functions)))
4521       (gnus-message 7 "Sorting articles...done"))))
4522
4523 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4524 (defmacro gnus-thread-header (thread)
4525   "Return header of first article in THREAD.
4526 Note that THREAD must never, ever be anything else than a variable -
4527 using some other form will lead to serious barfage."
4528   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4529   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4530   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4531         (vector thread) 2))
4532
4533 (defsubst gnus-article-sort-by-number (h1 h2)
4534   "Sort articles by article number."
4535   (< (mail-header-number h1)
4536      (mail-header-number h2)))
4537
4538 (defun gnus-thread-sort-by-number (h1 h2)
4539   "Sort threads by root article number."
4540   (gnus-article-sort-by-number
4541    (gnus-thread-header h1) (gnus-thread-header h2)))
4542
4543 (defsubst gnus-article-sort-by-random (h1 h2)
4544   "Sort articles by article number."
4545   (zerop (random 2)))
4546
4547 (defun gnus-thread-sort-by-random (h1 h2)
4548   "Sort threads by root article number."
4549   (gnus-article-sort-by-random
4550    (gnus-thread-header h1) (gnus-thread-header h2)))
4551
4552 (defsubst gnus-article-sort-by-lines (h1 h2)
4553   "Sort articles by article Lines header."
4554   (< (mail-header-lines h1)
4555      (mail-header-lines h2)))
4556
4557 (defun gnus-thread-sort-by-lines (h1 h2)
4558   "Sort threads by root article Lines header."
4559   (gnus-article-sort-by-lines
4560    (gnus-thread-header h1) (gnus-thread-header h2)))
4561
4562 (defsubst gnus-article-sort-by-chars (h1 h2)
4563   "Sort articles by octet length."
4564   (< (mail-header-chars h1)
4565      (mail-header-chars h2)))
4566
4567 (defun gnus-thread-sort-by-chars (h1 h2)
4568   "Sort threads by root article octet length."
4569   (gnus-article-sort-by-chars
4570    (gnus-thread-header h1) (gnus-thread-header h2)))
4571
4572 (defsubst gnus-article-sort-by-author (h1 h2)
4573   "Sort articles by root author."
4574   (string-lessp
4575    (let ((addr (car (mime-entity-read-field h1 'From))))
4576      (or (std11-full-name-string addr)
4577          (std11-address-string addr)
4578          ""))
4579    (let ((addr (car (mime-entity-read-field h2 'From))))
4580      (or (std11-full-name-string addr)
4581          (std11-address-string addr)
4582          ""))
4583    ))
4584
4585 (defun gnus-thread-sort-by-author (h1 h2)
4586   "Sort threads by root author."
4587   (gnus-article-sort-by-author
4588    (gnus-thread-header h1)  (gnus-thread-header h2)))
4589
4590 (defsubst gnus-article-sort-by-recipient (h1 h2)
4591   "Sort articles by recipient."
4592   (string-lessp
4593    (let ((extract (funcall
4594                    gnus-extract-address-components
4595                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4596      (or (car extract) (cadr extract)))
4597    (let ((extract (funcall
4598                    gnus-extract-address-components
4599                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4600      (or (car extract) (cadr extract)))))
4601
4602 (defsubst gnus-article-sort-by-subject (h1 h2)
4603   "Sort articles by root subject."
4604   (string-lessp
4605    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4606    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4607
4608 (defun gnus-thread-sort-by-subject (h1 h2)
4609   "Sort threads by root subject."
4610   (gnus-article-sort-by-subject
4611    (gnus-thread-header h1) (gnus-thread-header h2)))
4612
4613 (defsubst gnus-article-sort-by-date (h1 h2)
4614   "Sort articles by root article date."
4615   (time-less-p
4616    (gnus-date-get-time (mail-header-date h1))
4617    (gnus-date-get-time (mail-header-date h2))))
4618
4619 (defun gnus-thread-sort-by-date (h1 h2)
4620   "Sort threads by root article date."
4621   (gnus-article-sort-by-date
4622    (gnus-thread-header h1) (gnus-thread-header h2)))
4623
4624 (defsubst gnus-article-sort-by-score (h1 h2)
4625   "Sort articles by root article score.
4626 Unscored articles will be counted as having a score of zero."
4627   (> (or (cdr (assq (mail-header-number h1)
4628                     gnus-newsgroup-scored))
4629          gnus-summary-default-score 0)
4630      (or (cdr (assq (mail-header-number h2)
4631                     gnus-newsgroup-scored))
4632          gnus-summary-default-score 0)))
4633
4634 (defun gnus-thread-sort-by-score (h1 h2)
4635   "Sort threads by root article score."
4636   (gnus-article-sort-by-score
4637    (gnus-thread-header h1) (gnus-thread-header h2)))
4638
4639 (defun gnus-thread-sort-by-total-score (h1 h2)
4640   "Sort threads by the sum of all scores in the thread.
4641 Unscored articles will be counted as having a score of zero."
4642   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4643
4644 (defun gnus-thread-total-score (thread)
4645   ;; This function find the total score of THREAD.
4646   (cond
4647    ((null thread)
4648     0)
4649    ((consp thread)
4650     (if (stringp (car thread))
4651         (apply gnus-thread-score-function 0
4652                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4653       (gnus-thread-total-score-1 thread)))
4654    (t
4655     (gnus-thread-total-score-1 (list thread)))))
4656
4657 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4658   "Sort threads such that the thread with the most recently arrived article comes first."
4659   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4660
4661 (defun gnus-thread-highest-number (thread)
4662   "Return the highest article number in THREAD."
4663   (apply 'max (mapcar (lambda (header)
4664                         (mail-header-number header))
4665                       (message-flatten-list thread))))
4666
4667 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4668   "Sort threads such that the thread with the most recently dated article comes first."
4669   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4670
4671 (defun gnus-thread-latest-date (thread)
4672   "Return the highest article date in THREAD."
4673   (let ((previous-time 0))
4674     (apply 'max
4675            (mapcar
4676             (lambda (header)
4677               (setq previous-time
4678                     (condition-case ()
4679                         (time-to-seconds (mail-header-parse-date
4680                                           (mail-header-date header)))
4681                       (error previous-time))))
4682             (sort
4683              (message-flatten-list thread)
4684              (lambda (h1 h2)
4685                (< (mail-header-number h1)
4686                   (mail-header-number h2))))))))
4687
4688 (defun gnus-thread-total-score-1 (root)
4689   ;; This function find the total score of the thread below ROOT.
4690   (setq root (car root))
4691   (apply gnus-thread-score-function
4692          (or (append
4693               (mapcar 'gnus-thread-total-score
4694                       (cdr (gnus-id-to-thread (mail-header-id root))))
4695               (when (> (mail-header-number root) 0)
4696                 (list (or (cdr (assq (mail-header-number root)
4697                                      gnus-newsgroup-scored))
4698                           gnus-summary-default-score 0))))
4699              (list gnus-summary-default-score)
4700              '(0))))
4701
4702 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4703 (defvar gnus-tmp-prev-subject nil)
4704 (defvar gnus-tmp-false-parent nil)
4705 (defvar gnus-tmp-root-expunged nil)
4706 (defvar gnus-tmp-dummy-line nil)
4707
4708 (eval-when-compile (defvar gnus-tmp-header))
4709 (defun gnus-extra-header (type &optional header)
4710   "Return the extra header of TYPE."
4711   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4712       ""))
4713
4714 (defvar gnus-tmp-thread-tree-header-string "")
4715
4716 (defcustom gnus-sum-thread-tree-root "> "
4717   "With %B spec, used for the root of a thread.
4718 If nil, use subject instead."
4719   :version "22.1"
4720   :type '(radio (const :format "%v  " nil) string)
4721   :group 'gnus-thread)
4722 (defcustom gnus-sum-thread-tree-false-root "> "
4723   "With %B spec, used for a false root of a thread.
4724 If nil, use subject instead."
4725   :version "22.1"
4726   :type '(radio (const :format "%v  " nil) string)
4727   :group 'gnus-thread)
4728 (defcustom gnus-sum-thread-tree-single-indent ""
4729   "With %B spec, used for a thread with just one message.
4730 If nil, use subject instead."
4731   :version "22.1"
4732   :type '(radio (const :format "%v  " nil) string)
4733   :group 'gnus-thread)
4734 (defcustom gnus-sum-thread-tree-vertical "| "
4735   "With %B spec, used for drawing a vertical line."
4736   :version "22.1"
4737   :type 'string
4738   :group 'gnus-thread)
4739 (defcustom gnus-sum-thread-tree-indent "  "
4740   "With %B spec, used for indenting."
4741   :version "22.1"
4742   :type 'string
4743   :group 'gnus-thread)
4744 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4745   "With %B spec, used for a leaf with brothers."
4746   :version "22.1"
4747   :type 'string
4748   :group 'gnus-thread)
4749 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4750   "With %B spec, used for a leaf without brothers."
4751   :version "22.1"
4752   :type 'string
4753   :group 'gnus-thread)
4754
4755 (defun gnus-summary-prepare-threads (threads)
4756   "Prepare summary buffer from THREADS and indentation LEVEL.
4757 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4758 or a straight list of headers."
4759   (gnus-message 7 "Generating summary...")
4760
4761   (setq gnus-newsgroup-threads threads)
4762   (beginning-of-line)
4763
4764   (let ((gnus-tmp-level 0)
4765         (default-score (or gnus-summary-default-score 0))
4766         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4767         (building-line-count gnus-summary-display-while-building)
4768         (building-count (integerp gnus-summary-display-while-building))
4769         thread number subject stack state gnus-tmp-gathered beg-match
4770         new-roots gnus-tmp-new-adopts thread-end simp-subject
4771         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4772         gnus-tmp-replied gnus-tmp-subject-or-nil
4773         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4774         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4775         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4776         tree-stack)
4777
4778     (setq gnus-tmp-prev-subject nil
4779           gnus-tmp-thread-tree-header-string "")
4780
4781     (if (vectorp (car threads))
4782         ;; If this is a straight (sic) list of headers, then a
4783         ;; threaded summary display isn't required, so we just create
4784         ;; an unthreaded one.
4785         (gnus-summary-prepare-unthreaded threads)
4786
4787       ;; Do the threaded display.
4788
4789       (if gnus-summary-display-while-building
4790           (switch-to-buffer (buffer-name)))
4791       (while (or threads stack gnus-tmp-new-adopts new-roots)
4792
4793         (if (and (= gnus-tmp-level 0)
4794                  (or (not stack)
4795                      (= (caar stack) 0))
4796                  (not gnus-tmp-false-parent)
4797                  (or gnus-tmp-new-adopts new-roots))
4798             (if gnus-tmp-new-adopts
4799                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4800                       thread (list (car gnus-tmp-new-adopts))
4801                       gnus-tmp-header (caar thread)
4802                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4803               (when new-roots
4804                 (setq thread (list (car new-roots))
4805                       gnus-tmp-header (caar thread)
4806                       new-roots (cdr new-roots))))
4807
4808           (if threads
4809               ;; If there are some threads, we do them before the
4810               ;; threads on the stack.
4811               (setq thread threads
4812                     gnus-tmp-header (caar thread))
4813             ;; There were no current threads, so we pop something off
4814             ;; the stack.
4815             (setq state (car stack)
4816                   gnus-tmp-level (car state)
4817                   tree-stack (cadr state)
4818                   thread (caddr state)
4819                   stack (cdr stack)
4820                   gnus-tmp-header (caar thread))))
4821
4822         (setq gnus-tmp-false-parent nil)
4823         (setq gnus-tmp-root-expunged nil)
4824         (setq thread-end nil)
4825
4826         (if (stringp gnus-tmp-header)
4827             ;; The header is a dummy root.
4828             (cond
4829              ((eq gnus-summary-make-false-root 'adopt)
4830               ;; We let the first article adopt the rest.
4831               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4832                                                (cddar thread)))
4833               (setq gnus-tmp-gathered
4834                     (nconc (mapcar
4835                             (lambda (h) (mail-header-number (car h)))
4836                             (cddar thread))
4837                            gnus-tmp-gathered))
4838               (setq thread (cons (list (caar thread)
4839                                        (cadar thread))
4840                                  (cdr thread)))
4841               (setq gnus-tmp-level -1
4842                     gnus-tmp-false-parent t))
4843              ((eq gnus-summary-make-false-root 'empty)
4844               ;; We print adopted articles with empty subject fields.
4845               (setq gnus-tmp-gathered
4846                     (nconc (mapcar
4847                             (lambda (h) (mail-header-number (car h)))
4848                             (cddar thread))
4849                            gnus-tmp-gathered))
4850               (setq gnus-tmp-level -1))
4851              ((eq gnus-summary-make-false-root 'dummy)
4852               ;; We remember that we probably want to output a dummy
4853               ;; root.
4854               (setq gnus-tmp-dummy-line gnus-tmp-header)
4855               (setq gnus-tmp-prev-subject gnus-tmp-header))
4856              (t
4857               ;; We do not make a root for the gathered
4858               ;; sub-threads at all.
4859               (setq gnus-tmp-level -1)))
4860
4861           (setq number (mail-header-number gnus-tmp-header)
4862                 subject (mail-header-subject gnus-tmp-header)
4863                 simp-subject (gnus-simplify-subject-fully subject))
4864
4865           (cond
4866            ;; If the thread has changed subject, we might want to make
4867            ;; this subthread into a root.
4868            ((and (null gnus-thread-ignore-subject)
4869                  (not (zerop gnus-tmp-level))
4870                  gnus-tmp-prev-subject
4871                  (not (string= gnus-tmp-prev-subject simp-subject)))
4872             (setq new-roots (nconc new-roots (list (car thread)))
4873                   thread-end t
4874                   gnus-tmp-header nil))
4875            ;; If the article lies outside the current limit,
4876            ;; then we do not display it.
4877            ((not (memq number gnus-newsgroup-limit))
4878             (setq gnus-tmp-gathered
4879                   (nconc (mapcar
4880                           (lambda (h) (mail-header-number (car h)))
4881                           (cdar thread))
4882                          gnus-tmp-gathered))
4883             (setq gnus-tmp-new-adopts (if (cdar thread)
4884                                           (append gnus-tmp-new-adopts
4885                                                   (cdar thread))
4886                                         gnus-tmp-new-adopts)
4887                   thread-end t
4888                   gnus-tmp-header nil)
4889             (when (zerop gnus-tmp-level)
4890               (setq gnus-tmp-root-expunged t)))
4891            ;; Perhaps this article is to be marked as read?
4892            ((and gnus-summary-mark-below
4893                  (< (or (cdr (assq number gnus-newsgroup-scored))
4894                         default-score)
4895                     gnus-summary-mark-below)
4896                  ;; Don't touch sparse articles.
4897                  (not (gnus-summary-article-sparse-p number))
4898                  (not (gnus-summary-article-ancient-p number)))
4899             (setq gnus-newsgroup-unreads
4900                   (delq number gnus-newsgroup-unreads))
4901             (if gnus-newsgroup-auto-expire
4902                 (setq gnus-newsgroup-expirable
4903                       (gnus-add-to-sorted-list
4904                        gnus-newsgroup-expirable number))
4905               (push (cons number gnus-low-score-mark)
4906                     gnus-newsgroup-reads))))
4907
4908           (when gnus-tmp-header
4909             ;; We may have an old dummy line to output before this
4910             ;; article.
4911             (when (and gnus-tmp-dummy-line
4912                        (gnus-subject-equal
4913                         gnus-tmp-dummy-line
4914                         (mail-header-subject gnus-tmp-header)))
4915               (gnus-summary-insert-dummy-line
4916                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4917               (setq gnus-tmp-dummy-line nil))
4918
4919             ;; Compute the mark.
4920             (setq gnus-tmp-unread (gnus-article-mark number))
4921
4922             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4923                                   gnus-tmp-header gnus-tmp-level)
4924                   gnus-newsgroup-data)
4925
4926             ;; Actually insert the line.
4927             (setq
4928              gnus-tmp-subject-or-nil
4929              (cond
4930               ((and gnus-thread-ignore-subject
4931                     gnus-tmp-prev-subject
4932                     (not (string= gnus-tmp-prev-subject simp-subject)))
4933                subject)
4934               ((zerop gnus-tmp-level)
4935                (if (and (eq gnus-summary-make-false-root 'empty)
4936                         (memq number gnus-tmp-gathered)
4937                         gnus-tmp-prev-subject
4938                         (string= gnus-tmp-prev-subject simp-subject))
4939                    gnus-summary-same-subject
4940                  subject))
4941               (t gnus-summary-same-subject)))
4942             (if (and (eq gnus-summary-make-false-root 'adopt)
4943                      (= gnus-tmp-level 1)
4944                      (memq number gnus-tmp-gathered))
4945                 (setq gnus-tmp-opening-bracket ?\<
4946                       gnus-tmp-closing-bracket ?\>)
4947               (setq gnus-tmp-opening-bracket ?\[
4948                     gnus-tmp-closing-bracket ?\]))
4949             (setq
4950              gnus-tmp-indentation
4951              (aref gnus-thread-indent-array gnus-tmp-level)
4952              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4953              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4954                                 gnus-summary-default-score 0)
4955              gnus-tmp-score-char
4956              (if (or (null gnus-summary-default-score)
4957                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4958                          gnus-summary-zcore-fuzz))
4959                  ?\ ;;;Whitespace
4960                (if (< gnus-tmp-score gnus-summary-default-score)
4961                    gnus-score-below-mark gnus-score-over-mark))
4962              gnus-tmp-replied
4963              (cond ((memq number gnus-newsgroup-processable)
4964                     gnus-process-mark)
4965                    ((memq number gnus-newsgroup-cached)
4966                     gnus-cached-mark)
4967                    ((memq number gnus-newsgroup-replied)
4968                     gnus-replied-mark)
4969                    ((memq number gnus-newsgroup-forwarded)
4970                     gnus-forwarded-mark)
4971                    ((memq number gnus-newsgroup-saved)
4972                     gnus-saved-mark)
4973                    ((memq number gnus-newsgroup-recent)
4974                     gnus-recent-mark)
4975                    ((memq number gnus-newsgroup-unseen)
4976                     gnus-unseen-mark)
4977                    (t gnus-no-mark))
4978              gnus-tmp-downloaded
4979              (cond ((memq number gnus-newsgroup-undownloaded)
4980                     gnus-undownloaded-mark)
4981                    (gnus-newsgroup-agentized
4982                     gnus-downloaded-mark)
4983                    (t
4984                     gnus-no-mark))
4985              gnus-tmp-from (mail-header-from gnus-tmp-header)
4986              gnus-tmp-name
4987              (cond
4988               ((string-match "<[^>]+> *$" gnus-tmp-from)
4989                (setq beg-match (match-beginning 0))
4990                (or (and (string-match "^\".+\"" gnus-tmp-from)
4991                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4992                    (substring gnus-tmp-from 0 beg-match)))
4993               ((string-match "(.+)" gnus-tmp-from)
4994                (substring gnus-tmp-from
4995                           (1+ (match-beginning 0)) (1- (match-end 0))))
4996               (t gnus-tmp-from))
4997
4998              ;; Do the %B string
4999              gnus-tmp-thread-tree-header-string
5000              (cond
5001               ((not gnus-show-threads) "")
5002               ((zerop gnus-tmp-level)
5003                (cond ((cdar thread)
5004                       (or gnus-sum-thread-tree-root subject))
5005                      (gnus-tmp-new-adopts
5006                       (or gnus-sum-thread-tree-false-root subject))
5007                      (t
5008                       (or gnus-sum-thread-tree-single-indent subject))))
5009               (t
5010                (concat (apply 'concat
5011                               (mapcar (lambda (item)
5012                                         (if (= item 1)
5013                                             gnus-sum-thread-tree-vertical
5014                                           gnus-sum-thread-tree-indent))
5015                                       (cdr (reverse tree-stack))))
5016                        (if (nth 1 thread)
5017                            gnus-sum-thread-tree-leaf-with-other
5018                          gnus-sum-thread-tree-single-leaf)))))
5019             (when (string= gnus-tmp-name "")
5020               (setq gnus-tmp-name gnus-tmp-from))
5021             (unless (numberp gnus-tmp-lines)
5022               (setq gnus-tmp-lines -1))
5023             (if (= gnus-tmp-lines -1)
5024                 (setq gnus-tmp-lines "?")
5025               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5026               (gnus-put-text-property
5027              (point)
5028              (progn (eval gnus-summary-line-format-spec) (point))
5029                'gnus-number number)
5030             (when gnus-visual-p
5031               (forward-line -1)
5032               (gnus-run-hooks 'gnus-summary-update-hook)
5033               (forward-line 1))
5034
5035             (setq gnus-tmp-prev-subject simp-subject)))
5036
5037         (when (nth 1 thread)
5038           (push (list (max 0 gnus-tmp-level)
5039                       (copy-sequence tree-stack)
5040                       (nthcdr 1 thread))
5041                 stack))
5042         (push (if (nth 1 thread) 1 0) tree-stack)
5043         (incf gnus-tmp-level)
5044         (setq threads (if thread-end nil (cdar thread)))
5045         (if gnus-summary-display-while-building
5046             (if building-count
5047                 (progn
5048                   ;; use a set frequency
5049                   (setq building-line-count (1- building-line-count))
5050                   (when (= building-line-count 0)
5051                     (sit-for 0)
5052                     (setq building-line-count
5053                           gnus-summary-display-while-building)))
5054               ;; always
5055               (sit-for 0)))
5056         (unless threads
5057           (setq gnus-tmp-level 0)))))
5058   (gnus-message 7 "Generating summary...done"))
5059
5060 (defun gnus-summary-prepare-unthreaded (headers)
5061   "Generate an unthreaded summary buffer based on HEADERS."
5062   (let (header number mark)
5063
5064     (beginning-of-line)
5065
5066     (while headers
5067       ;; We may have to root out some bad articles...
5068       (when (memq (setq number (mail-header-number
5069                                 (setq header (pop headers))))
5070                   gnus-newsgroup-limit)
5071         ;; Mark article as read when it has a low score.
5072         (when (and gnus-summary-mark-below
5073                    (< (or (cdr (assq number gnus-newsgroup-scored))
5074                           gnus-summary-default-score 0)
5075                       gnus-summary-mark-below)
5076                    (not (gnus-summary-article-ancient-p number)))
5077           (setq gnus-newsgroup-unreads
5078                 (delq number gnus-newsgroup-unreads))
5079           (if gnus-newsgroup-auto-expire
5080               (push number gnus-newsgroup-expirable)
5081             (push (cons number gnus-low-score-mark)
5082                   gnus-newsgroup-reads)))
5083
5084         (setq mark (gnus-article-mark number))
5085         (push (gnus-data-make number mark (1+ (point)) header 0)
5086               gnus-newsgroup-data)
5087         (gnus-summary-insert-line
5088          header 0 number
5089          (memq number gnus-newsgroup-undownloaded)
5090          mark (memq number gnus-newsgroup-replied)
5091          (memq number gnus-newsgroup-expirable)
5092          (mail-header-subject header) nil
5093          (cdr (assq number gnus-newsgroup-scored))
5094          (memq number gnus-newsgroup-processable))))))
5095
5096 (defun gnus-summary-remove-list-identifiers ()
5097   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5098   (let ((regexp (if (consp gnus-list-identifiers)
5099                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5100                   gnus-list-identifiers))
5101         changed subject)
5102     (when regexp
5103       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5104       (dolist (header gnus-newsgroup-headers)
5105         (setq subject (mail-header-subject header)
5106               changed nil)
5107         (while (string-match regexp subject)
5108           (setq subject
5109                 (concat (substring subject 0 (match-beginning 1))
5110                         (substring subject (match-end 0)))
5111                 changed t))
5112         (when changed
5113           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5114             (setq subject
5115                   (concat (substring subject 0 (match-beginning 1))
5116                           (substring subject (match-end 1)))))
5117           (mail-header-set-subject header subject))))))
5118
5119 (defun gnus-fetch-headers (articles)
5120   "Fetch headers of ARTICLES."
5121   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5122     (gnus-message 5 "Fetching headers for %s..." name)
5123     (prog1
5124         (if (eq 'nov
5125                 (setq gnus-headers-retrieved-by
5126                       (gnus-retrieve-headers
5127                        articles gnus-newsgroup-name
5128                        ;; We might want to fetch old headers, but
5129                        ;; not if there is only 1 article.
5130                        (and (or (and
5131                                  (not (eq gnus-fetch-old-headers 'some))
5132                                  (not (numberp gnus-fetch-old-headers)))
5133                                 (> (length articles) 1))
5134                             gnus-fetch-old-headers))))
5135             (gnus-get-newsgroup-headers-xover
5136              articles nil nil gnus-newsgroup-name t)
5137           (gnus-get-newsgroup-headers))
5138       (gnus-message 5 "Fetching headers for %s...done" name))))
5139
5140 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5141   "Select newsgroup GROUP.
5142 If READ-ALL is non-nil, all articles in the group are selected.
5143 If SELECT-ARTICLES, only select those articles from GROUP."
5144   (let* ((entry (gnus-group-entry group))
5145          ;;!!! Dirty hack; should be removed.
5146          (gnus-summary-ignore-duplicates
5147           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5148               t
5149             gnus-summary-ignore-duplicates))
5150          (info (nth 2 entry))
5151          articles fetched-articles cached)
5152
5153     (unless (gnus-check-server
5154              (set (make-local-variable 'gnus-current-select-method)
5155                   (gnus-find-method-for-group group)))
5156       (error "Couldn't open server"))
5157
5158     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5159         (gnus-activate-group group)     ; Or we can activate it...
5160         (progn                          ; Or we bug out.
5161           (when (equal major-mode 'gnus-summary-mode)
5162             (gnus-kill-buffer (current-buffer)))
5163           (error "Couldn't activate group %s: %s"
5164                  group (gnus-status-message group))))
5165
5166     (unless (gnus-request-group group t)
5167       (when (equal major-mode 'gnus-summary-mode)
5168         (gnus-kill-buffer (current-buffer)))
5169       (error "Couldn't request group %s: %s"
5170              group (gnus-status-message group)))
5171
5172     (when gnus-agent
5173       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5174
5175       (setq gnus-summary-use-undownloaded-faces
5176             (gnus-agent-find-parameter
5177              group
5178              'agent-enable-undownloaded-faces)))
5179
5180     (setq gnus-newsgroup-name group
5181           gnus-newsgroup-unselected nil
5182           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5183
5184     (let ((display (gnus-group-find-parameter group 'display)))
5185       (setq gnus-newsgroup-display
5186             (cond
5187              ((not (zerop (or (car-safe read-all) 0)))
5188               ;; The user entered the group with C-u SPC/RET, let's show
5189               ;; all articles.
5190               'gnus-not-ignore)
5191              ((eq display 'all)
5192               'gnus-not-ignore)
5193              ((arrayp display)
5194               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5195              ((numberp display)
5196               ;; The following is probably the "correct" solution, but
5197               ;; it makes Gnus fetch all headers and then limit the
5198               ;; articles (which is slow), so instead we hack the
5199               ;; select-articles parameter instead. -- Simon Josefsson
5200               ;; <jas@kth.se>
5201               ;;
5202               ;; (gnus-byte-compile
5203               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5204               ;;                         display)))))
5205               (setq select-articles
5206                     (gnus-uncompress-range
5207                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5208                              (if (> tmp 0)
5209                                  tmp
5210                                1))
5211                            (cdr (gnus-active group)))))
5212               nil)
5213              (t
5214               nil))))
5215
5216     (gnus-summary-setup-default-charset)
5217
5218     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5219     (when (gnus-virtual-group-p group)
5220       (setq cached gnus-newsgroup-cached))
5221
5222     (setq gnus-newsgroup-unreads
5223           (gnus-sorted-ndifference
5224            (gnus-sorted-ndifference gnus-newsgroup-unreads
5225                                     gnus-newsgroup-marked)
5226            gnus-newsgroup-dormant))
5227
5228     (setq gnus-newsgroup-processable nil)
5229
5230     (gnus-update-read-articles group gnus-newsgroup-unreads)
5231
5232     ;; Adjust and set lists of article marks.
5233     (when info
5234       (gnus-adjust-marked-articles info))
5235     (if (setq articles select-articles)
5236         (setq gnus-newsgroup-unselected
5237               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5238       (setq articles (gnus-articles-to-read group read-all)))
5239
5240     (cond
5241      ((null articles)
5242       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5243       'quit)
5244      ((eq articles 0) nil)
5245      (t
5246       ;; Init the dependencies hash table.
5247       (setq gnus-newsgroup-dependencies
5248             (gnus-make-hashtable (length articles)))
5249       (gnus-set-global-variables)
5250       ;; Retrieve the headers and read them in.
5251
5252       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5253
5254       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5255       (when cached
5256         (setq gnus-newsgroup-cached cached))
5257
5258       ;; Suppress duplicates?
5259       (when gnus-suppress-duplicates
5260         (gnus-dup-suppress-articles))
5261
5262       ;; Set the initial limit.
5263       (setq gnus-newsgroup-limit (copy-sequence articles))
5264       ;; Remove canceled articles from the list of unread articles.
5265       (setq fetched-articles
5266             (mapcar (lambda (headers) (mail-header-number headers))
5267                     gnus-newsgroup-headers))
5268       (setq gnus-newsgroup-articles fetched-articles)
5269       (setq gnus-newsgroup-unreads
5270             (gnus-sorted-nintersection
5271              gnus-newsgroup-unreads fetched-articles))
5272       (gnus-compute-unseen-list)
5273
5274       ;; Removed marked articles that do not exist.
5275       (gnus-update-missing-marks
5276        (gnus-sorted-difference articles fetched-articles))
5277       ;; We might want to build some more threads first.
5278       (when (and gnus-fetch-old-headers
5279                  (eq gnus-headers-retrieved-by 'nov))
5280         (if (eq gnus-fetch-old-headers 'invisible)
5281             (gnus-build-all-threads)
5282           (gnus-build-old-threads)))
5283       ;; Let the Gnus agent mark articles as read.
5284       (when gnus-agent
5285         (gnus-agent-get-undownloaded-list))
5286       ;; Remove list identifiers from subject
5287       (when gnus-list-identifiers
5288         (gnus-summary-remove-list-identifiers))
5289       ;; Check whether auto-expire is to be done in this group.
5290       (setq gnus-newsgroup-auto-expire
5291             (gnus-group-auto-expirable-p group))
5292       ;; Set up the article buffer now, if necessary.
5293       (unless gnus-single-article-buffer
5294         (gnus-article-setup-buffer))
5295       ;; First and last article in this newsgroup.
5296       (when gnus-newsgroup-headers
5297         (setq gnus-newsgroup-begin
5298               (mail-header-number (car gnus-newsgroup-headers))
5299               gnus-newsgroup-end
5300               (mail-header-number
5301                (gnus-last-element gnus-newsgroup-headers))))
5302       ;; GROUP is successfully selected.
5303       (or gnus-newsgroup-headers t)))))
5304
5305 (defun gnus-compute-unseen-list ()
5306   ;; The `seen' marks are treated specially.
5307   (if (not gnus-newsgroup-seen)
5308       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5309     (setq gnus-newsgroup-unseen
5310           (gnus-inverse-list-range-intersection
5311            gnus-newsgroup-articles gnus-newsgroup-seen))))
5312
5313 (defun gnus-summary-display-make-predicate (display)
5314   (require 'gnus-agent)
5315   (when (= (length display) 1)
5316     (setq display (car display)))
5317   (unless gnus-summary-display-cache
5318     (dolist (elem (append '((unread . unread)
5319                             (read . read)
5320                             (unseen . unseen))
5321                           gnus-article-mark-lists))
5322       (push (cons (cdr elem)
5323                   (gnus-byte-compile
5324                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5325             gnus-summary-display-cache)))
5326   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5327         (gnus-category-predicate-cache gnus-summary-display-cache))
5328     (gnus-get-predicate display)))
5329
5330 ;; Uses the dynamically bound `number' variable.
5331 (eval-when-compile
5332   (defvar number))
5333 (defun gnus-article-marked-p (type &optional article)
5334   (let ((article (or article number)))
5335     (cond
5336      ((eq type 'tick)
5337       (memq article gnus-newsgroup-marked))
5338      ((eq type 'spam)
5339       (memq article gnus-newsgroup-spam-marked))
5340      ((eq type 'unsend)
5341       (memq article gnus-newsgroup-unsendable))
5342      ((eq type 'undownload)
5343       (memq article gnus-newsgroup-undownloaded))
5344      ((eq type 'download)
5345       (memq article gnus-newsgroup-downloadable))
5346      ((eq type 'unread)
5347       (memq article gnus-newsgroup-unreads))
5348      ((eq type 'read)
5349       (memq article gnus-newsgroup-reads))
5350      ((eq type 'dormant)
5351       (memq article gnus-newsgroup-dormant) )
5352      ((eq type 'expire)
5353       (memq article gnus-newsgroup-expirable))
5354      ((eq type 'reply)
5355       (memq article gnus-newsgroup-replied))
5356      ((eq type 'killed)
5357       (memq article gnus-newsgroup-killed))
5358      ((eq type 'bookmark)
5359       (assq article gnus-newsgroup-bookmarks))
5360      ((eq type 'score)
5361       (assq article gnus-newsgroup-scored))
5362      ((eq type 'save)
5363       (memq article gnus-newsgroup-saved))
5364      ((eq type 'cache)
5365       (memq article gnus-newsgroup-cached))
5366      ((eq type 'forward)
5367       (memq article gnus-newsgroup-forwarded))
5368      ((eq type 'seen)
5369       (not (memq article gnus-newsgroup-unseen)))
5370      ((eq type 'recent)
5371       (memq article gnus-newsgroup-recent))
5372      (t t))))
5373
5374 (defun gnus-articles-to-read (group &optional read-all)
5375   "Find out what articles the user wants to read."
5376   (let* ((articles
5377           ;; Select all articles if `read-all' is non-nil, or if there
5378           ;; are no unread articles.
5379           (if (or read-all
5380                   (and (zerop (length gnus-newsgroup-marked))
5381                        (zerop (length gnus-newsgroup-unreads)))
5382                   ;; Fetch all if the predicate is non-nil.
5383                   gnus-newsgroup-display)
5384               ;; We want to select the headers for all the articles in
5385               ;; the group, so we select either all the active
5386               ;; articles in the group, or (if that's nil), the
5387               ;; articles in the cache.
5388               (or
5389                (gnus-uncompress-range (gnus-active group))
5390                (gnus-cache-articles-in-group group))
5391             ;; Select only the "normal" subset of articles.
5392             (gnus-sorted-nunion
5393              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5394              gnus-newsgroup-unreads)))
5395          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5396          (scored (length scored-list))
5397          (number (length articles))
5398          (marked (+ (length gnus-newsgroup-marked)
5399                     (length gnus-newsgroup-dormant)))
5400          (select
5401           (cond
5402            ((numberp read-all)
5403             read-all)
5404            ((numberp gnus-newsgroup-display)
5405             gnus-newsgroup-display)
5406            (t
5407             (condition-case ()
5408                 (cond
5409                  ((and (or (<= scored marked) (= scored number))
5410                        (numberp gnus-large-newsgroup)
5411                        (> number gnus-large-newsgroup))
5412                   (let* ((cursor-in-echo-area nil)
5413                          (initial (gnus-parameter-large-newsgroup-initial
5414                                    gnus-newsgroup-name))
5415                          (input
5416                           (read-string
5417                            (format
5418                             "How many articles from %s (%s %d): "
5419                             (gnus-limit-string
5420                              (gnus-group-decoded-name gnus-newsgroup-name)
5421                              35)
5422                             (if initial "max" "default")
5423                             number)
5424                            (if initial
5425                                (cons (number-to-string initial)
5426                                      0)))))
5427                     (if (string-match "^[ \t]*$" input) number input)))
5428                  ((and (> scored marked) (< scored number)
5429                        (> (- scored number) 20))
5430                   (let ((input
5431                          (read-string
5432                           (format "%s %s (%d scored, %d total): "
5433                                   "How many articles from"
5434                                   (gnus-group-decoded-name group)
5435                                   scored number))))
5436                     (if (string-match "^[ \t]*$" input)
5437                         number input)))
5438                  (t number))
5439               (quit
5440                (message "Quit getting the articles to read")
5441                nil))))))
5442     (setq select (if (stringp select) (string-to-number select) select))
5443     (if (or (null select) (zerop select))
5444         select
5445       (if (and (not (zerop scored)) (<= (abs select) scored))
5446           (progn
5447             (setq articles (sort scored-list '<))
5448             (setq number (length articles)))
5449         (setq articles (copy-sequence articles)))
5450
5451       (when (< (abs select) number)
5452         (if (< select 0)
5453             ;; Select the N oldest articles.
5454             (setcdr (nthcdr (1- (abs select)) articles) nil)
5455           ;; Select the N most recent articles.
5456           (setq articles (nthcdr (- number select) articles))))
5457       (setq gnus-newsgroup-unselected
5458             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5459       (when gnus-alter-articles-to-read-function
5460         (setq articles
5461               (sort
5462                (funcall gnus-alter-articles-to-read-function
5463                         gnus-newsgroup-name articles)
5464                '<)))
5465       articles)))
5466
5467 (defun gnus-killed-articles (killed articles)
5468   (let (out)
5469     (while articles
5470       (when (inline (gnus-member-of-range (car articles) killed))
5471         (push (car articles) out))
5472       (setq articles (cdr articles)))
5473     out))
5474
5475 (defun gnus-uncompress-marks (marks)
5476   "Uncompress the mark ranges in MARKS."
5477   (let ((uncompressed '(score bookmark))
5478         out)
5479     (while marks
5480       (if (memq (caar marks) uncompressed)
5481           (push (car marks) out)
5482         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5483       (setq marks (cdr marks)))
5484     out))
5485
5486 (defun gnus-article-mark-to-type (mark)
5487   "Return the type of MARK."
5488   (or (cadr (assq mark gnus-article-special-mark-lists))
5489       'list))
5490
5491 (defun gnus-article-unpropagatable-p (mark)
5492   "Return whether MARK should be propagated to back end."
5493   (memq mark gnus-article-unpropagated-mark-lists))
5494
5495 (defun gnus-adjust-marked-articles (info)
5496   "Set all article lists and remove all marks that are no longer valid."
5497   (let* ((marked-lists (gnus-info-marks info))
5498          (active (gnus-active (gnus-info-group info)))
5499          (min (car active))
5500          (max (cdr active))
5501          (types gnus-article-mark-lists)
5502          marks var articles article mark mark-type
5503          bgn end)
5504
5505     (dolist (marks marked-lists)
5506       (setq mark (car marks)
5507             mark-type (gnus-article-mark-to-type mark)
5508             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5509
5510       ;; We set the variable according to the type of the marks list,
5511       ;; and then adjust the marks to a subset of the active articles.
5512       (cond
5513        ;; Adjust "simple" lists - compressed yet unsorted
5514        ((eq mark-type 'list)
5515         ;; Simultaneously uncompress and clip to active range
5516         ;; See gnus-uncompress-range for a description of possible marks
5517         (let (l lh)
5518           (if (not (cadr marks))
5519               (set var nil)
5520             (setq articles (if (numberp (cddr marks))
5521                                (list (cdr marks))
5522                              (cdr marks))
5523                   lh (cons nil nil)
5524                   l lh)
5525
5526             (while (setq article (pop articles))
5527               (cond ((consp article)
5528                      (setq bgn (max (car article) min)
5529                            end (min (cdr article) max))
5530                      (while (<= bgn end)
5531                        (setq l (setcdr l (cons bgn nil))
5532                              bgn (1+ bgn))))
5533                     ((and (<= min article)
5534                           (>= max article))
5535                      (setq l (setcdr l (cons article nil))))))
5536             (set var (cdr lh)))))
5537        ;; Adjust assocs.
5538        ((eq mark-type 'tuple)
5539         (set var (setq articles (cdr marks)))
5540         (when (not (listp (cdr (symbol-value var))))
5541           (set var (list (symbol-value var))))
5542         (when (not (listp (cdr articles)))
5543           (setq articles (list articles)))
5544         (while articles
5545           (when (or (not (consp (setq article (pop articles))))
5546                     (< (car article) min)
5547                     (> (car article) max))
5548             (set var (delq article (symbol-value var))))))
5549        ;; Adjust ranges (sloppily).
5550        ((eq mark-type 'range)
5551         (cond
5552          ((eq mark 'seen)
5553           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5554           ;; It should be (seen (NUM1 . NUM2)).
5555           (when (numberp (cddr marks))
5556             (setcdr marks (list (cdr marks))))
5557           (setq articles (cdr marks))
5558           (while (and articles
5559                       (or (and (consp (car articles))
5560                                (> min (cdar articles)))
5561                           (and (numberp (car articles))
5562                                (> min (car articles)))))
5563             (pop articles))
5564           (set var articles))))))))
5565
5566 (defun gnus-update-missing-marks (missing)
5567   "Go through the list of MISSING articles and remove them from the mark lists."
5568   (when missing
5569     (let (var m)
5570       ;; Go through all types.
5571       (dolist (elem gnus-article-mark-lists)
5572         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5573           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5574           (when (symbol-value var)
5575             ;; This list has articles.  So we delete all missing
5576             ;; articles from it.
5577             (setq m missing)
5578             (while m
5579               (set var (delq (pop m) (symbol-value var))))))))))
5580
5581 (defun gnus-update-marks ()
5582   "Enter the various lists of marked articles into the newsgroup info list."
5583   (let ((types gnus-article-mark-lists)
5584         (info (gnus-get-info gnus-newsgroup-name))
5585         type list newmarked symbol delta-marks)
5586     (when info
5587       ;; Add all marks lists to the list of marks lists.
5588       (while (setq type (pop types))
5589         (setq list (symbol-value
5590                     (setq symbol
5591                           (intern (format "gnus-newsgroup-%s" (car type))))))
5592
5593         (when list
5594           ;; Get rid of the entries of the articles that have the
5595           ;; default score.
5596           (when (and (eq (cdr type) 'score)
5597                      gnus-save-score
5598                      list)
5599             (let* ((arts list)
5600                    (prev (cons nil list))
5601                    (all prev))
5602               (while arts
5603                 (if (or (not (consp (car arts)))
5604                         (= (cdar arts) gnus-summary-default-score))
5605                     (setcdr prev (cdr arts))
5606                   (setq prev arts))
5607                 (setq arts (cdr arts)))
5608               (setq list (cdr all)))))
5609
5610         (when (eq (cdr type) 'seen)
5611           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5612
5613         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5614           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5615
5616         (when (and (gnus-check-backend-function
5617                     'request-set-mark gnus-newsgroup-name)
5618                    (not (gnus-article-unpropagatable-p (cdr type))))
5619           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5620                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5621                  (add (gnus-remove-from-range
5622                        (gnus-copy-sequence list) old)))
5623             (when add
5624               (push (list add 'add (list (cdr type))) delta-marks))
5625             (when del
5626               (push (list del 'del (list (cdr type))) delta-marks))))
5627
5628         (when list
5629           (push (cons (cdr type) list) newmarked)))
5630
5631       (when delta-marks
5632         (unless (gnus-check-group gnus-newsgroup-name)
5633           (error "Can't open server for %s" gnus-newsgroup-name))
5634         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5635
5636       ;; Enter these new marks into the info of the group.
5637       (if (nthcdr 3 info)
5638           (setcar (nthcdr 3 info) newmarked)
5639         ;; Add the marks lists to the end of the info.
5640         (when newmarked
5641           (setcdr (nthcdr 2 info) (list newmarked))))
5642
5643       ;; Cut off the end of the info if there's nothing else there.
5644       (let ((i 5))
5645         (while (and (> i 2)
5646                     (not (nth i info)))
5647           (when (nthcdr (decf i) info)
5648             (setcdr (nthcdr i info) nil)))))))
5649
5650 (defun gnus-set-mode-line (where)
5651   "Set the mode line of the article or summary buffers.
5652 If WHERE is `summary', the summary mode line format will be used."
5653   ;; Is this mode line one we keep updated?
5654   (when (and (memq where gnus-updated-mode-lines)
5655              (symbol-value
5656               (intern (format "gnus-%s-mode-line-format-spec" where))))
5657     (let (mode-string)
5658       (save-excursion
5659         ;; We evaluate this in the summary buffer since these
5660         ;; variables are buffer-local to that buffer.
5661         (set-buffer gnus-summary-buffer)
5662         ;; We bind all these variables that are used in the `eval' form
5663         ;; below.
5664         (let* ((mformat (symbol-value
5665                          (intern
5666                           (format "gnus-%s-mode-line-format-spec" where))))
5667                (gnus-tmp-group-name (gnus-group-decoded-name
5668                                      gnus-newsgroup-name))
5669                (gnus-tmp-article-number (or gnus-current-article 0))
5670                (gnus-tmp-unread gnus-newsgroup-unreads)
5671                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5672                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5673                (gnus-tmp-unread-and-unselected
5674                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5675                             (zerop gnus-tmp-unselected))
5676                        "")
5677                       ((zerop gnus-tmp-unselected)
5678                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5679                       (t (format "{%d(+%d) more}"
5680                                  gnus-tmp-unread-and-unticked
5681                                  gnus-tmp-unselected))))
5682                (gnus-tmp-subject
5683                 (if (and gnus-current-headers
5684                          (vectorp gnus-current-headers))
5685                     (gnus-mode-string-quote
5686                      (mail-header-subject gnus-current-headers))
5687                   ""))
5688                bufname-length max-len
5689                gnus-tmp-header);; passed as argument to any user-format-funcs
5690           (setq mode-string (eval mformat))
5691           (setq bufname-length (if (string-match "%b" mode-string)
5692                                    (- (length
5693                                        (buffer-name
5694                                         (if (eq where 'summary)
5695                                             nil
5696                                           (get-buffer gnus-article-buffer))))
5697                                       2)
5698                                  0))
5699           (setq max-len (max 4 (if gnus-mode-non-string-length
5700                                    (- (window-width)
5701                                       gnus-mode-non-string-length
5702                                       bufname-length)
5703                                  (length mode-string))))
5704           ;; We might have to chop a bit of the string off...
5705           (when (> (length mode-string) max-len)
5706             (setq mode-string
5707                   (concat (gnus-truncate-string mode-string (- max-len 3))
5708                           "...")))
5709           ;; Pad the mode string a bit.
5710           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5711       ;; Update the mode line.
5712       (setq mode-line-buffer-identification
5713             (gnus-mode-line-buffer-identification (list mode-string)))
5714       (set-buffer-modified-p t))))
5715
5716 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5717   "Go through the HEADERS list and add all Xrefs to a hash table.
5718 The resulting hash table is returned, or nil if no Xrefs were found."
5719   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5720          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5721          (xref-hashtb (gnus-make-hashtable))
5722          start group entry number xrefs header)
5723     (while headers
5724       (setq header (pop headers))
5725       (when (and (setq xrefs (mail-header-xref header))
5726                  (not (memq (setq number (mail-header-number header))
5727                             unreads)))
5728         (setq start 0)
5729         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5730           (setq start (match-end 0))
5731           (setq group (if prefix
5732                           (concat prefix (substring xrefs (match-beginning 1)
5733                                                     (match-end 1)))
5734                         (substring xrefs (match-beginning 1) (match-end 1))))
5735           (setq number
5736                 (string-to-number (substring xrefs (match-beginning 2)
5737                                           (match-end 2))))
5738           (if (setq entry (gnus-gethash group xref-hashtb))
5739               (setcdr entry (cons number (cdr entry)))
5740             (gnus-sethash group (cons number nil) xref-hashtb)))))
5741     (and start xref-hashtb)))
5742
5743 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5744   "Look through all the headers and mark the Xrefs as read."
5745   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5746         name info xref-hashtb idlist method nth4)
5747     (save-excursion
5748       (set-buffer gnus-group-buffer)
5749       (when (setq xref-hashtb
5750                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5751         (mapatoms
5752          (lambda (group)
5753            (unless (string= from-newsgroup (setq name (symbol-name group)))
5754              (setq idlist (symbol-value group))
5755              ;; Dead groups are not updated.
5756              (and (prog1
5757                       (setq info (gnus-get-info name))
5758                     (when (stringp (setq nth4 (gnus-info-method info)))
5759                       (setq nth4 (gnus-server-to-method nth4))))
5760                   ;; Only do the xrefs if the group has the same
5761                   ;; select method as the group we have just read.
5762                   (or (gnus-methods-equal-p
5763                        nth4 (gnus-find-method-for-group from-newsgroup))
5764                       virtual
5765                       (equal nth4 (setq method (gnus-find-method-for-group
5766                                                 from-newsgroup)))
5767                       (and (equal (car nth4) (car method))
5768                            (equal (nth 1 nth4) (nth 1 method))))
5769                   gnus-use-cross-reference
5770                   (or (not (eq gnus-use-cross-reference t))
5771                       virtual
5772                       ;; Only do cross-references on subscribed
5773                       ;; groups, if that is what is wanted.
5774                       (<= (gnus-info-level info) gnus-level-subscribed))
5775                   (gnus-group-make-articles-read name idlist))))
5776          xref-hashtb)))))
5777
5778 (defun gnus-compute-read-articles (group articles)
5779   (let* ((entry (gnus-group-entry group))
5780          (info (nth 2 entry))
5781          (active (gnus-active group))
5782          ninfo)
5783     (when entry
5784       ;; First peel off all invalid article numbers.
5785       (when active
5786         (let ((ids articles)
5787               id first)
5788           (while (setq id (pop ids))
5789             (when (and first (> id (cdr active)))
5790               ;; We'll end up in this situation in one particular
5791               ;; obscure situation.  If you re-scan a group and get
5792               ;; a new article that is cross-posted to a different
5793               ;; group that has not been re-scanned, you might get
5794               ;; crossposted article that has a higher number than
5795               ;; Gnus believes possible.  So we re-activate this
5796               ;; group as well.  This might mean doing the
5797               ;; crossposting thingy will *increase* the number
5798               ;; of articles in some groups.  Tsk, tsk.
5799               (setq active (or (gnus-activate-group group) active)))
5800             (when (or (> id (cdr active))
5801                       (< id (car active)))
5802               (setq articles (delq id articles))))))
5803       ;; If the read list is nil, we init it.
5804       (if (and active
5805                (null (gnus-info-read info))
5806                (> (car active) 1))
5807           (setq ninfo (cons 1 (1- (car active))))
5808         (setq ninfo (gnus-info-read info)))
5809       ;; Then we add the read articles to the range.
5810       (gnus-add-to-range
5811        ninfo (setq articles (sort articles '<))))))
5812
5813 (defun gnus-group-make-articles-read (group articles)
5814   "Update the info of GROUP to say that ARTICLES are read."
5815   (let* ((num 0)
5816          (entry (gnus-group-entry group))
5817          (info (nth 2 entry))
5818          (active (gnus-active group))
5819          range)
5820     (when entry
5821       (setq range (gnus-compute-read-articles group articles))
5822       (with-current-buffer gnus-group-buffer
5823         (gnus-undo-register
5824           `(progn
5825              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5826              (gnus-info-set-read ',info ',(gnus-info-read info))
5827              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5828              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5829              (gnus-group-update-group ,group t))))
5830       ;; Add the read articles to the range.
5831       (gnus-info-set-read info range)
5832       (gnus-request-set-mark group (list (list range 'add '(read))))
5833       ;; Then we have to re-compute how many unread
5834       ;; articles there are in this group.
5835       (when active
5836         (cond
5837          ((not range)
5838           (setq num (- (1+ (cdr active)) (car active))))
5839          ((not (listp (cdr range)))
5840           (setq num (- (cdr active) (- (1+ (cdr range))
5841                                        (car range)))))
5842          (t
5843           (while range
5844             (if (numberp (car range))
5845                 (setq num (1+ num))
5846               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5847             (setq range (cdr range)))
5848           (setq num (- (cdr active) num))))
5849         ;; Update the number of unread articles.
5850         (setcar entry num)
5851         ;; Update the group buffer.
5852         (unless (gnus-ephemeral-group-p group)
5853           (gnus-group-update-group group t))))))
5854
5855 (defvar gnus-newsgroup-none-id 0)
5856
5857 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5858   (let ((cur nntp-server-buffer)
5859         (dependencies
5860          (or dependencies
5861              (with-current-buffer gnus-summary-buffer
5862                gnus-newsgroup-dependencies)))
5863         headers id end ref number
5864         (mail-parse-charset gnus-newsgroup-charset)
5865         (mail-parse-ignored-charsets
5866          (save-excursion (condition-case nil
5867                              (set-buffer gnus-summary-buffer)
5868                            (error))
5869                          gnus-newsgroup-ignored-charsets)))
5870     (save-excursion
5871       (set-buffer nntp-server-buffer)
5872       ;; Translate all TAB characters into SPACE characters.
5873       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5874       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5875       (ietf-drums-unfold-fws)
5876       (gnus-run-hooks 'gnus-parse-headers-hook)
5877       (let ((case-fold-search t)
5878             in-reply-to header p lines chars ctype)
5879         (goto-char (point-min))
5880         ;; Search to the beginning of the next header.  Error messages
5881         ;; do not begin with 2 or 3.
5882         (while (re-search-forward "^[23][0-9]+ " nil t)
5883           (setq id nil
5884                 ref nil)
5885           ;; This implementation of this function, with nine
5886           ;; search-forwards instead of the one re-search-forward and
5887           ;; a case (which basically was the old function) is actually
5888           ;; about twice as fast, even though it looks messier.  You
5889           ;; can't have everything, I guess.  Speed and elegance
5890           ;; doesn't always go hand in hand.
5891           (setq
5892            header
5893            (make-full-mail-header
5894             ;; Number.
5895             (prog1
5896                 (setq number (read cur))
5897               (end-of-line)
5898               (setq p (point))
5899               (narrow-to-region (point)
5900                                 (or (and (search-forward "\n.\n" nil t)
5901                                          (- (point) 2))
5902                                     (point))))
5903             ;; Subject.
5904             (progn
5905               (goto-char p)
5906               (if (search-forward "\nsubject:" nil t)
5907                   (nnheader-header-value)
5908                 "(none)"))
5909             ;; From.
5910             (progn
5911               (goto-char p)
5912               (if (search-forward "\nfrom:" nil t)
5913                   (nnheader-header-value)
5914                 "(nobody)"))
5915             ;; Date.
5916             (progn
5917               (goto-char p)
5918               (if (search-forward "\ndate:" nil t)
5919                   (nnheader-header-value) ""))
5920             ;; Message-ID.
5921             (progn
5922               (goto-char p)
5923               (setq id (if (re-search-forward
5924                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5925                            ;; We do it this way to make sure the Message-ID
5926                            ;; is (somewhat) syntactically valid.
5927                            (buffer-substring (match-beginning 1)
5928                                              (match-end 1))
5929                          ;; If there was no message-id, we just fake one
5930                          ;; to make subsequent routines simpler.
5931                          (nnheader-generate-fake-message-id number))))
5932             ;; References.
5933             (progn
5934               (goto-char p)
5935               (if (search-forward "\nreferences:" nil t)
5936                   (progn
5937                     (setq end (point))
5938                     (prog1
5939                         (nnheader-header-value)
5940                       (setq ref
5941                             (buffer-substring
5942                              (progn
5943                                ;; (end-of-line)
5944                                (search-backward ">" end t)
5945                                (1+ (point)))
5946                              (progn
5947                                (search-backward "<" end t)
5948                                (point))))))
5949                 ;; Get the references from the in-reply-to header if there
5950                 ;; were no references and the in-reply-to header looks
5951                 ;; promising.
5952                 (if (and (search-forward "\nin-reply-to:" nil t)
5953                          (setq in-reply-to (nnheader-header-value))
5954                          (string-match "<[^>]+>" in-reply-to))
5955                     (let (ref2)
5956                       (setq ref (substring in-reply-to (match-beginning 0)
5957                                            (match-end 0)))
5958                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5959                         (setq ref2 (substring in-reply-to (match-beginning 0)
5960                                               (match-end 0)))
5961                         (when (> (length ref2) (length ref))
5962                           (setq ref ref2)))
5963                       ref)
5964                   (setq ref nil))))
5965             ;; Chars.
5966             (progn
5967               (goto-char p)
5968               (if (search-forward "\nchars: " nil t)
5969                   (if (numberp (setq chars (ignore-errors (read cur))))
5970                       chars -1)
5971                 -1))
5972             ;; Lines.
5973             (progn
5974               (goto-char p)
5975               (if (search-forward "\nlines: " nil t)
5976                   (if (numberp (setq lines (ignore-errors (read cur))))
5977                       lines -1)
5978                 -1))
5979             ;; Xref.
5980             (progn
5981               (goto-char p)
5982               (and (search-forward "\nxref:" nil t)
5983                    (nnheader-header-value)))
5984             ;; Extra.
5985             (when gnus-extra-headers
5986               (let ((extra gnus-extra-headers)
5987                     out)
5988                 (while extra
5989                   (goto-char p)
5990                   (when (search-forward
5991                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5992                     (push (cons (car extra) (nnheader-header-value)) out))
5993                   (pop extra))
5994                 out))))
5995           (goto-char p)
5996           (if (and (search-forward "\ncontent-type: " nil t)
5997                    (setq ctype (nnheader-header-value)))
5998               (mime-entity-set-content-type-internal
5999                header (mime-parse-Content-Type ctype)))
6000           (when (equal id ref)
6001             (setq ref nil))
6002
6003           (when gnus-alter-header-function
6004             (funcall gnus-alter-header-function header)
6005             (setq id (mail-header-id header)
6006                   ref (gnus-parent-id (mail-header-references header))))
6007
6008           (when (setq header
6009                       (gnus-dependencies-add-header
6010                        header dependencies force-new))
6011             (push header headers))
6012           (goto-char (point-max))
6013           (widen))
6014         (nreverse headers)))))
6015
6016 ;; Goes through the xover lines and returns a list of vectors
6017 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6018                                                   force-new dependencies
6019                                                   group also-fetch-heads)
6020   "Parse the news overview data in the server buffer.
6021 Return a list of headers that match SEQUENCE (see
6022 `nntp-retrieve-headers')."
6023   ;; Get the Xref when the users reads the articles since most/some
6024   ;; NNTP servers do not include Xrefs when using XOVER.
6025   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6026   (let ((mail-parse-charset gnus-newsgroup-charset)
6027         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6028         (cur nntp-server-buffer)
6029         (dependencies (or dependencies gnus-newsgroup-dependencies))
6030         (allp (cond
6031                ((eq gnus-read-all-available-headers t)
6032                 t)
6033                ((stringp gnus-read-all-available-headers)
6034                 (string-match gnus-read-all-available-headers group))
6035                (t
6036                 nil)))
6037         number headers header)
6038     (save-excursion
6039       (set-buffer nntp-server-buffer)
6040       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6041       ;; Allow the user to mangle the headers before parsing them.
6042       (gnus-run-hooks 'gnus-parse-headers-hook)
6043       (goto-char (point-min))
6044       (gnus-parse-without-error
6045         (while (and (or sequence allp)
6046                     (not (eobp)))
6047           (setq number (read cur))
6048           (when (not allp)
6049             (while (and sequence
6050                         (< (car sequence) number))
6051               (setq sequence (cdr sequence))))
6052           (when (and (or allp
6053                          (and sequence
6054                               (eq number (car sequence))))
6055                      (progn
6056                        (setq sequence (cdr sequence))
6057                        (setq header (inline
6058                                       (gnus-nov-parse-line
6059                                        number dependencies force-new)))))
6060             (push header headers))
6061           (forward-line 1)))
6062       ;; A common bug in inn is that if you have posted an article and
6063       ;; then retrieves the active file, it will answer correctly --
6064       ;; the new article is included.  However, a NOV entry for the
6065       ;; article may not have been generated yet, so this may fail.
6066       ;; We work around this problem by retrieving the last few
6067       ;; headers using HEAD.
6068       (if (or (not also-fetch-heads)
6069               (not sequence))
6070           ;; We (probably) got all the headers.
6071           (nreverse headers)
6072         (let ((gnus-nov-is-evil t))
6073           (nconc
6074            (nreverse headers)
6075            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6076              (gnus-get-newsgroup-headers))))))))
6077
6078 (defun gnus-article-get-xrefs ()
6079   "Fill in the Xref value in `gnus-current-headers', if necessary.
6080 This is meant to be called in `gnus-article-internal-prepare-hook'."
6081   (let ((headers (with-current-buffer gnus-summary-buffer
6082                    gnus-current-headers)))
6083     (or (not gnus-use-cross-reference)
6084         (not headers)
6085         (and (mail-header-xref headers)
6086              (not (string= (mail-header-xref headers) "")))
6087         (let ((case-fold-search t)
6088               xref)
6089           (save-restriction
6090             (nnheader-narrow-to-headers)
6091             (goto-char (point-min))
6092             (when (or (and (not (eobp))
6093                            (eq (downcase (char-after)) ?x)
6094                            (looking-at "Xref:"))
6095                       (search-forward "\nXref:" nil t))
6096               (goto-char (1+ (match-end 0)))
6097               (setq xref (buffer-substring (point) (point-at-eol)))
6098               (mail-header-set-xref headers xref)))))))
6099
6100 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6101   "Find article ID and insert the summary line for that article.
6102 OLD-HEADER can either be a header or a line number to insert
6103 the subject line on."
6104   (let* ((line (and (numberp old-header) old-header))
6105          (old-header (and (vectorp old-header) old-header))
6106          (header (cond ((and old-header use-old-header)
6107                         old-header)
6108                        ((and (numberp id)
6109                              (gnus-number-to-header id))
6110                         (gnus-number-to-header id))
6111                        (t
6112                         (gnus-read-header id))))
6113          (number (and (numberp id) id))
6114          d)
6115     (when header
6116       ;; Rebuild the thread that this article is part of and go to the
6117       ;; article we have fetched.
6118       (when (and (not gnus-show-threads)
6119                  old-header)
6120         (when (and number
6121                    (setq d (gnus-data-find (mail-header-number old-header))))
6122           (goto-char (gnus-data-pos d))
6123           (gnus-data-remove
6124            number
6125            (- (point-at-bol)
6126               (prog1
6127                   (1+ (point-at-eol))
6128                 (gnus-delete-line))))))
6129       ;; Remove list identifiers from subject.
6130       (when gnus-list-identifiers
6131         (let ((gnus-newsgroup-headers (list header)))
6132           (gnus-summary-remove-list-identifiers)))
6133       (when old-header
6134         (mail-header-set-number header (mail-header-number old-header)))
6135       (setq gnus-newsgroup-sparse
6136             (delq (setq number (mail-header-number header))
6137                   gnus-newsgroup-sparse))
6138       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6139       (push number gnus-newsgroup-limit)
6140       (gnus-rebuild-thread (mail-header-id header) line)
6141       (gnus-summary-goto-subject number nil t))
6142     (when (and (numberp number)
6143                (> number 0))
6144       ;; We have to update the boundaries even if we can't fetch the
6145       ;; article if ID is a number -- so that the next `P' or `N'
6146       ;; command will fetch the previous (or next) article even
6147       ;; if the one we tried to fetch this time has been canceled.
6148       (when (> number gnus-newsgroup-end)
6149         (setq gnus-newsgroup-end number))
6150       (when (< number gnus-newsgroup-begin)
6151         (setq gnus-newsgroup-begin number))
6152       (setq gnus-newsgroup-unselected
6153             (delq number gnus-newsgroup-unselected)))
6154     ;; Report back a success?
6155     (and header (mail-header-number header))))
6156
6157 ;;; Process/prefix in the summary buffer
6158
6159 (defun gnus-summary-work-articles (n)
6160   "Return a list of articles to be worked upon.
6161 The prefix argument, the list of process marked articles, and the
6162 current article will be taken into consideration."
6163   (save-excursion
6164     (set-buffer gnus-summary-buffer)
6165     (cond
6166      (n
6167       ;; A numerical prefix has been given.
6168       (setq n (prefix-numeric-value n))
6169       (let ((backward (< n 0))
6170             (n (abs (prefix-numeric-value n)))
6171             articles article)
6172         (save-excursion
6173           (while
6174               (and (> n 0)
6175                    (push (setq article (gnus-summary-article-number))
6176                          articles)
6177                    (if backward
6178                        (gnus-summary-find-prev nil article)
6179                      (gnus-summary-find-next nil article)))
6180             (decf n)))
6181         (nreverse articles)))
6182      ((and (gnus-region-active-p) (mark))
6183       (message "region active")
6184       ;; Work on the region between point and mark.
6185       (let ((max (max (point) (mark)))
6186             articles article)
6187         (save-excursion
6188           (goto-char (min (point) (mark)))
6189           (while
6190               (and
6191                (push (setq article (gnus-summary-article-number)) articles)
6192                (gnus-summary-find-next nil article)
6193                (< (point) max)))
6194           (nreverse articles))))
6195      (gnus-newsgroup-processable
6196       ;; There are process-marked articles present.
6197       ;; Save current state.
6198       (gnus-summary-save-process-mark)
6199       ;; Return the list.
6200       (reverse gnus-newsgroup-processable))
6201      (t
6202       ;; Just return the current article.
6203       (list (gnus-summary-article-number))))))
6204
6205 (defmacro gnus-summary-iterate (arg &rest forms)
6206   "Iterate over the process/prefixed articles and do FORMS.
6207 ARG is the interactive prefix given to the command.  FORMS will be
6208 executed with point over the summary line of the articles."
6209   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6210     `(let ((,articles (gnus-summary-work-articles ,arg)))
6211        (while ,articles
6212          (gnus-summary-goto-subject (car ,articles))
6213          ,@forms
6214          (pop ,articles)))))
6215
6216 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6217 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6218
6219 (defun gnus-summary-save-process-mark ()
6220   "Push the current set of process marked articles on the stack."
6221   (interactive)
6222   (push (copy-sequence gnus-newsgroup-processable)
6223         gnus-newsgroup-process-stack))
6224
6225 (defun gnus-summary-kill-process-mark ()
6226   "Push the current set of process marked articles on the stack and unmark."
6227   (interactive)
6228   (gnus-summary-save-process-mark)
6229   (gnus-summary-unmark-all-processable))
6230
6231 (defun gnus-summary-yank-process-mark ()
6232   "Pop the last process mark state off the stack and restore it."
6233   (interactive)
6234   (unless gnus-newsgroup-process-stack
6235     (error "Empty mark stack"))
6236   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6237
6238 (defun gnus-summary-process-mark-set (set)
6239   "Make SET into the current process marked articles."
6240   (gnus-summary-unmark-all-processable)
6241   (mapc 'gnus-summary-set-process-mark set))
6242
6243 ;;; Searching and stuff
6244
6245 (defun gnus-summary-search-group (&optional backward use-level)
6246   "Search for next unread newsgroup.
6247 If optional argument BACKWARD is non-nil, search backward instead."
6248   (save-excursion
6249     (set-buffer gnus-group-buffer)
6250     (when (gnus-group-search-forward
6251            backward nil (if use-level (gnus-group-group-level) nil))
6252       (gnus-group-group-name))))
6253
6254 (defun gnus-summary-best-group (&optional exclude-group)
6255   "Find the name of the best unread group.
6256 If EXCLUDE-GROUP, do not go to this group."
6257   (with-current-buffer gnus-group-buffer
6258     (save-excursion
6259       (gnus-group-best-unread-group exclude-group))))
6260
6261 (defun gnus-summary-find-next (&optional unread article backward)
6262   (if backward
6263       (gnus-summary-find-prev unread article)
6264     (let* ((dummy (gnus-summary-article-intangible-p))
6265            (article (or article (gnus-summary-article-number)))
6266            (data (gnus-data-find-list article))
6267            result)
6268       (when (and (not dummy)
6269                  (or (not gnus-summary-check-current)
6270                      (not unread)
6271                      (not (gnus-data-unread-p (car data)))))
6272         (setq data (cdr data)))
6273       (when (setq result
6274                   (if unread
6275                       (progn
6276                         (while data
6277                           (unless (memq (gnus-data-number (car data))
6278                                         (cond
6279                                          ((eq gnus-auto-goto-ignores
6280                                               'always-undownloaded)
6281                                           gnus-newsgroup-undownloaded)
6282                                          (gnus-plugged
6283                                           nil)
6284                                          ((eq gnus-auto-goto-ignores
6285                                               'unfetched)
6286                                           gnus-newsgroup-unfetched)
6287                                          ((eq gnus-auto-goto-ignores
6288                                               'undownloaded)
6289                                           gnus-newsgroup-undownloaded)))
6290                             (when (gnus-data-unread-p (car data))
6291                               (setq result (car data)
6292                                     data nil)))
6293                           (setq data (cdr data)))
6294                         result)
6295                     (car data)))
6296         (goto-char (gnus-data-pos result))
6297         (gnus-data-number result)))))
6298
6299 (defun gnus-summary-find-prev (&optional unread article)
6300   (let* ((eobp (eobp))
6301          (article (or article (gnus-summary-article-number)))
6302          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6303          result)
6304     (when (and (not eobp)
6305                (or (not gnus-summary-check-current)
6306                    (not unread)
6307                    (not (gnus-data-unread-p (car data)))))
6308       (setq data (cdr data)))
6309     (when (setq result
6310                 (if unread
6311                     (progn
6312                       (while data
6313                         (unless (memq (gnus-data-number (car data))
6314                                       (cond
6315                                        ((eq gnus-auto-goto-ignores
6316                                             'always-undownloaded)
6317                                         gnus-newsgroup-undownloaded)
6318                                        (gnus-plugged
6319                                         nil)
6320                                        ((eq gnus-auto-goto-ignores
6321                                             'unfetched)
6322                                         gnus-newsgroup-unfetched)
6323                                        ((eq gnus-auto-goto-ignores
6324                                             'undownloaded)
6325                                         gnus-newsgroup-undownloaded)))
6326                           (when (gnus-data-unread-p (car data))
6327                             (setq result (car data)
6328                                   data nil)))
6329                         (setq data (cdr data)))
6330                       result)
6331                   (car data)))
6332       (goto-char (gnus-data-pos result))
6333       (gnus-data-number result))))
6334
6335 (defun gnus-summary-find-subject (subject &optional unread backward article)
6336   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6337          (article (or article (gnus-summary-article-number)))
6338          (articles (gnus-data-list backward))
6339          (arts (gnus-data-find-list article articles))
6340          result)
6341     (when (or (not gnus-summary-check-current)
6342               (not unread)
6343               (not (gnus-data-unread-p (car arts))))
6344       (setq arts (cdr arts)))
6345     (while arts
6346       (and (or (not unread)
6347                (gnus-data-unread-p (car arts)))
6348            (vectorp (gnus-data-header (car arts)))
6349            (gnus-subject-equal
6350             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6351            (setq result (car arts)
6352                  arts nil))
6353       (setq arts (cdr arts)))
6354     (and result
6355          (goto-char (gnus-data-pos result))
6356          (gnus-data-number result))))
6357
6358 (defun gnus-summary-search-forward (&optional unread subject backward)
6359   "Search forward for an article.
6360 If UNREAD, look for unread articles.  If SUBJECT, look for
6361 articles with that subject.  If BACKWARD, search backward instead."
6362   (cond (subject (gnus-summary-find-subject subject unread backward))
6363         (backward (gnus-summary-find-prev unread))
6364         (t (gnus-summary-find-next unread))))
6365
6366 (defun gnus-recenter (&optional n)
6367   "Center point in window and redisplay frame.
6368 Also do horizontal recentering."
6369   (interactive "P")
6370   (when (and gnus-auto-center-summary
6371              (not (eq gnus-auto-center-summary 'vertical)))
6372     (gnus-horizontal-recenter))
6373   (recenter n))
6374
6375 (defun gnus-summary-recenter ()
6376   "Center point in the summary window.
6377 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6378 displayed, no centering will be performed."
6379   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6380   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6381   (interactive)
6382   ;; The user has to want it.
6383   (when gnus-auto-center-summary
6384     (let* ((top (cond ((< (window-height) 4) 0)
6385                       ((< (window-height) 7) 1)
6386                       (t (if (numberp gnus-auto-center-summary)
6387                              gnus-auto-center-summary
6388                            (/ (1- (window-height)) 2)))))
6389            (height (1- (window-height)))
6390            (bottom (save-excursion (goto-char (point-max))
6391                                    (forward-line (- height))
6392                                    (point)))
6393            (window (get-buffer-window (current-buffer))))
6394       (when (get-buffer-window gnus-article-buffer)
6395         ;; Only do recentering when the article buffer is displayed,
6396         ;; Set the window start to either `bottom', which is the biggest
6397         ;; possible valid number, or the second line from the top,
6398         ;; whichever is the least.
6399         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6400           (if (> bottom top-pos)
6401               ;; Keep the second line from the top visible
6402               (set-window-start window top-pos t)
6403             ;; Try to keep the bottom line visible; if it's partially
6404             ;; obscured, either scroll one more line to make it fully
6405             ;; visible, or revert to using TOP-POS.
6406             (save-excursion
6407               (goto-char (point-max))
6408               (forward-line -1)
6409               (let ((last-line-start (point)))
6410                 (goto-char bottom)
6411                 (set-window-start window (point) t)
6412                 (when (not (pos-visible-in-window-p last-line-start window))
6413                   (forward-line 1)
6414                   (set-window-start window (min (point) top-pos) t)))))))
6415       ;; Do horizontal recentering while we're at it.
6416       (when (and (get-buffer-window (current-buffer) t)
6417                  (not (eq gnus-auto-center-summary 'vertical)))
6418         (let ((selected (selected-window)))
6419           (select-window (get-buffer-window (current-buffer) t))
6420           (gnus-summary-position-point)
6421           (gnus-horizontal-recenter)
6422           (select-window selected))))))
6423
6424 (defun gnus-summary-jump-to-group (newsgroup)
6425   "Move point to NEWSGROUP in group mode buffer."
6426   ;; Keep update point of group mode buffer if visible.
6427   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6428       (save-window-excursion
6429         ;; Take care of tree window mode.
6430         (when (get-buffer-window gnus-group-buffer)
6431           (pop-to-buffer gnus-group-buffer))
6432         (gnus-group-jump-to-group newsgroup))
6433     (save-excursion
6434       ;; Take care of tree window mode.
6435       (if (get-buffer-window gnus-group-buffer)
6436           (pop-to-buffer gnus-group-buffer)
6437         (set-buffer gnus-group-buffer))
6438       (gnus-group-jump-to-group newsgroup))))
6439
6440 ;; This function returns a list of article numbers based on the
6441 ;; difference between the ranges of read articles in this group and
6442 ;; the range of active articles.
6443 (defun gnus-list-of-unread-articles (group)
6444   (let* ((read (gnus-info-read (gnus-get-info group)))
6445          (active (or (gnus-active group) (gnus-activate-group group)))
6446          (last (or (cdr active)
6447                    (error "Group %s couldn't be activated " group)))
6448          first nlast unread)
6449     ;; If none are read, then all are unread.
6450     (if (not read)
6451         (setq first (car active))
6452       ;; If the range of read articles is a single range, then the
6453       ;; first unread article is the article after the last read
6454       ;; article.  Sounds logical, doesn't it?
6455       (if (and (not (listp (cdr read)))
6456                (or (< (car read) (car active))
6457                    (progn (setq read (list read))
6458                           nil)))
6459           (setq first (max (car active) (1+ (cdr read))))
6460         ;; `read' is a list of ranges.
6461         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6462                                   (caar read)))
6463                   1)
6464           (setq first (car active)))
6465         (while read
6466           (when first
6467             (while (< first nlast)
6468               (setq unread (cons first unread)
6469                     first (1+ first))))
6470           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6471           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6472           (setq read (cdr read)))))
6473     ;; And add the last unread articles.
6474     (while (<= first last)
6475       (setq unread (cons first unread)
6476             first (1+ first)))
6477     ;; Return the list of unread articles.
6478     (delq 0 (nreverse unread))))
6479
6480 (defun gnus-list-of-read-articles (group)
6481   "Return a list of unread, unticked and non-dormant articles."
6482   (let* ((info (gnus-get-info group))
6483          (marked (gnus-info-marks info))
6484          (active (gnus-active group)))
6485     (and info active
6486          (gnus-list-range-difference
6487           (gnus-list-range-difference
6488            (gnus-sorted-complement
6489             (gnus-uncompress-range active)
6490             (gnus-list-of-unread-articles group))
6491            (cdr (assq 'dormant marked)))
6492           (cdr (assq 'tick marked))))))
6493
6494 ;; This function returns a sequence of article numbers based on the
6495 ;; difference between the ranges of read articles in this group and
6496 ;; the range of active articles.
6497 (defun gnus-sequence-of-unread-articles (group)
6498   (let* ((read (gnus-info-read (gnus-get-info group)))
6499          (active (or (gnus-active group) (gnus-activate-group group)))
6500          (last (cdr active))
6501          first nlast unread)
6502     ;; If none are read, then all are unread.
6503     (if (not read)
6504         (setq first (car active))
6505       ;; If the range of read articles is a single range, then the
6506       ;; first unread article is the article after the last read
6507       ;; article.  Sounds logical, doesn't it?
6508       (if (and (not (listp (cdr read)))
6509                (or (< (car read) (car active))
6510                    (progn (setq read (list read))
6511                           nil)))
6512           (setq first (max (car active) (1+ (cdr read))))
6513         ;; `read' is a list of ranges.
6514         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6515                                   (caar read)))
6516                   1)
6517           (setq first (car active)))
6518         (while read
6519           (when first
6520             (push (cons first nlast) unread))
6521           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6522           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6523           (setq read (cdr read)))))
6524     ;; And add the last unread articles.
6525     (cond ((< first last)
6526            (push (cons first last) unread))
6527           ((= first last)
6528            (push first unread)))
6529     ;; Return the sequence of unread articles.
6530     (delq 0 (nreverse unread))))
6531
6532 ;; Various summary commands
6533
6534 (defun gnus-summary-select-article-buffer ()
6535   "Reconfigure windows to show article buffer."
6536   (interactive)
6537   (if (not (gnus-buffer-live-p gnus-article-buffer))
6538       (error "There is no article buffer for this summary buffer")
6539     (gnus-configure-windows 'article)
6540     (select-window (get-buffer-window gnus-article-buffer))))
6541
6542 (defun gnus-summary-universal-argument (arg)
6543   "Perform any operation on all articles that are process/prefixed."
6544   (interactive "P")
6545   (let ((articles (gnus-summary-work-articles arg))
6546         func article)
6547     (if (eq
6548          (setq
6549           func
6550           (key-binding
6551            (read-key-sequence
6552             (substitute-command-keys
6553              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6554          'undefined)
6555         (gnus-error 1 "Undefined key")
6556       (save-excursion
6557         (while articles
6558           (gnus-summary-goto-subject (setq article (pop articles)))
6559           (let (gnus-newsgroup-processable)
6560             (command-execute func))
6561           (gnus-summary-remove-process-mark article)))))
6562   (gnus-summary-position-point))
6563
6564 (defun gnus-summary-toggle-truncation (&optional arg)
6565   "Toggle truncation of summary lines.
6566 With ARG, turn line truncation on if ARG is positive."
6567   (interactive "P")
6568   (setq truncate-lines
6569         (if (null arg) (not truncate-lines)
6570           (> (prefix-numeric-value arg) 0)))
6571   (redraw-display))
6572
6573 (defun gnus-summary-find-for-reselect ()
6574   "Return the number of an article to stay on across a reselect.
6575 The current article is considered, then following articles, then previous
6576 articles.  An article is sought which is not cancelled and isn't a temporary
6577 insertion from another group.  If there's no such then return a dummy 0."
6578   (let (found)
6579     (dolist (rev '(nil t))
6580       (unless found      ; don't demand the reverse list if we don't need it
6581         (let ((data (gnus-data-find-list
6582                      (gnus-summary-article-number) (gnus-data-list rev))))
6583           (while (and data (not found))
6584             (if (and (< 0 (gnus-data-number (car data)))
6585                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6586                 (setq found (gnus-data-number (car data))))
6587             (setq data (cdr data))))))
6588     (or found 0)))
6589
6590 (defun gnus-summary-reselect-current-group (&optional all rescan)
6591   "Exit and then reselect the current newsgroup.
6592 The prefix argument ALL means to select all articles."
6593   (interactive "P")
6594   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6595     (error "Ephemeral groups can't be reselected"))
6596   (let ((current-subject (gnus-summary-find-for-reselect))
6597         (group gnus-newsgroup-name))
6598     (setq gnus-newsgroup-begin nil)
6599     (gnus-summary-exit nil 'leave-hidden)
6600     ;; We have to adjust the point of group mode buffer because
6601     ;; point was moved to the next unread newsgroup by exiting.
6602     (gnus-summary-jump-to-group group)
6603     (when rescan
6604       (save-excursion
6605         (save-window-excursion
6606           ;; Don't show group contents.
6607           (set-window-start (selected-window) (point-max))
6608           (gnus-group-get-new-news-this-group 1))))
6609     (gnus-group-read-group all t)
6610     (gnus-summary-goto-subject current-subject nil t)))
6611
6612 (defun gnus-summary-rescan-group (&optional all)
6613   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6614   (interactive "P")
6615   (gnus-summary-reselect-current-group all t))
6616
6617 (defun gnus-summary-update-info (&optional non-destructive)
6618   (save-excursion
6619     (let ((group gnus-newsgroup-name))
6620       (when group
6621         (when gnus-newsgroup-kill-headers
6622           (setq gnus-newsgroup-killed
6623                 (gnus-compress-sequence
6624                  (gnus-sorted-union
6625                   (gnus-list-range-intersection
6626                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6627                   gnus-newsgroup-unreads)
6628                  t)))
6629         (unless (listp (cdr gnus-newsgroup-killed))
6630           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6631         (let ((headers gnus-newsgroup-headers))
6632           ;; Set the new ranges of read articles.
6633           (with-current-buffer gnus-group-buffer
6634             (gnus-undo-force-boundary))
6635           (gnus-update-read-articles
6636            group (gnus-sorted-union
6637                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6638           ;; Set the current article marks.
6639           (let ((gnus-newsgroup-scored
6640                  (if (and (not gnus-save-score)
6641                           (not non-destructive))
6642                      nil
6643                    gnus-newsgroup-scored)))
6644             (save-excursion
6645               (gnus-update-marks)))
6646           ;; Do the cross-ref thing.
6647           (when gnus-use-cross-reference
6648             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6649           ;; Do not switch windows but change the buffer to work.
6650           (set-buffer gnus-group-buffer)
6651           (unless (gnus-ephemeral-group-p group)
6652             (gnus-group-update-group group)))))))
6653
6654 (defun gnus-summary-save-newsrc (&optional force)
6655   "Save the current number of read/marked articles in the dribble buffer.
6656 The dribble buffer will then be saved.
6657 If FORCE (the prefix), also save the .newsrc file(s)."
6658   (interactive "P")
6659   (gnus-summary-update-info t)
6660   (if force
6661       (gnus-save-newsrc-file)
6662     (gnus-dribble-save)))
6663
6664 (defun gnus-summary-exit (&optional temporary leave-hidden)
6665   "Exit reading current newsgroup, and then return to group selection mode.
6666 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6667   (interactive)
6668   (gnus-set-global-variables)
6669   (gnus-kill-save-kill-buffer)
6670   (gnus-async-halt-prefetch)
6671   (let* ((group gnus-newsgroup-name)
6672          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6673          (gnus-group-is-exiting-p t)
6674          (mode major-mode)
6675          (group-point nil)
6676          (buf (current-buffer)))
6677     (unless quit-config
6678       ;; Do adaptive scoring, and possibly save score files.
6679       (when gnus-newsgroup-adaptive
6680         (gnus-score-adaptive))
6681       (when gnus-use-scoring
6682         (gnus-score-save)))
6683     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6684     ;; If we have several article buffers, we kill them at exit.
6685     (unless gnus-single-article-buffer
6686       (gnus-kill-buffer gnus-original-article-buffer)
6687       (setq gnus-article-current nil))
6688     (when gnus-use-cache
6689       (gnus-cache-possibly-remove-articles)
6690       (gnus-cache-save-buffers))
6691     (gnus-async-prefetch-remove-group group)
6692     (when gnus-suppress-duplicates
6693       (gnus-dup-enter-articles))
6694     (when gnus-use-trees
6695       (gnus-tree-close group))
6696     (when gnus-use-cache
6697       (gnus-cache-write-active))
6698     ;; Remove entries for this group.
6699     (nnmail-purge-split-history (gnus-group-real-name group))
6700     ;; Make all changes in this group permanent.
6701     (unless quit-config
6702       (gnus-run-hooks 'gnus-exit-group-hook)
6703       (gnus-summary-update-info))
6704     (gnus-close-group group)
6705     ;; Make sure where we were, and go to next newsgroup.
6706     (set-buffer gnus-group-buffer)
6707     (unless quit-config
6708       (gnus-group-jump-to-group group))
6709     (gnus-run-hooks 'gnus-summary-exit-hook)
6710     (unless (or quit-config
6711                 ;; If this group has disappeared from the summary
6712                 ;; buffer, don't skip forwards.
6713                 (not (string= group (gnus-group-group-name))))
6714       (gnus-group-next-unread-group 1))
6715     (setq group-point (point))
6716     (if temporary
6717         nil                             ;Nothing to do.
6718       ;; If we have several article buffers, we kill them at exit.
6719       (unless gnus-single-article-buffer
6720         (gnus-kill-buffer gnus-article-buffer)
6721         (gnus-kill-buffer gnus-original-article-buffer)
6722         (setq gnus-article-current nil))
6723       (set-buffer buf)
6724       (if (not gnus-kill-summary-on-exit)
6725           (progn
6726             (gnus-deaden-summary)
6727             (setq mode nil))
6728         ;; We set all buffer-local variables to nil.  It is unclear why
6729         ;; this is needed, but if we don't, buffer-local variables are
6730         ;; not garbage-collected, it seems.  This would the lead to en
6731         ;; ever-growing Emacs.
6732         (gnus-summary-clear-local-variables)
6733         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6734           (gnus-summary-clear-local-variables))
6735         (when (get-buffer gnus-article-buffer)
6736           (bury-buffer gnus-article-buffer))
6737         ;; Return to group mode buffer.
6738         (when (eq mode 'gnus-summary-mode)
6739           (gnus-kill-buffer buf)))
6740       (setq gnus-current-select-method gnus-select-method)
6741       (set-buffer gnus-group-buffer)
6742       (if quit-config
6743           (gnus-handle-ephemeral-exit quit-config)
6744         (goto-char group-point)
6745         ;; If gnus-group-buffer is already displayed, make sure we also move
6746         ;; the cursor in the window that displays it.
6747         (let ((win (get-buffer-window (current-buffer) 0)))
6748           (if win (set-window-point win (point))))
6749         (unless leave-hidden
6750           (gnus-configure-windows 'group 'force))
6751         (unless (pos-visible-in-window-p)
6752           (forward-line (/ (static-if (featurep 'xemacs)
6753                                (window-displayed-height)
6754                              (1- (window-height)))
6755                            -2))
6756           (set-window-start (selected-window) (point))
6757           (goto-char group-point)))
6758       ;; Clear the current group name.
6759       (unless quit-config
6760         (setq gnus-newsgroup-name nil)))))
6761
6762 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6763 (defun gnus-summary-exit-no-update (&optional no-questions)
6764   "Quit reading current newsgroup without updating read article info."
6765   (interactive)
6766   (let* ((group gnus-newsgroup-name)
6767          (gnus-group-is-exiting-p t)
6768          (gnus-group-is-exiting-without-update-p t)
6769          (quit-config (gnus-group-quit-config group)))
6770     (when (or no-questions
6771               gnus-expert-user
6772               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6773       (gnus-async-halt-prefetch)
6774       (run-hooks 'gnus-summary-prepare-exit-hook)
6775       ;; If we have several article buffers, we kill them at exit.
6776       (unless gnus-single-article-buffer
6777         (gnus-kill-buffer gnus-article-buffer)
6778         (gnus-kill-buffer gnus-original-article-buffer)
6779         (setq gnus-article-current nil))
6780       (if (not gnus-kill-summary-on-exit)
6781           (gnus-deaden-summary)
6782         (gnus-close-group group)
6783         (gnus-summary-clear-local-variables)
6784         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6785           (gnus-summary-clear-local-variables))
6786         (gnus-kill-buffer gnus-summary-buffer))
6787       (unless gnus-single-article-buffer
6788         (setq gnus-article-current nil))
6789       (when gnus-use-trees
6790         (gnus-tree-close group))
6791       (gnus-async-prefetch-remove-group group)
6792       (when (get-buffer gnus-article-buffer)
6793         (bury-buffer gnus-article-buffer))
6794       ;; Return to the group buffer.
6795       (gnus-configure-windows 'group 'force)
6796       ;; Clear the current group name.
6797       (setq gnus-newsgroup-name nil)
6798       (unless (gnus-ephemeral-group-p group)
6799         (gnus-group-update-group group))
6800       (when (equal (gnus-group-group-name) group)
6801         (gnus-group-next-unread-group 1))
6802       (when quit-config
6803         (gnus-handle-ephemeral-exit quit-config)))))
6804
6805 (defun gnus-handle-ephemeral-exit (quit-config)
6806   "Handle movement when leaving an ephemeral group.
6807 The state which existed when entering the ephemeral is reset."
6808   (if (not (buffer-name (car quit-config)))
6809       (gnus-configure-windows 'group 'force)
6810     (set-buffer (car quit-config))
6811     (cond ((eq major-mode 'gnus-summary-mode)
6812            (gnus-set-global-variables))
6813           ((eq major-mode 'gnus-article-mode)
6814            (save-excursion
6815              ;; The `gnus-summary-buffer' variable may point
6816              ;; to the old summary buffer when using a single
6817              ;; article buffer.
6818              (unless (gnus-buffer-live-p gnus-summary-buffer)
6819                (set-buffer gnus-group-buffer))
6820              (set-buffer gnus-summary-buffer)
6821              (gnus-set-global-variables))))
6822     (if (or (eq (cdr quit-config) 'article)
6823             (eq (cdr quit-config) 'pick))
6824         (progn
6825           ;; The current article may be from the ephemeral group
6826           ;; thus it is best that we reload this article
6827           ;;
6828           ;; If we're exiting from a large digest, this can be
6829           ;; extremely slow.  So, it's better not to reload it. -- jh.
6830           ;;(gnus-summary-show-article)
6831           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6832               (gnus-configure-windows 'pick 'force)
6833             (gnus-configure-windows (cdr quit-config) 'force)))
6834       (gnus-configure-windows (cdr quit-config) 'force))
6835     (when (eq major-mode 'gnus-summary-mode)
6836       (gnus-summary-next-subject 1 nil t)
6837       (gnus-summary-recenter)
6838       (gnus-summary-position-point))))
6839
6840 (defun gnus-summary-preview-mime-message ()
6841   "MIME decode and play this message."
6842   (interactive)
6843   (let ((gnus-break-pages nil)
6844         (gnus-show-mime t))
6845     (gnus-summary-select-article gnus-show-all-headers t))
6846   (let ((w (get-buffer-window gnus-article-buffer)))
6847     (when w
6848       (select-window (get-buffer-window gnus-article-buffer)))))
6849
6850 ;;; Dead summaries.
6851
6852 (defvar gnus-dead-summary-mode-map nil)
6853
6854 (unless gnus-dead-summary-mode-map
6855   (setq gnus-dead-summary-mode-map (make-keymap))
6856   (suppress-keymap gnus-dead-summary-mode-map)
6857   (substitute-key-definition
6858    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6859   (dolist (key '("\C-d" "\r" "\177" [delete]))
6860     (define-key gnus-dead-summary-mode-map
6861       key 'gnus-summary-wake-up-the-dead))
6862   (dolist (key '("q" "Q"))
6863     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6864
6865 (defvar gnus-dead-summary-mode nil
6866   "Minor mode for Gnus summary buffers.")
6867
6868 (defun gnus-dead-summary-mode (&optional arg)
6869   "Minor mode for Gnus summary buffers."
6870   (interactive "P")
6871   (when (eq major-mode 'gnus-summary-mode)
6872     (make-local-variable 'gnus-dead-summary-mode)
6873     (setq gnus-dead-summary-mode
6874           (if (null arg) (not gnus-dead-summary-mode)
6875             (> (prefix-numeric-value arg) 0)))
6876     (when gnus-dead-summary-mode
6877       (add-minor-mode
6878        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6879
6880 (defun gnus-deaden-summary ()
6881   "Make the current summary buffer into a dead summary buffer."
6882   ;; Kill any previous dead summary buffer.
6883   (when (and gnus-dead-summary
6884              (buffer-name gnus-dead-summary))
6885     (with-current-buffer gnus-dead-summary
6886       (when gnus-dead-summary-mode
6887         (kill-buffer (current-buffer)))))
6888   ;; Make this the current dead summary.
6889   (setq gnus-dead-summary (current-buffer))
6890   (gnus-dead-summary-mode 1)
6891   (let ((name (buffer-name)))
6892     (when (string-match "Summary" name)
6893       (rename-buffer
6894        (concat (substring name 0 (match-beginning 0)) "Dead "
6895                (substring name (match-beginning 0)))
6896        t)
6897       (bury-buffer))))
6898
6899 (defun gnus-kill-or-deaden-summary (buffer)
6900   "Kill or deaden the summary BUFFER."
6901   (save-excursion
6902     (when (and (buffer-name buffer)
6903                (not gnus-single-article-buffer))
6904       (with-current-buffer buffer
6905         (gnus-kill-buffer gnus-article-buffer)
6906         (gnus-kill-buffer gnus-original-article-buffer)))
6907     (cond
6908      ;; Kill the buffer.
6909      (gnus-kill-summary-on-exit
6910       (when (and gnus-use-trees
6911                  (gnus-buffer-exists-p buffer))
6912         (save-excursion
6913           (set-buffer buffer)
6914           (gnus-tree-close gnus-newsgroup-name)))
6915       (gnus-kill-buffer buffer))
6916      ;; Deaden the buffer.
6917      ((gnus-buffer-exists-p buffer)
6918       (save-excursion
6919         (set-buffer buffer)
6920         (gnus-deaden-summary))))))
6921
6922 (defun gnus-summary-wake-up-the-dead (&rest args)
6923   "Wake up the dead summary buffer."
6924   (interactive)
6925   (gnus-dead-summary-mode -1)
6926   (let ((name (buffer-name)))
6927     (when (string-match "Dead " name)
6928       (rename-buffer
6929        (concat (substring name 0 (match-beginning 0))
6930                (substring name (match-end 0)))
6931        t)))
6932   (gnus-message 3 "This dead summary is now alive again"))
6933
6934 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6935 (defun gnus-summary-fetch-faq (&optional faq-dir)
6936   "Fetch the FAQ for the current group.
6937 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6938 in."
6939   (interactive
6940    (list
6941     (when current-prefix-arg
6942       (completing-read
6943        "FAQ dir: " (and (listp gnus-group-faq-directory)
6944                         (mapcar 'list
6945                                 gnus-group-faq-directory))))))
6946   (let (gnus-faq-buffer)
6947     (when (setq gnus-faq-buffer
6948                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6949       (gnus-configure-windows 'summary-faq))))
6950
6951 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6952 (defun gnus-summary-describe-group (&optional force)
6953   "Describe the current newsgroup."
6954   (interactive "P")
6955   (gnus-group-describe-group force gnus-newsgroup-name))
6956
6957 (defun gnus-summary-describe-briefly ()
6958   "Describe summary mode commands briefly."
6959   (interactive)
6960   (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")))
6961
6962 ;; Walking around group mode buffer from summary mode.
6963
6964 (defun gnus-summary-next-group (&optional no-article target-group backward)
6965   "Exit current newsgroup and then select next unread newsgroup.
6966 If prefix argument NO-ARTICLE is non-nil, no article is selected
6967 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6968 previous group instead."
6969   (interactive "P")
6970   ;; Stop pre-fetching.
6971   (gnus-async-halt-prefetch)
6972   (let ((current-group gnus-newsgroup-name)
6973         (current-buffer (current-buffer))
6974         entered)
6975     ;; First we semi-exit this group to update Xrefs and all variables.
6976     ;; We can't do a real exit, because the window conf must remain
6977     ;; the same in case the user is prompted for info, and we don't
6978     ;; want the window conf to change before that...
6979     (gnus-summary-exit t)
6980     (while (not entered)
6981       ;; Then we find what group we are supposed to enter.
6982       (set-buffer gnus-group-buffer)
6983       (gnus-group-jump-to-group current-group)
6984       (setq target-group
6985             (or target-group
6986                 (if (eq gnus-keep-same-level 'best)
6987                     (gnus-summary-best-group gnus-newsgroup-name)
6988                   (gnus-summary-search-group backward gnus-keep-same-level))))
6989       (if (not target-group)
6990           ;; There are no further groups, so we return to the group
6991           ;; buffer.
6992           (progn
6993             (gnus-message 5 "Returning to the group buffer")
6994             (setq entered t)
6995             (when (gnus-buffer-live-p current-buffer)
6996               (set-buffer current-buffer)
6997               (gnus-summary-exit))
6998             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6999         ;; We try to enter the target group.
7000         (gnus-group-jump-to-group target-group)
7001         (let ((unreads (gnus-group-group-unread)))
7002           (if (and (or (eq t unreads)
7003                        (and unreads (not (zerop unreads))))
7004                    (gnus-summary-read-group
7005                     target-group nil no-article
7006                     (and (buffer-name current-buffer) current-buffer)
7007                     nil backward))
7008               (setq entered t)
7009             (setq current-group target-group
7010                   target-group nil)))))))
7011
7012 (defun gnus-summary-prev-group (&optional no-article)
7013   "Exit current newsgroup and then select previous unread newsgroup.
7014 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7015   (interactive "P")
7016   (gnus-summary-next-group no-article nil t))
7017
7018 ;; Walking around summary lines.
7019
7020 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7021   "Go to the first subject satisfying any non-nil constraint.
7022 If UNREAD is non-nil, the article should be unread.
7023 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7024 If UNSEEN is non-nil, the article should be unseen.
7025 Returns the article selected or nil if there are no matching articles."
7026   (interactive "P")
7027   (cond
7028    ;; Empty summary.
7029    ((null gnus-newsgroup-data)
7030     (gnus-message 3 "No articles in the group")
7031     nil)
7032    ;; Pick the first article.
7033    ((not (or unread undownloaded unseen))
7034     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7035     (gnus-data-number (car gnus-newsgroup-data)))
7036    ;; Find the first unread article.
7037    (t
7038     (let ((data gnus-newsgroup-data))
7039       (while (and data
7040                   (let ((num (gnus-data-number (car data))))
7041                     (or (memq num gnus-newsgroup-unfetched)
7042                         (not (or (and unread
7043                                       (memq num gnus-newsgroup-unreads))
7044                                  (and undownloaded
7045                                       (memq num gnus-newsgroup-undownloaded))
7046                                  (and unseen
7047                                       (memq num gnus-newsgroup-unseen)))))))
7048         (setq data (cdr data)))
7049       (prog1
7050           (if data
7051               (progn
7052                 (goto-char (gnus-data-pos (car data)))
7053                 (gnus-data-number (car data)))
7054             (gnus-message 3 "No more%s articles"
7055                           (let* ((r (when unread " unread"))
7056                                  (d (when undownloaded " undownloaded"))
7057                                  (s (when unseen " unseen"))
7058                                  (l (delq nil (list r d s))))
7059                             (cond ((= 3 (length l))
7060                                    (concat r "," d ", or" s))
7061                                   ((= 2 (length l))
7062                                    (concat (car l) ", or" (cadr l)))
7063                                   ((= 1 (length l))
7064                                    (car l))
7065                                   (t
7066                                    ""))))
7067             nil
7068             )
7069         (gnus-summary-position-point))))))
7070
7071 (defun gnus-summary-next-subject (n &optional unread dont-display)
7072   "Go to next N'th summary line.
7073 If N is negative, go to the previous N'th subject line.
7074 If UNREAD is non-nil, only unread articles are selected.
7075 The difference between N and the actual number of steps taken is
7076 returned."
7077   (interactive "p")
7078   (let ((backward (< n 0))
7079         (n (abs n)))
7080     (while (and (> n 0)
7081                 (if backward
7082                     (gnus-summary-find-prev unread)
7083                   (gnus-summary-find-next unread)))
7084       (unless (zerop (setq n (1- n)))
7085         (gnus-summary-show-thread)))
7086     (when (/= 0 n)
7087       (gnus-message 7 "No more%s articles"
7088                     (if unread " unread" "")))
7089     (unless dont-display
7090       (gnus-summary-recenter)
7091       (gnus-summary-position-point))
7092     n))
7093
7094 (defun gnus-summary-next-unread-subject (n)
7095   "Go to next N'th unread summary line."
7096   (interactive "p")
7097   (gnus-summary-next-subject n t))
7098
7099 (defun gnus-summary-prev-subject (n &optional unread)
7100   "Go to previous N'th summary line.
7101 If optional argument UNREAD is non-nil, only unread article is selected."
7102   (interactive "p")
7103   (gnus-summary-next-subject (- n) unread))
7104
7105 (defun gnus-summary-prev-unread-subject (n)
7106   "Go to previous N'th unread summary line."
7107   (interactive "p")
7108   (gnus-summary-next-subject (- n) t))
7109
7110 (defun gnus-summary-goto-subjects (articles)
7111   "Insert the subject header for ARTICLES in the current buffer."
7112   (save-excursion
7113     (dolist (article articles)
7114       (gnus-summary-goto-subject article t)))
7115   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7116   (gnus-summary-position-point))
7117
7118 (defun gnus-summary-goto-subject (article &optional force silent)
7119   "Go the subject line of ARTICLE.
7120 If FORCE, also allow jumping to articles not currently shown."
7121   (interactive "nArticle number: ")
7122   (unless (numberp article)
7123     (error "Article %s is not a number" article))
7124   (let ((b (point))
7125         (data (gnus-data-find article)))
7126     ;; We read in the article if we have to.
7127     (and (not data)
7128          force
7129          (gnus-summary-insert-subject
7130           article
7131           (if (or (numberp force) (vectorp force)) force)
7132           t)
7133          (setq data (gnus-data-find article)))
7134     (goto-char b)
7135     (if (not data)
7136         (progn
7137           (unless silent
7138             (gnus-message 3 "Can't find article %d" article))
7139           nil)
7140       (let ((pt (gnus-data-pos data)))
7141         (goto-char pt)
7142         (gnus-summary-set-article-display-arrow pt))
7143       (gnus-summary-position-point)
7144       article)))
7145
7146 ;; Walking around summary lines with displaying articles.
7147
7148 (defun gnus-summary-expand-window (&optional arg)
7149   "Make the summary buffer take up the entire Emacs frame.
7150 Given a prefix, will force an `article' buffer configuration."
7151   (interactive "P")
7152   (if arg
7153       (gnus-configure-windows 'article 'force)
7154     (gnus-configure-windows 'summary 'force)))
7155
7156 (defun gnus-summary-display-article (article &optional all-header)
7157   "Display ARTICLE in article buffer."
7158   (when (gnus-buffer-live-p gnus-article-buffer)
7159     (with-current-buffer gnus-article-buffer
7160       (set-buffer-multibyte t)))
7161   (gnus-set-global-variables)
7162   (when (gnus-buffer-live-p gnus-article-buffer)
7163     (with-current-buffer gnus-article-buffer
7164       (setq gnus-article-charset gnus-newsgroup-charset)
7165       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7166       (set-buffer-multibyte t)))
7167   (if (null article)
7168       nil
7169     (prog1
7170         (if gnus-summary-display-article-function
7171             (funcall gnus-summary-display-article-function article all-header)
7172           (gnus-article-prepare article all-header))
7173       (with-current-buffer gnus-article-buffer
7174         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7175              nil))
7176       (gnus-run-hooks 'gnus-select-article-hook)
7177       (when (and gnus-current-article
7178                  (not (zerop gnus-current-article)))
7179         (gnus-summary-goto-subject gnus-current-article))
7180       (gnus-summary-recenter)
7181       (when (and gnus-use-trees gnus-show-threads)
7182         (gnus-possibly-generate-tree article)
7183         (gnus-highlight-selected-tree article))
7184       ;; Successfully display article.
7185       (gnus-article-set-window-start
7186        (cdr (assq article gnus-newsgroup-bookmarks))))))
7187
7188 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7189   "Select the current article.
7190 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7191 non-nil, the article will be re-fetched even if it already present in
7192 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7193 be displayed."
7194   ;; Make sure we are in the summary buffer to work around bbdb bug.
7195   (unless (eq major-mode 'gnus-summary-mode)
7196     (set-buffer gnus-summary-buffer))
7197   (let ((article (or article (gnus-summary-article-number)))
7198         (all-headers (not (not all-headers))) ;Must be T or NIL.
7199         gnus-summary-display-article-function)
7200     (and (not pseudo)
7201          (gnus-summary-article-pseudo-p article)
7202          (error "This is a pseudo-article"))
7203     (save-excursion
7204       (set-buffer gnus-summary-buffer)
7205       (if (or (and gnus-single-article-buffer
7206                    (or (null gnus-current-article)
7207                        (null gnus-article-current)
7208                        (null (get-buffer gnus-article-buffer))
7209                        (not (eq article (cdr gnus-article-current)))
7210                        (not (equal (car gnus-article-current)
7211                                    gnus-newsgroup-name))))
7212               (and (not gnus-single-article-buffer)
7213                    (or (null gnus-current-article)
7214                        (not (eq gnus-current-article article))))
7215               force)
7216           ;; The requested article is different from the current article.
7217           (progn
7218             (gnus-summary-display-article article all-headers)
7219             (gnus-article-set-window-start
7220              (cdr (assq article gnus-newsgroup-bookmarks)))
7221             article)
7222         'old))))
7223
7224 (defun gnus-summary-force-verify-and-decrypt ()
7225   "Display buttons for signed/encrypted parts and verify/decrypt them."
7226   (interactive)
7227   (let ((mm-verify-option 'known)
7228         (mm-decrypt-option 'known)
7229         (gnus-article-emulate-mime t)
7230         (gnus-buttonized-mime-types (append (list "multipart/signed"
7231                                                   "multipart/encrypted")
7232                                             gnus-buttonized-mime-types)))
7233     (gnus-summary-select-article nil 'force)))
7234
7235 (defun gnus-summary-set-current-mark (&optional current-mark)
7236   "Obsolete function."
7237   nil)
7238
7239 (defun gnus-summary-next-article (&optional unread subject backward push)
7240   "Select the next article.
7241 If UNREAD, only unread articles are selected.
7242 If SUBJECT, only articles with SUBJECT are selected.
7243 If BACKWARD, the previous article is selected instead of the next."
7244   (interactive "P")
7245   (cond
7246    ;; Is there such an article?
7247    ((and (gnus-summary-search-forward unread subject backward)
7248          (or (gnus-summary-display-article (gnus-summary-article-number))
7249              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7250     (gnus-summary-position-point))
7251    ;; If not, we try the first unread, if that is wanted.
7252    ((and subject
7253          gnus-auto-select-same
7254          (gnus-summary-first-unread-article))
7255     (gnus-summary-position-point)
7256     (gnus-message 6 "Wrapped"))
7257    ;; Try to get next/previous article not displayed in this group.
7258    ((and gnus-auto-extend-newsgroup
7259          (not unread) (not subject))
7260     (gnus-summary-goto-article
7261      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7262      nil (count-lines (point-min) (point))))
7263    ;; Go to next/previous group.
7264    (t
7265     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7266       (gnus-summary-jump-to-group gnus-newsgroup-name))
7267     (let ((cmd last-command-char)
7268           (point
7269            (with-current-buffer gnus-group-buffer
7270              (point)))
7271           (group
7272            (if (eq gnus-keep-same-level 'best)
7273                (gnus-summary-best-group gnus-newsgroup-name)
7274              (gnus-summary-search-group backward gnus-keep-same-level))))
7275       ;; For some reason, the group window gets selected.  We change
7276       ;; it back.
7277       (select-window (get-buffer-window (current-buffer)))
7278       ;; Select next unread newsgroup automagically.
7279       (cond
7280        ((or (not gnus-auto-select-next)
7281             (not cmd))
7282         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7283        ((or (eq gnus-auto-select-next 'quietly)
7284             (and (eq gnus-auto-select-next 'slightly-quietly)
7285                  push)
7286             (and (eq gnus-auto-select-next 'almost-quietly)
7287                  (gnus-summary-last-article-p)))
7288         ;; Select quietly.
7289         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7290             (gnus-summary-exit)
7291           (gnus-message 7 "No more%s articles (%s)..."
7292                         (if unread " unread" "")
7293                         (if group (concat "selecting " group)
7294                           "exiting"))
7295           (gnus-summary-next-group nil group backward)))
7296        (t
7297         (when (gnus-key-press-event-p last-input-event)
7298           (gnus-summary-walk-group-buffer
7299            gnus-newsgroup-name cmd unread backward point))))))))
7300
7301 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7302   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7303                       (?\C-p (gnus-group-prev-unread-group 1))))
7304         (cursor-in-echo-area t)
7305         keve key group ended prompt)
7306     (save-excursion
7307       (set-buffer gnus-group-buffer)
7308       (goto-char start)
7309       (setq group
7310             (if (eq gnus-keep-same-level 'best)
7311                 (gnus-summary-best-group gnus-newsgroup-name)
7312               (gnus-summary-search-group backward gnus-keep-same-level))))
7313     (while (not ended)
7314       (setq prompt
7315             (format
7316              "No more%s articles%s " (if unread " unread" "")
7317              (if (and group
7318                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7319                  (format " (Type %s for %s [%s])"
7320                          (single-key-description cmd)
7321                          (gnus-group-decoded-name group)
7322                          (gnus-group-unread group))
7323                (format " (Type %s to exit %s)"
7324                        (single-key-description cmd)
7325                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7326       ;; Confirm auto selection.
7327       (setq key (car (setq keve (gnus-read-event-char prompt)))
7328             ended t)
7329       (cond
7330        ((assq key keystrokes)
7331         (let ((obuf (current-buffer)))
7332           (switch-to-buffer gnus-group-buffer)
7333           (when group
7334             (gnus-group-jump-to-group group))
7335           (eval (cadr (assq key keystrokes)))
7336           (setq group (gnus-group-group-name))
7337           (switch-to-buffer obuf))
7338         (setq ended nil))
7339        ((equal key cmd)
7340         (if (or (not group)
7341                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7342             (gnus-summary-exit)
7343           (gnus-summary-next-group nil group backward)))
7344        (t
7345         (push (cdr keve) unread-command-events))))))
7346
7347 (defun gnus-summary-next-unread-article ()
7348   "Select unread article after current one."
7349   (interactive)
7350   (gnus-summary-next-article
7351    (or (not (eq gnus-summary-goto-unread 'never))
7352        (gnus-summary-last-article-p (gnus-summary-article-number)))
7353    (and gnus-auto-select-same
7354         (gnus-summary-article-subject))))
7355
7356 (defun gnus-summary-prev-article (&optional unread subject)
7357   "Select the article after the current one.
7358 If UNREAD is non-nil, only unread articles are selected."
7359   (interactive "P")
7360   (gnus-summary-next-article unread subject t))
7361
7362 (defun gnus-summary-prev-unread-article ()
7363   "Select unread article before current one."
7364   (interactive)
7365   (gnus-summary-prev-article
7366    (or (not (eq gnus-summary-goto-unread 'never))
7367        (gnus-summary-first-article-p (gnus-summary-article-number)))
7368    (and gnus-auto-select-same
7369         (gnus-summary-article-subject))))
7370
7371 (defun gnus-summary-next-page (&optional lines circular stop)
7372   "Show next page of the selected article.
7373 If at the end of the current article, select the next article.
7374 LINES says how many lines should be scrolled up.
7375
7376 If CIRCULAR is non-nil, go to the start of the article instead of
7377 selecting the next article when reaching the end of the current
7378 article.
7379
7380 If STOP is non-nil, just stop when reaching the end of the message.
7381
7382 Also see the variable `gnus-article-skip-boring'."
7383   (interactive "P")
7384   (setq gnus-summary-buffer (current-buffer))
7385   (gnus-set-global-variables)
7386   (let ((article (gnus-summary-article-number))
7387         (article-window (get-buffer-window gnus-article-buffer t))
7388         endp)
7389     ;; If the buffer is empty, we have no article.
7390     (unless article
7391       (error "No article to select"))
7392     (gnus-configure-windows 'article)
7393     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7394         (if (and (eq gnus-summary-goto-unread 'never)
7395                  (not (gnus-summary-last-article-p article)))
7396             (gnus-summary-next-article)
7397           (gnus-summary-next-unread-article))
7398       (if (or (null gnus-current-article)
7399               (null gnus-article-current)
7400               (/= article (cdr gnus-article-current))
7401               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7402           ;; Selected subject is different from current article's.
7403           (gnus-summary-display-article article)
7404         (when article-window
7405           (gnus-eval-in-buffer-window gnus-article-buffer
7406             (setq endp (or (gnus-article-next-page lines)
7407                            (gnus-article-only-boring-p))))
7408           (when endp
7409             (cond (stop
7410                    (gnus-message 3 "End of message"))
7411                   (circular
7412                    (gnus-summary-beginning-of-article))
7413                   (lines
7414                    (gnus-message 3 "End of message"))
7415                   ((null lines)
7416                    (if (and (eq gnus-summary-goto-unread 'never)
7417                             (not (gnus-summary-last-article-p article)))
7418                        (gnus-summary-next-article)
7419                      (gnus-summary-next-unread-article))))))))
7420     (gnus-summary-recenter)
7421     (gnus-summary-position-point)))
7422
7423 (defun gnus-summary-prev-page (&optional lines move)
7424   "Show previous page of selected article.
7425 Argument LINES specifies lines to be scrolled down.
7426 If MOVE, move to the previous unread article if point is at
7427 the beginning of the buffer."
7428   (interactive "P")
7429   (let ((article (gnus-summary-article-number))
7430         (article-window (get-buffer-window gnus-article-buffer t))
7431         endp)
7432     (gnus-configure-windows 'article)
7433     (if (or (null gnus-current-article)
7434             (null gnus-article-current)
7435             (/= article (cdr gnus-article-current))
7436             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7437         ;; Selected subject is different from current article's.
7438         (gnus-summary-display-article article)
7439       (gnus-summary-recenter)
7440       (when article-window
7441         (gnus-eval-in-buffer-window gnus-article-buffer
7442           (setq endp (gnus-article-prev-page lines)))
7443         (when (and move endp)
7444           (cond (lines
7445                  (gnus-message 3 "Beginning of message"))
7446                 ((null lines)
7447                  (if (and (eq gnus-summary-goto-unread 'never)
7448                           (not (gnus-summary-first-article-p article)))
7449                      (gnus-summary-prev-article)
7450                    (gnus-summary-prev-unread-article))))))))
7451   (gnus-summary-position-point))
7452
7453 (defun gnus-summary-prev-page-or-article (&optional lines)
7454   "Show previous page of selected article.
7455 Argument LINES specifies lines to be scrolled down.
7456 If at the beginning of the article, go to the next article."
7457   (interactive "P")
7458   (gnus-summary-prev-page lines t))
7459
7460 (defun gnus-summary-scroll-up (lines)
7461   "Scroll up (or down) one line current article.
7462 Argument LINES specifies lines to be scrolled up (or down if negative)."
7463   (interactive "p")
7464   (gnus-configure-windows 'article)
7465   (gnus-summary-show-thread)
7466   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7467     (gnus-eval-in-buffer-window gnus-article-buffer
7468       (cond ((> lines 0)
7469              (when (gnus-article-next-page lines)
7470                (gnus-message 3 "End of message")))
7471             ((< lines 0)
7472              (gnus-article-prev-page (- lines))))))
7473   (gnus-summary-recenter)
7474   (gnus-summary-position-point))
7475
7476 (defun gnus-summary-scroll-down (lines)
7477   "Scroll down (or up) one line current article.
7478 Argument LINES specifies lines to be scrolled down (or up if negative)."
7479   (interactive "p")
7480   (gnus-summary-scroll-up (- lines)))
7481
7482 (defun gnus-summary-next-same-subject ()
7483   "Select next article which has the same subject as current one."
7484   (interactive)
7485   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7486
7487 (defun gnus-summary-prev-same-subject ()
7488   "Select previous article which has the same subject as current one."
7489   (interactive)
7490   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7491
7492 (defun gnus-summary-next-unread-same-subject ()
7493   "Select next unread article which has the same subject as current one."
7494   (interactive)
7495   (gnus-summary-next-article t (gnus-summary-article-subject)))
7496
7497 (defun gnus-summary-prev-unread-same-subject ()
7498   "Select previous unread article which has the same subject as current one."
7499   (interactive)
7500   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7501
7502 (defun gnus-summary-first-unread-article ()
7503   "Select the first unread article.
7504 Return nil if there are no unread articles."
7505   (interactive)
7506   (prog1
7507       (when (gnus-summary-first-subject t)
7508         (gnus-summary-show-thread)
7509         (gnus-summary-first-subject t)
7510         (gnus-summary-display-article (gnus-summary-article-number)))
7511     (gnus-summary-position-point)))
7512
7513 (defun gnus-summary-first-unread-subject ()
7514   "Place the point on the subject line of the first unread article.
7515 Return nil if there are no unread articles."
7516   (interactive)
7517   (prog1
7518       (when (gnus-summary-first-subject t)
7519         (gnus-summary-show-thread)
7520         (gnus-summary-first-subject t))
7521     (gnus-summary-position-point)))
7522
7523 (defun gnus-summary-first-unseen-subject ()
7524   "Place the point on the subject line of the first unseen article.
7525 Return nil if there are no unseen articles."
7526   (interactive)
7527   (prog1
7528       (when (gnus-summary-first-subject nil nil t)
7529         (gnus-summary-show-thread)
7530         (gnus-summary-first-subject nil nil t))
7531     (gnus-summary-position-point)))
7532
7533 (defun gnus-summary-first-unseen-or-unread-subject ()
7534   "Place the point on the subject line of the first unseen article or,
7535 if all article have been seen, on the subject line of the first unread
7536 article."
7537   (interactive)
7538   (prog1
7539       (unless (when (gnus-summary-first-subject nil nil t)
7540                 (gnus-summary-show-thread)
7541                 (gnus-summary-first-subject nil nil t))
7542         (when (gnus-summary-first-subject t)
7543           (gnus-summary-show-thread)
7544           (gnus-summary-first-subject t)))
7545     (gnus-summary-position-point)))
7546
7547 (defun gnus-summary-first-article ()
7548   "Select the first article.
7549 Return nil if there are no articles."
7550   (interactive)
7551   (prog1
7552       (when (gnus-summary-first-subject)
7553         (gnus-summary-show-thread)
7554         (gnus-summary-first-subject)
7555         (gnus-summary-display-article (gnus-summary-article-number)))
7556     (gnus-summary-position-point)))
7557
7558 (defun gnus-summary-best-unread-article (&optional arg)
7559   "Select the unread article with the highest score.
7560 If given a prefix argument, select the next unread article that has a
7561 score higher than the default score."
7562   (interactive "P")
7563   (let ((article (if arg
7564                      (gnus-summary-better-unread-subject)
7565                    (gnus-summary-best-unread-subject))))
7566     (if article
7567         (gnus-summary-goto-article article)
7568       (error "No unread articles"))))
7569
7570 (defun gnus-summary-best-unread-subject ()
7571   "Select the unread subject with the highest score."
7572   (interactive)
7573   (let ((best -1000000)
7574         (data gnus-newsgroup-data)
7575         article score)
7576     (while data
7577       (and (gnus-data-unread-p (car data))
7578            (> (setq score
7579                     (gnus-summary-article-score (gnus-data-number (car data))))
7580               best)
7581            (setq best score
7582                  article (gnus-data-number (car data))))
7583       (setq data (cdr data)))
7584     (when article
7585       (gnus-summary-goto-subject article))
7586     (gnus-summary-position-point)
7587     article))
7588
7589 (defun gnus-summary-better-unread-subject ()
7590   "Select the first unread subject that has a score over the default score."
7591   (interactive)
7592   (let ((data gnus-newsgroup-data)
7593         article score)
7594     (while (and (setq article (gnus-data-number (car data)))
7595                 (or (gnus-data-read-p (car data))
7596                     (not (> (gnus-summary-article-score article)
7597                             gnus-summary-default-score))))
7598       (setq data (cdr data)))
7599     (when article
7600       (gnus-summary-goto-subject article))
7601     (gnus-summary-position-point)
7602     article))
7603
7604 (defun gnus-summary-last-subject ()
7605   "Go to the last displayed subject line in the group."
7606   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7607     (when article
7608       (gnus-summary-goto-subject article))))
7609
7610 (defun gnus-summary-goto-article (article &optional all-headers force)
7611   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7612 If ALL-HEADERS is non-nil, no header lines are hidden.
7613 If FORCE, go to the article even if it isn't displayed.  If FORCE
7614 is a number, it is the line the article is to be displayed on."
7615   (interactive
7616    (list
7617     (completing-read
7618      "Article number or Message-ID: "
7619      (mapcar (lambda (number) (list (int-to-string number)))
7620              gnus-newsgroup-limit))
7621     current-prefix-arg
7622     t))
7623   (prog1
7624       (if (and (stringp article)
7625                (string-match "@\\|%40" article))
7626           (gnus-summary-refer-article article)
7627         (when (stringp article)
7628           (setq article (string-to-number article)))
7629         (if (gnus-summary-goto-subject article force)
7630             (gnus-summary-display-article article all-headers)
7631           (gnus-message 4 "Couldn't go to article %s" article) nil))
7632     (gnus-summary-position-point)))
7633
7634 (defun gnus-summary-goto-last-article ()
7635   "Go to the previously read article."
7636   (interactive)
7637   (prog1
7638       (when gnus-last-article
7639         (gnus-summary-goto-article gnus-last-article nil t))
7640     (gnus-summary-position-point)))
7641
7642 (defun gnus-summary-pop-article (number)
7643   "Pop one article off the history and go to the previous.
7644 NUMBER articles will be popped off."
7645   (interactive "p")
7646   (let (to)
7647     (setq gnus-newsgroup-history
7648           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7649     (if to
7650         (gnus-summary-goto-article (car to) nil t)
7651       (error "Article history empty")))
7652   (gnus-summary-position-point))
7653
7654 ;; Summary commands and functions for limiting the summary buffer.
7655
7656 (defun gnus-summary-limit-to-articles (n)
7657   "Limit the summary buffer to the next N articles.
7658 If not given a prefix, use the process marked articles instead."
7659   (interactive "P")
7660   (prog1
7661       (let ((articles (gnus-summary-work-articles n)))
7662         (setq gnus-newsgroup-processable nil)
7663         (gnus-summary-limit articles))
7664     (gnus-summary-position-point)))
7665
7666 (defun gnus-summary-pop-limit (&optional total)
7667   "Restore the previous limit.
7668 If given a prefix, remove all limits."
7669   (interactive "P")
7670   (when total
7671     (setq gnus-newsgroup-limits
7672           (list (mapcar (lambda (h) (mail-header-number h))
7673                         gnus-newsgroup-headers))))
7674   (unless gnus-newsgroup-limits
7675     (error "No limit to pop"))
7676   (prog1
7677       (gnus-summary-limit nil 'pop)
7678     (gnus-summary-position-point)))
7679
7680 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7681   "Limit the summary buffer to articles that have subjects that match a regexp.
7682 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7683   (interactive
7684    (list (read-string (if current-prefix-arg
7685                           "Exclude subject (regexp): "
7686                         "Limit to subject (regexp): "))
7687          nil current-prefix-arg))
7688   (unless header
7689     (setq header "subject"))
7690   (when (not (equal "" subject))
7691     (prog1
7692         (let ((articles (gnus-summary-find-matching
7693                          (or header "subject") subject 'all nil nil
7694                          not-matching)))
7695           (unless articles
7696             (error "Found no matches for \"%s\"" subject))
7697           (gnus-summary-limit articles))
7698       (gnus-summary-position-point))))
7699
7700 (defun gnus-summary-limit-to-author (from &optional not-matching)
7701   "Limit the summary buffer to articles that have authors that match a regexp.
7702 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7703   (interactive
7704    (list (read-string (if current-prefix-arg
7705                           "Exclude author (regexp): "
7706                         "Limit to author (regexp): "))
7707          current-prefix-arg))
7708   (gnus-summary-limit-to-subject from "from" not-matching))
7709
7710 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7711   "Limit the summary buffer to articles with the given RECIPIENT.
7712
7713 If NOT-MATCHING, exclude RECIPIENT.
7714
7715 To and Cc headers are checked.  You need to include them in
7716 `nnmail-extra-headers'."
7717   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7718   (interactive
7719    (list (read-string (format "%s recipient (regexp): "
7720                               (if current-prefix-arg "Exclude" "Limit to")))
7721          current-prefix-arg))
7722   (when (not (equal "" recipient))
7723     (prog1 (let* ((to
7724                    (if (memq 'To nnmail-extra-headers)
7725                        (gnus-summary-find-matching
7726                         (cons 'extra 'To) recipient 'all nil nil
7727                         not-matching)
7728                      (gnus-message
7729                       1 "`To' isn't present in `nnmail-extra-headers'")
7730                      (sit-for 1)
7731                      nil))
7732                   (cc
7733                    (if (memq 'Cc nnmail-extra-headers)
7734                        (gnus-summary-find-matching
7735                         (cons 'extra 'Cc) recipient 'all nil nil
7736                         not-matching)
7737                      (gnus-message
7738                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7739                      (sit-for 1)
7740                      nil))
7741                   (articles
7742                    (if not-matching
7743                        ;; We need the numbers that are in both lists:
7744                        (mapcar (lambda (a)
7745                                  (and (memq a to) a))
7746                                cc)
7747                      (nconc to cc))))
7748              (unless articles
7749                (error "Found no matches for \"%s\"" recipient))
7750              (gnus-summary-limit articles))
7751       (gnus-summary-position-point))))
7752
7753 (defun gnus-summary-limit-to-age (age &optional younger-p)
7754   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7755 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7756 articles that are younger than AGE days."
7757   (interactive
7758    (let ((younger current-prefix-arg)
7759          (days-got nil)
7760          days)
7761      (while (not days-got)
7762        (setq days (if younger
7763                       (read-string "Limit to articles younger than (in days, older when negative): ")
7764                     (read-string
7765                      "Limit to articles older than (in days, younger when negative): ")))
7766        (when (> (length days) 0)
7767          (setq days (read days)))
7768        (if (numberp days)
7769            (progn
7770              (setq days-got t)
7771              (when (< days 0)
7772                (setq younger (not younger))
7773                (setq days (* days -1))))
7774          (message "Please enter a number.")
7775          (sleep-for 1)))
7776      (list days younger)))
7777   (prog1
7778       (let ((data gnus-newsgroup-data)
7779             (cutoff (days-to-time age))
7780             articles d date is-younger)
7781         (while (setq d (pop data))
7782           (when (and (vectorp (gnus-data-header d))
7783                      (setq date (mail-header-date (gnus-data-header d))))
7784             (setq is-younger (time-less-p
7785                               (time-since (condition-case ()
7786                                               (date-to-time date)
7787                                             (error '(0 0))))
7788                               cutoff))
7789             (when (if younger-p
7790                       is-younger
7791                     (not is-younger))
7792               (push (gnus-data-number d) articles))))
7793         (gnus-summary-limit (nreverse articles)))
7794     (gnus-summary-position-point)))
7795
7796 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7797   "Limit the summary buffer to articles that match an 'extra' header."
7798   (interactive
7799    (let ((header
7800           (intern
7801            (gnus-completing-read-with-default
7802             (symbol-name (car gnus-extra-headers))
7803             (if current-prefix-arg
7804                 "Exclude extra header:"
7805               "Limit extra header:")
7806             (mapcar (lambda (x)
7807                       (cons (symbol-name x) x))
7808                     gnus-extra-headers)
7809             nil
7810             t))))
7811      (list header
7812            (read-string (format "%s header %s (regexp): "
7813                                 (if current-prefix-arg "Exclude" "Limit to")
7814                                 header))
7815            current-prefix-arg)))
7816   (when (not (equal "" regexp))
7817     (prog1
7818         (let ((articles (gnus-summary-find-matching
7819                          (cons 'extra header) regexp 'all nil nil
7820                          not-matching)))
7821           (unless articles
7822             (error "Found no matches for \"%s\"" regexp))
7823           (gnus-summary-limit articles))
7824       (gnus-summary-position-point))))
7825
7826 (defun gnus-summary-limit-to-display-predicate ()
7827   "Limit the summary buffer to the predicated in the `display' group parameter."
7828   (interactive)
7829   (unless gnus-newsgroup-display
7830     (error "There is no `display' group parameter"))
7831   (let (articles)
7832     (dolist (number gnus-newsgroup-articles)
7833       (when (funcall gnus-newsgroup-display)
7834         (push number articles)))
7835     (gnus-summary-limit articles))
7836   (gnus-summary-position-point))
7837
7838 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7839 (make-obsolete
7840  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7841
7842 (defun gnus-summary-limit-to-unread (&optional all)
7843   "Limit the summary buffer to articles that are not marked as read.
7844 If ALL is non-nil, limit strictly to unread articles."
7845   (interactive "P")
7846   (if all
7847       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7848     (gnus-summary-limit-to-marks
7849      ;; Concat all the marks that say that an article is read and have
7850      ;; those removed.
7851      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7852            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7853            gnus-low-score-mark gnus-expirable-mark
7854            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7855            gnus-duplicate-mark gnus-souped-mark)
7856      'reverse)))
7857
7858 (defun gnus-summary-limit-to-replied (&optional unreplied)
7859   "Limit the summary buffer to replied articles.
7860 If UNREPLIED (the prefix), limit to unreplied articles."
7861   (interactive "P")
7862   (if unreplied
7863       (gnus-summary-limit
7864        (gnus-set-difference gnus-newsgroup-articles
7865         gnus-newsgroup-replied))
7866     (gnus-summary-limit gnus-newsgroup-replied))
7867   (gnus-summary-position-point))
7868
7869 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7870 (make-obsolete 'gnus-summary-delete-marked-with
7871                'gnus-summary-limit-exclude-marks)
7872
7873 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7874   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7875 If REVERSE, limit the summary buffer to articles that are marked
7876 with MARKS.  MARKS can either be a string of marks or a list of marks.
7877 Returns how many articles were removed."
7878   (interactive "sMarks: ")
7879   (gnus-summary-limit-to-marks marks t))
7880
7881 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7882   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7883 If REVERSE (the prefix), limit the summary buffer to articles that are
7884 not marked with MARKS.  MARKS can either be a string of marks or a
7885 list of marks.
7886 Returns how many articles were removed."
7887   (interactive "sMarks: \nP")
7888   (prog1
7889       (let ((data gnus-newsgroup-data)
7890             (marks (if (listp marks) marks
7891                      (append marks nil))) ; Transform to list.
7892             articles)
7893         (while data
7894           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7895                   (memq (gnus-data-mark (car data)) marks))
7896             (push (gnus-data-number (car data)) articles))
7897           (setq data (cdr data)))
7898         (gnus-summary-limit articles))
7899     (gnus-summary-position-point)))
7900
7901 (defun gnus-summary-limit-to-score (score)
7902   "Limit to articles with score at or above SCORE."
7903   (interactive "NLimit to articles with score of at least: ")
7904   (let ((data gnus-newsgroup-data)
7905         articles)
7906     (while data
7907       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7908                 score)
7909         (push (gnus-data-number (car data)) articles))
7910       (setq data (cdr data)))
7911     (prog1
7912         (gnus-summary-limit articles)
7913       (gnus-summary-position-point))))
7914
7915 (defun gnus-summary-limit-to-unseen ()
7916   "Limit to unseen articles."
7917   (interactive)
7918   (prog1
7919       (gnus-summary-limit gnus-newsgroup-unseen)
7920     (gnus-summary-position-point)))
7921
7922 (defun gnus-summary-limit-include-thread (id)
7923   "Display all the hidden articles that is in the thread with ID in it.
7924 When called interactively, ID is the Message-ID of the current
7925 article."
7926   (interactive (list (mail-header-id (gnus-summary-article-header))))
7927   (let ((articles (gnus-articles-in-thread
7928                    (gnus-id-to-thread (gnus-root-id id)))))
7929     (prog1
7930         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7931       (gnus-summary-limit-include-matching-articles
7932        "subject"
7933        (regexp-quote (gnus-simplify-subject-re
7934                       (mail-header-subject (gnus-id-to-header id)))))
7935       (gnus-summary-position-point))))
7936
7937 (defun gnus-summary-limit-include-matching-articles (header regexp)
7938   "Display all the hidden articles that have HEADERs that match REGEXP."
7939   (interactive (list (read-string "Match on header: ")
7940                      (read-string "Regexp: ")))
7941   (let ((articles (gnus-find-matching-articles header regexp)))
7942     (prog1
7943         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7944       (gnus-summary-position-point))))
7945
7946 (defun gnus-summary-insert-dormant-articles ()
7947   "Insert all the dormant articles for this group into the current buffer."
7948   (interactive)
7949   (let ((gnus-verbose (max 6 gnus-verbose)))
7950     (if (not gnus-newsgroup-dormant)
7951         (gnus-message 3 "No cached articles for this group")
7952       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7953
7954 (defun gnus-summary-limit-include-dormant ()
7955   "Display all the hidden articles that are marked as dormant.
7956 Note that this command only works on a subset of the articles currently
7957 fetched for this group."
7958   (interactive)
7959   (unless gnus-newsgroup-dormant
7960     (error "There are no dormant articles in this group"))
7961   (prog1
7962       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7963     (gnus-summary-position-point)))
7964
7965 (defun gnus-summary-limit-exclude-dormant ()
7966   "Hide all dormant articles."
7967   (interactive)
7968   (prog1
7969       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7970     (gnus-summary-position-point)))
7971
7972 (defun gnus-summary-limit-exclude-childless-dormant ()
7973   "Hide all dormant articles that have no children."
7974   (interactive)
7975   (let ((data (gnus-data-list t))
7976         articles d children)
7977     ;; Find all articles that are either not dormant or have
7978     ;; children.
7979     (while (setq d (pop data))
7980       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7981                 (and (setq children
7982                            (gnus-article-children (gnus-data-number d)))
7983                      (let (found)
7984                        (while children
7985                          (when (memq (car children) articles)
7986                            (setq children nil
7987                                  found t))
7988                          (pop children))
7989                        found)))
7990         (push (gnus-data-number d) articles)))
7991     ;; Do the limiting.
7992     (prog1
7993         (gnus-summary-limit articles)
7994       (gnus-summary-position-point))))
7995
7996 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7997   "Mark all unread excluded articles as read.
7998 If ALL, mark even excluded ticked and dormants as read."
7999   (interactive "P")
8000   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8001   (let ((articles (gnus-sorted-ndifference
8002                    (sort
8003                     (mapcar (lambda (h) (mail-header-number h))
8004                             gnus-newsgroup-headers)
8005                     '<)
8006                    gnus-newsgroup-limit))
8007         article)
8008     (setq gnus-newsgroup-unreads
8009           (gnus-sorted-intersection gnus-newsgroup-unreads
8010                                     gnus-newsgroup-limit))
8011     (if all
8012         (setq gnus-newsgroup-dormant nil
8013               gnus-newsgroup-marked nil
8014               gnus-newsgroup-reads
8015               (nconc
8016                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8017                gnus-newsgroup-reads))
8018       (while (setq article (pop articles))
8019         (unless (or (memq article gnus-newsgroup-dormant)
8020                     (memq article gnus-newsgroup-marked))
8021           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8022
8023 (defun gnus-summary-limit (articles &optional pop)
8024   (if pop
8025       ;; We pop the previous limit off the stack and use that.
8026       (setq articles (car gnus-newsgroup-limits)
8027             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8028     ;; We use the new limit, so we push the old limit on the stack.
8029     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8030   ;; Set the limit.
8031   (setq gnus-newsgroup-limit articles)
8032   (let ((total (length gnus-newsgroup-data))
8033         (data (gnus-data-find-list (gnus-summary-article-number)))
8034         (gnus-summary-mark-below nil)   ; Inhibit this.
8035         found)
8036     ;; This will do all the work of generating the new summary buffer
8037     ;; according to the new limit.
8038     (gnus-summary-prepare)
8039     ;; Hide any threads, possibly.
8040     (gnus-summary-maybe-hide-threads)
8041     ;; Try to return to the article you were at, or one in the
8042     ;; neighborhood.
8043     (when data
8044       ;; We try to find some article after the current one.
8045       (while data
8046         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8047           (setq data nil
8048                 found t))
8049         (setq data (cdr data))))
8050     (unless found
8051       ;; If there is no data, that means that we were after the last
8052       ;; article.  The same goes when we can't find any articles
8053       ;; after the current one.
8054       (goto-char (point-max))
8055       (gnus-summary-find-prev))
8056     (gnus-set-mode-line 'summary)
8057     ;; We return how many articles were removed from the summary
8058     ;; buffer as a result of the new limit.
8059     (- total (length gnus-newsgroup-data))))
8060
8061 (defsubst gnus-invisible-cut-children (threads)
8062   (let ((num 0))
8063     (while threads
8064       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8065         (incf num))
8066       (pop threads))
8067     (< num 2)))
8068
8069 (defsubst gnus-cut-thread (thread)
8070   "Go forwards in the thread until we find an article that we want to display."
8071   (when (or (eq gnus-fetch-old-headers 'some)
8072             (eq gnus-fetch-old-headers 'invisible)
8073             (numberp gnus-fetch-old-headers)
8074             (eq gnus-build-sparse-threads 'some)
8075             (eq gnus-build-sparse-threads 'more))
8076     ;; Deal with old-fetched headers and sparse threads.
8077     (while (and
8078             thread
8079             (or
8080              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8081              (gnus-summary-article-ancient-p
8082               (mail-header-number (car thread))))
8083             (if (or (<= (length (cdr thread)) 1)
8084                     (eq gnus-fetch-old-headers 'invisible))
8085                 (setq gnus-newsgroup-limit
8086                       (delq (mail-header-number (car thread))
8087                             gnus-newsgroup-limit)
8088                       thread (cadr thread))
8089               (when (gnus-invisible-cut-children (cdr thread))
8090                 (let ((th (cdr thread)))
8091                   (while th
8092                     (if (memq (mail-header-number (caar th))
8093                               gnus-newsgroup-limit)
8094                         (setq thread (car th)
8095                               th nil)
8096                       (setq th (cdr th))))))))))
8097   thread)
8098
8099 (defun gnus-cut-threads (threads)
8100   "Cut off all uninteresting articles from the beginning of THREADS."
8101   (when (or (eq gnus-fetch-old-headers 'some)
8102             (eq gnus-fetch-old-headers 'invisible)
8103             (numberp gnus-fetch-old-headers)
8104             (eq gnus-build-sparse-threads 'some)
8105             (eq gnus-build-sparse-threads 'more))
8106     (let ((th threads))
8107       (while th
8108         (setcar th (gnus-cut-thread (car th)))
8109         (setq th (cdr th)))))
8110   ;; Remove nixed out threads.
8111   (delq nil threads))
8112
8113 (defun gnus-summary-initial-limit (&optional show-if-empty)
8114   "Figure out what the initial limit is supposed to be on group entry.
8115 This entails weeding out unwanted dormants, low-scored articles,
8116 fetch-old-headers verbiage, and so on."
8117   ;; Most groups have nothing to remove.
8118   (if (or gnus-inhibit-limiting
8119           (and (null gnus-newsgroup-dormant)
8120                (eq gnus-newsgroup-display 'gnus-not-ignore)
8121                (not (eq gnus-fetch-old-headers 'some))
8122                (not (numberp gnus-fetch-old-headers))
8123                (not (eq gnus-fetch-old-headers 'invisible))
8124                (null gnus-summary-expunge-below)
8125                (not (eq gnus-build-sparse-threads 'some))
8126                (not (eq gnus-build-sparse-threads 'more))
8127                (null gnus-thread-expunge-below)
8128                (not gnus-use-nocem)))
8129       ()                                ; Do nothing.
8130     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8131     (setq gnus-newsgroup-limit nil)
8132     (mapatoms
8133      (lambda (node)
8134        (unless (car (symbol-value node))
8135          ;; These threads have no parents -- they are roots.
8136          (let ((nodes (cdr (symbol-value node)))
8137                thread)
8138            (while nodes
8139              (if (and gnus-thread-expunge-below
8140                       (< (gnus-thread-total-score (car nodes))
8141                          gnus-thread-expunge-below))
8142                  (gnus-expunge-thread (pop nodes))
8143                (setq thread (pop nodes))
8144                (gnus-summary-limit-children thread))))))
8145      gnus-newsgroup-dependencies)
8146     ;; If this limitation resulted in an empty group, we might
8147     ;; pop the previous limit and use it instead.
8148     (when (and (not gnus-newsgroup-limit)
8149                show-if-empty)
8150       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8151     gnus-newsgroup-limit))
8152
8153 (defun gnus-summary-limit-children (thread)
8154   "Return 1 if this subthread is visible and 0 if it is not."
8155   ;; First we get the number of visible children to this thread.  This
8156   ;; is done by recursing down the thread using this function, so this
8157   ;; will really go down to a leaf article first, before slowly
8158   ;; working its way up towards the root.
8159   (when thread
8160     (let* ((max-lisp-eval-depth 5000)
8161            (children
8162            (if (cdr thread)
8163                (apply '+ (mapcar 'gnus-summary-limit-children
8164                                  (cdr thread)))
8165              0))
8166           (number (mail-header-number (car thread)))
8167           score)
8168       (if (and
8169            (not (memq number gnus-newsgroup-marked))
8170            (or
8171             ;; If this article is dormant and has absolutely no visible
8172             ;; children, then this article isn't visible.
8173             (and (memq number gnus-newsgroup-dormant)
8174                  (zerop children))
8175             ;; If this is "fetch-old-headered" and there is no
8176             ;; visible children, then we don't want this article.
8177             (and (or (eq gnus-fetch-old-headers 'some)
8178                      (numberp gnus-fetch-old-headers))
8179                  (gnus-summary-article-ancient-p number)
8180                  (zerop children))
8181             ;; If this is "fetch-old-headered" and `invisible', then
8182             ;; we don't want this article.
8183             (and (eq gnus-fetch-old-headers 'invisible)
8184                  (gnus-summary-article-ancient-p number))
8185             ;; If this is a sparsely inserted article with no children,
8186             ;; we don't want it.
8187             (and (eq gnus-build-sparse-threads 'some)
8188                  (gnus-summary-article-sparse-p number)
8189                  (zerop children))
8190             ;; If we use expunging, and this article is really
8191             ;; low-scored, then we don't want this article.
8192             (when (and gnus-summary-expunge-below
8193                        (< (setq score
8194                                 (or (cdr (assq number gnus-newsgroup-scored))
8195                                     gnus-summary-default-score))
8196                           gnus-summary-expunge-below))
8197               ;; We increase the expunge-tally here, but that has
8198               ;; nothing to do with the limits, really.
8199               (incf gnus-newsgroup-expunged-tally)
8200               ;; We also mark as read here, if that's wanted.
8201               (when (and gnus-summary-mark-below
8202                          (< score gnus-summary-mark-below))
8203                 (setq gnus-newsgroup-unreads
8204                       (delq number gnus-newsgroup-unreads))
8205                 (if gnus-newsgroup-auto-expire
8206                     (push number gnus-newsgroup-expirable)
8207                   (push (cons number gnus-low-score-mark)
8208                         gnus-newsgroup-reads)))
8209               t)
8210             ;; Do the `display' group parameter.
8211             (and gnus-newsgroup-display
8212                  (not (funcall gnus-newsgroup-display)))
8213             ;; Check NoCeM things.
8214             (when (and gnus-use-nocem
8215                        (gnus-nocem-unwanted-article-p
8216                         (mail-header-id (car thread))))
8217               (setq gnus-newsgroup-unreads
8218                     (delq number gnus-newsgroup-unreads))
8219               t)))
8220           ;; Nope, invisible article.
8221           0
8222         ;; Ok, this article is to be visible, so we add it to the limit
8223         ;; and return 1.
8224         (push number gnus-newsgroup-limit)
8225         1))))
8226
8227 (defun gnus-expunge-thread (thread)
8228   "Mark all articles in THREAD as read."
8229   (let* ((number (mail-header-number (car thread))))
8230     (incf gnus-newsgroup-expunged-tally)
8231     ;; We also mark as read here, if that's wanted.
8232     (setq gnus-newsgroup-unreads
8233           (delq number gnus-newsgroup-unreads))
8234     (if gnus-newsgroup-auto-expire
8235         (push number gnus-newsgroup-expirable)
8236       (push (cons number gnus-low-score-mark)
8237             gnus-newsgroup-reads)))
8238   ;; Go recursively through all subthreads.
8239   (mapcar 'gnus-expunge-thread (cdr thread)))
8240
8241 ;; Summary article oriented commands
8242
8243 (defun gnus-summary-refer-parent-article (n)
8244   "Refer parent article N times.
8245 If N is negative, go to ancestor -N instead.
8246 The difference between N and the number of articles fetched is returned."
8247   (interactive "p")
8248   (let ((skip 1)
8249         error header ref)
8250     (when (not (natnump n))
8251       (setq skip (abs n)
8252             n 1))
8253     (while (and (> n 0)
8254                 (not error))
8255       (setq header (gnus-summary-article-header))
8256       (if (and (eq (mail-header-number header)
8257                    (cdr gnus-article-current))
8258                (equal gnus-newsgroup-name
8259                       (car gnus-article-current)))
8260           ;; If we try to find the parent of the currently
8261           ;; displayed article, then we take a look at the actual
8262           ;; References header, since this is slightly more
8263           ;; reliable than the References field we got from the
8264           ;; server.
8265           (save-excursion
8266             (set-buffer gnus-original-article-buffer)
8267             (nnheader-narrow-to-headers)
8268             (unless (setq ref (message-fetch-field "references"))
8269               (when (setq ref (message-fetch-field "in-reply-to"))
8270                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8271             (widen))
8272         (setq ref
8273               ;; It's not the current article, so we take a bet on
8274               ;; the value we got from the server.
8275               (mail-header-references header)))
8276       (if (and ref
8277                (not (equal ref "")))
8278           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8279             (gnus-message 1 "Couldn't find parent"))
8280         (gnus-message 1 "No references in article %d"
8281                       (gnus-summary-article-number))
8282         (setq error t))
8283       (decf n))
8284     (gnus-summary-position-point)
8285     n))
8286
8287 (defun gnus-summary-refer-references ()
8288   "Fetch all articles mentioned in the References header.
8289 Return the number of articles fetched."
8290   (interactive)
8291   (let ((ref (mail-header-references (gnus-summary-article-header)))
8292         (current (gnus-summary-article-number))
8293         (n 0))
8294     (if (or (not ref)
8295             (equal ref ""))
8296         (error "No References in the current article")
8297       ;; For each Message-ID in the References header...
8298       (while (string-match "<[^>]*>" ref)
8299         (incf n)
8300         ;; ... fetch that article.
8301         (gnus-summary-refer-article
8302          (prog1 (match-string 0 ref)
8303            (setq ref (substring ref (match-end 0))))))
8304       (gnus-summary-goto-subject current)
8305       (gnus-summary-position-point)
8306       n)))
8307
8308 (defun gnus-summary-refer-thread (&optional limit)
8309   "Fetch all articles in the current thread.
8310 If LIMIT (the numerical prefix), fetch that many old headers instead
8311 of what's specified by the `gnus-refer-thread-limit' variable."
8312   (interactive "P")
8313   (let ((id (mail-header-id (gnus-summary-article-header)))
8314         (limit (if limit (prefix-numeric-value limit)
8315                  gnus-refer-thread-limit)))
8316     (unless (eq gnus-fetch-old-headers 'invisible)
8317       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8318       ;; Retrieve the headers and read them in.
8319       (if (eq (if (numberp limit)
8320                   (gnus-retrieve-headers
8321                    (list (min
8322                           (+ (mail-header-number
8323                               (gnus-summary-article-header))
8324                              limit)
8325                           gnus-newsgroup-end))
8326                    gnus-newsgroup-name (* limit 2))
8327                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8328                 ;; headers.
8329                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8330                                        gnus-newsgroup-name limit))
8331               'nov)
8332           (gnus-build-all-threads)
8333         (error "Can't fetch thread from back ends that don't support NOV"))
8334       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8335     (gnus-summary-limit-include-thread id)))
8336
8337 (defun gnus-summary-refer-article (message-id)
8338   "Fetch an article specified by MESSAGE-ID."
8339   (interactive "sMessage-ID: ")
8340   (when (and (stringp message-id)
8341              (not (zerop (length message-id))))
8342     (setq message-id (gnus-replace-in-string message-id " " ""))
8343     ;; Construct the correct Message-ID if necessary.
8344     ;; Suggested by tale@pawl.rpi.edu.
8345     (unless (string-match "^<" message-id)
8346       (setq message-id (concat "<" message-id)))
8347     (unless (string-match ">$" message-id)
8348       (setq message-id (concat message-id ">")))
8349     ;; People often post MIDs from URLs, so unhex it:
8350     (unless (string-match "@" message-id)
8351       (setq message-id (gnus-url-unhex-string message-id)))
8352     (let* ((header (gnus-id-to-header message-id))
8353            (sparse (and header
8354                         (gnus-summary-article-sparse-p
8355                          (mail-header-number header))
8356                         (memq (mail-header-number header)
8357                               gnus-newsgroup-limit)))
8358            number)
8359       (cond
8360        ;; If the article is present in the buffer we just go to it.
8361        ((and header
8362              (or (not (gnus-summary-article-sparse-p
8363                        (mail-header-number header)))
8364                  sparse))
8365         (prog1
8366             (gnus-summary-goto-article
8367              (mail-header-number header) nil t)
8368           (when sparse
8369             (gnus-summary-update-article (mail-header-number header)))))
8370        (t
8371         ;; We fetch the article.
8372         (catch 'found
8373           (dolist (gnus-override-method (gnus-refer-article-methods))
8374             (when (and (gnus-check-server gnus-override-method)
8375                        ;; Fetch the header,
8376                        (setq number (gnus-summary-insert-subject message-id)))
8377               ;; and display the article.
8378               (gnus-summary-select-article nil nil nil number)
8379               (throw 'found t)))
8380           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8381
8382 (defun gnus-refer-article-methods ()
8383   "Return a list of referable methods."
8384   (cond
8385    ;; No method, so we default to current and native.
8386    ((null gnus-refer-article-method)
8387     (list gnus-current-select-method gnus-select-method))
8388    ;; Current.
8389    ((eq 'current gnus-refer-article-method)
8390     (list gnus-current-select-method))
8391    ;; List of select methods.
8392    ((not (and (symbolp (car gnus-refer-article-method))
8393               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8394     (let (out)
8395       (dolist (method gnus-refer-article-method)
8396         (push (if (eq 'current method)
8397                   gnus-current-select-method
8398                 method)
8399               out))
8400       (nreverse out)))
8401    ;; One single select method.
8402    (t
8403     (list gnus-refer-article-method))))
8404
8405 (defun gnus-summary-edit-parameters ()
8406   "Edit the group parameters of the current group."
8407   (interactive)
8408   (gnus-group-edit-group gnus-newsgroup-name 'params))
8409
8410 (defun gnus-summary-customize-parameters ()
8411   "Customize the group parameters of the current group."
8412   (interactive)
8413   (gnus-group-customize gnus-newsgroup-name))
8414
8415 (defun gnus-summary-enter-digest-group (&optional force)
8416   "Enter an nndoc group based on the current article.
8417 If FORCE, force a digest interpretation.  If not, try
8418 to guess what the document format is."
8419   (interactive "P")
8420   (let ((conf gnus-current-window-configuration))
8421     (save-window-excursion
8422       (save-excursion
8423         (let (gnus-article-prepare-hook
8424               gnus-display-mime-function
8425               gnus-break-pages)
8426           (gnus-summary-select-article))))
8427     (setq gnus-current-window-configuration conf)
8428     (let* ((name (format "%s-%d"
8429                          (gnus-group-prefixed-name
8430                           gnus-newsgroup-name (list 'nndoc ""))
8431                          (with-current-buffer gnus-summary-buffer
8432                            gnus-current-article)))
8433            (ogroup gnus-newsgroup-name)
8434            (params (append (gnus-info-params (gnus-get-info ogroup))
8435                            (list (cons 'to-group ogroup))
8436                            (list (cons 'parent-group ogroup))
8437                            (list (cons 'save-article-group ogroup))))
8438            (case-fold-search t)
8439            (buf (current-buffer))
8440            dig to-address)
8441       (save-excursion
8442         (set-buffer gnus-original-article-buffer)
8443         ;; Have the digest group inherit the main mail address of
8444         ;; the parent article.
8445         (when (setq to-address (or (gnus-fetch-field "reply-to")
8446                                    (gnus-fetch-field "from")))
8447           (setq params (append
8448                         (list (cons 'to-address
8449                                     (funcall gnus-decode-encoded-word-function
8450                                              to-address))))))
8451         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8452         (insert-buffer-substring gnus-original-article-buffer)
8453         ;; Remove lines that may lead nndoc to misinterpret the
8454         ;; document type.
8455         (narrow-to-region
8456          (goto-char (point-min))
8457          (or (search-forward "\n\n" nil t) (point)))
8458         (goto-char (point-min))
8459         (delete-matching-lines "^Path:\\|^From ")
8460         (widen))
8461       (unwind-protect
8462           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8463                     (gnus-newsgroup-ephemeral-ignored-charsets
8464                      gnus-newsgroup-ignored-charsets))
8465                 (gnus-group-read-ephemeral-group
8466                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8467                               (nndoc-article-type
8468                                ,(if force 'mbox 'guess)))
8469                  t nil nil nil
8470                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8471                                                         "ADAPT")))))
8472               ;; Make all postings to this group go to the parent group.
8473               (nconc (gnus-info-params (gnus-get-info name))
8474                      params)
8475             ;; Couldn't select this doc group.
8476             (switch-to-buffer buf)
8477             (gnus-set-global-variables)
8478             (gnus-configure-windows 'summary)
8479             (gnus-message 3 "Article couldn't be entered?"))
8480         (kill-buffer dig)))))
8481
8482 (defun gnus-summary-read-document (n)
8483   "Open a new group based on the current article(s).
8484 This will allow you to read digests and other similar
8485 documents as newsgroups.
8486 Obeys the standard process/prefix convention."
8487   (interactive "P")
8488   (let* ((ogroup gnus-newsgroup-name)
8489          (params (append (gnus-info-params (gnus-get-info ogroup))
8490                          (list (cons 'to-group ogroup))))
8491          group egroup groups vgroup)
8492     (dolist (article (gnus-summary-work-articles n))
8493       (setq group (format "%s-%d" gnus-newsgroup-name article))
8494       (gnus-summary-remove-process-mark article)
8495       (when (gnus-summary-display-article article)
8496         (save-excursion
8497           (with-temp-buffer
8498             (insert-buffer-substring gnus-original-article-buffer)
8499             ;; Remove some headers that may lead nndoc to make
8500             ;; the wrong guess.
8501             (message-narrow-to-head)
8502             (goto-char (point-min))
8503             (delete-matching-lines "^Path:\\|^From ")
8504             (widen)
8505             (if (setq egroup
8506                       (gnus-group-read-ephemeral-group
8507                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8508                                      (nndoc-article-type guess))
8509                        t nil t))
8510                 (progn
8511                   ;; Make all postings to this group go to the parent group.
8512                   (nconc (gnus-info-params (gnus-get-info egroup))
8513                          params)
8514                   (push egroup groups))
8515               ;; Couldn't select this doc group.
8516               (gnus-error 3 "Article couldn't be entered"))))))
8517     ;; Now we have selected all the documents.
8518     (cond
8519      ((not groups)
8520       (error "None of the articles could be interpreted as documents"))
8521      ((gnus-group-read-ephemeral-group
8522        (setq vgroup (format
8523                      "nnvirtual:%s-%s" gnus-newsgroup-name
8524                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8525        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8526        t
8527        (cons (current-buffer) 'summary)))
8528      (t
8529       (error "Couldn't select virtual nndoc group")))))
8530
8531 (defun gnus-summary-isearch-article (&optional regexp-p)
8532   "Do incremental search forward on the current article.
8533 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8534   (interactive "P")
8535   (let* ((gnus-inhibit-treatment t)
8536          (old (gnus-summary-select-article)))
8537     (gnus-configure-windows 'article)
8538     (gnus-eval-in-buffer-window gnus-article-buffer
8539       (save-restriction
8540         (widen)
8541         (when (eq 'old old)
8542           (gnus-article-show-all-headers))
8543         (goto-char (point-min))
8544         (isearch-forward regexp-p)))))
8545
8546 (defun gnus-summary-search-article-forward (regexp &optional backward)
8547   "Search for an article containing REGEXP forward.
8548 If BACKWARD, search backward instead."
8549   (interactive
8550    (list (read-string
8551           (format "Search article %s (regexp%s): "
8552                   (if current-prefix-arg "backward" "forward")
8553                   (if gnus-last-search-regexp
8554                       (concat ", default " gnus-last-search-regexp)
8555                     "")))
8556          current-prefix-arg))
8557   (if (string-equal regexp "")
8558       (setq regexp (or gnus-last-search-regexp ""))
8559     (setq gnus-last-search-regexp regexp)
8560     (setq gnus-article-before-search gnus-current-article))
8561   ;; Intentionally set gnus-last-article.
8562   (setq gnus-last-article gnus-article-before-search)
8563   (let ((gnus-last-article gnus-last-article))
8564     (if (gnus-summary-search-article regexp backward)
8565         (gnus-summary-show-thread)
8566       (signal 'search-failed (list regexp)))))
8567
8568 (defun gnus-summary-search-article-backward (regexp)
8569   "Search for an article containing REGEXP backward."
8570   (interactive
8571    (list (read-string
8572           (format "Search article backward (regexp%s): "
8573                   (if gnus-last-search-regexp
8574                       (concat ", default " gnus-last-search-regexp)
8575                     "")))))
8576   (gnus-summary-search-article-forward regexp 'backward))
8577
8578 (eval-when-compile
8579   (defmacro gnus-summary-search-article-position-point (regexp backward)
8580     "Dehighlight the last matched text and goto the beginning position."
8581     (` (if (and gnus-summary-search-article-matched-data
8582                 (let ((text (caddr gnus-summary-search-article-matched-data))
8583                       (inhibit-read-only t)
8584                       buffer-read-only)
8585                   (delete-region
8586                    (goto-char (car gnus-summary-search-article-matched-data))
8587                    (cadr gnus-summary-search-article-matched-data))
8588                   (insert text)
8589                   (string-match (, regexp) text)))
8590            (if (, backward) (beginning-of-line) (end-of-line))
8591          (goto-char (if (, backward) (point-max) (point-min))))))
8592
8593   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8594     "Place point where X-Face image is displayed."
8595     (if (featurep 'xemacs)
8596         (` (let ((end (if (search-forward "\n\n" nil t)
8597                           (goto-char (1- (point)))
8598                         (point-min)))
8599                  extent)
8600              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8601              (unless (and (re-search-forward "^From:" end t)
8602                           (setq extent (extent-at (point)))
8603                           (extent-begin-glyph extent))
8604                (goto-char (, opoint)))))
8605       (` (let ((end (if (search-forward "\n\n" nil t)
8606                         (goto-char (1- (point)))
8607                       (point-min)))
8608                (start (or (search-backward "\n\n" nil t) (point-min))))
8609            (goto-char
8610             (or (text-property-any start end 'x-face-image t);; x-face-e21
8611                 (, opoint)))))))
8612
8613   (defmacro gnus-summary-search-article-highlight-matched-text
8614     (backward treated x-face)
8615     "Highlight matched text in the function `gnus-summary-search-article'."
8616     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8617              (end (set-marker (make-marker) (match-end 0)))
8618              (inhibit-read-only t)
8619              buffer-read-only)
8620          (unless treated
8621            (let ((,@
8622                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8623                     (mapcar
8624                      (lambda (item) (setq items (delq item items)))
8625                      '(gnus-treat-buttonize
8626                        gnus-treat-fill-article
8627                        gnus-treat-fill-long-lines
8628                        gnus-treat-emphasize
8629                        gnus-treat-highlight-headers
8630                        gnus-treat-highlight-citation
8631                        gnus-treat-highlight-signature
8632                        gnus-treat-overstrike
8633                        gnus-treat-display-x-face
8634                        gnus-treat-buttonize-head
8635                        gnus-treat-decode-article-as-default-mime-charset))
8636                     items))
8637                  (gnus-treat-display-x-face
8638                   (when (, x-face) gnus-treat-display-x-face)))
8639              (gnus-article-prepare-mime-display)))
8640          (goto-char (if (, backward) start end))
8641          (when (, x-face)
8642            (gnus-summary-search-article-highlight-goto-x-face (point)))
8643          (setq gnus-summary-search-article-matched-data
8644                (list start end (buffer-substring start end)))
8645          (unless (eq start end);; matched text has been deleted. :-<
8646            (put-text-property start end 'face
8647                               (or (find-face 'isearch)
8648                                   'secondary-selection))))))
8649   )
8650
8651 (defun gnus-summary-search-article (regexp &optional backward)
8652   "Search for an article containing REGEXP.
8653 Optional argument BACKWARD means do search for backward.
8654 `gnus-select-article-hook' is not called during the search."
8655   ;; We have to require this here to make sure that the following
8656   ;; dynamic binding isn't shadowed by autoloading.
8657   (require 'gnus-async)
8658   (require 'gnus-art)
8659   (let ((gnus-select-article-hook nil)  ;Disable hook.
8660         (gnus-article-prepare-hook nil)
8661         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8662         (gnus-use-article-prefetch nil)
8663         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8664         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8665         (gnus-visual nil)
8666         (gnus-keep-backlog nil)
8667         (gnus-break-pages nil)
8668         (gnus-summary-display-arrow nil)
8669         (gnus-updated-mode-lines nil)
8670         (gnus-auto-center-summary nil)
8671         (sum (current-buffer))
8672         (found nil)
8673         point treated)
8674     (gnus-save-hidden-threads
8675       (static-if (featurep 'xemacs)
8676           (let ((gnus-inhibit-treatment t))
8677             (setq treated (eq 'old (gnus-summary-select-article)))
8678             (when (and treated
8679                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8680                                  (window-live-p (get-buffer-window
8681                                                  gnus-article-buffer t)))))
8682               (gnus-summary-select-article nil t)
8683               (setq treated nil)))
8684         (let ((gnus-inhibit-treatment t))
8685           (setq treated (eq 'old (gnus-summary-select-article)))
8686           (when (and treated
8687                      (not
8688                       (and (gnus-buffer-live-p gnus-article-buffer)
8689                            (window-live-p (get-buffer-window
8690                                            gnus-article-buffer t))
8691                            (or (not (string-match "^\\^X-Face:" regexp))
8692                                (with-current-buffer gnus-article-buffer
8693                                  gnus-summary-search-article-matched-data)))))
8694             (gnus-summary-select-article nil t)
8695             (setq treated nil))))
8696       (set-buffer gnus-article-buffer)
8697       (widen)
8698       (if treated
8699           (progn
8700             (gnus-article-show-all-headers)
8701             (gnus-summary-search-article-position-point regexp backward))
8702         (goto-char (if backward (point-max) (point-min))))
8703       (while (not found)
8704         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8705         (if (if backward
8706                 (re-search-backward regexp nil t)
8707               (re-search-forward regexp nil t))
8708             ;; We found the regexp.
8709             (progn
8710               (gnus-summary-search-article-highlight-matched-text
8711                backward treated (string-match "^\\^X-Face:" regexp))
8712               (setq found 'found)
8713               (forward-line
8714                (/ (- 2 (window-height
8715                         (get-buffer-window gnus-article-buffer t)))
8716                   2))
8717               (set-window-start
8718                (get-buffer-window (current-buffer))
8719                (point))
8720               (set-buffer sum)
8721               (setq point (point)))
8722           ;; We didn't find it, so we go to the next article.
8723           (set-buffer sum)
8724           (setq found 'not)
8725           (while (eq found 'not)
8726             (if (not (if backward (gnus-summary-find-prev)
8727                        (gnus-summary-find-next)))
8728                 ;; No more articles.
8729                 (setq found t)
8730               ;; Select the next article and adjust point.
8731               (unless (gnus-summary-article-sparse-p
8732                        (gnus-summary-article-number))
8733                 (setq found nil)
8734                 (let ((gnus-inhibit-treatment t))
8735                   (gnus-summary-select-article))
8736                 (setq treated nil)
8737                 (set-buffer gnus-article-buffer)
8738                 (widen)
8739                 (goto-char (if backward (point-max) (point-min))))))))
8740       (gnus-message 7 ""))
8741     ;; Return whether we found the regexp.
8742     (when (eq found 'found)
8743       (goto-char point)
8744       (gnus-summary-show-thread)
8745       (gnus-summary-goto-subject gnus-current-article)
8746       (gnus-summary-position-point)
8747       t)))
8748
8749 (defun gnus-find-matching-articles (header regexp)
8750   "Return a list of all articles that match REGEXP on HEADER.
8751 This search includes all articles in the current group that Gnus has
8752 fetched headers for, whether they are displayed or not."
8753   (let ((articles nil)
8754         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8755         (case-fold-search t))
8756     (dolist (header gnus-newsgroup-headers)
8757       (when (string-match regexp (funcall func header))
8758         (push (mail-header-number header) articles)))
8759     (nreverse articles)))
8760
8761 (defun gnus-summary-find-matching (header regexp &optional backward unread
8762                                           not-case-fold not-matching)
8763   "Return a list of all articles that match REGEXP on HEADER.
8764 The search stars on the current article and goes forwards unless
8765 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8766 If UNREAD is non-nil, only unread articles will
8767 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8768 in the comparisons. If NOT-MATCHING, return a list of all articles that
8769 not match REGEXP on HEADER."
8770   (let ((case-fold-search (not not-case-fold))
8771         articles d func)
8772     (if (consp header)
8773         (if (eq (car header) 'extra)
8774             (setq func
8775                   `(lambda (h)
8776                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8777                          "")))
8778           (error "%s is an invalid header" header))
8779       (unless (fboundp (intern (concat "mail-header-" header)))
8780         (error "%s is not a valid header" header))
8781       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8782     (dolist (d (if (eq backward 'all)
8783                    gnus-newsgroup-data
8784                  (gnus-data-find-list
8785                   (gnus-summary-article-number)
8786                   (gnus-data-list backward))))
8787       (when (and (or (not unread)       ; We want all articles...
8788                      (gnus-data-unread-p d)) ; Or just unreads.
8789                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8790                  (if not-matching
8791                      (not (string-match
8792                            regexp
8793                            (funcall func (gnus-data-header d))))
8794                    (string-match regexp
8795                                  (funcall func (gnus-data-header d)))))
8796         (push (gnus-data-number d) articles))) ; Success!
8797     (nreverse articles)))
8798
8799 (defun gnus-summary-execute-command (header regexp command &optional backward)
8800   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8801 If HEADER is an empty string (or nil), the match is done on the entire
8802 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8803   (interactive
8804    (list (let ((completion-ignore-case t))
8805            (completing-read
8806             "Header name: "
8807             (mapcar (lambda (header) (list (format "%s" header)))
8808                     (append
8809                      '("Number" "Subject" "From" "Lines" "Date"
8810                        "Message-ID" "Xref" "References" "Body")
8811                      gnus-extra-headers))
8812             nil 'require-match))
8813          (read-string "Regexp: ")
8814          (read-key-sequence "Command: ")
8815          current-prefix-arg))
8816   (when (equal header "Body")
8817     (setq header ""))
8818   ;; Hidden thread subtrees must be searched as well.
8819   (gnus-summary-show-all-threads)
8820   ;; We don't want to change current point nor window configuration.
8821   (save-excursion
8822     (save-window-excursion
8823       (let (gnus-visual
8824             gnus-treat-strip-trailing-blank-lines
8825             gnus-treat-strip-leading-blank-lines
8826             gnus-treat-strip-multiple-blank-lines
8827             gnus-treat-hide-boring-headers
8828             gnus-treat-fold-newsgroups
8829             gnus-article-prepare-hook)
8830         (gnus-message 6 "Executing %s..." (key-description command))
8831         ;; We'd like to execute COMMAND interactively so as to give arguments.
8832         (gnus-execute header regexp
8833                       `(call-interactively ',(key-binding command))
8834                       backward)
8835         (gnus-message 6 "Executing %s...done" (key-description command))))))
8836
8837 (defun gnus-summary-beginning-of-article ()
8838   "Scroll the article back to the beginning."
8839   (interactive)
8840   (gnus-summary-select-article)
8841   (gnus-configure-windows 'article)
8842   (gnus-eval-in-buffer-window gnus-article-buffer
8843     (widen)
8844     (goto-char (point-min))
8845     (when gnus-break-pages
8846       (gnus-narrow-to-page))))
8847
8848 (defun gnus-summary-end-of-article ()
8849   "Scroll to the end of the article."
8850   (interactive)
8851   (gnus-summary-select-article)
8852   (gnus-configure-windows 'article)
8853   (gnus-eval-in-buffer-window gnus-article-buffer
8854     (widen)
8855     (goto-char (point-max))
8856     (recenter -3)
8857     (when gnus-break-pages
8858       (when (re-search-backward page-delimiter nil t)
8859         (narrow-to-region (match-end 0) (point-max)))
8860       (gnus-narrow-to-page))))
8861
8862 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8863   "Truncate to LEN and quote all \"(\"'s in STRING."
8864   (gnus-replace-in-string (if (and len (> (length string) len))
8865                               (substring string 0 len)
8866                             string)
8867                           "[()]" "\\\\\\&"))
8868
8869 (defun gnus-summary-print-article (&optional filename n)
8870   "Generate and print a PostScript image of the process-marked (mail) articles.
8871
8872 If used interactively, print the current article if none are
8873 process-marked.  With prefix arg, prompt the user for the name of the
8874 file to save in.
8875
8876 When used from Lisp, accept two optional args FILENAME and N.  N means
8877 to print the next N articles.  If N is negative, print the N previous
8878 articles.  If N is nil and articles have been marked with the process
8879 mark, print these instead.
8880
8881 If the optional first argument FILENAME is nil, send the image to the
8882 printer.  If FILENAME is a string, save the PostScript image in a file with
8883 that name.  If FILENAME is a number, prompt the user for the name of the file
8884 to save in."
8885   (interactive (list (ps-print-preprint current-prefix-arg)))
8886   (dolist (article (gnus-summary-work-articles n))
8887     (gnus-summary-select-article nil nil 'pseudo article)
8888     (gnus-eval-in-buffer-window gnus-article-buffer
8889       (gnus-print-buffer))
8890     (gnus-summary-remove-process-mark article))
8891   (ps-despool filename))
8892
8893 (defun gnus-print-buffer ()
8894   (let ((buffer (generate-new-buffer " *print*")))
8895     (unwind-protect
8896         (progn
8897           (copy-to-buffer buffer (point-min) (point-max))
8898           (set-buffer buffer)
8899           (gnus-remove-text-with-property 'gnus-decoration)
8900           (when (gnus-visual-p 'article-highlight 'highlight)
8901             ;; Copy-to-buffer doesn't copy overlay.  So redo
8902             ;; highlight.
8903             (let ((gnus-article-buffer buffer))
8904               (gnus-article-highlight-citation t)
8905               (gnus-article-highlight-signature)
8906               (gnus-article-emphasize)
8907               (gnus-article-delete-invisible-text)))
8908           (let ((ps-left-header
8909                  (list
8910                   (concat "("
8911                           (gnus-summary-print-truncate-and-quote
8912                            (mail-header-subject gnus-current-headers)
8913                            66) ")")
8914                   (concat "("
8915                           (gnus-summary-print-truncate-and-quote
8916                            (mail-header-from gnus-current-headers)
8917                            45) ")")))
8918                 (ps-right-header
8919                  (list
8920                   "/pagenumberstring load"
8921                   (concat "("
8922                           (mail-header-date gnus-current-headers) ")"))))
8923             (gnus-run-hooks 'gnus-ps-print-hook)
8924             (save-excursion
8925               (if window-system
8926                   (ps-spool-buffer-with-faces)
8927                 (ps-spool-buffer)))))
8928       (kill-buffer buffer))))
8929
8930 (defun gnus-summary-show-article (&optional arg)
8931   "Force redisplaying of the current article.
8932 If ARG (the prefix) is a number, show the article with the charset
8933 defined in `gnus-summary-show-article-charset-alist', or the charset
8934 input.
8935 If ARG (the prefix) is non-nil and not a number, show the raw article
8936 without any article massaging functions being run.  Normally, the key
8937 strokes are `C-u g'."
8938   (interactive "P")
8939   (cond
8940    ((numberp arg)
8941     (gnus-summary-show-article t)
8942     (let* ((gnus-newsgroup-charset
8943             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8944                 (mm-read-coding-system
8945                  "View as charset: " ;; actually it is coding system.
8946                  (with-current-buffer gnus-article-buffer
8947                    (mm-detect-coding-region (point) (point-max))))))
8948            (default-mime-charset gnus-newsgroup-charset)
8949            (gnus-newsgroup-ignored-charsets 'gnus-all))
8950       (gnus-summary-select-article nil 'force)
8951       (let ((deps gnus-newsgroup-dependencies)
8952             head header lines)
8953         (save-excursion
8954           (set-buffer gnus-original-article-buffer)
8955           (save-restriction
8956             (message-narrow-to-head)
8957             (setq head (buffer-string))
8958             (goto-char (point-min))
8959             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8960               (goto-char (point-max))
8961               (widen)
8962               (setq lines (1- (count-lines (point) (point-max))))))
8963           (with-temp-buffer
8964             (insert (format "211 %d Article retrieved.\n"
8965                             (cdr gnus-article-current)))
8966             (insert head)
8967             (if lines (insert (format "Lines: %d\n" lines)))
8968             (insert ".\n")
8969             (let ((nntp-server-buffer (current-buffer)))
8970               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8971         (gnus-data-set-header
8972          (gnus-data-find (cdr gnus-article-current))
8973          header)
8974         (gnus-summary-update-article-line
8975          (cdr gnus-article-current) header)
8976         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8977           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8978    ((not arg)
8979     ;; Select the article the normal way.
8980     (gnus-summary-select-article nil 'force))
8981    (t
8982     ;; We have to require this here to make sure that the following
8983     ;; dynamic binding isn't shadowed by autoloading.
8984     (require 'gnus-async)
8985     (require 'gnus-art)
8986     ;; Bind the article treatment functions to nil.
8987     (let ((gnus-have-all-headers t)
8988           gnus-article-prepare-hook
8989           gnus-article-decode-hook
8990           gnus-break-pages
8991           gnus-show-mime
8992           (gnus-inhibit-treatment t))
8993       (gnus-summary-select-article nil 'force))))
8994   (gnus-summary-goto-subject gnus-current-article)
8995   (gnus-summary-position-point))
8996
8997 (defun gnus-summary-show-raw-article ()
8998   "Show the raw article without any article massaging functions being run."
8999   (interactive)
9000   (gnus-summary-show-article t))
9001
9002 (defun gnus-summary-verbose-headers (&optional arg)
9003   "Toggle permanent full header display.
9004 If ARG is a positive number, turn header display on.
9005 If ARG is a negative number, turn header display off."
9006   (interactive "P")
9007   (setq gnus-show-all-headers
9008         (cond ((or (not (numberp arg))
9009                    (zerop arg))
9010                (not gnus-show-all-headers))
9011               ((natnump arg)
9012                t)))
9013   (gnus-summary-show-article))
9014
9015 (defun gnus-summary-toggle-header (&optional arg)
9016   "Show the headers if they are hidden, or hide them if they are shown.
9017 If ARG is a positive number, show the entire header.
9018 If ARG is a negative number, hide the unwanted header lines."
9019   (interactive "P")
9020   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9021                      (get-buffer-window gnus-article-buffer t))))
9022     (with-current-buffer gnus-article-buffer
9023       (widen)
9024       (article-narrow-to-head)
9025       (let* ((buffer-read-only nil)
9026              (inhibit-point-motion-hooks t)
9027              (hidden (if (numberp arg)
9028                          (>= arg 0)
9029                        (or (not (looking-at "[^ \t\n]+:"))
9030                            (gnus-article-hidden-text-p 'headers))))
9031              s e)
9032         (delete-region (point-min) (point-max))
9033         (with-current-buffer gnus-original-article-buffer
9034           (goto-char (setq s (point-min)))
9035           (setq e (if (search-forward "\n\n" nil t)
9036                       (1- (point))
9037                     (point-max))))
9038         (insert-buffer-substring gnus-original-article-buffer s e)
9039         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9040         ;; article-decode-encoded-words by default.
9041         (article-decode-encoded-words)
9042         (run-hooks 'gnus-article-decode-hook)
9043         (if hidden
9044             (let ((gnus-treat-hide-headers nil)
9045                   (gnus-treat-hide-boring-headers nil))
9046               (gnus-delete-wash-type 'headers)
9047               (gnus-treat-article 'head))
9048           (gnus-treat-article 'head))
9049         (widen)
9050         (if window
9051             (set-window-start window (goto-char (point-min))))
9052         (if gnus-break-pages
9053             (gnus-narrow-to-page)
9054           (when (gnus-visual-p 'page-marker)
9055             (let ((buffer-read-only nil))
9056               (gnus-remove-text-with-property 'gnus-prev)
9057               (gnus-remove-text-with-property 'gnus-next))))
9058         (gnus-set-mode-line 'article)))))
9059
9060 (defun gnus-summary-show-all-headers ()
9061   "Make all header lines visible."
9062   (interactive)
9063   (gnus-summary-toggle-header 1))
9064
9065 (defun gnus-summary-toggle-mime (&optional arg)
9066   "Toggle MIME processing.
9067 If ARG is a positive number, turn MIME processing on."
9068   (interactive "P")
9069   (setq gnus-show-mime
9070         (if (null arg)
9071             (not gnus-show-mime)
9072           (> (prefix-numeric-value arg) 0)))
9073   (gnus-summary-select-article t 'force))
9074
9075 (defun gnus-summary-caesar-message (&optional arg)
9076   "Caesar rotate the current article by 13.
9077 The numerical prefix specifies how many places to rotate each letter
9078 forward."
9079   (interactive "P")
9080   (gnus-summary-select-article)
9081   (let ((mail-header-separator ""))
9082     (gnus-eval-in-buffer-window gnus-article-buffer
9083       (save-restriction
9084         (widen)
9085         (let ((start (window-start))
9086               buffer-read-only)
9087           (message-caesar-buffer-body arg)
9088           (set-window-start (get-buffer-window (current-buffer)) start)))))
9089   ;; Create buttons and stuff...
9090   (gnus-treat-article nil))
9091
9092 (defun gnus-summary-idna-message (&optional arg)
9093   "Decode IDNA encoded domain names in the current articles.
9094 IDNA encoded domain names looks like `xn--bar'.  If a string
9095 remain unencoded after running this function, it is likely an
9096 invalid IDNA string (`xn--bar' is invalid).
9097
9098 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9099 installed for this command to work."
9100   (interactive "P")
9101   (if (not (and (condition-case nil (require 'idna)
9102                   (file-error))
9103                 (mm-coding-system-p 'utf-8)
9104                 (executable-find (symbol-value 'idna-program))))
9105       (gnus-message
9106        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9107     (gnus-summary-select-article)
9108     (let ((mail-header-separator ""))
9109       (gnus-eval-in-buffer-window gnus-article-buffer
9110         (save-restriction
9111           (widen)
9112           (let ((start (window-start))
9113                 buffer-read-only)
9114             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9115               (replace-match (idna-to-unicode (match-string 1))))
9116             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9117
9118 (autoload 'unmorse-region "morse"
9119   "Convert morse coded text in region to ordinary ASCII text."
9120   t)
9121
9122 (defun gnus-summary-morse-message (&optional arg)
9123   "Morse decode the current article."
9124   (interactive "P")
9125   (gnus-summary-select-article)
9126   (let ((mail-header-separator ""))
9127     (gnus-eval-in-buffer-window gnus-article-buffer
9128       (save-excursion
9129         (save-restriction
9130           (widen)
9131           (let ((pos (window-start))
9132                 buffer-read-only)
9133             (goto-char (point-min))
9134             (when (message-goto-body)
9135               (gnus-narrow-to-body))
9136             (goto-char (point-min))
9137             (while (search-forward "·" (point-max) t)
9138               (replace-match "."))
9139             (unmorse-region (point-min) (point-max))
9140             (widen)
9141             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9142
9143 (defun gnus-summary-stop-page-breaking ()
9144   "Stop page breaking in the current article."
9145   (interactive)
9146   (gnus-summary-select-article)
9147   (gnus-eval-in-buffer-window gnus-article-buffer
9148     (widen)
9149     (when (gnus-visual-p 'page-marker)
9150       (let ((buffer-read-only nil))
9151         (gnus-remove-text-with-property 'gnus-prev)
9152         (gnus-remove-text-with-property 'gnus-next))
9153       (setq gnus-page-broken nil))))
9154
9155 (defun gnus-summary-move-article (&optional n to-newsgroup
9156                                             select-method action)
9157   "Move the current article to a different newsgroup.
9158 If N is a positive number, move the N next articles.
9159 If N is a negative number, move the N previous articles.
9160 If N is nil and any articles have been marked with the process mark,
9161 move those articles instead.
9162 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9163 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9164 re-spool using this method.
9165
9166 When called interactively with TO-NEWSGROUP being nil, the value of
9167 the variable `gnus-move-split-methods' is used for finding a default
9168 for the target newsgroup.
9169
9170 For this function to work, both the current newsgroup and the
9171 newsgroup that you want to move to have to support the `request-move'
9172 and `request-accept' functions.
9173
9174 ACTION can be either `move' (the default), `crosspost' or `copy'."
9175   (interactive "P")
9176   (unless action
9177     (setq action 'move))
9178   ;; Check whether the source group supports the required functions.
9179   (cond ((and (eq action 'move)
9180               (not (gnus-check-backend-function
9181                     'request-move-article gnus-newsgroup-name)))
9182          (error "The current group does not support article moving"))
9183         ((and (eq action 'crosspost)
9184               (not (gnus-check-backend-function
9185                     'request-replace-article gnus-newsgroup-name)))
9186          (error "The current group does not support article editing")))
9187   (let ((articles (gnus-summary-work-articles n))
9188         (prefix (if (gnus-check-backend-function
9189                      'request-move-article gnus-newsgroup-name)
9190                     (funcall gnus-move-group-prefix-function
9191                              gnus-newsgroup-name)
9192                   ""))
9193         (names '((move "Move" "Moving")
9194                  (copy "Copy" "Copying")
9195                  (crosspost "Crosspost" "Crossposting")))
9196         (copy-buf (save-excursion
9197                     (nnheader-set-temp-buffer " *copy article*")))
9198         art-group to-method new-xref article to-groups articles-to-update-marks)
9199     (unless (assq action names)
9200       (error "Unknown action %s" action))
9201     ;; Read the newsgroup name.
9202     (when (and (not to-newsgroup)
9203                (not select-method))
9204       (if (and gnus-move-split-methods
9205                (not
9206                 (and (memq gnus-current-article articles)
9207                      (gnus-buffer-live-p gnus-original-article-buffer))))
9208           ;; When `gnus-move-split-methods' is non-nil, we have to
9209           ;; select an article to give `gnus-read-move-group-name' an
9210           ;; opportunity to suggest an appropriate default.  However,
9211           ;; we needn't render or mark the article.
9212           (let ((gnus-display-mime-function nil)
9213                 (gnus-article-prepare-hook nil)
9214                 (gnus-mark-article-hook nil))
9215             (gnus-summary-select-article nil nil nil (car articles))))
9216       (setq to-newsgroup
9217             (gnus-read-move-group-name
9218              (cadr (assq action names))
9219              (symbol-value (intern (format "gnus-current-%s-group" action)))
9220              articles prefix))
9221       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9222     (setq to-method (or select-method
9223                         (gnus-server-to-method
9224                          (gnus-group-method to-newsgroup))))
9225     ;; Check the method we are to move this article to...
9226     (unless (gnus-check-backend-function
9227              'request-accept-article (car to-method))
9228       (error "%s does not support article copying" (car to-method)))
9229     (unless (gnus-check-server to-method)
9230       (error "Can't open server %s" (car to-method)))
9231     (gnus-message 6 "%s to %s: %s..."
9232                   (caddr (assq action names))
9233                   (or (car select-method) to-newsgroup) articles)
9234     (while articles
9235       (setq article (pop articles))
9236       (setq
9237        art-group
9238        (cond
9239         ;; Move the article.
9240         ((eq action 'move)
9241          ;; Remove this article from future suppression.
9242          (gnus-dup-unsuppress-article article)
9243          (let* ((from-method (gnus-find-method-for-group
9244                               gnus-newsgroup-name))
9245                 (to-method (gnus-find-method-for-group
9246                             to-newsgroup))
9247                 (move-is-internal (gnus-method-equal from-method to-method)))
9248          (gnus-request-move-article
9249           article                       ; Article to move
9250           gnus-newsgroup-name           ; From newsgroup
9251           (nth 1 (gnus-find-method-for-group
9252                   gnus-newsgroup-name)) ; Server
9253           (list 'gnus-request-accept-article
9254                 to-newsgroup (list 'quote select-method)
9255                 (not articles) t)       ; Accept form
9256           (not articles)                ; Only save nov last time
9257           move-is-internal)))           ; is this move internal?
9258         ;; Copy the article.
9259         ((eq action 'copy)
9260          (save-excursion
9261            (set-buffer copy-buf)
9262            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9263              (save-restriction
9264                (nnheader-narrow-to-headers)
9265                (dolist (hdr gnus-copy-article-ignored-headers)
9266                  (message-remove-header hdr t)))
9267              (gnus-request-accept-article
9268               to-newsgroup select-method (not articles) t))))
9269         ;; Crosspost the article.
9270         ((eq action 'crosspost)
9271          (let ((xref (message-tokenize-header
9272                       (mail-header-xref (gnus-summary-article-header article))
9273                       " ")))
9274            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9275                                   ":" (number-to-string article)))
9276            (unless xref
9277              (setq xref (list (system-name))))
9278            (setq new-xref
9279                  (concat
9280                   (mapconcat 'identity
9281                              (delete "Xref:" (delete new-xref xref))
9282                              " ")
9283                   " " new-xref))
9284            (save-excursion
9285              (set-buffer copy-buf)
9286              ;; First put the article in the destination group.
9287              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9288              (when (consp (setq art-group
9289                                 (gnus-request-accept-article
9290                                  to-newsgroup select-method (not articles))))
9291                (setq new-xref (concat new-xref " " (car art-group)
9292                                       ":"
9293                                       (number-to-string (cdr art-group))))
9294                ;; Now we have the new Xrefs header, so we insert
9295                ;; it and replace the new article.
9296                (nnheader-replace-header "Xref" new-xref)
9297                (gnus-request-replace-article
9298                 (cdr art-group) to-newsgroup (current-buffer))
9299                art-group))))))
9300       (cond
9301        ((not art-group)
9302         (gnus-message 1 "Couldn't %s article %s: %s"
9303                       (cadr (assq action names)) article
9304                       (nnheader-get-report (car to-method))))
9305        ((eq art-group 'junk)
9306         (when (eq action 'move)
9307           (gnus-summary-mark-article article gnus-canceled-mark)
9308           (gnus-message 4 "Deleted article %s" article)
9309           ;; run the delete hook
9310           (run-hook-with-args 'gnus-summary-article-delete-hook
9311                               action
9312                               (gnus-data-header
9313                                (assoc article (gnus-data-list nil)))
9314                               gnus-newsgroup-name nil
9315                               select-method)))
9316        (t
9317         (let* ((pto-group (gnus-group-prefixed-name
9318                            (car art-group) to-method))
9319                (info (gnus-get-info pto-group))
9320                (to-group (gnus-info-group info))
9321                to-marks)
9322           ;; Update the group that has been moved to.
9323           (when (and info
9324                      (memq action '(move copy)))
9325             (unless (member to-group to-groups)
9326               (push to-group to-groups))
9327
9328             (unless (memq article gnus-newsgroup-unreads)
9329               (push 'read to-marks)
9330               (gnus-info-set-read
9331                info (gnus-add-to-range (gnus-info-read info)
9332                                        (list (cdr art-group)))))
9333
9334             ;; See whether the article is to be put in the cache.
9335             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9336                              gnus-article-mark-lists
9337                            (delete '(expirable . expire)
9338                                    (copy-sequence gnus-article-mark-lists))))
9339                   (to-article (cdr art-group)))
9340
9341               ;; Enter the article into the cache in the new group,
9342               ;; if that is required.
9343               (when gnus-use-cache
9344                 (gnus-cache-possibly-enter-article
9345                  to-group to-article
9346                  (let ((header (copy-sequence
9347                                 (gnus-summary-article-header article))))
9348                    (mail-header-set-number header to-article)
9349                    header)
9350                  (memq article gnus-newsgroup-marked)
9351                  (memq article gnus-newsgroup-dormant)
9352                  (memq article gnus-newsgroup-unreads)))
9353
9354               (when gnus-preserve-marks
9355                 ;; Copy any marks over to the new group.
9356                 (when (and (equal to-group gnus-newsgroup-name)
9357                            (not (memq article gnus-newsgroup-unreads)))
9358                   ;; Mark this article as read in this group.
9359                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9360                   (setcdr (gnus-active to-group) to-article)
9361                   (setcdr gnus-newsgroup-active to-article))
9362
9363                 (while marks
9364                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9365                     (when (memq article (symbol-value
9366                                          (intern (format "gnus-newsgroup-%s"
9367                                                          (caar marks)))))
9368                       (push (cdar marks) to-marks)
9369                       ;; If the other group is the same as this group,
9370                       ;; then we have to add the mark to the list.
9371                       (when (equal to-group gnus-newsgroup-name)
9372                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9373                              (cons to-article
9374                                    (symbol-value
9375                                     (intern (format "gnus-newsgroup-%s"
9376                                                     (caar marks)))))))
9377                       ;; Copy the marks to other group.
9378                       (gnus-add-marked-articles
9379                        to-group (cdar marks) (list to-article) info)))
9380                   (setq marks (cdr marks)))
9381
9382                 (gnus-request-set-mark
9383                  to-group (list (list (list to-article) 'add to-marks))))
9384
9385               (gnus-dribble-enter
9386                (concat "(gnus-group-set-info '"
9387                        (gnus-prin1-to-string (gnus-get-info to-group))
9388                        ")"))))
9389
9390           ;; Update the Xref header in this article to point to
9391           ;; the new crossposted article we have just created.
9392           (when (eq action 'crosspost)
9393             (save-excursion
9394               (set-buffer copy-buf)
9395               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9396               (nnheader-replace-header "Xref" new-xref)
9397               (gnus-request-replace-article
9398                article gnus-newsgroup-name (current-buffer))))
9399
9400           ;; run the move/copy/crosspost/respool hook
9401           (run-hook-with-args 'gnus-summary-article-move-hook
9402                               action
9403                               (gnus-data-header
9404                                (assoc article (gnus-data-list nil)))
9405                               gnus-newsgroup-name
9406                               to-newsgroup
9407                               select-method))
9408
9409         ;;;!!!Why is this necessary?
9410         (set-buffer gnus-summary-buffer)
9411         
9412         (gnus-summary-goto-subject article)
9413         (when (eq action 'move)
9414           (gnus-summary-mark-article article gnus-canceled-mark))))
9415       (push article articles-to-update-marks))
9416
9417     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9418     ;; Re-activate all groups that have been moved to.
9419     (save-excursion
9420       (set-buffer gnus-group-buffer)
9421       (let ((gnus-group-marked to-groups))
9422         (gnus-group-get-new-news-this-group nil t)))
9423     
9424     (gnus-kill-buffer copy-buf)
9425     (gnus-summary-position-point)
9426     (gnus-set-mode-line 'summary)))
9427
9428 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9429   "Copy the current article to some other group.
9430 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9431 When called interactively, if TO-NEWSGROUP is nil, use the value of
9432 the variable `gnus-move-split-methods' for finding a default target
9433 newsgroup.
9434 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9435 re-spool using this method."
9436   (interactive "P")
9437   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9438
9439 (defun gnus-summary-crosspost-article (&optional n)
9440   "Crosspost the current article to some other group."
9441   (interactive "P")
9442   (gnus-summary-move-article n nil nil 'crosspost))
9443
9444 (defcustom gnus-summary-respool-default-method nil
9445   "Default method type for respooling an article.
9446 If nil, use to the current newsgroup method."
9447   :type 'symbol
9448   :group 'gnus-summary-mail)
9449
9450 (defcustom gnus-summary-display-while-building nil
9451   "If non-nil, show and update the summary buffer as it's being built.
9452 If the value is t, update the buffer after every line is inserted.  If
9453 the value is an integer (N), update the display every N lines."
9454   :version "22.1"
9455   :group 'gnus-thread
9456   :type '(choice (const :tag "off" nil)
9457                  number
9458                  (const :tag "frequently" t)))
9459
9460 (defun gnus-summary-respool-article (&optional n method)
9461   "Respool the current article.
9462 The article will be squeezed through the mail spooling process again,
9463 which means that it will be put in some mail newsgroup or other
9464 depending on `nnmail-split-methods'.
9465 If N is a positive number, respool the N next articles.
9466 If N is a negative number, respool the N previous articles.
9467 If N is nil and any articles have been marked with the process mark,
9468 respool those articles instead.
9469
9470 Respooling can be done both from mail groups and \"real\" newsgroups.
9471 In the former case, the articles in question will be moved from the
9472 current group into whatever groups they are destined to.  In the
9473 latter case, they will be copied into the relevant groups."
9474   (interactive
9475    (list current-prefix-arg
9476          (let* ((methods (gnus-methods-using 'respool))
9477                 (methname
9478                  (symbol-name (or gnus-summary-respool-default-method
9479                                   (car (gnus-find-method-for-group
9480                                         gnus-newsgroup-name)))))
9481                 (method
9482                  (gnus-completing-read-with-default
9483                   methname "What backend do you want to use when respooling?"
9484                   methods nil t nil 'gnus-mail-method-history))
9485                 ms)
9486            (cond
9487             ((zerop (length (setq ms (gnus-servers-using-backend
9488                                       (intern method)))))
9489              (list (intern method) ""))
9490             ((= 1 (length ms))
9491              (car ms))
9492             (t
9493              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9494                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9495                            ms-alist))))))))
9496   (unless method
9497     (error "No method given for respooling"))
9498   (if (assoc (symbol-name
9499               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9500              (gnus-methods-using 'respool))
9501       (gnus-summary-move-article n nil method)
9502     (gnus-summary-copy-article n nil method)))
9503
9504 (defun gnus-summary-import-article (file &optional edit)
9505   "Import an arbitrary file into a mail newsgroup."
9506   (interactive "fImport file: \nP")
9507   (let ((group gnus-newsgroup-name)
9508         (now (current-time))
9509         atts lines group-art)
9510     (unless (gnus-check-backend-function 'request-accept-article group)
9511       (error "%s does not support article importing" group))
9512     (or (file-readable-p file)
9513         (not (file-regular-p file))
9514         (error "Can't read %s" file))
9515     (save-excursion
9516       (set-buffer (gnus-get-buffer-create " *import file*"))
9517       (erase-buffer)
9518       (nnheader-insert-file-contents file)
9519       (goto-char (point-min))
9520       (if (nnheader-article-p)
9521           (save-restriction
9522             (goto-char (point-min))
9523             (search-forward "\n\n" nil t)
9524             (narrow-to-region (point-min) (1- (point)))
9525             (goto-char (point-min))
9526             (unless (re-search-forward "^date:" nil t)
9527               (goto-char (point-max))
9528               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9529         ;; This doesn't look like an article, so we fudge some headers.
9530         (setq atts (file-attributes file)
9531               lines (count-lines (point-min) (point-max)))
9532         (insert "From: " (read-string "From: ") "\n"
9533                 "Subject: " (read-string "Subject: ") "\n"
9534                 "Date: " (message-make-date (nth 5 atts)) "\n"
9535                 "Message-ID: " (message-make-message-id) "\n"
9536                 "Lines: " (int-to-string lines) "\n"
9537                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9538       (setq group-art (gnus-request-accept-article group nil t))
9539       (kill-buffer (current-buffer)))
9540     (setq gnus-newsgroup-active (gnus-activate-group group))
9541     (forward-line 1)
9542     (gnus-summary-goto-article (cdr group-art) nil t)
9543     (when edit
9544       (gnus-summary-edit-article))))
9545
9546 (defun gnus-summary-create-article ()
9547   "Create an article in a mail newsgroup."
9548   (interactive)
9549   (let ((group gnus-newsgroup-name)
9550         (now (current-time))
9551         group-art)
9552     (unless (gnus-check-backend-function 'request-accept-article group)
9553       (error "%s does not support article importing" group))
9554     (save-excursion
9555       (set-buffer (gnus-get-buffer-create " *import file*"))
9556       (erase-buffer)
9557       (goto-char (point-min))
9558       ;; This doesn't look like an article, so we fudge some headers.
9559       (insert "From: " (read-string "From: ") "\n"
9560               "Subject: " (read-string "Subject: ") "\n"
9561               "Date: " (message-make-date now) "\n"
9562               "Message-ID: " (message-make-message-id) "\n")
9563       (setq group-art (gnus-request-accept-article group nil t))
9564       (kill-buffer (current-buffer)))
9565     (setq gnus-newsgroup-active (gnus-activate-group group))
9566     (forward-line 1)
9567     (gnus-summary-goto-article (cdr group-art) nil t)
9568     (gnus-summary-edit-article)))
9569
9570 (defun gnus-summary-article-posted-p ()
9571   "Say whether the current (mail) article is available from news as well.
9572 This will be the case if the article has both been mailed and posted."
9573   (interactive)
9574   (let ((id (mail-header-references (gnus-summary-article-header)))
9575         (gnus-override-method (car (gnus-refer-article-methods))))
9576     (if (gnus-request-head id "")
9577         (gnus-message 2 "The current message was found on %s"
9578                       gnus-override-method)
9579       (gnus-message 2 "The current message couldn't be found on %s"
9580                     gnus-override-method)
9581       nil)))
9582
9583 (defun gnus-summary-expire-articles (&optional now)
9584   "Expire all articles that are marked as expirable in the current group."
9585   (interactive)
9586   (when (and (not gnus-group-is-exiting-without-update-p)
9587              (gnus-check-backend-function
9588               'request-expire-articles gnus-newsgroup-name))
9589     ;; This backend supports expiry.
9590     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9591            (expirable (if total
9592                           (progn
9593                             ;; We need to update the info for
9594                             ;; this group for `gnus-list-of-read-articles'
9595                             ;; to give us the right answer.
9596                             (gnus-run-hooks 'gnus-exit-group-hook)
9597                             (gnus-summary-update-info)
9598                             (gnus-list-of-read-articles gnus-newsgroup-name))
9599                         (setq gnus-newsgroup-expirable
9600                               (sort gnus-newsgroup-expirable '<))))
9601            (expiry-wait (if now 'immediate
9602                           (gnus-group-find-parameter
9603                            gnus-newsgroup-name 'expiry-wait)))
9604            (nnmail-expiry-target
9605             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9606                 nnmail-expiry-target))
9607            es)
9608       (when expirable
9609         ;; There are expirable articles in this group, so we run them
9610         ;; through the expiry process.
9611         (gnus-message 6 "Expiring articles...")
9612         (unless (gnus-check-group gnus-newsgroup-name)
9613           (error "Can't open server for %s" gnus-newsgroup-name))
9614         ;; The list of articles that weren't expired is returned.
9615         (save-excursion
9616           (if expiry-wait
9617               (let ((nnmail-expiry-wait-function nil)
9618                     (nnmail-expiry-wait expiry-wait))
9619                 (setq es (gnus-request-expire-articles
9620                           expirable gnus-newsgroup-name)))
9621             (setq es (gnus-request-expire-articles
9622                       expirable gnus-newsgroup-name)))
9623           (unless total
9624             (setq gnus-newsgroup-expirable es))
9625           ;; We go through the old list of expirable, and mark all
9626           ;; really expired articles as nonexistent.
9627           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9628             (let ((gnus-use-cache nil))
9629               (dolist (article expirable)
9630                 (when (and (not (memq article es))
9631                            (gnus-data-find article))
9632                   (gnus-summary-mark-article article gnus-canceled-mark)
9633                   (run-hook-with-args 'gnus-summary-article-expire-hook
9634                                       'delete
9635                                       (gnus-data-header
9636                                        (assoc article (gnus-data-list nil)))
9637                                       gnus-newsgroup-name
9638                                       nil
9639                                       nil))))))
9640         (gnus-message 6 "Expiring articles...done")))))
9641
9642 (defun gnus-summary-expire-articles-now ()
9643   "Expunge all expirable articles in the current group.
9644 This means that *all* articles that are marked as expirable will be
9645 deleted forever, right now."
9646   (interactive)
9647   (or gnus-expert-user
9648       (gnus-yes-or-no-p
9649        "Are you really, really, really sure you want to delete all these messages? ")
9650       (error "Phew!"))
9651   (gnus-summary-expire-articles t))
9652
9653 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9654 (defun gnus-summary-delete-article (&optional n)
9655   "Delete the N next (mail) articles.
9656 This command actually deletes articles.  This is not a marking
9657 command.  The article will disappear forever from your life, never to
9658 return.
9659
9660 If N is negative, delete backwards.
9661 If N is nil and articles have been marked with the process mark,
9662 delete these instead.
9663
9664 If `gnus-novice-user' is non-nil you will be asked for
9665 confirmation before the articles are deleted."
9666   (interactive "P")
9667   (unless (gnus-check-backend-function 'request-expire-articles
9668                                        gnus-newsgroup-name)
9669     (error "The current newsgroup does not support article deletion"))
9670   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9671     (error "Couldn't open server"))
9672   ;; Compute the list of articles to delete.
9673   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9674         (nnmail-expiry-target 'delete)
9675         not-deleted)
9676     (if (and gnus-novice-user
9677              (not (gnus-yes-or-no-p
9678                    (format "Do you really want to delete %s forever? "
9679                            (if (> (length articles) 1)
9680                                (format "these %s articles" (length articles))
9681                              "this article")))))
9682         ()
9683       ;; Delete the articles.
9684       (setq not-deleted (gnus-request-expire-articles
9685                          articles gnus-newsgroup-name 'force))
9686       (while articles
9687         (gnus-summary-remove-process-mark (car articles))
9688         ;; The backend might not have been able to delete the article
9689         ;; after all.
9690         (unless (memq (car articles) not-deleted)
9691           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9692         (let* ((article (car articles))
9693                (ghead  (gnus-data-header
9694                                     (assoc article (gnus-data-list nil)))))
9695           (run-hook-with-args 'gnus-summary-article-delete-hook
9696                               'delete ghead gnus-newsgroup-name nil
9697                               nil))
9698         (setq articles (cdr articles)))
9699       (when not-deleted
9700         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9701     (gnus-summary-position-point)
9702     (gnus-set-mode-line 'summary)
9703     not-deleted))
9704
9705 (defun gnus-summary-edit-article (&optional force)
9706   "Edit the current article.
9707 This will have permanent effect only in mail groups.
9708 If FORCE is non-nil, allow editing of articles even in read-only
9709 groups."
9710   (interactive "P")
9711   (save-excursion
9712     (set-buffer gnus-summary-buffer)
9713     (let ((mail-parse-charset gnus-newsgroup-charset)
9714           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9715       (gnus-set-global-variables)
9716       (when (and (not force)
9717                  (gnus-group-read-only-p))
9718         (error "The current newsgroup does not support article editing"))
9719       (gnus-summary-show-article t)
9720       (gnus-article-edit-article
9721        'ignore
9722        `(lambda (no-highlight)
9723           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9724                 (message-options message-options)
9725                 (message-options-set-recipient)
9726                 (mail-parse-ignored-charsets
9727                  ',gnus-newsgroup-ignored-charsets))
9728             (gnus-summary-edit-article-done
9729              ,(or (mail-header-references gnus-current-headers) "")
9730              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9731
9732 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9733
9734 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9735                                                  no-highlight)
9736   "Make edits to the current article permanent."
9737   (interactive)
9738   (save-excursion
9739     ;; The buffer restriction contains the entire article if it exists.
9740     (when (article-goto-body)
9741       (let ((lines (count-lines (point) (point-max)))
9742             (length (- (point-max) (point)))
9743             (case-fold-search t)
9744             (body (copy-marker (point))))
9745         (goto-char (point-min))
9746         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9747           (delete-region (match-beginning 1) (match-end 1))
9748           (insert (number-to-string length)))
9749         (goto-char (point-min))
9750         (when (re-search-forward
9751                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9752           (delete-region (match-beginning 1) (match-end 1))
9753           (insert (number-to-string length)))
9754         (goto-char (point-min))
9755         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9756           (delete-region (match-beginning 1) (match-end 1))
9757           (insert (number-to-string lines))))))
9758   ;; Replace the article.
9759   (let ((buf (current-buffer)))
9760     (with-temp-buffer
9761       (insert-buffer-substring buf)
9762
9763       (if (and (not read-only)
9764                (not (gnus-request-replace-article
9765                      (cdr gnus-article-current) (car gnus-article-current)
9766                      (current-buffer) t)))
9767           (error "Couldn't replace article")
9768         ;; Update the summary buffer.
9769         (if (and references
9770                  (equal (message-tokenize-header references " ")
9771                         (message-tokenize-header
9772                          (or (message-fetch-field "references") "") " ")))
9773             ;; We only have to update this line.
9774             (save-excursion
9775               (save-restriction
9776                 (message-narrow-to-head)
9777                 (let ((head (buffer-string))
9778                       header)
9779                   (with-temp-buffer
9780                     (insert (format "211 %d Article retrieved.\n"
9781                                     (cdr gnus-article-current)))
9782                     (insert head)
9783                     (insert ".\n")
9784                     (let ((nntp-server-buffer (current-buffer)))
9785                       (setq header (car (gnus-get-newsgroup-headers
9786                                          nil t))))
9787                     (save-excursion
9788                       (set-buffer gnus-summary-buffer)
9789                       (gnus-data-set-header
9790                        (gnus-data-find (cdr gnus-article-current))
9791                        header)
9792                       (gnus-summary-update-article-line
9793                        (cdr gnus-article-current) header)
9794                       (if (gnus-summary-goto-subject
9795                            (cdr gnus-article-current) nil t)
9796                           (gnus-summary-update-secondary-mark
9797                            (cdr gnus-article-current))))))))
9798           ;; Update threads.
9799           (set-buffer (or buffer gnus-summary-buffer))
9800           (gnus-summary-update-article (cdr gnus-article-current))
9801           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9802               (gnus-summary-update-secondary-mark
9803                (cdr gnus-article-current))))
9804         ;; Prettify the article buffer again.
9805         (unless no-highlight
9806           (save-excursion
9807             (set-buffer gnus-article-buffer)
9808             ;;;!!! Fix this -- article should be rehighlighted.
9809             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9810             (set-buffer gnus-original-article-buffer)
9811             (gnus-request-article
9812              (cdr gnus-article-current)
9813              (car gnus-article-current) (current-buffer))))
9814         ;; Prettify the summary buffer line.
9815         (when (gnus-visual-p 'summary-highlight 'highlight)
9816           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9817
9818 (defun gnus-summary-edit-wash (key)
9819   "Perform editing command KEY in the article buffer."
9820   (interactive
9821    (list
9822     (progn
9823       (message "%s" (concat (this-command-keys) "- "))
9824       (read-char))))
9825   (message "")
9826   (gnus-summary-edit-article)
9827   (execute-kbd-macro (concat (this-command-keys) key))
9828   (gnus-article-edit-done))
9829
9830 ;;; Respooling
9831
9832 (defun gnus-summary-respool-query (&optional silent trace)
9833   "Query where the respool algorithm would put this article."
9834   (interactive)
9835   (let (gnus-mark-article-hook)
9836     (gnus-summary-select-article)
9837     (save-excursion
9838       (set-buffer gnus-original-article-buffer)
9839       (let ((groups (nnmail-article-group 'identity trace)))
9840         (unless silent
9841           (if groups
9842               (message "This message would go to %s"
9843                        (mapconcat 'car groups ", "))
9844             (message "This message would go to no groups"))
9845           groups)))))
9846
9847 (defun gnus-summary-respool-trace ()
9848   "Trace where the respool algorithm would put this article.
9849 Display a buffer showing all fancy splitting patterns which matched."
9850   (interactive)
9851   (gnus-summary-respool-query nil t))
9852
9853 ;; Summary marking commands.
9854
9855 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9856   "Mark articles which has the same subject as read, and then select the next.
9857 If UNMARK is positive, remove any kind of mark.
9858 If UNMARK is negative, tick articles."
9859   (interactive "P")
9860   (when unmark
9861     (setq unmark (prefix-numeric-value unmark)))
9862   (let ((count
9863          (gnus-summary-mark-same-subject
9864           (gnus-summary-article-subject) unmark)))
9865     ;; Select next unread article.  If auto-select-same mode, should
9866     ;; select the first unread article.
9867     (gnus-summary-next-article t (and gnus-auto-select-same
9868                                       (gnus-summary-article-subject)))
9869     (gnus-message 7 "%d article%s marked as %s"
9870                   count (if (= count 1) " is" "s are")
9871                   (if unmark "unread" "read"))))
9872
9873 (defun gnus-summary-kill-same-subject (&optional unmark)
9874   "Mark articles which has the same subject as read.
9875 If UNMARK is positive, remove any kind of mark.
9876 If UNMARK is negative, tick articles."
9877   (interactive "P")
9878   (when unmark
9879     (setq unmark (prefix-numeric-value unmark)))
9880   (let ((count
9881          (gnus-summary-mark-same-subject
9882           (gnus-summary-article-subject) unmark)))
9883     ;; If marked as read, go to next unread subject.
9884     (when (null unmark)
9885       ;; Go to next unread subject.
9886       (gnus-summary-next-subject 1 t))
9887     (gnus-message 7 "%d articles are marked as %s"
9888                   count (if unmark "unread" "read"))))
9889
9890 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9891   "Mark articles with same SUBJECT as read, and return marked number.
9892 If optional argument UNMARK is positive, remove any kinds of marks.
9893 If optional argument UNMARK is negative, mark articles as unread instead."
9894   (let ((count 1))
9895     (save-excursion
9896       (cond
9897        ((null unmark)                   ; Mark as read.
9898         (while (and
9899                 (progn
9900                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9901                   (gnus-summary-show-thread) t)
9902                 (gnus-summary-find-subject subject))
9903           (setq count (1+ count))))
9904        ((> unmark 0)                    ; Tick.
9905         (while (and
9906                 (progn
9907                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9908                   (gnus-summary-show-thread) t)
9909                 (gnus-summary-find-subject subject))
9910           (setq count (1+ count))))
9911        (t                               ; Mark as unread.
9912         (while (and
9913                 (progn
9914                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9915                   (gnus-summary-show-thread) t)
9916                 (gnus-summary-find-subject subject))
9917           (setq count (1+ count)))))
9918       (gnus-set-mode-line 'summary)
9919       ;; Return the number of marked articles.
9920       count)))
9921
9922 (defun gnus-summary-mark-as-processable (n &optional unmark)
9923   "Set the process mark on the next N articles.
9924 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9925 the process mark instead.  The difference between N and the actual
9926 number of articles marked is returned."
9927   (interactive "P")
9928   (if (and (null n) (gnus-region-active-p))
9929       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9930     (setq n (prefix-numeric-value n))
9931     (let ((backward (< n 0))
9932           (n (abs n)))
9933       (while (and
9934               (> n 0)
9935               (if unmark
9936                   (gnus-summary-remove-process-mark
9937                    (gnus-summary-article-number))
9938                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9939               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9940         (setq n (1- n)))
9941       (when (/= 0 n)
9942         (gnus-message 7 "No more articles"))
9943       (gnus-summary-recenter)
9944       (gnus-summary-position-point)
9945       n)))
9946
9947 (defun gnus-summary-unmark-as-processable (n)
9948   "Remove the process mark from the next N articles.
9949 If N is negative, unmark backward instead.  The difference between N and
9950 the actual number of articles unmarked is returned."
9951   (interactive "P")
9952   (gnus-summary-mark-as-processable n t))
9953
9954 (defun gnus-summary-unmark-all-processable ()
9955   "Remove the process mark from all articles."
9956   (interactive)
9957   (save-excursion
9958     (while gnus-newsgroup-processable
9959       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9960   (gnus-summary-position-point))
9961
9962 (defun gnus-summary-add-mark (article type)
9963   "Mark ARTICLE with a mark of TYPE."
9964   (let ((vtype (car (assq type gnus-article-mark-lists)))
9965         var)
9966     (if (not vtype)
9967         (error "No such mark type: %s" type)
9968       (setq var (intern (format "gnus-newsgroup-%s" type)))
9969       (set var (cons article (symbol-value var)))
9970       (if (memq type '(processable cached replied forwarded recent saved))
9971           (gnus-summary-update-secondary-mark article)
9972         ;;; !!! This is bogus.  We should find out what primary
9973         ;;; !!! mark we want to set.
9974         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9975
9976 (defun gnus-summary-mark-as-expirable (n)
9977   "Mark N articles forward as expirable.
9978 If N is negative, mark backward instead.  The difference between N and
9979 the actual number of articles marked is returned."
9980   (interactive "p")
9981   (gnus-summary-mark-forward n gnus-expirable-mark))
9982
9983 (defun gnus-summary-mark-as-spam (n)
9984   "Mark N articles forward as spam.
9985 If N is negative, mark backward instead.  The difference between N and
9986 the actual number of articles marked is returned."
9987   (interactive "p")
9988   (gnus-summary-mark-forward n gnus-spam-mark))
9989
9990 (defun gnus-summary-mark-article-as-replied (article)
9991   "Mark ARTICLE as replied to and update the summary line.
9992 ARTICLE can also be a list of articles."
9993   (interactive (list (gnus-summary-article-number)))
9994   (let ((articles (if (listp article) article (list article))))
9995     (dolist (article articles)
9996       (unless (numberp article)
9997         (error "%s is not a number" article))
9998       (push article gnus-newsgroup-replied)
9999       (let ((buffer-read-only nil))
10000         (when (gnus-summary-goto-subject article nil t)
10001           (gnus-summary-update-secondary-mark article))))))
10002
10003 (defun gnus-summary-mark-article-as-forwarded (article)
10004   "Mark ARTICLE as forwarded and update the summary line.
10005 ARTICLE can also be a list of articles."
10006   (let ((articles (if (listp article) article (list article))))
10007     (dolist (article articles)
10008       (push article gnus-newsgroup-forwarded)
10009       (let ((buffer-read-only nil))
10010         (when (gnus-summary-goto-subject article nil t)
10011           (gnus-summary-update-secondary-mark article))))))
10012
10013 (defun gnus-summary-set-bookmark (article)
10014   "Set a bookmark in current article."
10015   (interactive (list (gnus-summary-article-number)))
10016   (when (or (not (get-buffer gnus-article-buffer))
10017             (not gnus-current-article)
10018             (not gnus-article-current)
10019             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10020     (error "No current article selected"))
10021   ;; Remove old bookmark, if one exists.
10022   (gnus-pull article gnus-newsgroup-bookmarks)
10023   ;; Set the new bookmark, which is on the form
10024   ;; (article-number . line-number-in-body).
10025   (push
10026    (cons article
10027          (with-current-buffer gnus-article-buffer
10028            (count-lines
10029             (min (point)
10030                  (save-excursion
10031                    (article-goto-body)
10032                    (point)))
10033             (point))))
10034    gnus-newsgroup-bookmarks)
10035   (gnus-message 6 "A bookmark has been added to the current article."))
10036
10037 (defun gnus-summary-remove-bookmark (article)
10038   "Remove the bookmark from the current article."
10039   (interactive (list (gnus-summary-article-number)))
10040   ;; Remove old bookmark, if one exists.
10041   (if (not (assq article gnus-newsgroup-bookmarks))
10042       (gnus-message 6 "No bookmark in current article.")
10043     (gnus-pull article gnus-newsgroup-bookmarks)
10044     (gnus-message 6 "Removed bookmark.")))
10045
10046 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10047 (defun gnus-summary-mark-as-dormant (n)
10048   "Mark N articles forward as dormant.
10049 If N is negative, mark backward instead.  The difference between N and
10050 the actual number of articles marked is returned."
10051   (interactive "p")
10052   (gnus-summary-mark-forward n gnus-dormant-mark))
10053
10054 (defun gnus-summary-set-process-mark (article)
10055   "Set the process mark on ARTICLE and update the summary line."
10056   (setq gnus-newsgroup-processable
10057         (cons article
10058               (delq article gnus-newsgroup-processable)))
10059   (when (gnus-summary-goto-subject article)
10060     (gnus-summary-show-thread)
10061     (gnus-summary-goto-subject article)
10062     (gnus-summary-update-secondary-mark article)))
10063
10064 (defun gnus-summary-remove-process-mark (&rest articles)
10065   "Remove the process mark from ARTICLES and update the summary line."
10066   (dolist (article articles)
10067     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10068     (when (gnus-summary-goto-subject article)
10069       (gnus-summary-show-thread)
10070       (gnus-summary-goto-subject article)
10071       (gnus-summary-update-secondary-mark article))))
10072
10073 (defun gnus-summary-set-saved-mark (article)
10074   "Set the process mark on ARTICLE and update the summary line."
10075   (push article gnus-newsgroup-saved)
10076   (when (gnus-summary-goto-subject article)
10077     (gnus-summary-update-secondary-mark article)))
10078
10079 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10080   "Mark N articles as read forwards.
10081 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10082 The difference between N and the actual number of articles marked is
10083 returned.
10084 If NO-EXPIRE, auto-expiry will be inhibited."
10085   (interactive "p")
10086   (gnus-summary-show-thread)
10087   (let ((backward (< n 0))
10088         (gnus-summary-goto-unread
10089          (and gnus-summary-goto-unread
10090               (not (eq gnus-summary-goto-unread 'never))
10091               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10092                                     gnus-ticked-mark gnus-dormant-mark)))))
10093         (n (abs n))
10094         (mark (or mark gnus-del-mark)))
10095     (while (and (> n 0)
10096                 (gnus-summary-mark-article nil mark no-expire)
10097                 (zerop (gnus-summary-next-subject
10098                         (if backward -1 1)
10099                         (and gnus-summary-goto-unread
10100                              (not (eq gnus-summary-goto-unread 'never)))
10101                         t)))
10102       (setq n (1- n)))
10103     (when (/= 0 n)
10104       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10105     (gnus-summary-recenter)
10106     (gnus-summary-position-point)
10107     (gnus-set-mode-line 'summary)
10108     n))
10109
10110 (defun gnus-summary-mark-article-as-read (mark)
10111   "Mark the current article quickly as read with MARK."
10112   (let ((article (gnus-summary-article-number)))
10113     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10114     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10115     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10116     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10117     (push (cons article mark) gnus-newsgroup-reads)
10118     ;; Possibly remove from cache, if that is used.
10119     (when gnus-use-cache
10120       (gnus-cache-enter-remove-article article))
10121     ;; Allow the backend to change the mark.
10122     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10123     ;; Check for auto-expiry.
10124     (when (and gnus-newsgroup-auto-expire
10125                (memq mark gnus-auto-expirable-marks))
10126       (setq mark gnus-expirable-mark)
10127       ;; Let the backend know about the mark change.
10128       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10129       (push article gnus-newsgroup-expirable))
10130     ;; Set the mark in the buffer.
10131     (gnus-summary-update-mark mark 'unread)
10132     t))
10133
10134 (defun gnus-summary-mark-article-as-unread (mark)
10135   "Mark the current article quickly as unread with MARK."
10136   (let* ((article (gnus-summary-article-number))
10137          (old-mark (gnus-summary-article-mark article)))
10138     ;; Allow the backend to change the mark.
10139     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10140     (if (eq mark old-mark)
10141         t
10142       (if (<= article 0)
10143           (progn
10144             (gnus-error 1 "Can't mark negative article numbers")
10145             nil)
10146         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10147         (setq gnus-newsgroup-spam-marked
10148               (delq article gnus-newsgroup-spam-marked))
10149         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10150         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10151         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10152         (cond ((= mark gnus-ticked-mark)
10153                (setq gnus-newsgroup-marked
10154                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10155                                               article)))
10156               ((= mark gnus-spam-mark)
10157                (setq gnus-newsgroup-spam-marked
10158                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10159                                               article)))
10160               ((= mark gnus-dormant-mark)
10161                (setq gnus-newsgroup-dormant
10162                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10163                                               article)))
10164               (t
10165                (setq gnus-newsgroup-unreads
10166                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10167                                               article))))
10168         (gnus-pull article gnus-newsgroup-reads)
10169
10170         ;; See whether the article is to be put in the cache.
10171         (and gnus-use-cache
10172              (vectorp (gnus-summary-article-header article))
10173              (save-excursion
10174                (gnus-cache-possibly-enter-article
10175                 gnus-newsgroup-name article
10176                 (gnus-summary-article-header article)
10177                 (= mark gnus-ticked-mark)
10178                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10179
10180         ;; Fix the mark.
10181         (gnus-summary-update-mark mark 'unread)
10182         t))))
10183
10184 (defun gnus-summary-mark-article (&optional article mark no-expire)
10185   "Mark ARTICLE with MARK.  MARK can be any character.
10186 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10187 `??' (dormant) and `?E' (expirable).
10188 If MARK is nil, then the default character `?r' is used.
10189 If ARTICLE is nil, then the article on the current line will be
10190 marked.
10191 If NO-EXPIRE, auto-expiry will be inhibited."
10192   ;; The mark might be a string.
10193   (when (stringp mark)
10194     (setq mark (aref mark 0)))
10195   ;; If no mark is given, then we check auto-expiring.
10196   (when (null mark)
10197     (setq mark gnus-del-mark))
10198   (when (and (not no-expire)
10199              gnus-newsgroup-auto-expire
10200              (memq mark gnus-auto-expirable-marks))
10201     (setq mark gnus-expirable-mark))
10202   (let ((article (or article (gnus-summary-article-number)))
10203         (old-mark (gnus-summary-article-mark article)))
10204     ;; Allow the backend to change the mark.
10205     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10206     (if (eq mark old-mark)
10207         t
10208       (unless article
10209         (error "No article on current line"))
10210       (if (not (if (or (= mark gnus-unread-mark)
10211                        (= mark gnus-ticked-mark)
10212                        (= mark gnus-spam-mark)
10213                        (= mark gnus-dormant-mark))
10214                    (gnus-mark-article-as-unread article mark)
10215                  (gnus-mark-article-as-read article mark)))
10216           t
10217         ;; See whether the article is to be put in the cache.
10218         (and gnus-use-cache
10219              (not (= mark gnus-canceled-mark))
10220              (vectorp (gnus-summary-article-header article))
10221              (save-excursion
10222                (gnus-cache-possibly-enter-article
10223                 gnus-newsgroup-name article
10224                 (gnus-summary-article-header article)
10225                 (= mark gnus-ticked-mark)
10226                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10227
10228         (when (gnus-summary-goto-subject article nil t)
10229           (let ((buffer-read-only nil))
10230             (gnus-summary-show-thread)
10231             ;; Fix the mark.
10232             (gnus-summary-update-mark mark 'unread)
10233             t))))))
10234
10235 (defun gnus-summary-update-secondary-mark (article)
10236   "Update the secondary (read, process, cache) mark."
10237   (gnus-summary-update-mark
10238    (cond ((memq article gnus-newsgroup-processable)
10239           gnus-process-mark)
10240          ((memq article gnus-newsgroup-cached)
10241           gnus-cached-mark)
10242          ((memq article gnus-newsgroup-replied)
10243           gnus-replied-mark)
10244          ((memq article gnus-newsgroup-forwarded)
10245           gnus-forwarded-mark)
10246          ((memq article gnus-newsgroup-saved)
10247           gnus-saved-mark)
10248          ((memq article gnus-newsgroup-recent)
10249           gnus-recent-mark)
10250          ((memq article gnus-newsgroup-unseen)
10251           gnus-unseen-mark)
10252          (t gnus-no-mark))
10253    'replied)
10254   (when (gnus-visual-p 'summary-highlight 'highlight)
10255     (gnus-run-hooks 'gnus-summary-update-hook))
10256   t)
10257
10258 (defun gnus-summary-update-download-mark (article)
10259   "Update the download mark."
10260   (gnus-summary-update-mark
10261    (cond ((memq article gnus-newsgroup-undownloaded)
10262           gnus-undownloaded-mark)
10263          (gnus-newsgroup-agentized
10264           gnus-downloaded-mark)
10265          (t
10266           gnus-no-mark))
10267    'download)
10268   (gnus-summary-update-line t)
10269   t)
10270
10271 (defun gnus-summary-update-mark (mark type)
10272   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10273         (buffer-read-only nil))
10274     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10275     (when forward
10276       (when (looking-at "\r")
10277         (incf forward))
10278       (when (<= (+ forward (point)) (point-max))
10279         ;; Go to the right position on the line.
10280         (goto-char (+ forward (point)))
10281         ;; Replace the old mark with the new mark.
10282         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10283         ;; Optionally update the marks by some user rule.
10284         (when (eq type 'unread)
10285           (gnus-data-set-mark
10286            (gnus-data-find (gnus-summary-article-number)) mark)
10287           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10288
10289 (defun gnus-mark-article-as-read (article &optional mark)
10290   "Enter ARTICLE in the pertinent lists and remove it from others."
10291   ;; Make the article expirable.
10292   (let ((mark (or mark gnus-del-mark)))
10293     (setq gnus-newsgroup-expirable
10294           (if (= mark gnus-expirable-mark)
10295               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10296             (delq article gnus-newsgroup-expirable)))
10297     ;; Remove from unread and marked lists.
10298     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10299     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10300     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10301     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10302     (push (cons article mark) gnus-newsgroup-reads)
10303     ;; Possibly remove from cache, if that is used.
10304     (when gnus-use-cache
10305       (gnus-cache-enter-remove-article article))
10306     t))
10307
10308 (defun gnus-mark-article-as-unread (article &optional mark)
10309   "Enter ARTICLE in the pertinent lists and remove it from others."
10310   (let ((mark (or mark gnus-ticked-mark)))
10311     (if (<= article 0)
10312         (progn
10313           (gnus-error 1 "Can't mark negative article numbers")
10314           nil)
10315       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10316             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10317             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10318             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10319             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10320
10321       ;; Unsuppress duplicates?
10322       (when gnus-suppress-duplicates
10323         (gnus-dup-unsuppress-article article))
10324
10325       (cond ((= mark gnus-ticked-mark)
10326              (setq gnus-newsgroup-marked
10327                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10328             ((= mark gnus-spam-mark)
10329              (setq gnus-newsgroup-spam-marked
10330                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10331                                             article)))
10332             ((= mark gnus-dormant-mark)
10333              (setq gnus-newsgroup-dormant
10334                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10335             (t
10336              (setq gnus-newsgroup-unreads
10337                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10338       (gnus-pull article gnus-newsgroup-reads)
10339       t)))
10340
10341 (defalias 'gnus-summary-mark-as-unread-forward
10342   'gnus-summary-tick-article-forward)
10343 (make-obsolete 'gnus-summary-mark-as-unread-forward
10344                'gnus-summary-tick-article-forward)
10345 (defun gnus-summary-tick-article-forward (n)
10346   "Tick N articles forwards.
10347 If N is negative, tick backwards instead.
10348 The difference between N and the number of articles ticked is returned."
10349   (interactive "p")
10350   (gnus-summary-mark-forward n gnus-ticked-mark))
10351
10352 (defalias 'gnus-summary-mark-as-unread-backward
10353   'gnus-summary-tick-article-backward)
10354 (make-obsolete 'gnus-summary-mark-as-unread-backward
10355                'gnus-summary-tick-article-backward)
10356 (defun gnus-summary-tick-article-backward (n)
10357   "Tick N articles backwards.
10358 The difference between N and the number of articles ticked is returned."
10359   (interactive "p")
10360   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10361
10362 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10363 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10364 (defun gnus-summary-tick-article (&optional article clear-mark)
10365   "Mark current article as unread.
10366 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10367 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10368   (interactive)
10369   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10370                                        gnus-ticked-mark)))
10371
10372 (defun gnus-summary-mark-as-read-forward (n)
10373   "Mark N articles as read forwards.
10374 If N is negative, mark backwards instead.
10375 The difference between N and the actual number of articles marked is
10376 returned."
10377   (interactive "p")
10378   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10379
10380 (defun gnus-summary-mark-as-read-backward (n)
10381   "Mark the N articles as read backwards.
10382 The difference between N and the actual number of articles marked is
10383 returned."
10384   (interactive "p")
10385   (gnus-summary-mark-forward
10386    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10387
10388 (defun gnus-summary-mark-as-read (&optional article mark)
10389   "Mark current article as read.
10390 ARTICLE specifies the article to be marked as read.
10391 MARK specifies a string to be inserted at the beginning of the line."
10392   (gnus-summary-mark-article article mark))
10393
10394 (defun gnus-summary-clear-mark-forward (n)
10395   "Clear marks from N articles forward.
10396 If N is negative, clear backward instead.
10397 The difference between N and the number of marks cleared is returned."
10398   (interactive "p")
10399   (gnus-summary-mark-forward n gnus-unread-mark))
10400
10401 (defun gnus-summary-clear-mark-backward (n)
10402   "Clear marks from N articles backward.
10403 The difference between N and the number of marks cleared is returned."
10404   (interactive "p")
10405   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10406
10407 (defun gnus-summary-mark-unread-as-read ()
10408   "Intended to be used by `gnus-summary-mark-article-hook'."
10409   (when (memq gnus-current-article gnus-newsgroup-unreads)
10410     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10411
10412 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10413   "Intended to be used by `gnus-summary-mark-article-hook'."
10414   (let ((mark (gnus-summary-article-mark)))
10415     (when (or (gnus-unread-mark-p mark)
10416               (gnus-read-mark-p mark))
10417       (gnus-summary-mark-article gnus-current-article
10418                                  (or new-mark gnus-read-mark)))))
10419
10420 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10421   "Intended to be used by `gnus-summary-mark-article-hook'."
10422   (let ((mark (gnus-summary-article-mark)))
10423     (when (or (gnus-unread-mark-p mark)
10424               (gnus-read-mark-p mark))
10425       (gnus-summary-mark-article (gnus-summary-article-number)
10426                                  (or new-mark gnus-read-mark)))))
10427
10428 (defun gnus-summary-mark-unread-as-ticked ()
10429   "Intended to be used by `gnus-summary-mark-article-hook'."
10430   (when (memq gnus-current-article gnus-newsgroup-unreads)
10431     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10432
10433 (defun gnus-summary-mark-region-as-read (point mark all)
10434   "Mark all unread articles between point and mark as read.
10435 If given a prefix, mark all articles between point and mark as read,
10436 even ticked and dormant ones."
10437   (interactive "r\nP")
10438   (save-excursion
10439     (let (article)
10440       (goto-char point)
10441       (beginning-of-line)
10442       (while (and
10443               (< (point) mark)
10444               (progn
10445                 (when (or all
10446                           (memq (setq article (gnus-summary-article-number))
10447                                 gnus-newsgroup-unreads))
10448                   (gnus-summary-mark-article article gnus-del-mark))
10449                 t)
10450               (gnus-summary-find-next))))))
10451
10452 (defun gnus-summary-mark-below (score mark)
10453   "Mark articles with score less than SCORE with MARK."
10454   (interactive "P\ncMark: ")
10455   (setq score (if score
10456                   (prefix-numeric-value score)
10457                 (or gnus-summary-default-score 0)))
10458   (save-excursion
10459     (set-buffer gnus-summary-buffer)
10460     (goto-char (point-min))
10461     (while
10462         (progn
10463           (and (< (gnus-summary-article-score) score)
10464                (gnus-summary-mark-article nil mark))
10465           (gnus-summary-find-next)))))
10466
10467 (defun gnus-summary-kill-below (&optional score)
10468   "Mark articles with score below SCORE as read."
10469   (interactive "P")
10470   (gnus-summary-mark-below score gnus-killed-mark))
10471
10472 (defun gnus-summary-clear-above (&optional score)
10473   "Clear all marks from articles with score above SCORE."
10474   (interactive "P")
10475   (gnus-summary-mark-above score gnus-unread-mark))
10476
10477 (defun gnus-summary-tick-above (&optional score)
10478   "Tick all articles with score above SCORE."
10479   (interactive "P")
10480   (gnus-summary-mark-above score gnus-ticked-mark))
10481
10482 (defun gnus-summary-mark-above (score mark)
10483   "Mark articles with score over SCORE with MARK."
10484   (interactive "P\ncMark: ")
10485   (setq score (if score
10486                   (prefix-numeric-value score)
10487                 (or gnus-summary-default-score 0)))
10488   (save-excursion
10489     (set-buffer gnus-summary-buffer)
10490     (goto-char (point-min))
10491     (while (and (progn
10492                   (when (> (gnus-summary-article-score) score)
10493                     (gnus-summary-mark-article nil mark))
10494                   t)
10495                 (gnus-summary-find-next)))))
10496
10497 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10498 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10499 (defun gnus-summary-limit-include-expunged (&optional no-error)
10500   "Display all the hidden articles that were expunged for low scores."
10501   (interactive)
10502   (let ((buffer-read-only nil))
10503     (let ((scored gnus-newsgroup-scored)
10504           headers h)
10505       (while scored
10506         (unless (gnus-summary-article-header (caar scored))
10507           (and (setq h (gnus-number-to-header (caar scored)))
10508                (< (cdar scored) gnus-summary-expunge-below)
10509                (push h headers)))
10510         (setq scored (cdr scored)))
10511       (if (not headers)
10512           (when (not no-error)
10513             (error "No expunged articles hidden"))
10514         (goto-char (point-min))
10515         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10516         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10517         (mapcar (lambda (x) (push (mail-header-number x)
10518                                   gnus-newsgroup-limit))
10519                 headers)
10520         (gnus-summary-prepare-unthreaded (nreverse headers))
10521         (goto-char (point-min))
10522         (gnus-summary-position-point)
10523         t))))
10524
10525 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10526   "Mark all unread articles in this newsgroup as read.
10527 If prefix argument ALL is non-nil, ticked and dormant articles will
10528 also be marked as read.
10529 If QUIETLY is non-nil, no questions will be asked.
10530
10531 If TO-HERE is non-nil, it should be a point in the buffer.  All
10532 articles before (after, if REVERSE is set) this point will be marked
10533 as read.
10534
10535 Note that this function will only catch up the unread article
10536 in the current summary buffer limitation.
10537
10538 The number of articles marked as read is returned."
10539   (interactive "P")
10540   (prog1
10541       (save-excursion
10542         (when (or quietly
10543                   (not gnus-interactive-catchup) ;Without confirmation?
10544                   gnus-expert-user
10545                   (gnus-y-or-n-p
10546                    (if all
10547                        "Mark absolutely all articles as read? "
10548                      "Mark all unread articles as read? ")))
10549           (if (and not-mark
10550                    (not gnus-newsgroup-adaptive)
10551                    (not gnus-newsgroup-auto-expire)
10552                    (not gnus-suppress-duplicates)
10553                    (or (not gnus-use-cache)
10554                        (eq gnus-use-cache 'passive)))
10555               (progn
10556                 (when all
10557                   (setq gnus-newsgroup-marked nil
10558                         gnus-newsgroup-spam-marked nil
10559                         gnus-newsgroup-dormant nil))
10560                 (setq gnus-newsgroup-unreads
10561                       (gnus-sorted-nunion
10562                        (gnus-intersection gnus-newsgroup-unreads
10563                                           gnus-newsgroup-downloadable)
10564                        gnus-newsgroup-unfetched)))
10565             ;; We actually mark all articles as canceled, which we
10566             ;; have to do when using auto-expiry or adaptive scoring.
10567             (gnus-summary-show-all-threads)
10568             (if (and to-here reverse)
10569                 (progn
10570                   (goto-char to-here)
10571                   (gnus-summary-mark-current-read-and-unread-as-read
10572                    gnus-catchup-mark)
10573                   (while (gnus-summary-find-next (not all))
10574                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10575               (when (gnus-summary-first-subject (not all))
10576                 (while (and
10577                         (if to-here (< (point) to-here) t)
10578                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10579                         (gnus-summary-find-next (not all))))))
10580             (gnus-set-mode-line 'summary))
10581           t))
10582     (gnus-summary-position-point)))
10583
10584 (defun gnus-summary-catchup-to-here (&optional all)
10585   "Mark all unticked articles before the current one as read.
10586 If ALL is non-nil, also mark ticked and dormant articles as read."
10587   (interactive "P")
10588   (save-excursion
10589     (gnus-save-hidden-threads
10590       (let ((beg (point)))
10591         ;; We check that there are unread articles.
10592         (when (or all (gnus-summary-find-prev))
10593           (gnus-summary-catchup all t beg)))))
10594   (gnus-summary-position-point))
10595
10596 (defun gnus-summary-catchup-from-here (&optional all)
10597   "Mark all unticked articles after (and including) the current one as read.
10598 If ALL is non-nil, also mark ticked and dormant articles as read."
10599   (interactive "P")
10600   (save-excursion
10601     (gnus-save-hidden-threads
10602       (let ((beg (point)))
10603         ;; We check that there are unread articles.
10604         (when (or all (gnus-summary-find-next))
10605           (gnus-summary-catchup all t beg nil t)))))
10606   (gnus-summary-position-point))
10607
10608 (defun gnus-summary-catchup-all (&optional quietly)
10609   "Mark all articles in this newsgroup as read.
10610 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10611 instead, which marks only unread articles as read."
10612   (interactive "P")
10613   (gnus-summary-catchup t quietly))
10614
10615 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10616   "Mark all unread articles in this group as read, then exit.
10617 If prefix argument ALL is non-nil, all articles are marked as read.
10618 If QUIETLY is non-nil, no questions will be asked."
10619   (interactive "P")
10620   (when (gnus-summary-catchup all quietly nil 'fast)
10621     ;; Select next newsgroup or exit.
10622     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10623              (eq gnus-auto-select-next 'quietly))
10624         (gnus-summary-next-group nil)
10625       (gnus-summary-exit))))
10626
10627 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10628   "Mark all articles in this newsgroup as read, and then exit.
10629 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10630 instead, which marks only unread articles as read."
10631   (interactive "P")
10632   (gnus-summary-catchup-and-exit t quietly))
10633
10634 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10635   "Mark all articles in this group as read and select the next group.
10636 If given a prefix, mark all articles, unread as well as ticked, as
10637 read."
10638   (interactive "P")
10639   (save-excursion
10640     (gnus-summary-catchup all))
10641   (gnus-summary-next-group))
10642
10643 ;;;
10644 ;;; with article
10645 ;;;
10646
10647 (defmacro gnus-with-article (article &rest forms)
10648   "Select ARTICLE and perform FORMS in the original article buffer.
10649 Then replace the article with the result."
10650   `(progn
10651      ;; We don't want the article to be marked as read.
10652      (let (gnus-mark-article-hook)
10653        (gnus-summary-select-article t t nil ,article))
10654      (set-buffer gnus-original-article-buffer)
10655      ,@forms
10656      (if (not (gnus-check-backend-function
10657                'request-replace-article (car gnus-article-current)))
10658          (gnus-message 5 "Read-only group; not replacing")
10659        (unless (gnus-request-replace-article
10660                 ,article (car gnus-article-current)
10661                 (current-buffer) t)
10662          (error "Couldn't replace article")))
10663      ;; The cache and backlog have to be flushed somewhat.
10664      (when gnus-keep-backlog
10665        (gnus-backlog-remove-article
10666         (car gnus-article-current) (cdr gnus-article-current)))
10667      (when gnus-use-cache
10668        (gnus-cache-update-article
10669         (car gnus-article-current) (cdr gnus-article-current)))))
10670
10671 (put 'gnus-with-article 'lisp-indent-function 1)
10672 (put 'gnus-with-article 'edebug-form-spec '(form body))
10673
10674 ;; Thread-based commands.
10675
10676 (defun gnus-summary-articles-in-thread (&optional article)
10677   "Return a list of all articles in the current thread.
10678 If ARTICLE is non-nil, return all articles in the thread that starts
10679 with that article."
10680   (let* ((article (or article (gnus-summary-article-number)))
10681          (data (gnus-data-find-list article))
10682          (top-level (gnus-data-level (car data)))
10683          (top-subject
10684           (cond ((null gnus-thread-operation-ignore-subject)
10685                  (gnus-simplify-subject-re
10686                   (mail-header-subject (gnus-data-header (car data)))))
10687                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10688                  (gnus-simplify-subject-fuzzy
10689                   (mail-header-subject (gnus-data-header (car data)))))
10690                 (t nil)))
10691          (end-point (save-excursion
10692                       (if (gnus-summary-go-to-next-thread)
10693                           (point) (point-max))))
10694          articles)
10695     (while (and data
10696                 (< (gnus-data-pos (car data)) end-point))
10697       (when (or (not top-subject)
10698                 (string= top-subject
10699                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10700                              (gnus-simplify-subject-fuzzy
10701                               (mail-header-subject
10702                                (gnus-data-header (car data))))
10703                            (gnus-simplify-subject-re
10704                             (mail-header-subject
10705                              (gnus-data-header (car data)))))))
10706         (push (gnus-data-number (car data)) articles))
10707       (unless (and (setq data (cdr data))
10708                    (> (gnus-data-level (car data)) top-level))
10709         (setq data nil)))
10710     ;; Return the list of articles.
10711     (nreverse articles)))
10712
10713 (defun gnus-summary-rethread-current ()
10714   "Rethread the thread the current article is part of."
10715   (interactive)
10716   (let* ((gnus-show-threads t)
10717          (article (gnus-summary-article-number))
10718          (id (mail-header-id (gnus-summary-article-header)))
10719          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10720     (unless id
10721       (error "No article on the current line"))
10722     (gnus-rebuild-thread id)
10723     (gnus-summary-goto-subject article)))
10724
10725 (defun gnus-summary-reparent-thread ()
10726   "Make the current article child of the marked (or previous) article.
10727
10728 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10729 is non-nil or the Subject: of both articles are the same."
10730   (interactive)
10731   (unless (not (gnus-group-read-only-p))
10732     (error "The current newsgroup does not support article editing"))
10733   (unless (<= (length gnus-newsgroup-processable) 1)
10734     (error "No more than one article may be marked"))
10735   (save-window-excursion
10736     (let ((gnus-article-buffer " *reparent*")
10737           (current-article (gnus-summary-article-number))
10738           ;; First grab the marked article, otherwise one line up.
10739           (parent-article (if (not (null gnus-newsgroup-processable))
10740                               (car gnus-newsgroup-processable)
10741                             (save-excursion
10742                               (if (eq (forward-line -1) 0)
10743                                   (gnus-summary-article-number)
10744                                 (error "Beginning of summary buffer"))))))
10745       (unless (not (eq current-article parent-article))
10746         (error "An article may not be self-referential"))
10747       (let ((message-id (mail-header-id
10748                          (gnus-summary-article-header parent-article))))
10749         (unless (and message-id (not (equal message-id "")))
10750           (error "No message-id in desired parent"))
10751         (gnus-with-article current-article
10752           (save-restriction
10753             (goto-char (point-min))
10754             (message-narrow-to-head)
10755             (if (re-search-forward "^References: " nil t)
10756                 (progn
10757                   (re-search-forward "^[^ \t]" nil t)
10758                   (forward-line -1)
10759                   (end-of-line)
10760                   (insert " " message-id))
10761               (insert "References: " message-id "\n"))))
10762         (set-buffer gnus-summary-buffer)
10763         (gnus-summary-unmark-all-processable)
10764         (gnus-summary-update-article current-article)
10765         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10766             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10767         (gnus-summary-rethread-current)
10768         (gnus-message 3 "Article %d is now the child of article %d"
10769                       current-article parent-article)))))
10770
10771 (defun gnus-summary-toggle-threads (&optional arg)
10772   "Toggle showing conversation threads.
10773 If ARG is positive number, turn showing conversation threads on."
10774   (interactive "P")
10775   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10776     (setq gnus-show-threads
10777           (if (null arg) (not gnus-show-threads)
10778             (> (prefix-numeric-value arg) 0)))
10779     (gnus-summary-prepare)
10780     (gnus-summary-goto-subject current)
10781     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10782     (gnus-summary-position-point)))
10783
10784 (defun gnus-summary-show-all-threads ()
10785   "Show all threads."
10786   (interactive)
10787   (save-excursion
10788     (let ((buffer-read-only nil))
10789       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10790   (gnus-summary-position-point))
10791
10792 (defun gnus-summary-show-thread ()
10793   "Show thread subtrees.
10794 Returns nil if no thread was there to be shown."
10795   (interactive)
10796   (let ((buffer-read-only nil)
10797         (orig (point))
10798         (end (point-at-eol))
10799         ;; Leave point at bol
10800         (beg (progn (beginning-of-line) (point))))
10801     (prog1
10802         ;; Any hidden lines here?
10803         (search-forward "\r" end t)
10804       (subst-char-in-region beg end ?\^M ?\n t)
10805       (goto-char orig)
10806       (gnus-summary-position-point))))
10807
10808 (defun gnus-summary-maybe-hide-threads ()
10809   "If requested, hide the threads that should be hidden."
10810   (when (and gnus-show-threads
10811              gnus-thread-hide-subtree)
10812     (gnus-summary-hide-all-threads
10813      (if (or (consp gnus-thread-hide-subtree)
10814              (functionp gnus-thread-hide-subtree))
10815          (gnus-make-predicate gnus-thread-hide-subtree)
10816        nil))))
10817
10818 ;;; Hiding predicates.
10819
10820 (defun gnus-article-unread-p (header)
10821   (memq (mail-header-number header) gnus-newsgroup-unreads))
10822
10823 (defun gnus-article-unseen-p (header)
10824   (memq (mail-header-number header) gnus-newsgroup-unseen))
10825
10826 (defun gnus-map-articles (predicate articles)
10827   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10828   (apply 'gnus-or (mapcar predicate
10829                           (mapcar 'gnus-summary-article-header articles))))
10830
10831 (defun gnus-summary-hide-all-threads (&optional predicate)
10832   "Hide all thread subtrees.
10833 If PREDICATE is supplied, threads that satisfy this predicate
10834 will not be hidden."
10835   (interactive)
10836   (save-excursion
10837     (goto-char (point-min))
10838     (let ((end nil))
10839       (while (not end)
10840         (when (or (not predicate)
10841                   (gnus-map-articles
10842                    predicate (gnus-summary-article-children)))
10843             (gnus-summary-hide-thread))
10844         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10845   (gnus-summary-position-point))
10846
10847 (defun gnus-summary-hide-thread ()
10848   "Hide thread subtrees.
10849 If PREDICATE is supplied, threads that satisfy this predicate
10850 will not be hidden.
10851 Returns nil if no threads were there to be hidden."
10852   (interactive)
10853   (let ((buffer-read-only nil)
10854         (start (point))
10855         (article (gnus-summary-article-number)))
10856     (goto-char start)
10857     ;; Go forward until either the buffer ends or the subthread
10858     ;; ends.
10859     (when (and (not (eobp))
10860                (or (zerop (gnus-summary-next-thread 1 t))
10861                    (goto-char (point-max))))
10862       (prog1
10863           (if (and (> (point) start)
10864                    (search-backward "\n" start t))
10865               (progn
10866                 (subst-char-in-region start (point) ?\n ?\^M)
10867                 (gnus-summary-goto-subject article))
10868             (goto-char start)
10869             nil)))))
10870
10871 (defun gnus-summary-go-to-next-thread (&optional previous)
10872   "Go to the same level (or less) next thread.
10873 If PREVIOUS is non-nil, go to previous thread instead.
10874 Return the article number moved to, or nil if moving was impossible."
10875   (let ((level (gnus-summary-thread-level))
10876         (way (if previous -1 1))
10877         (beg (point)))
10878     (forward-line way)
10879     (while (and (not (eobp))
10880                 (< level (gnus-summary-thread-level)))
10881       (forward-line way))
10882     (if (eobp)
10883         (progn
10884           (goto-char beg)
10885           nil)
10886       (setq beg (point))
10887       (prog1
10888           (gnus-summary-article-number)
10889         (goto-char beg)))))
10890
10891 (defun gnus-summary-next-thread (n &optional silent)
10892   "Go to the same level next N'th thread.
10893 If N is negative, search backward instead.
10894 Returns the difference between N and the number of skips actually
10895 done.
10896
10897 If SILENT, don't output messages."
10898   (interactive "p")
10899   (let ((backward (< n 0))
10900         (n (abs n)))
10901     (while (and (> n 0)
10902                 (gnus-summary-go-to-next-thread backward))
10903       (decf n))
10904     (unless silent
10905       (gnus-summary-position-point))
10906     (when (and (not silent) (/= 0 n))
10907       (gnus-message 7 "No more threads"))
10908     n))
10909
10910 (defun gnus-summary-prev-thread (n)
10911   "Go to the same level previous N'th thread.
10912 Returns the difference between N and the number of skips actually
10913 done."
10914   (interactive "p")
10915   (gnus-summary-next-thread (- n)))
10916
10917 (defun gnus-summary-go-down-thread ()
10918   "Go down one level in the current thread."
10919   (let ((children (gnus-summary-article-children)))
10920     (when children
10921       (gnus-summary-goto-subject (car children)))))
10922
10923 (defun gnus-summary-go-up-thread ()
10924   "Go up one level in the current thread."
10925   (let ((parent (gnus-summary-article-parent)))
10926     (when parent
10927       (gnus-summary-goto-subject parent))))
10928
10929 (defun gnus-summary-down-thread (n)
10930   "Go down thread N steps.
10931 If N is negative, go up instead.
10932 Returns the difference between N and how many steps down that were
10933 taken."
10934   (interactive "p")
10935   (let ((up (< n 0))
10936         (n (abs n)))
10937     (while (and (> n 0)
10938                 (if up (gnus-summary-go-up-thread)
10939                   (gnus-summary-go-down-thread)))
10940       (setq n (1- n)))
10941     (gnus-summary-position-point)
10942     (when (/= 0 n)
10943       (gnus-message 7 "Can't go further"))
10944     n))
10945
10946 (defun gnus-summary-up-thread (n)
10947   "Go up thread N steps.
10948 If N is negative, go down instead.
10949 Returns the difference between N and how many steps down that were
10950 taken."
10951   (interactive "p")
10952   (gnus-summary-down-thread (- n)))
10953
10954 (defun gnus-summary-top-thread ()
10955   "Go to the top of the thread."
10956   (interactive)
10957   (while (gnus-summary-go-up-thread))
10958   (gnus-summary-article-number))
10959
10960 (defun gnus-summary-kill-thread (&optional unmark)
10961   "Mark articles under current thread as read.
10962 If the prefix argument is positive, remove any kinds of marks.
10963 If the prefix argument is negative, tick articles instead."
10964   (interactive "P")
10965   (when unmark
10966     (setq unmark (prefix-numeric-value unmark)))
10967   (let ((articles (gnus-summary-articles-in-thread)))
10968     (save-excursion
10969       ;; Expand the thread.
10970       (gnus-summary-show-thread)
10971       ;; Mark all the articles.
10972       (while articles
10973         (gnus-summary-goto-subject (car articles))
10974         (cond ((null unmark)
10975                (gnus-summary-mark-article-as-read gnus-killed-mark))
10976               ((> unmark 0)
10977                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10978               (t
10979                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10980         (setq articles (cdr articles))))
10981     ;; Hide killed subtrees.
10982     (and (null unmark)
10983          gnus-thread-hide-killed
10984          (gnus-summary-hide-thread))
10985     ;; If marked as read, go to next unread subject.
10986     (when (null unmark)
10987       ;; Go to next unread subject.
10988       (gnus-summary-next-subject 1 t)))
10989   (gnus-set-mode-line 'summary))
10990
10991 ;; Summary sorting commands
10992
10993 (defun gnus-summary-sort-by-number (&optional reverse)
10994   "Sort the summary buffer by article number.
10995 Argument REVERSE means reverse order."
10996   (interactive "P")
10997   (gnus-summary-sort 'number reverse))
10998
10999 (defun gnus-summary-sort-by-random (&optional reverse)
11000   "Randomize the order in the summary buffer.
11001 Argument REVERSE means to randomize in reverse order."
11002   (interactive "P")
11003   (gnus-summary-sort 'random reverse))
11004
11005 (defun gnus-summary-sort-by-author (&optional reverse)
11006   "Sort the summary buffer by author name alphabetically.
11007 If `case-fold-search' is non-nil, case of letters is ignored.
11008 Argument REVERSE means reverse order."
11009   (interactive "P")
11010   (gnus-summary-sort 'author reverse))
11011
11012 (defun gnus-summary-sort-by-recipient (&optional reverse)
11013   "Sort the summary buffer by recipient name alphabetically.
11014 If `case-fold-search' is non-nil, case of letters is ignored.
11015 Argument REVERSE means reverse order."
11016   (interactive "P")
11017   (gnus-summary-sort 'recipient reverse))
11018
11019 (defun gnus-summary-sort-by-subject (&optional reverse)
11020   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11021 If `case-fold-search' is non-nil, case of letters is ignored.
11022 Argument REVERSE means reverse order."
11023   (interactive "P")
11024   (gnus-summary-sort 'subject reverse))
11025
11026 (defun gnus-summary-sort-by-date (&optional reverse)
11027   "Sort the summary buffer by date.
11028 Argument REVERSE means reverse order."
11029   (interactive "P")
11030   (gnus-summary-sort 'date reverse))
11031
11032 (defun gnus-summary-sort-by-score (&optional reverse)
11033   "Sort the summary buffer by score.
11034 Argument REVERSE means reverse order."
11035   (interactive "P")
11036   (gnus-summary-sort 'score reverse))
11037
11038 (defun gnus-summary-sort-by-lines (&optional reverse)
11039   "Sort the summary buffer by the number of lines.
11040 Argument REVERSE means reverse order."
11041   (interactive "P")
11042   (gnus-summary-sort 'lines reverse))
11043
11044 (defun gnus-summary-sort-by-chars (&optional reverse)
11045   "Sort the summary buffer by article length.
11046 Argument REVERSE means reverse order."
11047   (interactive "P")
11048   (gnus-summary-sort 'chars reverse))
11049
11050 (defun gnus-summary-sort-by-original (&optional reverse)
11051   "Sort the summary buffer using the default sorting method.
11052 Argument REVERSE means reverse order."
11053   (interactive "P")
11054   (let* ((buffer-read-only)
11055          (gnus-summary-prepare-hook nil))
11056     ;; We do the sorting by regenerating the threads.
11057     (gnus-summary-prepare)
11058     ;; Hide subthreads if needed.
11059     (gnus-summary-maybe-hide-threads)))
11060
11061 (defun gnus-summary-sort (predicate reverse)
11062   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11063   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11064          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11065          (gnus-thread-sort-functions
11066           (if (not reverse)
11067               thread
11068             `(lambda (t1 t2)
11069                (,thread t2 t1))))
11070          (gnus-sort-gathered-threads-function
11071           gnus-thread-sort-functions)
11072          (gnus-article-sort-functions
11073           (if (not reverse)
11074               article
11075             `(lambda (t1 t2)
11076                (,article t2 t1))))
11077          (buffer-read-only)
11078          (gnus-summary-prepare-hook nil))
11079     ;; We do the sorting by regenerating the threads.
11080     (gnus-summary-prepare)
11081     ;; Hide subthreads if needed.
11082     (gnus-summary-maybe-hide-threads)))
11083
11084 ;; Summary saving commands.
11085
11086 (defun gnus-summary-save-article (&optional n not-saved)
11087   "Save the current article using the default saver function.
11088 If N is a positive number, save the N next articles.
11089 If N is a negative number, save the N previous articles.
11090 If N is nil and any articles have been marked with the process mark,
11091 save those articles instead.
11092 The variable `gnus-default-article-saver' specifies the saver function."
11093   (interactive "P")
11094   (let* ((articles (gnus-summary-work-articles n))
11095          (save-buffer (save-excursion
11096                         (nnheader-set-temp-buffer " *Gnus Save*")))
11097          (num (length articles))
11098          header file)
11099     (dolist (article articles)
11100       (setq header (gnus-summary-article-header article))
11101       (if (not (vectorp header))
11102           ;; This is a pseudo-article.
11103           (if (assq 'name header)
11104               (gnus-copy-file (cdr (assq 'name header)))
11105             (gnus-message 1 "Article %d is unsaveable" article))
11106         ;; This is a real article.
11107         (save-window-excursion
11108           (let ((gnus-display-mime-function nil)
11109                 (gnus-article-prepare-hook nil))
11110             (gnus-summary-select-article t nil nil article)))
11111         (save-excursion
11112           (set-buffer save-buffer)
11113           (erase-buffer)
11114           (insert-buffer-substring gnus-original-article-buffer))
11115         (setq file (gnus-article-save save-buffer file num))
11116         (gnus-summary-remove-process-mark article)
11117         (unless not-saved
11118           (gnus-summary-set-saved-mark article))))
11119     (gnus-kill-buffer save-buffer)
11120     (gnus-summary-position-point)
11121     (gnus-set-mode-line 'summary)
11122     n))
11123
11124 (defun gnus-summary-pipe-output (&optional arg headers)
11125   "Pipe the current article to a subprocess.
11126 If N is a positive number, pipe the N next articles.
11127 If N is a negative number, pipe the N previous articles.
11128 If N is nil and any articles have been marked with the process mark,
11129 pipe those articles instead.
11130 If HEADERS (the symbolic prefix), include the headers, too."
11131   (interactive (gnus-interactive "P\ny"))
11132   (require 'gnus-art)
11133   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11134         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11135     (gnus-summary-save-article arg t))
11136   (let ((buffer (get-buffer "*Shell Command Output*")))
11137     (when (and buffer
11138                (not (zerop (buffer-size buffer))))
11139       (gnus-configure-windows 'pipe))))
11140
11141 (defun gnus-summary-save-article-mail (&optional arg)
11142   "Append the current article to an mail file.
11143 If N is a positive number, save the N next articles.
11144 If N is a negative number, save the N previous articles.
11145 If N is nil and any articles have been marked with the process mark,
11146 save those articles instead."
11147   (interactive "P")
11148   (require 'gnus-art)
11149   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11150     (gnus-summary-save-article arg)))
11151
11152 (defun gnus-summary-save-article-rmail (&optional arg)
11153   "Append the current article to an rmail file.
11154 If N is a positive number, save the N next articles.
11155 If N is a negative number, save the N previous articles.
11156 If N is nil and any articles have been marked with the process mark,
11157 save those articles instead."
11158   (interactive "P")
11159   (require 'gnus-art)
11160   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11161     (gnus-summary-save-article arg)))
11162
11163 (defun gnus-summary-save-article-file (&optional arg)
11164   "Append the current article to a file.
11165 If N is a positive number, save the N next articles.
11166 If N is a negative number, save the N previous articles.
11167 If N is nil and any articles have been marked with the process mark,
11168 save those articles instead."
11169   (interactive "P")
11170   (require 'gnus-art)
11171   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11172     (gnus-summary-save-article arg)))
11173
11174 (defun gnus-summary-write-article-file (&optional arg)
11175   "Write the current article to a file, deleting the previous file.
11176 If N is a positive number, save the N next articles.
11177 If N is a negative number, save the N previous articles.
11178 If N is nil and any articles have been marked with the process mark,
11179 save those articles instead."
11180   (interactive "P")
11181   (require 'gnus-art)
11182   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11183     (gnus-summary-save-article arg)))
11184
11185 (defun gnus-summary-save-article-body-file (&optional arg)
11186   "Append the current article body to a file.
11187 If N is a positive number, save the N next articles.
11188 If N is a negative number, save the N previous articles.
11189 If N is nil and any articles have been marked with the process mark,
11190 save those articles instead."
11191   (interactive "P")
11192   (require 'gnus-art)
11193   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11194     (gnus-summary-save-article arg)))
11195
11196 (defun gnus-summary-muttprint (&optional arg)
11197   "Print the current article using Muttprint.
11198 If N is a positive number, save the N next articles.
11199 If N is a negative number, save the N previous articles.
11200 If N is nil and any articles have been marked with the process mark,
11201 save those articles instead."
11202   (interactive "P")
11203   (require 'gnus-art)
11204   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11205     (gnus-summary-save-article arg t)))
11206
11207 (defun gnus-summary-pipe-message (program)
11208   "Pipe the current article through PROGRAM."
11209   (interactive "sProgram: ")
11210   (gnus-summary-select-article)
11211   (let ((mail-header-separator ""))
11212     (gnus-eval-in-buffer-window gnus-article-buffer
11213       (save-restriction
11214         (widen)
11215         (let ((start (window-start))
11216               buffer-read-only)
11217           (message-pipe-buffer-body program)
11218           (set-window-start (get-buffer-window (current-buffer)) start))))))
11219
11220 (defun gnus-get-split-value (methods)
11221   "Return a value based on the split METHODS."
11222   (let (split-name method result match)
11223     (when methods
11224       (save-excursion
11225         (set-buffer gnus-original-article-buffer)
11226         (save-restriction
11227           (nnheader-narrow-to-headers)
11228           (while (and methods (not split-name))
11229             (goto-char (point-min))
11230             (setq method (pop methods))
11231             (setq match (car method))
11232             (when (cond
11233                    ((stringp match)
11234                     ;; Regular expression.
11235                     (ignore-errors
11236                       (re-search-forward match nil t)))
11237                    ((functionp match)
11238                     ;; Function.
11239                     (save-restriction
11240                       (widen)
11241                       (setq result (funcall match gnus-newsgroup-name))))
11242                    ((consp match)
11243                     ;; Form.
11244                     (save-restriction
11245                       (widen)
11246                       (setq result (eval match)))))
11247               (setq split-name (cdr method))
11248               (cond ((stringp result)
11249                      (push (expand-file-name
11250                             result gnus-article-save-directory)
11251                            split-name))
11252                     ((consp result)
11253                      (setq split-name (append result split-name)))))))))
11254     (nreverse split-name)))
11255
11256 (defun gnus-valid-move-group-p (group)
11257   (and (boundp group)
11258        (symbol-name group)
11259        (symbol-value group)
11260        (gnus-get-function (gnus-find-method-for-group
11261                            (symbol-name group)) 'request-accept-article t)))
11262
11263 (defun gnus-read-move-group-name (prompt default articles prefix)
11264   "Read a group name."
11265   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11266          (minibuffer-confirm-incomplete nil) ; XEmacs
11267          (prom
11268           (format "%s %s to:"
11269                   prompt
11270                   (if (> (length articles) 1)
11271                       (format "these %d articles" (length articles))
11272                     "this article")))
11273          (to-newsgroup
11274           (cond
11275            ((null split-name)
11276             (gnus-completing-read-with-default
11277              default prom
11278              gnus-active-hashtb
11279              'gnus-valid-move-group-p
11280              nil prefix
11281              'gnus-group-history))
11282            ((= 1 (length split-name))
11283             (gnus-completing-read-with-default
11284              (car split-name) prom
11285              gnus-active-hashtb
11286              'gnus-valid-move-group-p
11287              nil nil
11288              'gnus-group-history))
11289            (t
11290             (gnus-completing-read-with-default
11291              nil prom
11292              (mapcar 'list (nreverse split-name))
11293              nil nil nil
11294              'gnus-group-history))))
11295          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11296     (when to-newsgroup
11297       (if (or (string= to-newsgroup "")
11298               (string= to-newsgroup prefix))
11299           (setq to-newsgroup default))
11300       (unless to-newsgroup
11301         (error "No group name entered"))
11302       (or (gnus-active to-newsgroup)
11303           (gnus-activate-group to-newsgroup nil nil to-method)
11304           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11305                                      to-newsgroup))
11306               (or (and (gnus-request-create-group to-newsgroup to-method)
11307                        (gnus-activate-group
11308                         to-newsgroup nil nil to-method)
11309                        (gnus-subscribe-group to-newsgroup))
11310                   (error "Couldn't create group %s" to-newsgroup)))
11311           (error "No such group: %s" to-newsgroup)))
11312     to-newsgroup))
11313
11314 (defun gnus-summary-save-parts (type dir n &optional reverse)
11315   "Save parts matching TYPE to DIR.
11316 If REVERSE, save parts that do not match TYPE."
11317   (interactive
11318    (list (read-string "Save parts of type: "
11319                       (or (car gnus-summary-save-parts-type-history)
11320                           gnus-summary-save-parts-default-mime)
11321                       'gnus-summary-save-parts-type-history)
11322          (setq gnus-summary-save-parts-last-directory
11323                (read-file-name "Save to directory: "
11324                                gnus-summary-save-parts-last-directory
11325                                nil t))
11326          current-prefix-arg))
11327   (gnus-summary-iterate n
11328     (let ((gnus-display-mime-function nil)
11329           (gnus-inhibit-treatment t))
11330       (gnus-summary-select-article))
11331     (save-excursion
11332       (set-buffer gnus-article-buffer)
11333       (let ((handles (or gnus-article-mime-handles
11334                          (mm-dissect-buffer nil gnus-article-loose-mime)
11335                          (and gnus-article-emulate-mime
11336                               (mm-uu-dissect)))))
11337         (when handles
11338           (gnus-summary-save-parts-1 type dir handles reverse)
11339           (unless gnus-article-mime-handles ;; Don't destroy this case.
11340             (mm-destroy-parts handles)))))))
11341
11342 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11343   (if (stringp (car handle))
11344       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11345               (cdr handle))
11346     (when (if reverse
11347               (not (string-match type (mm-handle-media-type handle)))
11348             (string-match type (mm-handle-media-type handle)))
11349       (let ((file (expand-file-name
11350                    (gnus-map-function
11351                     mm-file-name-rewrite-functions
11352                     (file-name-nondirectory
11353                      (or
11354                       (mail-content-type-get
11355                        (mm-handle-disposition handle) 'filename)
11356                       (mail-content-type-get
11357                        (mm-handle-type handle) 'name)
11358                       (concat gnus-newsgroup-name
11359                               "." (number-to-string
11360                                    (cdr gnus-article-current))))))
11361                    dir)))
11362         (unless (file-exists-p file)
11363           (mm-save-part-to-file handle file))))))
11364
11365 ;; Summary extract commands
11366
11367 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11368   (let ((buffer-read-only nil)
11369         (article (gnus-summary-article-number))
11370         after-article b e)
11371     (unless (gnus-summary-goto-subject article)
11372       (error "No such article: %d" article))
11373     (gnus-summary-position-point)
11374     ;; If all commands are to be bunched up on one line, we collect
11375     ;; them here.
11376     (unless gnus-view-pseudos-separately
11377       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11378             files action)
11379         (while ps
11380           (setq action (cdr (assq 'action (car ps))))
11381           (setq files (list (cdr (assq 'name (car ps)))))
11382           (while (and ps (cdr ps)
11383                       (string= (or action "1")
11384                                (or (cdr (assq 'action (cadr ps))) "2")))
11385             (push (cdr (assq 'name (cadr ps))) files)
11386             (setcdr ps (cddr ps)))
11387           (when files
11388             (when (not (string-match "%s" action))
11389               (push " " files))
11390             (push " " files)
11391             (when (assq 'execute (car ps))
11392               (setcdr (assq 'execute (car ps))
11393                       (funcall (if (string-match "%s" action)
11394                                    'format 'concat)
11395                                action
11396                                (mapconcat
11397                                 (lambda (f)
11398                                   (if (equal f " ")
11399                                       f
11400                                     (shell-quote-argument f)))
11401                                 files " ")))))
11402           (setq ps (cdr ps)))))
11403     (if (and gnus-view-pseudos (not not-view))
11404         (while pslist
11405           (when (assq 'execute (car pslist))
11406             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11407                                   (eq gnus-view-pseudos 'not-confirm)))
11408           (setq pslist (cdr pslist)))
11409       (save-excursion
11410         (while pslist
11411           (setq after-article (or (cdr (assq 'article (car pslist)))
11412                                   (gnus-summary-article-number)))
11413           (gnus-summary-goto-subject after-article)
11414           (forward-line 1)
11415           (setq b (point))
11416           (insert "    " (file-name-nondirectory
11417                           (cdr (assq 'name (car pslist))))
11418                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11419           (setq e (point))
11420           (forward-line -1)             ; back to `b'
11421           (gnus-add-text-properties
11422            b (1- e) (list 'gnus-number gnus-reffed-article-number
11423                           gnus-mouse-face-prop gnus-mouse-face))
11424           (gnus-data-enter
11425            after-article gnus-reffed-article-number
11426            gnus-unread-mark b (car pslist) 0 (- e b))
11427           (setq gnus-newsgroup-unreads
11428                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11429                                          gnus-reffed-article-number))
11430           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11431           (setq pslist (cdr pslist)))))))
11432
11433 (defun gnus-pseudos< (p1 p2)
11434   (let ((c1 (cdr (assq 'action p1)))
11435         (c2 (cdr (assq 'action p2))))
11436     (and c1 c2 (string< c1 c2))))
11437
11438 (defun gnus-request-pseudo-article (props)
11439   (cond ((assq 'execute props)
11440          (gnus-execute-command (cdr (assq 'execute props)))))
11441   (let ((gnus-current-article (gnus-summary-article-number)))
11442     (gnus-run-hooks 'gnus-mark-article-hook)))
11443
11444 (defun gnus-execute-command (command &optional automatic)
11445   (save-excursion
11446     (gnus-article-setup-buffer)
11447     (set-buffer gnus-article-buffer)
11448     (setq buffer-read-only nil)
11449     (let ((command (if automatic command
11450                      (read-string "Command: " (cons command 0)))))
11451       (erase-buffer)
11452       (insert "$ " command "\n\n")
11453       (if gnus-view-pseudo-asynchronously
11454           (start-process "gnus-execute" (current-buffer) shell-file-name
11455                          shell-command-switch command)
11456         (call-process shell-file-name nil t nil
11457                       shell-command-switch command)))))
11458
11459 ;; Summary kill commands.
11460
11461 (defun gnus-summary-edit-global-kill (article)
11462   "Edit the \"global\" kill file."
11463   (interactive (list (gnus-summary-article-number)))
11464   (gnus-group-edit-global-kill article))
11465
11466 (defun gnus-summary-edit-local-kill ()
11467   "Edit a local kill file applied to the current newsgroup."
11468   (interactive)
11469   (setq gnus-current-headers (gnus-summary-article-header))
11470   (gnus-group-edit-local-kill
11471    (gnus-summary-article-number) gnus-newsgroup-name))
11472
11473 ;;; Header reading.
11474
11475 (defun gnus-read-header (id &optional header)
11476   "Read the headers of article ID and enter them into the Gnus system."
11477   (let ((group gnus-newsgroup-name)
11478         (gnus-override-method
11479          (or
11480           gnus-override-method
11481           (and (gnus-news-group-p gnus-newsgroup-name)
11482                (car (gnus-refer-article-methods)))))
11483         where)
11484     ;; First we check to see whether the header in question is already
11485     ;; fetched.
11486     (if (stringp id)
11487         ;; This is a Message-ID.
11488         (setq header (or header (gnus-id-to-header id)))
11489       ;; This is an article number.
11490       (setq header (or header (gnus-summary-article-header id))))
11491     (if (and header
11492              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11493         ;; We have found the header.
11494         header
11495       ;; We have to really fetch the header to this article.
11496       (save-excursion
11497         (set-buffer nntp-server-buffer)
11498         (when (setq where (gnus-request-head id group))
11499           (nnheader-fold-continuation-lines)
11500           (goto-char (point-max))
11501           (insert ".\n")
11502           (goto-char (point-min))
11503           (insert "211 ")
11504           (princ (cond
11505                   ((numberp id) id)
11506                   ((cdr where) (cdr where))
11507                   (header (mail-header-number header))
11508                   (t gnus-reffed-article-number))
11509                  (current-buffer))
11510           (insert " Article retrieved.\n"))
11511         (if (or (not where)
11512                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11513             ()                          ; Malformed head.
11514           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11515             (when (and (stringp id)
11516                        (not (string= (gnus-group-real-name group)
11517                                      (car where))))
11518               ;; If we fetched by Message-ID and the article came
11519               ;; from a different group, we fudge some bogus article
11520               ;; numbers for this article.
11521               (mail-header-set-number header gnus-reffed-article-number))
11522             (save-excursion
11523               (set-buffer gnus-summary-buffer)
11524               (decf gnus-reffed-article-number)
11525               (gnus-remove-header (mail-header-number header))
11526               (push header gnus-newsgroup-headers)
11527               (setq gnus-current-headers header)
11528               (push (mail-header-number header) gnus-newsgroup-limit)))
11529           header)))))
11530
11531 (defun gnus-remove-header (number)
11532   "Remove header NUMBER from `gnus-newsgroup-headers'."
11533   (if (and gnus-newsgroup-headers
11534            (= number (mail-header-number (car gnus-newsgroup-headers))))
11535       (pop gnus-newsgroup-headers)
11536     (let ((headers gnus-newsgroup-headers))
11537       (while (and (cdr headers)
11538                   (not (= number (mail-header-number (cadr headers)))))
11539         (pop headers))
11540       (when (cdr headers)
11541         (setcdr headers (cddr headers))))))
11542
11543 ;;;
11544 ;;; summary highlights
11545 ;;;
11546
11547 (defun gnus-highlight-selected-summary ()
11548   "Highlight selected article in summary buffer."
11549   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11550   (when gnus-summary-selected-face
11551     (save-excursion
11552       (let* ((beg (point-at-bol))
11553              (end (point-at-eol))
11554              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11555              (from (if (get-text-property beg gnus-mouse-face-prop)
11556                        beg
11557                      (or (next-single-property-change
11558                           beg gnus-mouse-face-prop nil end)
11559                          beg)))
11560              (to
11561               (if (= from end)
11562                   (- from 2)
11563                 (or (next-single-property-change
11564                      from gnus-mouse-face-prop nil end)
11565                     end))))
11566         ;; If no mouse-face prop on line we will have to = from = end,
11567         ;; so we highlight the entire line instead.
11568         (when (= (+ to 2) from)
11569           (setq from beg)
11570           (setq to end))
11571         (if gnus-newsgroup-selected-overlay
11572             ;; Move old overlay.
11573             (gnus-move-overlay
11574              gnus-newsgroup-selected-overlay from to (current-buffer))
11575           ;; Create new overlay.
11576           (gnus-overlay-put
11577            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11578            'face gnus-summary-selected-face))))))
11579
11580 (defvar gnus-summary-highlight-line-cached nil)
11581 (defvar gnus-summary-highlight-line-trigger nil)
11582
11583 (defun gnus-summary-highlight-line-0 ()
11584   (if (and (eq gnus-summary-highlight-line-trigger
11585                gnus-summary-highlight)
11586            gnus-summary-highlight-line-cached)
11587       gnus-summary-highlight-line-cached
11588     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11589           gnus-summary-highlight-line-cached
11590           (let* ((cond (list 'cond))
11591                  (c cond)
11592                  (list gnus-summary-highlight))
11593             (while list
11594               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11595                               nil))
11596               (setq c (cdr c)
11597                     list (cdr list)))
11598             (gnus-byte-compile (list 'lambda nil cond))))))
11599
11600 (defun gnus-summary-highlight-line ()
11601   "Highlight current line according to `gnus-summary-highlight'."
11602   (let* ((beg (point-at-bol))
11603          (article (or (gnus-summary-article-number) gnus-current-article))
11604          (score (or (cdr (assq article
11605                                gnus-newsgroup-scored))
11606                     gnus-summary-default-score 0))
11607          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11608          (inhibit-read-only t)
11609          (default gnus-summary-default-score)
11610          (default-high gnus-summary-default-high-score)
11611          (default-low gnus-summary-default-low-score)
11612          (uncached (and gnus-summary-use-undownloaded-faces
11613                         (memq article gnus-newsgroup-undownloaded)
11614                         (not (memq article gnus-newsgroup-cached)))))
11615     (let ((face (funcall (gnus-summary-highlight-line-0))))
11616       (unless (eq face (get-text-property beg 'face))
11617         (gnus-put-text-property-excluding-characters-with-faces
11618          beg (point-at-eol) 'face
11619          (setq face (if (boundp face) (symbol-value face) face)))
11620         (when gnus-summary-highlight-line-function
11621           (funcall gnus-summary-highlight-line-function article face))))))
11622
11623 (defun gnus-update-read-articles (group unread &optional compute)
11624   "Update the list of read articles in GROUP.
11625 UNREAD is a sorted list."
11626   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11627         (info (gnus-get-info group))
11628         (prev 1)
11629         read)
11630     (if (or (not info) (not active))
11631         ;; There is no info on this group if it was, in fact,
11632         ;; killed.  Gnus stores no information on killed groups, so
11633         ;; there's nothing to be done.
11634         ;; One could store the information somewhere temporarily,
11635         ;; perhaps...  Hmmm...
11636         ()
11637       ;; Remove any negative articles numbers.
11638       (while (and unread (< (car unread) 0))
11639         (setq unread (cdr unread)))
11640       ;; Remove any expired article numbers
11641       (while (and unread (< (car unread) (car active)))
11642         (setq unread (cdr unread)))
11643       ;; Compute the ranges of read articles by looking at the list of
11644       ;; unread articles.
11645       (while unread
11646         (when (/= (car unread) prev)
11647           (push (if (= prev (1- (car unread))) prev
11648                   (cons prev (1- (car unread))))
11649                 read))
11650         (setq prev (1+ (car unread)))
11651         (setq unread (cdr unread)))
11652       (when (<= prev (cdr active))
11653         (push (cons prev (cdr active)) read))
11654       (setq read (if (> (length read) 1) (nreverse read) read))
11655       (if compute
11656           read
11657         (save-excursion
11658           (let (setmarkundo)
11659             ;; Propagate the read marks to the backend.
11660             (when (gnus-check-backend-function 'request-set-mark group)
11661               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11662                     (add (gnus-remove-from-range read (gnus-info-read info))))
11663                 (when (or add del)
11664                   (unless (gnus-check-group group)
11665                     (error "Can't open server for %s" group))
11666                   (gnus-request-set-mark
11667                    group (delq nil (list (if add (list add 'add '(read)))
11668                                          (if del (list del 'del '(read))))))
11669                   (setq setmarkundo
11670                         `(gnus-request-set-mark
11671                           ,group
11672                           ',(delq nil (list
11673                                        (if del (list del 'add '(read)))
11674                                        (if add (list add 'del '(read))))))))))
11675             (set-buffer gnus-group-buffer)
11676             (gnus-undo-register
11677               `(progn
11678                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11679                  (gnus-info-set-read ',info ',(gnus-info-read info))
11680                  (gnus-get-unread-articles-in-group ',info
11681                                                     (gnus-active ,group))
11682                  (gnus-group-update-group ,group t)
11683                  ,setmarkundo))))
11684         ;; Enter this list into the group info.
11685         (gnus-info-set-read info read)
11686         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11687         (gnus-get-unread-articles-in-group info (gnus-active group))
11688         t))))
11689
11690 (defun gnus-offer-save-summaries ()
11691   "Offer to save all active summary buffers."
11692   (let (buffers)
11693     ;; Go through all buffers and find all summaries.
11694     (dolist (buffer (buffer-list))
11695       (when (and (setq buffer (buffer-name buffer))
11696                  (string-match "Summary" buffer)
11697                  (with-current-buffer buffer
11698                    ;; We check that this is, indeed, a summary buffer.
11699                    (and (eq major-mode 'gnus-summary-mode)
11700                         ;; Also make sure this isn't bogus.
11701                         gnus-newsgroup-prepared
11702                         ;; Also make sure that this isn't a
11703                         ;; dead summary buffer.
11704                         (not gnus-dead-summary-mode))))
11705         (push buffer buffers)))
11706     ;; Go through all these summary buffers and offer to save them.
11707     (when buffers
11708       (save-excursion
11709         (map-y-or-n-p
11710          "Update summary buffer %s? "
11711          (lambda (buf)
11712            (switch-to-buffer buf)
11713            (gnus-summary-exit))
11714          buffers)))))
11715
11716
11717 ;;; @ for mime-partial
11718 ;;;
11719
11720 (defun gnus-request-partial-message ()
11721   (save-excursion
11722     (let ((number (gnus-summary-article-number))
11723           (group gnus-newsgroup-name)
11724           (mother gnus-article-buffer))
11725       (set-buffer (get-buffer-create " *Partial Article*"))
11726       (erase-buffer)
11727       (setq mime-preview-buffer mother)
11728       (gnus-request-article-this-buffer number group)
11729       (mime-parse-buffer)
11730       )))
11731
11732 (autoload 'mime-combine-message/partial-pieces-automatically
11733   "mime-partial"
11734   "Internal method to combine message/partial messages automatically.")
11735
11736 (mime-add-condition
11737  'action '((type . message)(subtype . partial)
11738            (major-mode . gnus-original-article-mode)
11739            (method . mime-combine-message/partial-pieces-automatically)
11740            (summary-buffer-exp . gnus-summary-buffer)
11741            (request-partial-message-method . gnus-request-partial-message)
11742            ))
11743
11744
11745 ;;; @ for message/rfc822
11746 ;;;
11747
11748 (defun gnus-mime-extract-message/rfc822 (entity situation)
11749   "Burst a forwarded article."
11750   (save-excursion
11751     (set-buffer gnus-summary-buffer)
11752     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11753                                    gnus-newsgroup-name 'gnus-group-history))
11754            (gnus-group-marked (list group))
11755            article info)
11756       (with-temp-buffer
11757         (mime-insert-entity-content entity)
11758         (setq article (gnus-request-accept-article group)))
11759       (when (and (consp article)
11760                  (numberp (setq article (cdr article))))
11761         (setq info (gnus-get-info group))
11762         (gnus-info-set-read info
11763                             (gnus-remove-from-range (gnus-info-read info)
11764                                                     (list article)))
11765         (when (string-equal group gnus-newsgroup-name)
11766           (forward-line 1)
11767           (let (gnus-show-threads)
11768             (gnus-summary-goto-subject article t))
11769           (gnus-summary-clear-mark-forward 1))
11770         (set-buffer gnus-group-buffer)
11771         (gnus-group-get-new-news-this-group nil t)))))
11772
11773 (mime-add-condition
11774  'action '((type . message)(subtype . rfc822)
11775            (major-mode . gnus-original-article-mode)
11776            (method . gnus-mime-extract-message/rfc822)
11777            (mode . "extract")
11778            ))
11779
11780 (mime-add-condition
11781  'action '((type . message)(subtype . news)
11782            (major-mode . gnus-original-article-mode)
11783            (method . gnus-mime-extract-message/rfc822)
11784            (mode . "extract")
11785            ))
11786
11787 (defun gnus-mime-extract-multipart (entity situation)
11788   (let ((children (mime-entity-children entity))
11789         mime-acting-situation-to-override
11790         f)
11791     (while children
11792       (mime-play-entity (car children)
11793                         (cons (assq 'mode situation)
11794                               mime-acting-situation-to-override))
11795       (setq children (cdr children)))
11796     (if (setq f (cdr (assq 'after-method
11797                            mime-acting-situation-to-override)))
11798         (eval f)
11799       )))
11800
11801 (mime-add-condition
11802  'action '((type . multipart)
11803            (method . gnus-mime-extract-multipart)
11804            (mode . "extract")
11805            )
11806  'with-default)
11807
11808
11809 ;;; @ end
11810 ;;;
11811
11812 (defun gnus-summary-inherit-default-charset ()
11813   "Import `default-mime-charset' from summary buffer.
11814 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11815 of FLIM is used."
11816   (if (buffer-live-p gnus-summary-buffer)
11817       (let (d-m-c d-m-c-u)
11818         (with-current-buffer gnus-summary-buffer
11819           (setq d-m-c (if (local-variable-p 'default-mime-charset
11820                                             gnus-summary-buffer)
11821                           default-mime-charset
11822                         t)
11823                 ;; LIMIT
11824                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11825                                               gnus-summary-buffer)
11826                             (symbol-value 'default-mime-charset-unlimited)
11827                           t)))
11828         (if (eq t d-m-c)
11829             (kill-local-variable 'default-mime-charset)
11830           (set (make-local-variable 'default-mime-charset) d-m-c))
11831         (if (eq t d-m-c-u)
11832             (kill-local-variable 'default-mime-charset-unlimited)
11833           (set (make-local-variable 'default-mime-charset-unlimited)
11834                d-m-c-u)))))
11835
11836 (defun gnus-summary-setup-default-charset ()
11837   "Setup newsgroup default charset."
11838   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11839       (progn
11840         (setq gnus-newsgroup-charset nil)
11841         (set (make-local-variable 'default-mime-charset) nil)
11842         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11843           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11844     (let ((ignored-charsets
11845            (or gnus-newsgroup-ephemeral-ignored-charsets
11846                (append
11847                 (and gnus-newsgroup-name
11848                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11849                 gnus-newsgroup-ignored-charsets)))
11850           charset)
11851       (setq gnus-newsgroup-charset
11852             (or gnus-newsgroup-ephemeral-charset
11853                 (when (and gnus-newsgroup-name
11854                            (setq charset (gnus-parameter-charset
11855                                           gnus-newsgroup-name)))
11856                   (make-local-variable 'default-mime-charset)
11857                   (setq default-mime-charset charset))
11858                 gnus-default-charset))
11859       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11860            ignored-charsets))))
11861
11862 ;;;
11863 ;;; Mime Commands
11864 ;;;
11865
11866 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11867   "Display the current article buffer fully MIME-buttonized.
11868 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11869 treated as multipart/mixed."
11870   (interactive "P")
11871   (require 'gnus-art)
11872   (let ((gnus-unbuttonized-mime-types nil)
11873         (gnus-mime-display-multipart-as-mixed show-all-parts))
11874     (gnus-summary-show-article)))
11875
11876 (defun gnus-summary-repair-multipart (article)
11877   "Add a Content-Type header to a multipart article without one."
11878   (interactive (list (gnus-summary-article-number)))
11879   (gnus-with-article article
11880     (message-narrow-to-head)
11881     (message-remove-header "Mime-Version")
11882     (goto-char (point-max))
11883     (insert "Mime-Version: 1.0\n")
11884     (widen)
11885     (when (search-forward "\n--" nil t)
11886       (let ((separator (buffer-substring (point) (point-at-eol))))
11887         (message-narrow-to-head)
11888         (message-remove-header "Content-Type")
11889         (goto-char (point-max))
11890         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11891                         separator))
11892         (widen))))
11893   (let (gnus-mark-article-hook)
11894     (gnus-summary-select-article t t nil article)))
11895
11896 (defun gnus-summary-toggle-display-buttonized ()
11897   "Toggle the buttonizing of the article buffer."
11898   (interactive)
11899   (require 'gnus-art)
11900   (if (setq gnus-inhibit-mime-unbuttonizing
11901             (not gnus-inhibit-mime-unbuttonizing))
11902       (let ((gnus-unbuttonized-mime-types nil))
11903         (gnus-summary-show-article))
11904     (gnus-summary-show-article)))
11905
11906 ;;;
11907 ;;; Intelli-mouse commmands
11908 ;;;
11909
11910 (defun gnus-wheel-summary-scroll (event)
11911   (interactive "e")
11912   (let ((amount (if (memq 'shift (event-modifiers event))
11913                     (car gnus-wheel-scroll-amount)
11914                   (cdr gnus-wheel-scroll-amount)))
11915         (direction (- (* (static-if (featurep 'xemacs)
11916                              (event-button event)
11917                            (cond ((eq 'mouse-4 (event-basic-type event))
11918                                   4)
11919                                  ((eq 'mouse-5 (event-basic-type event))
11920                                   5)))
11921                          2) 9))
11922         edge)
11923     (gnus-summary-scroll-up (* amount direction))
11924     (when (gnus-eval-in-buffer-window gnus-article-buffer
11925             (save-restriction
11926               (widen)
11927               (and (if (< 0 direction)
11928                        (gnus-article-next-page 0)
11929                      (gnus-article-prev-page 0)
11930                      (bobp))
11931                    (if (setq edge (get-text-property
11932                                    (point-min) 'gnus-wheel-edge))
11933                        (setq edge (* edge direction))
11934                      (setq edge -1))
11935                    (or (plusp edge)
11936                        (let ((buffer-read-only nil)
11937                              (inhibit-read-only t))
11938                          (put-text-property (point-min) (point-max)
11939                                             'gnus-wheel-edge direction)
11940                          nil))
11941                    (or (> edge gnus-wheel-edge-resistance)
11942                        (let ((buffer-read-only nil)
11943                              (inhibit-read-only t))
11944                          (put-text-property (point-min) (point-max)
11945                                             'gnus-wheel-edge
11946                                             (* (1+ edge) direction))
11947                          nil))
11948                    (eq last-command 'gnus-wheel-summary-scroll))))
11949       (gnus-summary-next-article nil nil (minusp direction)))))
11950
11951 (defun gnus-wheel-install ()
11952   "Enable mouse wheel support on summary window."
11953   (when gnus-use-wheel
11954     (let ((keys
11955            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11956       (dolist (key keys)
11957         (define-key gnus-summary-mode-map key
11958           'gnus-wheel-summary-scroll)))))
11959
11960 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11961
11962 ;;;
11963 ;;; Traditional PGP commmands
11964 ;;;
11965
11966 (defun gnus-summary-decrypt-article (&optional force)
11967   "Decrypt the current article in traditional PGP way.
11968 This will have permanent effect only in mail groups.
11969 If FORCE is non-nil, allow editing of articles even in read-only
11970 groups."
11971   (interactive "P")
11972   (gnus-summary-select-article t)
11973   (gnus-eval-in-buffer-window gnus-article-buffer
11974     (save-excursion
11975       (save-restriction
11976         (widen)
11977         (goto-char (point-min))
11978         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11979           (error "Not a traditional PGP message!"))
11980         (let ((armor-start (match-beginning 0)))
11981           (if (and (pgg-decrypt-region armor-start (point-max))
11982                    (or force (not (gnus-group-read-only-p))))
11983               (let ((inhibit-read-only t)
11984                     buffer-read-only)
11985                 (delete-region armor-start
11986                                (progn
11987                                  (re-search-forward "^-+END PGP" nil t)
11988                                  (beginning-of-line 2)
11989                                  (point)))
11990                 (insert-buffer-substring pgg-output-buffer))))))))
11991
11992 (defun gnus-summary-verify-article ()
11993   "Verify the current article in traditional PGP way."
11994   (interactive)
11995   (save-excursion
11996     (set-buffer gnus-original-article-buffer)
11997     (goto-char (point-min))
11998     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11999       (error "Not a traditional PGP message!"))
12000     (re-search-forward "^-+END PGP" nil t)
12001     (beginning-of-line 2)
12002     (call-interactively (function pgg-verify-region))))
12003
12004 ;;;
12005 ;;; Generic summary marking commands
12006 ;;;
12007
12008 (defvar gnus-summary-marking-alist
12009   '((read gnus-del-mark "d")
12010     (unread gnus-unread-mark "u")
12011     (ticked gnus-ticked-mark "!")
12012     (dormant gnus-dormant-mark "?")
12013     (expirable gnus-expirable-mark "e"))
12014   "An alist of names/marks/keystrokes.")
12015
12016 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12017 (defvar gnus-summary-mark-map)
12018
12019 (defun gnus-summary-make-all-marking-commands ()
12020   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12021   (dolist (elem gnus-summary-marking-alist)
12022     (apply 'gnus-summary-make-marking-command elem)))
12023
12024 (defun gnus-summary-make-marking-command (name mark keystroke)
12025   (let ((map (make-sparse-keymap)))
12026     (define-key gnus-summary-generic-mark-map keystroke map)
12027     (dolist (lway `((next "next" next nil "n")
12028                     (next-unread "next unread" next t "N")
12029                     (prev "previous" prev nil "p")
12030                     (prev-unread "previous unread" prev t "P")
12031                     (nomove "" nil nil ,keystroke)))
12032       (let ((func (gnus-summary-make-marking-command-1
12033                    mark (car lway) lway name)))
12034         (setq func (eval func))
12035         (define-key map (nth 4 lway) func)))))
12036
12037 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12038   `(defun ,(intern
12039             (format "gnus-summary-put-mark-as-%s%s"
12040                     name (if (eq way 'nomove)
12041                              ""
12042                            (concat "-" (symbol-name way)))))
12043      (n)
12044      ,(format
12045        "Mark the current article as %s%s.
12046 If N, the prefix, then repeat N times.
12047 If N is negative, move in reverse order.
12048 The difference between N and the actual number of articles marked is
12049 returned."
12050        name (car (cdr lway)))
12051      (interactive "p")
12052      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12053
12054 (defun gnus-summary-generic-mark (n mark move unread)
12055   "Mark N articles with MARK."
12056   (unless (eq major-mode 'gnus-summary-mode)
12057     (error "This command can only be used in the summary buffer"))
12058   (gnus-summary-show-thread)
12059   (let ((nummove
12060          (cond
12061           ((eq move 'next) 1)
12062           ((eq move 'prev) -1)
12063           (t 0))))
12064     (if (zerop nummove)
12065         (setq n 1)
12066       (when (< n 0)
12067         (setq n (abs n)
12068               nummove (* -1 nummove))))
12069     (while (and (> n 0)
12070                 (gnus-summary-mark-article nil mark)
12071                 (zerop (gnus-summary-next-subject nummove unread t)))
12072       (setq n (1- n)))
12073     (when (/= 0 n)
12074       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12075     (gnus-summary-recenter)
12076     (gnus-summary-position-point)
12077     (gnus-set-mode-line 'summary)
12078     n))
12079
12080 (defun gnus-summary-insert-articles (articles)
12081   (when (setq articles
12082               (gnus-sorted-difference articles
12083                                       (mapcar (lambda (h)
12084                                                 (mail-header-number h))
12085                                               gnus-newsgroup-headers)))
12086     (setq gnus-newsgroup-headers
12087           (gnus-merge 'list
12088                       gnus-newsgroup-headers
12089                       (gnus-fetch-headers articles)
12090                       'gnus-article-sort-by-number))
12091     ;; Suppress duplicates?
12092     (when gnus-suppress-duplicates
12093       (gnus-dup-suppress-articles))
12094
12095     ;; We might want to build some more threads first.
12096     (when (and gnus-fetch-old-headers
12097                (eq gnus-headers-retrieved-by 'nov))
12098       (if (eq gnus-fetch-old-headers 'invisible)
12099           (gnus-build-all-threads)
12100         (gnus-build-old-threads)))
12101     ;; Let the Gnus agent mark articles as read.
12102     (when gnus-agent
12103       (gnus-agent-get-undownloaded-list))
12104     ;; Remove list identifiers from subject
12105     (when gnus-list-identifiers
12106       (gnus-summary-remove-list-identifiers))
12107     ;; First and last article in this newsgroup.
12108     (when gnus-newsgroup-headers
12109       (setq gnus-newsgroup-begin
12110             (mail-header-number (car gnus-newsgroup-headers))
12111             gnus-newsgroup-end
12112             (mail-header-number
12113              (gnus-last-element gnus-newsgroup-headers))))
12114     (when gnus-use-scoring
12115       (gnus-possibly-score-headers))))
12116
12117 (defun gnus-summary-insert-old-articles (&optional all)
12118   "Insert all old articles in this group.
12119 If ALL is non-nil, already read articles become readable.
12120 If ALL is a number, fetch this number of articles."
12121   (interactive "P")
12122   (prog1
12123       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12124             older len)
12125         (setq older
12126               ;; Some nntp servers lie about their active range.  When
12127               ;; this happens, the active range can be in the millions.
12128               ;; Use a compressed range to avoid creating a huge list.
12129               (gnus-range-difference (list gnus-newsgroup-active) old))
12130         (setq len (gnus-range-length older))
12131         (cond
12132          ((null older) nil)
12133          ((numberp all)
12134           (if (< all len)
12135               (let ((older-range (nreverse older)))
12136                 (setq older nil)
12137
12138                 (while (> all 0)
12139                   (let* ((r (pop older-range))
12140                          (min (if (numberp r) r (car r)))
12141                          (max (if (numberp r) r (cdr r))))
12142                     (while (and (<= min max)
12143                                 (> all 0))
12144                       (push max older)
12145                       (setq all (1- all)
12146                             max (1- max))))))
12147             (setq older (gnus-uncompress-range older))))
12148          (all
12149           (setq older (gnus-uncompress-range older)))
12150          (t
12151           (when (and (numberp gnus-large-newsgroup)
12152                    (> len gnus-large-newsgroup))
12153               (let* ((cursor-in-echo-area nil)
12154                      (initial (gnus-parameter-large-newsgroup-initial
12155                                gnus-newsgroup-name))
12156                      (input
12157                       (read-string
12158                        (format
12159                         "How many articles from %s (%s %d): "
12160                         (gnus-limit-string
12161                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12162                         (if initial "max" "default")
12163                         len)
12164                        (if initial
12165                            (cons (number-to-string initial)
12166                                  0)))))
12167                 (unless (string-match "^[ \t]*$" input)
12168                   (setq all (string-to-number input))
12169                   (if (< all len)
12170                       (let ((older-range (nreverse older)))
12171                         (setq older nil)
12172
12173                         (while (> all 0)
12174                           (let* ((r (pop older-range))
12175                                  (min (if (numberp r) r (car r)))
12176                                  (max (if (numberp r) r (cdr r))))
12177                             (while (and (<= min max)
12178                                         (> all 0))
12179                               (push max older)
12180                               (setq all (1- all)
12181                                     max (1- max))))))))))
12182           (setq older (gnus-uncompress-range older))))
12183         (if (not older)
12184             (message "No old news.")
12185           (gnus-summary-insert-articles older)
12186           (gnus-summary-limit (gnus-sorted-nunion old older))))
12187     (gnus-summary-position-point)))
12188
12189 (defun gnus-summary-insert-new-articles ()
12190   "Insert all new articles in this group."
12191   (interactive)
12192   (prog1
12193       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12194             (old-active gnus-newsgroup-active)
12195             (nnmail-fetched-sources (list t))
12196             i new)
12197         (setq gnus-newsgroup-active
12198               (gnus-activate-group gnus-newsgroup-name 'scan))
12199         (setq i (cdr gnus-newsgroup-active))
12200         (while (> i (cdr old-active))
12201           (push i new)
12202           (decf i))
12203         (if (not new)
12204             (message "No gnus is bad news")
12205           (gnus-summary-insert-articles new)
12206           (setq gnus-newsgroup-unreads
12207                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12208           (gnus-summary-limit (gnus-sorted-nunion old new))))
12209     (gnus-summary-position-point)))
12210
12211 (gnus-summary-make-all-marking-commands)
12212
12213 (gnus-ems-redefine)
12214
12215 (provide 'gnus-sum)
12216
12217 (run-hooks 'gnus-sum-load-hook)
12218
12219 ;; Local Variables:
12220 ;; coding: iso-8859-1
12221 ;; End:
12222
12223 ;;; gnus-sum.el ends here